From 4018b56c7cbe5d63cc3728179346066977e203af Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 1 Aug 2017 23:20:42 -0400 Subject: [PATCH] Bug 1386485 - Part 4: Devirtualize and inline EditorBase::IsEditable(); r=masayuki --- editor/libeditor/EditorBase.cpp | 19 ------------------- editor/libeditor/EditorBase.h | 22 +++++++++++++++++++++- editor/libeditor/HTMLEditor.cpp | 15 --------------- editor/libeditor/HTMLEditor.h | 1 - 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp index fe83f808ad8d..88372a78c50e 100644 --- a/editor/libeditor/EditorBase.cpp +++ b/editor/libeditor/EditorBase.cpp @@ -3578,25 +3578,6 @@ EditorBase::IsEditable(nsIDOMNode* aNode) return IsEditable(content); } -bool -EditorBase::IsEditable(nsINode* aNode) -{ - NS_ENSURE_TRUE(aNode, false); - - if (!aNode->IsNodeOfType(nsINode::eCONTENT) || IsMozEditorBogusNode(aNode) || - !IsModifiableNode(aNode)) { - return false; - } - - switch (aNode->NodeType()) { - case nsIDOMNode::ELEMENT_NODE: - case nsIDOMNode::TEXT_NODE: - return true; - default: - return false; - } -} - uint32_t EditorBase::CountEditableChildren(nsINode* aNode) { diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h index faa3c75309a8..a927e9d5514f 100644 --- a/editor/libeditor/EditorBase.h +++ b/editor/libeditor/EditorBase.h @@ -765,7 +765,27 @@ public: * returns true if aNode is an editable node. */ bool IsEditable(nsIDOMNode* aNode); - virtual bool IsEditable(nsINode* aNode); + bool IsEditable(nsINode* aNode) + { + NS_ENSURE_TRUE(aNode, false); + + if (!aNode->IsNodeOfType(nsINode::eCONTENT) || IsMozEditorBogusNode(aNode) || + !IsModifiableNode(aNode)) { + return false; + } + + switch (aNode->NodeType()) { + case nsIDOMNode::ELEMENT_NODE: + // In HTML editors, if we're dealing with an element, then ask it + // whether it's editable. + return mIsHTMLEditorClass ? aNode->IsEditable() : true; + case nsIDOMNode::TEXT_NODE: + // Text nodes are considered to be editable by both typed of editors. + return true; + default: + return false; + } + } /** * Returns true if aNode is a MozEditorBogus node. diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 6e4778169918..42532dd76d8b 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -5290,21 +5290,6 @@ HTMLEditor::GetInputEventTargetContent() return target.forget(); } -bool -HTMLEditor::IsEditable(nsINode* aNode) -{ - if (!TextEditor::IsEditable(aNode)) { - return false; - } - if (aNode->IsElement()) { - // If we're dealing with an element, then ask it whether it's editable. - return aNode->IsEditable(); - } - // We might be dealing with a text node for example, which we always consider - // to be editable. - return true; -} - Element* HTMLEditor::GetEditorRoot() { diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index a417190ba103..0eb90699a0eb 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -119,7 +119,6 @@ public: nsINode *aNode) override; virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) override; virtual already_AddRefed GetInputEventTargetContent() override; - virtual bool IsEditable(nsINode* aNode) override; using EditorBase::IsEditable; virtual nsresult RemoveAttributeOrEquivalent( Element* aElement,