Bug 1570165 - Port Bug 517902 "Reimplement image properties, using the existing "Media" panel" to SeaMonkey. r=frg a=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Wed, 31 Jul 2019 21:56:04 +0200
changeset 32258 2375c07411d59718c1323a98ab08eb603cec5d27
parent 32257 7f9f81bab5610f028e80c9f2b90412c66085f51c
child 32259 bee6a4cc555f5f324936c6029cbc6a46ceab14dc
push id208
push userfrgrahl@gmx.net
push dateWed, 31 Jul 2019 19:58:37 +0000
treeherdercomm-esr60@2375c07411d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1570165, 517902
Bug 1570165 - Port Bug 517902 "Reimplement image properties, using the existing "Media" panel" to SeaMonkey. r=frg a=frg
suite/base/content/contentAreaContextOverlay.xul
suite/base/content/nsContextMenu.js
suite/browser/navigator.js
suite/browser/pageinfo/pageInfo.js
suite/locales/en-US/chrome/common/contentAreaCommands.dtd
--- a/suite/base/content/contentAreaContextOverlay.xul
+++ b/suite/base/content/contentAreaContextOverlay.xul
@@ -202,16 +202,20 @@
                 valueSaveAs="&saveImageAsCmd.label;"
                 valueSave="&saveImageCmd.label;"
                 accesskey="&saveImageCmd.accesskey;"
                 oncommand="gContextMenu.saveMedia();"/>
       <menuitem id="context-setDesktopBackground"
                 label="&setDesktopBackgroundCmd.label;"
                 accesskey="&setDesktopBackgroundCmd.accesskey;"
                 oncommand="gContextMenu.setDesktopBackground();"/>
+      <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/suite/base/content/nsContextMenu.js
+++ b/suite/base/content/nsContextMenu.js
@@ -274,16 +274,18 @@ nsContextMenu.prototype = {
     this.setItemAttr("context-viewvideo", "disabled", !this.mediaURL);
 
     // View background image depends on whether there is one, but don't make
     // background images of a stand-alone media document available
     this.showItem("context-viewbgimage", showView && !this.inSyntheticDoc);
     this.showItem("context-sep-viewbgimage", showView && !this.inSyntheticDoc);
     this.setItemAttr("context-viewbgimage", "disabled", this.hasBGImage ? null : "true");
 
+    this.showItem("context-viewimageinfo", this.onImage);
+
     // Hide Block and Unblock menuitems.
     this.showItem("context-blockimage", false);
     this.showItem("context-unblockimage", false);
 
     // Block image depends on whether an image was clicked on.
     if (this.onImage) {
       var uri = Services.io.newURI(this.mediaURL);
       if (uri instanceof Ci.nsIURL && uri.host) {
@@ -949,16 +951,21 @@ nsContextMenu.prototype = {
       outerWindowID: gContextMenuContentData.frameOuterWindowID,
     });
   },
 
   viewInfo: function() {
     BrowserPageInfo();
   },
 
+  viewImageInfo: function() {
+    BrowserPageInfo(this.target.ownerDocument.defaultView.top.document,
+                    "mediaTab", this.target);
+  },
+
   viewFrameInfo: function() {
     BrowserPageInfo(this.target.ownerDocument);
   },
 
   toggleImageSize: function() {
     content.document.toggleImageSize();
   },
 
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -2449,22 +2449,23 @@ function BrowserViewSource(aBrowser) {
     browser: aBrowser,
     outerWindowID: aBrowser.outerWindowID,
     URL: aBrowser.currentURI.spec,
   });
 }
 
 // doc - document to use for source, or null for the current tab
 // initialTab - id of the initial tab to display, or null for the first tab
-function BrowserPageInfo(doc, initialTab)
-{
+// imageElement - image to load in the Media Tab of the Page Info window;
+//                can be null/omitted
+function BrowserPageInfo(doc, initialTab, imageElement) {
   if (!doc)
     doc = window.content.document;
   var relatedUrl = doc.location.toString();
-  var args = {doc: doc, initialTab: initialTab};
+  var args = {doc: doc, initialTab: initialTab, imageElement: imageElement};
 
   var enumerator = Services.wm.getEnumerator("Browser:page-info");
   // Check for windows matching the url
   while (enumerator.hasMoreElements()) {
     let win = enumerator.getNext();
     if (win.document.documentElement
            .getAttribute("relatedUrl") == relatedUrl) {
       win.focus();
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -50,16 +50,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 && !gImageElement)
+      this.selection.select(0);
   },
 
   rowCountChanged: function(index, count)
   {
     this.tree.rowCountChanged(index, count);
   },
 
   invalidate: function()
@@ -150,16 +152,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 gImageElement = 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;
@@ -334,16 +337,21 @@ function onLoadPageInfo()
   }
 
   initView("imagetree", gImageView);
   initView("formtree", gFormView);
   initView("formpreview", gFieldView);
   initView("linktree", gLinkView);
   initPermission();
 
+  // set gImageElement if present
+  if ("arguments" in window && window.arguments.length >= 1 &&
+      window.arguments[0].imageElement)
+    gImageElement = window.arguments[0].imageElement;
+
   // build the content
   loadPageInfo();
 
   /* Select the requested tab, if the name is specified */
   var initialTab = (args && args.initialTab) || "generalTab";
   showTab(initialTab);
   Services.obs.notifyObservers(window, "page-info-dialog-loaded");
 }
@@ -545,16 +553,17 @@ 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, 10, iterator);
+    onFinished.push(selectImage);
   }
   else
     onFinished.forEach(function(func) { func(); });
 }
 
 function doGrab(iterator)
 {
   for (var i = 0; i < 500; ++i)
@@ -616,16 +625,18 @@ function onCacheEntryAvailable(cacheEntr
     // Add the observer, only once.
     if (gImageView.data.length == 1) {
       Services.obs.addObserver(imagePermissionObserver, "perm-changed");
     }
   }
   else {
     var i = gImageHash[url][type][alt];
     gImageView.data[i][COL_IMAGE_COUNT]++;
+    if (elem == gImageElement)
+      gImageView.data[i][COL_IMAGE_NODE] = elem;
   }
 };
 
 imgCacheListener.prototype.onCacheEntryCheck =
 function onCacheEntryCheck() {
   return ENTRY_WANTED;
 };
 
@@ -1390,15 +1401,30 @@ function doCopy(isLinkMode)
 function doSelectAll()
 {
   var elem = document.commandDispatcher.focusedElement;
 
   if (elem && "treeBoxObject" in elem)
     elem.view.selection.selectAll();
 }
 
+function selectImage() {
+  if (!gImageElement)
+    return;
+
+  var tree = document.getElementById("imagetree");
+  for (var i = 0; i < tree.view.rowCount; i++) {
+    if (gImageElement == gImageView.data[i][COL_IMAGE_NODE]) {
+      tree.view.selection.select(i);
+      tree.treeBoxObject.ensureRowIsVisible(i);
+      tree.focus();
+      return;
+    }
+  }
+}
+
 function onOpenIn(mode)
 {
   var linkList = getSelectedItems(true);
 
   if (linkList.length)
     openUILinkArrayIn(linkList, mode);
 }
--- a/suite/locales/en-US/chrome/common/contentAreaCommands.dtd
+++ b/suite/locales/en-US/chrome/common/contentAreaCommands.dtd
@@ -48,16 +48,18 @@
 <!ENTITY viewFrameInfoCmd.label       "View Frame Info">
 <!ENTITY viewFrameInfoCmd.accesskey   "I">
 <!ENTITY fitImageCmd.label            "Fit Image to Window">
 <!ENTITY fitImageCmd.accesskey        "F">
 <!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 Desktop Background…">
 <!ENTITY setDesktopBackgroundCmd.accesskey "a">
 <!ENTITY bookmarkPageCmd.label        "Bookmark This Page…">
 <!ENTITY bookmarkPageCmd.accesskey    "m">