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, 2010 Apple Inc. All rights reserved.
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.
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.
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.
24 #include "core/html/HTMLTitleElement.h"
26 #include "bindings/v8/ExceptionStatePlaceholder.h"
27 #include "core/HTMLNames.h"
28 #include "core/dom/ChildListMutationScope.h"
29 #include "core/dom/Document.h"
30 #include "core/dom/Text.h"
31 #include "core/rendering/style/RenderStyle.h"
32 #include "core/rendering/style/StyleInheritedData.h"
33 #include "wtf/text/StringBuilder.h"
37 using namespace HTMLNames;
39 inline HTMLTitleElement::HTMLTitleElement(Document& document)
40 : HTMLElement(titleTag, document)
41 , m_ignoreTitleUpdatesWhenChildrenChange(false)
43 setHasCustomStyleCallbacks();
44 ScriptWrappable::init(this);
47 DEFINE_NODE_FACTORY(HTMLTitleElement)
49 Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode* insertionPoint)
51 HTMLElement::insertedInto(insertionPoint);
52 if (inDocument() && !isInShadowTree())
53 document().setTitleElement(text(), this);
57 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint)
59 HTMLElement::removedFrom(insertionPoint);
60 if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree())
61 document().removeTitle(this);
64 void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
66 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
67 if (inDocument() && !isInShadowTree() && !m_ignoreTitleUpdatesWhenChildrenChange)
68 document().setTitleElement(text(), this);
71 String HTMLTitleElement::text() const
75 for (Node *n = firstChild(); n; n = n->nextSibling()) {
77 result.append(toText(n)->data());
80 return result.toString();
83 void HTMLTitleElement::setText(const String &value)
85 RefPtrWillBeRawPtr<Node> protectFromMutationEvents(this);
86 ChildListMutationScope mutation(*this);
88 // Avoid calling Document::setTitleElement() during intermediate steps.
89 m_ignoreTitleUpdatesWhenChildrenChange = !value.isEmpty();
91 m_ignoreTitleUpdatesWhenChildrenChange = false;
94 appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION);