diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 06:24:43 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 06:24:43 -0400 |
commit | 61e46a6d58a58e249f1982d903780bf5bccb8f6b (patch) | |
tree | fd3de5eca4f0bdce70df9f0a9a51549dae4942d9 /editor/libeditor/HTMLEditor.cpp | |
parent | 8114d58fee29120ab4a7af7bd9b5c77252ab1d86 (diff) | |
download | UXP-61e46a6d58a58e249f1982d903780bf5bccb8f6b.tar UXP-61e46a6d58a58e249f1982d903780bf5bccb8f6b.tar.gz UXP-61e46a6d58a58e249f1982d903780bf5bccb8f6b.tar.lz UXP-61e46a6d58a58e249f1982d903780bf5bccb8f6b.tar.xz UXP-61e46a6d58a58e249f1982d903780bf5bccb8f6b.zip |
Issue #1375 - Stop largely using the parser service
This is based on Bug 1395828
* Add nsHTMLElement::IsBlock()
* Rename nsHTMLTags methods
* Remove AssertParserServiceIsCorrect()
* Remove most uses of nsIParserService/nsParserService
Diffstat (limited to 'editor/libeditor/HTMLEditor.cpp')
-rw-r--r-- | editor/libeditor/HTMLEditor.cpp | 78 |
1 files changed, 9 insertions, 69 deletions
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 766ab81cf..04a710cde 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -63,13 +63,13 @@ #include "nsIWidget.h" #include "nsIFrame.h" -#include "nsIParserService.h" #include "mozilla/dom/Selection.h" #include "mozilla/dom/DocumentFragment.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/EventTarget.h" #include "mozilla/dom/HTMLBodyElement.h" +#include "nsElementTable.h" #include "nsTextFragment.h" #include "nsContentList.h" #include "mozilla/StyleSheet.h" @@ -690,49 +690,6 @@ HTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) return TypedText(str, eTypedText); } -static void -AssertParserServiceIsCorrect(nsIAtom* aTag, bool aIsBlock) -{ -#ifdef DEBUG - // Check this against what we would have said with the old code: - if (aTag == nsGkAtoms::p || - aTag == nsGkAtoms::div || - aTag == nsGkAtoms::blockquote || - aTag == nsGkAtoms::h1 || - aTag == nsGkAtoms::h2 || - aTag == nsGkAtoms::h3 || - aTag == nsGkAtoms::h4 || - aTag == nsGkAtoms::h5 || - aTag == nsGkAtoms::h6 || - aTag == nsGkAtoms::ul || - aTag == nsGkAtoms::ol || - aTag == nsGkAtoms::dl || - aTag == nsGkAtoms::noscript || - aTag == nsGkAtoms::form || - aTag == nsGkAtoms::hr || - aTag == nsGkAtoms::table || - aTag == nsGkAtoms::fieldset || - aTag == nsGkAtoms::address || - aTag == nsGkAtoms::col || - aTag == nsGkAtoms::colgroup || - aTag == nsGkAtoms::li || - aTag == nsGkAtoms::dt || - aTag == nsGkAtoms::dd || - aTag == nsGkAtoms::legend) { - if (!aIsBlock) { - nsAutoString assertmsg (NS_LITERAL_STRING("Parser and editor disagree on blockness: ")); - - nsAutoString tagName; - aTag->ToString(tagName); - assertmsg.Append(tagName); - char* assertstr = ToNewCString(assertmsg); - NS_ASSERTION(aIsBlock, assertstr); - free(assertstr); - } - } -#endif // DEBUG -} - /** * Returns true if the id represents an element of block type. * Can be used to determine if a new paragraph should be started. @@ -742,8 +699,8 @@ HTMLEditor::NodeIsBlockStatic(const nsINode* aElement) { MOZ_ASSERT(aElement); - // Nodes we know we want to treat as block - // even though the parser says they're not: + // We want to treat these as block nodes even though nsHTMLElement says + // they're not. if (aElement->IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::head, nsGkAtoms::tbody, @@ -752,27 +709,13 @@ HTMLEditor::NodeIsBlockStatic(const nsINode* aElement) nsGkAtoms::tr, nsGkAtoms::th, nsGkAtoms::td, - nsGkAtoms::li, nsGkAtoms::dt, - nsGkAtoms::dd, - nsGkAtoms::pre)) { + nsGkAtoms::dd)) { return true; } - bool isBlock; -#ifdef DEBUG - // XXX we can't use DebugOnly here because VC++ is stupid (bug 802884) - nsresult rv = -#endif - nsContentUtils::GetParserService()-> - IsBlock(nsContentUtils::GetParserService()->HTMLAtomTagToId( - aElement->NodeInfo()->NameAtom()), - isBlock); - MOZ_ASSERT(rv == NS_OK); - - AssertParserServiceIsCorrect(aElement->NodeInfo()->NameAtom(), isBlock); - - return isBlock; + return nsHTMLElement::IsBlock( + nsHTMLTags::AtomTagToId(aElement->NodeInfo()->NameAtom())); } nsresult @@ -3538,17 +3481,15 @@ bool HTMLEditor::TagCanContainTag(nsIAtom& aParentTag, nsIAtom& aChildTag) { - nsIParserService* parserService = nsContentUtils::GetParserService(); - int32_t childTagEnum; // XXX Should this handle #cdata-section too? if (&aChildTag == nsGkAtoms::textTagName) { childTagEnum = eHTMLTag_text; } else { - childTagEnum = parserService->HTMLAtomTagToId(&aChildTag); + childTagEnum = nsHTMLTags::AtomTagToId(&aChildTag); } - int32_t parentTagEnum = parserService->HTMLAtomTagToId(&aParentTag); + int32_t parentTagEnum = nsHTMLTags::AtomTagToId(&aParentTag); return HTMLEditUtils::CanContain(parentTagEnum, childTagEnum); } @@ -3562,8 +3503,7 @@ HTMLEditor::IsContainer(nsINode* aNode) if (aNode->IsNodeOfType(nsINode::eTEXT)) { tagEnum = eHTMLTag_text; } else { - tagEnum = - nsContentUtils::GetParserService()->HTMLStringTagToId(aNode->NodeName()); + tagEnum = nsHTMLTags::StringTagToId(aNode->NodeName()); } return HTMLEditUtils::IsContainer(tagEnum); |