diff --git a/browser/base/content/browser-menubar.inc b/browser/base/content/browser-menubar.inc index ae0922a12032..a7189c2feab9 100644 --- a/browser/base/content/browser-menubar.inc +++ b/browser/base/content/browser-menubar.inc @@ -201,10 +201,12 @@ - + + + + #ifdef XP_MACOSX { + if (this.maybeDisableMenu(document)) { + aNode.setAttribute("disabled", "true"); + } else { + aNode.removeAttribute("disabled"); + } + }; + + let getPanel = () => { + let { PanelUI } = document.ownerGlobal; + return PanelUI.overflowPanel; + }; + + if ( + CustomizableUI.getAreaType(this.currentArea) == + CustomizableUI.TYPE_MENU_PANEL + ) { + getPanel().addEventListener("popupshowing", updateButton); + } + + let listener = { + onWidgetAdded: (aWidgetId, aArea) => { + if (aWidgetId != this.id) { + return; + } + if ( + CustomizableUI.getAreaType(aArea) == CustomizableUI.TYPE_MENU_PANEL + ) { + getPanel().addEventListener("popupshowing", updateButton); + } + }, + onWidgetRemoved: (aWidgetId, aPrevArea) => { + if (aWidgetId != this.id) { + return; + } + aNode.removeAttribute("disabled"); + if ( + CustomizableUI.getAreaType(aPrevArea) == + CustomizableUI.TYPE_MENU_PANEL + ) { + getPanel().removeEventListener("popupshowing", updateButton); + } + }, + onWidgetInstanceRemoved: (aWidgetId, aDoc) => { + if (aWidgetId != this.id || aDoc != document) { + return; + } + + CustomizableUI.removeListener(listener); + getPanel().removeEventListener("popupshowing", updateButton); + }, + }; + CustomizableUI.addListener(listener); + this.onInit(); + }, + onInit() { + this._inited = true; + if (!this.charsetInfo) { + this.charsetInfo = CharsetMenu.getData(); + } }, }, { diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index 2d47501e62b6..5b90353af5cb 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -139,6 +139,7 @@ skip-if = verify [browser_bookmarks_toolbar_collapsed_restore_default.js] [browser_bookmarks_toolbar_shown_newtab.js] [browser_bootstrapped_custom_toolbar.js] +[browser_character_encoding_ctrl_click.js] [browser_ctrl_click_panel_opening.js] [browser_currentset_post_reset.js] [browser_customizemode_contextmenu_menubuttonstate.js] diff --git a/browser/components/customizableui/test/browser_967000_button_charEncoding.js b/browser/components/customizableui/test/browser_967000_button_charEncoding.js index 806bf72924fa..15d28347c029 100644 --- a/browser/components/customizableui/test/browser_967000_button_charEncoding.js +++ b/browser/components/customizableui/test/browser_967000_button_charEncoding.js @@ -38,6 +38,11 @@ add_task(async function() { "The Character encoding button is initially disabled" ); + let panelHidePromise = promiseOverflowHidden(window); + document.getElementById("nav-bar").overflowable._panel.hidePopup(); + await panelHidePromise; + info("Panel hidden"); + let newTab = await BrowserTestUtils.openNewForegroundTab( gBrowser, TEST_PAGE, @@ -50,6 +55,42 @@ add_task(async function() { !charEncodingButton.hasAttribute("disabled"), "The Character encoding button gets enabled" ); + charEncodingButton.click(); + let characterEncodingView = document.getElementById( + "PanelUI-characterEncodingView" + ); + let subviewShownPromise = subviewShown(characterEncodingView); + await subviewShownPromise; + + ok( + characterEncodingView.hasAttribute("visible"), + "The Character encoding panel is displayed" + ); + + let pinnedEncodings = document.getElementById( + "PanelUI-characterEncodingView-pinned" + ); + let charsetsList = document.getElementById( + "PanelUI-characterEncodingView-charsets" + ); + ok(pinnedEncodings, "Pinned charsets are available"); + ok(charsetsList, "Charsets list is available"); + + let checkedButtons = characterEncodingView.querySelectorAll( + "toolbarbutton[checked='true']" + ); + is(checkedButtons.length, 1, "There should be 1 checked item."); + is( + checkedButtons[0].getAttribute("label"), + "Western", + "The western encoding is correctly selected" + ); + + panelHidePromise = promiseOverflowHidden(window); + document.getElementById("nav-bar").overflowable._panel.hidePopup(); + await panelHidePromise; + info("Panel hidden"); + BrowserTestUtils.removeTab(newTab); }); diff --git a/browser/components/customizableui/test/browser_969661_character_encoding_navbar_disabled.js b/browser/components/customizableui/test/browser_969661_character_encoding_navbar_disabled.js index a8810543c485..dc2b32cc5bbf 100644 --- a/browser/components/customizableui/test/browser_969661_character_encoding_navbar_disabled.js +++ b/browser/components/customizableui/test/browser_969661_character_encoding_navbar_disabled.js @@ -5,8 +5,7 @@ "use strict"; // Adding the character encoding menu to the panel, exiting customize mode, -// and moving it to the nav-bar should have it disabled if the page in the -// content area isn't eligible to have its encoding overridden. +// and moving it to the nav-bar should have it enabled, not disabled. add_task(async function() { await startCustomizing(); CustomizableUI.addWidgetToArea( @@ -20,7 +19,7 @@ add_task(async function() { await panelHiddenPromise; CustomizableUI.addWidgetToArea("characterencoding-button", "nav-bar"); let button = document.getElementById("characterencoding-button"); - ok(button.hasAttribute("disabled"), "Button should be disabled"); + ok(!button.hasAttribute("disabled"), "Button shouldn't be disabled"); }); add_task(function asyncCleanup() { diff --git a/browser/components/customizableui/test/browser_987640_charEncoding.js b/browser/components/customizableui/test/browser_987640_charEncoding.js index 1d43299dff5a..3e2a3b3ac9b3 100644 --- a/browser/components/customizableui/test/browser_987640_charEncoding.js +++ b/browser/components/customizableui/test/browser_987640_charEncoding.js @@ -27,14 +27,32 @@ add_task(async function() { await document.getElementById("nav-bar").overflowable.show(); let charEncodingButton = document.getElementById("characterencoding-button"); + charEncodingButton.click(); + let characterEncodingView = document.getElementById( + "PanelUI-characterEncodingView" + ); + let subviewShownPromise = subviewShown(characterEncodingView); + await subviewShownPromise; - ok( - !charEncodingButton.hasAttribute("disabled"), - "The encoding button should be enabled" + let checkedButtons = characterEncodingView.querySelectorAll( + "toolbarbutton[checked='true']" + ); + let initialEncoding = checkedButtons[0]; + is( + initialEncoding.getAttribute("label"), + "Western", + "The western encoding is initially selected" ); + // change the encoding + let encodings = characterEncodingView.querySelectorAll( + "toolbarbutton:not(.subviewbutton-back)" + ); + let newEncoding = encodings[1].hasAttribute("checked") + ? encodings[2] + : encodings[1]; let browserStopPromise = BrowserTestUtils.browserStopped(gBrowser, TEST_PAGE); - charEncodingButton.click(); + newEncoding.click(); await browserStopPromise; is( gBrowser.selectedBrowser.characterSet, @@ -46,10 +64,16 @@ add_task(async function() { "The encoding menu should be disabled" ); - is( - charEncodingButton.getAttribute("disabled"), - "true", - "We should disable the encoding button in toolbar" + // check that the new encodng is applied + await document.getElementById("nav-bar").overflowable.show(); + charEncodingButton.click(); + checkedButtons = characterEncodingView.querySelectorAll( + "toolbarbutton[checked='true']" + ); + let selectedEncodingName = checkedButtons[0].getAttribute("label"); + ok( + selectedEncodingName == "Unicode", + "The encoding was changed to " + selectedEncodingName ); CustomizableUI.removeWidgetFromArea("characterencoding-button"); @@ -65,7 +89,7 @@ add_task(async function() { is( charEncodingButton.getAttribute("disabled"), "true", - "We should disable the encoding button in overflow menu" + "We should disable the encoding menu" ); BrowserTestUtils.removeTab(newTab); diff --git a/browser/components/customizableui/test/browser_character_encoding_ctrl_click.js b/browser/components/customizableui/test/browser_character_encoding_ctrl_click.js new file mode 100644 index 000000000000..57f49f3db5ab --- /dev/null +++ b/browser/components/customizableui/test/browser_character_encoding_ctrl_click.js @@ -0,0 +1,27 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_character_encoding_menu() { + CustomizableUI.addWidgetToArea( + "characterencoding-button", + CustomizableUI.AREA_NAVBAR, + 4 + ); + + const button = document.getElementById("characterencoding-button"); + EventUtils.synthesizeMouseAtCenter(button, { ctrlKey: true }); + + const view = document.getElementById("PanelUI-characterEncodingView"); + let shownPromise = subviewShown(view); + await shownPromise; + ok(true, "Character encoding menu shown after button pressed"); + + // Close character encoding popup. + let hiddenPromise = subviewHidden(view); + view.closest("panel").hidePopup(); + await hiddenPromise; + + CustomizableUI.reset(); +}); diff --git a/browser/locales/en-US/browser/browser.ftl b/browser/locales/en-US/browser/browser.ftl index d6d54ac09ba6..6d15f768305c 100644 --- a/browser/locales/en-US/browser/browser.ftl +++ b/browser/locales/en-US/browser/browser.ftl @@ -680,12 +680,6 @@ save-to-pocket-button = .label = Save to { -pocket-brand-name } .tooltiptext = Save to { -pocket-brand-name } -## Repair text encoding toolbar button - -repair-text-encoding-button = - .label = Repair text encoding - .tooltiptext = Guess correct text encoding from page content - ## Customize Toolbar Buttons # Variables: diff --git a/browser/locales/en-US/browser/menubar.ftl b/browser/locales/en-US/browser/menubar.ftl index 3ca9add99f6b..f7b8f4522c5c 100644 --- a/browser/locales/en-US/browser/menubar.ftl +++ b/browser/locales/en-US/browser/menubar.ftl @@ -166,8 +166,8 @@ menu-view-page-style-no-style = menu-view-page-basic-style = .label = Basic Page Style .accesskey = B -menu-view-repair-text-encoding = - .label = Repair Text Encoding +menu-view-charset = + .label = Text Encoding .accesskey = c ## These should match what Safari and other Apple applications diff --git a/browser/locales/en-US/chrome/browser/customizableui/customizableWidgets.properties b/browser/locales/en-US/chrome/browser/customizableui/customizableWidgets.properties index 1765cce88139..a767c36b29a4 100644 --- a/browser/locales/en-US/chrome/browser/customizableui/customizableWidgets.properties +++ b/browser/locales/en-US/chrome/browser/customizableui/customizableWidgets.properties @@ -64,6 +64,12 @@ paste-button.label = Paste # LOCALIZATION NOTE(paste-button.tooltiptext2): %S is the keyboard shortcut. paste-button.tooltiptext2 = Paste (%S) +# LOCALIZATION NOTE (characterencoding-button2.label): The \u00ad text at the beginning +# of the string is used to disable auto hyphenation on the button text when it is displayed +# in the menu panel. +characterencoding-button2.label = \u00adText Encoding +characterencoding-button2.tooltiptext = Show text encoding options + email-link-button.label = Email Link email-link-button.tooltiptext3 = Email a link to this page diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index c3fbbb6cef71..675d32bbb15c 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -689,41 +689,7 @@ bool nsHTMLDocument::WillIgnoreCharsetOverride() { return true; } } - - switch (mCharacterSetSource) { - case kCharsetUninitialized: - case kCharsetFromFallback: - case kCharsetFromTopLevelDomain: - case kCharsetFromDocTypeDefault: - case kCharsetFromInitialAutoDetectionWouldHaveBeenUTF8: - case kCharsetFromInitialAutoDetectionWouldNotHaveBeenUTF8DependedOnTLD: - case kCharsetFromFinalJapaneseAutoDetection: - case kCharsetFromFinalAutoDetectionWouldHaveBeenUTF8: - case kCharsetFromFinalAutoDetectionWouldNotHaveBeenUTF8DependedOnTLD: - case kCharsetFromParentFrame: - case kCharsetFromXmlDeclaration: - case kCharsetFromMetaPrescan: - case kCharsetFromMetaTag: - case kCharsetFromChannel: - case kCharsetFromUserForced: - case kCharsetFromUserForcedJapaneseAutoDetection: - return false; - } - - bool potentialEffect = false; - nsIPrincipal* parentPrincipal = NodePrincipal(); - - auto subDoc = [&potentialEffect, parentPrincipal](Document& aSubDoc) { - if (parentPrincipal->Equals(aSubDoc.NodePrincipal()) && - !aSubDoc.WillIgnoreCharsetOverride()) { - potentialEffect = true; - return CallState::Stop; - } - return CallState::Continue; - }; - EnumerateSubDocuments(subDoc); - - return !potentialEffect; + return false; } void nsHTMLDocument::GetFormsAndFormControls(nsContentList** aFormList, diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index cc748fc3625b..313fb6a36282 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -63,7 +63,6 @@ skip-if = true # bug 1399845 tracks re-enabling this test. [browser_bug1693577.js] [browser_cancel_starting_autoscrolling_requested_by_background_tab.js] [browser_charsetMenu_swapBrowsers.js] -[browser_charsetMenu_disable_on_ascii.js] [browser_click_event_during_autoscrolling.js] skip-if = !e10s [browser_content_url_annotation.js] diff --git a/toolkit/content/tests/browser/browser_charsetMenu_disable_on_ascii.js b/toolkit/content/tests/browser/browser_charsetMenu_disable_on_ascii.js deleted file mode 100644 index 2982a6314124..000000000000 --- a/toolkit/content/tests/browser/browser_charsetMenu_disable_on_ascii.js +++ /dev/null @@ -1,18 +0,0 @@ -/* Test that the charset menu is properly enabled when swapping browsers. */ -add_task(async function test() { - function charsetMenuEnabled() { - return !document - .getElementById("repair-text-encoding") - .hasAttribute("disabled"); - } - - const PAGE = "data:text/html,ASCII-only"; - let tab = await BrowserTestUtils.openNewForegroundTab({ - gBrowser, - url: PAGE, - waitForStateStop: true, - }); - ok(!charsetMenuEnabled(), "should have a charset menu here"); - - BrowserTestUtils.removeTab(tab); -}); diff --git a/toolkit/content/tests/browser/browser_charsetMenu_swapBrowsers.js b/toolkit/content/tests/browser/browser_charsetMenu_swapBrowsers.js index 9ea8fccf290a..8eda01de8e08 100644 --- a/toolkit/content/tests/browser/browser_charsetMenu_swapBrowsers.js +++ b/toolkit/content/tests/browser/browser_charsetMenu_swapBrowsers.js @@ -1,22 +1,17 @@ /* Test that the charset menu is properly enabled when swapping browsers. */ add_task(async function test() { + // NB: This test cheats and calls updateCharacterEncodingMenuState directly + // instead of opening the "View" menu. function charsetMenuEnabled() { - return !document - .getElementById("repair-text-encoding") - .hasAttribute("disabled"); + updateCharacterEncodingMenuState(); + return !document.getElementById("charsetMenu").hasAttribute("disabled"); } - const PAGE = - "data:text/html;charset=windows-1252,hello %e4"; + const PAGE = "data:text/html,hello"; let tab1 = await BrowserTestUtils.openNewForegroundTab({ gBrowser, url: PAGE, }); - await BrowserTestUtils.waitForMutationCondition( - document.getElementById("repair-text-encoding"), - { attributes: true }, - charsetMenuEnabled - ); ok(charsetMenuEnabled(), "should have a charset menu here"); let tab2 = await BrowserTestUtils.openNewForegroundTab({ gBrowser });