Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLBaseElement.cpp
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, 2008, 2009, 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 "config.h"
24 #include "core/html/HTMLBaseElement.h"
25
26 #include "core/HTMLNames.h"
27 #include "core/dom/Attribute.h"
28 #include "core/dom/Document.h"
29 #include "core/html/parser/HTMLParserIdioms.h"
30 #include "core/html/parser/TextResourceDecoder.h"
31
32 namespace blink {
33
34 using namespace HTMLNames;
35
36 inline HTMLBaseElement::HTMLBaseElement(Document& document)
37     : HTMLElement(baseTag, document)
38 {
39 }
40
41 DEFINE_NODE_FACTORY(HTMLBaseElement)
42
43 void HTMLBaseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
44 {
45     if (name == hrefAttr || name == targetAttr)
46         document().processBaseElement();
47     else
48         HTMLElement::parseAttribute(name, value);
49 }
50
51 Node::InsertionNotificationRequest HTMLBaseElement::insertedInto(ContainerNode* insertionPoint)
52 {
53     HTMLElement::insertedInto(insertionPoint);
54     if (insertionPoint->inDocument())
55         document().processBaseElement();
56     return InsertionDone;
57 }
58
59 void HTMLBaseElement::removedFrom(ContainerNode* insertionPoint)
60 {
61     HTMLElement::removedFrom(insertionPoint);
62     if (insertionPoint->inDocument())
63         document().processBaseElement();
64 }
65
66 bool HTMLBaseElement::isURLAttribute(const Attribute& attribute) const
67 {
68     return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribute(attribute);
69 }
70
71 KURL HTMLBaseElement::href() const
72 {
73     // This does not use the getURLAttribute function because that will resolve relative to the document's base URL;
74     // base elements like this one can be used to set that base URL. Thus we need to resolve relative to the document's
75     // URL and ignore the base URL.
76
77     const AtomicString& attributeValue = fastGetAttribute(hrefAttr);
78     if (attributeValue.isNull())
79         return document().url();
80
81     KURL url = document().encoding().isValid() ?
82         KURL(document().url(), stripLeadingAndTrailingHTMLSpaces(attributeValue)) :
83         KURL(document().url(), stripLeadingAndTrailingHTMLSpaces(attributeValue), document().encoding());
84
85     if (!url.isValid())
86         return KURL();
87
88     return url;
89 }
90
91 void HTMLBaseElement::setHref(const AtomicString& value)
92 {
93     setAttribute(hrefAttr, value);
94 }
95
96 }