Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / html / HTMLMarqueeElement.cpp
blob0cb650145265631488ad779d6d0569b71151e1f7
1 /**
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
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.
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.
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.
23 #include "config.h"
24 #include "HTMLMarqueeElement.h"
26 #include "CSSPropertyNames.h"
27 #include "CSSValueKeywords.h"
28 #include "HTMLNames.h"
29 #include "MappedAttribute.h"
30 #include "RenderLayer.h"
31 #include "RenderMarquee.h"
33 namespace WebCore {
35 using namespace HTMLNames;
37 // WinIE uses 60ms as the minimum delay by default.
38 const int defaultMinimumDelay = 60;
40 HTMLMarqueeElement::HTMLMarqueeElement(const QualifiedName& tagName, Document* doc)
41 : HTMLElement(tagName, doc)
42 , ActiveDOMObject(doc, this)
43 , m_minimumDelay(defaultMinimumDelay)
45 ASSERT(hasTagName(marqueeTag));
48 bool HTMLMarqueeElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
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;
64 return HTMLElement::mapToEntry(attrName, result);
67 void HTMLMarqueeElement::parseMappedAttribute(MappedAttribute *attr)
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());
83 } else if (attr->name() == hspaceAttr) {
84 if (!attr->value().isEmpty()) {
85 addCSSLength(attr, CSSPropertyMarginLeft, attr->value());
86 addCSSLength(attr, CSSPropertyMarginRight, attr->value());
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());
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);
113 void HTMLMarqueeElement::start()
115 if (renderer() && renderer()->hasLayer() && renderBox()->layer()->marquee())
116 renderBox()->layer()->marquee()->start();
119 void HTMLMarqueeElement::stop()
121 if (renderer() && renderer()->hasLayer() && renderBox()->layer()->marquee())
122 renderBox()->layer()->marquee()->stop();
125 bool HTMLMarqueeElement::canSuspend() const
127 return true;
130 void HTMLMarqueeElement::suspend()
132 if (renderer() && renderer()->hasLayer() && renderBox()->layer()->marquee())
133 renderBox()->layer()->marquee()->suspend();
136 void HTMLMarqueeElement::resume()
138 if (renderer() && renderer()->hasLayer() && renderBox()->layer()->marquee())
139 renderBox()->layer()->marquee()->updateMarqueePosition();
142 } // namespace WebCore