Home | History | Annotate | Download | only in wml
      1 /**
      2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  *
     19  */
     20 
     21 #include "config.h"
     22 
     23 #if ENABLE(WML)
     24 #include "WMLSetvarElement.h"
     25 
     26 #include "Attribute.h"
     27 #include "HTMLNames.h"
     28 #include "WMLErrorHandling.h"
     29 #include "WMLTaskElement.h"
     30 #include "WMLVariables.h"
     31 
     32 namespace WebCore {
     33 
     34 WMLSetvarElement::WMLSetvarElement(const QualifiedName& tagName, Document* doc)
     35     : WMLElement(tagName, doc)
     36 {
     37 }
     38 
     39 PassRefPtr<WMLSetvarElement> WMLSetvarElement::create(const QualifiedName& tagName, Document* document)
     40 {
     41     return adoptRef(new WMLSetvarElement(tagName, document));
     42 }
     43 
     44 WMLSetvarElement::~WMLSetvarElement()
     45 {
     46 }
     47 
     48 void WMLSetvarElement::parseMappedAttribute(Attribute* attr)
     49 {
     50     if (attr->name() == HTMLNames::nameAttr) {
     51         if (!isValidVariableName(parseValueSubstitutingVariableReferences(attr->value(), WMLErrorInvalidVariableName))) {
     52             reportWMLError(document(), WMLErrorInvalidVariableName);
     53             return;
     54         }
     55     } else
     56         WMLElement::parseMappedAttribute(attr);
     57 }
     58 
     59 void WMLSetvarElement::insertedIntoDocument()
     60 {
     61     WMLElement::insertedIntoDocument();
     62 
     63     ContainerNode* parent = parentNode();
     64     if (!parent || !parent->isWMLElement())
     65         return;
     66 
     67     if (static_cast<WMLElement*>(parent)->isWMLTaskElement())
     68         static_cast<WMLTaskElement*>(parent)->registerVariableSetter(this);
     69 }
     70 
     71 void WMLSetvarElement::removedFromDocument()
     72 {
     73     ContainerNode* parent = parentNode();
     74     if (parent && parent->isWMLElement()) {
     75         if (static_cast<WMLElement*>(parent)->isWMLTaskElement())
     76             static_cast<WMLTaskElement*>(parent)->deregisterVariableSetter(this);
     77     }
     78 
     79     WMLElement::removedFromDocument();
     80 }
     81 
     82 String WMLSetvarElement::name() const
     83 {
     84     return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::nameAttr), WMLErrorInvalidVariableName);
     85 }
     86 
     87 String WMLSetvarElement::value() const
     88 {
     89     return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::valueAttr));
     90 }
     91 
     92 }
     93 
     94 #endif
     95