| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 45 | 45 | 
| 46 PassRefPtr<HTMLTitleElement> HTMLTitleElement::create(const QualifiedName& tagNa
     me, Document* document) | 46 PassRefPtr<HTMLTitleElement> HTMLTitleElement::create(const QualifiedName& tagNa
     me, Document* document) | 
| 47 { | 47 { | 
| 48     return adoptRef(new HTMLTitleElement(tagName, document)); | 48     return adoptRef(new HTMLTitleElement(tagName, document)); | 
| 49 } | 49 } | 
| 50 | 50 | 
| 51 Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode*
      insertionPoint) | 51 Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode*
      insertionPoint) | 
| 52 { | 52 { | 
| 53     HTMLElement::insertedInto(insertionPoint); | 53     HTMLElement::insertedInto(insertionPoint); | 
| 54     if (inDocument() && !isInShadowTree()) | 54     if (inDocument() && !isInShadowTree()) | 
| 55         document()->setTitleElement(textWithDirection(), this); | 55         document()->setTitleElement(text(), this); | 
| 56     return InsertionDone; | 56     return InsertionDone; | 
| 57 } | 57 } | 
| 58 | 58 | 
| 59 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint) | 59 void HTMLTitleElement::removedFrom(ContainerNode* insertionPoint) | 
| 60 { | 60 { | 
| 61     HTMLElement::removedFrom(insertionPoint); | 61     HTMLElement::removedFrom(insertionPoint); | 
| 62     if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree()) | 62     if (insertionPoint->inDocument() && !insertionPoint->isInShadowTree()) | 
| 63         document()->removeTitle(this); | 63         document()->removeTitle(this); | 
| 64 } | 64 } | 
| 65 | 65 | 
| 66 void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange,
      Node* afterChange, int childCountDelta) | 66 void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange,
      Node* afterChange, int childCountDelta) | 
| 67 { | 67 { | 
| 68     HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi
     ldCountDelta); | 68     HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, chi
     ldCountDelta); | 
| 69     if (inDocument() && !isInShadowTree()) | 69     if (inDocument() && !isInShadowTree()) | 
| 70         document()->setTitleElement(textWithDirection(), this); | 70         document()->setTitleElement(text(), this); | 
| 71 } |  | 
| 72 |  | 
| 73 void HTMLTitleElement::attach(const AttachContext& context) |  | 
| 74 { |  | 
| 75     HTMLElement::attach(context); |  | 
| 76     // If after attaching nothing called styleForRenderer() on this node we |  | 
| 77     // manually cache the value. This happens if our parent doesn't have a |  | 
| 78     // renderer like <optgroup> or if it doesn't allow children like <select>. |  | 
| 79     if (!m_style) |  | 
| 80         updateNonRenderStyle(); |  | 
| 81 } |  | 
| 82 |  | 
| 83 void HTMLTitleElement::detach(const AttachContext& context) |  | 
| 84 { |  | 
| 85     m_style.clear(); |  | 
| 86     HTMLElement::detach(context); |  | 
| 87 } |  | 
| 88 |  | 
| 89 void HTMLTitleElement::updateNonRenderStyle() |  | 
| 90 { |  | 
| 91     m_style = document()->styleForElementIgnoringPendingStylesheets(this); |  | 
| 92 } |  | 
| 93 |  | 
| 94 RenderStyle* HTMLTitleElement::nonRendererStyle() const |  | 
| 95 { |  | 
| 96     return m_style.get(); |  | 
| 97 } |  | 
| 98 |  | 
| 99 PassRefPtr<RenderStyle> HTMLTitleElement::customStyleForRenderer() |  | 
| 100 { |  | 
| 101     // styleForRenderer is called whenever a new style should be associated |  | 
| 102     // with an Element so now is a good time to update our cached style. |  | 
| 103     updateNonRenderStyle(); |  | 
| 104     return m_style; |  | 
| 105 } |  | 
| 106 |  | 
| 107 void HTMLTitleElement::didRecalcStyle(StyleChange) |  | 
| 108 { |  | 
| 109     if (isInShadowTree()) |  | 
| 110         return; |  | 
| 111 |  | 
| 112     document()->setTitleElement(textWithDirection(), this); |  | 
| 113 } | 71 } | 
| 114 | 72 | 
| 115 String HTMLTitleElement::text() const | 73 String HTMLTitleElement::text() const | 
| 116 { | 74 { | 
| 117     StringBuilder result; | 75     StringBuilder result; | 
| 118 | 76 | 
| 119     for (Node *n = firstChild(); n; n = n->nextSibling()) { | 77     for (Node *n = firstChild(); n; n = n->nextSibling()) { | 
| 120         if (n->isTextNode()) | 78         if (n->isTextNode()) | 
| 121             result.append(toText(n)->data()); | 79             result.append(toText(n)->data()); | 
| 122     } | 80     } | 
| 123 | 81 | 
| 124     return result.toString(); | 82     return result.toString(); | 
| 125 } | 83 } | 
| 126 | 84 | 
| 127 StringWithDirection HTMLTitleElement::textWithDirection() |  | 
| 128 { |  | 
| 129     TextDirection direction = LTR; |  | 
| 130     if (m_style) |  | 
| 131         direction = m_style->direction(); |  | 
| 132     return StringWithDirection(text(), direction); |  | 
| 133 } |  | 
| 134 |  | 
| 135 void HTMLTitleElement::setText(const String &value) | 85 void HTMLTitleElement::setText(const String &value) | 
| 136 { | 86 { | 
| 137     RefPtr<Node> protectFromMutationEvents(this); | 87     RefPtr<Node> protectFromMutationEvents(this); | 
| 138 | 88 | 
| 139     int numChildren = childNodeCount(); | 89     int numChildren = childNodeCount(); | 
| 140 | 90 | 
| 141     if (numChildren == 1 && firstChild()->isTextNode()) | 91     if (numChildren == 1 && firstChild()->isTextNode()) | 
| 142         toText(firstChild())->setData(value); | 92         toText(firstChild())->setData(value); | 
| 143     else { | 93     else { | 
| 144         // We make a copy here because entity of "value" argument can be Documen
     t::m_title, | 94         // We make a copy here because entity of "value" argument can be Documen
     t::m_title, | 
| 145         // which goes empty during removeChildren() invocation below, | 95         // which goes empty during removeChildren() invocation below, | 
| 146         // which causes HTMLTitleElement::childrenChanged(), which ends up Docum
     ent::setTitle(). | 96         // which causes HTMLTitleElement::childrenChanged(), which ends up Docum
     ent::setTitle(). | 
| 147         String valueCopy(value); | 97         String valueCopy(value); | 
| 148 | 98 | 
| 149         if (numChildren > 0) | 99         if (numChildren > 0) | 
| 150             removeChildren(); | 100             removeChildren(); | 
| 151 | 101 | 
| 152         appendChild(document()->createTextNode(valueCopy.impl()), IGNORE_EXCEPTI
     ON, DeprecatedAttachNow); | 102         appendChild(document()->createTextNode(valueCopy.impl()), IGNORE_EXCEPTI
     ON, DeprecatedAttachNow); | 
| 153     } | 103     } | 
| 154 } | 104 } | 
| 155 | 105 | 
| 156 } | 106 } | 
| OLD | NEW | 
|---|