1 /**
2 * This file is part of the DOM implementation for KDE.
3 *
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * Copyright (C) 2003 Apple Computer, Inc.
7 *
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.
12 *
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.
17 *
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., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25 #include "config.h"
26 #include "HTMLPreElement.h"
27
28 #include "CSSPropertyNames.h"
29 #include "CSSValueKeywords.h"
30 #include "HTMLNames.h"
31 #include "MappedAttribute.h"
32
33 namespace WebCore {
34
35 using namespace HTMLNames;
36
HTMLPreElement(const QualifiedName & tagName,Document * doc)37 HTMLPreElement::HTMLPreElement(const QualifiedName& tagName, Document* doc)
38 : HTMLElement(tagName, doc)
39 {
40 }
41
mapToEntry(const QualifiedName & attrName,MappedAttributeEntry & result) const42 bool HTMLPreElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
43 {
44 if (attrName == widthAttr || attrName == wrapAttr) {
45 result = ePre;
46 return false;
47 }
48 return HTMLElement::mapToEntry(attrName, result);
49 }
50
parseMappedAttribute(MappedAttribute * attr)51 void HTMLPreElement::parseMappedAttribute(MappedAttribute *attr)
52 {
53 if (attr->name() == widthAttr) {
54 // FIXME: Implement this some day. Width on a <pre> is the # of characters that
55 // we should size the pre to. We basically need to take the width of a space,
56 // multiply by the value of the attribute and then set that as the width CSS
57 // property.
58 } else if (attr->name() == wrapAttr) {
59 if (!attr->value().isNull())
60 addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValuePreWrap);
61 } else
62 return HTMLElement::parseMappedAttribute(attr);
63 }
64
width() const65 int HTMLPreElement::width() const
66 {
67 return getAttribute(widthAttr).toInt();
68 }
69
setWidth(int width)70 void HTMLPreElement::setWidth(int width)
71 {
72 setAttribute(widthAttr, String::number(width));
73 }
74
wrap() const75 bool HTMLPreElement::wrap() const
76 {
77 return !getAttribute(wrapAttr).isNull();
78 }
79
setWrap(bool wrap)80 void HTMLPreElement::setWrap(bool wrap)
81 {
82 setAttribute(wrapAttr, wrap ? "" : 0);
83 }
84
85 }
86