From 3846292d902ade073adc3dba257c6efd1b7124cd Mon Sep 17 00:00:00 2001 From: Paul ADENOT Date: Wed, 2 Nov 2011 13:52:21 -0700 Subject: [PATCH] Bug 556563 - Disable/remove "View video" when you're already viewing the video. r=dolske --- browser/base/content/nsContextMenu.js | 11 +-- .../base/content/test/subtst_contextmenu.html | 2 + .../base/content/test/test_contextmenu.html | 75 +++++++++++++++++-- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 0c43e17dc031..a1a03f596cd0 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -277,9 +277,10 @@ nsContextMenu.prototype = { // View image depends on having an image that's not standalone // (or is in a frame), or a canvas. this.showItem("context-viewimage", (this.onImage && - (!this.onStandaloneImage || this.inFrame)) || this.onCanvas); + (!this.inSyntheticDoc || this.inFrame)) || this.onCanvas); - this.showItem("context-viewvideo", this.onVideo); + // View video depends on not having a standalone video. + this.showItem("context-viewvideo", this.onVideo && (!this.inSyntheticDoc || this.inFrame)); this.setItemAttr("context-viewvideo", "disabled", !this.mediaURL); // View background image depends on whether there is one. @@ -466,7 +467,6 @@ nsContextMenu.prototype = { this.onImage = false; this.onLoadedImage = false; this.onCompletedImage = false; - this.onStandaloneImage = false; this.onCanvas = false; this.onVideo = false; this.onAudio = false; @@ -482,6 +482,7 @@ nsContextMenu.prototype = { this.linkProtocol = ""; this.onMathML = false; this.inFrame = false; + this.inSyntheticDoc = false; this.hasBGImage = false; this.bgImageURL = ""; this.onEditableArea = false; @@ -500,6 +501,8 @@ nsContextMenu.prototype = { // Remember the node that was clicked. this.target = aNode; + // Check if we are in a synthetic document (stand alone image, video, etc.). + this.inSyntheticDoc = this.target.ownerDocument.mozSyntheticDocument; // First, do checks for nodes that never have children. if (this.target.nodeType == Node.ELEMENT_NODE) { // See if the user clicked on an image. @@ -515,8 +518,6 @@ nsContextMenu.prototype = { this.onCompletedImage = true; this.mediaURL = this.target.currentURI.spec; - if (this.target.ownerDocument instanceof ImageDocument) - this.onStandaloneImage = true; } else if (this.target instanceof HTMLCanvasElement) { this.onCanvas = true; diff --git a/browser/base/content/test/subtst_contextmenu.html b/browser/base/content/test/subtst_contextmenu.html index 95fbae1bcaa6..ad1b7c2375bb 100644 --- a/browser/base/content/test/subtst_contextmenu.html +++ b/browser/base/content/test/subtst_contextmenu.html @@ -18,6 +18,8 @@ Browser context menu subtest. + +
chssseefsbbbie
diff --git a/browser/base/content/test/test_contextmenu.html b/browser/base/content/test/test_contextmenu.html index 0700218efe8f..f80995bef77e 100644 --- a/browser/base/content/test/test_contextmenu.html +++ b/browser/base/content/test/test_contextmenu.html @@ -433,10 +433,68 @@ function runTest(testNum) { "context-viewinfo", true ].concat(inspectItems)); closeContextMenu(); - openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck. + openContextMenuFor(video_in_iframe); // Invoke context menu for next test. break; case 12: + // Context menu for a video in an iframe + checkContextMenu(["context-media-play", true, + "context-media-mute", true, + "context-media-hidecontrols", true, + "context-video-showstats", true, + "context-video-fullscreen", true, + "---", null, + "context-viewvideo", true, + "context-copyvideourl", true, + "---", null, + "context-savevideo", true, + "context-video-saveimage", true, + "context-sendvideo", true, + "frame", null, + ["context-showonlythisframe", true, + "context-openframeintab", true, + "context-openframe", true, + "---", null, + "context-reloadframe", true, + "---", null, + "context-bookmarkframe", true, + "context-saveframe", true, + "---", null, + "context-printframe", true, + "---", null, + "context-viewframeinfo", true], null].concat(inspectItems)); + closeContextMenu(); + openContextMenuFor(image_in_iframe); // Invoke context menu for next test. + break; + + case 13: + // Context menu for an image in an iframe + checkContextMenu(["context-viewimage", true, + "context-copyimage-contents", true, + "context-copyimage", true, + "---", null, + "context-saveimage", true, + "context-sendimage", true, + "context-setDesktopBackground", true, + "context-viewimageinfo", true, + "frame", null, + ["context-showonlythisframe", true, + "context-openframeintab", true, + "context-openframe", true, + "---", null, + "context-reloadframe", true, + "---", null, + "context-bookmarkframe", true, + "context-saveframe", true, + "---", null, + "context-printframe", true, + "---", null, + "context-viewframeinfo", true], null].concat(inspectItems)); + closeContextMenu(); + openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck. + break; + + case 14: // Context menu for textarea checkContextMenu(["*chubbiness", true, // spelling suggestion "spell-add-to-dictionary", true, @@ -461,7 +519,7 @@ function runTest(testNum) { openContextMenuFor(contenteditable); // Invoke context menu for next test. break; - case 13: + case 15: // Context menu for contenteditable checkContextMenu(["spell-no-suggestions", false, "spell-add-to-dictionary", true, @@ -486,7 +544,7 @@ function runTest(testNum) { openContextMenuFor(inputspell); // Invoke context menu for next test. break; - case 14: + case 16: // Context menu for spell-check input checkContextMenu(["*prodigality", true, // spelling suggestion "spell-add-to-dictionary", true, @@ -511,13 +569,13 @@ function runTest(testNum) { openContextMenuFor(link); // Invoke context menu for next test. break; - case 15: + case 17: executeCopyCommand("cmd_copyLink", "http://mozilla.com/"); closeContextMenu(); openContextMenuFor(pagemenu); // Invoke context menu for next test. break; - case 16: + case 18: // Context menu for element with assigned content context menu checkContextMenu(["+Plain item", {type: "", icon: "", checked: false, disabled: false}, "+Disabled item", {type: "", icon: "", checked: false, disabled: true}, @@ -560,7 +618,7 @@ function runTest(testNum) { openContextMenuFor(pagemenu, true); // Invoke context menu for next test. break; - case 17: + case 19: // Context menu for element with assigned content context menu // The shift key should bypass content context menu processing checkContextMenu(["context-back", false, @@ -604,7 +662,7 @@ 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, textarea, contenteditable, inputspell, pagemenu; + iframe, video_in_iframe, image_in_iframe, textarea, contenteditable, inputspell, pagemenu; function startTest() { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); @@ -636,6 +694,9 @@ function startTest() { video_bad = subwindow.document.getElementById("test-video-bad"); video_bad2 = subwindow.document.getElementById("test-video-bad2"); iframe = subwindow.document.getElementById("test-iframe"); + 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