• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Apple Computer, Inc.
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 #include "config.h"
23 #include "HTMLTitleElement.h"
24 
25 #include "Document.h"
26 #include "HTMLNames.h"
27 #include "Text.h"
28 
29 namespace WebCore {
30 
31 using namespace HTMLNames;
32 
HTMLTitleElement(const QualifiedName & tagName,Document * doc)33 HTMLTitleElement::HTMLTitleElement(const QualifiedName& tagName, Document* doc)
34     : HTMLElement(tagName, doc)
35     , m_title("")
36 {
37     ASSERT(hasTagName(titleTag));
38 }
39 
~HTMLTitleElement()40 HTMLTitleElement::~HTMLTitleElement()
41 {
42 }
43 
insertedIntoDocument()44 void HTMLTitleElement::insertedIntoDocument()
45 {
46     HTMLElement::insertedIntoDocument();
47     document()->setTitle(m_title, this);
48 }
49 
removedFromDocument()50 void HTMLTitleElement::removedFromDocument()
51 {
52     HTMLElement::removedFromDocument();
53     document()->removeTitle(this);
54 }
55 
childrenChanged(bool changedByParser,Node * beforeChange,Node * afterChange,int childCountDelta)56 void HTMLTitleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
57 {
58     m_title = "";
59     for (Node* c = firstChild(); c != 0; c = c->nextSibling())
60         if (c->nodeType() == TEXT_NODE || c->nodeType() == CDATA_SECTION_NODE)
61             m_title += c->nodeValue();
62     if (inDocument())
63         document()->setTitle(m_title, this);
64     HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
65 }
66 
text() const67 String HTMLTitleElement::text() const
68 {
69     String val = "";
70 
71     for (Node *n = firstChild(); n; n = n->nextSibling()) {
72         if (n->isTextNode())
73             val += static_cast<Text*>(n)->data();
74     }
75 
76     return val;
77 }
78 
setText(const String & value)79 void HTMLTitleElement::setText(const String &value)
80 {
81     ExceptionCode ec = 0;
82     int numChildren = childNodeCount();
83 
84     if (numChildren == 1 && firstChild()->isTextNode())
85         static_cast<Text*>(firstChild())->setData(value, ec);
86     else {
87         if (numChildren > 0)
88             removeChildren();
89 
90         appendChild(document()->createTextNode(value.impl()), ec);
91     }
92 }
93 
94 }
95