Move some utility methods in editor classes which can be static to EditorUtils or HTMLEditUtils
Categories
(Core :: DOM: Editor, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox90 | --- | fixed |
People
(Reporter: masayuki, Assigned: masayuki)
References
(Blocks 1 open bug)
Details
Attachments
(68 files)
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
47 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review | |
48 bytes,
text/x-phabricator-request
|
Details | Review |
Currently, a lot of utility methods are in editor classes, but it's difficult to find what you want. So, they should be moved to utility classes if they can be static.
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 1•5 years ago
|
||
HTMLEditor::IsBlockNode()
is a virtual method derived from
EditorBase::IsBlockNode()
. For the performance, EditorBase
's one just
return false for text node and <br>
element. However, these check cost
is really cheap in these days. Therefore, we can make TextEditor
also
use rich API.
This patch moves HTMLEditor::NodeIsBlockStatic()
and
HTMLEditor::NodeIsInlineStatic()
to HTMLEditUtils
, and removes the wrapper
of the fommer, HTMLEditor::IsBlockNode()
and WSRunScanner::IsBlockNode()
.
Assignee | ||
Comment 2•5 years ago
|
||
Due to the include hell, EditorBase.h
cannot include EditorUtils.h
.
Therefore we need these 3 methods once. Additionally, IsModifiableNode()
is really odd method and looks like that it's used for the following 2 purposes:
- Simply can be editable.
- Can be removed from parent.
For the former case, we should sort out it with
EditorUtils::IsEditableContent()
, but for now, this patch moves it to
HTMLEditUtils::IsSimplyEditable()
. On the other hand, for the latter case,
we obviously has a bug. Therefore, this patch creates
HTMLEditUtils::IsRemovableFromParentNode()
and make it check whether the
removing node is also editable.
Unfortunately, EditorUtils::IsEditableContent()
needs to take editor type.
But it's most callers are in HTMLEditor
and most of remains are in
common methods of EditorBase
. I guess we could remove this ugly argument
in the future.
Depends on D70874
Assignee | ||
Comment 3•5 years ago
|
||
It's only non-HTMLEditor
user is EditorBase::JoinNodesDeepWithTransaction()
,
but it's called only by HTMLEditor
. Therefore, we can move it into
HTMLEditUtils
and move EditorBase::JoinNodesDeepWithTransaction()
to
HTMLEditor
.
Depends on D70875
Assignee | ||
Comment 4•5 years ago
|
||
A lot of editor code refers nsINode::IsText()
directly so that we don't
need to keep the too simple editor API anymore.
Depends on D70876
Assignee | ||
Comment 5•5 years ago
|
||
Their users should use EditorDOMPoint
or something instead.
This patch cleans up EditorBase::DoJoinNodes()
too because of their heavy
user. It requires only joined nodes because aParent
is used only for
removing aContentToJoin
, but we now have nsINode::Remove()
which does
not require parent node and never fails.
Depends on D70877
Assignee | ||
Comment 6•5 years ago
|
||
Actually, they are used only by HTMLEditor
because TextEditor
finally
returns true
for any cases in TextEditor
, but the users are overridden by
HTMLEditor
and never used by HTMLEditor
. Therefore, we cam move them
into HTMLEditUtils
.
Depends on D70878
Assignee | ||
Comment 7•5 years ago
|
||
It's also used in <textarea>
so that it should be in EditorUtils
rather
than HTMLEditUtils
.
Depends on D70879
Assignee | ||
Comment 8•5 years ago
|
||
It's a virtual method which always returns true if TextEditor
. Therefore,
we can move it into HTMLEditUtils
and we can make the only caller of
EditorBase
check IsTextEditor()
instead.
Depends on D70880
Assignee | ||
Comment 9•5 years ago
|
||
This patch also names the former to GetInclusiveAncestorBlockElement()
and
the latter to GetAncestorBlockElement()
for consistency with modern DOM
API names.
Depends on D70882
Assignee | ||
Comment 10•5 years ago
|
||
Depends on D70883
Comment 11•5 years ago
|
||
Comment 12•5 years ago
|
||
Comment 13•5 years ago
|
||
Comment 14•5 years ago
|
||
Comment 15•5 years ago
|
||
Comment 16•5 years ago
|
||
bugherder |
Comment 17•5 years ago
|
||
Comment 18•5 years ago
|
||
bugherder |
Comment 19•5 years ago
|
||
bugherder |
Comment 20•5 years ago
|
||
Comment 21•5 years ago
|
||
Comment 22•5 years ago
|
||
Comment 23•5 years ago
|
||
bugherder |
Comment 24•5 years ago
|
||
Comment 25•5 years ago
|
||
bugherder |
Assignee | ||
Comment 26•5 years ago
|
||
As an alternative of HTMLEditor::GetCellFromRange()
, this patch creates more
generic utility method.
Depends on D72296
Assignee | ||
Comment 27•5 years ago
|
||
Even though the method returns only in specific cases, but the result affects
only one caller, HTMLEditor::GetNextSelectedTableCellElement()
. Therefore,
we can create new generic utility method,
HTMLEditUtils::GetTableCellElementIfOnlyOneSelected()
and get rid of
HTMLEditor::GetCellFromRange()
.
Note that the warnings in HTMLEditor::GetCellFromRange()
is just noise for
any callers. So, this gets rid of the useless spam warnings.
Depends on D72585
Comment 28•5 years ago
|
||
Comment 29•5 years ago
|
||
bugherder |
Assignee | ||
Comment 30•5 years ago
|
||
It's currently enough simple and there is only one user. So, we can get rid
of it.
Depends on D74203
Assignee | ||
Comment 31•5 years ago
|
||
Depends on D74204
Assignee | ||
Comment 32•5 years ago
|
||
This is used by TextEditor::UndoAsAction()
too, so, it might be better to be
in EditorUtils
. However, it is completely designed for HTMLEditor
and
ideally, UndoAsAction
should be overridden by HTMLEditor
too and
TextEditor
should use faster path because of its content is in anonymous
subtree. But we don't have any merit to do that instead of avoiding virtual
call.
Depends on D74361
Comment 33•5 years ago
|
||
Comment 34•5 years ago
|
||
bugherder |
Comment 35•5 years ago
|
||
Comment 36•5 years ago
|
||
bugherder |
Assignee | ||
Comment 37•5 years ago
|
||
It looks for next leaf content or next block element for finding "end reason
node" of WSRunScanner
. Especially for clearing the latter case, this
patch renames it to GetNextLeafContentOrNextBlockElement()
.
Assignee | ||
Comment 38•5 years ago
|
||
Similar to the previous patch, this patch moves it into HTMLEditUtils
with
renaming it to GetPreviousLeafContentOrPreviousBlockElement()
.
Depends on D74804
Assignee | ||
Comment 39•5 years ago
|
||
They are returning same meaning value as
HTMLEditUtils::GetNextLeafContentOrNextBlockElement()
and
HTMLEditUtils::GetPreviousLeafContentOrPreviousBlockElement()
so that
they can be renamed to same name to overload them.
Depends on D74805
Comment 40•5 years ago
|
||
Comment 41•5 years ago
|
||
Comment 42•5 years ago
|
||
bugherder |
Comment 43•5 years ago
|
||
Comment 44•5 years ago
|
||
bugherder |
Comment 45•5 years ago
|
||
bugherder |
Assignee | ||
Comment 46•5 years ago
|
||
Depends on D75888
Comment 47•5 years ago
|
||
Comment 48•5 years ago
|
||
bugherder |
Assignee | ||
Comment 49•4 years ago
|
||
Now, it does not depend on HTMLEditor
. So, we can move it into the
HTMLEditUtils
.
Depends on D112509
Assignee | ||
Comment 50•4 years ago
|
||
Depends on D112510
Assignee | ||
Comment 51•4 years ago
|
||
It returns true only when it's a text node, but the text is empty.
However, HTMLEditUtils::IsVisibleTextNode()
is used in
HTMLEditor::IsEmptyNodeImpl()
. So, we replace it with directly using
HTMLEditUtils::IsVisibleTextNode()
.
Depends on D112511
Assignee | ||
Comment 52•4 years ago
|
||
It's hard to understand each caller of HTMLEditor::IsEmptyNode()
tries to
check with multiple bool
arguments. Therefore, they should be replaced
with an EnumSet
.
Note that only the first argument is reverted the meaning. Therefore, if
it's omitted or false
, EmptyCheckOption::TreatSingleBRElementAsVisible
is specified explicitly. Otherwise, i.e., true
, nothing should be
specified.
Depends on D112512
Comment 53•4 years ago
|
||
Comment 54•4 years ago
|
||
Comment 55•4 years ago
|
||
bugherder |
Comment 56•4 years ago
|
||
Comment 57•4 years ago
|
||
bugherder |
Assignee | ||
Comment 58•4 years ago
|
||
Before moving them from EditorBase
, they should take only one option argument
whose type is an EnumSet
class.
Note that I wanted to name each option for optional behavior, but
FindAnyDataNode
requires to revert the its meaning (I.e., only with this
patch, true
should be set an option). Therefore, the following patch renames
it.
Assignee | ||
Comment 59•4 years ago
|
||
So, the meaning is reverted of this action. But with this change, the scanner
methods scans any nodes by default. This is simpler to understand from the
callers.
Depends on D113228
Assignee | ||
Comment 60•4 years ago
|
||
The following patches will get rid of inline wrapper methods of them.
Therefore, they shouldn't be called as "internal". And they return
nsIContent*
instead of nsINode*
so, Get*Content()
is better name for
them.
Depends on D113229
Assignee | ||
Comment 61•4 years ago
|
||
Depends on D113230
Assignee | ||
Comment 62•4 years ago
|
||
Depends on D113231
Assignee | ||
Comment 63•4 years ago
|
||
Depends on D113232
Assignee | ||
Comment 64•4 years ago
|
||
Depends on D113233
Assignee | ||
Comment 65•4 years ago
|
||
Depends on D113234
Assignee | ||
Comment 66•4 years ago
|
||
Depends on D113235
Assignee | ||
Comment 67•4 years ago
|
||
They are instance members of EditorBase
only for referring editor type and
editing host. Therefore, we can make them static with making them take
editor type and ancestor limiter as arguments.
Depends on D113236
Assignee | ||
Comment 68•4 years ago
|
||
Depends on D113237
Assignee | ||
Comment 69•4 years ago
|
||
Only the user is EditorBase::BeginningOfDocument()
which is used by both
TextEditor
and HTMLEditor
. However, if it's a TextEditor
, expected
result is only the first text node only when there is one. Therefore, we can
move it into HTMLEditUtils
and make EditorBase::BeginningOfDocument()
find the text node by it self. Then, we can get rid of using
EditorBase::GetEditorType()
in this case.
Depends on D113238
Assignee | ||
Comment 70•4 years ago
|
||
If the editor instance is a TextEditor
, the root element has to be
anonymous <div>
element and it has only one text node when it has non-empty
value. Therefore, if it's in TextEditor
, the method does not need to use
the complicated APIs for finding a text node from the anonymous <div>
element
or padding <br>
element since it can adjust the given point into the text
node without such API.
Depends on D113239
Assignee | ||
Comment 71•4 years ago
|
||
Depends on D113240
Assignee | ||
Comment 72•4 years ago
|
||
Depends on D113241
Assignee | ||
Comment 73•4 years ago
|
||
Depends on D113242
Assignee | ||
Comment 74•4 years ago
|
||
Depends on D113279
Assignee | ||
Comment 75•4 years ago
|
||
Depends on D113280
Assignee | ||
Comment 76•4 years ago
|
||
This changes the logic of HTMLEditor::GetFirstEditableLeaf()
and
HTMLEditor::GetLastEditableLeaf()
, but it shouldn't change actual behavior
because the case is that the first/last child of aNode
is not in editing
host but editable.
Depends on D113281
Comment 77•4 years ago
|
||
Comment 78•4 years ago
|
||
Comment 79•4 years ago
|
||
Comment 80•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/8134628ba8bf
https://hg.mozilla.org/mozilla-central/rev/54b001545864
https://hg.mozilla.org/mozilla-central/rev/73beaa39972d
https://hg.mozilla.org/mozilla-central/rev/38d54b3f0e7e
https://hg.mozilla.org/mozilla-central/rev/3cc2bc76803d
https://hg.mozilla.org/mozilla-central/rev/a446dafdd54a
https://hg.mozilla.org/mozilla-central/rev/8c688ae2cca9
https://hg.mozilla.org/mozilla-central/rev/68e36962f1c8
https://hg.mozilla.org/mozilla-central/rev/afd4832eef7a
https://hg.mozilla.org/mozilla-central/rev/48c21b42fee5
https://hg.mozilla.org/mozilla-central/rev/952dc69a0c72
https://hg.mozilla.org/mozilla-central/rev/c33dc0983218
https://hg.mozilla.org/mozilla-central/rev/d2431da8edea
https://hg.mozilla.org/mozilla-central/rev/e9def24bca26
https://hg.mozilla.org/mozilla-central/rev/a765064201f8
Comment 81•4 years ago
|
||
bugherder |
Comment 82•4 years ago
|
||
Comment 83•4 years ago
|
||
Comment 84•4 years ago
|
||
bugherder |
Assignee | ||
Comment 85•4 years ago
|
||
Assignee | ||
Comment 86•4 years ago
|
||
When I review patches, sometimes I saw wrong usage of !IsVisibleBRElement()
.
It means that it's an invisible <br> element or non-<br> element node,
but developers may think it checks whether it's an invisible <br>
element
or not without checking the specifying content is a <br> element.
For avoiding this, there should be IsInvisibleBRElement()
too.
Depends on D114932
Assignee | ||
Comment 87•4 years ago
|
||
This must make the callers of HTMLEditUtils::IsVisibleBRElement()
and
HTMLEditUtils::IsInvisibleBRElement()
easier to read.
Depends on D114933
Comment 88•4 years ago
|
||
Comment 89•4 years ago
|
||
Comment 90•4 years ago
|
||
bugherder |
Comment 91•4 years ago
|
||
Comment 92•4 years ago
|
||
bugherder |
Comment 93•4 years ago
|
||
bugherder |
Assignee | ||
Comment 94•4 years ago
|
||
Assignee | ||
Comment 95•4 years ago
|
||
Depends on D115115
Assignee | ||
Comment 96•4 years ago
|
||
I realized that it's used only by the dead path because the only caller,
EditorBase::BeginningOfDocument()
is overridden by HTMLEditor
and
is never called.
Depends on D115116
Assignee | ||
Comment 97•4 years ago
|
||
Depends on D115117
Assignee | ||
Comment 98•4 years ago
|
||
Depends on D115118
Assignee | ||
Comment 99•4 years ago
|
||
Depends on D115119
Assignee | ||
Comment 100•4 years ago
|
||
Depends on D115120
Assignee | ||
Comment 101•4 years ago
|
||
They may return a descendant, and now HTMLEditUtils
has some methods whose
name ends with Child
and they scan only direct children of given node.
So, we should rename these methods for avoiding misunderstanding.
Depends on D115121
Assignee | ||
Comment 102•4 years ago
|
||
The different points are, whether it checks in a given element or not, and
whether it ignores non-editable content. Therefore, this patch adds new
LeafNodeType
and new ancestor limiter argument.
The new flag is not handled in the other methods which take LeafNodeType
because there is no test.
Depends on D115122
Assignee | ||
Comment 103•4 years ago
|
||
Depends on D115123
Assignee | ||
Comment 104•4 years ago
|
||
Depends on D115164
Assignee | ||
Comment 105•4 years ago
|
||
Depends on D115165
Assignee | ||
Comment 106•4 years ago
|
||
Depends on D115166
Assignee | ||
Comment 107•4 years ago
|
||
Depends on D115167
Assignee | ||
Comment 108•4 years ago
|
||
Depends on D115168
Assignee | ||
Comment 109•4 years ago
|
||
Despite its name, it checks whether both given nodes are in same/no table
structure element or not. For avoiding this confusion, let's add
GetInclusiveAncestorAnyTableElement()
to HTMLEditUtils
and compare
the result of its calls with 2 content nodes.
Depends on D115169
Assignee | ||
Comment 110•4 years ago
|
||
It's used only by HTMLEditor::GetWhiteSpaceEndPoint()
and it just skips
white-spaces and returns first white-space position if and only if the
given point container is a text node and its previous character is a
white-space. Therefore, it can be rewritten with EditorDOMPoint
simply in
the caller.
Depends on D115170
Assignee | ||
Comment 111•4 years ago
|
||
Similarly, it's called only by HTMLEditor::GetWhiteSpaceEndPoint()
and
it returns after point of last white-space if and only if the given point
container is a text node and the offset is not end of the text node.
Therefore, we can reimplement it in the caller simply.
Depends on D115171
Assignee | ||
Comment 112•4 years ago
|
||
Now, it does easy things and called only by
HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces()
. Therefore, we can
move the code into the caller.
Depends on D115172
Comment 113•4 years ago
|
||
Assignee | ||
Comment 114•4 years ago
|
||
And also HTMLEditor::CountEditableChildren()
is moved since it's used only by
it.
Despite the long method name, it's really unclear what it does. I try to
explain it with new name, but the things which the method does are not make
sense. So, if you have better name idea, I'll take it...
Depends on D115173
Assignee | ||
Comment 115•4 years ago
|
||
Depends on D115177
Assignee | ||
Comment 116•4 years ago
|
||
Depends on D115178
Assignee | ||
Comment 117•4 years ago
|
||
Depends on D115179
Comment 118•4 years ago
|
||
Comment 119•4 years ago
|
||
Comment 120•4 years ago
|
||
Comment 121•4 years ago
|
||
Comment 122•4 years ago
|
||
Comment 123•4 years ago
|
||
Comment 124•4 years ago
|
||
Comment 125•4 years ago
|
||
Comment 126•4 years ago
|
||
Comment 127•4 years ago
|
||
Comment 128•4 years ago
|
||
bugherder |
Comment 129•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/4faec743b5f1
https://hg.mozilla.org/mozilla-central/rev/480d25550e0f
https://hg.mozilla.org/mozilla-central/rev/67d0fba3df92
https://hg.mozilla.org/mozilla-central/rev/f4f4f32f1270
https://hg.mozilla.org/mozilla-central/rev/31e6ee41cd5a
https://hg.mozilla.org/mozilla-central/rev/05436a767b5b
https://hg.mozilla.org/mozilla-central/rev/a5c77aa7cbc5
Comment 130•4 years ago
|
||
Comment 131•4 years ago
|
||
Comment 132•4 years ago
|
||
Comment 133•4 years ago
|
||
Comment 134•4 years ago
|
||
Comment 135•4 years ago
|
||
Comment 136•4 years ago
|
||
Comment 137•4 years ago
|
||
Comment 138•4 years ago
|
||
Comment 139•4 years ago
|
||
Comment 140•4 years ago
|
||
Comment 141•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/734be62c0dbc
https://hg.mozilla.org/mozilla-central/rev/40eb2ea58aa7
https://hg.mozilla.org/mozilla-central/rev/8ca3ae12971f
https://hg.mozilla.org/mozilla-central/rev/51c404b61e6c
https://hg.mozilla.org/mozilla-central/rev/6a0552785275
https://hg.mozilla.org/mozilla-central/rev/ea32cc59ac32
https://hg.mozilla.org/mozilla-central/rev/99e716181ac9
https://hg.mozilla.org/mozilla-central/rev/7ecdf3309563
https://hg.mozilla.org/mozilla-central/rev/55bb517a4ff5
Assignee | ||
Updated•4 years ago
|
Comment 142•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/3dd600a5fc90
https://hg.mozilla.org/mozilla-central/rev/e72cd321bbaf
Description
•