Bug 582190 - ContextMenu should resize when switching the window orientation [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 28 Jul 2010 00:54:09 +0200
changeset 66402 e7a6216aec49bba87e40d98d79d59d1bb1f499a7
parent 66401 946f9085be0345162a1e4d49126fc6f1ef440f35
child 66403 2cf4257aaa995f59c2a4a3d189bf4c0c212b1dc0
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
bugs582190
Bug 582190 - ContextMenu should resize when switching the window orientation [r=mfinkle]
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -2072,39 +2072,52 @@ var ContextHelper = {
     if (this.popupState.onImage)
       label.value = this.popupState.mediaURL;
     if (this.popupState.onLink)
       label.value = this.popupState.linkURL;
     if (this.popupState.onBookmark)
       label.value = this.popupState.bookmarkURL;
 
     this._panel.hidden = false;
+    window.addEventListener("resize", this, true);
 
+    this.sizeToContent();
+    BrowserUI.pushPopup(this, [this._popup]);
+  },
+
+  hide: function ch_hide() {
+    this.popupState = null;
+    this._panel.hidden = true;
+    window.removeEventListener("resize", this, true);
+
+    BrowserUI.popPopup();
+  },
+
+  sizeToContent: function sizeToContent() {
     // Make sure the container is at least sized to the content
     let popup = this._popup;
     let preferredHeight = 0;
     for (let i=0; i<popup.childElementCount; i++) {
       preferredHeight += popup.children[i].getBoundingClientRect().height;
     }
 
+    // Ensure to reset the assigned width/height to have the default's one set
+    // by the content
+    popup.width = popup.height = "";
+
     let rect = popup.getBoundingClientRect();
     let height = Math.min(preferredHeight, 0.75 * window.innerWidth);
     let width = Math.min(rect.width, 0.75 * window.innerWidth);
 
     popup.height = height;
     popup.width = width;
-
-    BrowserUI.pushPopup(this, [popup]);
   },
 
-  hide: function ch_hide() {
-    this.popupState = null;
-    this._panel.hidden = true;
-
-    BrowserUI.popPopup();
+  handleEvent: function handleEvent(aEvent) {
+    this.sizeToContent();
   }
 };
 
 var ContextCommands = {
   openInNewTab: function cc_openInNewTab(aEvent) {
     Browser.addTab(ContextHelper.popupState.linkURL, false, Browser.selectedTab);
   },