2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2007, 2010 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.
24 #include "HTMLMarqueeElement.h"
26 #include "Attribute.h"
27 #include "CSSPropertyNames.h"
28 #include "CSSValueKeywords.h"
29 #include "ExceptionCode.h"
30 #include "HTMLNames.h"
31 #include "RenderLayer.h"
32 #include "RenderMarquee.h"
36 using namespace HTMLNames;
38 // WinIE uses 60ms as the minimum delay by default.
39 const int defaultMinimumDelay = 60;
41 inline HTMLMarqueeElement::HTMLMarqueeElement(const QualifiedName& tagName, Document* document)
42 : HTMLElement(tagName, document)
43 , ActiveDOMObject(document, this)
44 , m_minimumDelay(defaultMinimumDelay)
46 ASSERT(hasTagName(marqueeTag));
49 PassRefPtr<HTMLMarqueeElement> HTMLMarqueeElement::create(const QualifiedName& tagName, Document* document)
51 return adoptRef(new HTMLMarqueeElement(tagName, document));
54 bool HTMLMarqueeElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
56 if (attrName == widthAttr ||
57 attrName == heightAttr ||
58 attrName == bgcolorAttr ||
59 attrName == vspaceAttr ||
60 attrName == hspaceAttr ||
61 attrName == scrollamountAttr ||
62 attrName == scrolldelayAttr ||
63 attrName == loopAttr ||
64 attrName == behaviorAttr ||
65 attrName == directionAttr) {
70 return HTMLElement::mapToEntry(attrName, result);
73 void HTMLMarqueeElement::parseMappedAttribute(Attribute* attr)
75 if (attr->name() == widthAttr) {
76 if (!attr->value().isEmpty())
77 addCSSLength(attr, CSSPropertyWidth, attr->value());
78 } else if (attr->name() == heightAttr) {
79 if (!attr->value().isEmpty())
80 addCSSLength(attr, CSSPropertyHeight, attr->value());
81 } else if (attr->name() == bgcolorAttr) {
82 if (!attr->value().isEmpty())
83 addCSSColor(attr, CSSPropertyBackgroundColor, attr->value());
84 } else if (attr->name() == vspaceAttr) {
85 if (!attr->value().isEmpty()) {
86 addCSSLength(attr, CSSPropertyMarginTop, attr->value());
87 addCSSLength(attr, CSSPropertyMarginBottom, attr->value());
89 } else if (attr->name() == hspaceAttr) {
90 if (!attr->value().isEmpty()) {
91 addCSSLength(attr, CSSPropertyMarginLeft, attr->value());
92 addCSSLength(attr, CSSPropertyMarginRight, attr->value());
94 } else if (attr->name() == scrollamountAttr) {
95 if (!attr->value().isEmpty())
96 addCSSLength(attr, CSSPropertyWebkitMarqueeIncrement, attr->value());
97 } else if (attr->name() == scrolldelayAttr) {
98 if (!attr->value().isEmpty())
99 addCSSLength(attr, CSSPropertyWebkitMarqueeSpeed, attr->value());
100 } else if (attr->name() == loopAttr) {
101 if (!attr->value().isEmpty()) {
102 if (attr->value() == "-1" || equalIgnoringCase(attr->value(), "infinite"))
103 addCSSProperty(attr, CSSPropertyWebkitMarqueeRepetition, CSSValueInfinite);
105 addCSSLength(attr, CSSPropertyWebkitMarqueeRepetition, attr->value());
107 } else if (attr->name() == behaviorAttr) {
108 if (!attr->value().isEmpty())
109 addCSSProperty(attr, CSSPropertyWebkitMarqueeStyle, attr->value());
110 } else if (attr->name() == directionAttr) {
111 if (!attr->value().isEmpty())
112 addCSSProperty(attr, CSSPropertyWebkitMarqueeDirection, attr->value());
113 } else if (attr->name() == truespeedAttr)
114 m_minimumDelay = !attr->isEmpty() ? 0 : defaultMinimumDelay;
116 HTMLElement::parseMappedAttribute(attr);
119 void HTMLMarqueeElement::start()
121 if (RenderMarquee* marqueeRenderer = renderMarquee())
122 marqueeRenderer->start();
125 void HTMLMarqueeElement::stop()
127 if (RenderMarquee* marqueeRenderer = renderMarquee())
128 marqueeRenderer->stop();
131 int HTMLMarqueeElement::scrollAmount() const
134 int scrollAmount = fastGetAttribute(scrollamountAttr).toInt(&ok);
135 return ok && scrollAmount >= 0 ? scrollAmount : RenderStyle::initialMarqueeIncrement().value();
138 void HTMLMarqueeElement::setScrollAmount(int scrollAmount, ExceptionCode& ec)
140 if (scrollAmount < 0)
143 setIntegralAttribute(scrollamountAttr, scrollAmount);
146 int HTMLMarqueeElement::scrollDelay() const
149 int scrollDelay = fastGetAttribute(scrolldelayAttr).toInt(&ok);
150 return ok && scrollDelay >= 0 ? scrollDelay : RenderStyle::initialMarqueeSpeed();
153 void HTMLMarqueeElement::setScrollDelay(int scrollDelay, ExceptionCode& ec)
158 setIntegralAttribute(scrolldelayAttr, scrollDelay);
161 int HTMLMarqueeElement::loop() const
164 int loopValue = fastGetAttribute(loopAttr).toInt(&ok);
165 return ok && loopValue > 0 ? loopValue : -1;
168 void HTMLMarqueeElement::setLoop(int loop, ExceptionCode& ec)
170 if (loop <= 0 && loop != -1)
173 setIntegralAttribute(loopAttr, loop);
176 bool HTMLMarqueeElement::canSuspend() const
181 void HTMLMarqueeElement::suspend(ReasonForSuspension)
183 if (RenderMarquee* marqueeRenderer = renderMarquee())
184 marqueeRenderer->suspend();
187 void HTMLMarqueeElement::resume()
189 if (RenderMarquee* marqueeRenderer = renderMarquee())
190 marqueeRenderer->updateMarqueePosition();
193 RenderMarquee* HTMLMarqueeElement::renderMarquee() const
195 if (renderer() && renderer()->hasLayer())
196 return renderBoxModelObject()->layer()->marquee();
200 } // namespace WebCore