Bug 482921 part 9 - Support tooltips in the View Source window. r=gavin.sharp.
authorHenri Sivonen <hsivonen@iki.fi>
Tue, 01 Nov 2011 13:33:11 +0200
changeset 80031 f715a1cf1e23dccfef21c039784a33a20cb21024
parent 80030 06eab34f121ab03d9753b41cab34617422ad6d5e
child 80032 775c075bd75287373a0eb4c62baa126de202deef
push idunknown
push userunknown
push dateunknown
reviewersgavin.sharp
bugs482921
milestone10.0a1
Bug 482921 part 9 - Support tooltips in the View Source window. r=gavin.sharp.
toolkit/components/viewsource/content/viewSource.js
toolkit/components/viewsource/content/viewSource.xul
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -766,8 +766,44 @@ function UpdateBackForwardCommands() {
   else
     backBroadcaster.setAttribute("disabled", "true");
 
   if (getWebNavigation().canGoForward)
     forwardBroadcaster.removeAttribute("disabled");
   else
     forwardBroadcaster.setAttribute("disabled", "true");
 }
+
+// FIXME copied and modified from browser.js.
+// Deduplication is part of bug 480356.
+function FillInHTMLTooltip(tipElement)
+{
+  var retVal = false;
+  var titleText = null;
+  var direction = tipElement.ownerDocument.dir;
+
+  while (!titleText && tipElement) {
+    if (tipElement.nodeType == Node.ELEMENT_NODE) {
+      titleText = tipElement.getAttribute("title");
+      var defView = tipElement.ownerDocument.defaultView;
+      // XXX Work around bug 350679:
+      // "Tooltips can be fired in documents with no view".
+      if (!defView)
+        return retVal;
+      direction = defView.getComputedStyle(tipElement, "")
+        .getPropertyValue("direction");
+    }
+    tipElement = tipElement.parentNode;
+  }
+
+  var tipNode = document.getElementById("aHTMLTooltip");
+  tipNode.style.direction = direction;
+
+  if (titleText && /\S/.test(titleText)) {
+    // Make CRLF and CR render one line break each.  
+    titleText = titleText.replace(/\r\n/g, '\n');
+    titleText = titleText.replace(/\r/g, '\n');
+    tipNode.setAttribute("label", titleText);
+    retVal = true;
+  }
+  return retVal;
+}
+
--- a/toolkit/components/viewsource/content/viewSource.xul
+++ b/toolkit/components/viewsource/content/viewSource.xul
@@ -136,16 +136,18 @@
     <key id="goForwardKb" keycode="VK_RIGHT" command="Browser:Forward" modifiers="accel" />
 #endif
 #ifdef XP_UNIX
     <key id="goBackKb2" key="&goBackCmd.commandKey;" command="Browser:Back" modifiers="accel"/>
     <key id="goForwardKb2" key="&goForwardCmd.commandKey;" command="Browser:Forward" modifiers="accel"/>
 #endif
 
   </keyset>
+  
+  <tooltip id="aHTMLTooltip" onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
 
   <menupopup id="viewSourceContextMenu">
     <menuitem id="context-back"
               label="&backCmd.label;"
               accesskey="&backCmd.accesskey;"
               command="Browser:Back"
               observes="viewSourceNavigation"/>
     <menuitem id="context-forward"
@@ -231,17 +233,17 @@
         </menupopup>
       </menu>
     </menubar>  
   </toolbox>
 
   <vbox id="appcontent" flex="1">
 
     <browser id="content" type="content-primary" name="content" src="about:blank" flex="1"
-             context="viewSourceContextMenu" showcaret="true"/>
+             context="viewSourceContextMenu" showcaret="true" tooltip="aHTMLTooltip"/>
     <findbar id="FindToolbar" browserid="content"/>
   </vbox> 
 
   <statusbar id="status-bar" class="chromeclass-status">
     <statusbarpanel id="statusbar-line-col" label="" flex="1"/>
   </statusbar>
 
 </window>