Commit bbbd45f0 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Use Document::CreateRawElement instead of createElement.

If the first argument of createElement() is a pre-defined QualifiedName,
CreateRawElement() is less expensive.

This CL should not have user-visible behavior changes.

Bug: 806641
Change-Id: I80c96306031e83e1124882fcde456d54f762529f
Reviewed-on: https://chromium-review.googlesource.com/892601Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532803}
parent 5dde39d2
......@@ -343,7 +343,12 @@ class CORE_EXPORT Document : public ContainerNode,
Element* createElementNS(const AtomicString& namespace_uri,
const AtomicString& qualified_name,
ExceptionState&);
// Creates an element with autonomous custom element processing. If
// LocalName of the specified qualified name doesn't contain '-', this
// function is equivalent to CreateRawElement().
Element* createElement(const QualifiedName&, CreateElementFlags);
// Creates an element without custom element processing.
Element* CreateRawElement(const QualifiedName&, CreateElementFlags);
Element* ElementFromPoint(double x, double y) const;
HeapVector<Member<Element>> ElementsFromPoint(double x, double y) const;
......@@ -1537,8 +1542,6 @@ class CORE_EXPORT Document : public ContainerNode,
// the LocalFrameClient.
void ApplyFeaturePolicy(const ParsedFeaturePolicy& declared_policy);
Element* CreateRawElement(const QualifiedName&, CreateElementFlags);
DocumentLifecycle lifecycle_;
bool has_nodes_with_placeholder_style_;
......
......@@ -17,8 +17,8 @@ namespace blink {
class EventPathTest : public PageTestBase {};
TEST_F(EventPathTest, ShouldBeEmptyForPseudoElementWithoutParentElement) {
Element* div =
GetDocument().createElement(HTMLNames::divTag, kCreatedByCreateElement);
Element* div = GetDocument().CreateRawElement(HTMLNames::divTag,
kCreatedByCreateElement);
PseudoElement* pseudo = PseudoElement::Create(div, kPseudoIdFirstLetter);
pseudo->Dispose();
EventPath event_path(*pseudo);
......
......@@ -25,8 +25,8 @@ Element* GetOrCreateElement(ContainerNode* parent,
tag_name.NamespaceURI(), tag_name.LocalName());
if (!elements->IsEmpty())
return elements->item(0);
return parent->ownerDocument()->createElement(tag_name,
kCreatedByCreateElement);
return parent->ownerDocument()->CreateRawElement(tag_name,
kCreatedByCreateElement);
}
} // namespace
......@@ -38,8 +38,8 @@ EditingTestBase::~EditingTestBase() = default;
void EditingTestBase::InsertStyleElement(const std::string& style_rules) {
Element* const head = GetOrCreateElement(&GetDocument(), HTMLNames::headTag);
DCHECK_EQ(head, GetOrCreateElement(&GetDocument(), HTMLNames::headTag));
Element* const style =
GetDocument().createElement(HTMLNames::styleTag, kCreatedByCreateElement);
Element* const style = GetDocument().CreateRawElement(
HTMLNames::styleTag, kCreatedByCreateElement);
style->setTextContent(String(style_rules.data(), style_rules.size()));
head->appendChild(style);
}
......
......@@ -422,9 +422,7 @@ void HTMLSelectElement::setLength(unsigned new_len,
if (diff < 0) { // Add dummy elements.
do {
AppendChild(
GetDocument().createElement(optionTag, kCreatedByCreateElement),
exception_state);
AppendChild(HTMLOptionElement::Create(GetDocument()), exception_state);
if (exception_state.HadException())
break;
} while (++diff);
......
......@@ -97,7 +97,7 @@ void XMLErrors::AppendErrorMessage(const String& type_string,
static inline Element* CreateXHTMLParserErrorHeader(
Document* doc,
const String& error_messages) {
Element* report_element = doc->createElement(
Element* report_element = doc->CreateRawElement(
QualifiedName(g_null_atom, "parsererror", xhtmlNamespaceURI),
kCreatedByParser);
......@@ -108,12 +108,12 @@ static inline Element* CreateXHTMLParserErrorHeader(
"1em 0 1em; margin: 1em; background-color: #fdd; color: black"));
report_element->ParserSetAttributes(report_attributes);
Element* h3 = doc->createElement(h3Tag, kCreatedByParser);
Element* h3 = doc->CreateRawElement(h3Tag, kCreatedByParser);
report_element->ParserAppendChild(h3);
h3->ParserAppendChild(
doc->createTextNode("This page contains the following errors:"));
Element* fixed = doc->createElement(divTag, kCreatedByParser);
Element* fixed = doc->CreateRawElement(divTag, kCreatedByParser);
Vector<Attribute> fixed_attributes;
fixed_attributes.push_back(
Attribute(styleAttr, "font-family:monospace;font-size:12px"));
......@@ -122,7 +122,7 @@ static inline Element* CreateXHTMLParserErrorHeader(
fixed->ParserAppendChild(doc->createTextNode(error_messages));
h3 = doc->createElement(h3Tag, kCreatedByParser);
h3 = doc->CreateRawElement(h3Tag, kCreatedByParser);
report_element->ParserAppendChild(h3);
h3->ParserAppendChild(doc->createTextNode(
"Below is a rendering of the page up to the first error."));
......@@ -138,22 +138,24 @@ void XMLErrors::InsertErrorMessageBlock() {
// Create elements for display
Element* document_element = document_->documentElement();
if (!document_element) {
Element* root_element = document_->createElement(htmlTag, kCreatedByParser);
Element* body = document_->createElement(bodyTag, kCreatedByParser);
Element* root_element =
document_->CreateRawElement(htmlTag, kCreatedByParser);
Element* body = document_->CreateRawElement(bodyTag, kCreatedByParser);
root_element->ParserAppendChild(body);
document_->ParserAppendChild(root_element);
document_element = body;
} else if (document_element->namespaceURI() == SVGNames::svgNamespaceURI) {
Element* root_element = document_->createElement(htmlTag, kCreatedByParser);
Element* head = document_->createElement(headTag, kCreatedByParser);
Element* style = document_->createElement(styleTag, kCreatedByParser);
Element* root_element =
document_->CreateRawElement(htmlTag, kCreatedByParser);
Element* head = document_->CreateRawElement(headTag, kCreatedByParser);
Element* style = document_->CreateRawElement(styleTag, kCreatedByParser);
head->ParserAppendChild(style);
style->ParserAppendChild(
document_->createTextNode("html, body { height: 100% } parsererror + "
"svg { width: 100%; height: 100% }"));
style->FinishParsingChildren();
root_element->ParserAppendChild(head);
Element* body = document_->createElement(bodyTag, kCreatedByParser);
Element* body = document_->CreateRawElement(bodyTag, kCreatedByParser);
root_element->ParserAppendChild(body);
document_->ParserRemoveChild(*document_element);
......@@ -171,7 +173,7 @@ void XMLErrors::InsertErrorMessageBlock() {
if (DocumentXSLT::HasTransformSourceDocument(*document_)) {
Vector<Attribute> attributes;
attributes.push_back(Attribute(styleAttr, "white-space: normal"));
Element* paragraph = document_->createElement(pTag, kCreatedByParser);
Element* paragraph = document_->CreateRawElement(pTag, kCreatedByParser);
paragraph->ParserSetAttributes(attributes);
paragraph->ParserAppendChild(document_->createTextNode(
"This document was created as the result of an XSL transformation. The "
......
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