| OLD | NEW |
| (Empty) |
| 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, 2010 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 "sky/engine/core/html/HTMLTitleElement.h" | |
| 24 | |
| 25 #include "gen/sky/core/HTMLNames.h" | |
| 26 #include "sky/engine/bindings/exception_state_placeholder.h" | |
| 27 #include "sky/engine/core/dom/ChildListMutationScope.h" | |
| 28 #include "sky/engine/core/dom/Document.h" | |
| 29 #include "sky/engine/core/dom/Text.h" | |
| 30 #include "sky/engine/core/rendering/style/RenderStyle.h" | |
| 31 #include "sky/engine/core/rendering/style/StyleInheritedData.h" | |
| 32 #include "sky/engine/wtf/text/StringBuilder.h" | |
| 33 | |
| 34 namespace blink { | |
| 35 | |
| 36 inline HTMLTitleElement::HTMLTitleElement(Document& document) | |
| 37 : HTMLElement(HTMLNames::titleTag, document) | |
| 38 , m_ignoreTitleUpdatesWhenChildrenChange(false) | |
| 39 { | |
| 40 } | |
| 41 | |
| 42 DEFINE_NODE_FACTORY(HTMLTitleElement) | |
| 43 | |
| 44 void HTMLTitleElement::insertedInto(ContainerNode* insertionPoint) | |
| 45 { | |
| 46 HTMLElement::insertedInto(insertionPoint); | |
| 47 if (inDocument() && !isInShadowTree()) | |
| 48 document().setTitleElement(this); | |
| 49 } | |
| 50 | |
| 51 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint) | |
| 52 { | |
| 53 HTMLElement::removedFrom(insertionPoint); | |
| 54 if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree()) | |
| 55 document().removeTitle(this); | |
| 56 } | |
| 57 | |
| 58 void HTMLTitleElement::childrenChanged(const ChildrenChange& change) | |
| 59 { | |
| 60 HTMLElement::childrenChanged(change); | |
| 61 if (inDocument() && !isInShadowTree() && !m_ignoreTitleUpdatesWhenChildrenCh
ange) | |
| 62 document().setTitleElement(this); | |
| 63 } | |
| 64 | |
| 65 String HTMLTitleElement::text() const | |
| 66 { | |
| 67 StringBuilder result; | |
| 68 | |
| 69 for (Node *n = firstChild(); n; n = n->nextSibling()) { | |
| 70 if (n->isTextNode()) | |
| 71 result.append(toText(n)->data()); | |
| 72 } | |
| 73 | |
| 74 return result.toString(); | |
| 75 } | |
| 76 | |
| 77 void HTMLTitleElement::setText(const String &value) | |
| 78 { | |
| 79 RefPtr<Node> protectFromMutationEvents(this); | |
| 80 ChildListMutationScope mutation(*this); | |
| 81 | |
| 82 // Avoid calling Document::setTitleElement() during intermediate steps. | |
| 83 m_ignoreTitleUpdatesWhenChildrenChange = !value.isEmpty(); | |
| 84 removeChildren(); | |
| 85 m_ignoreTitleUpdatesWhenChildrenChange = false; | |
| 86 | |
| 87 if (!value.isEmpty()) | |
| 88 appendChild(Text::create(document(), value.impl()), IGNORE_EXCEPTION); | |
| 89 } | |
| 90 | |
| 91 } | |
| OLD | NEW |