Bug 597036 - Find in page does not display results on screen when page is zoomed [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Mon, 25 Oct 2010 16:35:13 +0200
changeset 66913 a2fbdc56de3eac626512ce6775a50f90b81e40b4
parent 66912 d4cafa28c14a3ceed2cbd92ca4366af3825686a9
child 66914 35f3509f0261333dd6117a8e2097c9a8d22f1571
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs597036
Bug 597036 - Find in page does not display results on screen when page is zoomed [r=mfinkle]
mobile/chrome/content/bindings/browser.xml
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
mobile/chrome/content/content.js
--- a/mobile/chrome/content/bindings/browser.xml
+++ b/mobile/chrome/content/bindings/browser.xml
@@ -833,25 +833,30 @@
                 readonly="true"/>
 
       <constructor>
         <![CDATA[
           this.messageManager.addMessageListener("scroll", this._messageListenerRemote);
         ]]>
       </constructor>
 
+      <field name="scrollSync">true</field>
+
       <field name="_messageListenerRemote"><![CDATA[
         ({
           self: this,
           receiveMessage: function receiveMessage(aMessage) {
             let self = this.self;
             let json = aMessage.json;
 
             switch (aMessage.name) {
               case "scroll":
+                if (!this.scrollSync)
+                  return;
+
                 // When CSS scroll offset changes, we must redefine our cache viewport because
                 // the cache viewport coordinate system's origin is the CSS scroll offset. Setting
                 // _pendingPixels* guarantees that _updateCacheViewport is called in scrollTo.
                 self._pendingPixelsX = Number.MAX_VALUE;
                 self._pendingPixelsY = Number.MAX_VALUE;
 
                 // Use floor so that we always guarantee top-left corner of content is visible.
                 self.scrollTo(Math.floor(json.x * self.scale), Math.floor(json.y * self.scale));
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1677,22 +1677,26 @@ var FindHelperUI = {
     if (aEvent.type == "TabSelect" || aEvent.type == "URLChanged")
       this.hide();
   },
 
   show: function findHelperShow() {
     this._container.show(this);
     this.search("");
     this._textbox.focus();
+
+    // Prevent the view to scroll automatically while searching
+    Browser.selectedBrowser.scrollSync = false;
   },
 
   hide: function findHelperHide() {
     this._textbox.value = "";
     this._textbox.blur();
     this._container.hide(this);
+    Browser.selectedBrowser.scrollSync = true;
   },
 
   goToPrevious: function findHelperGoToPrevious() {
     Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Previous", { });
   },
 
   goToNext: function findHelperGoToNext() {
     Browser.selectedBrowser.messageManager.sendAsyncMessage("FindAssist:Next", { });
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -892,18 +892,19 @@ var Browser = {
 
     let zoomValues = ZoomManager.zoomValues;
     let i = zoomValues.indexOf(ZoomManager.snap(zoomLevel)) + (aDirection < 0 ? 1 : -1);
     if (i >= 0 && i < zoomValues.length)
       zoomLevel = zoomValues[i];
 
     zoomLevel = tab.clampZoomLevel(zoomLevel);
 
-    let center = browser.transformClientToBrowser(window.innerWidth / 2,
-                                                  window.innerHeight / 2);
+    let browserRect = browser.getBoundingClientRect();
+    let center = browser.transformClientToBrowser(browserRect.width / 2,
+                                                  browserRect.height / 2);
     let rect = this._getZoomRectForPoint(center.x, center.y, zoomLevel);
     this.animatedZoomTo(rect);
   },
 
   /** Rect should be in browser coordinates. */
   _getZoomLevelForRect: function _getZoomLevelForRect(rect) {
     const margin = 15;
     return this.selectedTab.clampZoomLevel(window.innerWidth / (rect.width + margin * 2));
@@ -935,17 +936,18 @@ var Browser = {
   _getZoomRectForPoint: function _getZoomRectForPoint(x, y, zoomLevel) {
     let browser = getBrowser();
     x = x * browser.scale;
     y = y * browser.scale;
 
     zoomLevel = Math.min(ZoomManager.MAX, zoomLevel);
     let oldScale = browser.scale;
     let zoomRatio = zoomLevel / oldScale;
-    let newVisW = window.innerWidth / zoomRatio, newVisH = window.innerHeight / zoomRatio;
+    let browserRect = browser.getBoundingClientRect();
+    let newVisW = browserRect.width / zoomRatio, newVisH = browserRect.height / zoomRatio;
     let result = new Rect(x - newVisW / 2, y - newVisH / 2, newVisW, newVisH);
 
     // Make sure rectangle doesn't poke out of viewport
     return result.translateInside(new Rect(0, 0, browser.contentDocumentWidth * oldScale,
                                                  browser.contentDocumentHeight * oldScale));
   },
 
   animatedZoomTo: function animatedZoomTo(rect) {
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -902,13 +902,18 @@ var FindHandler = {
       let rect = frame.frameElement.getBoundingClientRect();
       let left = frame.getComputedStyle(frame.frameElement, "").borderLeftWidth;
       let top = frame.getComputedStyle(frame.frameElement, "").borderTopWidth;
       scroll.add(rect.left + parseInt(left), rect.top + parseInt(top));
     }
 
     let rangeRect = selection.getRangeAt(0).getBoundingClientRect();
     let rect = new Rect(scroll.x + rangeRect.left, scroll.y + rangeRect.top, rangeRect.width, rangeRect.height);
-    sendAsyncMessage("FindAssist:Show", { rect: rect.isEmpty() ? null: rect , result: findResult });
+
+    // Ensure the potential "scroll" event fired during a search as already fired
+    let timer = new Util.Timeout(function() {
+      sendAsyncMessage("FindAssist:Show", { rect: rect.isEmpty() ? null: rect , result: findResult });
+    });
+    timer.once(0);
   }
 };
 
 FindHandler.init();