Merge inbound to mozilla-central a=merge

This commit is contained in:
Coroiu Cristina 2018-04-23 12:59:31 +03:00
Родитель b52121beb6 94dd5a92a4
Коммит 8f06c1b9a0
16 изменённых файлов: 299 добавлений и 29 удалений

Просмотреть файл

@ -1268,6 +1268,8 @@ var gBrowserInit = {
remoteType, sameProcessAsFrameLoader
});
BrowserSearch.initPlaceHolder();
// Hack to ensure that the about:home favicon is loaded
// instantaneously, to avoid flickering and improve perceived performance.
this._callWithURIToLoad(uriToLoad => {
@ -1463,6 +1465,7 @@ var gBrowserInit = {
UpdateUrlbarSearchSplitterState();
BookmarkingUI.init();
BrowserSearch.delayedStartupInit();
AutoShowBookmarksToolbar.init();
Services.prefs.addObserver(gHomeButton.prefDomain, gHomeButton);
@ -3765,10 +3768,25 @@ const DOMEventHandler = {
};
const BrowserSearch = {
_searchInitComplete: false,
init() {
Services.obs.addObserver(this, "browser-search-engine-modified");
},
delayedStartupInit() {
// Asynchronously initialize the search service if necessary, to get the
// current engine for working out the placeholder.
Services.search.init(rv => {
if (Components.isSuccessCode(rv)) {
// Delay the update for this until so that we don't change it while
// the user is looking at it / isn't expecting it.
this._updateURLBarPlaceholder(Services.search.currentEngine, true);
this._searchInitComplete = true;
}
});
},
uninit() {
Services.obs.removeObserver(this, "browser-search-engine-modified");
},
@ -3795,6 +3813,11 @@ const BrowserSearch = {
// browser's offered engines.
this._removeMaybeOfferedEngine(engineName);
break;
case "engine-current":
if (this._searchInitComplete) {
this._updateURLBarPlaceholder(engine);
}
break;
}
},
@ -3842,6 +3865,88 @@ const BrowserSearch = {
}
},
/**
* Initializes the urlbar placeholder to the pre-saved engine name. We do this
* via a preference, to avoid needing to synchronously init the search service.
*
* This should be called around the time of DOMContentLoaded, so that it is
* initialized quickly before the user sees anything.
*
* Note: If the preference doesn't exist, we don't do anything as the default
* placeholder is a string which doesn't have the engine name.
*/
initPlaceHolder() {
let engineName = Services.prefs.getStringPref("browser.urlbar.placeholderName", "");
if (engineName) {
// We can do this directly, since we know we're at DOMContentLoaded.
this._setURLBarPlaceholder(engineName);
}
},
/**
* Updates the URLBar placeholder for the specified engine, delaying the
* update if required. This also saves the current engine name in preferences
* for the next restart.
*
* Note: The engine name will only be displayed for built-in engines, as we
* know they should have short names.
*
* @param {nsISearchEngine} engine The search engine to use for the update.
* @param {Boolean} delayUpdate Set to true, to delay update until the
* placeholder is not displayed.
*/
_updateURLBarPlaceholder(engine, delayUpdate = false) {
if (!engine) {
throw new Error("Expected an engine to be specified");
}
let engineName = "";
if (Services.search.getDefaultEngines().includes(engine)) {
engineName = engine.name;
Services.prefs.setStringPref("browser.urlbar.placeholderName", engineName);
} else {
Services.prefs.clearUserPref("browser.urlbar.placeholderName");
}
// Only delay if requested, and we're not displaying text in the URL bar
// currently.
if (delayUpdate && !gURLBar.value) {
// Delays changing the URL Bar placeholder until the user is not going to be
// seeing it, e.g. when there is a value entered in the bar, or if there is
// a tab switch to a tab which has a url loaded.
let placeholderUpdateListener = () => {
if (gURLBar.value) {
this._setURLBarPlaceholder(engineName);
gURLBar.removeEventListener("input", placeholderUpdateListener);
gBrowser.tabContainer.removeEventListener("TabSelect", placeholderUpdateListener);
}
};
gURLBar.addEventListener("input", placeholderUpdateListener);
gBrowser.tabContainer.addEventListener("TabSelect", placeholderUpdateListener);
} else {
this._setURLBarPlaceholder(engineName);
}
},
/**
* Sets the URLBar placeholder to either something based on the engine name,
* or the default placeholder.
*
* @param {String} name The name of the engine to use, an empty string if to
* use the default placeholder.
*/
_setURLBarPlaceholder(name) {
let placeholder;
if (name) {
placeholder = gBrowserBundle.formatStringFromName("urlbar.placeholder",
[name], 1);
} else {
placeholder = gURLBar.getAttribute("defaultPlaceholder");
}
gURLBar.setAttribute("placeholder", placeholder);
},
addEngine(browser, engine, uri) {
// Check to see whether we've already added an engine with this title
if (browser.engines) {

Просмотреть файл

@ -777,6 +777,7 @@
class="chromeclass-location" overflows="false">
<textbox id="urlbar" flex="1"
placeholder="&urlbar.placeholder2;"
defaultPlaceholder="&urlbar.placeholder2;"
focused="true"
type="autocomplete"
autocompletesearch="unifiedcomplete"

Просмотреть файл

@ -92,6 +92,10 @@ support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
[browser_urlbarOneOffs_searchSuggestions.js]
support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
[browser_urlbarPlaceholder.js]
support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs

Просмотреть файл

@ -0,0 +1,93 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This test ensures the placeholder is set correctly for different search
* engines.
*/
"use strict";
const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
const originalEngine = Services.search.currentEngine;
const expectedString = gBrowserBundle.formatStringFromName("urlbar.placeholder",
[originalEngine.name], 1);
var extraEngine;
var tabs = [];
add_task(async function setup() {
extraEngine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME);
// Force display of a tab with a URL bar, to clear out any possible placeholder
// initialization listeners that happen on startup.
let urlTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
BrowserTestUtils.removeTab(urlTab);
registerCleanupFunction(() => {
Services.search.currentEngine = originalEngine;
for (let tab of tabs) {
BrowserTestUtils.removeTab(tab);
}
});
});
add_task(async function test_change_default_engine_updates_placeholder() {
tabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser));
Services.search.currentEngine = extraEngine;
await TestUtils.waitForCondition(
() => gURLBar.getAttribute("placeholder") == gURLBar.getAttribute("defaultPlaceholder"),
"The placeholder should match the default placeholder for non-built-in engines.");
Services.search.currentEngine = originalEngine;
await TestUtils.waitForCondition(
() => gURLBar.getAttribute("placeholder") == expectedString,
"The placeholder should include the engine name for built-in engines.");
});
add_task(async function test_delayed_update_placeholder() {
// Since we can't easily test for startup changes, we'll at least test the delay
// of update for the placeholder works.
let urlTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:mozilla");
tabs.push(urlTab);
// Open a tab with a blank URL bar.
let blankTab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
tabs.push(blankTab);
// Pretend we've "initialized".
BrowserSearch._updateURLBarPlaceholder(extraEngine, true);
Assert.equal(gURLBar.getAttribute("placeholder"), expectedString,
"Placeholder should be unchanged.");
// Now switch to a tab with something in the URL Bar.
await BrowserTestUtils.switchTab(gBrowser, urlTab);
await TestUtils.waitForCondition(
() => gURLBar.getAttribute("placeholder") == gURLBar.getAttribute("defaultPlaceholder"),
"The placeholder should have updated in the background.");
// Do it the other way to check both named engine and fallback code paths.
await BrowserTestUtils.switchTab(gBrowser, blankTab);
BrowserSearch._updateURLBarPlaceholder(originalEngine, true);
Assert.equal(gURLBar.getAttribute("placeholder"), gURLBar.getAttribute("defaultPlaceholder"),
"Placeholder should be unchanged.");
await BrowserTestUtils.switchTab(gBrowser, urlTab);
await TestUtils.waitForCondition(
() => gURLBar.getAttribute("placeholder") == expectedString,
"The placeholder should include the engine name for built-in engines.");
// Now check when we have a URL displayed, the placeholder is updated straight away.
BrowserSearch._updateURLBarPlaceholder(extraEngine);
Assert.equal(gURLBar.getAttribute("placeholder"), gURLBar.getAttribute("defaultPlaceholder"),
"Placeholder should be the default.");
});

Просмотреть файл

@ -434,7 +434,6 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY openCmd.commandkey "l">
<!ENTITY urlbar.placeholder2 "Search or enter address">
<!ENTITY urlbar.placeholder3 "Enter search terms and addresses here">
<!ENTITY urlbar.accesskey "d">
<!-- LOCALIZATION NOTE (urlbar.extension.label): Used to indicate that a selected autocomplete entry is provided by an extension. -->
<!ENTITY urlbar.extension.label "Extension:">

Просмотреть файл

@ -337,14 +337,14 @@ var Scratchpad = {
* Hide the menu bar.
*/
hideMenu: function SP_hideMenu() {
document.getElementById("sp-menubar").style.display = "none";
document.getElementById("sp-menu-toolbar").style.display = "none";
},
/**
* Show the menu bar.
*/
showMenu: function SP_showMenu() {
document.getElementById("sp-menubar").style.display = "";
document.getElementById("sp-menu-toolbar").style.display = "";
},
/**

Просмотреть файл

@ -141,8 +141,8 @@
</keyset>
<toolbar type="menubar">
<menubar id="sp-menubar">
<toolbar type="menubar" id="sp-menu-toolbar">
<menubar>
<menu id="sp-file-menu" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
<menupopup id="sp-menu-filepopup">
<menuitem id="sp-menu-newscratchpad"

Просмотреть файл

@ -45,3 +45,4 @@ support-files = NS_ERROR_ILLEGAL_INPUT.txt
[browser_scratchpad_close_toolbox.js]
[browser_scratchpad_remember_view_options.js]
[browser_scratchpad_disable_view_menu_items.js]
[browser_scratchpad_menubar.js]

Просмотреть файл

@ -0,0 +1,36 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Sanity test that menu bar is displayed. If open the scratchpad as toolbox panel,
// this menu should be hidden.
var {TargetFactory} = require("devtools/client/framework/target");
add_task(async function() {
// Now open the scratchpad as window.
info("Test existence of menu bar of scratchpad.");
const options = {
tabContent: "Sanity test for scratchpad panel."
};
info("Open scratchpad.");
let [win] = await openTabAndScratchpad(options);
let menuToolbar = win.document.getElementById("sp-menu-toolbar");
ok(menuToolbar, "The scratchpad should have a menu bar.");
});
add_task(async function() {
// Now open the scratchpad panel after setting visibility preference.
info("Test existence of menu bar of scratchpad panel.");
await new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [["devtools.scratchpad.enabled", true]]}, resolve);
});
info("Open devtools on the Scratchpad.");
let target = TargetFactory.forTab(gBrowser.selectedTab);
let toolbox = await gDevTools.showToolbox(target, "scratchpad");
let menuToolbar = toolbox.doc.getElementById("sp-menu-toolbar");
ok(!menuToolbar, "The scratchpad panel should not have a menu bar.");
});

Просмотреть файл

@ -234,6 +234,16 @@ public:
return mParent && mParent->IsText();
}
/**
* IsInNativeAnonymousSubtree() returns true if the container is in
* native anonymous subtree.
*/
bool
IsInNativeAnonymousSubtree() const
{
return mParent && mParent->IsInNativeAnonymousSubtree();
}
/**
* IsContainerHTMLElement() returns true if the container node is an HTML
* element node and its node name is aTag.
@ -531,6 +541,33 @@ public:
return true;
}
/**
* GetNonAnonymousSubtreePoint() returns a DOM point which is NOT in
* native-anonymous subtree. If the instance isn't in native-anonymous
* subtree, this returns same point. Otherwise, climbs up until finding
* non-native-anonymous parent and returns the point of it. I.e.,
* container is parent of the found non-anonymous-native node.
*/
EditorRawDOMPoint
GetNonAnonymousSubtreePoint() const
{
if (NS_WARN_IF(!IsSet())) {
return EditorRawDOMPoint();
}
if (!IsInNativeAnonymousSubtree()) {
return EditorRawDOMPoint(*this);
}
nsINode* parent;
for (parent = mParent->GetParentNode();
parent && parent->IsInNativeAnonymousSubtree();
parent = mParent->GetParentNode()) {
}
if (!parent) {
return EditorRawDOMPoint();
}
return EditorRawDOMPoint(parent);
}
bool
IsSet() const
{

Просмотреть файл

@ -1459,14 +1459,20 @@ HTMLEditor::GetBetterInsertionPointFor(nsINode& aNodeToInsert,
return aPointToInsert;
}
EditorRawDOMPoint pointToInsert(aPointToInsert.GetNonAnonymousSubtreePoint());
if (NS_WARN_IF(!pointToInsert.IsSet())) {
// Cannot insert aNodeToInsert into this DOM tree.
return EditorRawDOMPoint();
}
// If the node to insert is not a block level element, we can insert it
// at any point.
if (!IsBlockNode(&aNodeToInsert)) {
return aPointToInsert;
return pointToInsert;
}
WSRunObject wsObj(this, aPointToInsert.GetContainer(),
aPointToInsert.Offset());
WSRunObject wsObj(this, pointToInsert.GetContainer(),
pointToInsert.Offset());
// If the insertion position is after the last visible item in a line,
// i.e., the insertion position is just before a visible line break <br>,
@ -1474,13 +1480,13 @@ HTMLEditor::GetBetterInsertionPointFor(nsINode& aNodeToInsert,
nsCOMPtr<nsINode> nextVisibleNode;
int32_t nextVisibleOffset = 0;
WSType nextVisibleType;
wsObj.NextVisibleNode(aPointToInsert, address_of(nextVisibleNode),
wsObj.NextVisibleNode(pointToInsert, address_of(nextVisibleNode),
&nextVisibleOffset, &nextVisibleType);
// So, if the next visible node isn't a <br> element, we can insert the block
// level element to the point.
if (!nextVisibleNode ||
!(nextVisibleType & WSType::br)) {
return aPointToInsert;
return pointToInsert;
}
// However, we must not skip next <br> element when the caret appears to be
@ -1490,7 +1496,7 @@ HTMLEditor::GetBetterInsertionPointFor(nsINode& aNodeToInsert,
nsCOMPtr<nsINode> previousVisibleNode;
int32_t previousVisibleOffset = 0;
WSType previousVisibleType;
wsObj.PriorVisibleNode(aPointToInsert, address_of(previousVisibleNode),
wsObj.PriorVisibleNode(pointToInsert, address_of(previousVisibleNode),
&previousVisibleOffset, &previousVisibleType);
// So, if there is no previous visible node,
// or, if both nodes of the insertion point is <br> elements,
@ -1500,7 +1506,7 @@ HTMLEditor::GetBetterInsertionPointFor(nsINode& aNodeToInsert,
if (!previousVisibleNode ||
(previousVisibleType & WSType::br) ||
(previousVisibleType & WSType::thisBlock)) {
return aPointToInsert;
return pointToInsert;
}
EditorRawDOMPoint afterBRNode(nextVisibleNode);

Просмотреть файл

@ -43,8 +43,6 @@ struct CSSAnonBoxAtoms
const nsICSSAnonBoxPseudo mAtoms[static_cast<size_t>(Atoms::AtomsCount)];
};
extern const CSSAnonBoxAtoms gCSSAnonBoxAtoms;
} // namespace detail
} // namespace mozilla
@ -66,7 +64,7 @@ public:
private:
static const nsStaticAtom* const sAtoms;
static constexpr size_t sAtomsLen =
mozilla::ArrayLength(mozilla::detail::gCSSAnonBoxAtoms.mAtoms);
static_cast<size_t>(mozilla::detail::CSSAnonBoxAtoms::Atoms::AtomsCount);
public:
#define CSS_ANON_BOX(name_, value_) \

Просмотреть файл

@ -110,8 +110,6 @@ struct CSSPseudoElementAtoms
const nsICSSPseudoElement mAtoms[static_cast<size_t>(Atoms::AtomsCount)];
};
extern const CSSPseudoElementAtoms gCSSPseudoElementAtoms;
} // namespace detail
} // namespace mozilla
@ -139,7 +137,7 @@ public:
private:
static const nsStaticAtom* const sAtoms;
static constexpr size_t sAtomsLen =
mozilla::ArrayLength(mozilla::detail::gCSSPseudoElementAtoms.mAtoms);
static_cast<size_t>(mozilla::detail::CSSPseudoElementAtoms::Atoms::AtomsCount);
public:
#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \

Просмотреть файл

@ -29,8 +29,6 @@ struct GkAtoms
const nsStaticAtom mAtoms[static_cast<size_t>(Atoms::AtomsCount)];
};
extern const GkAtoms gGkAtoms;
} // namespace detail
} // namespace mozilla
@ -39,7 +37,7 @@ class nsGkAtoms
private:
static const nsStaticAtom* const sAtoms;
static constexpr size_t sAtomsLen =
mozilla::ArrayLength(mozilla::detail::gGkAtoms.mAtoms);
static_cast<size_t>(mozilla::detail::GkAtoms::Atoms::AtomsCount);
public:
static void RegisterStaticAtoms();

Просмотреть файл

@ -96,10 +96,6 @@
// const nsStaticAtom mAtoms[static_cast<size_t>(Atoms::AtomsCount)];
// };
//
// // The MyAtoms instance is `extern const` so it can be defined in a .cpp
// // file.
// extern const MyAtoms gMyAtoms;
//
// } // namespace detail
//
// // This class holds the pointers to the individual atoms.
@ -112,7 +108,7 @@
//
// // The number of atoms, used below.
// static constexpr size_t sAtomsLen =
// mozilla::ArrayLength(detail::gMyAtoms.mAtoms);
// static_cast<size_t>(detail::MyAtoms::Atoms::AtomsCount);
//
// public:
// // The type is not `nsStaticAtom* const` -- even though these atoms are

Просмотреть файл

@ -40,8 +40,6 @@ struct DirectoryAtoms
const nsStaticAtom mAtoms[static_cast<size_t>(Atoms::AtomsCount)];
};
extern const DirectoryAtoms gDirectoryAtoms;
} // namespace detail
} // namespace mozilla
@ -81,7 +79,7 @@ private:
static const nsStaticAtom* const sAtoms;
static constexpr size_t sAtomsLen =
mozilla::ArrayLength(mozilla::detail::gDirectoryAtoms.mAtoms);
static_cast<size_t>(mozilla::detail::DirectoryAtoms::Atoms::AtomsCount);
public:
#define DIR_ATOM(name_, value_) NS_STATIC_ATOM_DECL_PTR(nsStaticAtom, name_)