OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "core/rendering/style/RenderStyle.h" | 30 #include "core/rendering/style/RenderStyle.h" |
31 #include "core/rendering/style/StyleInheritedData.h" | 31 #include "core/rendering/style/StyleInheritedData.h" |
32 #include "wtf/text/StringBuilder.h" | 32 #include "wtf/text/StringBuilder.h" |
33 | 33 |
34 namespace WebCore { | 34 namespace WebCore { |
35 | 35 |
36 using namespace HTMLNames; | 36 using namespace HTMLNames; |
37 | 37 |
38 inline HTMLTitleElement::HTMLTitleElement(Document& document) | 38 inline HTMLTitleElement::HTMLTitleElement(Document& document) |
39 : HTMLElement(titleTag, document) | 39 : HTMLElement(titleTag, document) |
40 , m_ignoreTitleUpdatesWhenChildrenChange(false) | |
40 { | 41 { |
41 setHasCustomStyleCallbacks(); | 42 setHasCustomStyleCallbacks(); |
42 ScriptWrappable::init(this); | 43 ScriptWrappable::init(this); |
43 } | 44 } |
44 | 45 |
45 PassRefPtr<HTMLTitleElement> HTMLTitleElement::create(Document& document) | 46 PassRefPtr<HTMLTitleElement> HTMLTitleElement::create(Document& document) |
46 { | 47 { |
47 return adoptRef(new HTMLTitleElement(document)); | 48 return adoptRef(new HTMLTitleElement(document)); |
48 } | 49 } |
49 | 50 |
50 Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode* insertionPoint) | 51 Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode* insertionPoint) |
51 { | 52 { |
52 HTMLElement::insertedInto(insertionPoint); | 53 HTMLElement::insertedInto(insertionPoint); |
53 if (inDocument() && !isInShadowTree()) | 54 if (inDocument() && !isInShadowTree()) |
54 document().setTitleElement(text(), this); | 55 document().setTitleElement(text(), this); |
55 return InsertionDone; | 56 return InsertionDone; |
56 } | 57 } |
57 | 58 |
58 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint) | 59 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint) |
59 { | 60 { |
60 HTMLElement::removedFrom(insertionPoint); | 61 HTMLElement::removedFrom(insertionPoint); |
61 if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree()) | 62 if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree()) |
62 document().removeTitle(this); | 63 document().removeTitle(this); |
63 } | 64 } |
64 | 65 |
65 void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) | 66 void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) |
66 { | 67 { |
67 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi ldCountDelta); | 68 HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi ldCountDelta); |
68 if (inDocument() && !isInShadowTree()) | 69 if (inDocument() && !isInShadowTree() && !m_ignoreTitleUpdatesWhenChildrenCh ange) |
69 document().setTitleElement(text(), this); | 70 document().setTitleElement(text(), this); |
70 } | 71 } |
71 | 72 |
72 String HTMLTitleElement::text() const | 73 String HTMLTitleElement::text() const |
73 { | 74 { |
74 StringBuilder result; | 75 StringBuilder result; |
75 | 76 |
76 for (Node *n = firstChild(); n; n = n->nextSibling()) { | 77 for (Node *n = firstChild(); n; n = n->nextSibling()) { |
77 if (n->isTextNode()) | 78 if (n->isTextNode()) |
78 result.append(toText(n)->data()); | 79 result.append(toText(n)->data()); |
79 } | 80 } |
80 | 81 |
81 return result.toString(); | 82 return result.toString(); |
82 } | 83 } |
83 | 84 |
84 void HTMLTitleElement::setText(const String &value) | 85 void HTMLTitleElement::setText(const String &value) |
85 { | 86 { |
86 RefPtr<Node> protectFromMutationEvents(this); | 87 RefPtr<Node> protectFromMutationEvents(this); |
87 | 88 |
88 int numChildren = childNodeCount(); | 89 int numChildren = childNodeCount(); |
89 | 90 |
90 if (numChildren == 1 && firstChild()->isTextNode()) | 91 if (numChildren == 1 && firstChild()->isTextNode()) |
91 toText(firstChild())->setData(value); | 92 toText(firstChild())->setData(value); |
92 else { | 93 else { |
93 // We make a copy here because entity of "value" argument can be Documen t::m_title, | 94 if (numChildren > 0) { |
94 // which goes empty during removeChildren() invocation below, | 95 IgnoreTitleUpdatesWhenChildrenChange inhibitor(this); |
jochen (gone - plz use gerrit)
2014/01/09 12:17:33
here you can then set the bool directly and don't
| |
95 // which causes HTMLTitleElement::childrenChanged(), which ends up in Do cument::setTitleElement(). | 96 removeChildren(); |
96 String valueCopy(value); | 97 } |
97 | 98 |
98 if (numChildren > 0) | 99 appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION); |
99 removeChildren(); | |
100 | |
101 appendChild(document().createTextNode(valueCopy.impl()), IGNORE_EXCEPTIO N); | |
102 } | 100 } |
103 } | 101 } |
104 | 102 |
105 } | 103 } |
OLD | NEW |