Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2001 Dirk Mueller (mueller (at) 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 "HTMLNames.h"
     27 #include "core/dom/Attribute.h"
     28 #include "core/dom/Document.h"
     29 #include "core/html/parser/HTMLParserIdioms.h"
     30 #include "core/loader/TextResourceDecoder.h"
     31 
     32 namespace WebCore {
     33 
     34 using namespace HTMLNames;
     35 
     36 inline HTMLBaseElement::HTMLBaseElement(const QualifiedName& tagName, Document* document)
     37     : HTMLElement(tagName, document)
     38 {
     39     ASSERT(hasTagName(baseTag));
     40     ScriptWrappable::init(this);
     41 }
     42 
     43 PassRefPtr<HTMLBaseElement> HTMLBaseElement::create(const QualifiedName& tagName, Document* document)
     44 {
     45     return adoptRef(new HTMLBaseElement(tagName, document));
     46 }
     47 
     48 void HTMLBaseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
     49 {
     50     if (name == hrefAttr || name == targetAttr)
     51         document()->processBaseElement();
     52     else
     53         HTMLElement::parseAttribute(name, value);
     54 }
     55 
     56 Node::InsertionNotificationRequest HTMLBaseElement::insertedInto(ContainerNode* insertionPoint)
     57 {
     58     HTMLElement::insertedInto(insertionPoint);
     59     if (insertionPoint->inDocument())
     60         document()->processBaseElement();
     61     return InsertionDone;
     62 }
     63 
     64 void HTMLBaseElement::removedFrom(ContainerNode* insertionPoint)
     65 {
     66     HTMLElement::removedFrom(insertionPoint);
     67     if (insertionPoint->inDocument())
     68         document()->processBaseElement();
     69 }
     70 
     71 bool HTMLBaseElement::isURLAttribute(const Attribute& attribute) const
     72 {
     73     return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribute(attribute);
     74 }
     75 
     76 String HTMLBaseElement::target() const
     77 {
     78     return fastGetAttribute(targetAttr);
     79 }
     80 
     81 KURL HTMLBaseElement::href() const
     82 {
     83     // This does not use the getURLAttribute function because that will resolve relative to the document's base URL;
     84     // base elements like this one can be used to set that base URL. Thus we need to resolve relative to the document's
     85     // URL and ignore the base URL.
     86 
     87     const AtomicString& attributeValue = fastGetAttribute(hrefAttr);
     88     if (attributeValue.isNull())
     89         return document()->url();
     90 
     91     KURL url = !document()->decoder() ?
     92         KURL(document()->url(), stripLeadingAndTrailingHTMLSpaces(attributeValue)) :
     93         KURL(document()->url(), stripLeadingAndTrailingHTMLSpaces(attributeValue), document()->decoder()->encoding());
     94 
     95     if (!url.isValid())
     96         return KURL();
     97 
     98     return url;
     99 }
    100 
    101 void HTMLBaseElement::setHref(const AtomicString& value)
    102 {
    103     setAttribute(hrefAttr, value);
    104 }
    105 
    106 }
    107