Fix bug 541310 - Related Link (in Edit Task and Edit Event Window) is NOT clickable. r=decathlon,a=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 27 Oct 2011 17:13:27 +0200
changeset 8959 913cc0cb37f9e76de6b1c9a8deeb28a27352fd8d
parent 8958 359d0ea7f24d6495b9eded00581bde7360a4c0d4
child 8960 1980e02f69fb0b79be63fa583c2f52f6765f422b
push idunknown
push userunknown
push dateunknown
reviewersdecathlon, philipp
bugs541310
Fix bug 541310 - Related Link (in Edit Task and Edit Event Window) is NOT clickable. r=decathlon,a=philipp
calendar/base/content/dialogs/calendar-event-dialog.xul
calendar/base/content/dialogs/calendar-summary-dialog.xul
calendar/base/src/calApplicationUtils.js
--- a/calendar/base/content/dialogs/calendar-event-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-event-dialog.xul
@@ -1091,16 +1091,18 @@
                        class="groove" 
                        hidden="true"/>
             <row id="event-grid-link-row"
                  align="center"
                  hidden="true">
               <label value="&event.url.label;"
                      control="url-link"/>
               <label id="url-link"
+                     onclick="launchBrowser(this.getAttribute('href'), event)"
+                     oncommand="launchBrowser(this.getAttribute('href'), event)"
                      class="text-link"
                      crop="end"/>
             </row>
         </rows>
     </grid>
 
     <statusbar class="chromeclass-status" id="status-bar">
       <statusbarpanel id="status-text"
--- a/calendar/base/content/dialogs/calendar-summary-dialog.xul
+++ b/calendar/base/content/dialogs/calendar-summary-dialog.xul
@@ -306,13 +306,14 @@
 
   <!-- URL link -->
   <box id="event-grid-link-row" hidden="true" orient="vertical">
     <spacer class="default-spacer"/>
     <calendar-caption label="&read.only.link.label;"
                       control="url-link"/>
     <label id="url-link"
            class="text-link default-indent"
-           value=" "
+           onclick="launchBrowser(this.getAttribute('href'), event)"
+           oncommand="launchBrowser(this.getAttribute('href'), event)"
            crop="end"/>
   </box>
 
 </dialog>
--- a/calendar/base/src/calApplicationUtils.js
+++ b/calendar/base/src/calApplicationUtils.js
@@ -124,31 +124,44 @@ function openFormattedRegionURL(aPrefNam
  */
 function getFormattedRegionURL(aPrefName)
 {
   var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"].
                              getService(Components.interfaces.nsIURLFormatter);
   return formatter.formatURLPref(aPrefName);
 }
 
-function launchBrowser(UrlToGoTo)
+/**
+ * Launch the given url (string) in the external browser. If an event is passed,
+ * then this is only done on left click and the event propagation is stopped.
+ *
+ * @param url       The URL to open, as a string
+ * @param event     (optional) The event that caused the URL to open
+ */
+function launchBrowser(url, event)
 {
-  if (!UrlToGoTo) {
+  // Bail out if there is no url set, or an event was passed without left-click
+  if (!url || (event && event.button != 0)) {
     return;
   }
 
   // 0. Prevent people from trying to launch URLs such as javascript:foo();
   //    by only allowing URLs starting with http or https.
   // XXX: We likely will want to do this using nsIURLs in the future to
   //      prevent sneaky nasty escaping issues, but this is fine for now.
-  if (UrlToGoTo.indexOf("http") != 0) {
+  if (url.indexOf("http") != 0) {
     Components.utils.reportError ("launchBrowser: " +
-                                  "Invalid URL provided: " + UrlToGoTo +
+                                  "Invalid URL provided: " + url +
                                   " Only http:// and https:// URLs are valid.");
     return;
   }
 
-  var externalLoader =
-    (Components
-     .classes["@mozilla.org/uriloader/external-protocol-service;1"]
-     .getService(Components.interfaces.nsIExternalProtocolService));
-  externalLoader.loadUrl(cal.getIOService().newURI(UrlToGoTo, null, null));
+  Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
+            .getService(Components.interfaces.nsIExternalProtocolService)
+            .loadUrl(cal.getIOService().newURI(url, null, null));
+
+  // Make sure that any default click handlers don't do anything, we have taken
+  // care of all processing
+  if (event) {
+      event.stopPropagation();
+      event.preventDefault();
+  }
 }