2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * Copyright (C) 2003 Apple Computer, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 // -------------------------------------------------------------------------
26 #include "html_blockimpl.h"
27 #include "html_documentimpl.h"
28 #include "css/cssstyleselector.h"
30 #include "css/cssproperties.h"
31 #include "css/cssvalues.h"
32 #include "misc/htmlhashes.h"
36 using namespace khtml;
39 HTMLBlockquoteElementImpl::HTMLBlockquoteElementImpl(DocumentPtr *doc)
40 : HTMLElementImpl(HTMLNames::blockquote(), doc)
44 HTMLBlockquoteElementImpl::~HTMLBlockquoteElementImpl()
48 DOMString HTMLBlockquoteElementImpl::cite() const
50 return getAttribute(ATTR_CITE);
53 void HTMLBlockquoteElementImpl::setCite(const DOMString &value)
55 setAttribute(ATTR_CITE, value);
58 // -------------------------------------------------------------------------
60 HTMLDivElementImpl::HTMLDivElementImpl(DocumentPtr *doc)
61 : HTMLElementImpl(HTMLNames::div(), doc)
65 HTMLDivElementImpl::~HTMLDivElementImpl()
69 bool HTMLDivElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
71 if (attr == ATTR_ALIGN) {
75 return HTMLElementImpl::mapToEntry(attr, result);
78 void HTMLDivElementImpl::parseMappedAttribute(MappedAttributeImpl *attr)
84 DOMString v = attr->value();
85 if ( strcasecmp( attr->value(), "middle" ) == 0 || strcasecmp( attr->value(), "center" ) == 0 )
86 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, CSS_VAL__KHTML_CENTER);
87 else if (strcasecmp(attr->value(), "left") == 0)
88 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, CSS_VAL__KHTML_LEFT);
89 else if (strcasecmp(attr->value(), "right") == 0)
90 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, CSS_VAL__KHTML_RIGHT);
92 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, v);
96 HTMLElementImpl::parseMappedAttribute(attr);
100 DOMString HTMLDivElementImpl::align() const
102 return getAttribute(ATTR_ALIGN);
105 void HTMLDivElementImpl::setAlign(const DOMString &value)
107 setAttribute(ATTR_ALIGN, value);
110 // -------------------------------------------------------------------------
112 HTMLHRElementImpl::HTMLHRElementImpl(DocumentPtr *doc)
113 : HTMLElementImpl(HTMLNames::hr(), doc)
117 HTMLHRElementImpl::~HTMLHRElementImpl()
121 bool HTMLHRElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
134 return HTMLElementImpl::mapToEntry(attr, result);
137 void HTMLHRElementImpl::parseMappedAttribute(MappedAttributeImpl *attr)
142 if (strcasecmp(attr->value(), "left") == 0) {
143 addCSSProperty(attr, CSS_PROP_MARGIN_LEFT, "0");
144 addCSSProperty(attr, CSS_PROP_MARGIN_RIGHT, CSS_VAL_AUTO);
146 else if (strcasecmp(attr->value(), "right") == 0) {
147 addCSSProperty(attr, CSS_PROP_MARGIN_LEFT, CSS_VAL_AUTO);
148 addCSSProperty(attr, CSS_PROP_MARGIN_RIGHT, "0");
151 addCSSProperty(attr, CSS_PROP_MARGIN_LEFT, CSS_VAL_AUTO);
152 addCSSProperty(attr, CSS_PROP_MARGIN_RIGHT, CSS_VAL_AUTO);
158 // cheap hack to cause linebreaks
159 // khtmltests/html/strange_hr.html
161 int v = attr->value().implementation()->toInt(&ok);
163 addCSSLength(attr, CSS_PROP_WIDTH, "1");
165 addCSSLength(attr, CSS_PROP_WIDTH, attr->value());
169 addCSSProperty(attr, CSS_PROP_BORDER_TOP_STYLE, CSS_VAL_SOLID);
170 addCSSProperty(attr, CSS_PROP_BORDER_RIGHT_STYLE, CSS_VAL_SOLID);
171 addCSSProperty(attr, CSS_PROP_BORDER_BOTTOM_STYLE, CSS_VAL_SOLID);
172 addCSSProperty(attr, CSS_PROP_BORDER_LEFT_STYLE, CSS_VAL_SOLID);
173 addCSSColor(attr, CSS_PROP_BORDER_COLOR, attr->value());
174 addCSSColor(attr, CSS_PROP_BACKGROUND_COLOR, attr->value());
177 addCSSProperty(attr, CSS_PROP_BORDER_TOP_STYLE, CSS_VAL_SOLID);
178 addCSSProperty(attr, CSS_PROP_BORDER_RIGHT_STYLE, CSS_VAL_SOLID);
179 addCSSProperty(attr, CSS_PROP_BORDER_BOTTOM_STYLE, CSS_VAL_SOLID);
180 addCSSProperty(attr, CSS_PROP_BORDER_LEFT_STYLE, CSS_VAL_SOLID);
181 addCSSColor(attr, CSS_PROP_BORDER_COLOR, DOMString("grey"));
182 addCSSColor(attr, CSS_PROP_BACKGROUND_COLOR, DOMString("grey"));
185 DOMStringImpl* si = attr->value().implementation();
186 int size = si->toInt();
188 addCSSProperty(attr, CSS_PROP_BORDER_BOTTOM_WIDTH, DOMString("0"));
190 addCSSLength(attr, CSS_PROP_HEIGHT, DOMString(QString::number(size-2)));
194 HTMLElementImpl::parseMappedAttribute(attr);
198 DOMString HTMLHRElementImpl::align() const
200 return getAttribute(ATTR_ALIGN);
203 void HTMLHRElementImpl::setAlign(const DOMString &value)
205 setAttribute(ATTR_ALIGN, value);
208 bool HTMLHRElementImpl::noShade() const
210 return !getAttribute(ATTR_NOSHADE).isNull();
213 void HTMLHRElementImpl::setNoShade(bool noShade)
215 setAttribute(ATTR_NOSHADE, noShade ? "" : 0);
218 DOMString HTMLHRElementImpl::size() const
220 return getAttribute(ATTR_SIZE);
223 void HTMLHRElementImpl::setSize(const DOMString &value)
225 setAttribute(ATTR_SIZE, value);
228 DOMString HTMLHRElementImpl::width() const
230 return getAttribute(ATTR_WIDTH);
233 void HTMLHRElementImpl::setWidth(const DOMString &value)
235 setAttribute(ATTR_WIDTH, value);
238 // -------------------------------------------------------------------------
240 HTMLHeadingElementImpl::HTMLHeadingElementImpl(const QualifiedName& tagName, DocumentPtr *doc)
241 : HTMLElementImpl(tagName, doc)
245 bool HTMLHeadingElementImpl::checkDTD(const NodeImpl* newChild)
247 if (newChild->hasTagName(HTMLNames::h1()) || newChild->hasTagName(HTMLNames::h2()) ||
248 newChild->hasTagName(HTMLNames::h3()) || newChild->hasTagName(HTMLNames::h4()) ||
249 newChild->hasTagName(HTMLNames::h5()) || newChild->hasTagName(HTMLNames::h6()))
252 return inEitherTagList(newChild);
255 DOMString HTMLHeadingElementImpl::align() const
257 return getAttribute(ATTR_ALIGN);
260 void HTMLHeadingElementImpl::setAlign(const DOMString &value)
262 setAttribute(ATTR_ALIGN, value);
265 // -------------------------------------------------------------------------
267 HTMLParagraphElementImpl::HTMLParagraphElementImpl(DocumentPtr *doc)
268 : HTMLElementImpl(HTMLNames::p(), doc)
272 bool HTMLParagraphElementImpl::checkDTD(const NodeImpl* newChild)
274 return inInlineTagList(newChild) || (getDocument()->inCompatMode() && newChild->hasTagName(HTMLNames::table()));
277 bool HTMLParagraphElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
279 if (attr == ATTR_ALIGN) {
280 result = eBlock; // We can share with DIV here.
283 return HTMLElementImpl::mapToEntry(attr, result);
286 void HTMLParagraphElementImpl::parseMappedAttribute(MappedAttributeImpl *attr)
292 DOMString v = attr->value();
293 if ( strcasecmp( attr->value(), "middle" ) == 0 || strcasecmp( attr->value(), "center" ) == 0 )
294 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, CSS_VAL__KHTML_CENTER);
295 else if (strcasecmp(attr->value(), "left") == 0)
296 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, CSS_VAL__KHTML_LEFT);
297 else if (strcasecmp(attr->value(), "right") == 0)
298 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, CSS_VAL__KHTML_RIGHT);
300 addCSSProperty(attr, CSS_PROP_TEXT_ALIGN, v);
304 HTMLElementImpl::parseMappedAttribute(attr);
308 DOMString HTMLParagraphElementImpl::align() const
310 return getAttribute(ATTR_ALIGN);
313 void HTMLParagraphElementImpl::setAlign(const DOMString &value)
315 setAttribute(ATTR_ALIGN, value);
318 // -------------------------------------------------------------------------
320 HTMLPreElementImpl::HTMLPreElementImpl(const QualifiedName& tagName, DocumentPtr *doc)
321 : HTMLElementImpl(tagName, doc)
325 long HTMLPreElementImpl::width() const
327 return getAttribute(ATTR_WIDTH).toInt();
330 void HTMLPreElementImpl::setWidth(long width)
332 setAttribute(ATTR_WIDTH, QString::number(width));
335 // -------------------------------------------------------------------------
337 // WinIE uses 60ms as the minimum delay by default.
338 const int defaultMinimumDelay = 60;
340 HTMLMarqueeElementImpl::HTMLMarqueeElementImpl(DocumentPtr *doc)
341 : HTMLElementImpl(HTMLNames::marquee(), doc),
342 m_minimumDelay(defaultMinimumDelay)
346 bool HTMLMarqueeElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
350 // Needed to create eMarquee hash key to treat height attribute like WinIE. Fix for half of 4172312.
357 case ATTR_SCROLLAMOUNT:
358 case ATTR_SCROLLDELAY:
367 return HTMLElementImpl::mapToEntry(attr, result);
371 void HTMLMarqueeElementImpl::parseMappedAttribute(MappedAttributeImpl *attr)
376 if (!attr->value().isEmpty())
377 addCSSLength(attr, CSS_PROP_WIDTH, attr->value());
380 if (!attr->value().isEmpty())
381 addCSSLength(attr, CSS_PROP_MIN_HEIGHT, attr->value());
384 if (!attr->value().isEmpty())
385 addCSSColor(attr, CSS_PROP_BACKGROUND_COLOR, attr->value());
388 if (!attr->value().isEmpty()) {
389 addCSSLength(attr, CSS_PROP_MARGIN_TOP, attr->value());
390 addCSSLength(attr, CSS_PROP_MARGIN_BOTTOM, attr->value());
394 if (!attr->value().isEmpty()) {
395 addCSSLength(attr, CSS_PROP_MARGIN_LEFT, attr->value());
396 addCSSLength(attr, CSS_PROP_MARGIN_RIGHT, attr->value());
399 case ATTR_SCROLLAMOUNT:
400 if (!attr->value().isEmpty())
401 addCSSLength(attr, CSS_PROP__KHTML_MARQUEE_INCREMENT, attr->value());
403 case ATTR_SCROLLDELAY:
404 if (!attr->value().isEmpty())
405 addCSSLength(attr, CSS_PROP__KHTML_MARQUEE_SPEED, attr->value());
408 if (!attr->value().isEmpty()) {
409 if (attr->value() == "-1" || strcasecmp(attr->value(), "infinite") == 0)
410 addCSSProperty(attr, CSS_PROP__KHTML_MARQUEE_REPETITION, CSS_VAL_INFINITE);
412 addCSSLength(attr, CSS_PROP__KHTML_MARQUEE_REPETITION, attr->value());
416 if (!attr->value().isEmpty())
417 addCSSProperty(attr, CSS_PROP__KHTML_MARQUEE_STYLE, attr->value());
420 if (!attr->value().isEmpty())
421 addCSSProperty(attr, CSS_PROP__KHTML_MARQUEE_DIRECTION, attr->value());
424 m_minimumDelay = !attr->isNull() ? 0 : defaultMinimumDelay;
427 HTMLElementImpl::parseMappedAttribute(attr);