Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree getAbsoluteLeft()/getAbsoluteTop() doesn't return correct values? #48

Closed
dankurka opened this issue Jun 10, 2015 · 11 comments
Closed

Comments

@dankurka
Copy link
Member

Originally reported on Google Code with ID 39

GWT Release:
1.1.10

Browser or OS version (if applicable):

Detailed description:

Reporter sets position of tree to 5,5 in root container, but Tree reports
its position as 5,25 when queried.

Example code showing the problem (strongly preferred):

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ImageViewer implements EntryPoint {
        private CheckBox m_checkBox;
        private Tree m_tree;
        public void onModuleLoad() {
                RootPanel rootPanel = RootPanel.get();
                {
                        m_tree = new Tree();
                        rootPanel.add(m_tree, 5, 5);
                }
                {
                        final Button button = new Button();
                        rootPanel.add(button, 192, 225);
                        button.addClickListener(new ButtonClickListener());
                        button.setText("Show tree location");
                }
                {
                        m_checkBox = new CheckBox();
                        rootPanel.add(m_checkBox, 200, 5);
                        m_checkBox.setText("New CheckBox");
                }
                {
                        final Button showCheckboxLocationButton = new Button();
                        rootPanel.add(showCheckboxLocationButton, 192, 260);
                        showCheckboxLocationButton.addClickListener(new
ShowCheckboxLocationButtonClickListener());
                        showCheckboxLocationButton.setText("Show CheckBox
location");
                }
        }
        private class ButtonClickListener implements ClickListener {
                public void onClick(Widget sender) {
                        System.out.println("tree location: " +
m_tree.getAbsoluteLeft() + ",
" + m_tree.getAbsoluteTop());
                }
        }
        private class ShowCheckboxLocationButtonClickListener implements
ClickListener {
                public void onClick(Widget sender) {
                        System.out.println("checkBox location: "
                                + m_checkBox.getAbsoluteLeft()
                                + ", "
                                + m_checkBox.getAbsoluteTop());
                } 
}

Workaround if you have one:

Links to the relevant discussion group topics (optional):
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/d9408e43f15b4053

Reported by gwt.team.vli on 2006-09-20 06:59:11

@dankurka
Copy link
Member Author

The problem is that IE starts its window at 2,2 rather than 0,0 
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/getboundingclientrect.asp

Reported by gwt.team.ecc on 2006-09-25 14:16:20

@dankurka
Copy link
Member Author

Fixed by added -2 to getAbsoluteLeft and getAbsoluteTop

Reported by gwt.team.ecc on 2006-09-26 18:31:23

@dankurka
Copy link
Member Author

Reported by gwt.team.ecc on 2006-09-26 18:31:47

  • Status changed: FixedNotReleased

@dankurka
Copy link
Member Author


  I am not sure that this is correct fix.

1. I use IE6 and problems in MSDN tells that (2,2) is reported on IE5
2. Different is not (2,2), but (0,20).

Reported by Konstantin.Scheglov on 2006-09-29 08:22:42

@dankurka
Copy link
Member Author

The implementation of getAbsoluteLeft had already changed before this bug was looked
at. By the time this bug was repro'd, the tests were only 2 off. I would be very
curious if the following fix, patched into DOMImplIE6, does not work for you.

public native int getAbsoluteLeft(Element elem) /*-{
    // Offset needed as IE starts the window's upper left as 2,2 rather than 0,0
    return elem.getBoundingClientRect().left - 2;
  }-*/;   

Reported by gwt.team.ecc on 2006-10-09 11:31:37

  • Labels added: Milestone-1_2_Final

@dankurka
Copy link
Member Author

Minor detail, shouldn't it be Milestone-1_2_RC?

Reported by ismaelj on 2006-10-20 01:22:22

@dankurka
Copy link
Member Author

Reported by gwt.team.bruce on 2006-10-23 16:27:38

  • Labels added: Milestone-1_2_RC
  • Labels removed: Release-1.1.10, Milestone-1_2_Final

@dankurka
Copy link
Member Author

Reported by gwt.team.jgw on 2006-10-31 17:00:26

  • Status changed: Fixed

@dankurka
Copy link
Member Author

Just for future reference, it appears that the (2, 2) offset can be found in the
clientLeft/clientTop on the documentElement (standard mode) or body (quirks mode)
element.

In other words either in standard mode:
  $doc.documentElement.clientLeft == 2
  $doc.documentElement.clientTop  == 2

And in quirks mode:
  $doc.body.clientLeft == 2
  $doc.body.clientTop  == 2



Reported by fredsa on 2007-03-06 19:52:43

@dankurka
Copy link
Member Author


Reported by sumitchandel+legacy@google.com on 2008-05-02 02:32:22

@dankurka
Copy link
Member Author

Reported by rjrjr@google.com on 2011-02-09 00:10:59

  • Labels added: Milestone-1_2-RC
  • Labels removed: Milestone-1_2_RC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant