Bug 702159 - Add context menu to exit DOM full screen mode and tests. r=jaws
authorDan Wendorf <dan@danwendorf.com>
Thu, 24 May 2012 23:57:59 -0500
changeset 95062 01673165f0eef183e8a72ebada6c6caebd32c9f1
parent 95061 4ce695c26fc563dac5efc4a4ca9e8f0f9db2c4ae
child 95063 e1a1d40f2246333ba95fc705d938007d00a07b90
push id22776
push userryanvm@gmail.com
push dateMon, 28 May 2012 01:01:29 +0000
treeherdermozilla-central@4c3f2ddd82e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs702159
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 702159 - Add context menu to exit DOM full screen mode and tests. r=jaws
browser/base/content/browser-context.inc
browser/base/content/nsContextMenu.js
browser/base/content/test/subtst_contextmenu.html
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
@@ -81,16 +81,20 @@
       <menuitem id="context-video-hidestats"
                 accesskey="&videoHideStats.accesskey;"
                 label="&videoHideStats.label;"
                 oncommand="gContextMenu.mediaCommand('hidestats');"/>
       <menuitem id="context-video-fullscreen"
                 accesskey="&videoFullScreen.accesskey;"
                 label="&videoFullScreen.label;"
                 oncommand="gContextMenu.fullScreenVideo();"/>
+      <menuitem id="context-leave-dom-fullscreen"
+                accesskey="&leaveDOMFullScreen.accesskey;"
+                label="&leaveDOMFullScreen.label;"
+                oncommand="gContextMenu.leaveDOMFullScreen();"/>
       <menuseparator id="context-media-sep-commands"/>
       <menuitem id="context-reloadimage"
                 label="&reloadImageCmd.label;"
                 accesskey="&reloadImageCmd.accesskey;"
                 oncommand="gContextMenu.reloadImage();"/>
       <menuitem id="context-viewimage"
                 label="&viewImageCmd.label;"
                 accesskey="&viewImageCmd.accesskey;"
@@ -119,17 +123,17 @@
                 label="&copyAudioURLCmd.label;"
                 accesskey="&copyAudioURLCmd.accesskey;"
                 oncommand="gContextMenu.copyMediaLocation();"/>
       <menuseparator id="context-sep-copyimage"/>
       <menuitem id="context-saveimage"
                 label="&saveImageCmd.label;"
                 accesskey="&saveImageCmd.accesskey;"
                 oncommand="gContextMenu.saveMedia();"/>
-      <menuitem id="context-sendimage" 
+      <menuitem id="context-sendimage"
                 label="&sendImageCmd.label;"
                 accesskey="&sendImageCmd.accesskey;"
                 oncommand="gContextMenu.sendMedia();"/>
       <menuitem id="context-setDesktopBackground"
                 label="&setDesktopBackgroundCmd.label;"
                 accesskey="&setDesktopBackgroundCmd.accesskey;"
                 oncommand="gContextMenu.setDesktopBackground();"/>
       <menuitem id="context-viewimageinfo"
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -49,16 +49,17 @@ nsContextMenu.prototype = {
     this.initOpenItems();
     this.initNavigationItems();
     this.initViewItems();
     this.initMiscItems();
     this.initSpellingItems();
     this.initSaveItems();
     this.initClipboardItems();
     this.initMediaPlayerItems();
+    this.initLeaveDOMFullScreenItems();
   },
 
   initPageMenuSeparator: function CM_initPageMenuSeparator() {
     this.showItem("page-menu-separator", this.hasPageMenu);
   },
 
   initOpenItems: function CM_initOpenItems() {
     var isMailtoInternal = false;
@@ -150,16 +151,26 @@ nsContextMenu.prototype = {
     this.showItem("context-reload", shouldShow);
     this.showItem("context-stop", shouldShow);
     this.showItem("context-sep-stop", shouldShow);
 
     // XXX: Stop is determined in browser.js; the canStop broadcaster is broken
     //this.setItemAttrFromNode( "context-stop", "disabled", "canStop" );
   },
 
+  initLeaveDOMFullScreenItems: function CM_initLeaveFullScreenItem() {
+    // only show the option if the user is in DOM fullscreen
+    var shouldShow = (this.target.ownerDocument.mozFullScreenElement != null);
+    this.showItem("context-leave-dom-fullscreen", shouldShow);
+
+    // Explicitly show if in DOM fullscreen, but do not hide it has already been shown
+    if (shouldShow)
+        this.showItem("context-media-sep-commands", true);
+  },
+
   initSaveItems: function CM_initSaveItems() {
     var shouldShow = !(this.onTextInput || this.onLink ||
                        this.isContentSelected || this.onImage ||
                        this.onCanvas || this.onVideo || this.onAudio);
     this.showItem("context-savepage", shouldShow);
     this.showItem("context-sendpage", shouldShow);
 
     // Save+Send link depends on whether we're in a link, or selected text matches valid URL pattern.
@@ -814,16 +825,20 @@ nsContextMenu.prototype = {
   },
 
   fullScreenVideo: function () {
     let video = this.target;
     if (document.mozFullScreenEnabled)
       video.mozRequestFullScreen();
   },
 
+  leaveDOMFullScreen: function() {
+    document.mozCancelFullScreen();
+  },
+
   // Change current window to the URL of the background image.
   viewBGImage: function(e) {
     urlSecurityCheck(this.bgImageURL,
                      this.browser.contentPrincipal,
                      Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
     var doc = this.target.ownerDocument;
     openUILink(this.bgImageURL, e, { disallowInheritPrincipal: true,
                                      referrerURI: doc.documentURIObject });
--- a/browser/base/content/test/subtst_contextmenu.html
+++ b/browser/base/content/test/subtst_contextmenu.html
@@ -19,16 +19,17 @@ Browser context menu subtest.
   <source src="bogus.duh" type="video/durrrr;">
 </video>
 <iframe id="test-iframe" width="98"  height="98" style="border: 1px solid black"></iframe>
 <iframe id="test-video-in-iframe" src="video.ogg" width="98" height="98" style="border: 1px solid black"></iframe>
 <iframe id="test-image-in-iframe" src="ctxmenu-image.png" width="98" height="98" style="border: 1px solid black"></iframe>
 <textarea id="test-textarea">chssseesbbbie</textarea> <!-- a weird word which generates only one suggestion -->
 <div id="test-contenteditable" contenteditable="true">chssseefsbbbie</div> <!-- a more weird word which generates no suggestions -->
 <input id="test-input-spellcheck" type="text" spellcheck="true" autofocus value="prodkjfgigrty"> <!-- this one also generates one suggestion -->
+<div id="test-dom-full-screen">DOM full screen FTW</div>
 <div contextmenu="myMenu">
   <p id="test-pagemenu" hopeless="true">I've got a context menu!</p>
   <menu id="myMenu" type="context">
     <menuitem label="Plain item" onclick="document.getElementById('test-pagemenu').removeAttribute('hopeless');"></menuitem>
     <menuitem label="Disabled item" disabled></menuitem>
     <menuitem> Item w/ textContent</menuitem>
     <menu>
       <menuitem type="checkbox" label="Checkbox" checked></menuitem>
--- a/browser/base/content/test/test_contextmenu.html
+++ b/browser/base/content/test/test_contextmenu.html
@@ -22,17 +22,17 @@ netscape.security.PrivilegeManager.enabl
 Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 function openContextMenuFor(element, shiftkey, shouldWaitForFocus) {
     // Context menu should be closed before we open it again.
-    is(contextMenu.state, "closed", "checking if popup is closed");
+    is(SpecialPowers.wrap(contextMenu).state, "closed", "checking if popup is closed");
 
     if (lastElement)
       lastElement.blur();
     element.focus();
 
     // Some elements need time to focus and spellcheck before any tests are
     // run on them.
     function actuallyOpenContextMenuFor() {
@@ -666,20 +666,61 @@ function runTest(testNum) {
                           "context-selectall",    true,
                           "---",                  null,
                           "context-viewsource",   true,
                           "context-viewinfo",     true
                          ].concat(inspectItems));
 
         invokeItemAction("0");
         closeContextMenu();
-        openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
+
+        // run mozRequestFullScreen on the element we're testing
+        var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
+        var openDomFullScreen = function() {
+            subwindow.removeEventListener("mozfullscreenchange", openDomFullScreen, false);
+            SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
+            openContextMenuFor(dom_full_screen, true); // Invoke context menu for next test.
+        }
+        subwindow.addEventListener("mozfullscreenchange", openDomFullScreen, false);
+        SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
+        full_screen_element.mozRequestFullScreen();
         break;
 
-    case 22:
+        case 22:
+        // Context menu for DOM Fullscreen mode (NOTE: this is *NOT* on an img)
+        checkContextMenu(["context-leave-dom-fullscreen", true,
+                          "---",                          null,
+                          "context-back",                 false,
+                          "context-forward",              false,
+                          "context-reload",               true,
+                          "context-stop",                 false,
+                          "---",                          null,
+                          "context-bookmarkpage",         true,
+                          "context-savepage",             true,
+                          "context-sendpage",             true,
+                          "---",                          null,
+                          "context-viewbgimage",          false,
+                          "context-selectall",            true,
+                          "---",                          null,
+                          "context-viewsource",           true,
+                          "context-viewinfo",             true
+                         ].concat(inspectItems));
+        closeContextMenu();
+        var full_screen_element = subwindow.document.getElementById("test-dom-full-screen");
+        var openPagemenu = function() {
+            subwindow.removeEventListener("mozfullscreenchange", openPagemenu, false);
+            SpecialPowers.clearUserPref("full-screen-api.allow-trusted-requests-only");
+            openContextMenuFor(pagemenu, true); // Invoke context menu for next test.
+        }
+        subwindow.addEventListener("mozfullscreenchange", openPagemenu, false);
+        SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);
+        subwindow.document.mozCancelFullScreen();
+        break;
+
+    case 23:
         // Context menu for element with assigned content context menu
         // The shift key should bypass content context menu processing
         checkContextMenu(["context-back",         false,
                           "context-forward",      false,
                           "context-reload",       true,
                           "context-stop",         false,
                           "---",                  null,
                           "context-bookmarkpage", true,
@@ -692,33 +733,33 @@ function runTest(testNum) {
                           "context-viewsource",   true,
                           "context-viewinfo",     true
                          ].concat(inspectItems));
         closeContextMenu();
         selectText(selecttext); // Select text prior to opening context menu.
         openContextMenuFor(selecttext); // Invoke context menu for next test.
         return;
 
-    case 23:
+    case 24:
         // Context menu for selected text
         if (Services.appinfo.OS == "Darwin") {
           // This test is only enabled on Mac due to bug 736399.
           checkContextMenu(["context-copy",                        true,
                             "context-selectall",                   true,
                             "---",                                 null,
                             "context-searchselect",                true,
                             "context-viewpartialsource-selection", true
                            ].concat(inspectItems));
         }
         closeContextMenu();
         selectText(selecttextlink); // Select text prior to opening context menu.
         openContextMenuFor(selecttextlink); // Invoke context menu for next test.
         return;
 
-    case 24:
+    case 25:
         // Context menu for selected text which matches valid URL pattern
         if (Services.appinfo.OS == "Darwin") {
           // This test is only enabled on Mac due to bug 736399.
           checkContextMenu(["context-openlinkincurrent",           true,
                             "context-openlinkintab",               true,
                             "context-openlink",                    true,
                             "---",                                 null,
                             "context-bookmarklink",                true,
@@ -753,17 +794,17 @@ function runTest(testNum) {
 
 }
 
 
 var testNum = 1;
 var subwindow, chromeWin, contextMenu, lastElement;
 var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2,
     iframe, video_in_iframe, image_in_iframe, textarea, contenteditable,
-    inputspell, pagemenu, plainTextItems, audio_in_video;
+    inputspell, pagemenu, dom_full_screen, plainTextItems, audio_in_video;
 
 function startTest() {
     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
     chromeWin = subwindow
                     .QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIWebNavigation)
                     .QueryInterface(Ci.nsIDocShellTreeItem)
                     .rootTreeItem
@@ -774,16 +815,17 @@ function startTest() {
     ok(contextMenu, "Got context menu XUL");
 
     if (chromeWin.document.getElementById("Browser:Stop").getAttribute("disabled") != "true") {
       todo(false, "Wait for subwindow to load... (This should usually happen once.)");
       SimpleTest.executeSoon(startTest);
       return;
     }
 
+    subwindow.mozAllowFullScreen = true;
     lastElement = null;
 
     text   = subwindow.document.getElementById("test-text");
     link   = subwindow.document.getElementById("test-link");
     mailto = subwindow.document.getElementById("test-mailto");
     input  = subwindow.document.getElementById("test-input");
     img    = subwindow.document.getElementById("test-image");
     canvas = subwindow.document.getElementById("test-canvas");
@@ -795,16 +837,17 @@ function startTest() {
     video_in_iframe = subwindow.document.getElementById("test-video-in-iframe").contentDocument.getElementsByTagName("video")[0];
     video_in_iframe.pause();
     image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0];
     textarea = subwindow.document.getElementById("test-textarea");
     contenteditable = subwindow.document.getElementById("test-contenteditable");
     contenteditable.focus(); // content editable needs to be focused to enable spellcheck
     inputspell = subwindow.document.getElementById("test-input-spellcheck");
     pagemenu = subwindow.document.getElementById("test-pagemenu");
+    dom_full_screen = subwindow.document.getElementById("test-dom-full-screen");
     selecttext = subwindow.document.getElementById("test-select-text");
     selecttextlink = subwindow.document.getElementById("test-select-text-link");
 
     contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false);
     runTest(1);
 }
 
 // We open this in a separate window, because the Mochitests run inside a frame.
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -98,17 +98,20 @@ These should match what Safari and other
 <!ENTITY fullScreenClose.tooltip "Close">
 <!ENTITY fullScreenAutohide.label "Hide Toolbars">
 <!ENTITY fullScreenAutohide.accesskey "H">
 <!ENTITY fullScreenExit.label "Exit Full Screen Mode">
 <!ENTITY fullScreenExit.accesskey "F">
 <!ENTITY fullscreenAllowButton.label "Allow">
 <!ENTITY fullscreenExitButton.label "Deny">
 <!ENTITY fullscreenApproval.value "Allow fullscreen?">
+
 <!ENTITY fullscreenExitHint.value "Press ESC at any time to exit fullscreen.">
+<!ENTITY leaveDOMFullScreen.label "Exit Full Screen">
+<!ENTITY leaveDOMFullScreen.accesskey "u">
 
 <!ENTITY closeWindow.label "Close Window">
 <!ENTITY closeWindow.accesskey "d">
 
 <!ENTITY bookmarksMenu.label "Bookmarks">
 <!ENTITY bookmarksMenu.accesskey "B">
 <!ENTITY bookmarkThisPageCmd.label "Bookmark This Page">
 <!ENTITY bookmarkThisPageCmd.commandkey "d">