Bug 1455649 - DocumentL10n, part 3 - Plug DocumentL10n life cycle into DOM hooks.
Adds hooks to XULDocument, HTMLLinkElement etc. to trigger DocumentL10n lifecycle.
MozReview-Commit-ID: JpPSWHkl558
--- a/dom/html/HTMLLinkElement.cpp
+++ b/dom/html/HTMLLinkElement.cpp
@@ -141,16 +141,24 @@ HTMLLinkElement::BindToTree(nsIDocument*
doc->RegisterPendingLinkUpdate(this);
TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender();
}
void (HTMLLinkElement::*update)() = &HTMLLinkElement::UpdateStyleSheetInternal;
nsContentUtils::AddScriptRunner(
NewRunnableMethod("dom::HTMLLinkElement::BindToTree", this, update));
+ if (aDocument) {
+ nsAutoString rel;
+ GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
+ if (rel.EqualsLiteral("localization")) {
+ aDocument->LocalizationLinkAdded(this);
+ }
+ }
+
CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded"));
return rv;
}
void
HTMLLinkElement::LinkAdded()
{
@@ -177,16 +185,23 @@ HTMLLinkElement::UnbindFromTree(bool aDe
// be under a different xml:base, so forget the cached state now.
Link::ResetLinkState(false, Link::ElementHasHref());
// If this is reinserted back into the document it will not be
// from the parser.
nsIDocument* oldDoc = GetUncomposedDoc();
ShadowRoot* oldShadowRoot = GetContainingShadow();
+ if (oldDoc) {
+ nsAutoString rel;
+ GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
+ if (rel.EqualsLiteral("localization"))
+ oldDoc->LocalizationLinkRemoved(this);
+ }
+
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
Unused << UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
}
bool
HTMLLinkElement::ParseAttribute(int32_t aNamespaceID,
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1158,16 +1158,18 @@ XULDocument::AddElementToDocumentPost(El
if (aElement == GetRootElement()) {
ResetDocumentDirection();
}
// We need to pay special attention to the keyset tag to set up a listener
if (aElement->NodeInfo()->Equals(nsGkAtoms::keyset, kNameSpaceID_XUL)) {
// Create our XUL key listener and hook it up.
nsXBLService::AttachGlobalKeyHandler(aElement);
+ } else if (aElement->IsXULElement(nsGkAtoms::linkset)) {
+ OnL10nResourceContainerParsed();
}
return NS_OK;
}
nsresult
XULDocument::AddSubtreeToDocument(nsIContent* aContent)
{
@@ -1964,16 +1966,18 @@ XULDocument::DoneWalking()
NotifyPossibleTitleChange(false);
nsContentUtils::DispatchTrustedEvent(
this,
static_cast<nsIDocument*>(this),
NS_LITERAL_STRING("MozBeforeInitialXULLayout"),
CanBubble::eYes,
Cancelable::eNo);
+ OnL10nResourceContainerParsed();
+ OnDocumentParsed();
// Before starting layout, check whether we're a toplevel chrome
// window. If we are, setup some state so that we don't have to restyle
// the whole tree after StartLayout.
if (nsCOMPtr<nsIXULWindow> win = GetXULWindowIfToplevelChrome()) {
// We're the chrome document!
win->BeforeStartLayout();
}