diff options
author | Feng Qian <fqian@google.com> | 2009-06-17 12:12:20 -0700 |
---|---|---|
committer | Feng Qian <fqian@google.com> | 2009-06-17 12:12:20 -0700 |
commit | 5f1ab04193ad0130ca8204aadaceae083aca9881 (patch) | |
tree | 5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/wml | |
parent | 194315e5a908cc8ed67d597010544803eef1ac59 (diff) | |
download | external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2 |
Get WebKit r44544.
Diffstat (limited to 'WebCore/wml')
31 files changed, 467 insertions, 155 deletions
diff --git a/WebCore/wml/WMLAElement.cpp b/WebCore/wml/WMLAElement.cpp index 758be78..5fbeac6 100644 --- a/WebCore/wml/WMLAElement.cpp +++ b/WebCore/wml/WMLAElement.cpp @@ -37,6 +37,7 @@ #include "FrameLoader.h" #include "HTMLNames.h" #include "KeyboardEvent.h" +#include "MappedAttribute.h" #include "MouseEvent.h" #include "RenderBox.h" #include "WMLNames.h" @@ -56,7 +57,7 @@ void WMLAElement::parseMappedAttribute(MappedAttribute* attr) bool wasLink = isLink(); setIsLink(!attr->isNull()); if (wasLink != isLink()) - setChanged(); + setNeedsStyleRecalc(); if (isLink() && document()->isDNSPrefetchEnabled()) { String value = attr->value(); if (protocolIs(value, "http") || protocolIs(value, "https") || value.startsWith("//")) diff --git a/WebCore/wml/WMLAccessElement.cpp b/WebCore/wml/WMLAccessElement.cpp index 7668c74..db0ab67 100644 --- a/WebCore/wml/WMLAccessElement.cpp +++ b/WebCore/wml/WMLAccessElement.cpp @@ -23,6 +23,7 @@ #if ENABLE(WML) #include "WMLAccessElement.h" +#include "MappedAttribute.h" #include "WMLDocument.h" #include "WMLNames.h" #include "WMLVariables.h" diff --git a/WebCore/wml/WMLBRElement.cpp b/WebCore/wml/WMLBRElement.cpp index 7bd6360..035619f 100644 --- a/WebCore/wml/WMLBRElement.cpp +++ b/WebCore/wml/WMLBRElement.cpp @@ -30,6 +30,7 @@ #include "CSSPropertyNames.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "RenderBR.h" namespace WebCore { diff --git a/WebCore/wml/WMLCardElement.cpp b/WebCore/wml/WMLCardElement.cpp index b969612..c8e92af 100644 --- a/WebCore/wml/WMLCardElement.cpp +++ b/WebCore/wml/WMLCardElement.cpp @@ -26,10 +26,12 @@ #include "Frame.h" #include "FrameLoader.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "NodeList.h" #include "RenderStyle.h" #include "WMLDocument.h" #include "WMLDoElement.h" +#include "WMLInputElement.h" #include "WMLIntrinsicEventHandler.h" #include "WMLNames.h" #include "WMLTemplateElement.h" @@ -48,6 +50,7 @@ WMLCardElement::WMLCardElement(const QualifiedName& tagName, Document* doc) , m_eventTimer(0) , m_template(0) { + ASSERT(hasTagName(cardTag)); } WMLCardElement::~WMLCardElement() @@ -162,16 +165,18 @@ void WMLCardElement::handleIntrinsicEventIfNeeded() if (m_eventTimer) m_eventTimer->start(); - // FIXME: Initialize input/select elements in this card - /* - Node* node = this; - while (node = node->traverseNextNode()) { + // FIXME: Initialize select elements in this card + for (Node* node = traverseNextNode(); node != 0; node = node->traverseNextNode()) { + if (!node->isElementNode()) + continue; + if (node->hasTagName(inputTag)) - static_cast<WMLInputElement*>(node)->init(); + static_cast<WMLInputElement*>(node)->initialize(); + /* else if (node->hasTagName(selectTag)) static_cast<WMLSelectElement*>(node)->selectInitialOptions(); + */ } - */ } void WMLCardElement::handleDeckLevelTaskOverridesIfNeeded() diff --git a/WebCore/wml/WMLDoElement.cpp b/WebCore/wml/WMLDoElement.cpp index 8d7952b..916bc6e 100644 --- a/WebCore/wml/WMLDoElement.cpp +++ b/WebCore/wml/WMLDoElement.cpp @@ -27,6 +27,7 @@ #include "EventNames.h" #include "HTMLNames.h" #include "KeyboardEvent.h" +#include "MappedAttribute.h" #include "Page.h" #include "RenderButton.h" #include "WMLCardElement.h" diff --git a/WebCore/wml/WMLDocument.cpp b/WebCore/wml/WMLDocument.cpp index 36c436f..7f73848 100644 --- a/WebCore/wml/WMLDocument.cpp +++ b/WebCore/wml/WMLDocument.cpp @@ -61,6 +61,12 @@ void WMLDocument::finishedParsing() // Remember that we'e successfully entered the deck wmlPageState->setNeedCheckDeckAccess(false); + initialize(); + Document::finishedParsing(); +} + +void WMLDocument::initialize() +{ // Notify the existance of templates to all cards of the current deck WMLTemplateElement::registerTemplatesInDocument(this); @@ -77,8 +83,6 @@ void WMLDocument::finishedParsing() // Handle card-level intrinsic event card->handleIntrinsicEventIfNeeded(); - - Document::finishedParsing(); } WMLPageState* wmlPageStateForDocument(Document* doc) diff --git a/WebCore/wml/WMLDocument.h b/WebCore/wml/WMLDocument.h index d7eb8b2..9189085 100644 --- a/WebCore/wml/WMLDocument.h +++ b/WebCore/wml/WMLDocument.h @@ -40,6 +40,8 @@ public: virtual bool isWMLDocument() const { return true; } virtual void finishedParsing(); + void initialize(); + private: WMLDocument(Frame*); }; diff --git a/WebCore/wml/WMLElement.cpp b/WebCore/wml/WMLElement.cpp index c88c5d3..e818f9d 100644 --- a/WebCore/wml/WMLElement.cpp +++ b/WebCore/wml/WMLElement.cpp @@ -25,6 +25,7 @@ #include "CSSPropertyNames.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "RenderObject.h" #include "WMLErrorHandling.h" #include "WMLNames.h" diff --git a/WebCore/wml/WMLFieldSetElement.cpp b/WebCore/wml/WMLFieldSetElement.cpp index d32f9b1..8146375 100644 --- a/WebCore/wml/WMLFieldSetElement.cpp +++ b/WebCore/wml/WMLFieldSetElement.cpp @@ -24,6 +24,7 @@ #include "WMLFieldSetElement.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "RenderFieldset.h" #include "Text.h" #include "WMLElementFactory.h" diff --git a/WebCore/wml/WMLFormControlElement.cpp b/WebCore/wml/WMLFormControlElement.cpp index 4e76cb8..f849ac8 100644 --- a/WebCore/wml/WMLFormControlElement.cpp +++ b/WebCore/wml/WMLFormControlElement.cpp @@ -29,7 +29,6 @@ namespace WebCore { -// WMLFormControlElement WMLFormControlElement::WMLFormControlElement(const QualifiedName& tagName, Document* document) : WMLElement(tagName, document) , m_valueMatchesRenderer(false) @@ -56,14 +55,24 @@ bool WMLFormControlElement::isFocusable() const return true; } -// WMLFormControlElementWithState -WMLFormControlElementWithState::WMLFormControlElementWithState(const QualifiedName& tagName, Document* document) - : WMLFormControlElement(tagName, document) +void WMLFormControlElement::attach() { + ASSERT(!attached()); + WMLElement::attach(); + + // The call to updateFromElement() needs to go after the call through + // to the base class's attach() because that can sometimes do a close + // on the renderer. + if (renderer()) + renderer()->updateFromElement(); } -WMLFormControlElementWithState::~WMLFormControlElementWithState() +void WMLFormControlElement::recalcStyle(StyleChange change) { + WMLElement::recalcStyle(change); + + if (renderer()) + renderer()->updateFromElement(); } } diff --git a/WebCore/wml/WMLFormControlElement.h b/WebCore/wml/WMLFormControlElement.h index 449e512..dde86ed 100644 --- a/WebCore/wml/WMLFormControlElement.h +++ b/WebCore/wml/WMLFormControlElement.h @@ -22,42 +22,31 @@ #define WMLFormControlElement_h #if ENABLE(WML) -#include "FormControlElementWithState.h" -#include "FormControlElement.h" #include "WMLElement.h" namespace WebCore { -class WMLFormControlElement : public WMLElement, public FormControlElement { +class WMLFormControlElement : public WMLElement { public: - WMLFormControlElement(const QualifiedName& tagName, Document* document); + WMLFormControlElement(const QualifiedName&, Document*); virtual ~WMLFormControlElement(); - virtual bool isEnabled() const { return true; } virtual bool isFormControlElement() const { return true; } - virtual bool isReadOnlyControl() const { return false; } - virtual bool isTextControl() const { return false; } + virtual bool isReadOnlyFormControl() const { return false; } + virtual bool isTextFormControl() const { return false; } - virtual bool valueMatchesRenderer() const { return m_valueMatchesRenderer; } - virtual void setValueMatchesRenderer(bool b = true) { m_valueMatchesRenderer = b; } - - virtual const AtomicString& name() const { return emptyAtom; } + virtual bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; } + virtual void setFormControlValueMatchesRenderer(bool b = true) { m_valueMatchesRenderer = b; } virtual bool isFocusable() const; + virtual void attach(); + virtual void recalcStyle(StyleChange); + private: bool m_valueMatchesRenderer; }; -class WMLFormControlElementWithState : public WMLFormControlElement, public FormControlElementWithState { -public: - WMLFormControlElementWithState(const QualifiedName& tagName, Document*); - virtual ~WMLFormControlElementWithState(); - - virtual bool isFormControlElementWithState() const { return true; } - virtual FormControlElement* toFormControlElement() { return this; } -}; - } #endif diff --git a/WebCore/wml/WMLGoElement.cpp b/WebCore/wml/WMLGoElement.cpp index 603a71d..7293e66 100644 --- a/WebCore/wml/WMLGoElement.cpp +++ b/WebCore/wml/WMLGoElement.cpp @@ -28,6 +28,7 @@ #include "Frame.h" #include "FrameLoader.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "ResourceRequest.h" #include "TextEncoding.h" #include "WMLCardElement.h" diff --git a/WebCore/wml/WMLImageElement.cpp b/WebCore/wml/WMLImageElement.cpp index 39d103d..d47868a 100644 --- a/WebCore/wml/WMLImageElement.cpp +++ b/WebCore/wml/WMLImageElement.cpp @@ -27,6 +27,7 @@ #include "CSSValueKeywords.h" #include "HTMLElement.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "RenderImage.h" #include "WMLNames.h" #include "WMLVariables.h" diff --git a/WebCore/wml/WMLInputElement.cpp b/WebCore/wml/WMLInputElement.cpp index 9a44013..cb824d1 100644 --- a/WebCore/wml/WMLInputElement.cpp +++ b/WebCore/wml/WMLInputElement.cpp @@ -28,6 +28,7 @@ #include "Frame.h" #include "HTMLNames.h" #include "KeyboardEvent.h" +#include "MappedAttribute.h" #include "RenderTextControlSingleLine.h" #include "TextEvent.h" #include "WMLDocument.h" @@ -37,8 +38,7 @@ namespace WebCore { WMLInputElement::WMLInputElement(const QualifiedName& tagName, Document* doc) - : WMLFormControlElementWithState(tagName, doc) - , m_data(this, this) + : WMLFormControlElement(tagName, doc) , m_isPasswordField(false) , m_isEmptyOk(false) , m_numOfCharsAllowedByMask(0) @@ -59,17 +59,17 @@ static const AtomicString& formatCodes() bool WMLInputElement::isKeyboardFocusable(KeyboardEvent*) const { - return WMLFormControlElementWithState::isFocusable(); + return WMLFormControlElement::isFocusable(); } bool WMLInputElement::isMouseFocusable() const { - return WMLFormControlElementWithState::isFocusable(); + return WMLFormControlElement::isFocusable(); } void WMLInputElement::dispatchFocusEvent() { - InputElement::dispatchFocusEvent(m_data, document()); + InputElement::dispatchFocusEvent(m_data, this, this); WMLElement::dispatchFocusEvent(); } @@ -83,22 +83,22 @@ void WMLInputElement::dispatchBlurEvent() } // update the name variable of WML input elmenet - String nameVariable = name(); + String nameVariable = formControlName(); if (!nameVariable.isEmpty()) wmlPageStateForDocument(document())->storeVariable(nameVariable, val); - InputElement::dispatchBlurEvent(m_data, document()); + InputElement::dispatchBlurEvent(m_data, this, this); WMLElement::dispatchBlurEvent(); } void WMLInputElement::updateFocusAppearance(bool restorePreviousSelection) { - InputElement::updateFocusAppearance(m_data, document(), restorePreviousSelection); + InputElement::updateFocusAppearance(m_data, this, this, restorePreviousSelection); } void WMLInputElement::aboutToUnload() { - InputElement::aboutToUnload(m_data, document()); + InputElement::aboutToUnload(this, this); } int WMLInputElement::size() const @@ -106,7 +106,7 @@ int WMLInputElement::size() const return m_data.size(); } -const AtomicString& WMLInputElement::type() const +const AtomicString& WMLInputElement::formControlType() const { // needs to be lowercase according to DOM spec if (m_isPasswordField) { @@ -118,7 +118,7 @@ const AtomicString& WMLInputElement::type() const return text; } -const AtomicString& WMLInputElement::name() const +const AtomicString& WMLInputElement::formControlName() const { return m_data.name(); } @@ -134,30 +134,30 @@ String WMLInputElement::value() const void WMLInputElement::setValue(const String& value) { - InputElement::updatePlaceholderVisibility(m_data, document()); - setValueMatchesRenderer(false); + InputElement::updatePlaceholderVisibility(m_data, this, this); + setFormControlValueMatchesRenderer(false); m_data.setValue(constrainValue(value)); if (inDocument()) - document()->updateRendering(); + document()->updateStyleIfNeeded(); if (renderer()) renderer()->updateFromElement(); - setChanged(); + setNeedsStyleRecalc(); unsigned max = m_data.value().length(); if (document()->focusedNode() == this) - InputElement::updateSelectionRange(m_data, max, max); + InputElement::updateSelectionRange(this, this, max, max); else cacheSelection(max, max); - InputElement::notifyFormStateChanged(m_data, document()); + InputElement::notifyFormStateChanged(this); } void WMLInputElement::setValueFromRenderer(const String& value) { - InputElement::setValueFromRenderer(m_data, document(), value); + InputElement::setValueFromRenderer(m_data, this, this, value); } -bool WMLInputElement::saveState(String& result) const +bool WMLInputElement::saveFormControlState(String& result) const { if (m_isPasswordField) return false; @@ -166,7 +166,7 @@ bool WMLInputElement::saveState(String& result) const return true; } -void WMLInputElement::restoreState(const String& state) +void WMLInputElement::restoreFormControlState(const String& state) { ASSERT(!m_isPasswordField); // should never save/restore password fields setValue(state); @@ -194,12 +194,12 @@ void WMLInputElement::parseMappedAttribute(MappedAttribute* attr) } else if (attr->name() == HTMLNames::valueAttr) { // We only need to setChanged if the form is looking at the default value right now. if (m_data.value().isNull()) - setChanged(); - setValueMatchesRenderer(false); + setNeedsStyleRecalc(); + setFormControlValueMatchesRenderer(false); } else if (attr->name() == HTMLNames::maxlengthAttr) - InputElement::parseMaxLengthAttribute(m_data, attr); + InputElement::parseMaxLengthAttribute(m_data, this, this, attr); else if (attr->name() == HTMLNames::sizeAttr) - InputElement::parseSizeAttribute(m_data, attr); + InputElement::parseSizeAttribute(m_data, this, attr); else if (attr->name() == WMLNames::formatAttr) m_formatMask = validateInputMask(parseValueForbiddingVariableReferences(attr->value())); else if (attr->name() == WMLNames::emptyokAttr) @@ -224,37 +224,18 @@ RenderObject* WMLInputElement::createRenderer(RenderArena* arena, RenderStyle*) return new (arena) RenderTextControlSingleLine(this); } -void WMLInputElement::attach() -{ - ASSERT(!attached()); - WMLElement::attach(); - - // The call to updateFromElement() needs to go after the call through - // to the base class's attach() because that can sometimes do a close - // on the renderer. - if (renderer()) - renderer()->updateFromElement(); - - // FIXME: maybe this is not a good place to do this since it is possible - // to cause unexpected several times initialise of <input> if we force the - // node to be reattached. But placing it here can ensure the run-webkit-tests - // get expected result,i.e. multiple-times initialise is expected when making - // layout test for WMLInputElement - init(); -} - void WMLInputElement::detach() { WMLElement::detach(); - setValueMatchesRenderer(false); + setFormControlValueMatchesRenderer(false); } bool WMLInputElement::appendFormData(FormDataList& encoding, bool) { - if (name().isEmpty()) + if (formControlName().isEmpty()) return false; - encoding.appendData(name(), value()); + encoding.appendData(formControlName(), value()); return true; } @@ -300,13 +281,13 @@ void WMLInputElement::defaultEventHandler(Event* evt) if (clickDefaultFormButton) { // Fire onChange for text fields. RenderObject* r = renderer(); - if (r && r->isEdited()) { - dispatchEventForType(eventNames().changeEvent, true, false); + if (r && toRenderTextControl(r)->isEdited()) { + dispatchEvent(eventNames().changeEvent, true, false); // Refetch the renderer since arbitrary JS code run during onchange can do anything, including destroying it. r = renderer(); if (r) - r->setEdited(false); + toRenderTextControl(r)->setEdited(false); } evt->setDefaultHandled(); @@ -314,7 +295,7 @@ void WMLInputElement::defaultEventHandler(Event* evt) } if (evt->isBeforeTextInsertedEvent()) - InputElement::handleBeforeTextInsertedEvent(m_data, document(), evt); + InputElement::handleBeforeTextInsertedEvent(m_data, this, document(), evt); if (renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent() || evt->type() == eventNames().blurEvent || evt->type() == eventNames().focusEvent)) static_cast<RenderTextControlSingleLine*>(renderer())->forwardEvent(evt); @@ -328,7 +309,7 @@ void WMLInputElement::cacheSelection(int start, int end) String WMLInputElement::constrainValue(const String& proposedValue) const { - return InputElement::constrainValue(m_data, proposedValue, m_data.maxLength()); + return InputElement::constrainValue(this, proposedValue, m_data.maxLength()); } void WMLInputElement::documentDidBecomeActive() @@ -359,9 +340,9 @@ void WMLInputElement::didMoveToNewOwnerDocument() WMLElement::didMoveToNewOwnerDocument(); } -void WMLInputElement::init() +void WMLInputElement::initialize() { - String nameVariable = name(); + String nameVariable = formControlName(); String variableValue; WMLPageState* pageSate = wmlPageStateForDocument(document()); ASSERT(pageSate); diff --git a/WebCore/wml/WMLInputElement.h b/WebCore/wml/WMLInputElement.h index a2c904f..7529968 100644 --- a/WebCore/wml/WMLInputElement.h +++ b/WebCore/wml/WMLInputElement.h @@ -29,7 +29,7 @@ namespace WebCore { class FormDataList; -class WMLInputElement : public WMLFormControlElementWithState, public InputElement { +class WMLInputElement : public WMLFormControlElement, public InputElement { public: WMLInputElement(const QualifiedName& tagName, Document*); virtual ~WMLInputElement(); @@ -45,7 +45,7 @@ public: virtual bool isChecked() const { return false; } virtual bool isAutofilled() const { return false; } virtual bool isIndeterminate() const { return false; } - virtual bool isTextControl() const { return true; } + virtual bool isTextFormControl() const { return true; } virtual bool isRadioButton() const { return false; } virtual bool isTextField() const { return true; } virtual bool isSearchField() const { return false; } @@ -54,15 +54,16 @@ public: virtual bool searchEventsShouldBeDispatched() const { return false; } virtual int size() const; - virtual const AtomicString& type() const; - virtual const AtomicString& name() const; + virtual const AtomicString& formControlType() const; + virtual const AtomicString& formControlName() const; virtual String value() const; virtual void setValue(const String&); - virtual String placeholderValue() const { return String(); } + virtual String placeholder() const { return String(); } + virtual void setPlaceholder(const String&) { } virtual void setValueFromRenderer(const String&); - virtual bool saveState(String& value) const; - virtual void restoreState(const String&); + virtual bool saveFormControlState(String& value) const; + virtual void restoreFormControlState(const String&); virtual void select(); virtual void accessKeyAction(bool sendToAnyElement); @@ -71,7 +72,6 @@ public: virtual void copyNonAttributeProperties(const Element* source); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - virtual void attach(); virtual void detach(); virtual bool appendFormData(FormDataList&, bool); virtual void reset(); @@ -91,7 +91,9 @@ public: bool isConformedToInputMask(UChar, unsigned, bool isUserInput = true); private: - void init(); + friend class WMLCardElement; + void initialize(); + String validateInputMask(const String&); unsigned cursorPositionToMaskIndex(unsigned); diff --git a/WebCore/wml/WMLMetaElement.cpp b/WebCore/wml/WMLMetaElement.cpp index 71bbf51..81109ae 100644 --- a/WebCore/wml/WMLMetaElement.cpp +++ b/WebCore/wml/WMLMetaElement.cpp @@ -25,6 +25,7 @@ #include "Document.h" #include "HTMLNames.h" +#include "MappedAttribute.h" namespace WebCore { diff --git a/WebCore/wml/WMLNoopElement.cpp b/WebCore/wml/WMLNoopElement.cpp index 0460d9f..1ba1c18 100644 --- a/WebCore/wml/WMLNoopElement.cpp +++ b/WebCore/wml/WMLNoopElement.cpp @@ -53,7 +53,7 @@ void WMLNoopElement::insertedIntoDocument() if (parent->hasTagName(doTag)) { WMLDoElement* doElement = static_cast<WMLDoElement*>(parent); doElement->setNoop(true); - doElement->setChanged(); + doElement->setNeedsStyleRecalc(); } else if (parent->hasTagName(anchorTag)) reportWMLError(document(), WMLErrorForbiddenTaskInAnchorElement); } diff --git a/WebCore/wml/WMLOnEventElement.cpp b/WebCore/wml/WMLOnEventElement.cpp index 2b808c8..a8d35a0 100644 --- a/WebCore/wml/WMLOnEventElement.cpp +++ b/WebCore/wml/WMLOnEventElement.cpp @@ -24,6 +24,7 @@ #include "WMLOnEventElement.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "WMLErrorHandling.h" #include "WMLEventHandlingElement.h" #include "WMLIntrinsicEventHandler.h" diff --git a/WebCore/wml/WMLOptGroupElement.cpp b/WebCore/wml/WMLOptGroupElement.cpp index 3658cf6..d70731c 100644 --- a/WebCore/wml/WMLOptGroupElement.cpp +++ b/WebCore/wml/WMLOptGroupElement.cpp @@ -24,10 +24,12 @@ #include "WMLOptGroupElement.h" #include "Document.h" +#include "MappedAttribute.h" #include "HTMLNames.h" #include "NodeRenderStyle.h" #include "RenderStyle.h" #include "WMLNames.h" +#include "WMLSelectElement.h" namespace WebCore { @@ -42,7 +44,7 @@ WMLOptGroupElement::~WMLOptGroupElement() { } -const AtomicString& WMLOptGroupElement::type() const +const AtomicString& WMLOptGroupElement::formControlType() const { DEFINE_STATIC_LOCAL(const AtomicString, optgroup, ("optgroup")); return optgroup; @@ -50,7 +52,7 @@ const AtomicString& WMLOptGroupElement::type() const bool WMLOptGroupElement::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec, bool shouldLazyAttach) { - bool result = WMLElement::insertBefore(newChild, refChild, ec, shouldLazyAttach); + bool result = WMLFormControlElement::insertBefore(newChild, refChild, ec, shouldLazyAttach); if (result) recalcSelectOptions(); return result; @@ -58,7 +60,7 @@ bool WMLOptGroupElement::insertBefore(PassRefPtr<Node> newChild, Node* refChild, bool WMLOptGroupElement::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec, bool shouldLazyAttach) { - bool result = WMLElement::replaceChild(newChild, oldChild, ec, shouldLazyAttach); + bool result = WMLFormControlElement::replaceChild(newChild, oldChild, ec, shouldLazyAttach); if (result) recalcSelectOptions(); return result; @@ -66,7 +68,7 @@ bool WMLOptGroupElement::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, bool WMLOptGroupElement::removeChild(Node* oldChild, ExceptionCode& ec) { - bool result = WMLElement::removeChild(oldChild, ec); + bool result = WMLFormControlElement::removeChild(oldChild, ec); if (result) recalcSelectOptions(); return result; @@ -74,7 +76,7 @@ bool WMLOptGroupElement::removeChild(Node* oldChild, ExceptionCode& ec) bool WMLOptGroupElement::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, bool shouldLazyAttach) { - bool result = WMLElement::appendChild(newChild, ec, shouldLazyAttach); + bool result = WMLFormControlElement::appendChild(newChild, ec, shouldLazyAttach); if (result) recalcSelectOptions(); return result; @@ -82,17 +84,15 @@ bool WMLOptGroupElement::appendChild(PassRefPtr<Node> newChild, ExceptionCode& e bool WMLOptGroupElement::removeChildren() { - bool result = WMLElement::removeChildren(); + bool result = WMLFormControlElement::removeChildren(); if (result) recalcSelectOptions(); return result; } -// FIXME: Activate once WMLSelectElement is available -#if 0 -static inline WMLElement* ownerSelectElement() +static inline WMLSelectElement* ownerSelectElement(Element* element) { - Node* select = parentNode(); + Node* select = element->parentNode(); while (select && !select->hasTagName(selectTag)) select = select->parentNode(); @@ -101,25 +101,21 @@ static inline WMLElement* ownerSelectElement() return static_cast<WMLSelectElement*>(select); } -#endif void WMLOptGroupElement::accessKeyAction(bool) { - // FIXME: Activate once WMLSelectElement is available -#if 0 - WMLSelectElement* select = ownerSelectElement(); + WMLSelectElement* select = ownerSelectElement(this); if (!select || select->focused()) return; // send to the parent to bring focus to the list box select->accessKeyAction(false); -#endif } void WMLOptGroupElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) { recalcSelectOptions(); - WMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + WMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); } void WMLOptGroupElement::parseMappedAttribute(MappedAttribute* attr) @@ -129,7 +125,7 @@ void WMLOptGroupElement::parseMappedAttribute(MappedAttribute* attr) return; } - WMLElement::parseMappedAttribute(attr); + WMLFormControlElement::parseMappedAttribute(attr); recalcSelectOptions(); } @@ -137,13 +133,13 @@ void WMLOptGroupElement::attach() { if (parentNode()->renderStyle()) setRenderStyle(styleForRenderer()); - WMLElement::attach(); + WMLFormControlElement::attach(); } void WMLOptGroupElement::detach() { m_style.clear(); - WMLElement::detach(); + WMLFormControlElement::detach(); } void WMLOptGroupElement::setRenderStyle(PassRefPtr<RenderStyle> style) @@ -170,11 +166,8 @@ String WMLOptGroupElement::groupLabelText() const void WMLOptGroupElement::recalcSelectOptions() { - // FIXME: Activate once WMLSelectElement is available -#if 0 - if (WMLSelectElement* select = ownerSelectElement()) + if (WMLSelectElement* select = ownerSelectElement(this)) select->setRecalcListItems(); -#endif } } diff --git a/WebCore/wml/WMLOptGroupElement.h b/WebCore/wml/WMLOptGroupElement.h index 45e5412..1ba5ac1 100644 --- a/WebCore/wml/WMLOptGroupElement.h +++ b/WebCore/wml/WMLOptGroupElement.h @@ -34,7 +34,7 @@ public: String title() const { return m_title; } - virtual const AtomicString& type() const; + virtual const AtomicString& formControlType() const; virtual bool rendererIsNeeded(RenderStyle*) { return false; } diff --git a/WebCore/wml/WMLOptionElement.cpp b/WebCore/wml/WMLOptionElement.cpp index dd1466f..1087134 100644 --- a/WebCore/wml/WMLOptionElement.cpp +++ b/WebCore/wml/WMLOptionElement.cpp @@ -24,9 +24,11 @@ #include "WMLOptionElement.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "NodeRenderStyle.h" #include "RenderStyle.h" #include "WMLNames.h" +#include "WMLSelectElement.h" namespace WebCore { @@ -34,7 +36,6 @@ using namespace WMLNames; WMLOptionElement::WMLOptionElement(const QualifiedName& tagName, Document* doc) : WMLFormControlElement(tagName, doc) - , m_data(this) { } @@ -42,17 +43,15 @@ WMLOptionElement::~WMLOptionElement() { } -const AtomicString& WMLOptionElement::type() const +const AtomicString& WMLOptionElement::formControlType() const { DEFINE_STATIC_LOCAL(const AtomicString, option, ("option")); return option; } -// FIXME: Activate once WMLSelectElement is available -#if 0 -static inline WMLElement* ownerSelectElement() +static inline WMLSelectElement* ownerSelectElement(Element* element) { - Node* select = parentNode(); + Node* select = element->parentNode(); while (select && !select->hasTagName(selectTag)) select = select->parentNode(); @@ -61,26 +60,19 @@ static inline WMLElement* ownerSelectElement() return static_cast<WMLSelectElement*>(select); } -#endif void WMLOptionElement::accessKeyAction(bool) { - // FIXME: Activate once WMLSelectElement is available -#if 0 - if (WMLSelectElement* select = ownerSelectElement()) - select->accessKeySetSelectedIndex(index()); -#endif + if (WMLSelectElement* select = ownerSelectElement(this)) + select->accessKeySetSelectedIndex(OptionElement::optionIndex(select, this)); } void WMLOptionElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) { - // FIXME: Activate once WMLSelectElement is available -#if 0 - if (WMLSelectElement* select = ownerSelectElement()) + if (WMLSelectElement* select = ownerSelectElement(this)) select->childrenChanged(changedByParser); -#endif - WMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); + WMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); } void WMLOptionElement::parseMappedAttribute(MappedAttribute* attr) @@ -96,20 +88,20 @@ void WMLOptionElement::parseMappedAttribute(MappedAttribute* attr) createEventHandlerIfNeeded(); eventHandler()->registerIntrinsicEvent(WMLIntrinsicEventOnPick, event); } else - WMLElement::parseMappedAttribute(attr); + WMLFormControlElement::parseMappedAttribute(attr); } void WMLOptionElement::attach() { if (parentNode()->renderStyle()) setRenderStyle(styleForRenderer()); - WMLElement::attach(); + WMLFormControlElement::attach(); } void WMLOptionElement::detach() { m_style.clear(); - WMLElement::detach(); + WMLFormControlElement::detach(); } void WMLOptionElement::setRenderStyle(PassRefPtr<RenderStyle> style) @@ -119,14 +111,11 @@ void WMLOptionElement::setRenderStyle(PassRefPtr<RenderStyle> style) void WMLOptionElement::insertedIntoDocument() { - // FIXME: Activate once WMLSelectElement is available -#if 0 WMLSelectElement* select; - if (selected() && (select = ownerSelectElement())) + if (selected() && (select = ownerSelectElement(this))) select->scrollToSelection(); -#endif - WMLElement::insertedIntoDocument(); + WMLFormControlElement::insertedIntoDocument(); } bool WMLOptionElement::selected() const @@ -136,17 +125,22 @@ bool WMLOptionElement::selected() const void WMLOptionElement::setSelectedState(bool selected) { - OptionElement::setSelectedState(m_data, selected); + OptionElement::setSelectedState(m_data, this, selected); } String WMLOptionElement::value() const { - return OptionElement::collectOptionValue(m_data, document()); + return OptionElement::collectOptionValue(m_data, this); +} + +String WMLOptionElement::text() const +{ + return OptionElement::collectOptionText(m_data, this); } String WMLOptionElement::textIndentedToRespectGroupLabel() const { - return OptionElement::collectOptionTextRespectingGroupLabel(m_data, document()); + return OptionElement::collectOptionTextRespectingGroupLabel(m_data, this); } RenderStyle* WMLOptionElement::nonRendererRenderStyle() const diff --git a/WebCore/wml/WMLOptionElement.h b/WebCore/wml/WMLOptionElement.h index e1d2e80..c34f319 100644 --- a/WebCore/wml/WMLOptionElement.h +++ b/WebCore/wml/WMLOptionElement.h @@ -33,7 +33,7 @@ public: WMLOptionElement(const QualifiedName& tagName, Document*); virtual ~WMLOptionElement(); - virtual const AtomicString& type() const; + virtual const AtomicString& formControlType() const; virtual bool rendererIsNeeded(RenderStyle*) { return false; } @@ -50,6 +50,7 @@ public: virtual bool selected() const; virtual void setSelectedState(bool); + virtual String text() const; virtual String textIndentedToRespectGroupLabel() const; virtual String value() const; diff --git a/WebCore/wml/WMLPElement.cpp b/WebCore/wml/WMLPElement.cpp index 3655b2e..0cec653 100644 --- a/WebCore/wml/WMLPElement.cpp +++ b/WebCore/wml/WMLPElement.cpp @@ -30,6 +30,7 @@ #include "CSSValueKeywords.h" #include "Document.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "NodeList.h" #include "WMLNames.h" diff --git a/WebCore/wml/WMLPostfieldElement.cpp b/WebCore/wml/WMLPostfieldElement.cpp index 0cc7d42..69f61f5 100644 --- a/WebCore/wml/WMLPostfieldElement.cpp +++ b/WebCore/wml/WMLPostfieldElement.cpp @@ -26,6 +26,7 @@ #include "CString.h" #include "TextEncoding.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "WMLDocument.h" #include "WMLGoElement.h" #include "WMLNames.h" diff --git a/WebCore/wml/WMLSelectElement.cpp b/WebCore/wml/WMLSelectElement.cpp new file mode 100644 index 0000000..5b5aed1 --- /dev/null +++ b/WebCore/wml/WMLSelectElement.cpp @@ -0,0 +1,224 @@ +/** + * Copyright (C) 2009 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 "WMLSelectElement.h" + +#include "HTMLNames.h" +#include "MappedAttribute.h" +#include "RenderListBox.h" +#include "RenderMenuList.h" + +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +WMLSelectElement::WMLSelectElement(const QualifiedName& tagName, Document* document) + : WMLFormControlElement(tagName, document) +{ +} + +WMLSelectElement::~WMLSelectElement() +{ +} + +const AtomicString& WMLSelectElement::formControlType() const +{ + DEFINE_STATIC_LOCAL(const AtomicString, selectMultiple, ("select-multiple")); + DEFINE_STATIC_LOCAL(const AtomicString, selectOne, ("select-one")); + return m_data.multiple() ? selectMultiple : selectOne; +} + +bool WMLSelectElement::isKeyboardFocusable(KeyboardEvent* event) const +{ + if (renderer()) + return isFocusable(); + + return WMLFormControlElement::isKeyboardFocusable(event); +} + +bool WMLSelectElement::isMouseFocusable() const +{ + if (renderer()) + return isFocusable(); + + return WMLFormControlElement::isMouseFocusable(); +} + +void WMLSelectElement::selectAll() +{ + SelectElement::selectAll(m_data, this); +} + +void WMLSelectElement::recalcStyle(StyleChange change) +{ + SelectElement::recalcStyle(m_data, this); + WMLFormControlElement::recalcStyle(change); +} + +void WMLSelectElement::dispatchFocusEvent() +{ + SelectElement::dispatchFocusEvent(m_data, this); + WMLFormControlElement::dispatchFocusEvent(); +} + +void WMLSelectElement::dispatchBlurEvent() +{ + SelectElement::dispatchBlurEvent(m_data, this); + WMLFormControlElement::dispatchBlurEvent(); +} + +int WMLSelectElement::selectedIndex() const +{ + return SelectElement::selectedIndex(m_data, this); +} + +void WMLSelectElement::setSelectedIndex(int index, bool deselect, bool fireOnChange) +{ + SelectElement::setSelectedIndex(m_data, this, index, deselect, fireOnChange); +} + +bool WMLSelectElement::saveFormControlState(String& value) const +{ + return SelectElement::saveFormControlState(m_data, this, value); +} + +void WMLSelectElement::restoreFormControlState(const String& state) +{ + SelectElement::restoreFormControlState(m_data, this, state); +} + +void WMLSelectElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) +{ + SelectElement::setRecalcListItems(m_data, this); + WMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); +} + +void WMLSelectElement::parseMappedAttribute(MappedAttribute* attr) +{ + if (attr->name() == HTMLNames::multipleAttr) + SelectElement::parseMultipleAttribute(m_data, this, attr); + else + WMLFormControlElement::parseMappedAttribute(attr); +} + +RenderObject* WMLSelectElement::createRenderer(RenderArena* arena, RenderStyle*) +{ + if (m_data.usesMenuList()) + return new (arena) RenderMenuList(this); + return new (arena) RenderListBox(this); +} + +bool WMLSelectElement::appendFormData(FormDataList& list, bool) +{ + return SelectElement::appendFormData(m_data, this, list); +} + +int WMLSelectElement::optionToListIndex(int optionIndex) const +{ + return SelectElement::optionToListIndex(m_data, this, optionIndex); +} + +int WMLSelectElement::listToOptionIndex(int listIndex) const +{ + return SelectElement::listToOptionIndex(m_data, this, listIndex); +} + +void WMLSelectElement::reset() +{ + SelectElement::reset(m_data, this); +} + +void WMLSelectElement::defaultEventHandler(Event* event) +{ + SelectElement::defaultEventHandler(m_data, this, event); +} + +void WMLSelectElement::accessKeyAction(bool sendToAnyElement) +{ + focus(); + dispatchSimulatedClick(0, sendToAnyElement); +} + +void WMLSelectElement::setActiveSelectionAnchorIndex(int index) +{ + SelectElement::setActiveSelectionAnchorIndex(m_data, this, index); +} + +void WMLSelectElement::setActiveSelectionEndIndex(int index) +{ + SelectElement::setActiveSelectionEndIndex(m_data, index); +} + +void WMLSelectElement::updateListBoxSelection(bool deselectOtherOptions) +{ + SelectElement::updateListBoxSelection(m_data, this, deselectOtherOptions); +} + +void WMLSelectElement::listBoxOnChange() +{ + SelectElement::listBoxOnChange(m_data, this); +} + +void WMLSelectElement::menuListOnChange() +{ + SelectElement::menuListOnChange(m_data, this); +} + +int WMLSelectElement::activeSelectionStartListIndex() const +{ + if (m_data.activeSelectionAnchorIndex() >= 0) + return m_data.activeSelectionAnchorIndex(); + return optionToListIndex(selectedIndex()); +} + +int WMLSelectElement::activeSelectionEndListIndex() const +{ + if (m_data.activeSelectionEndIndex() >= 0) + return m_data.activeSelectionEndIndex(); + return SelectElement::lastSelectedListIndex(m_data, this); +} + +void WMLSelectElement::accessKeySetSelectedIndex(int index) +{ + SelectElement::accessKeySetSelectedIndex(m_data, this, index); +} + +void WMLSelectElement::setRecalcListItems() +{ + SelectElement::setRecalcListItems(m_data, this); +} + +void WMLSelectElement::scrollToSelection() +{ + SelectElement::scrollToSelection(m_data, this); +} + +void WMLSelectElement::insertedIntoTree(bool deep) +{ + SelectElement::insertedIntoTree(m_data, this); + WMLFormControlElement::insertedIntoTree(deep); +} + +} + +#endif diff --git a/WebCore/wml/WMLSelectElement.h b/WebCore/wml/WMLSelectElement.h new file mode 100644 index 0000000..8d3e0f9 --- /dev/null +++ b/WebCore/wml/WMLSelectElement.h @@ -0,0 +1,94 @@ +/** + * Copyright (C) 2009 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 WMLSelectElement_h +#define WMLSelectElement_h + +#if ENABLE(WML) +#include "WMLFormControlElement.h" +#include "SelectElement.h" + +namespace WebCore { + +class WMLSelectElement : public WMLFormControlElement, public SelectElement { +public: + WMLSelectElement(const QualifiedName&, Document*); + virtual ~WMLSelectElement(); + + virtual const AtomicString& formControlType() const; + + virtual bool isKeyboardFocusable(KeyboardEvent*) const; + virtual bool isMouseFocusable() const; + virtual bool canSelectAll() const { return !m_data.usesMenuList(); } + virtual void selectAll(); + + virtual void recalcStyle(StyleChange); + + virtual void dispatchFocusEvent(); + virtual void dispatchBlurEvent(); + + virtual bool canStartSelection() const { return false; } + + virtual int selectedIndex() const; + virtual void setSelectedIndex(int index, bool deselect = true, bool fireOnChange = false); + + virtual int size() const { return m_data.size(); } + virtual bool multiple() const { return m_data.multiple(); } + + virtual bool saveFormControlState(String& value) const; + virtual void restoreFormControlState(const String&); + + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + + virtual void parseMappedAttribute(MappedAttribute*); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool appendFormData(FormDataList&, bool); + virtual int optionToListIndex(int optionIndex) const; + virtual int listToOptionIndex(int listIndex) const; + + virtual const Vector<Element*>& listItems() const { return m_data.listItems(this); } + virtual void reset(); + + virtual void defaultEventHandler(Event*); + virtual void accessKeyAction(bool sendToAnyElement); + virtual void setActiveSelectionAnchorIndex(int index); + virtual void setActiveSelectionEndIndex(int index); + virtual void updateListBoxSelection(bool deselectOtherOptions); + virtual void listBoxOnChange(); + virtual void menuListOnChange(); + + virtual int activeSelectionStartListIndex() const; + virtual int activeSelectionEndListIndex() const; + + void accessKeySetSelectedIndex(int); + void setRecalcListItems(); + void scrollToSelection(); + +private: + virtual void insertedIntoTree(bool); + + SelectElementData m_data; +}; + +} + +#endif +#endif diff --git a/WebCore/wml/WMLSetvarElement.cpp b/WebCore/wml/WMLSetvarElement.cpp index 9bce944..da9a1f4 100644 --- a/WebCore/wml/WMLSetvarElement.cpp +++ b/WebCore/wml/WMLSetvarElement.cpp @@ -24,6 +24,7 @@ #include "WMLSetvarElement.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "WMLErrorHandling.h" #include "WMLTaskElement.h" #include "WMLVariables.h" diff --git a/WebCore/wml/WMLTableElement.cpp b/WebCore/wml/WMLTableElement.cpp index a305f97..92c7580 100644 --- a/WebCore/wml/WMLTableElement.cpp +++ b/WebCore/wml/WMLTableElement.cpp @@ -28,6 +28,7 @@ #include "CSSValueKeywords.h" #include "Document.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "NodeList.h" #include "RenderObject.h" #include "Text.h" diff --git a/WebCore/wml/WMLTagNames.in b/WebCore/wml/WMLTagNames.in index cabb1a5..fd7c762 100644 --- a/WebCore/wml/WMLTagNames.in +++ b/WebCore/wml/WMLTagNames.in @@ -13,7 +13,9 @@ go head interfaceName=WMLElement img interfaceName=WMLImageElement input +#if 0 # Note: 'insertedLegend' is not an official WML element - internal purpose only! +#endif insertedLegend interfaceName=WMLInsertedLegendElement meta noop @@ -24,14 +26,10 @@ p postfield prev refresh +select 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. -# select -#endif diff --git a/WebCore/wml/WMLTemplateElement.cpp b/WebCore/wml/WMLTemplateElement.cpp index 73e9c06..2575c9a 100644 --- a/WebCore/wml/WMLTemplateElement.cpp +++ b/WebCore/wml/WMLTemplateElement.cpp @@ -23,6 +23,7 @@ #if ENABLE(WML) #include "WMLTemplateElement.h" +#include "MappedAttribute.h" #include "NodeList.h" #include "WMLCardElement.h" #include "WMLDocument.h" diff --git a/WebCore/wml/WMLTimerElement.cpp b/WebCore/wml/WMLTimerElement.cpp index 7cd2e50..00c7036 100644 --- a/WebCore/wml/WMLTimerElement.cpp +++ b/WebCore/wml/WMLTimerElement.cpp @@ -24,6 +24,7 @@ #include "WMLTimerElement.h" #include "HTMLNames.h" +#include "MappedAttribute.h" #include "WMLCardElement.h" #include "WMLDocument.h" #include "WMLNames.h" |