DOM::Node::getRect problem. Help please.

Michael A. Borisov mic at i-house.ru
Wed Jul 21 06:52:32 BST 2004


Leo Savernik wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Am Dienstag 20 Juli 2004 12:33 schrieb Michael A. Borisov:
>[...]
>  
>
>>Ok. I'll do it later today. 
>>    
>>
>
>I couldn't reproduce the issue with the following testcase:
>data:text/html,lala<br><img alt="p" width="2000" height="1500" title="showme">
>
>  
>
I'm using the following code to get map areas.

tvresult tvGeoNavigation::getMapAreas(KHTMLPart* htmlPart, const int 
parentFrameX, const int parentFrameY, tvElementList* list)
{
  DOM::HTMLImageElement image;
  DOM::DOMString mapName;
  DOM::HTMLMapElement map;
  DOM::HTMLCollection areas;
  QRect imageRect;
  unsigned int i, j, k;
  tvresult res;

  DOM::NodeList maps = htmlPart->htmlDocument().getElementsByTagName("map");

  if (!maps.length())
    return OK;

  DOM::HTMLCollection images = htmlPart->htmlDocument().images();
  if (!images.length())
    return OK;

  for (i = 0; i < images.length(); ++i) {
    image = (DOM::HTMLImageElement)images.item(i);
    if (image.useMap().isEmpty())
      continue;
    mapName = image.useMap().copy();
    mapName.remove(0);

    imageRect = image.getRect(); // This getRect returns wrong 
coordinates. Try www.yahoo.com (map at the top).

    for (j = 0; j < maps.length(); ++j) {
      map = (DOM::HTMLMapElement)maps.item(i);
      if (map.name() == mapName) {
        areas = map.areas();
        for (k = 0; k < areas.length(); ++k)
          list->push_back(new tvHtmlMapAreaElement(areas.item(k), 
imageRect, parentFrameX, parentFrameY));
        break;
      }
    }
  }

  return OK;
}

Also try to get rect of the most left item in main menu at 
www.sdesigns.com ("company").

With respect,
Michael.

>>But I need an immediate solution. So I'm 
>>using the following trick.
>>
>>    
>>
>[...]
>  
>
>>  rect->setRect(
>>    htmlPart->executeScript(node, jsGetX).asInt(),
>>    htmlPart->executeScript(node, jsGetY).asInt(),
>>    htmlPart->executeScript(node, "this.offsetWidth;").asInt(),
>>    htmlPart->executeScript(node, "this.offsetHeight;").asInt()
>>  );
>>    
>>
>[...]
>
>Wow, cool hack. No wonder it's slow ;-).
>
>  
>
>>This trick works fine with KDE libs 3.2.x but does not work with libs
>>3.1.x. What's wrong in my code? Will it faster to preload these
>>functions after document loading finished and invoke these functions later?
>>    
>>
>
>You certainly can precalculate the values, but you have to ensure that the 
>layout cannot be changed afterwards (i. e. no resize happens, and the 
>document structure is not changed dynamically).
>
>The best way to make it work is to fix it.
>  
>
>[...]
>
>mfg
>	Leo
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.6 (GNU/Linux)
>Comment: For info see http://www.gnupg.org
>
>iD8DBQFA/Ttrj5jssenUYTsRAtLaAJ9zOpFc0tfL2aRwTlyimjylqLwkAQCfW5wt
>fKkCLt5+YAMl8ObuPNvDEts=
>=JA3V
>-----END PGP SIGNATURE-----
>
>
>  
>




More information about the kfm-devel mailing list