Author: [email protected]
Date: Tue Jun  2 10:48:36 2009
New Revision: 5495

Modified:
    branches/snapshot-2009.05.12-r5406/branch-info.txt
     
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE6.java
     
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE8.java
     
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplTrident.java
     
branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dom/client/ElementTest.java

Log:
Merge trunk 5485, 5492 to snapshot branch.

5485:
Fixes missing body scroll-position addition in IE8's implementation of
getAbsoluteLeft/Top().

Review: http://gwt-code-reviews.appspot.com/34827
Patch by: jgw

r5492:
Fixes test failure on FF2 with a bit of a hack in the test (FF2 has an
off-by-one error in getBoxObjectFor() that cannot easily be fixed).

TBR: jlabanca
Patch by: jgw



Modified: branches/snapshot-2009.05.12-r5406/branch-info.txt
==============================================================================
--- branches/snapshot-2009.05.12-r5406/branch-info.txt  (original)
+++ branches/snapshot-2009.05.12-r5406/branch-info.txt  Tue Jun  2 10:48:36  
2009
@@ -24,3 +24,6 @@
    svn merge -c5487 https://google-web-toolkit.googlecode.com/svn/trunk .
  /trunk c5490 was merged into this branch (Date diag info)
    svn merge -c5490 https://google-web-toolkit.googlecode.com/svn/trunk .
+/trunk c5485,5492 were merged into this branch (IE8 fix)
+  svn merge -c5485 https://google-web-toolkit.googlecode.com/svn/trunk .
+  svn merge -c5492 https://google-web-toolkit.googlecode.com/svn/trunk .

Modified:  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE6.java
==============================================================================
---  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE6.java
    
(original)
+++  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE6.java
    
Tue Jun  2 10:48:36 2009
@@ -24,14 +24,14 @@
    @Override
    public int getAbsoluteLeft(Element elem) {
      Document doc = elem.getOwnerDocument();
-    return (int) Math.floor(super.getAbsoluteLeft(elem)
+    return (int) Math.floor(getBoundingClientRectLeft(elem)
          / getZoomMultiple(doc) + doc.getScrollLeft());
    }

    @Override
    public int getAbsoluteTop(Element elem) {
      Document doc = elem.getOwnerDocument();
-    return (int) Math.floor(super.getAbsoluteTop(elem)
+    return (int) Math.floor(getBoundingClientRectTop(elem)
          / getZoomMultiple(doc) + doc.getScrollTop());
    }


Modified:  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE8.java
==============================================================================
---  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE8.java
    
(original)
+++  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplIE8.java
    
Tue Jun  2 10:48:36 2009
@@ -18,6 +18,18 @@
  class DOMImplIE8 extends DOMImplTrident {

    @Override
+  public int getAbsoluteLeft(Element elem) {
+    Document doc = elem.getOwnerDocument();
+    return getBoundingClientRectLeft(elem) + doc.getScrollLeft();
+  }
+
+  @Override
+  public int getAbsoluteTop(Element elem) {
+    Document doc = elem.getOwnerDocument();
+    return getBoundingClientRectTop(elem) + doc.getScrollTop();
+  }
+
+  @Override
    public int getScrollLeft(Element elem) {
      if (isRTL(elem)) {
        // IE8 returns increasingly *positive* values as you scroll left in  
RTL.

Modified:  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplTrident.java
==============================================================================
---  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplTrident.java
        
(original)
+++  
branches/snapshot-2009.05.12-r5406/user/src/com/google/gwt/dom/client/DOMImplTrident.java
        
Tue Jun  2 10:48:36 2009
@@ -166,16 +166,6 @@
      return "[event" + evt.type + "]";
    }-*/;

-  @Override
-  public int getAbsoluteLeft(Element elem) {
-    return getBoundingClientRectLeft(elem);
-  }
-
-  @Override
-  public int getAbsoluteTop(Element elem) {
-    return getBoundingClientRectTop(elem);
-  }
-
    /**
     * IE returns a numeric type for some attributes that are really  
properties,
     * such as offsetWidth.  We need to coerce these to strings to prevent a
@@ -253,23 +243,7 @@
      elem.innerText = text || '';
    }-*/;

-  protected native boolean isRTL(Element elem) /*-{
-    return elem.currentStyle.direction == 'rtl';
-  }-*/;
-
-  private native Element createElementInternal(Document doc, String  
tagName) /*-{
-    return doc.createElement(tagName);
-  }-*/;
-
-  // IE needs a container div *for each document* for use by  
createElement().
-  private native Element ensureContainer(Document doc) /*-{
-    if (!doc.__gwt_container) {
-      doc.__gwt_container = doc.createElement('div');
-    }
-    return doc.__gwt_container;
-  }-*/;
-
-  private native int getBoundingClientRectLeft(Element elem) /*-{
+  protected native int getBoundingClientRectLeft(Element elem) /*-{
      // getBoundingClientRect() throws a JS exception if the elem is not  
attached
      // to the document, so we wrap it in a try/catch block
      try {
@@ -279,7 +253,7 @@
      }
    }-*/;

-  private native int getBoundingClientRectTop(Element elem) /*-{
+  protected native int getBoundingClientRectTop(Element elem) /*-{
      // getBoundingClientRect() throws a JS exception if the elem is not  
attached
      // to the document, so we wrap it in a try/catch block
      try {
@@ -287,6 +261,22 @@
      } catch (e) {
        return 0;
      }
+  }-*/;
+
+  protected native boolean isRTL(Element elem) /*-{
+    return elem.currentStyle.direction == 'rtl';
+  }-*/;
+
+  private native Element createElementInternal(Document doc, String  
tagName) /*-{
+    return doc.createElement(tagName);
+  }-*/;
+
+  // IE needs a container div *for each document* for use by  
createElement().
+  private native Element ensureContainer(Document doc) /*-{
+    if (!doc.__gwt_container) {
+      doc.__gwt_container = doc.createElement('div');
+    }
+    return doc.__gwt_container;
    }-*/;

    /**

Modified:  
branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dom/client/ElementTest.java
==============================================================================
---  
branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dom/client/ElementTest.java
  
(original)
+++  
branches/snapshot-2009.05.12-r5406/user/test/com/google/gwt/dom/client/ElementTest.java
  
Tue Jun  2 10:48:36 2009
@@ -16,6 +16,8 @@
  package com.google.gwt.dom.client;

  import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.dom.client.Style.Position;
+import com.google.gwt.dom.client.Style.Unit;
  import com.google.gwt.junit.client.GWTTestCase;
  import com.google.gwt.user.client.Command;
  import com.google.gwt.user.client.DeferredCommand;
@@ -212,37 +214,37 @@
    }

    /**
-   * scroll[Left|Top], scrollIntoView.
+   * scroll[Left|Top], getAbsolute[Left|Top].
     */
-  public void testGetAbsolutePositionWhenScrolled() {
-    final DivElement outer = Document.get().createDivElement();
-    final DivElement inner = Document.get().createDivElement();
-
-    outer.getStyle().setProperty("position", "absolute");
-    outer.getStyle().setProperty("top", "0px");
-    outer.getStyle().setProperty("left", "0px");
-    outer.getStyle().setProperty("overflow", "auto");
-    outer.getStyle().setProperty("width", "200px");
-    outer.getStyle().setProperty("height", "200px");
-
-    inner.getStyle().setProperty("marginTop", "800px");
-    inner.getStyle().setProperty("marginLeft", "800px");
-
-    outer.appendChild(inner);
-    Document.get().getBody().appendChild(outer);
-    inner.setInnerText(":-)");
-    inner.scrollIntoView();
-
-    // Ensure that we are scrolled.
-    assertTrue(outer.getScrollTop() > 0);
-    assertTrue(outer.getScrollLeft() > 0);
+  public void testGetAbsolutePositionWhenBodyScrolled() {
+    Document doc = Document.get();
+    BodyElement body = doc.getBody();

-    outer.setScrollLeft(0);
-    outer.setScrollTop(0);
+    DivElement div = doc.createDivElement();
+    body.appendChild(div);

-    // Ensure that we are no longer scrolled.
-    assertEquals(outer.getScrollTop(), 0);
-    assertEquals(outer.getScrollLeft(), 0);
+    div.setInnerText("foo");
+    div.getStyle().setPosition(Position.ABSOLUTE);
+    div.getStyle().setLeft(1000, Unit.PX);
+    div.getStyle().setTop(1000, Unit.PX);
+
+    // Get the absolute position of the element when the body is  
unscrolled.
+    int absLeft = div.getAbsoluteLeft();
+    int absTop = div.getAbsoluteTop();
+
+    // Scroll the body as far down and to the right as possible.
+    body.setScrollLeft(10000);
+    body.setScrollTop(10000);
+
+    // Make sure the absolute position hasn't changed (this has turned out  
to
+    // be a common error in getAbsoluteLeft/Top() implementations).
+    //
+    // HACK: Firefox 2 has a bug that causes its getBoxObjectFor() to  
become
+    // off-by-one at times when scrolling. It's not clear how to make this  
go
+    // away, and doesn't seem to be worth the trouble to implement
+    // getAbsoluteLeft/Top() yet again for FF2.
+    assertTrue(Math.abs(absLeft - div.getAbsoluteLeft()) <= 1);
+    assertTrue(Math.abs(absTop - div.getAbsoluteTop()) <= 1);
    }

    /**
@@ -308,6 +310,20 @@
    }

    /**
+   * Tests Element.is() and Element.as().
+   */
+  public void testIsAndAs() {
+    assertFalse(Element.is(Document.get()));
+
+    Node div = Document.get().createDivElement();
+    assertTrue(Element.is(div));
+    assertEquals("div", Element.as(div).getTagName().toLowerCase());
+
+    // Element.is(null) is allowed and should return false.
+    assertFalse(Element.is(null));
+  }
+
+  /**
     * Document.createElement('ns:tag'), getTagName().
     */
    public void testNamespaces() {
@@ -389,6 +405,40 @@
      JavaScriptObject jso = createTrivialJSO();
      div.setPropertyJSO("tintin", jso);
      assertEquals(jso, div.getPropertyJSO("tintin"));
+  }
+
+  /**
+   * scroll[Left|Top], scrollIntoView.
+   */
+  public void testScrollIntoView() {
+    final DivElement outer = Document.get().createDivElement();
+    final DivElement inner = Document.get().createDivElement();
+
+    outer.getStyle().setProperty("position", "absolute");
+    outer.getStyle().setProperty("top", "0px");
+    outer.getStyle().setProperty("left", "0px");
+    outer.getStyle().setProperty("overflow", "auto");
+    outer.getStyle().setProperty("width", "200px");
+    outer.getStyle().setProperty("height", "200px");
+
+    inner.getStyle().setProperty("marginTop", "800px");
+    inner.getStyle().setProperty("marginLeft", "800px");
+
+    outer.appendChild(inner);
+    Document.get().getBody().appendChild(outer);
+    inner.setInnerText(":-)");
+    inner.scrollIntoView();
+
+    // Ensure that we are scrolled.
+    assertTrue(outer.getScrollTop() > 0);
+    assertTrue(outer.getScrollLeft() > 0);
+
+    outer.setScrollLeft(0);
+    outer.setScrollTop(0);
+
+    // Ensure that we are no longer scrolled.
+    assertEquals(outer.getScrollTop(), 0);
+    assertEquals(outer.getScrollLeft(), 0);
    }

    /**

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to