Commit 5c576d1e authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Reduce usage of HTMLElementFactory::createHTMLElement

The function contains autonomous custom element processing.  It's
unexpected in many cases.

If it's called with known HTML tags, custom element processing is
unnecessary and it should be replaced with
Document::CreateRawElement().

If it's called with arbitrary tag names, custom element processing
is necessary and it should be replaced with Document::createElement().

This CL is a preparation to remove HTMLElementFactory::createElement().

Bug: 806641
Change-Id: I00dae6c2cdac18eccd1580a72d94862b5cb2d657
Reviewed-on: https://chromium-review.googlesource.com/895203Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533235}
parent 6caa6321
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "core/editing/SelectionTemplate.h" #include "core/editing/SelectionTemplate.h"
#include "core/editing/VisiblePosition.h" #include "core/editing/VisiblePosition.h"
#include "core/editing/VisibleSelection.h" #include "core/editing/VisibleSelection.h"
#include "core/html_element_factory.h"
#include "core/layout/LayoutObject.h" #include "core/layout/LayoutObject.h"
namespace blink { namespace blink {
...@@ -332,8 +331,9 @@ bool LineBreakExistsAtVisiblePosition(const VisiblePosition& visible_position) { ...@@ -332,8 +331,9 @@ bool LineBreakExistsAtVisiblePosition(const VisiblePosition& visible_position) {
} }
HTMLElement* CreateHTMLElement(Document& document, const QualifiedName& name) { HTMLElement* CreateHTMLElement(Document& document, const QualifiedName& name) {
return HTMLElementFactory::createHTMLElement(name.LocalName(), document, DCHECK_EQ(name.NamespaceURI(), HTMLNames::xhtmlNamespaceURI)
kCreatedByCloneNode); << "Unexpected namespace: " << name;
return ToHTMLElement(document.createElement(name, kCreatedByCloneNode));
} }
HTMLElement* EnclosingList(const Node* node) { HTMLElement* EnclosingList(const Node* node) {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "core/html/track/vtt/VTTElement.h" #include "core/html/track/vtt/VTTElement.h"
#include "core/css/StyleChangeReason.h" #include "core/css/StyleChangeReason.h"
#include "core/html_element_factory.h" #include "core/dom/Document.h"
namespace blink { namespace blink {
...@@ -82,37 +82,37 @@ Element* VTTElement::CloneElementWithoutAttributesAndChildren() { ...@@ -82,37 +82,37 @@ Element* VTTElement::CloneElementWithoutAttributesAndChildren() {
} }
HTMLElement* VTTElement::CreateEquivalentHTMLElement(Document& document) { HTMLElement* VTTElement::CreateEquivalentHTMLElement(Document& document) {
HTMLElement* html_element = nullptr; Element* html_element = nullptr;
switch (web_vtt_node_type_) { switch (web_vtt_node_type_) {
case kVTTNodeTypeClass: case kVTTNodeTypeClass:
case kVTTNodeTypeLanguage: case kVTTNodeTypeLanguage:
case kVTTNodeTypeVoice: case kVTTNodeTypeVoice:
html_element = HTMLElementFactory::createHTMLElement( html_element =
HTMLNames::spanTag.LocalName(), document); document.CreateRawElement(HTMLNames::spanTag, kCreatedByParser);
html_element->setAttribute(HTMLNames::titleAttr, html_element->setAttribute(HTMLNames::titleAttr,
getAttribute(VoiceAttributeName())); getAttribute(VoiceAttributeName()));
html_element->setAttribute(HTMLNames::langAttr, html_element->setAttribute(HTMLNames::langAttr,
getAttribute(LangAttributeName())); getAttribute(LangAttributeName()));
break; break;
case kVTTNodeTypeItalic: case kVTTNodeTypeItalic:
html_element = HTMLElementFactory::createHTMLElement( html_element =
HTMLNames::iTag.LocalName(), document); document.CreateRawElement(HTMLNames::iTag, kCreatedByParser);
break; break;
case kVTTNodeTypeBold: case kVTTNodeTypeBold:
html_element = HTMLElementFactory::createHTMLElement( html_element =
HTMLNames::bTag.LocalName(), document); document.CreateRawElement(HTMLNames::bTag, kCreatedByParser);
break; break;
case kVTTNodeTypeUnderline: case kVTTNodeTypeUnderline:
html_element = HTMLElementFactory::createHTMLElement( html_element =
HTMLNames::uTag.LocalName(), document); document.CreateRawElement(HTMLNames::uTag, kCreatedByParser);
break; break;
case kVTTNodeTypeRuby: case kVTTNodeTypeRuby:
html_element = HTMLElementFactory::createHTMLElement( html_element =
HTMLNames::rubyTag.LocalName(), document); document.CreateRawElement(HTMLNames::rubyTag, kCreatedByParser);
break; break;
case kVTTNodeTypeRubyText: case kVTTNodeTypeRubyText:
html_element = HTMLElementFactory::createHTMLElement( html_element =
HTMLNames::rtTag.LocalName(), document); document.CreateRawElement(HTMLNames::rtTag, kCreatedByParser);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -120,7 +120,7 @@ HTMLElement* VTTElement::CreateEquivalentHTMLElement(Document& document) { ...@@ -120,7 +120,7 @@ HTMLElement* VTTElement::CreateEquivalentHTMLElement(Document& document) {
html_element->setAttribute(HTMLNames::classAttr, html_element->setAttribute(HTMLNames::classAttr,
getAttribute(HTMLNames::classAttr)); getAttribute(HTMLNames::classAttr));
return html_element; return ToHTMLElement(html_element);
} }
void VTTElement::SetIsPastNode(bool is_past_node) { void VTTElement::SetIsPastNode(bool is_past_node) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment