2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
27 #include "WMLPElement.h"
29 #include "Attribute.h"
30 #include "CSSPropertyNames.h"
31 #include "CSSValueKeywords.h"
33 #include "HTMLNames.h"
39 using namespace WMLNames;
41 WMLPElement::WMLPElement(const QualifiedName& tagName, Document* doc)
42 : WMLElement(tagName, doc)
46 bool WMLPElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
48 if (attrName == HTMLNames::alignAttr) {
49 result = eBlock; // We can share with DIV here.
53 return WMLElement::mapToEntry(attrName, result);
56 void WMLPElement::parseMappedAttribute(Attribute* attr)
58 if (attr->name() == HTMLNames::alignAttr) {
59 const AtomicString& value = attr->value();
60 if (equalIgnoringCase(value, "middle") || equalIgnoringCase(value, "center"))
61 addCSSProperty(attr, CSSPropertyTextAlign, CSSValueWebkitCenter);
62 else if (equalIgnoringCase(value, "left"))
63 addCSSProperty(attr, CSSPropertyTextAlign, CSSValueWebkitLeft);
64 else if (equalIgnoringCase(value, "right"))
65 addCSSProperty(attr, CSSPropertyTextAlign, CSSValueWebkitRight);
67 addCSSProperty(attr, CSSPropertyTextAlign, value);
68 } else if (attr->name() == modeAttr) {
69 m_mode = attr->value();
71 addCSSProperty(attr, CSSPropertyWordWrap, CSSValueBreakWord);
72 else if (m_mode == "nowrap")
73 addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueNowrap);
75 WMLElement::parseMappedAttribute(attr);
78 void WMLPElement::insertedIntoDocument()
80 WMLElement::insertedIntoDocument();
82 // If not explicitly specified, the linewrap mode is identical to
83 // the line-wrap mode of the previous paragraph in the text flow of
84 // a card. The default mode for the first paragraph in a card is wrap.
85 if (!m_mode.isEmpty())
88 RefPtr<NodeList> nodeList = document()->getElementsByTagName("p");
92 unsigned length = nodeList->length();
96 // Assure we're the last inserted paragraph element
97 // This only works while parsing, otherwhise this statement is never true.
98 if (nodeList->item(length - 1) != this)
101 WMLPElement* lastParagraph = static_cast<WMLPElement*>(nodeList->item(length - 2));
102 ASSERT(lastParagraph);
104 String lastMode = lastParagraph->getAttribute(modeAttr);
105 if (lastMode.isEmpty() || lastMode == "wrap") // Default value, do nothing.
108 setAttribute(modeAttr, lastMode);