OSDN Git Service

Merge WebKit at r65615 : Initial merge by git.
[android-x86/external-webkit.git] / WebCore / wml / WMLPElement.cpp
1 /**
2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3  *
4  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
6  *
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.
11  *
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.
16  *
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.
21  *
22  */
23
24 #include "config.h"
25
26 #if ENABLE(WML)
27 #include "WMLPElement.h"
28
29 #include "Attribute.h"
30 #include "CSSPropertyNames.h"
31 #include "CSSValueKeywords.h"
32 #include "Document.h"
33 #include "HTMLNames.h"
34 #include "NodeList.h"
35 #include "WMLNames.h"
36
37 namespace WebCore {
38
39 using namespace WMLNames;
40
41 WMLPElement::WMLPElement(const QualifiedName& tagName, Document* doc)
42     : WMLElement(tagName, doc)
43 {
44 }
45
46 bool WMLPElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
47 {
48     if (attrName == HTMLNames::alignAttr) {
49         result = eBlock; // We can share with DIV here.
50         return false;
51     }
52
53     return WMLElement::mapToEntry(attrName, result);
54 }
55
56 void WMLPElement::parseMappedAttribute(Attribute* attr)
57 {
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);
66         else
67             addCSSProperty(attr, CSSPropertyTextAlign, value);
68     } else if (attr->name() == modeAttr) {
69         m_mode = attr->value();
70         if (m_mode == "wrap")
71             addCSSProperty(attr, CSSPropertyWordWrap, CSSValueBreakWord);
72         else if (m_mode == "nowrap")
73             addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueNowrap);
74     } else
75         WMLElement::parseMappedAttribute(attr);
76 }
77
78 void WMLPElement::insertedIntoDocument()
79 {
80     WMLElement::insertedIntoDocument();
81
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())
86         return;
87
88     RefPtr<NodeList> nodeList = document()->getElementsByTagName("p");
89     if (!nodeList)
90         return;
91
92     unsigned length = nodeList->length();
93     if (length < 2)
94         return;
95
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)
99         return;
100
101     WMLPElement* lastParagraph = static_cast<WMLPElement*>(nodeList->item(length - 2));
102     ASSERT(lastParagraph);
103
104     String lastMode = lastParagraph->getAttribute(modeAttr);
105     if (lastMode.isEmpty() || lastMode == "wrap") // Default value, do nothing.
106         return;
107
108     setAttribute(modeAttr, lastMode);
109 }
110
111 }
112
113 #endif