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  * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  *
     21  */
     22 
     23 #include "config.h"
     24 #include "HTMLMarqueeElement.h"
     25 
     26 #include "CSSPropertyNames.h"
     27 #include "CSSValueKeywords.h"
     28 #include "HTMLNames.h"
     29 #include "MappedAttribute.h"
     30 #include "RenderLayer.h"
     31 #include "RenderMarquee.h"
     32 
     33 namespace WebCore {
     34 
     35 using namespace HTMLNames;
     36 
     37 // WinIE uses 60ms as the minimum delay by default.
     38 const int defaultMinimumDelay = 60;
     39 
     40 HTMLMarqueeElement::HTMLMarqueeElement(const QualifiedName& tagName, Document* doc)
     41     : HTMLElement(tagName, doc)
     42     , ActiveDOMObject(doc, this)
     43     , m_minimumDelay(defaultMinimumDelay)
     44 {
     45     ASSERT(hasTagName(marqueeTag));
     46 }
     47 
     48 bool HTMLMarqueeElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
     49 {
     50     if (attrName == widthAttr ||
     51         attrName == heightAttr ||
     52         attrName == bgcolorAttr ||
     53         attrName == vspaceAttr ||
     54         attrName == hspaceAttr ||
     55         attrName == scrollamountAttr ||
     56         attrName == scrolldelayAttr ||
     57         attrName == loopAttr ||
     58         attrName == behaviorAttr ||
     59         attrName == directionAttr) {
     60         result = eUniversal;
     61         return false;
     62     }
     63 
     64     return HTMLElement::mapToEntry(attrName, result);
     65 }
     66 
     67 void HTMLMarqueeElement::parseMappedAttribute(MappedAttribute *attr)
     68 {
     69     if (attr->name() == widthAttr) {
     70         if (!attr->value().isEmpty())
     71             addCSSLength(attr, CSSPropertyWidth, attr->value());
     72     } else if (attr->name() == heightAttr) {
     73         if (!attr->value().isEmpty())
     74             addCSSLength(attr, CSSPropertyHeight, attr->value());
     75     } else if (attr->name() == bgcolorAttr) {
     76         if (!attr->value().isEmpty())
     77             addCSSColor(attr, CSSPropertyBackgroundColor, attr->value());
     78     } else if (attr->name() == vspaceAttr) {
     79         if (!attr->value().isEmpty()) {
     80             addCSSLength(attr, CSSPropertyMarginTop, attr->value());
     81             addCSSLength(attr, CSSPropertyMarginBottom, attr->value());
     82         }
     83     } else if (attr->name() == hspaceAttr) {
     84         if (!attr->value().isEmpty()) {
     85             addCSSLength(attr, CSSPropertyMarginLeft, attr->value());
     86             addCSSLength(attr, CSSPropertyMarginRight, attr->value());
     87         }
     88     } else if (attr->name() == scrollamountAttr) {
     89         if (!attr->value().isEmpty())
     90             addCSSLength(attr, CSSPropertyWebkitMarqueeIncrement, attr->value());
     91     } else if (attr->name() == scrolldelayAttr) {
     92         if (!attr->value().isEmpty())
     93             addCSSLength(attr, CSSPropertyWebkitMarqueeSpeed, attr->value());
     94     } else if (attr->name() == loopAttr) {
     95         if (!attr->value().isEmpty()) {
     96             if (attr->value() == "-1" || equalIgnoringCase(attr->value(), "infinite"))
     97                 addCSSProperty(attr, CSSPropertyWebkitMarqueeRepetition, CSSValueInfinite);
     98             else
     99                 addCSSLength(attr, CSSPropertyWebkitMarqueeRepetition, attr->value());
    100         }
    101     } else if (attr->name() == behaviorAttr) {
    102         if (!attr->value().isEmpty())
    103             addCSSProperty(attr, CSSPropertyWebkitMarqueeStyle, attr->value());
    104     } else if (attr->name() == directionAttr) {
    105         if (!attr->value().isEmpty())
    106             addCSSProperty(attr, CSSPropertyWebkitMarqueeDirection, attr->value());
    107     } else if (attr->name() == truespeedAttr)
    108         m_minimumDelay = !attr->isEmpty() ? 0 : defaultMinimumDelay;
    109     else
    110         HTMLElement::parseMappedAttribute(attr);
    111 }
    112 
    113 void HTMLMarqueeElement::start()
    114 {
    115     if (RenderMarquee* marqueeRenderer = renderMarquee())
    116         marqueeRenderer->start();
    117 }
    118 
    119 void HTMLMarqueeElement::stop()
    120 {
    121     if (RenderMarquee* marqueeRenderer = renderMarquee())
    122         marqueeRenderer->stop();
    123 }
    124 
    125 bool HTMLMarqueeElement::canSuspend() const
    126 {
    127     return true;
    128 }
    129 
    130 void HTMLMarqueeElement::suspend()
    131 {
    132     if (RenderMarquee* marqueeRenderer = renderMarquee())
    133         marqueeRenderer->suspend();
    134 }
    135 
    136 void HTMLMarqueeElement::resume()
    137 {
    138     if (RenderMarquee* marqueeRenderer = renderMarquee())
    139         marqueeRenderer->updateMarqueePosition();
    140 }
    141 
    142 RenderMarquee* HTMLMarqueeElement::renderMarquee() const
    143 {
    144     if (renderer() && renderer()->hasLayer())
    145         return renderBoxModelObject()->layer()->marquee();
    146     return 0;
    147 }
    148 
    149 } // namespace WebCore
    150