Bug 486821 - Misplaced white line under last visible entry of location bar autocomplete. r=enn
☠☠ backed out by fca91e13946d ☠ ☠
authorDão Gottwald <dao@mozilla.com>
Thu, 09 Apr 2009 08:42:01 +0200
changeset 27114 716fc2e4f7d393f1f54a7602485549600beb128e
parent 27113 92ec425077690d93028c305830abc13015316c4d
child 27115 b1237eca36703defb4b7b1e3a42b843b523b4dfc
child 27132 fca91e13946daba978e4a7f5d394abbfac8aeec3
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersenn
bugs486821
milestone1.9.2a1pre
Bug 486821 - Misplaced white line under last visible entry of location bar autocomplete. r=enn
toolkit/content/widgets/autocomplete.xml
toolkit/content/widgets/richlistbox.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -1033,21 +1033,21 @@
           <![CDATA[
           // Figure out how many rows to show
           let rows = this.richlistbox.childNodes;
           let numRows = Math.min(this._matchCount, this.maxRows, rows.length);
 
           // Default the height to 0 if we have no rows to show
           let height = 0;
           if (numRows) {
-            let lastRowShown = rows[numRows - 1];
+            let firstRowRect = rows[0].getBoundingClientRect();
+            let lastRowRect = rows[numRows - 1].getBoundingClientRect();
 
             // Calculate the height to have the first row to last row shown
-            height = lastRowShown.boxObject.y + lastRowShown.boxObject.height -
-              rows[0].boxObject.y;
+            height = lastRowRect.bottom - firstRowRect.top;
           }
 
           // Only update the height if we have a non-zero height and if it
           // changed (the richlistbox is collapsed if there are no results)
           if (height && height != this.richlistbox.height)
             this.richlistbox.height = height;
           ]]>
         </body>
--- a/toolkit/content/widgets/richlistbox.xml
+++ b/toolkit/content/widgets/richlistbox.xml
@@ -53,22 +53,24 @@
       <children includes="listheader"/>
       <xul:scrollbox allowevents="true" orient="vertical" anonid="main-box"
                      flex="1" style="overflow: auto;">
         <children/>
       </xul:scrollbox>
     </content>
 
     <implementation>
-      <field name="scrollBoxObject">null</field>
+      <field name="_scrollbox">
+        document.getAnonymousElementByAttribute(this, "anonid", "main-box");
+      </field>
+      <field name="scrollBoxObject">
+        this._scrollbox.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
+      </field>
       <constructor>
         <![CDATA[
-          var x = document.getAnonymousElementByAttribute(this, "anonid", "main-box");
-          this.scrollBoxObject = x.boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
-
           // add a template build listener
           if (this.builder)
             this.builder.addListener(this._builderListener);
           else
             this._refreshSelection();
         ]]>
       </constructor>
 
@@ -182,18 +184,29 @@
           ]]>
         </body>
       </method>
 
       <method name="ensureElementIsVisible">
         <parameter name="aElement"/>
         <body>
           <![CDATA[
-            if (aElement)
-              this.scrollBoxObject.ensureElementIsVisible(aElement);
+            if (!aElement)
+              return;
+            var targetRect = aElement.getBoundingClientRect();
+            var scrollRect = this._scrollbox.getBoundingClientRect();
+            var offset = targetRect.top - scrollRect.top;
+            if (offset >= 0) {
+              // scrollRect.bottom wouldn't take a horizontal scroll bar into account
+              let scrollRectBottom = scrollRect.top + this._scrollbox.clientHeight;
+              offset = targetRect.bottom - scrollRectBottom;
+              if (offset <= 0)
+                return;
+            }
+            this._scrollbox.scrollTop += offset;
           ]]>
         </body>
       </method>
 
       <method name="scrollToIndex">
         <parameter name="aIndex"/>
         <body>
           <![CDATA[
@@ -456,36 +469,32 @@
       <!-- deprecated (is implied by currentItem and selectItem) -->
       <method name="fireActiveItemEvent"><body/></method>
     </implementation>
 
     <handlers>
       <handler event="click">
         <![CDATA[
           // clicking into nothing should unselect
-          if (event.originalTarget.getAttribute("anonid") == "main-box") {
+          if (event.originalTarget == this._scrollbox) {
             this.clearSelection();
             this.currentItem = null;
           }
         ]]>
       </handler>
 
       <handler event="MozSwipeGesture">
         <![CDATA[
-          // Figure out where to scroll to
-          let targetHeight = 0;
-          let scrollBox = document.getAnonymousElementByAttribute(this, "anonid", "main-box");
-
           // Only handle swipe gestures up and down
           switch (event.direction) {
             case event.DIRECTION_DOWN:
-              targetHeight = scrollBox.scrollHeight;
-              // Fall through for actual action
+              this._scrollbox.scrollTop = this._scrollbox.scrollHeight;
+              break;
             case event.DIRECTION_UP:
-              scrollBox.scrollTop = targetHeight;
+              this._scrollbox.scrollTop = 0;
               break;
           }
         ]]>
       </handler>
     </handlers>
   </binding>
 
   <binding id="richlistitem"