~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/html/HTMLTitleElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * This file is part of the DOM implementation for KDE.
 
3
 *
 
4
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 
5
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 
6
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
 
7
 * Copyright (C) 2003 Apple Computer, Inc.
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU Library General Public
 
11
 * License as published by the Free Software Foundation; either
 
12
 * version 2 of the License, or (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * Library General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Library General Public License
 
20
 * along with this library; see the file COPYING.LIB.  If not, write to
 
21
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
 * Boston, MA 02111-1307, USA.
 
23
 */
 
24
#include "config.h"
 
25
#include "HTMLTitleElement.h"
 
26
 
 
27
#include "Document.h"
 
28
#include "HTMLNames.h"
 
29
#include "Text.h"
 
30
 
 
31
namespace WebCore {
 
32
 
 
33
using namespace HTMLNames;
 
34
 
 
35
HTMLTitleElement::HTMLTitleElement(Document* doc)
 
36
    : HTMLElement(titleTag, doc)
 
37
    , m_title("")
 
38
{
 
39
}
 
40
 
 
41
HTMLTitleElement::~HTMLTitleElement()
 
42
{
 
43
}
 
44
 
 
45
void HTMLTitleElement::insertedIntoDocument()
 
46
{
 
47
    HTMLElement::insertedIntoDocument();
 
48
    document()->setTitle(m_title, this);
 
49
}
 
50
 
 
51
void HTMLTitleElement::removedFromDocument()
 
52
{
 
53
    HTMLElement::removedFromDocument();
 
54
    document()->removeTitle(this);
 
55
}
 
56
 
 
57
void HTMLTitleElement::childrenChanged()
 
58
{
 
59
    HTMLElement::childrenChanged();
 
60
    m_title = "";
 
61
    for (Node* c = firstChild(); c != 0; c = c->nextSibling())
 
62
        if (c->nodeType() == TEXT_NODE || c->nodeType() == CDATA_SECTION_NODE)
 
63
            m_title += c->nodeValue();
 
64
    if (inDocument())
 
65
        document()->setTitle(m_title, this);
 
66
}
 
67
 
 
68
String HTMLTitleElement::text() const
 
69
{
 
70
    String val = "";
 
71
    
 
72
    for (Node *n = firstChild(); n; n = n->nextSibling()) {
 
73
        if (n->isTextNode())
 
74
            val += static_cast<Text*>(n)->data();
 
75
    }
 
76
    
 
77
    return val;
 
78
}
 
79
 
 
80
void HTMLTitleElement::setText(const String &value)
 
81
{
 
82
    ExceptionCode ec = 0;
 
83
    int numChildren = childNodeCount();
 
84
    
 
85
    if (numChildren == 1 && firstChild()->isTextNode())
 
86
        static_cast<Text*>(firstChild())->setData(value, ec);
 
87
    else {  
 
88
        if (numChildren > 0)
 
89
            removeChildren();
 
90
    
 
91
        appendChild(document()->createTextNode(value.impl()), ec);
 
92
    }
 
93
}
 
94
 
 
95
}