diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:34:13 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:34:13 (GMT) |
commit | 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 (patch) | |
tree | 1dbf50b3dff8d5ca7e9344733968c72704eb15ff /src/3rdparty/webkit/WebCore/wml | |
download | Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.zip Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.gz Qt-67ad0519fd165acee4a4d2a94fa502e9e4847bd0.tar.bz2 |
Long live Qt!
Diffstat (limited to 'src/3rdparty/webkit/WebCore/wml')
64 files changed, 5258 insertions, 0 deletions
diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLAElement.cpp new file mode 100644 index 0000000..b3a8ecc --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAElement.cpp @@ -0,0 +1,178 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved. + * (C) 2006 Graham Dennis (graham.dennis@gmail.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLAElement.h" + +#include "DNS.h" +#include "Event.h" +#include "EventHandler.h" +#include "EventNames.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLNames.h" +#include "KeyboardEvent.h" +#include "MouseEvent.h" +#include "RenderFlow.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLAElement::WMLAElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +void WMLAElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::hrefAttr) { + bool wasLink = isLink(); + setIsLink(!attr->isNull()); + if (wasLink != isLink()) + setChanged(); + if (isLink() && document()->isDNSPrefetchEnabled()) { + String value = attr->value(); + if (protocolIs(value, "http") || protocolIs(value, "https") || value.startsWith("//")) + prefetchDNS(document()->completeURL(value).host()); + } + } else if (attr->name() == HTMLNames::nameAttr + || attr->name() == HTMLNames::titleAttr + || attr->name() == HTMLNames::relAttr) { + // Do nothing. + } else + WMLElement::parseMappedAttribute(attr); +} + +bool WMLAElement::supportsFocus() const +{ + return isFocusable() || (isLink() && document() && !document()->haveStylesheetsLoaded()); +} + +bool WMLAElement::isFocusable() const +{ + // FIXME: Even if we are not visible, we might have a child that is visible. + // Dave wants to fix that some day with a "has visible content" flag or the like. + if (!(isLink() && renderer() && renderer()->style()->visibility() == VISIBLE)) + return false; + + return true; +} + +bool WMLAElement::isMouseFocusable() const +{ + return false; +} + +bool WMLAElement::isKeyboardFocusable(KeyboardEvent* event) const +{ + if (!isFocusable()) + return false; + + if (!document()->frame()) + return false; + + if (!document()->frame()->eventHandler()->tabsToLinks(event)) + return false; + + // Before calling absoluteRects, check for the common case where the renderer + // or one of the continuations is non-empty, since this is a faster check and + // almost always returns true. + for (RenderObject* r = renderer(); r; r = r->continuation()) + if (r->width() > 0 && r->height() > 0) + return true; + + Vector<IntRect> rects; + FloatPoint absPos = renderer()->localToAbsolute(); + renderer()->absoluteRects(rects, absPos.x(), absPos.y()); + size_t n = rects.size(); + for (size_t i = 0; i < n; ++i) + if (!rects[i].isEmpty()) + return true; + + return false; +} + +void WMLAElement::defaultEventHandler(Event* event) +{ + if (isLink() && (event->type() == eventNames().clickEvent || (event->type() == eventNames().keydownEvent && focused()))) { + MouseEvent* e = 0; + if (event->type() == eventNames().clickEvent && event->isMouseEvent()) + e = static_cast<MouseEvent*>(event); + + KeyboardEvent* k = 0; + if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent()) + k = static_cast<KeyboardEvent*>(event); + + if (e && e->button() == RightButton) { + WMLElement::defaultEventHandler(event); + return; + } + + if (k) { + if (k->keyIdentifier() != "Enter") { + WMLElement::defaultEventHandler(event); + return; + } + + event->setDefaultHandled(); + dispatchSimulatedClick(event); + return; + } + + if (!event->defaultPrevented() && document()->frame()) { + KURL url = document()->completeURL(parseURL(getAttribute(HTMLNames::hrefAttr))); + document()->frame()->loader()->urlSelected(url, target(), event, false, true); + } + + event->setDefaultHandled(); + } + + WMLElement::defaultEventHandler(event); +} + +void WMLAElement::accessKeyAction(bool sendToAnyElement) +{ + // send the mouse button events if the caller specified sendToAnyElement + dispatchSimulatedClick(0, sendToAnyElement); +} + +bool WMLAElement::isURLAttribute(Attribute *attr) const +{ + return attr->name() == HTMLNames::hrefAttr; +} + +String WMLAElement::target() const +{ + return getAttribute(HTMLNames::targetAttr); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAElement.h b/src/3rdparty/webkit/WebCore/wml/WMLAElement.h new file mode 100644 index 0000000..3eece4c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAElement.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLAElement_h +#define WMLAElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLAElement : public WMLElement { +public: + WMLAElement(const QualifiedName& tagName, Document*); + + virtual bool supportsFocus() const; + virtual bool isFocusable() const; + virtual bool isMouseFocusable() const; + virtual bool isKeyboardFocusable(KeyboardEvent*) const; + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void defaultEventHandler(Event*); + + virtual void accessKeyAction(bool fullAction); + virtual bool isURLAttribute(Attribute*) const; + + virtual String target() const; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAccessElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLAccessElement.cpp new file mode 100644 index 0000000..7668c74 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAccessElement.cpp @@ -0,0 +1,70 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLAccessElement.h" + +#include "WMLDocument.h" +#include "WMLNames.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLAccessElement::WMLAccessElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +void WMLAccessElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == domainAttr) { + String value = parseValueForbiddingVariableReferences(attr->value()); + if (value.isEmpty()) + return; + + if (WMLPageState* pageState = wmlPageStateForDocument(document())) + pageState->restrictDeckAccessToDomain(value); + } else if (attr->name() == pathAttr) { + String value = parseValueForbiddingVariableReferences(attr->value()); + if (value.isEmpty()) + return; + + if (WMLPageState* pageState = wmlPageStateForDocument(document())) + pageState->restrictDeckAccessToPath(value); + } else + WMLElement::parseMappedAttribute(attr); +} + +void WMLAccessElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (pageState && !pageState->setNeedCheckDeckAccess(true)) + reportWMLError(document(), WMLErrorMultipleAccessElements); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAccessElement.h b/src/3rdparty/webkit/WebCore/wml/WMLAccessElement.h new file mode 100644 index 0000000..023d113 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAccessElement.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLAccessElement_h +#define WMLAccessElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLAccessElement : public WMLElement { +public: + WMLAccessElement(const QualifiedName& tagName, Document*); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAnchorElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLAnchorElement.cpp new file mode 100644 index 0000000..300cbf6 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAnchorElement.cpp @@ -0,0 +1,67 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLAnchorElement.h" + +#include "EventNames.h" +#include "KeyboardEvent.h" +#include "WMLTaskElement.h" +#include "HTMLNames.h" + +namespace WebCore { + +WMLAnchorElement::WMLAnchorElement(const QualifiedName& tagName, Document* doc) + : WMLAElement(tagName, doc) +{ + // Calling setIsLink(true), and returning a non-null value on CSSStyleSelectors' linkAttribute + // method, makes it possible to 'appear as link' (just like <a href="..">) without the need to + // actually set the href value to an empty value in the DOM tree. + setIsLink(true); +} + +WMLAnchorElement::~WMLAnchorElement() +{ +} + +void WMLAnchorElement::defaultEventHandler(Event* event) +{ + bool shouldHandle = false; + + if (event->type() == eventNames().clickEvent) + shouldHandle = true; + else if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent() && focused()) + shouldHandle = static_cast<KeyboardEvent*>(event)->keyIdentifier() == "Enter"; + + if (shouldHandle && m_task) { + m_task->executeTask(event); + event->setDefaultHandled(); + return; + } + + // Skip WMLAElement::defaultEventHandler, we don't own a href attribute, that needs to be handled. + WMLElement::defaultEventHandler(event); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAnchorElement.h b/src/3rdparty/webkit/WebCore/wml/WMLAnchorElement.h new file mode 100644 index 0000000..f4afee4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAnchorElement.h @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLAnchorElement_h +#define WMLAnchorElement_h + +#if ENABLE(WML) +#include "WMLAElement.h" + +namespace WebCore { + +class WMLTaskElement; + +class WMLAnchorElement : public WMLAElement { +public: + WMLAnchorElement(const QualifiedName& tagName, Document*); + virtual ~WMLAnchorElement(); + + virtual void defaultEventHandler(Event*); + +private: + friend class WMLTaskElement; + void registerTask(WMLTaskElement* task) { m_task = task; } + + WMLTaskElement* m_task; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLAttributeNames.in b/src/3rdparty/webkit/WebCore/wml/WMLAttributeNames.in new file mode 100644 index 0000000..9c0e8c5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLAttributeNames.in @@ -0,0 +1,24 @@ +namespace="WML" +namespaceURI="http://www.wapforum.org/DTD/wml_1.1.xml" +guardFactoryWith="ENABLE(WML)" +attrsNullNamespace="1" + +cache_control +columns +domain +emptyok +format +forua +iname +ivalue +localsrc +mode +newcontext +onenterbackward +onenterforward +onpick +ontimer +optional +ordered +path +sendreferer diff --git a/src/3rdparty/webkit/WebCore/wml/WMLBRElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLBRElement.cpp new file mode 100644 index 0000000..7bd6360 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLBRElement.cpp @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2003, 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLBRElement.h" + +#include "CSSPropertyNames.h" +#include "HTMLNames.h" +#include "RenderBR.h" + +namespace WebCore { + +WMLBRElement::WMLBRElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +bool WMLBRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const +{ + if (attrName == HTMLNames::clearAttr) { + result = eUniversal; + return false; + } + + return WMLElement::mapToEntry(attrName, result); +} + +void WMLBRElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::clearAttr) { + // If the string is empty, then don't add the clear property. + // <br clear> and <br clear=""> are just treated like <br> by Gecko, Mac IE, etc. -dwh + const AtomicString& value = attr->value(); + if (value.isEmpty()) + return; + + if (equalIgnoringCase(value, "all")) + addCSSProperty(attr, CSSPropertyClear, "both"); + else + addCSSProperty(attr, CSSPropertyClear, value); + } else + WMLElement::parseMappedAttribute(attr); +} + +RenderObject* WMLBRElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderBR(this); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLBRElement.h b/src/3rdparty/webkit/WebCore/wml/WMLBRElement.h new file mode 100644 index 0000000..4d65ed4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLBRElement.h @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Simon Hausmann <hausmann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLBRElement_h +#define WMLBRElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLBRElement : public WMLElement { +public: + WMLBRElement(const QualifiedName& tagName, Document*); + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(MappedAttribute*); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLCardElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLCardElement.cpp new file mode 100644 index 0000000..a2555a4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLCardElement.cpp @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLCardElement.h" + +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLNames.h" +#include "NodeList.h" +#include "RenderStyle.h" +#include "WMLDocument.h" +#include "WMLDoElement.h" +#include "WMLIntrinsicEventHandler.h" +#include "WMLNames.h" +#include "WMLTemplateElement.h" +#include "WMLTimerElement.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLCardElement::WMLCardElement(const QualifiedName& tagName, Document* doc) + : WMLEventHandlingElement(tagName, doc) + , m_isNewContext(false) + , m_isOrdered(false) + , m_isVisible(false) + , m_eventTimer(0) + , m_template(0) +{ +} + +WMLCardElement::~WMLCardElement() +{ +} + +void WMLCardElement::showCard() +{ + ASSERT(attached()); + + if (m_isVisible) { + ASSERT(renderer()); + return; + } + + m_isVisible = true; + ASSERT(!renderer()); + + detach(); + attach(); + + ASSERT(attached()); + ASSERT(renderer()); +} + +void WMLCardElement::hideCard() +{ + ASSERT(attached()); + + if (!m_isVisible) { + ASSERT(!renderer()); + return; + } + + m_isVisible = false; + ASSERT(renderer()); + + detach(); + attach(); + + ASSERT(attached()); + ASSERT(!renderer()); +} + +void WMLCardElement::setTemplateElement(WMLTemplateElement* temp) +{ + // Only one template is allowed to be attached to a card + if (m_template) { + reportWMLError(document(), WMLErrorMultipleTemplateElements); + return; + } + + m_template = temp; +} + +void WMLCardElement::setIntrinsicEventTimer(WMLTimerElement* timer) +{ + // Only one timer is allowed in a card + if (m_eventTimer) { + reportWMLError(document(), WMLErrorMultipleTimerElements); + return; + } + + m_eventTimer = timer; +} + +void WMLCardElement::handleIntrinsicEventIfNeeded() +{ + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (!pageState) + return; + + Frame* frame = document()->frame(); + if (!frame) + return; + + FrameLoader* loader = frame->loader(); + if (!loader) + return; + + int currentHistoryLength = loader->getHistoryLength(); + int lastHistoryLength = pageState->historyLength(); + + // Calculate the entry method of current card + WMLIntrinsicEventType eventType = WMLIntrinsicEventUnknown; + if (lastHistoryLength > currentHistoryLength) + eventType = WMLIntrinsicEventOnEnterBackward; + else if (lastHistoryLength < currentHistoryLength) + eventType = WMLIntrinsicEventOnEnterForward; + + // Synchronize history length with WMLPageState + pageState->setHistoryLength(currentHistoryLength); + + // Figure out target event handler + WMLIntrinsicEventHandler* eventHandler = this->eventHandler(); + bool hasIntrinsicEvent = false; + + if (eventType != WMLIntrinsicEventUnknown) { + if (eventHandler && eventHandler->hasIntrinsicEvent(eventType)) + hasIntrinsicEvent = true; + else if (m_template) { + eventHandler = m_template->eventHandler(); + if (eventHandler && eventHandler->hasIntrinsicEvent(eventType)) + hasIntrinsicEvent = true; + } + } + + if (hasIntrinsicEvent) + eventHandler->triggerIntrinsicEvent(eventType); + + // Start the timer if it exists in current card + if (m_eventTimer) + m_eventTimer->start(); + + // FIXME: Initialize input/select elements in this card + /* + Node* node = this; + while (node = node->traverseNextNode()) { + if (node->hasTagName(inputTag)) + static_cast<WMLInputElement*>(node)->init(); + else if (node->hasTagName(selectTag)) + static_cast<WMLSelectElement*>(node)->selectInitialOptions(); + } + */ +} + +void WMLCardElement::handleDeckLevelTaskOverridesIfNeeded() +{ + // Spec: The event-handling element may appear inside a template element and specify + // event-processing behaviour for all cards in the deck. A deck-level event-handling + // element is equivalent to specifying the event-handling element in each card. + if (!m_template) + return; + + Vector<WMLDoElement*>& templateDoElements = m_template->doElements(); + if (templateDoElements.isEmpty()) + return; + + Vector<WMLDoElement*>& cardDoElements = doElements(); + Vector<WMLDoElement*>::iterator it = cardDoElements.begin(); + Vector<WMLDoElement*>::iterator end = cardDoElements.end(); + + HashSet<String> cardDoElementNames; + for (; it != end; ++it) + cardDoElementNames.add((*it)->name()); + + it = templateDoElements.begin(); + end = templateDoElements.end(); + + for (; it != end; ++it) + (*it)->setActive(!cardDoElementNames.contains((*it)->name())); +} + +void WMLCardElement::parseMappedAttribute(MappedAttribute* attr) +{ + WMLIntrinsicEventType eventType = WMLIntrinsicEventUnknown; + + if (attr->name() == onenterforwardAttr) + eventType = WMLIntrinsicEventOnEnterForward; + else if (attr->name() == onenterbackwardAttr) + eventType = WMLIntrinsicEventOnEnterBackward; + else if (attr->name() == ontimerAttr) + eventType = WMLIntrinsicEventOnTimer; + else if (attr->name() == newcontextAttr) + m_isNewContext = (attr->value() == "true"); + else if (attr->name() == orderedAttr) + m_isOrdered = (attr->value() == "true"); + else { + WMLEventHandlingElement::parseMappedAttribute(attr); + return; + } + + if (eventType == WMLIntrinsicEventUnknown) + return; + + // Register intrinsic event in card + RefPtr<WMLIntrinsicEvent> event = WMLIntrinsicEvent::create(document(), attr->value()); + + createEventHandlerIfNeeded(); + eventHandler()->registerIntrinsicEvent(eventType, event); +} + +void WMLCardElement::insertedIntoDocument() +{ + WMLEventHandlingElement::insertedIntoDocument(); + + // The first card inserted into a document, is visible by default. + if (!m_isVisible) { + RefPtr<NodeList> nodeList = document()->getElementsByTagName("card"); + if (nodeList && nodeList->length() == 1 && nodeList->item(0) == this) + m_isVisible = true; + } +} + +RenderObject* WMLCardElement::createRenderer(RenderArena* arena, RenderStyle* style) +{ + if (!m_isVisible) { + style->setUnique(); + style->setDisplay(NONE); + } + + return WMLElement::createRenderer(arena, style); +} + +WMLCardElement* WMLCardElement::findNamedCardInDocument(Document* doc, const String& cardName) +{ + if (cardName.isEmpty()) + return 0; + + RefPtr<NodeList> nodeList = doc->getElementsByTagName("card"); + if (!nodeList) + return 0; + + unsigned length = nodeList->length(); + if (length < 1) + return 0; + + for (unsigned i = 0; i < length; ++i) { + WMLCardElement* card = static_cast<WMLCardElement*>(nodeList->item(i)); + if (card->getIDAttribute() != cardName) + continue; + + return card; + } + + return 0; +} + +WMLCardElement* WMLCardElement::determineActiveCard(Document* doc) +{ + WMLPageState* pageState = wmlPageStateForDocument(doc); + if (!pageState) + return 0; + + RefPtr<NodeList> nodeList = doc->getElementsByTagName("card"); + if (!nodeList) + return 0; + + unsigned length = nodeList->length(); + if (length < 1) + return 0; + + // Figure out the new target card + String cardName = doc->url().ref(); + + WMLCardElement* activeCard = findNamedCardInDocument(doc, cardName); + if (activeCard) { + // Hide all cards - except the destination card - in document + for (unsigned i = 0; i < length; ++i) { + WMLCardElement* card = static_cast<WMLCardElement*>(nodeList->item(i)); + + if (card == activeCard) + card->showCard(); + else + card->hideCard(); + } + } else { + // If the target URL didn't contain a fragment identifier, activeCard + // is 0, and has to be set to the first card element in the deck. + activeCard = static_cast<WMLCardElement*>(nodeList->item(0)); + activeCard->showCard(); + } + + // Assure destination card is visible + ASSERT(activeCard->isVisible()); + ASSERT(activeCard->attached()); + ASSERT(activeCard->renderer()); + + // Update the document title + doc->setTitle(activeCard->title()); + + // Set the active activeCard in the WMLPageState object + pageState->setActiveCard(activeCard); + return activeCard; +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLCardElement.h b/src/3rdparty/webkit/WebCore/wml/WMLCardElement.h new file mode 100644 index 0000000..5bc763a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLCardElement.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLCardElement_h +#define WMLCardElement_h + +#if ENABLE(WML) +#include "WMLEventHandlingElement.h" + +#include <wtf/Vector.h> + +namespace WebCore { + +class WMLTemplateElement; +class WMLTimerElement; + +class WMLCardElement : public WMLEventHandlingElement { +public: + WMLCardElement(const QualifiedName&, Document*); + virtual ~WMLCardElement(); + + bool isNewContext() const { return m_isNewContext; } + bool isOrdered() const { return m_isOrdered; } + WMLTimerElement* eventTimer() const { return m_eventTimer; } + WMLTemplateElement* templateElement() const { return m_template; } + + void setTemplateElement(WMLTemplateElement*); + void setIntrinsicEventTimer(WMLTimerElement*); + + void handleIntrinsicEventIfNeeded(); + void handleDeckLevelTaskOverridesIfNeeded(); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + // Switch active card in document to the one specified in the URL reference (foo.wml#mycard) + // If the 'targetUrl' doesn't contain a reference, use the first <card> element in the document. + static WMLCardElement* determineActiveCard(Document*); + static WMLCardElement* findNamedCardInDocument(Document*, const String& cardName); + +private: + bool isVisible() const { return m_isVisible; } + + void showCard(); + void hideCard(); + + bool m_isNewContext; + bool m_isOrdered; + bool m_isVisible; + + WMLTimerElement* m_eventTimer; + WMLTemplateElement* m_template; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLDoElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLDoElement.cpp new file mode 100644 index 0000000..8739e5c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLDoElement.cpp @@ -0,0 +1,152 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLDoElement.h" + +#include "Event.h" +#include "EventNames.h" +#include "HTMLNames.h" +#include "KeyboardEvent.h" +#include "Page.h" +#include "RenderButton.h" +#include "WMLCardElement.h" +#include "WMLDocument.h" +#include "WMLTaskElement.h" +#include "WMLTimerElement.h" +#include "WMLNames.h" +#include "WMLPageState.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLDoElement::WMLDoElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) + , m_task(0) + , m_isActive(false) + , m_isNoop(false) + , m_isOptional(false) +{ +} + +void WMLDoElement::defaultEventHandler(Event* event) +{ + if (m_isOptional) + return; + + if (event->type() == eventNames().keypressEvent) { + WMLElement::defaultEventHandler(event); + return; + } + + if (event->type() != eventNames().clickEvent && event->type() != eventNames().keydownEvent) + return; + + if (event->isKeyboardEvent() + && static_cast<KeyboardEvent*>(event)->keyIdentifier() != "Enter") + return; + + if (m_type == "accept" || m_type == "options") { + if (m_task) + m_task->executeTask(event); + } else if (m_type == "prev") { + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (!pageState) + return; + + // Stop the timer of the current card if it is active + if (WMLCardElement* card = pageState->activeCard()) { + if (WMLTimerElement* eventTimer = card->eventTimer()) + eventTimer->stop(); + } + + pageState->page()->goBack(); + } else if (m_type == "reset") { + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (!pageState) + return; + + pageState->reset(); + } +} + +void WMLDoElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::typeAttr) + m_type = parseValueForbiddingVariableReferences(attr->value()); + else if (attr->name() == HTMLNames::nameAttr) + m_name = parseValueForbiddingVariableReferences(attr->value()); + else if (attr->name() == HTMLNames::labelAttr) + m_label = parseValueSubstitutingVariableReferences(attr->value()); + else if (attr->name() == optionalAttr) + m_isOptional = (attr->value() == "true"); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLDoElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + // Spec: An unspecified 'name' defaults to the value of the 'type' attribute. + if (!hasAttribute(HTMLNames::nameAttr)) + m_name = m_type; + + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent || !parent->isWMLElement()) + return; + + WMLElement* parentElement = static_cast<WMLElement*>(parent); + if (!parentElement->isWMLEventHandlingElement()) + return; + + static_cast<WMLEventHandlingElement*>(parentElement)->registerDoElement(this); +} + +RenderObject* WMLDoElement::createRenderer(RenderArena* arena, RenderStyle* style) +{ + if (!m_isActive || m_isOptional || m_isNoop) + return 0; + + if (style) { + style->setUnique(); + style->setBackgroundColor(Color::lightGray); + } + + return new (arena) RenderButton(this); +} + +void WMLDoElement::recalcStyle(StyleChange change) +{ + WMLElement::recalcStyle(change); + + if (renderer()) + renderer()->updateFromElement(); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLDoElement.h b/src/3rdparty/webkit/WebCore/wml/WMLDoElement.h new file mode 100644 index 0000000..98e97cc --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLDoElement.h @@ -0,0 +1,64 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLDoElement_h +#define WMLDoElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLTaskElement; + +class WMLDoElement : public WMLElement { +public: + WMLDoElement(const QualifiedName& tagName, Document*); + + virtual void defaultEventHandler(Event*); + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual void recalcStyle(StyleChange); + + void registerTask(WMLTaskElement* task) { m_task = task; } + + bool isActive() const { return m_isActive; } + String label() const { return m_label; } + String name() const { return m_name; } + + void setActive(bool active) { m_isActive = active; } + void setNoop(bool noop) { m_isNoop = noop;} + +private: + WMLTaskElement* m_task; + bool m_isActive; + bool m_isNoop; + bool m_isOptional; + String m_label; + String m_name; + String m_type; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLDocument.cpp b/src/3rdparty/webkit/WebCore/wml/WMLDocument.cpp new file mode 100644 index 0000000..36c436f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLDocument.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLDocument.h" + +#include "Page.h" +#include "Tokenizer.h" +#include "WMLCardElement.h" +#include "WMLErrorHandling.h" +#include "WMLPageState.h" +#include "WMLTemplateElement.h" + +namespace WebCore { + +WMLDocument::WMLDocument(Frame* frame) + : Document(frame, false) +{ + clearXMLVersion(); +} + +WMLDocument::~WMLDocument() +{ +} + +void WMLDocument::finishedParsing() +{ + if (Tokenizer* tokenizer = this->tokenizer()) { + if (!tokenizer->wellFormed()) { + Document::finishedParsing(); + return; + } + } + + WMLPageState* wmlPageState = wmlPageStateForDocument(this); + if (!wmlPageState->isDeckAccessible()) { + reportWMLError(this, WMLErrorDeckNotAccessible); + Document::finishedParsing(); + return; + } + + // Remember that we'e successfully entered the deck + wmlPageState->setNeedCheckDeckAccess(false); + + // Notify the existance of templates to all cards of the current deck + WMLTemplateElement::registerTemplatesInDocument(this); + + // Set destination card + WMLCardElement* card = WMLCardElement::determineActiveCard(this); + if (!card) { + reportWMLError(this, WMLErrorNoCardInDocument); + Document::finishedParsing(); + return; + } + + // Handle deck-level task overrides + card->handleDeckLevelTaskOverridesIfNeeded(); + + // Handle card-level intrinsic event + card->handleIntrinsicEventIfNeeded(); + + Document::finishedParsing(); +} + +WMLPageState* wmlPageStateForDocument(Document* doc) +{ + ASSERT(doc); + + Page* page = doc->page(); + ASSERT(page); + + return page->wmlPageState(); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLDocument.h b/src/3rdparty/webkit/WebCore/wml/WMLDocument.h new file mode 100644 index 0000000..d7eb8b2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLDocument.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLDocument_h +#define WMLDocument_h + +#if ENABLE(WML) +#include "Document.h" +#include "WMLErrorHandling.h" +#include "WMLPageState.h" + +namespace WebCore { + +class WMLDocument : public Document { +public: + static PassRefPtr<WMLDocument> create(Frame* frame) + { + return new WMLDocument(frame); + } + + virtual ~WMLDocument(); + + virtual bool isWMLDocument() const { return true; } + virtual void finishedParsing(); + +private: + WMLDocument(Frame*); +}; + +WMLPageState* wmlPageStateForDocument(Document*); + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLElement.cpp new file mode 100644 index 0000000..c88c5d3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLElement.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLElement.h" + +#include "CSSPropertyNames.h" +#include "HTMLNames.h" +#include "RenderObject.h" +#include "WMLErrorHandling.h" +#include "WMLNames.h" +#include "WMLVariables.h" + +using std::max; +using std::min; + +namespace WebCore { + +using namespace WMLNames; + +WMLElement::WMLElement(const QualifiedName& tagName, Document* doc) + : StyledElement(tagName, doc) +{ +} + +bool WMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const +{ + if (attrName == HTMLNames::alignAttr) { + result = eUniversal; + return false; + } + + return StyledElement::mapToEntry(attrName, result); +} + +void WMLElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::idAttr + || attr->name() == HTMLNames::classAttr + || attr->name() == HTMLNames::styleAttr) + return StyledElement::parseMappedAttribute(attr); + + if (attr->name() == HTMLNames::alignAttr) { + if (equalIgnoringCase(attr->value(), "middle")) + addCSSProperty(attr, CSSPropertyTextAlign, "center"); + else + addCSSProperty(attr, CSSPropertyTextAlign, attr->value()); + } else if (attr->name() == HTMLNames::tabindexAttr) { + String indexstring = attr->value(); + if (indexstring.length()) { + bool parsedOK; + int tabindex = indexstring.toIntStrict(&parsedOK); + if (parsedOK) + // Clamp tabindex to the range of 'short' to match Firefox's behavior. + setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max())))); + } + } +} + +bool WMLElement::rendererIsNeeded(RenderStyle* style) +{ + return document()->documentElement() == this || style->display() != NONE; +} + +RenderObject* WMLElement::createRenderer(RenderArena*, RenderStyle* style) +{ + return RenderObject::createObject(this, style); +} + +String WMLElement::parseValueSubstitutingVariableReferences(const AtomicString& value, WMLErrorCode defaultErrorCode) +{ + bool isValid = false; + if (!containsVariableReference(value, isValid)) + return value; + + if (!isValid) { + reportWMLError(document(), defaultErrorCode); + return String(); + } + + return substituteVariableReferences(value, document()); +} + +String WMLElement::parseValueForbiddingVariableReferences(const AtomicString& value) +{ + bool isValid = false; + if (containsVariableReference(value, isValid)) { + reportWMLError(document(), WMLErrorInvalidVariableReferenceLocation); + return String(); + } + + return value; +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLElement.h b/src/3rdparty/webkit/WebCore/wml/WMLElement.h new file mode 100644 index 0000000..e5421da --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLElement.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLElement_h +#define WMLElement_h + +#if ENABLE(WML) +#include "StyledElement.h" +#include "WMLErrorHandling.h" + +namespace WebCore { + +class WMLElement : public StyledElement { +public: + WMLElement(const QualifiedName& tagName, Document*); + + virtual bool isWMLElement() const { return true; } + virtual bool isWMLEventHandlingElement() const { return false; } + virtual bool isWMLTaskElement() const { return false; } + + virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; + virtual void parseMappedAttribute(MappedAttribute*); + + virtual bool rendererIsNeeded(RenderStyle*); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + +protected: + // Helper function for derived classes + String parseValueSubstitutingVariableReferences(const AtomicString&, WMLErrorCode defaultErrorCode = WMLErrorInvalidVariableReference); + String parseValueForbiddingVariableReferences(const AtomicString&); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLErrorHandling.cpp b/src/3rdparty/webkit/WebCore/wml/WMLErrorHandling.cpp new file mode 100644 index 0000000..a228299 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLErrorHandling.cpp @@ -0,0 +1,105 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLErrorHandling.h" + +#include "Console.h" +#include "CString.h" +#include "Frame.h" +#include "Document.h" +#include "DOMWindow.h" +#include "XMLTokenizer.h" + +namespace WebCore { + +void reportWMLError(Document* doc, WMLErrorCode error) +{ + if (!doc || error == WMLErrorUnknown) + return; + + String errorMessage = errorMessageForErrorCode(error); + if (XMLTokenizer* tokenizer = static_cast<XMLTokenizer*>(doc->tokenizer())) { + // Some errors are reported as result of an insertedIntoDocument() call. + // If this happened, parsing has been stopped, and the document fragment + // is wrapped in a XHTML error document. That means insertedIntoDocument() + // will be called again - do NOT report the error twice, that would result + // in an infinite error reporting loop. + if (!tokenizer->wellFormed()) + return; + + tokenizer->handleError(XMLTokenizer::fatal, errorMessage.latin1().data(), tokenizer->lineNumber(), tokenizer->columnNumber()); + } else { + Frame* frame = doc->frame(); + if (!frame) + return; + + DOMWindow* domWindow = frame->domWindow(); + if (!domWindow) + return; + + Console* console = domWindow->console(); + if (!console) + return; + + console->addMessage(WMLMessageSource, ErrorMessageLevel, errorMessage, 0, String()); + } +} + +String errorMessageForErrorCode(WMLErrorCode error) +{ + switch (error) { + case WMLErrorConflictingEventBinding: + return "Conflicting event bindings within an element."; + case WMLErrorDeckNotAccessible: + return "Deck not accessible."; + case WMLErrorDuplicatedDoElement: + return "At least two do elements share a name, which is not allowed."; + case WMLErrorForbiddenTaskInAnchorElement: + return "Forbidden task contained in anchor element."; + case WMLErrorInvalidColumnsNumberInTable: + return "A table contains an invalid number of columns."; + case WMLErrorInvalidVariableName: + return "A variable name contains invalid characters."; + case WMLErrorInvalidVariableReference: + return "A variable reference uses invalid syntax."; + case WMLErrorInvalidVariableReferenceLocation: + return "A variable reference is placed in an invalid location."; + case WMLErrorMultipleAccessElements: + return "Only one access element is allowed in a deck."; + case WMLErrorMultipleTemplateElements: + return "Only one template element is allowed in a deck."; + case WMLErrorNoCardInDocument: + return "No card contained in document."; + case WMLErrorMultipleTimerElements: + return "Only one timer element is allowed in a card."; + case WMLErrorUnknown: + return String(); + }; + + ASSERT_NOT_REACHED(); + return String(); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLErrorHandling.h b/src/3rdparty/webkit/WebCore/wml/WMLErrorHandling.h new file mode 100644 index 0000000..3005803 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLErrorHandling.h @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLErrorCodes_h +#define WMLErrorCodes_h + +#if ENABLE(WML) +namespace WebCore { + + class Document; + class String; + + enum WMLErrorCode { + WMLErrorUnknown = 0, + WMLErrorConflictingEventBinding, + WMLErrorDeckNotAccessible, + WMLErrorDuplicatedDoElement, + WMLErrorForbiddenTaskInAnchorElement, + WMLErrorInvalidColumnsNumberInTable, + WMLErrorInvalidVariableName, + WMLErrorInvalidVariableReference, + WMLErrorInvalidVariableReferenceLocation, + WMLErrorMultipleAccessElements, + WMLErrorMultipleTemplateElements, + WMLErrorMultipleTimerElements, + WMLErrorNoCardInDocument + }; + + String errorMessageForErrorCode(WMLErrorCode); + void reportWMLError(Document*, WMLErrorCode); +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLEventHandlingElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLEventHandlingElement.cpp new file mode 100644 index 0000000..69b2f8e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLEventHandlingElement.cpp @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLEventHandlingElement.h" + +#include "WMLDoElement.h" +#include "WMLIntrinsicEventHandler.h" +#include "WMLTaskElement.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLEventHandlingElement::WMLEventHandlingElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLEventHandlingElement::~WMLEventHandlingElement() +{ +} + +void WMLEventHandlingElement::createEventHandlerIfNeeded() +{ + if (!m_eventHandler) + m_eventHandler.set(new WMLIntrinsicEventHandler); +} + +void WMLEventHandlingElement::registerDoElement(WMLDoElement* doElement) +{ + Vector<WMLDoElement*>::iterator it = m_doElements.begin(); + Vector<WMLDoElement*>::iterator end = m_doElements.end(); + + for (; it != end; ++it) { + if ((*it)->name() == doElement->name()) { + reportWMLError(document(), WMLErrorDuplicatedDoElement); + return; + } + } + + m_doElements.append(doElement); + doElement->setActive(true); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLEventHandlingElement.h b/src/3rdparty/webkit/WebCore/wml/WMLEventHandlingElement.h new file mode 100644 index 0000000..cb66e53 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLEventHandlingElement.h @@ -0,0 +1,56 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLEventHandlingElement_h +#define WMLEventHandlingElement_h + +#if ENABLE(WML) +#include "WMLElement.h" +#include "WMLIntrinsicEventHandler.h" + +#include <wtf/OwnPtr.h> +#include <wtf/Vector.h> + +namespace WebCore { + +class WMLDoElement; + +class WMLEventHandlingElement : public WMLElement { +public: + WMLEventHandlingElement(const QualifiedName& tagName, Document*); + virtual ~WMLEventHandlingElement(); + + virtual bool isWMLEventHandlingElement() const { return true; } + + WMLIntrinsicEventHandler* eventHandler() const { return m_eventHandler.get(); } + void createEventHandlerIfNeeded(); + + Vector<WMLDoElement*>& doElements() { return m_doElements; } + void registerDoElement(WMLDoElement*); + +private: + OwnPtr<WMLIntrinsicEventHandler> m_eventHandler; + Vector<WMLDoElement*> m_doElements; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLFieldSetElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLFieldSetElement.cpp new file mode 100644 index 0000000..d32f9b1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLFieldSetElement.cpp @@ -0,0 +1,86 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLFieldSetElement.h" + +#include "HTMLNames.h" +#include "RenderFieldset.h" +#include "Text.h" +#include "WMLElementFactory.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLFieldSetElement::WMLFieldSetElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLFieldSetElement::~WMLFieldSetElement() +{ +} + +void WMLFieldSetElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::titleAttr) + m_title = parseValueSubstitutingVariableReferences(attr->value()); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLFieldSetElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + if (m_title.isEmpty()) + return; + + m_insertedLegendElement = WMLElementFactory::createWMLElement(insertedLegendTag, document()); + + // Insert <dummyLegend> element, as RenderFieldset expect it to be present + // to layout it's child text content, when rendering <fieldset> elements + ExceptionCode ec = 0; + appendChild(m_insertedLegendElement, ec); + ASSERT(ec == 0); + + // Create text node holding the 'title' attribute value + m_insertedLegendElement->appendChild(document()->createTextNode(m_title), ec); + ASSERT(ec == 0); +} + +void WMLFieldSetElement::removedFromDocument() +{ + WMLElement::removedFromDocument(); + m_insertedLegendElement.clear(); +} + +RenderObject* WMLFieldSetElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderFieldset(this); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLFieldSetElement.h b/src/3rdparty/webkit/WebCore/wml/WMLFieldSetElement.h new file mode 100644 index 0000000..2043364 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLFieldSetElement.h @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLFieldSetElement_h +#define WMLFieldSetElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLFieldSetElement : public WMLElement { +public: + WMLFieldSetElement(const QualifiedName& tagName, Document*); + virtual ~WMLFieldSetElement(); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + +private: + String m_title; + RefPtr<WMLElement> m_insertedLegendElement; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLGoElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLGoElement.cpp new file mode 100644 index 0000000..5ecf495 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLGoElement.cpp @@ -0,0 +1,214 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLGoElement.h" + +#include "CString.h" +#include "FormData.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLNames.h" +#include "ResourceRequest.h" +#include "TextEncoding.h" +#include "WMLCardElement.h" +#include "WMLDocument.h" +#include "WMLNames.h" +#include "WMLPageState.h" +#include "WMLPostfieldElement.h" +#include "WMLTimerElement.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLGoElement::WMLGoElement(const QualifiedName& tagName, Document* doc) + : WMLTaskElement(tagName, doc) +{ +} + +void WMLGoElement::registerPostfieldElement(WMLPostfieldElement* postfield) +{ + m_postfieldElements.append(postfield); +} + +void WMLGoElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::methodAttr) + m_formDataBuilder.parseMethodType(attr->value()); + else if (attr->name() == HTMLNames::enctypeAttr) + m_formDataBuilder.parseEncodingType(parseValueSubstitutingVariableReferences(attr->value())); + else if (attr->name() == HTMLNames::accept_charsetAttr) + m_formDataBuilder.setAcceptCharset(parseValueForbiddingVariableReferences(attr->value())); + else + WMLTaskElement::parseMappedAttribute(attr); +} + +void WMLGoElement::executeTask(Event* event) +{ + Document* doc = document(); + WMLPageState* pageState = wmlPageStateForDocument(doc); + if (!pageState) + return; + + WMLCardElement* card = pageState->activeCard(); + if (!card) + return; + + Frame* frame = doc->frame(); + if (!frame) + return; + + FrameLoader* loader = frame->loader(); + if (!loader) + return; + + String href = getAttribute(HTMLNames::hrefAttr); + if (href.isEmpty()) + return; + + // Substitute variables within target url attribute value + KURL url = doc->completeURL(substituteVariableReferences(href, doc, WMLVariableEscapingEscape)); + if (url.isEmpty()) + return; + + storeVariableState(pageState); + + // Stop the timer of the current card if it is active + if (WMLTimerElement* eventTimer = card->eventTimer()) + eventTimer->stop(); + + // FIXME: 'newcontext' handling not implemented for external cards + bool inSameDeck = doc->url().path() == url.path(); + if (inSameDeck && url.hasRef()) { + // Force frame loader to load the URL with fragment identifier + loader->setForceReloadWmlDeck(true); + + if (WMLCardElement* card = WMLCardElement::findNamedCardInDocument(doc, url.ref())) { + if (card->isNewContext()) + pageState->reset(); + } + } + + // Prepare loading the destination url + ResourceRequest request(url); + + if (getAttribute(sendrefererAttr) == "true") + request.setHTTPReferrer(loader->outgoingReferrer()); + + String cacheControl = getAttribute(cache_controlAttr); + + if (m_formDataBuilder.isPostMethod()) + preparePOSTRequest(request, inSameDeck, cacheControl); + else + prepareGETRequest(request, url); + + // Set HTTP cache-control header if needed + if (!cacheControl.isEmpty()) { + request.setHTTPHeaderField("cache-control", cacheControl); + + if (cacheControl == "no-cache") + request.setCachePolicy(ReloadIgnoringCacheData); + } + + loader->load(request); +} + +void WMLGoElement::preparePOSTRequest(ResourceRequest& request, bool inSameDeck, const String& cacheControl) +{ + request.setHTTPMethod("POST"); + + if (inSameDeck && cacheControl != "no-cache") { + request.setCachePolicy(ReturnCacheDataDontLoad); + return; + } + + RefPtr<FormData> data; + + if (m_formDataBuilder.isMultiPartForm()) { // multipart/form-data + Vector<char> boundary = m_formDataBuilder.generateUniqueBoundaryString(); + data = createFormData(boundary.data()); + request.setHTTPContentType(m_formDataBuilder.encodingType() + "; boundary=" + boundary.data()); + } else { + // text/plain or application/x-www-form-urlencoded + data = createFormData(CString()); + request.setHTTPContentType(m_formDataBuilder.encodingType()); + } + + request.setHTTPBody(data.get()); +} + +void WMLGoElement::prepareGETRequest(ResourceRequest& request, const KURL& url) +{ + request.setHTTPMethod("GET"); + + // Eventually display error message? + if (m_formDataBuilder.isMultiPartForm()) + return; + + RefPtr<FormData> data = createFormData(CString()); + + KURL remoteURL(url); + remoteURL.setQuery(data->flattenToString()); + request.setURL(remoteURL); +} + +PassRefPtr<FormData> WMLGoElement::createFormData(const CString& boundary) +{ + CString key; + CString value; + + Vector<char> encodedData; + TextEncoding encoding = m_formDataBuilder.dataEncoding(document()).encodingForFormSubmission(); + + Vector<WMLPostfieldElement*>::iterator it = m_postfieldElements.begin(); + Vector<WMLPostfieldElement*>::iterator end = m_postfieldElements.end(); + + RefPtr<FormData> result = FormData::create(); + for (; it != end; ++it) { + (*it)->encodeData(encoding, key, value); + + if (m_formDataBuilder.isMultiPartForm()) { + Vector<char> header; + m_formDataBuilder.beginMultiPartHeader(header, boundary, key); + m_formDataBuilder.finishMultiPartHeader(header); + result->appendData(header.data(), header.size()); + + if (size_t dataSize = value.length()) + result->appendData(value.data(), dataSize); + + result->appendData("\r\n", 2); + } else + m_formDataBuilder.addKeyValuePairAsFormData(encodedData, key, value); + } + + if (m_formDataBuilder.isMultiPartForm()) + m_formDataBuilder.addBoundaryToMultiPartHeader(encodedData, boundary, true); + + result->appendData(encodedData.data(), encodedData.size()); + return result; +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLGoElement.h b/src/3rdparty/webkit/WebCore/wml/WMLGoElement.h new file mode 100644 index 0000000..3c70289 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLGoElement.h @@ -0,0 +1,56 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLGoElement_h +#define WMLGoElement_h + +#if ENABLE(WML) +#include "FormDataBuilder.h" +#include "WMLTaskElement.h" + +namespace WebCore { + +class FormData; +class ResourceRequest; +class WMLPostfieldElement; + +class WMLGoElement : public WMLTaskElement { +public: + WMLGoElement(const QualifiedName& tagName, Document*); + + void registerPostfieldElement(WMLPostfieldElement*); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void executeTask(Event*); + +private: + void preparePOSTRequest(ResourceRequest&, bool inSameDeck, const String& cacheControl); + void prepareGETRequest(ResourceRequest&, const KURL&); + + PassRefPtr<FormData> createFormData(const CString& boundary); + + Vector<WMLPostfieldElement*> m_postfieldElements; + FormDataBuilder m_formDataBuilder; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLImageElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLImageElement.cpp new file mode 100644 index 0000000..05ed9a0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLImageElement.cpp @@ -0,0 +1,148 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLImageElement.h" + +#include "CSSPropertyNames.h" +#include "CSSValueKeywords.h" +#include "HTMLElement.h" +#include "HTMLNames.h" +#include "RenderImage.h" +#include "WMLNames.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLImageElement::WMLImageElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) + , m_imageLoader(this) + , m_useFallbackAttribute(false) +{ +} + +WMLImageElement::~WMLImageElement() +{ +} + +bool WMLImageElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const +{ + if (attrName == HTMLNames::widthAttr || + attrName == HTMLNames::heightAttr || + attrName == HTMLNames::vspaceAttr || + attrName == HTMLNames::hspaceAttr) { + result = eUniversal; + return false; + } + + if (attrName == HTMLNames::alignAttr) { + result = eReplaced; + return false; + } + + return WMLElement::mapToEntry(attrName, result); +} + +void WMLImageElement::parseMappedAttribute(MappedAttribute* attr) +{ + const QualifiedName& attrName = attr->name(); + + if (attrName == HTMLNames::altAttr) { + if (renderer() && renderer()->isImage()) + static_cast<RenderImage*>(renderer())->updateAltText(); + } else if (attrName == HTMLNames::srcAttr || attrName == localsrcAttr) + m_imageLoader.updateFromElementIgnoringPreviousError(); + else if (attrName == HTMLNames::widthAttr) + addCSSLength(attr, CSSPropertyWidth, attr->value()); + else if (attrName == HTMLNames::heightAttr) + addCSSLength(attr, CSSPropertyHeight, attr->value()); + else if (attrName == HTMLNames::vspaceAttr) { + addCSSLength(attr, CSSPropertyMarginTop, attr->value()); + addCSSLength(attr, CSSPropertyMarginBottom, attr->value()); + } else if (attrName == HTMLNames::hspaceAttr) { + addCSSLength(attr, CSSPropertyMarginLeft, attr->value()); + addCSSLength(attr, CSSPropertyMarginRight, attr->value()); + } else if (attrName == HTMLNames::alignAttr) + HTMLElement::addHTMLAlignmentToStyledElement(this, attr); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLImageElement::attach() +{ + WMLElement::attach(); + + if (renderer() && renderer()->isImage()) { + RenderImage* imageObj = static_cast<RenderImage*>(renderer()); + if (imageObj->hasImage()) + return; + + imageObj->setCachedImage(m_imageLoader.image()); + + // If we have no image at all because we have no src attribute, set + // image height and width for the alt text instead. + if (!m_imageLoader.image() && !imageObj->cachedImage()) + imageObj->setImageSizeForAltText(); + } +} + +RenderObject* WMLImageElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderImage(this); +} + +void WMLImageElement::insertedIntoDocument() +{ + // If we have been inserted from a renderer-less document, + // our loader may have not fetched the image, so do it now. + if (!m_imageLoader.image()) + m_imageLoader.updateFromElement(); + + WMLElement::insertedIntoDocument(); +} + +bool WMLImageElement::isURLAttribute(Attribute* attr) const +{ + return attr->name() == HTMLNames::srcAttr + || attr->name() == localsrcAttr; +} + +const QualifiedName& WMLImageElement::imageSourceAttributeName() const +{ + // Spec: Any 'localsrc' parameter specified takes precedence over the + // image specified in the src parameter. + if (hasAttribute(localsrcAttr) && !m_useFallbackAttribute) + return localsrcAttr; + + return HTMLNames::srcAttr; +} + +String WMLImageElement::altText() const +{ + return substituteVariableReferences(getAttribute(HTMLNames::altAttr), document()); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLImageElement.h b/src/3rdparty/webkit/WebCore/wml/WMLImageElement.h new file mode 100644 index 0000000..8ace3ba --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLImageElement.h @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLImageElement_h +#define WMLImageElement_h + +#if ENABLE(WML) +#include "WMLElement.h" +#include "WMLImageLoader.h" + +namespace WebCore { + +class WMLImageElement : public WMLElement { +public: + WMLImageElement(const QualifiedName& tagName, Document*); + virtual ~WMLImageElement(); + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(MappedAttribute*); + + virtual void attach(); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual void insertedIntoDocument(); + virtual bool isURLAttribute(Attribute*) const; + virtual const QualifiedName& imageSourceAttributeName() const; + + String altText() const; + + bool useFallbackAttribute() { return m_useFallbackAttribute; } + void setUseFallbackAttribute(bool value) { m_useFallbackAttribute = value; } + +private: + WMLImageLoader m_imageLoader; + bool m_useFallbackAttribute; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLImageLoader.cpp b/src/3rdparty/webkit/WebCore/wml/WMLImageLoader.cpp new file mode 100644 index 0000000..a1a020d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLImageLoader.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLImageLoader.h" + +#include "CachedImage.h" +#include "CSSHelper.h" +#include "HTMLNames.h" +#include "WMLImageElement.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLImageLoader::WMLImageLoader(WMLImageElement* element) + : ImageLoader(element) +{ +} + +WMLImageLoader::~WMLImageLoader() +{ +} + +void WMLImageLoader::dispatchLoadEvent() +{ + // WML doesn't fire any events. + if (haveFiredLoadEvent()) + return; + + setHaveFiredLoadEvent(true); +} + +String WMLImageLoader::sourceURI(const AtomicString& attr) const +{ + return parseURL(KURL(element()->baseURI(), attr).string()); +} + +void WMLImageLoader::notifyFinished(CachedResource* image) +{ + ImageLoader::notifyFinished(image); + + if (!image->errorOccurred()) + return; + + WMLImageElement* imageElement = static_cast<WMLImageElement*>(element()); + ASSERT(imageElement); + + // Loading both 'localsrc' and 'src' failed. Ignore this image. + if (imageElement->useFallbackAttribute()) + return; + + if (!imageElement->hasAttribute(localsrcAttr) && !imageElement->hasAttribute(HTMLNames::srcAttr)) + return; + + imageElement->setUseFallbackAttribute(true); + updateFromElementIgnoringPreviousError(); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLImageLoader.h b/src/3rdparty/webkit/WebCore/wml/WMLImageLoader.h new file mode 100644 index 0000000..ecdb65a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLImageLoader.h @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLImageLoader_h +#define WMLImageLoader_h + +#if ENABLE(WML) +#include "ImageLoader.h" + +namespace WebCore { + +class WMLImageElement; + +class WMLImageLoader : public ImageLoader { +public: + WMLImageLoader(WMLImageElement*); + virtual ~WMLImageLoader(); + + virtual void dispatchLoadEvent(); + virtual String sourceURI(const AtomicString&) const; + + virtual void notifyFinished(CachedResource*); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLInsertedLegendElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLInsertedLegendElement.cpp new file mode 100644 index 0000000..7decd77 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLInsertedLegendElement.cpp @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLInsertedLegendElement.h" + +#include "RenderLegend.h" + +namespace WebCore { + +WMLInsertedLegendElement::WMLInsertedLegendElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLInsertedLegendElement::~WMLInsertedLegendElement() +{ +} + +RenderObject* WMLInsertedLegendElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + return new (arena) RenderLegend(this); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLInsertedLegendElement.h b/src/3rdparty/webkit/WebCore/wml/WMLInsertedLegendElement.h new file mode 100644 index 0000000..d758487 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLInsertedLegendElement.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLInsertedLegendElement_h +#define WMLInsertedLegendElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLInsertedLegendElement : public WMLElement { +public: + WMLInsertedLegendElement(const QualifiedName& tagName, Document*); + virtual ~WMLInsertedLegendElement(); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEvent.cpp b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEvent.cpp new file mode 100644 index 0000000..bb631b9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEvent.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLIntrinsicEvent.h" + +#include "HTMLNames.h" +#include "WMLElementFactory.h" +#include "WMLNames.h" +#include "WMLTaskElement.h" + +namespace WebCore { + +using namespace WMLNames; + +static PassRefPtr<WMLTaskElement> createTaskElement(Document* document) +{ + return static_pointer_cast<WMLTaskElement>(WMLElementFactory::createWMLElement(goTag, document, false)); +} + +WMLIntrinsicEvent::WMLIntrinsicEvent(Document* document, const String& targetURL) + : m_taskElement(createTaskElement(document)) +{ + m_taskElement->setAttribute(HTMLNames::hrefAttr, targetURL); +} + +WMLIntrinsicEvent::WMLIntrinsicEvent(WMLTaskElement* taskElement) + : m_taskElement(taskElement) +{ +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEvent.h b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEvent.h new file mode 100644 index 0000000..2a98bee --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEvent.h @@ -0,0 +1,59 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLIntrinsicEvent_h +#define WMLIntrinsicEvent_h + +#if ENABLE(WML) +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +#include "WMLTaskElement.h" + +namespace WebCore { + +class Document; + +class WMLIntrinsicEvent : public RefCounted<WMLIntrinsicEvent> { +public: + static PassRefPtr<WMLIntrinsicEvent> create(Document* document, const String& targetURL) + { + return adoptRef(new WMLIntrinsicEvent(document, targetURL)); + } + + static PassRefPtr<WMLIntrinsicEvent> createWithTask(WMLTaskElement* taskElement) + { + return adoptRef(new WMLIntrinsicEvent(taskElement)); + } + + WMLTaskElement* taskElement() const { return m_taskElement.get(); } + +private: + WMLIntrinsicEvent(Document*, const String& targetURL); + WMLIntrinsicEvent(WMLTaskElement*); + + RefPtr<WMLTaskElement> m_taskElement; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEventHandler.cpp b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEventHandler.cpp new file mode 100644 index 0000000..46cdb8c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEventHandler.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLIntrinsicEventHandler.h" + +namespace WebCore { + +WMLIntrinsicEventHandler::WMLIntrinsicEventHandler() +{ +} + +bool WMLIntrinsicEventHandler::registerIntrinsicEvent(WMLIntrinsicEventType type, PassRefPtr<WMLIntrinsicEvent> event) +{ + if (m_events.contains(type)) + return false; + + m_events.set(type, event); + return true; +} + +void WMLIntrinsicEventHandler::triggerIntrinsicEvent(WMLIntrinsicEventType type) const +{ + RefPtr<WMLIntrinsicEvent> event = m_events.get(type); + ASSERT(event->taskElement()); + event->taskElement()->executeTask(0); +} + +bool WMLIntrinsicEventHandler::hasIntrinsicEvent(WMLIntrinsicEventType type) const +{ + return m_events.contains(type); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEventHandler.h b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEventHandler.h new file mode 100644 index 0000000..b24bb54 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLIntrinsicEventHandler.h @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLIntrinsicEventHandler_h +#define WMLIntrinsicEventHandler_h + +#if ENABLE(WML) +#include <wtf/HashMap.h> +#include <wtf/PassRefPtr.h> + +#include "WMLIntrinsicEvent.h" + +namespace WebCore { + +enum WMLIntrinsicEventType { + WMLIntrinsicEventUnknown = 0, + WMLIntrinsicEventOnEnterForward, + WMLIntrinsicEventOnEnterBackward, + WMLIntrinsicEventOnTimer, + WMLIntrinsicEventOnPick +}; + +class WMLIntrinsicEvent; + +class WMLIntrinsicEventHandler { +public: + WMLIntrinsicEventHandler(); + + bool registerIntrinsicEvent(WMLIntrinsicEventType, PassRefPtr<WMLIntrinsicEvent>); + void triggerIntrinsicEvent(WMLIntrinsicEventType) const; + bool hasIntrinsicEvent(WMLIntrinsicEventType) const; + +private: + typedef HashMap<int, RefPtr<WMLIntrinsicEvent> > EventMap; + EventMap m_events; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLMetaElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLMetaElement.cpp new file mode 100644 index 0000000..71bbf51 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLMetaElement.cpp @@ -0,0 +1,64 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLMetaElement.h" + +#include "Document.h" +#include "HTMLNames.h" + +namespace WebCore { + +WMLMetaElement::WMLMetaElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLMetaElement::~WMLMetaElement() +{ +} + +void WMLMetaElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::http_equivAttr) + m_equiv = parseValueForbiddingVariableReferences(attr->value()); + else if (attr->name() == HTMLNames::contentAttr) + m_content = parseValueForbiddingVariableReferences(attr->value()); + else if (attr->name() == HTMLNames::nameAttr) { + // FIXME: The user agent must ignore any meta-data named with this attribute. + } else + WMLElement::parseMappedAttribute(attr); +} + +void WMLMetaElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + if (m_equiv.isNull() || m_content.isNull()) + return; + + document()->processHttpEquiv(m_equiv, m_content); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLMetaElement.h b/src/3rdparty/webkit/WebCore/wml/WMLMetaElement.h new file mode 100644 index 0000000..713e225 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLMetaElement.h @@ -0,0 +1,45 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLMetaElement_h +#define WMLMetaElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLMetaElement : public WMLElement { +public: + WMLMetaElement(const QualifiedName& tagName, Document*); + virtual ~WMLMetaElement(); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + +private: + String m_equiv; + String m_content; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLNoopElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLNoopElement.cpp new file mode 100644 index 0000000..0460d9f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLNoopElement.cpp @@ -0,0 +1,63 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLNoopElement.h" + +#include "WMLDoElement.h" +#include "WMLErrorHandling.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLNoopElement::WMLNoopElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLNoopElement::~WMLNoopElement() +{ +} + +void WMLNoopElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent || !parent->isWMLElement()) + return; + + if (parent->hasTagName(doTag)) { + WMLDoElement* doElement = static_cast<WMLDoElement*>(parent); + doElement->setNoop(true); + doElement->setChanged(); + } else if (parent->hasTagName(anchorTag)) + reportWMLError(document(), WMLErrorForbiddenTaskInAnchorElement); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLNoopElement.h b/src/3rdparty/webkit/WebCore/wml/WMLNoopElement.h new file mode 100644 index 0000000..63b316e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLNoopElement.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLNoopElement_h +#define WMLNoopElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLNoopElement : public WMLElement { +public: + WMLNoopElement(const QualifiedName& tagName, Document*); + virtual ~WMLNoopElement(); + + virtual void insertedIntoDocument(); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLOnEventElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLOnEventElement.cpp new file mode 100644 index 0000000..2e9e519 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLOnEventElement.cpp @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLOnEventElement.h" + +#include "HTMLNames.h" +#include "WMLErrorHandling.h" +#include "WMLEventHandlingElement.h" +#include "WMLIntrinsicEventHandler.h" +#include "WMLNames.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLOnEventElement::WMLOnEventElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) + , m_type(WMLIntrinsicEventUnknown) +{ +} + +void WMLOnEventElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::typeAttr) { + String parsedValue = parseValueForbiddingVariableReferences(attr->value()); + if (parsedValue.isEmpty()) + return; + + if (parsedValue == onenterforwardAttr) + m_type = WMLIntrinsicEventOnEnterForward; + else if (parsedValue == onenterbackwardAttr) + m_type = WMLIntrinsicEventOnEnterBackward; + else if (parsedValue == ontimerAttr) + m_type = WMLIntrinsicEventOnTimer; + else if (parsedValue == onpickAttr) + m_type = WMLIntrinsicEventOnPick; + } else + WMLElement::parseMappedAttribute(attr); +} + +void WMLOnEventElement::registerTask(WMLTaskElement* task) +{ + if (m_type == WMLIntrinsicEventUnknown) + return; + + // Register intrinsic event to the event handler of the owner of onevent element + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent || !parent->isWMLElement()) + return; + + WMLElement* parentElement = static_cast<WMLElement*>(parent); + if (!parentElement->isWMLEventHandlingElement()) + return; + + WMLEventHandlingElement* eventHandlingElement = static_cast<WMLEventHandlingElement*>(parentElement); + eventHandlingElement->createEventHandlerIfNeeded(); + + RefPtr<WMLIntrinsicEvent> event = WMLIntrinsicEvent::createWithTask(task); + if (!eventHandlingElement->eventHandler()->registerIntrinsicEvent(m_type, event)) + reportWMLError(document(), WMLErrorConflictingEventBinding); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLOnEventElement.h b/src/3rdparty/webkit/WebCore/wml/WMLOnEventElement.h new file mode 100644 index 0000000..bb004fe --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLOnEventElement.h @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLOnEventElement_h +#define WMLOnEventElement_h + +#if ENABLE(WML) +#include "WMLElement.h" +#include "WMLIntrinsicEventHandler.h" + +namespace WebCore { + +class WMLTaskElement; + +class WMLOnEventElement : public WMLElement { +public: + WMLOnEventElement(const QualifiedName& tagName, Document*); + + virtual void parseMappedAttribute(MappedAttribute*); + + void registerTask(WMLTaskElement*); + +private: + WMLIntrinsicEventType m_type; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLPElement.cpp new file mode 100644 index 0000000..3655b2e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPElement.cpp @@ -0,0 +1,112 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLPElement.h" + +#include "CSSPropertyNames.h" +#include "CSSValueKeywords.h" +#include "Document.h" +#include "HTMLNames.h" +#include "NodeList.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLPElement::WMLPElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +bool WMLPElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const +{ + if (attrName == HTMLNames::alignAttr) { + result = eBlock; // We can share with DIV here. + return false; + } + + return WMLElement::mapToEntry(attrName, result); +} + +void WMLPElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::alignAttr) { + const AtomicString& value = attr->value(); + if (equalIgnoringCase(value, "middle") || equalIgnoringCase(value, "center")) + addCSSProperty(attr, CSSPropertyTextAlign, CSSValueWebkitCenter); + else if (equalIgnoringCase(value, "left")) + addCSSProperty(attr, CSSPropertyTextAlign, CSSValueWebkitLeft); + else if (equalIgnoringCase(value, "right")) + addCSSProperty(attr, CSSPropertyTextAlign, CSSValueWebkitRight); + else + addCSSProperty(attr, CSSPropertyTextAlign, value); + } else if (attr->name() == modeAttr) { + m_mode = attr->value(); + if (m_mode == "wrap") + addCSSProperty(attr, CSSPropertyWordWrap, CSSValueBreakWord); + else if (m_mode == "nowrap") + addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueNowrap); + } else + WMLElement::parseMappedAttribute(attr); +} + +void WMLPElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + // If not explicitly specified, the linewrap mode is identical to + // the line-wrap mode of the previous paragraph in the text flow of + // a card. The default mode for the first paragraph in a card is wrap. + if (!m_mode.isEmpty()) + return; + + RefPtr<NodeList> nodeList = document()->getElementsByTagName("p"); + if (!nodeList) + return; + + unsigned length = nodeList->length(); + if (length < 2) + return; + + // Assure we're the last inserted paragraph element + // This only works while parsing, otherwhise this statement is never true. + if (nodeList->item(length - 1) != this) + return; + + WMLPElement* lastParagraph = static_cast<WMLPElement*>(nodeList->item(length - 2)); + ASSERT(lastParagraph); + + String lastMode = lastParagraph->getAttribute(modeAttr); + if (lastMode.isEmpty() || lastMode == "wrap") // Default value, do nothing. + return; + + setAttribute(modeAttr, lastMode); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPElement.h b/src/3rdparty/webkit/WebCore/wml/WMLPElement.h new file mode 100644 index 0000000..292e54f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPElement.h @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLPElement_h +#define WMLPElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLPElement : public WMLElement { +public: + WMLPElement(const QualifiedName& tagName, Document*); + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(MappedAttribute*); + + virtual void insertedIntoDocument(); + +private: + String m_mode; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPageState.cpp b/src/3rdparty/webkit/WebCore/wml/WMLPageState.cpp new file mode 100644 index 0000000..15ae9ca --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPageState.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 2004-2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLPageState.h" + +#include "HistoryItem.h" +#include "KURL.h" +#include "Page.h" + +namespace WebCore { + +WMLPageState::WMLPageState(Page* page) + : m_page(page) + , m_historyLength(0) + , m_activeCard(0) + , m_hasDeckAccess(false) +{ +} + +WMLPageState::~WMLPageState() +{ + m_variables.clear(); +} + +void WMLPageState::reset() +{ + // remove all the variables in the current browser context + m_variables.clear(); + + // clear the navigation history state + if (m_page) + m_page->backForwardList()->clearWmlPageHistory(); + + // reset implementation-specfic state if UA has + m_historyLength = 1; +} + +bool WMLPageState::setNeedCheckDeckAccess(bool need) +{ + if (m_hasDeckAccess && need) + return false; + + m_hasDeckAccess = need; + m_accessPath = String(); + m_accessDomain = String(); + return true; +} + +// FIXME: We may want another name, it does far more than just checking wheter the deck is accessable +bool WMLPageState::isDeckAccessible() +{ + if (!m_hasDeckAccess || !m_page || !m_page->backForwardList() || !m_page->backForwardList()->backItem()) + return true; + + HistoryItem* histItem = m_page->backForwardList()->backItem(); + KURL url(histItem->urlString()); + + String prevHost = url.host(); + String prevPath = url.path(); + + // for 'file' URI, the host part may be empty, so we should complete it. + if (prevHost.isEmpty()) + prevHost = "localhost"; + + histItem = m_page->backForwardList()->currentItem(); + KURL curUrl(histItem->urlString()); + String curPath = curUrl.path(); + + if (equalIgnoringRef(url, curUrl)) + return true; + + // "/" is the default value if not specified + if (m_accessPath.isEmpty()) + m_accessPath = "/"; + else if (m_accessPath.endsWith("/") && (m_accessPath != "/")) + m_accessPath = m_accessPath.left((m_accessPath.length()-1)); + + + // current deck domain is the default value if not specified + if (m_accessDomain.isEmpty()) + m_accessDomain = prevHost; + + // convert relative URL to absolute URL before performing path matching + if (prevHost == m_accessDomain) { + if (!m_accessPath.startsWith("/")) { + int index = curPath.reverseFind('/'); + if (index != -1) { + curPath = curPath.left(index + 1); + curPath += m_accessPath; + curUrl.setPath(curPath); + m_accessPath = curUrl.path(); + } + } + } + + // path prefix matching + if (prevPath.startsWith(m_accessPath) && + (prevPath[m_accessPath.length()] == '/' || prevPath.length() == m_accessPath.length())) { + // domain suffix matching + unsigned domainLength = m_accessDomain.length(); + unsigned hostLength = prevHost.length(); + return (prevHost.endsWith(m_accessDomain) && prevHost[hostLength - domainLength - 1] == '.') || hostLength == domainLength; + } + + return false; +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPageState.h b/src/3rdparty/webkit/WebCore/wml/WMLPageState.h new file mode 100644 index 0000000..6a1d960 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPageState.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * Copyright (C) 2004-2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLPageState_h +#define WMLPageState_h + +#if ENABLE(WML) +#include "StringHash.h" + +namespace WebCore { + +class Page; +class String; +class WMLCardElement; + +typedef HashMap<String, String> WMLVariableMap; + +class WMLPageState { +public: + WMLPageState(Page*); + virtual ~WMLPageState(); + + // reset the browser context when 'newcontext' attribute + // of card element is performed as part of go task + void reset(); + + // variables operations + void storeVariable(const String& name, const String& value) { m_variables.set(name, value); } + void storeVariables(WMLVariableMap& variables) { m_variables = variables; } + String getVariable(const String& name) const { return m_variables.get(name); } + bool hasVariables() const { return !m_variables.isEmpty(); } + + int historyLength() const { return m_historyLength; } + void setHistoryLength(int length) { m_historyLength = length; } + + Page* page() const { return m_page; } + + WMLCardElement* activeCard() const { return m_activeCard; } + void setActiveCard(WMLCardElement* card) { m_activeCard = card; } + + // deck access control + void restrictDeckAccessToDomain(const String& domain) { m_accessDomain = domain; } + void restrictDeckAccessToPath(const String& path) { m_accessPath = path; } + bool hasDeckAccess() const { return m_hasDeckAccess; } + + bool setNeedCheckDeckAccess(bool); + bool isDeckAccessible(); + +private: + Page* m_page; + WMLVariableMap m_variables; + int m_historyLength; + WMLCardElement* m_activeCard; + String m_accessDomain; + String m_accessPath; + bool m_hasDeckAccess; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPostfieldElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLPostfieldElement.cpp new file mode 100644 index 0000000..0cc7d42 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPostfieldElement.cpp @@ -0,0 +1,78 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLPostfieldElement.h" + +#include "CString.h" +#include "TextEncoding.h" +#include "HTMLNames.h" +#include "WMLDocument.h" +#include "WMLGoElement.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLPostfieldElement::WMLPostfieldElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +void WMLPostfieldElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::nameAttr) + m_name = parseValueSubstitutingVariableReferences(attr->value()); + else if (attr->name() == HTMLNames::valueAttr) + m_value = parseValueSubstitutingVariableReferences(attr->value()); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLPostfieldElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent->hasTagName(goTag)) + return; + + static_cast<WMLGoElement*>(parent)->registerPostfieldElement(this); +} + +static inline CString encodedString(const TextEncoding& encoding, const String& data) +{ + return encoding.encode(data.characters(), data.length(), EntitiesForUnencodables); +} + +void WMLPostfieldElement::encodeData(const TextEncoding& encoding, CString& name, CString& value) +{ + name = encodedString(encoding, m_name); + value = encodedString(encoding, m_value); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPostfieldElement.h b/src/3rdparty/webkit/WebCore/wml/WMLPostfieldElement.h new file mode 100644 index 0000000..59b7f64 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPostfieldElement.h @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLPostfieldElement_h +#define WMLPostfieldElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLPostfieldElement : public WMLElement { +public: + WMLPostfieldElement(const QualifiedName& tagName, Document*); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + + String name() const { return m_name; } + String value() const { return m_value; } + + // Encode name() and value() in a CString using the passed encoding + void encodeData(const TextEncoding&, CString& name, CString& value); + +private: + String m_name; + String m_value; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPrevElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLPrevElement.cpp new file mode 100644 index 0000000..2688d03 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPrevElement.cpp @@ -0,0 +1,64 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLPrevElement.h" + +#include "Page.h" +#include "WMLCardElement.h" +#include "WMLDocument.h" +#include "WMLPageState.h" +#include "WMLTimerElement.h" + +namespace WebCore { + +WMLPrevElement::WMLPrevElement(const QualifiedName& tagName, Document* doc) + : WMLTaskElement(tagName, doc) +{ +} + +WMLPrevElement::~WMLPrevElement() +{ +} + +void WMLPrevElement::executeTask(Event*) +{ + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (!pageState) + return; + + WMLCardElement* card = pageState->activeCard(); + if (!card) + return; + + storeVariableState(pageState); + + // Stop the timer of the current card if it is active + if (WMLTimerElement* eventTimer = card->eventTimer()) + eventTimer->stop(); + + pageState->page()->goBack(); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLPrevElement.h b/src/3rdparty/webkit/WebCore/wml/WMLPrevElement.h new file mode 100644 index 0000000..232c1b0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLPrevElement.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLPrevElement_h +#define WMLPrevElement_h + +#if ENABLE(WML) +#include "WMLTaskElement.h" + +namespace WebCore { + +class WMLPrevElement : public WMLTaskElement { +public: + WMLPrevElement(const QualifiedName& tagName, Document*); + virtual ~WMLPrevElement(); + + virtual void executeTask(Event*); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLRefreshElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLRefreshElement.cpp new file mode 100644 index 0000000..c05a2c9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLRefreshElement.cpp @@ -0,0 +1,77 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLRefreshElement.h" + +#include "Frame.h" +#include "FrameLoader.h" +#include "WMLCardElement.h" +#include "WMLDocument.h" +#include "WMLPageState.h" +#include "WMLTimerElement.h" + +namespace WebCore { + +WMLRefreshElement::WMLRefreshElement(const QualifiedName& tagName, Document* doc) + : WMLTaskElement(tagName, doc) +{ +} + +WMLRefreshElement::~WMLRefreshElement() +{ +} + +void WMLRefreshElement::executeTask(Event*) +{ + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (!pageState) + return; + + WMLCardElement* card = pageState->activeCard(); + if (!card) + return; + + // Before perform refresh task, we store the current timeout + // value in the page state and then stop the timer + WMLTimerElement* timer = card->eventTimer(); + if (timer) { + timer->storeIntervalToPageState(); + timer->stop(); + } + + storeVariableState(pageState); + + // Redisplay curremt card with current variable state + if (Frame* frame = document()->frame()) { + if (FrameLoader* loader = frame->loader()) + loader->reload(); + } + + // After refreshing task, resume the timer if it exsits + if (timer) + timer->start(); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLRefreshElement.h b/src/3rdparty/webkit/WebCore/wml/WMLRefreshElement.h new file mode 100644 index 0000000..7b1729e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLRefreshElement.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLRefreshElement_h +#define WMLRefreshElement_h + +#if ENABLE(WML) +#include "WMLTaskElement.h" + +namespace WebCore { + +class WMLRefreshElement : public WMLTaskElement { +public: + WMLRefreshElement(const QualifiedName& tagName, Document*); + virtual ~WMLRefreshElement(); + + virtual void executeTask(Event*); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLSetvarElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLSetvarElement.cpp new file mode 100644 index 0000000..9bce944 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLSetvarElement.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLSetvarElement.h" + +#include "HTMLNames.h" +#include "WMLErrorHandling.h" +#include "WMLTaskElement.h" +#include "WMLVariables.h" + +namespace WebCore { + +WMLSetvarElement::WMLSetvarElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLSetvarElement::~WMLSetvarElement() +{ +} + +void WMLSetvarElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::nameAttr) { + String name = parseValueSubstitutingVariableReferences(attr->value(), WMLErrorInvalidVariableName); + if (!isValidVariableName(name)) { + reportWMLError(document(), WMLErrorInvalidVariableName); + return; + } + + m_name = name; + } else if (attr->name() == HTMLNames::valueAttr) + m_value = parseValueSubstitutingVariableReferences(attr->value()); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLSetvarElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent || !parent->isWMLElement()) + return; + + if (static_cast<WMLElement*>(parent)->isWMLTaskElement()) + static_cast<WMLTaskElement*>(parent)->registerVariableSetter(this); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLSetvarElement.h b/src/3rdparty/webkit/WebCore/wml/WMLSetvarElement.h new file mode 100644 index 0000000..ebedbc8 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLSetvarElement.h @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLSetvarElement_h +#define WMLSetvarElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class WMLSetvarElement : public WMLElement { +public: + WMLSetvarElement(const QualifiedName& tagName, Document*); + virtual ~WMLSetvarElement(); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + + String name() const { return m_name; } + String value() const { return m_value; } + +private: + String m_name; + String m_value; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTableElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLTableElement.cpp new file mode 100644 index 0000000..f241f46 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTableElement.cpp @@ -0,0 +1,269 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLTableElement.h" + +#include "CharacterNames.h" +#include "CSSPropertyNames.h" +#include "CSSValueKeywords.h" +#include "Document.h" +#include "HTMLNames.h" +#include "NodeList.h" +#include "RenderObject.h" +#include "Text.h" +#include "WMLErrorHandling.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLTableElement::WMLTableElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) + , m_columns(0) +{ +} + +WMLTableElement::~WMLTableElement() +{ +} + +bool WMLTableElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const +{ + if (attrName == HTMLNames::alignAttr) { + result = eTable; + return false; + } + + return WMLElement::mapToEntry(attrName, result); +} + +void WMLTableElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == columnsAttr) { + bool isNumber = false; + m_columns = attr->value().string().toUIntStrict(&isNumber); + + // Spec: This required attribute specifies the number of columns for the table. + // The user agent must create a table with exactly the number of columns specified + // by the attribute value. It is an error to specify a value of zero (“0”). + if (!m_columns || !isNumber) + reportWMLError(document(), WMLErrorInvalidColumnsNumberInTable); + } else if (attr->name() == HTMLNames::alignAttr) + m_alignment = parseValueForbiddingVariableReferences(attr->value()); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLTableElement::finishParsingChildren() +{ + WMLElement::finishParsingChildren(); + + if (!m_columns) { + reportWMLError(document(), WMLErrorInvalidColumnsNumberInTable); + return; + } + + Vector<WMLElement*> rowElements = scanTableChildElements(this, trTag); + if (rowElements.isEmpty()) + return; + + Vector<WMLElement*>::iterator it = rowElements.begin(); + Vector<WMLElement*>::iterator end = rowElements.end(); + + for (; it != end; ++it) { + WMLElement* rowElement = (*it); + + // Squeeze the table to fit in the desired number of columns + Vector<WMLElement*> columnElements = scanTableChildElements(rowElement, tdTag); + unsigned actualNumberOfColumns = columnElements.size(); + + if (actualNumberOfColumns > m_columns) { + joinSuperflousColumns(columnElements, rowElement); + columnElements = scanTableChildElements(rowElement, tdTag); + } else if (actualNumberOfColumns < m_columns) { + padWithEmptyColumns(columnElements, rowElement); + columnElements = scanTableChildElements(rowElement, tdTag); + } + + // Layout cells according to the 'align' attribute + alignCells(columnElements, rowElement); + } +} + +Vector<WMLElement*> WMLTableElement::scanTableChildElements(WMLElement* startElement, const QualifiedName& tagName) const +{ + Vector<WMLElement*> childElements; + + RefPtr<NodeList> children = startElement->childNodes(); + if (!children) + return childElements; + + unsigned length = children->length(); + for (unsigned i = 0; i < length; ++i) { + Node* child = children->item(i); + if (child->hasTagName(tagName)) + childElements.append(static_cast<WMLElement*>(child)); + } + + return childElements; +} + +void WMLTableElement::transferAllChildrenOfElementToTargetElement(WMLElement* sourceElement, WMLElement* targetElement, unsigned startOffset) const +{ + RefPtr<NodeList> children = sourceElement->childNodes(); + if (!children) + return; + + ExceptionCode ec = 0; + + unsigned length = children->length(); + for (unsigned i = startOffset; i < length; ++i) { + RefPtr<Node> clonedNode = children->item(i)->cloneNode(true); + targetElement->appendChild(clonedNode.release(), ec); + ASSERT(ec == 0); + } +} + +bool WMLTableElement::tryMergeAdjacentTextCells(Node* item, Node* nextItem) const +{ + if (!item || !nextItem) + return false; + + if (!item->isTextNode() || !nextItem->isTextNode()) + return false; + + Text* itemText = static_cast<Text*>(item); + Text* nextItemText = static_cast<Text*>(nextItem); + + String newContent = " "; + newContent += nextItemText->data(); + + ExceptionCode ec = 0; + itemText->appendData(newContent, ec); + ASSERT(ec == 0); + + return true; +} + +void WMLTableElement::joinSuperflousColumns(Vector<WMLElement*>& columnElements, WMLElement* rowElement) const +{ + // Spec: If the actual number of columns in a row is greater than the value specified + // by this attribute, the extra columns of the row must be aggregated into the last + // column such that the row contains exactly the number of columns specified. + WMLElement* lastColumn = columnElements.at(m_columns - 1); + ASSERT(lastColumn); + + // Merge superflous columns into a single one + RefPtr<WMLElement> newCell = new WMLElement(tdTag, document()); + transferAllChildrenOfElementToTargetElement(lastColumn, newCell.get(), 0); + + ExceptionCode ec = 0; + unsigned actualNumberOfColumns = columnElements.size(); + + for (unsigned i = m_columns; i < actualNumberOfColumns; ++i) { + WMLElement* columnElement = columnElements.at(i); + unsigned startOffset = 0; + + // Spec: A single inter-word space must be inserted between two cells that are being aggregated. + if (tryMergeAdjacentTextCells(newCell->lastChild(), columnElement->firstChild())) + ++startOffset; + + transferAllChildrenOfElementToTargetElement(columnElement, newCell.get(), startOffset); + } + + // Remove the columns, that have just been merged + unsigned i = actualNumberOfColumns; + for (; i > m_columns; --i) { + rowElement->removeChild(columnElements.at(i - 1), ec); + ASSERT(ec == 0); + } + + // Replace the last column in the row with the new merged column + rowElement->replaceChild(newCell.release(), lastColumn, ec); + ASSERT(ec == 0); +} + +void WMLTableElement::padWithEmptyColumns(Vector<WMLElement*>& columnElements, WMLElement* rowElement) const +{ + // Spec: If the actual number of columns in a row is less than the value specified by the columns + // attribute, the row must be padded with empty columns effectively as if the user agent + // appended empty td elements to the row. + ExceptionCode ec = 0; + + for (unsigned i = columnElements.size(); i < m_columns; ++i) { + RefPtr<WMLElement> newCell = new WMLElement(tdTag, document()); + rowElement->appendChild(newCell.release(), ec); + ASSERT(ec == 0); + } +} + +void WMLTableElement::alignCells(Vector<WMLElement*>& columnElements, WMLElement* rowElement) const +{ + // Spec: User agents should consider the current language when determining + // the default alignment and the direction of the table. + bool rtl = false; + if (RenderObject* renderer = rowElement->renderer()) { + if (RenderStyle* style = renderer->style()) + rtl = style->direction() == RTL; + } + + rowElement->setAttribute(HTMLNames::alignAttr, rtl ? "right" : "left"); + + if (m_alignment.isEmpty()) + return; + + unsigned alignLength = m_alignment.length(); + + Vector<WMLElement*>::iterator it = columnElements.begin(); + Vector<WMLElement*>::iterator end = columnElements.end(); + + for (unsigned i = 0; it != end; ++it, ++i) { + if (i == alignLength) + break; + + String alignmentValue; + switch (m_alignment[i]) { + case 'C': + alignmentValue = "center"; + break; + case 'L': + alignmentValue = "left"; + break; + case 'R': + alignmentValue = "right"; + break; + default: + break; + } + + if (alignmentValue.isEmpty()) + continue; + + (*it)->setAttribute(HTMLNames::alignAttr, alignmentValue); + } +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTableElement.h b/src/3rdparty/webkit/WebCore/wml/WMLTableElement.h new file mode 100644 index 0000000..baf46af --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTableElement.h @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLTableElement_h +#define WMLTableElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +namespace WebCore { + +class HTMLCollection; + +class WMLTableElement : public WMLElement { +public: + WMLTableElement(const QualifiedName& tagName, Document*); + virtual ~WMLTableElement(); + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(MappedAttribute*); + + virtual void finishParsingChildren(); + +private: + Vector<WMLElement*> scanTableChildElements(WMLElement* startElement, const QualifiedName& tagName) const; + + bool tryMergeAdjacentTextCells(Node* item, Node* nextItem) const; + void transferAllChildrenOfElementToTargetElement(WMLElement* sourceElement, WMLElement* targetElement, unsigned startOffset) const; + void joinSuperflousColumns(Vector<WMLElement*>& columnElements, WMLElement* rowElement) const; + void padWithEmptyColumns(Vector<WMLElement*>& columnElements, WMLElement* rowElement) const; + void alignCells(Vector<WMLElement*>& columnElements, WMLElement* rowElement) const; + + unsigned m_columns; + String m_alignment; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTagNames.in b/src/3rdparty/webkit/WebCore/wml/WMLTagNames.in new file mode 100644 index 0000000..293c603 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTagNames.in @@ -0,0 +1,34 @@ +namespace="WML" +namespaceURI="http://www.wapforum.org/DTD/wml_1.1.xml" +guardFactoryWith="ENABLE(WML)" + +a +access +anchor +br interfaceName=WMLBRElement +card +do +fieldset interfaceName=WMLFieldSetElement +go +head interfaceName=WMLElement +img interfaceName=WMLImageElement +# Note: 'insertedLegend' is not an official WML element - internal purpose only! +insertedLegend interfaceName=WMLInsertedLegendElement +meta +noop +onevent interfaceName=WMLOnEventElement +p +postfield +prev +refresh +setvar +table +td interfaceName=WMLElement +template +timer +tr interfaceName=WMLElement + +#if 0 +# These elements have a corresponding HTML*Element class, that we want to share code with. +# input, optgroup, option, select +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTaskElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLTaskElement.cpp new file mode 100644 index 0000000..1add1da --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTaskElement.cpp @@ -0,0 +1,95 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLTaskElement.h" + +#include "WMLAnchorElement.h" +#include "WMLDoElement.h" +#include "WMLNames.h" +#include "WMLOnEventElement.h" +#include "WMLPageState.h" +#include "WMLSetvarElement.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLTaskElement::WMLTaskElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) +{ +} + +WMLTaskElement::~WMLTaskElement() +{ +} + +void WMLTaskElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent || !parent->isWMLElement()) + return; + + if (parent->hasTagName(anchorTag)) + static_cast<WMLAnchorElement*>(parent)->registerTask(this); + else if (parent->hasTagName(doTag)) + static_cast<WMLDoElement*>(parent)->registerTask(this); + else if (parent->hasTagName(oneventTag)) + static_cast<WMLOnEventElement*>(parent)->registerTask(this); +} + +void WMLTaskElement::registerVariableSetter(WMLSetvarElement* element) +{ + ASSERT(element); + m_variableSetterElements.add(element); +} + +void WMLTaskElement::storeVariableState(WMLPageState* pageState) +{ + if (!pageState || m_variableSetterElements.isEmpty()) + return; + + WMLVariableMap variables; + HashSet<WMLSetvarElement*>::iterator it = m_variableSetterElements.begin(); + HashSet<WMLSetvarElement*>::iterator end = m_variableSetterElements.end(); + + for (; it != end; ++it) { + WMLSetvarElement* setterElement = (*it); + if (setterElement->name().isEmpty()) + continue; + + variables.set(setterElement->name(), setterElement->value()); + } + + if (variables.isEmpty()) + return; + + pageState->storeVariables(variables); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTaskElement.h b/src/3rdparty/webkit/WebCore/wml/WMLTaskElement.h new file mode 100644 index 0000000..f28571a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTaskElement.h @@ -0,0 +1,56 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLTaskElement_h +#define WMLTaskElement_h + +#if ENABLE(WML) +#include "WMLElement.h" + +#include <wtf/HashSet.h> + +namespace WebCore { + +class WMLPageState; +class WMLSetvarElement; + +class WMLTaskElement : public WMLElement { +public: + WMLTaskElement(const QualifiedName& tagName, Document*); + virtual ~WMLTaskElement(); + + virtual bool isWMLTaskElement() const { return true; } + + virtual void insertedIntoDocument(); + virtual void executeTask(Event*) = 0; + + void registerVariableSetter(WMLSetvarElement*); + +protected: + void storeVariableState(WMLPageState*); + +private: + HashSet<WMLSetvarElement*> m_variableSetterElements; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTemplateElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLTemplateElement.cpp new file mode 100644 index 0000000..d0bfa61 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTemplateElement.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLTemplateElement.h" + +#include "NodeList.h" +#include "WMLCardElement.h" +#include "WMLDocument.h" +#include "WMLIntrinsicEventHandler.h" +#include "WMLNames.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLTemplateElement::WMLTemplateElement(const QualifiedName& tagName, Document* doc) + : WMLEventHandlingElement(tagName, doc) +{ +} + +WMLTemplateElement::~WMLTemplateElement() +{ +} + +void WMLTemplateElement::parseMappedAttribute(MappedAttribute* attr) +{ + WMLIntrinsicEventType eventType = WMLIntrinsicEventUnknown; + + if (attr->name() == onenterforwardAttr) + eventType = WMLIntrinsicEventOnEnterForward; + else if (attr->name() == onenterbackwardAttr) + eventType = WMLIntrinsicEventOnEnterBackward; + else if (attr->name() == ontimerAttr) + eventType = WMLIntrinsicEventOnTimer; + else { + WMLEventHandlingElement::parseMappedAttribute(attr); + return; + } + + if (eventType == WMLIntrinsicEventUnknown) + return; + + // Register intrinsic event in card + RefPtr<WMLIntrinsicEvent> event = WMLIntrinsicEvent::create(document(), attr->value()); + + createEventHandlerIfNeeded(); + eventHandler()->registerIntrinsicEvent(eventType, event); +} + +void WMLTemplateElement::registerTemplatesInDocument(Document* doc) +{ + ASSERT(doc); + + // Build list of cards in document + RefPtr<NodeList> nodeList = doc->getElementsByTagName("card"); + if (!nodeList) + return; + + unsigned length = nodeList->length(); + if (length < 1) + return; + + HashSet<WMLCardElement*> cards; + for (unsigned i = 0; i < length; ++i) + cards.add(static_cast<WMLCardElement*>(nodeList->item(i))); + + if (cards.isEmpty()) + return; + + // Register template element to all cards + nodeList = doc->getElementsByTagName("template"); + if (!nodeList) + return; + + length = nodeList->length(); + if (length < 1) + return; + + // Only one template element should be allowed in a document + // Calling setTemplateElement() twice on a WMLCardElement, will result in a tokenizer error. + for (unsigned i = 0; i < length; ++i) { + WMLTemplateElement* temp = static_cast<WMLTemplateElement*>(nodeList->item(i)); + + HashSet<WMLCardElement*>::iterator it = cards.begin(); + HashSet<WMLCardElement*>::iterator end = cards.end(); + + for (; it != end; ++it) + (*it)->setTemplateElement(temp); + } +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTemplateElement.h b/src/3rdparty/webkit/WebCore/wml/WMLTemplateElement.h new file mode 100644 index 0000000..1ba720e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTemplateElement.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLTemplateElement_h +#define WMLTemplateElement_h + +#if ENABLE(WML) +#include "WMLEventHandlingElement.h" + +namespace WebCore { + +class WMLTemplateElement : public WMLEventHandlingElement { +public: + WMLTemplateElement(const QualifiedName&, Document*); + virtual ~WMLTemplateElement(); + + virtual void parseMappedAttribute(MappedAttribute*); + + static void registerTemplatesInDocument(Document*); +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTimerElement.cpp b/src/3rdparty/webkit/WebCore/wml/WMLTimerElement.cpp new file mode 100644 index 0000000..7cd2e50 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTimerElement.cpp @@ -0,0 +1,141 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLTimerElement.h" + +#include "HTMLNames.h" +#include "WMLCardElement.h" +#include "WMLDocument.h" +#include "WMLNames.h" +#include "WMLPageState.h" +#include "WMLTemplateElement.h" +#include "WMLVariables.h" + +namespace WebCore { + +using namespace WMLNames; + +WMLTimerElement::WMLTimerElement(const QualifiedName& tagName, Document* doc) + : WMLElement(tagName, doc) + , m_timer(this, &WMLTimerElement::timerFired) +{ +} + +void WMLTimerElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::nameAttr) + m_name = parseValueForbiddingVariableReferences(attr->value()); + else if (attr->name() == HTMLNames::valueAttr) + m_value = parseValueSubstitutingVariableReferences(attr->value()); + else + WMLElement::parseMappedAttribute(attr); +} + +void WMLTimerElement::insertedIntoDocument() +{ + WMLElement::insertedIntoDocument(); + + // If the value of timeout is not a positive integer, ignore it + if (m_value.toInt() <= 0) + return; + + Node* parent = parentNode(); + ASSERT(parent); + + if (!parent || !parent->isWMLElement()) + return; + + if (parent->hasTagName(cardTag)) { + m_card = static_cast<WMLCardElement*>(parent); + m_card->setIntrinsicEventTimer(this); + } +} + +void WMLTimerElement::timerFired(Timer<WMLTimerElement>*) +{ + if (!m_card) + return; + + WMLPageState* pageState = wmlPageStateForDocument(document()); + if (!pageState) + return; + + // When the timer expires, set the name varialbe of timer to '0' + if (!m_name.isEmpty()) { + m_value = "0"; + pageState->storeVariable(m_name, m_value); + } + + WMLIntrinsicEventType eventType = WMLIntrinsicEventOnTimer; + WMLIntrinsicEventHandler* eventHandler = m_card->eventHandler(); + + bool hasIntrinsicEvent = false; + if (eventHandler && eventHandler->hasIntrinsicEvent(eventType)) + hasIntrinsicEvent = true; + else if (m_card->templateElement()) { + eventHandler = m_card->templateElement()->eventHandler(); + if (eventHandler && eventHandler->hasIntrinsicEvent(eventType)) + hasIntrinsicEvent = true; + } + + if (hasIntrinsicEvent) + eventHandler->triggerIntrinsicEvent(eventType); +} + +void WMLTimerElement::start(int interval) +{ + if (!m_card || m_timer.isActive()) + return; + + if (interval <= 0 && !m_name.isEmpty()) { + if (WMLPageState* pageState = wmlPageStateForDocument(document())) + interval = pageState->getVariable(m_name).toInt(); + } + + if (interval <= 0) + interval = m_value.toInt(); + + if (interval > 0) + m_timer.startOneShot(interval / 10.0f); +} + +void WMLTimerElement::stop() +{ + if (m_timer.isActive()) + m_timer.stop(); +} + +void WMLTimerElement::storeIntervalToPageState() +{ + if (!m_timer.isActive()) + return; + + int interval = static_cast<int>(m_timer.nextFireInterval()) * 10; + + if (WMLPageState* pageState = wmlPageStateForDocument(document())) + pageState->storeVariable(m_name, String::number(interval)); +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLTimerElement.h b/src/3rdparty/webkit/WebCore/wml/WMLTimerElement.h new file mode 100644 index 0000000..eecacf3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLTimerElement.h @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLTimerElement_h +#define WMLTimerElement_h + +#if ENABLE(WML) +#include "Timer.h" +#include "WMLElement.h" + +namespace WebCore { + +class WMLCardElement; + +class WMLTimerElement : public WMLElement { +public: + WMLTimerElement(const QualifiedName& tagName, Document*); + + virtual void parseMappedAttribute(MappedAttribute*); + virtual void insertedIntoDocument(); + + void timerFired(Timer<WMLTimerElement>*); + + void start(int interval = -1); + void stop(); + void storeIntervalToPageState(); + +private: + WMLCardElement* m_card; + String m_name; + String m_value; + Timer<WMLTimerElement> m_timer; +}; + +} + +#endif +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLVariables.cpp b/src/3rdparty/webkit/WebCore/wml/WMLVariables.cpp new file mode 100644 index 0000000..f206234 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLVariables.cpp @@ -0,0 +1,288 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" + +#if ENABLE(WML) +#include "WMLVariables.h" + +#include "WMLDocument.h" +#include <wtf/ASCIICType.h> + +namespace WebCore { + +// WML variables specification, excluding the +// pre-WML 1.0 deprecated variable syntax +// +// varname = ("_" | alpha) ("_" | alpha | digit)* +// conv = ":" ("e" ("scape")? | "n" ("oesc")? | "u" ("nesc")?) +// var = ("$" varname) | ("$(" varname (conv)? ")") + +static bool isValidFirstVariableNameCharacter(const UChar& character) +{ + return WTF::isASCIIAlpha(character) + || character == '_'; +} + +static bool isValidVariableNameCharacter(const UChar& character) +{ + return WTF::isASCIIAlpha(character) + || WTF::isASCIIDigit(character) + || character == '_'; +} + +static bool isValidVariableEscapingModeString(const String& mode, WMLVariableEscapingMode& escapeMode) +{ + if (mode == "e" || mode == "escape") + escapeMode = WMLVariableEscapingEscape; + else if (mode == "u" || mode == "unesc") + escapeMode = WMLVariableEscapingUnescape; + else if (mode == "n" || mode == "noesc") + escapeMode = WMLVariableEscapingNone; + else + return false; + + return true; +} + +bool isValidVariableName(const String& name) +{ + if (name.isEmpty()) + return false; + + const UChar* characters = name.characters(); + if (!isValidFirstVariableNameCharacter(characters[0])) + return false; + + unsigned length = name.length(); + for (unsigned i = 1; i < length; ++i) { + if (!isValidVariableNameCharacter(characters[i])) + return false; + } + + return true; +} + +bool containsVariableReference(const String& text, bool& isValid) +{ + isValid = true; + bool foundReference = false; + bool finished = false; + int currentPosition = 0; + const UChar* characters = text.characters(); + + while (!finished) { + // Find beginning of variable reference + int referenceStartPosition = text.find('$', currentPosition); + if (referenceStartPosition == -1) { + finished = true; + break; + } + + foundReference = true; + + int nameStartPosition = referenceStartPosition + 1; + int nameEndPosition = -1; + + if (characters[nameStartPosition] == '(') { + // If the input string contains an open brace, a close brace must exist as well + nameEndPosition = text.find(')', nameStartPosition + 1); + if (nameEndPosition == -1) { + finished = true; + isValid = false; + break; + } + + ++nameStartPosition; + } else { + int length = text.length(); + for (nameEndPosition = nameStartPosition; nameEndPosition < length; ++nameEndPosition) { + if (!isValidVariableNameCharacter(text[nameEndPosition])) + break; + } + + --nameEndPosition; + } + + if (nameEndPosition < nameStartPosition) { + finished = true; + isValid = false; + break; + } + + // Eventually split of conversion string, and check it's syntax afterwards + String conversionString; + String variableName = text.substring(nameStartPosition, nameEndPosition - nameStartPosition); + + int conversionStringStart = variableName.find(':'); + if (conversionStringStart != -1) { + conversionString = variableName.substring(conversionStringStart + 1, variableName.length() - (conversionStringStart + 1)); + variableName = variableName.left(conversionStringStart); + } + + isValid = isValidVariableName(variableName); + if (!isValid) { + finished = true; + break; + } + + if (!conversionString.isEmpty()) { + isValid = isValidVariableName(conversionString); + if (!isValid) { + finished = true; + break; + } + + WMLVariableEscapingMode escapeMode = WMLVariableEscapingNone; + isValid = isValidVariableEscapingModeString(conversionString, escapeMode); + if (!isValid) { + finished = true; + break; + } + } + + currentPosition = nameEndPosition; + } + + return foundReference; +} + +String substituteVariableReferences(const String& reference, Document* document, WMLVariableEscapingMode escapeMode) +{ + ASSERT(document); + + if (reference.isEmpty()) + return reference; + + WMLPageState* pageState = wmlPageStateForDocument(document); + if (!pageState) + return reference; + + bool isValid = true; + String remainingInput = reference; + String result; + + while (!remainingInput.isEmpty()) { + ASSERT(isValid); + + int start = remainingInput.find("$"); + if (start == -1) { + // Consume all remaining characters, as there's nothing more to substitute + result += remainingInput; + break; + } + + // Consume all characters until the variable reference beginning + result += remainingInput.left(start); + remainingInput.remove(0, start); + + // Transform adjacent dollar signs into a single dollar sign as string literal + if (remainingInput[1] == '$') { + result += "$"; + remainingInput.remove(0, 2); + continue; + } + + String variableName; + String conversionMode; + + if (remainingInput[1] == '(') { + int referenceEndPosition = remainingInput.find(")"); + if (referenceEndPosition == -1) { + isValid = false; + break; + } + + variableName = remainingInput.substring(2, referenceEndPosition - 2); + remainingInput.remove(0, referenceEndPosition + 1); + + // Determine variable conversion mode string + int pos = variableName.find(':'); + if (pos != -1) { + conversionMode = variableName.substring(pos + 1, variableName.length() - (pos + 1)); + variableName = variableName.left(pos); + } + } else { + int length = remainingInput.length(); + int referenceEndPosition = 1; + + for (; referenceEndPosition < length; ++referenceEndPosition) { + if (!isValidVariableNameCharacter(remainingInput[referenceEndPosition])) + break; + } + + variableName = remainingInput.substring(1, referenceEndPosition - 1); + remainingInput.remove(0, referenceEndPosition); + } + + isValid = isValidVariableName(variableName); + if (!isValid) + break; + + ASSERT(!variableName.isEmpty()); + + String variableValue = pageState->getVariable(variableName); + if (variableValue.isEmpty()) + continue; + + if (containsVariableReference(variableValue, isValid)) { + if (!isValid) + break; + + variableValue = substituteVariableReferences(variableValue, document, escapeMode); + continue; + } + + if (!conversionMode.isEmpty()) { + // Override default escape mode, if desired + WMLVariableEscapingMode specifiedEscapeMode = WMLVariableEscapingNone; + if (isValid = isValidVariableEscapingModeString(conversionMode, specifiedEscapeMode)) + escapeMode = specifiedEscapeMode; + + if (!isValid) + break; + } + + switch (escapeMode) { + case WMLVariableEscapingNone: + break; + case WMLVariableEscapingEscape: + variableValue = encodeWithURLEscapeSequences(variableValue); + break; + case WMLVariableEscapingUnescape: + variableValue = decodeURLEscapeSequences(variableValue); + break; + } + + result += variableValue; + ASSERT(isValid); + } + + if (!isValid) { + reportWMLError(document, WMLErrorInvalidVariableReference); + return reference; + } + + return result; +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/wml/WMLVariables.h b/src/3rdparty/webkit/WebCore/wml/WMLVariables.h new file mode 100644 index 0000000..18c6ba4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/wml/WMLVariables.h @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef WMLVariables_h +#define WMLVariables_h + +#if ENABLE(WML) +namespace WebCore { + + class Document; + class String; + + enum WMLVariableEscapingMode { + WMLVariableEscapingNone = 0, + WMLVariableEscapingEscape, + WMLVariableEscapingUnescape + }; + + bool isValidVariableName(const String&); + bool containsVariableReference(const String&, bool& isValid); + + String substituteVariableReferences(const String& variableReference, + Document*, + WMLVariableEscapingMode mode = WMLVariableEscapingNone); + +} + +#endif +#endif |