Bug 517902 - "Reimplement image properties, using the existing "Media" panel" [ui-r=faaborg r=db48x sr=mconnor]
authorTanner M. Young <mozilla.bugs@alyoung.com>
Thu, 22 Oct 2009 19:32:49 -0500
changeset 34111 9617b533502277651fac3aeb448a768ddd90d89c
parent 34110 10c4ec8f2a31fba61dc29d4666b62ce2904fdf0b
child 34112 c21e54da30f81b060c7c3ec7af402f680226ac03
child 36003 041115c448a0a03ef01302ebb716720f7ef3ee0e
push id9887
push userreed@reedloden.com
push dateFri, 23 Oct 2009 00:33:06 +0000
treeherdermozilla-central@9617b5335022 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfaaborg, db48x, mconnor
bugs517902
milestone1.9.3a1pre
Bug 517902 - "Reimplement image properties, using the existing "Media" panel" [ui-r=faaborg r=db48x sr=mconnor]
browser/base/content/browser-context.inc
browser/base/content/browser.js
browser/base/content/nsContextMenu.js
browser/base/content/pageinfo/pageInfo.js
browser/base/content/pageinfo/pageInfo.xul
browser/base/content/test/test_contextmenu.html
browser/locales/en-US/chrome/browser/browser.dtd
--- a/browser/base/content/browser-context.inc
+++ b/browser/base/content/browser-context.inc
@@ -151,16 +151,20 @@
       <menuitem id="context-setDesktopBackground"
                 label="&setDesktopBackgroundCmd.label;"
                 accesskey="&setDesktopBackgroundCmd.accesskey;"
                 oncommand="gContextMenu.setDesktopBackground();"/>
       <menuitem id="context-blockimage"
                 type="checkbox"
                 accesskey="&blockImageCmd.accesskey;"
                 oncommand="gContextMenu.toggleImageBlocking(this.getAttribute('checked') == 'true');"/>
+      <menuitem id="context-viewimageinfo"
+                label="&viewImageInfoCmd.label;"
+                accesskey="&viewImageInfoCmd.accesskey;"
+                oncommand="gContextMenu.viewImageInfo();"/>
       <menuitem id="context-savevideo"
                 label="&saveVideoCmd.label;"
                 accesskey="&saveVideoCmd.accesskey;"
                 oncommand="gContextMenu.saveMedia();"/>
       <menuitem id="context-saveaudio"
                 label="&saveAudioCmd.label;"
                 accesskey="&saveAudioCmd.accesskey;"
                 oncommand="gContextMenu.saveMedia();"/>
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2080,19 +2080,20 @@ function BrowserViewSourceOfDocument(aDo
     // If no page descriptor is available, just use the view-source URL...
   }
 
   top.gViewSourceUtils.viewSource(webNav.currentURI.spec, pageCookie, aDocument);
 }
 
 // doc - document to use for source, or null for this window's document
 // initialTab - name of the initial tab to display, or null for the first tab
-function BrowserPageInfo(doc, initialTab)
+// imageUrl - url of an image to load in the Media Tab of the Page Info window; can be null/omitted
+function BrowserPageInfo(doc, initialTab, imageUrl)
 {
-  var args = {doc: doc, initialTab: initialTab};
+  var args = {doc: doc, initialTab: initialTab, imageUrl: imageUrl};
   return toOpenDialogByTypeAndUrl("Browser:page-info",
                                   doc ? doc.location : window.content.document.location,
                                   "chrome://browser/content/pageinfo/pageInfo.xul",
                                   "chrome,toolbar,dialog=no,resizable",
                                   args);
 }
 
 #ifdef DEBUG
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -252,16 +252,18 @@ nsContextMenu.prototype = {
     this.showItem("context-viewvideo", this.onVideo);
     this.setItemAttr("context-viewvideo",  "disabled", !this.mediaURL);
 
     // View background image depends on whether there is one.
     this.showItem("context-viewbgimage", shouldShow && !this._hasMultipleBGImages);
     this.showItem("context-sep-viewbgimage", shouldShow && !this._hasMultipleBGImages);
     document.getElementById("context-viewbgimage")
             .disabled = !this.hasBGImage;
+
+    this.showItem("context-viewimageinfo", (this.onImage));
   },
 
   initMiscItems: function CM_initMiscItems() {
     var isTextSelected = this.isTextSelected;
     
     // Use "Bookmark This Link" if on a link.
     this.showItem("context-bookmarkpage",
                   !(this.isContentSelected || this.onTextInput || this.onLink ||
@@ -771,16 +773,20 @@ nsContextMenu.prototype = {
   viewFrameSource: function() {
     BrowserViewSourceOfDocument(this.target.ownerDocument);
   },
 
   viewInfo: function() {
     BrowserPageInfo(this.target.ownerDocument.defaultView.top.document);
   },
 
+  viewImageInfo: function() {
+    BrowserPageInfo(this.target.ownerDocument.defaultView.top.document,"mediaTab",this.mediaURL);
+  },
+
   viewFrameInfo: function() {
     BrowserPageInfo(this.target.ownerDocument);
   },
 
   reloadImage: function(e) {
     urlSecurityCheck(this.mediaURL,
                      this.browser.contentPrincipal,
                      Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -80,16 +80,18 @@ pageInfoTreeView.prototype = {
   {
     this.data[row][column.index] = value;
   },
 
   addRow: function(row)
   {
     this.rows = this.data.push(row);
     this.rowCountChanged(this.rows - 1, 1);
+    if (this.selection.count == 0 && this.rowCount)
+      this.selection.select(0);
   },
 
   rowCountChanged: function(index, count)
   {
     this.tree.rowCountChanged(index, count);
   },
 
   invalidate: function()
@@ -141,16 +143,17 @@ pageInfoTreeView.prototype = {
   isSelectable: function(row, column) { return false; },
   performAction: function(action) { },
   performActionOnCell: function(action, row, column) { }
 };
 
 // mmm, yummy. global variables.
 var gWindow = null;
 var gDocument = null;
+var gImageUrl = null;
 
 // column number to help using the data array
 const COL_IMAGE_ADDRESS = 0;
 const COL_IMAGE_TYPE    = 1;
 const COL_IMAGE_SIZE    = 2;
 const COL_IMAGE_ALT     = 3;
 const COL_IMAGE_COUNT   = 4;
 const COL_IMAGE_NODE    = 5;
@@ -288,16 +291,21 @@ function onLoadPageInfo()
       gWindow = window.opener.frames[0];
     gDocument = gWindow.document;
   }
 
   // init media view
   var imageTree = document.getElementById("imagetree");
   imageTree.view = gImageView;
 
+  // set gImageUrl if present
+  if ("arguments" in window && window.arguments.length >= 1 &&
+       window.arguments[0] && window.arguments[0].imageUrl)
+    gImageUrl = window.arguments[0].imageUrl;
+
   // build the content
   loadPageInfo();
 
   /* Select the requested tab, if the name is specified */
   var initialTab = "generalTab";
   if ("arguments" in window && window.arguments.length >= 1 &&
        window.arguments[0] && window.arguments[0].initialTab)
     initialTab = window.arguments[0].initialTab;
@@ -518,40 +526,33 @@ function goThroughFrames(aDocument, aWin
 function processFrames()
 {
   if (gFrameList.length) {
     var doc = gFrameList[0];
     onProcessFrame.forEach(function(func) { func(doc); });
     var iterator = doc.createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, grabAll, true);
     gFrameList.shift();
     setTimeout(doGrab, 16, iterator);
+    onFinished.push(selectImgUrl);
   }
   else
     onFinished.forEach(function(func) { func(); });
 }
 
 function doGrab(iterator)
 {
   for (var i = 0; i < 50; ++i)
     if (!iterator.nextNode()) {
       processFrames();
       return;
     }
 
   setTimeout(doGrab, 16, iterator);
 }
 
-function ensureSelection(view)
-{
-  // only select something if nothing is currently selected
-  // and if there's anything to select
-  if (view.selection.count == 0 && view.rowCount)
-    view.selection.select(0);
-}
-
 function addImage(url, type, alt, elem, isBg)
 {
   if (!url)
     return;
 
   if (!gImageHash.hasOwnProperty(url))
     gImageHash[url] = { };
   if (!gImageHash[url].hasOwnProperty(type))
@@ -1164,8 +1165,22 @@ function doCopy()
 
 function doSelectAll()
 {
   var elem = document.commandDispatcher.focusedElement;
 
   if (elem && "treeBoxObject" in elem)
     elem.view.selection.selectAll();
 }
+
+function selectImgUrl ()
+{
+  if (gImageUrl) {
+    var tree = document.getElementById("imagetree");
+    for (var c = 0; c < tree.view.rowCount; c++)
+    {
+      if (gImageUrl == gImageView.data[c][COL_IMAGE_ADDRESS]) {
+        tree.view.selection.select(c);
+        return;
+      }
+    }
+  }
+}
--- a/browser/base/content/pageinfo/pageInfo.xul
+++ b/browser/base/content/pageinfo/pageInfo.xul
@@ -114,17 +114,17 @@
     <menuitem id="menu_copy"      label="&copy.label;"      command="cmd_copy"      accesskey="&copy.accesskey;"/>
   </menupopup>
 
   <windowdragbox id="topBar" class="viewGroupWrapper">
     <radiogroup id="viewGroup" class="chromeclass-toolbar" orient="horizontal">
       <radio id="generalTab"  label="&generalTab;"  accesskey="&generalTab.accesskey;"
            oncommand="showTab('general');"/>
       <radio id="mediaTab"    label="&mediaTab;"    accesskey="&mediaTab.accesskey;"
-           oncommand="showTab('media'); ensureSelection(gImageView)" hidden="true"/>
+           oncommand="showTab('media');" hidden="true"/>
       <radio id="feedTab"     label="&feedTab;"     accesskey="&feedTab.accesskey;"
            oncommand="showTab('feed');" hidden="true"/>
       <radio id="permTab"     label="&permTab;"     accesskey="&permTab.accesskey;"
            oncommand="showTab('perm');"/>
       <radio id="securityTab" label="&securityTab;" accesskey="&securityTab.accesskey;"
            oncommand="showTab('security');"/>
       <!-- Others added by overlay -->
     </radiogroup>
--- a/browser/base/content/test/test_contextmenu.html
+++ b/browser/base/content/test/test_contextmenu.html
@@ -205,17 +205,18 @@ function runTest(testNum) {
         // Context menu for an image
         checkContextMenu(["context-viewimage",            true,
                           "context-copyimage-contents",   true,
                           "context-copyimage",            true,
                           "---",                          null,
                           "context-saveimage",            true,
                           "context-sendimage",            true,
                           "context-setDesktopBackground", true,
-                          "context-blockimage",           true]);
+                          "context-blockimage",           true,
+                          "context-viewimageinfo",        true]);
         closeContextMenu();
         openContextMenuFor(canvas); // Invoke context menu for next test.
         break;
 
     case 7:
         // Context menu for a canvas
         checkContextMenu(["context-viewimage",    true,
                           "context-saveimage",    true,
@@ -237,33 +238,33 @@ function runTest(testNum) {
                           "---",                        null,
                           "context-savevideo",          true,
                           "context-sendvideo",          true]);
         closeContextMenu();
         openContextMenuFor(video_bad); // Invoke context menu for next test.
         break;
 
     case 9:
-        // Context menu for a video (with a INVALID media source)
+        // Context menu for a video (with an INVALID media source)
         checkContextMenu(["context-media-play",         false,
                           "context-media-mute",         false,
                           "context-media-showcontrols", false,
                           "context-video-fullscreen",   false,
                           "---",                        null,
                           "context-viewvideo",          true,
                           "context-copyvideourl",       true,
                           "---",                        null,
                           "context-savevideo",          true,
                           "context-sendvideo",          true]);
         closeContextMenu();
         openContextMenuFor(video_bad2); // Invoke context menu for next test.
         break;
 
     case 10:
-        // Context menu for a video (with a INVALID media source)
+        // Context menu for a video (with an INVALID media source)
         checkContextMenu(["context-media-play",         false,
                           "context-media-mute",         false,
                           "context-media-showcontrols", false,
                           "context-video-fullscreen",   false,
                           "---",                        null,
                           "context-viewvideo",          false,
                           "context-copyvideourl",       false,
                           "---",                        null,
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -260,16 +260,18 @@
 <!ENTITY viewPageInfoCmd.label        "View Page Info">
 <!ENTITY viewPageInfoCmd.accesskey    "I">
 <!ENTITY viewFrameInfoCmd.label       "View Frame Info">
 <!ENTITY viewFrameInfoCmd.accesskey   "I">
 <!ENTITY reloadImageCmd.label         "Reload Image">
 <!ENTITY reloadImageCmd.accesskey     "R">
 <!ENTITY viewImageCmd.label           "View Image">
 <!ENTITY viewImageCmd.accesskey       "I">
+<!ENTITY viewImageInfoCmd.label       "View Image Info">
+<!ENTITY viewImageInfoCmd.accesskey   "f">
 <!ENTITY viewVideoCmd.label           "View Video">
 <!ENTITY viewVideoCmd.accesskey       "I">
 <!ENTITY viewBGImageCmd.label         "View Background Image">
 <!ENTITY viewBGImageCmd.accesskey     "w">
 <!ENTITY setDesktopBackgroundCmd.label      "Set As Desktop Background…">
 <!ENTITY setDesktopBackgroundCmd.accesskey  "S">
 <!ENTITY bookmarkPageCmd2.label       "Bookmark This Page">
 <!ENTITY bookmarkPageCmd2.accesskey   "m">