Bug 1569902 - part 2: Stop using attribute to consider whether a <br> element is a special node for empty last line or not r=m_kato,smaug

Editor creates a `<br>` element to end of a block if last line
of the block is empty because caret should be placed as there is an empty
line.  Such special `<br>` element has `type` attribute whose value is "_moz".
However, adding/removing the attribute is expensive and such hacky attribute
shouldn't be referred nor changed by web apps.

Therefore, this patch makes `HTMLBRElement` take another specific flag whether
it's a special node for empty last line.  For making the meaning clearer,
this patch calls the such `<br>` elements as "padding `<br>` element for
empty last line" insead of "moz-br".  So, this patch also includes a lot of
renaming methods and variables, and modifying related comments.

Note that with this change, `IMEContentObserver` counts the padding `<br>`
element in `<textarea>` because it's inserted before setting the new flag
and setting the flag does not cause DOM tree mutation.  This issue will be
fixed by the following patches.

Differential Revision: https://phabricator.services.mozilla.com/D39858
This commit is contained in:
Masayuki Nakano
2019-08-02 05:45:18 +00:00
parent 51e4ed4038
commit e65ef7b36c
20 changed files with 190 additions and 205 deletions

View File

@@ -208,8 +208,6 @@ bool nsXHTMLContentSerializer::SerializeAttributes(
PushNameSpaceDecl(aTagPrefix, aTagNamespaceURI, aOriginalElement);
}
NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
count = aElement->GetAttrCount();
// Now serialize each of the attributes
@@ -252,15 +250,6 @@ bool nsXHTMLContentSerializer::SerializeAttributes(
bool isJS = false;
if (kNameSpaceID_XHTML == contentNamespaceID) {
//
// Filter out special case of <br type="_moz"> or <br _moz*>,
// used by the editor. Bug 16988. Yuck.
//
if (namespaceID == kNameSpaceID_None && aTagName == nsGkAtoms::br &&
attrName == nsGkAtoms::type && StringBeginsWith(valueStr, _mozStr)) {
continue;
}
if (mIsCopying && mIsFirstChildOfOL && (aTagName == nsGkAtoms::li) &&
(attrName == nsGkAtoms::value)) {
// This is handled separately in SerializeLIValueAttribute()