diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/HTMLTitleElement.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/html/HTMLTitleElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLTitleElement.cpp | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/Source/WebCore/html/HTMLTitleElement.cpp b/Source/WebCore/html/HTMLTitleElement.cpp index a62d9a37a..81ba8deef 100644 --- a/Source/WebCore/html/HTMLTitleElement.cpp +++ b/Source/WebCore/html/HTMLTitleElement.cpp @@ -25,8 +25,11 @@ #include "Document.h" #include "HTMLNames.h" +#include "NodeRenderStyle.h" +#include "RenderElement.h" #include "RenderStyle.h" #include "StyleInheritedData.h" +#include "StyleResolver.h" #include "Text.h" #include "TextNodeTraversal.h" #include <wtf/Ref.h> @@ -42,74 +45,54 @@ inline HTMLTitleElement::HTMLTitleElement(const QualifiedName& tagName, Document ASSERT(hasTagName(titleTag)); } -PassRefPtr<HTMLTitleElement> HTMLTitleElement::create(const QualifiedName& tagName, Document& document) +Ref<HTMLTitleElement> HTMLTitleElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLTitleElement(tagName, document)); + return adoptRef(*new HTMLTitleElement(tagName, document)); } Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode& insertionPoint) { HTMLElement::insertedInto(insertionPoint); - if (inDocument() && !isInShadowTree()) - document().setTitleElement(m_title, this); + if (isConnected() && !isInShadowTree()) + document().titleElementAdded(*this); return InsertionDone; } void HTMLTitleElement::removedFrom(ContainerNode& insertionPoint) { HTMLElement::removedFrom(insertionPoint); - if (insertionPoint.inDocument() && !insertionPoint.isInShadowTree()) - document().removeTitle(this); + if (insertionPoint.isConnected() && !insertionPoint.isInShadowTree()) + document().titleElementRemoved(*this); } void HTMLTitleElement::childrenChanged(const ChildChange& change) { HTMLElement::childrenChanged(change); - m_title = textWithDirection(); - if (inDocument()) { - if (!isInShadowTree()) - document().setTitleElement(m_title, this); - else - document().removeTitle(this); - } + m_title = computedTextWithDirection(); + document().titleElementTextChanged(*this); } String HTMLTitleElement::text() const { - return TextNodeTraversal::contentsAsString(this); + StringBuilder result; + for (Text* text = TextNodeTraversal::firstChild(*this); text; text = TextNodeTraversal::nextSibling(*text)) + result.append(text->data()); + return result.toString(); } -StringWithDirection HTMLTitleElement::textWithDirection() +StringWithDirection HTMLTitleElement::computedTextWithDirection() { TextDirection direction = LTR; - if (RenderStyle* computedStyle = this->computedStyle()) + if (auto* computedStyle = this->computedStyle()) direction = computedStyle->direction(); - else { - Ref<RenderStyle> style(styleForRenderer()); - direction = style.get().direction(); - } - return StringWithDirection(text(), direction); + else + direction = styleResolver().styleForElement(*this, parentElement() ? parentElement()->renderStyle() : nullptr).renderStyle->direction(); + return { text(), direction }; } -void HTMLTitleElement::setText(const String &value) +void HTMLTitleElement::setText(const String& value) { - Ref<HTMLTitleElement> protectFromMutationEvents(*this); - - int numChildren = childNodeCount(); - - if (numChildren == 1 && firstChild()->isTextNode()) - toText(firstChild())->setData(value, IGNORE_EXCEPTION); - else { - // We make a copy here because entity of "value" argument can be Document::m_title, - // which goes empty during removeChildren() invocation below, - // which causes HTMLTitleElement::childrenChanged(), which ends up Document::setTitle(). - String valueCopy(value); - - if (numChildren > 0) - removeChildren(); - - appendChild(document().createTextNode(valueCopy.impl()), IGNORE_EXCEPTION); - } + setTextContent(value); } } |