Bug 1463327 - part 1: Change scope of some methods of EditorBase which won't be called by non-helper classes of editing to protected r=m_kato

EditorBase (and other editor classes) have 2 type of public methods.  One is
true-public methods.  I.e., they should be able to be called by anybody.
E.g., command handlers, event listeners, or JS via nsIEditor interface.
The other is semi-public methods.  They are not called by the above examples
but called by other classes which are helper classes to handle edit actions.
E.g., TextEditRules, HTMLEditRules, HTMLEditUtils, CSSEditUtils and Transaction
classes.

When we will implement InputEvent.inputType, we need to create new stack
class and create its instance at every true-public methods to manage current
inputType (like TextEditRules::AutoSafeEditorData).  Therefore, it should not
happen that new code starts to call semi-public methods without the new
stack class instance.

For preventing this issue, we should make EditorBase have only the true-public
methods as public.  The other public methods should be protected and their
users should be friend classes.  Then, we can protect such method from external
classes.

Note that this patch just moves the methods without any changes in EditorBase.h
(except removes GetName() since there is no body of this method and removes
IterDirection since it's unused).

MozReview-Commit-ID: HBseKLL6pxx

--HG--
extra : rebase_source : 2251ff659d831d01a6778d38f4e2714fcf2d6ef4
This commit is contained in:
Masayuki Nakano 2018-05-22 16:08:43 +09:00
Родитель 5d6053a080
Коммит 40ab33fe29
6 изменённых файлов: 709 добавлений и 684 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -44,10 +44,8 @@ class nsRange;
namespace mozilla {
class AutoSelectionSetterAfterTableEdit;
class HTMLEditorEventListener;
class HTMLEditRules;
class ResizerSelectionListener;
class TypeInState;
class WSRunObject;
enum class EditAction : int32_t;
struct PropItem;
template<class T> class OwningNonNull;
@ -1472,6 +1470,12 @@ public:
friend class WSRunObject;
private:
/**
* IsEmptyTextNode() returns true if aNode is a text node and does not have
* any visible characters.
*/
bool IsEmptyTextNode(nsINode& aNode);
bool IsSimpleModifiableNode(nsIContent* aContent,
nsAtom* aProperty,
nsAtom* aAttribute,

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

@ -45,12 +45,12 @@ namespace mozilla {
using namespace dom;
static bool
IsEmptyTextNode(HTMLEditor* aThis, nsINode* aNode)
bool
HTMLEditor::IsEmptyTextNode(nsINode& aNode)
{
bool isEmptyTextNode = false;
return EditorBase::IsTextNode(aNode) &&
NS_SUCCEEDED(aThis->IsEmptyNode(aNode, &isEmptyTextNode)) &&
return EditorBase::IsTextNode(&aNode) &&
NS_SUCCEEDED(IsEmptyNode(&aNode, &isEmptyTextNode)) &&
isEmptyTextNode;
}
@ -345,7 +345,7 @@ HTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent& aNode,
for (nsCOMPtr<nsIContent> child = aNode.GetFirstChild();
child;
child = child->GetNextSibling()) {
if (IsEditable(child) && !IsEmptyTextNode(this, child)) {
if (IsEditable(child) && !IsEmptyTextNode(*child)) {
arrayOfNodes.AppendElement(*child);
}
}
@ -1051,7 +1051,7 @@ HTMLEditor::GetInlinePropertyBase(nsAtom& aProperty,
// just ignore any non-editable nodes
if (content->GetAsText() && (!IsEditable(content) ||
IsEmptyTextNode(this, content))) {
IsEmptyTextNode(*content))) {
continue;
}
if (content->GetAsText()) {

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

@ -555,10 +555,13 @@ TextEditRules::CollapseSelectionToTrailingBRIfNeeded()
return NS_OK;
}
static inline already_AddRefed<nsINode>
GetTextNode(Selection* aSelection)
already_AddRefed<nsINode>
TextEditRules::GetTextNodeAroundSelectionStartContainer()
{
EditorRawDOMPoint selectionStartPoint(EditorBase::GetStartPoint(aSelection));
MOZ_ASSERT(IsEditorDataAvailable());
EditorRawDOMPoint selectionStartPoint(
EditorBase::GetStartPoint(&SelectionRef()));
if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
return nullptr;
}
@ -567,6 +570,8 @@ GetTextNode(Selection* aSelection)
return node.forget();
}
// This should be the root node, walk the tree looking for text nodes.
// XXX NodeIterator sets mutation observer even for this temporary use.
// It's too expensive if this is called from a hot path.
nsCOMPtr<nsINode> node = selectionStartPoint.GetContainer();
RefPtr<NodeIterator> iter =
new NodeIterator(node, NodeFilterBinding::SHOW_TEXT, nullptr);
@ -1720,7 +1725,7 @@ TextEditRules::HideLastPWInput()
TextEditorRef().GetRoot(),
start, end);
nsCOMPtr<nsINode> selNode = GetTextNode(&SelectionRef());
nsCOMPtr<nsINode> selNode = GetTextNodeAroundSelectionStartContainer();
if (NS_WARN_IF(!selNode)) {
return NS_OK;
}

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

@ -472,6 +472,14 @@ protected:
bool IsEditorDataAvailable() const { return !!mData; }
#endif // #ifdef DEBUG
/**
* GetTextNodeAroundSelectionStartContainer() may return a Text node around
* start container of Selection. If current selection container is not
* a text node, this will look for descendants and next siblings of the
* container.
*/
inline already_AddRefed<nsINode> GetTextNodeAroundSelectionStartContainer();
// A buffer we use to store the real value of password editors.
nsString mPasswordText;
// A buffer we use to track the IME composition string.

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

@ -24,7 +24,6 @@ class nsITransferable;
namespace mozilla {
class AutoEditInitRulesTrigger;
class HTMLEditRules;
enum class EditAction : int32_t;
namespace dom {