1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include "config.h"
24#include "HTMLTitleElement.h"
25
26#include "Document.h"
27#include "HTMLNames.h"
28#include "NodeRenderStyle.h"
29#include "RenderElement.h"
30#include "RenderStyle.h"
31#include "StyleInheritedData.h"
32#include "StyleResolver.h"
33#include "Text.h"
34#include "TextNodeTraversal.h"
35#include <wtf/IsoMallocInlines.h>
36#include <wtf/Ref.h>
37#include <wtf/text/StringBuilder.h>
38
39namespace WebCore {
40
41WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLTitleElement);
42
43using namespace HTMLNames;
44
45inline HTMLTitleElement::HTMLTitleElement(const QualifiedName& tagName, Document& document)
46 : HTMLElement(tagName, document)
47{
48 ASSERT(hasTagName(titleTag));
49}
50
51Ref<HTMLTitleElement> HTMLTitleElement::create(const QualifiedName& tagName, Document& document)
52{
53 return adoptRef(*new HTMLTitleElement(tagName, document));
54}
55
56Node::InsertedIntoAncestorResult HTMLTitleElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree)
57{
58 HTMLElement::insertedIntoAncestor(insertionType, parentOfInsertedTree);
59 document().titleElementAdded(*this);
60 return InsertedIntoAncestorResult::Done;
61}
62
63void HTMLTitleElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
64{
65 HTMLElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
66 document().titleElementRemoved(*this);
67}
68
69void HTMLTitleElement::childrenChanged(const ChildChange& change)
70{
71 HTMLElement::childrenChanged(change);
72 m_title = computedTextWithDirection();
73 document().titleElementTextChanged(*this);
74}
75
76String HTMLTitleElement::text() const
77{
78 return TextNodeTraversal::childTextContent(*this);
79}
80
81StringWithDirection HTMLTitleElement::computedTextWithDirection()
82{
83 auto direction = TextDirection::LTR;
84 if (auto* computedStyle = this->computedStyle())
85 direction = computedStyle->direction();
86 else
87 direction = styleResolver().styleForElement(*this, parentElement() ? parentElement()->renderStyle() : nullptr).renderStyle->direction();
88 return { text(), direction };
89}
90
91void HTMLTitleElement::setText(const String& value)
92{
93 setTextContent(value);
94}
95
96}
97