зеркало из https://github.com/mozilla/gecko-dev.git
Bug 811259 - Patch1: Implement Element.insertAdjacentText and Element.insertAdjacentElement. r=smaug
MozReview-Commit-ID: g54gUOBop7 --HG-- extra : rebase_source : 20d748bed16589a3d91c91711f3607888dd08801
This commit is contained in:
Родитель
5d4511e5b1
Коммит
ad2c3f5c70
|
@ -3646,6 +3646,53 @@ Element::InsertAdjacentHTML(const nsAString& aPosition, const nsAString& aText,
|
|||
}
|
||||
}
|
||||
|
||||
nsINode*
|
||||
Element::InsertAdjacent(const nsAString& aWhere,
|
||||
nsINode* aNode,
|
||||
ErrorResult& aError)
|
||||
{
|
||||
if (aWhere.LowerCaseEqualsLiteral("beforebegin")) {
|
||||
nsCOMPtr<nsINode> parent = GetParentNode();
|
||||
if (!parent) {
|
||||
return nullptr;
|
||||
}
|
||||
parent->InsertBefore(*aNode, this, aError);
|
||||
} else if (aWhere.LowerCaseEqualsLiteral("afterbegin")) {
|
||||
static_cast<nsINode*>(this)->InsertBefore(*aNode, GetFirstChild(), aError);
|
||||
} else if (aWhere.LowerCaseEqualsLiteral("beforeend")) {
|
||||
static_cast<nsINode*>(this)->AppendChild(*aNode, aError);
|
||||
} else if (aWhere.LowerCaseEqualsLiteral("afterend")) {
|
||||
nsCOMPtr<nsINode> parent = GetParentNode();
|
||||
if (!parent) {
|
||||
return nullptr;
|
||||
}
|
||||
parent->InsertBefore(*aNode, GetNextSibling(), aError);
|
||||
} else {
|
||||
aError.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return aError.Failed() ? nullptr : aNode;
|
||||
}
|
||||
|
||||
Element*
|
||||
Element::InsertAdjacentElement(const nsAString& aWhere,
|
||||
Element& aElement,
|
||||
ErrorResult& aError) {
|
||||
nsINode* newNode = InsertAdjacent(aWhere, &aElement, aError);
|
||||
MOZ_ASSERT(!newNode || newNode->IsElement());
|
||||
|
||||
return newNode ? newNode->AsElement() : nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
Element::InsertAdjacentText(
|
||||
const nsAString& aWhere, const nsAString& aData, ErrorResult& aError)
|
||||
{
|
||||
RefPtr<nsTextNode> textNode = OwnerDoc()->CreateTextNode(aData);
|
||||
InsertAdjacent(aWhere, textNode, aError);
|
||||
}
|
||||
|
||||
nsIEditor*
|
||||
Element::GetEditorInternal()
|
||||
{
|
||||
|
|
|
@ -679,6 +679,26 @@ public:
|
|||
ErrorResult& aError);
|
||||
already_AddRefed<nsIHTMLCollection>
|
||||
GetElementsByClassName(const nsAString& aClassNames);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Implement the algorithm specified at
|
||||
* https://dom.spec.whatwg.org/#insert-adjacent for both
|
||||
* |insertAdjacentElement()| and |insertAdjacentText()| APIs.
|
||||
*/
|
||||
nsINode* InsertAdjacent(const nsAString& aWhere,
|
||||
nsINode* aNode,
|
||||
ErrorResult& aError);
|
||||
|
||||
public:
|
||||
Element* InsertAdjacentElement(const nsAString& aWhere,
|
||||
Element& aElement,
|
||||
ErrorResult& aError);
|
||||
|
||||
void InsertAdjacentText(const nsAString& aWhere,
|
||||
const nsAString& aData,
|
||||
ErrorResult& aError);
|
||||
|
||||
void SetPointerCapture(int32_t aPointerId, ErrorResult& aError)
|
||||
{
|
||||
bool activeState = false;
|
||||
|
|
|
@ -71,6 +71,12 @@ interface Element : Node {
|
|||
[Pure]
|
||||
HTMLCollection getElementsByClassName(DOMString classNames);
|
||||
|
||||
[Throws, Pure]
|
||||
Element? insertAdjacentElement(DOMString where, Element element); // historical
|
||||
|
||||
[Throws]
|
||||
void insertAdjacentText(DOMString where, DOMString data); // historical
|
||||
|
||||
/**
|
||||
* The ratio of font-size-inflated text font size to computed font
|
||||
* size for this element. This will query the element for its primary frame,
|
||||
|
|
Загрузка…
Ссылка в новой задаче