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 "core/html/HTMLMarqueeElement.h"
26 #include "CSSPropertyNames.h"
27 #include "CSSValueKeywords.h"
28 #include "HTMLNames.h"
29 #include "bindings/v8/ExceptionState.h"
30 #include "core/dom/ExceptionCode.h"
31 #include "core/rendering/RenderMarquee.h"
35 using namespace HTMLNames;
37 inline HTMLMarqueeElement::HTMLMarqueeElement(Document& document)
38 : HTMLElement(marqueeTag, document)
39 , ActiveDOMObject(&document)
41 ScriptWrappable::init(this);
44 PassRefPtrWillBeRawPtr<HTMLMarqueeElement> HTMLMarqueeElement::create(Document& document)
46 RefPtrWillBeRawPtr<HTMLMarqueeElement> marqueeElement(adoptRefWillBeRefCountedGarbageCollected(new HTMLMarqueeElement(document)));
47 marqueeElement->suspendIfNeeded();
48 return marqueeElement.release();
51 int HTMLMarqueeElement::minimumDelay() const
53 if (fastGetAttribute(truespeedAttr).isEmpty()) {
54 // WinIE uses 60ms as the minimum delay by default.
60 void HTMLMarqueeElement::didMoveToNewDocument(Document& oldDocument)
62 ActiveDOMObject::didMoveToNewExecutionContext(&document());
63 HTMLElement::didMoveToNewDocument(oldDocument);
66 bool HTMLMarqueeElement::isPresentationAttribute(const QualifiedName& name) const
68 if (name == widthAttr || name == heightAttr || name == bgcolorAttr || name == vspaceAttr || name == hspaceAttr || name == scrollamountAttr || name == scrolldelayAttr || name == loopAttr || name == behaviorAttr || name == directionAttr)
70 return HTMLElement::isPresentationAttribute(name);
73 void HTMLMarqueeElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
75 if (name == widthAttr) {
77 addHTMLLengthToStyle(style, CSSPropertyWidth, value);
78 } else if (name == heightAttr) {
80 addHTMLLengthToStyle(style, CSSPropertyHeight, value);
81 } else if (name == bgcolorAttr) {
83 addHTMLColorToStyle(style, CSSPropertyBackgroundColor, value);
84 } else if (name == vspaceAttr) {
85 if (!value.isEmpty()) {
86 addHTMLLengthToStyle(style, CSSPropertyMarginTop, value);
87 addHTMLLengthToStyle(style, CSSPropertyMarginBottom, value);
89 } else if (name == hspaceAttr) {
90 if (!value.isEmpty()) {
91 addHTMLLengthToStyle(style, CSSPropertyMarginLeft, value);
92 addHTMLLengthToStyle(style, CSSPropertyMarginRight, value);
94 } else if (name == scrollamountAttr) {
96 addHTMLLengthToStyle(style, CSSPropertyInternalMarqueeIncrement, value);
97 } else if (name == scrolldelayAttr) {
99 addHTMLLengthToStyle(style, CSSPropertyInternalMarqueeSpeed, value);
100 } else if (name == loopAttr) {
101 if (!value.isEmpty()) {
102 if (value == "-1" || equalIgnoringCase(value, "infinite"))
103 addPropertyToPresentationAttributeStyle(style, CSSPropertyInternalMarqueeRepetition, CSSValueInfinite);
105 addHTMLLengthToStyle(style, CSSPropertyInternalMarqueeRepetition, value);
107 } else if (name == behaviorAttr) {
108 if (!value.isEmpty())
109 addPropertyToPresentationAttributeStyle(style, CSSPropertyInternalMarqueeStyle, value);
110 } else if (name == directionAttr) {
111 if (!value.isEmpty())
112 addPropertyToPresentationAttributeStyle(style, CSSPropertyInternalMarqueeDirection, value);
114 HTMLElement::collectStyleForPresentationAttribute(name, value, style);
117 void HTMLMarqueeElement::start()
119 if (RenderMarquee* marqueeRenderer = renderMarquee())
120 marqueeRenderer->start();
123 void HTMLMarqueeElement::stop()
125 if (RenderMarquee* marqueeRenderer = renderMarquee())
126 marqueeRenderer->stop();
129 int HTMLMarqueeElement::scrollAmount() const
132 int scrollAmount = fastGetAttribute(scrollamountAttr).toInt(&ok);
133 return ok && scrollAmount >= 0 ? scrollAmount : RenderStyle::initialMarqueeIncrement().intValue();
136 void HTMLMarqueeElement::setScrollAmount(int scrollAmount, ExceptionState& exceptionState)
138 if (scrollAmount < 0)
139 exceptionState.throwDOMException(IndexSizeError, "The provided value (" + String::number(scrollAmount) + ") is negative.");
141 setIntegralAttribute(scrollamountAttr, scrollAmount);
144 int HTMLMarqueeElement::scrollDelay() const
147 int scrollDelay = fastGetAttribute(scrolldelayAttr).toInt(&ok);
148 return ok && scrollDelay >= 0 ? scrollDelay : RenderStyle::initialMarqueeSpeed();
151 void HTMLMarqueeElement::setScrollDelay(int scrollDelay, ExceptionState& exceptionState)
154 exceptionState.throwDOMException(IndexSizeError, "The provided value (" + String::number(scrollDelay) + ") is negative.");
156 setIntegralAttribute(scrolldelayAttr, scrollDelay);
159 int HTMLMarqueeElement::loop() const
162 int loopValue = fastGetAttribute(loopAttr).toInt(&ok);
163 return ok && loopValue > 0 ? loopValue : -1;
166 void HTMLMarqueeElement::setLoop(int loop, ExceptionState& exceptionState)
168 if (loop <= 0 && loop != -1)
169 exceptionState.throwDOMException(IndexSizeError, "The provided value (" + String::number(loop) + ") is neither positive nor -1.");
171 setIntegralAttribute(loopAttr, loop);
174 void HTMLMarqueeElement::suspend()
176 if (RenderMarquee* marqueeRenderer = renderMarquee())
177 marqueeRenderer->suspend();
180 void HTMLMarqueeElement::resume()
182 if (RenderMarquee* marqueeRenderer = renderMarquee())
183 marqueeRenderer->updateMarqueePosition();
186 RenderMarquee* HTMLMarqueeElement::renderMarquee() const
188 if (renderer() && renderer()->isMarquee())
189 return toRenderMarquee(renderer());
193 RenderObject* HTMLMarqueeElement::createRenderer(RenderStyle*)
195 return new RenderMarquee(this);
198 void HTMLMarqueeElement::timerFired(Timer<HTMLMarqueeElement>*)
203 document().updateLayout();
205 // The updateLayout() could have destroyed renderer(), so this re-check is very important.
207 toRenderMarquee(renderer())->timerFired();
210 } // namespace WebCore