mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Bug 1426494 - Share more code between nsIDocument and ShadowRoot
Tag #1375
This commit is contained in:
parent
15f6d2efda
commit
db72493615
23 changed files with 369 additions and 335 deletions
104
dom/base/DocumentOrShadowRoot.cpp
Normal file
104
dom/base/DocumentOrShadowRoot.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "DocumentOrShadowRoot.h"
|
||||
#include "mozilla/dom/StyleSheetList.h"
|
||||
#include "ShadowRoot.h"
|
||||
#include "XULDocument.h"
|
||||
|
||||
class nsINode;
|
||||
class nsIDocument;
|
||||
class ShadowRoot;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
DocumentOrShadowRoot::DocumentOrShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot)
|
||||
: mAsNode(aShadowRoot)
|
||||
, mKind(Kind::ShadowRoot)
|
||||
{
|
||||
MOZ_ASSERT(mAsNode);
|
||||
}
|
||||
|
||||
DocumentOrShadowRoot::DocumentOrShadowRoot(nsIDocument* aDoc)
|
||||
: mAsNode(aDoc)
|
||||
, mKind(Kind::Document)
|
||||
{
|
||||
MOZ_ASSERT(mAsNode);
|
||||
}
|
||||
|
||||
StyleSheetList&
|
||||
DocumentOrShadowRoot::EnsureDOMStyleSheets()
|
||||
{
|
||||
if (!mDOMStyleSheets) {
|
||||
mDOMStyleSheets = new StyleSheetList(*this);
|
||||
}
|
||||
return *mDOMStyleSheets;
|
||||
}
|
||||
|
||||
Element*
|
||||
DocumentOrShadowRoot::GetElementById(const nsAString& aElementId)
|
||||
{
|
||||
if (MOZ_UNLIKELY(aElementId.IsEmpty())) {
|
||||
nsContentUtils::ReportEmptyGetElementByIdArg(AsNode().OwnerDoc());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (nsIdentifierMapEntry* entry = mIdentifierMap.GetEntry(aElementId)) {
|
||||
if (Element* el = entry->GetIdElement()) {
|
||||
return el;
|
||||
}
|
||||
}
|
||||
|
||||
if (MOZ_UNLIKELY(mKind == Kind::Document &&
|
||||
static_cast<nsIDocument&>(AsNode()).IsXULDocument())) {
|
||||
return static_cast<XULDocument&>(AsNode()).GetRefById(aElementId);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<nsContentList>
|
||||
DocumentOrShadowRoot::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aLocalName)
|
||||
{
|
||||
ErrorResult rv;
|
||||
RefPtr<nsContentList> list =
|
||||
GetElementsByTagNameNS(aNamespaceURI, aLocalName, rv);
|
||||
if (rv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
return list.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsContentList>
|
||||
DocumentOrShadowRoot::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aLocalName,
|
||||
mozilla::ErrorResult& aResult)
|
||||
{
|
||||
int32_t nameSpaceId = kNameSpaceID_Wildcard;
|
||||
|
||||
if (!aNamespaceURI.EqualsLiteral("*")) {
|
||||
aResult =
|
||||
nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
|
||||
nameSpaceId);
|
||||
if (aResult.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(nameSpaceId != kNameSpaceID_Unknown, "Unexpected namespace ID!");
|
||||
return NS_GetContentList(&AsNode(), nameSpaceId, aLocalName);
|
||||
}
|
||||
|
||||
already_AddRefed<nsContentList>
|
||||
DocumentOrShadowRoot::GetElementsByClassName(const nsAString& aClasses)
|
||||
{
|
||||
return nsContentUtils::GetElementsByClassName(&AsNode(), aClasses);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue