summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLTitleElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/html/HTMLTitleElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLTitleElement.cpp61
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);
}
}