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

Michael A. Borisov mic at i-house.ru
Tue Jul 20 11:33:17 BST 2004


Leo Savernik wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Am Montag 19 Juli 2004 08:18 schrieb Michael A. Borisov:
>[...]
>  
>
>>The problem is sometimes DOM::Node::getRect returns wrong coordinates of
>>DOM objects. Usually it occures for images. I investigated this problem
>>and I understand that it depends on scrolling.
>>    
>>
>
>Strange bug.
>
>  
>
>>For example if image width is smaller than KHTMLView::visibleWidth()
>>then getRect() returns correct coordinates. But if image width is bigger
>>than KHTMLView::visibleWidth() getRect() returns wrong x and y and
>>negative width and height.
>>    
>>
>
>Ah, now I understand what you mean. So the getRect is not wrong when the 
>document's scrollOffset is > 0, but it is wrong when the render object (the 
>image) is larger than the canvas.
>
>There are some position-bugs that plagued khtml 3.2 wrt inline and replaced 
>elements, and you probably seem to have uncovered even more. Can you attach a 
>small testcase that reliably reproduces the bug, along with instructions on 
>how to reproduce it?
>
Ok. I'll do it later today. But I need an immediate solution. So I'm 
using the following trick.

tvresult tvHtmlElement::getRect(DOM::Node& node, QRect* rect)
{
  KHTMLPart* htmlPart = node.ownerDocument().view()->part();

  const char jsGetX[] = "\
  function _tvGetDomNodeX_(obj) {\
    var parent = obj;\
    var x = 0;\
    while (parent != null) {\
      x += parent.offsetLeft;\
      parent = parent.offsetParent;\
    }\
    return x;\
  }\
  _tvGetDomNodeX_(this);\
  ";

  const char jsGetY[] = "\
  function _tvGetDomNodeY_(obj) {\
    var parent = obj;\
    var y = 0;\
    while (parent != null) {\
      y += parent.offsetTop;\
      parent = parent.offsetParent;\
    }\
    return y;\
  };\
  _tvGetDomNodeY_(this);\
  ";

  rect->setRect(
    htmlPart->executeScript(node, jsGetX).asInt(),
    htmlPart->executeScript(node, jsGetY).asInt(),
    htmlPart->executeScript(node, "this.offsetWidth;").asInt(),
    htmlPart->executeScript(node, "this.offsetHeight;").asInt()
  );

  return OK;
}

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?

With respect,
Michael.

>  
>
>[...]
>
>mfg
>	Leo
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.6 (GNU/Linux)
>Comment: For info see http://www.gnupg.org
>
>iD8DBQFA/Biwj5jssenUYTsRAs3XAJ9/TWfVHtAAdmjV+hge+F9RaPaiNQCeKyvG
>TdddOZ1CAEHI+uThQFxG1e4=
>=D5Oi
>-----END PGP SIGNATURE-----
>
>
>  
>






More information about the kfm-devel mailing list