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.
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.
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.
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.
24 #include "core/html/HTMLBaseElement.h"
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"
34 using namespace HTMLNames;
36 inline HTMLBaseElement::HTMLBaseElement(Document& document)
37 : HTMLElement(baseTag, document)
41 DEFINE_NODE_FACTORY(HTMLBaseElement)
43 void HTMLBaseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
45 if (name == hrefAttr || name == targetAttr)
46 document().processBaseElement();
48 HTMLElement::parseAttribute(name, value);
51 Node::InsertionNotificationRequest HTMLBaseElement::insertedInto(ContainerNode* insertionPoint)
53 HTMLElement::insertedInto(insertionPoint);
54 if (insertionPoint->inDocument())
55 document().processBaseElement();
59 void HTMLBaseElement::removedFrom(ContainerNode* insertionPoint)
61 HTMLElement::removedFrom(insertionPoint);
62 if (insertionPoint->inDocument())
63 document().processBaseElement();
66 bool HTMLBaseElement::isURLAttribute(const Attribute& attribute) const
68 return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribute(attribute);
71 KURL HTMLBaseElement::href() const
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.
77 const AtomicString& attributeValue = fastGetAttribute(hrefAttr);
78 if (attributeValue.isNull())
79 return document().url();
81 KURL url = document().encoding().isValid() ?
82 KURL(document().url(), stripLeadingAndTrailingHTMLSpaces(attributeValue)) :
83 KURL(document().url(), stripLeadingAndTrailingHTMLSpaces(attributeValue), document().encoding());
91 void HTMLBaseElement::setHref(const AtomicString& value)
93 setAttribute(hrefAttr, value);