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, 2010 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 "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" 33 34 namespace WebCore { 35 36 using namespace HTMLNames; 37 38 // WinIE uses 60ms as the minimum delay by default. 39 const int defaultMinimumDelay = 60; 40 41 inline HTMLMarqueeElement::HTMLMarqueeElement(const QualifiedName& tagName, Document* document) 42 : HTMLElement(tagName, document) 43 , ActiveDOMObject(document, this) 44 , m_minimumDelay(defaultMinimumDelay) 45 { 46 ASSERT(hasTagName(marqueeTag)); 47 } 48 49 PassRefPtr<HTMLMarqueeElement> HTMLMarqueeElement::create(const QualifiedName& tagName, Document* document) 50 { 51 return adoptRef(new HTMLMarqueeElement(tagName, document)); 52 } 53 54 bool HTMLMarqueeElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const 55 { 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) { 66 result = eUniversal; 67 return false; 68 } 69 70 return HTMLElement::mapToEntry(attrName, result); 71 } 72 73 void HTMLMarqueeElement::parseMappedAttribute(Attribute* attr) 74 { 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()); 88 } 89 } else if (attr->name() == hspaceAttr) { 90 if (!attr->value().isEmpty()) { 91 addCSSLength(attr, CSSPropertyMarginLeft, attr->value()); 92 addCSSLength(attr, CSSPropertyMarginRight, attr->value()); 93 } 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); 104 else 105 addCSSLength(attr, CSSPropertyWebkitMarqueeRepetition, attr->value()); 106 } 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; 115 else 116 HTMLElement::parseMappedAttribute(attr); 117 } 118 119 void HTMLMarqueeElement::start() 120 { 121 if (RenderMarquee* marqueeRenderer = renderMarquee()) 122 marqueeRenderer->start(); 123 } 124 125 void HTMLMarqueeElement::stop() 126 { 127 if (RenderMarquee* marqueeRenderer = renderMarquee()) 128 marqueeRenderer->stop(); 129 } 130 131 int HTMLMarqueeElement::scrollAmount() const 132 { 133 bool ok; 134 int scrollAmount = fastGetAttribute(scrollamountAttr).toInt(&ok); 135 return ok && scrollAmount >= 0 ? scrollAmount : RenderStyle::initialMarqueeIncrement().value(); 136 } 137 138 void HTMLMarqueeElement::setScrollAmount(int scrollAmount, ExceptionCode& ec) 139 { 140 if (scrollAmount < 0) 141 ec = INDEX_SIZE_ERR; 142 else 143 setIntegralAttribute(scrollamountAttr, scrollAmount); 144 } 145 146 int HTMLMarqueeElement::scrollDelay() const 147 { 148 bool ok; 149 int scrollDelay = fastGetAttribute(scrolldelayAttr).toInt(&ok); 150 return ok && scrollDelay >= 0 ? scrollDelay : RenderStyle::initialMarqueeSpeed(); 151 } 152 153 void HTMLMarqueeElement::setScrollDelay(int scrollDelay, ExceptionCode& ec) 154 { 155 if (scrollDelay < 0) 156 ec = INDEX_SIZE_ERR; 157 else 158 setIntegralAttribute(scrolldelayAttr, scrollDelay); 159 } 160 161 int HTMLMarqueeElement::loop() const 162 { 163 bool ok; 164 int loopValue = fastGetAttribute(loopAttr).toInt(&ok); 165 return ok && loopValue > 0 ? loopValue : -1; 166 } 167 168 void HTMLMarqueeElement::setLoop(int loop, ExceptionCode& ec) 169 { 170 if (loop <= 0 && loop != -1) 171 ec = INDEX_SIZE_ERR; 172 else 173 setIntegralAttribute(loopAttr, loop); 174 } 175 176 bool HTMLMarqueeElement::canSuspend() const 177 { 178 return true; 179 } 180 181 void HTMLMarqueeElement::suspend(ReasonForSuspension) 182 { 183 if (RenderMarquee* marqueeRenderer = renderMarquee()) 184 marqueeRenderer->suspend(); 185 } 186 187 void HTMLMarqueeElement::resume() 188 { 189 if (RenderMarquee* marqueeRenderer = renderMarquee()) 190 marqueeRenderer->updateMarqueePosition(); 191 } 192 193 RenderMarquee* HTMLMarqueeElement::renderMarquee() const 194 { 195 if (renderer() && renderer()->hasLayer()) 196 return renderBoxModelObject()->layer()->marquee(); 197 return 0; 198 } 199 200 } // namespace WebCore 201