WebCore/html/HTMLProgressElement.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     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 #if ENABLE(PROGRESS_TAG)
       
    23 #include "HTMLProgressElement.h"
       
    24 
       
    25 #include "Attribute.h"
       
    26 #include "EventNames.h"
       
    27 #include "ExceptionCode.h"
       
    28 #include "FormDataList.h"
       
    29 #include "HTMLFormElement.h"
       
    30 #include "HTMLNames.h"
       
    31 #include "LegacyHTMLTreeBuilder.h"
       
    32 #include "RenderProgress.h"
       
    33 #include <wtf/StdLibExtras.h>
       
    34 
       
    35 namespace WebCore {
       
    36 
       
    37 using namespace HTMLNames;
       
    38 
       
    39 HTMLProgressElement::HTMLProgressElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
       
    40     : HTMLFormControlElement(tagName, document, form)
       
    41 {
       
    42     ASSERT(hasTagName(progressTag));
       
    43 }
       
    44 
       
    45 PassRefPtr<HTMLProgressElement> HTMLProgressElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
       
    46 {
       
    47     return adoptRef(new HTMLProgressElement(tagName, document, form));
       
    48 }
       
    49 
       
    50 RenderObject* HTMLProgressElement::createRenderer(RenderArena* arena, RenderStyle*)
       
    51 {
       
    52     return new (arena) RenderProgress(this);
       
    53 }
       
    54 
       
    55 const AtomicString& HTMLProgressElement::formControlType() const
       
    56 {
       
    57     DEFINE_STATIC_LOCAL(const AtomicString, progress, ("progress"));
       
    58     return progress;
       
    59 }
       
    60 
       
    61 void HTMLProgressElement::parseMappedAttribute(Attribute* attribute)
       
    62 {
       
    63     if (attribute->name() == valueAttr) {
       
    64         if (renderer())
       
    65             renderer()->updateFromElement();
       
    66     } else if (attribute->name() == maxAttr) {
       
    67         if (renderer())
       
    68             renderer()->updateFromElement();
       
    69     } else
       
    70         HTMLFormControlElement::parseMappedAttribute(attribute);
       
    71 }
       
    72 
       
    73 double HTMLProgressElement::value() const
       
    74 {
       
    75     const AtomicString& valueString = getAttribute(valueAttr);
       
    76     double value;
       
    77     bool ok = parseToDoubleForNumberType(valueString, &value);
       
    78     if (!ok || value < 0)
       
    79         return valueString.isNull() ? 1 : 0;
       
    80     return (value > max()) ? max() : value;
       
    81 }
       
    82 
       
    83 void HTMLProgressElement::setValue(double value, ExceptionCode& ec)
       
    84 {
       
    85     if (!isfinite(value)) {
       
    86         ec = NOT_SUPPORTED_ERR;
       
    87         return;
       
    88     }
       
    89     setAttribute(valueAttr, String::number(value >= 0 ? value : 0));
       
    90 }
       
    91 
       
    92 double HTMLProgressElement::max() const
       
    93 {
       
    94     double max;
       
    95     bool ok = parseToDoubleForNumberType(getAttribute(maxAttr), &max);
       
    96     if (!ok || max <= 0)
       
    97         return 1;
       
    98     return max;
       
    99 }
       
   100 
       
   101 void HTMLProgressElement::setMax(double max, ExceptionCode& ec)
       
   102 {
       
   103     if (!isfinite(max)) {
       
   104         ec = NOT_SUPPORTED_ERR;
       
   105         return;
       
   106     }
       
   107     setAttribute(maxAttr, String::number(max > 0 ? max : 1));
       
   108 }
       
   109 
       
   110 double HTMLProgressElement::position() const
       
   111 {
       
   112     if (!hasAttribute(valueAttr))
       
   113         return -1;
       
   114     return value() / max();
       
   115 }
       
   116 
       
   117 } // namespace
       
   118 #endif