- fixed data structure used to save/restore form element state to remove the
O(n^2) algorithm and remove anomalies in how it works
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8683
REGRESSION: imdb search button has "Submit" overload after going back
* manual-tests/form-value-restore.html: Added.
* bridge/mac/WebCoreFrameBridge.mm:
(-[WebCoreFrameBridge saveDocumentState]): Rewrote to call the new formElementsState
function on the document and also to convert null strings to NSNull instead of empty
NSString objects.
(-[WebCoreFrameBridge restoreDocumentState]): Ditto, with the setStateForNewFormElements
function.
* dom/Document.h: Added FormElementKey, FormElementKeyHash, and FormElementKeyHashTraits
for use in the hash map. Made readyState, inputEncoding, defaultCharset, charset,
characterSet, getElementByAccessKey, haveStylesheetsLoaded, usesDescendantRules,
usesSiblingRules, inCompatMode, inAlmostStrictMode, inStrictMode, preferredStylesheetSet,
selectedStylesheetSet, and getCSSTarget all const member functions. Removed the unused
nextState function. Renamed registerMaintainsState and deregisterMaintainsState to
registerFormElementWithState and HTMLGenericFormElement and changed them to use form
elements rather than arbitrary DOM nodes. Replaced docState with formElementsState and
setRestoreState and restoreState with setStateForNewFormElements, hasStateForNewFormElements,
and takeStateForFormElement. Replaced m_maintainsState with m_formElementsWithState,
m_state with m_stateForNewFormElements. Made m_elementsByAccessKey and m_accessKeyMapValid
mutable. Removed unused m_elementNames, m_elementNameAlloc, m_elementNameCount, m_attrNames,
m_attrNameAlloc, m_attrNameCount, m_namespaceURIs, m_namespaceURIAlloc, m_namespaceURICount.
* dom/Document.cpp:
(WebCore::Document::Document): Remove initialization of long-obsolete m_elementNames and
m_attrNames.
(WebCore::Document::~Document): Remove destruction of same.
(WebCore::Document::readyState): Made const.
(WebCore::Document::inputEncoding): Ditto.
(WebCore::Document::defaultCharset): Ditto.
(WebCore::Document::getElementByAccessKey): Ditto.
(WebCore::Document::preferredStylesheetSet): Ditto.
(WebCore::Document::selectedStylesheetSet): Ditto.
(WebCore::Document::getCSSTarget): Ditto.
(WebCore::Document::formElementsState): Added. Replaces the old docState function.
Builds a vector of strings, with 3 strings for each form element containing the
name, type, and state value.
(WebCore::Document::setStateForNewFormElements): Added. Converts the state vector
into a hash map, considering the scheme with 3 strings for form element used above.
(WebCore::Document::hasStateForNewFormElements): Added.
(WebCore::Document::takeStateForFormElement): Added. Given a name and type, looks
up the values in the hash map and "peels off" the last one.
(WebCore::FormElementKey::FormElementKey): Added.
(WebCore::FormElementKey::~FormElementKey): Added.
(WebCore::FormElementKey::operator=): Added.
(WebCore::FormElementKey::ref): Added.
(WebCore::FormElementKey::deref): Added.
(WebCore::FormElementKeyHash::hash): Added.
(WebCore::FormElementKeyHashTraits::deletedValue): Added.
* dom/Element.h: Removed state function.
* dom/Node.h: Removed maintainsState, state, and restoreState functions.
* dom/Node.cpp: Ditto.
* dom/QualifiedName.cpp: Reformatted.
(WebCore::hashComponents): Removed code to handle buffers that are not multiples
of 4 bytes, since a QualifiedName is guaranteed to be; also asserted that fact.
* html/HTMLParser.cpp:
(WebCore::HTMLParser::insertNode): Remove code to restore state; that's now handled
by closeRenderer.
(WebCore::HTMLParser::popOneBlock): Ditto.
* html/HTMLFormElement.cpp: Added include of HTMLInputElement.h.
* html/HTMLGenericFormElement.h: Changed form to be a const member function.
Changed type function to return a const AtomicString& instead of a String.
Added an override of closeRenderer. Removed state and findMatchingState functions.
Added stateValue and restoreState functions. Made m_form, m_disabled, and m_readOnly
be private instead of protected. Removed m_inited. Changed booleans to not use bit
fields since there are only two of them.
* html/HTMLGenericFormElement.cpp: Removed encodedElementName, state, and
findMatchingState functions.
(WebCore::HTMLGenericFormElement::stateValue): Added. No implementation. This will only be
called for subclasses that call registerFormElementWithState, and those will override and
implement it.
(WebCore::HTMLGenericFormElement::restoreState): Ditto.
(WebCore::HTMLGenericFormElement::closeRenderer): Added. Replaces code that was in the
HTML parser. Calls takeStateForFormElement, passing in the name and type, and if a
state is found, calls restoreState.
* html/HTMLButtonElement.h: Changed type to return a const AtomicString& instead
of a String.
* html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::type): Return a const AtomicString& instead of a
String.
(WebCore::HTMLButtonElement::defaultEventHandler): Use form() instead of m_form.
(WebCore::HTMLButtonElement::isSuccessfulSubmitButton): Use disabled() instead of
m_disabled.
* html/HTMLInputElement.h: Changed type to return a const AtomicString& instead
of a String. Removed maintainsState, state, and restoreState functions, and added
new stateValue and restoreState functions. Added m_inited (moved here from the generic
form element base class).
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::init): Call registerFormElementWithState. This was
formerly done by the HTML parser.
(WebCore::HTMLInputElement::~HTMLInputElement): Call deregisterFormElementWithState
by its new name.
(WebCore::HTMLInputElement::isKeyboardFocusable): Use form() instead of m_form.
(WebCore::HTMLInputElement::setType): Ditto.
(WebCore::HTMLInputElement::setInputType): Ditto. Also call inputType() != PASSWORD
instead of maintainsState(), since this is the only function that needs to know
the rule and it's no longer a function in the base class. Also call register and
deregister functions by their new names.
(WebCore::HTMLInputElement::type): Changed to return const AtomicString& instead
of String.
(WebCore::HTMLInputElement::stateValue): Renamed from state and changed to no
longer include the name and type, formerly obtained by calling the base class's
HTMLGenericFormElement::state, and to no longer modify the value() string by
adding a ".", which gets in the way of distinguishing null and empty values
and is slower and unnecessary.
(WebCore::HTMLInputElement::restoreState): Changed because it takes a single
state and doesn't need to call findMatchingState, and also to no longer remove the last
character from the value when restoring state.
(WebCore::HTMLInputElement::parseMappedAttribute): Use form() instead of m_form.
(WebCore::HTMLInputElement::isSuccessfulSubmitButton): Use disabled() instead of
m_disabled.
(WebCore::HTMLInputElement::setChecked): Use form() instead of m_form.
(WebCore::HTMLInputElement::preDispatchEventHandler): Ditto.
(WebCore::HTMLInputElement::defaultEventHandler): Ditto.
* html/HTMLSelectElement.h: Changed type to return a const AtomicString& instead
of a String.
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::HTMLSelectElement): Call registerFormElementWithState.
This was formerly done by the HTML parser.
(WebCore::HTMLSelectElement::~HTMLSelectElement): Call deregisterFormElementWithState
by its new name.
(WebCore::HTMLSelectElement::type): Changed to return const AtomicString& instead
of String.
(WebCore::HTMLSelectElement::stateValue): Renamed from state and changed to no
longer include the name and type, formerly obtained by calling the base class's
HTMLGenericFormElement::state, and to build the string in a Vector<char> instead of
appending characters one at a time to a string.
(WebCore::HTMLSelectElement::restoreState): Changed because it takes a single
state and doesn't need to call findMatchingState.
(WebCore::HTMLSelectElement::defaultEventHandler): Use form() instead of m_form.
* html/HTMLTextAreaElement.h: Changed type to return a const AtomicString& instead
of a String. Removed maintainsState, state, and restoreState functions, and added
new stateValue and restoreState functions.
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::HTMLTextAreaElement): Call registerFormElementWithState.
This was formerly done by the HTML parser. Also use member initialization instead of
assignment.
(WebCore::HTMLTextAreaElement::~HTMLTextAreaElement): Call deregisterFormElementWithState
by its new name.
(WebCore::HTMLTextAreaElement::type): Changed to return const AtomicString& instead
of String.
(WebCore::HTMLTextAreaElement::stateValue): Renamed from state and changed to no
longer include the name and type, formerly obtained by calling the base class's
HTMLGenericFormElement::state, and to no longer modify the value() string by
adding a ".", which is unnecessary.
(WebCore::HTMLTextAreaElement::restoreState): Changed because it takes a single
state and doesn't need to call findMatchingState, and also to no longer remove the last
character from the value when restoring state.
(WebCore::HTMLTextAreaElement::updateValue): Changed to const.
(WebCore::HTMLTextAreaElement::value): Ditto.
(WebCore::HTMLTextAreaElement::defaultValue): Ditto.
* html/HTMLFieldSetElement.h: Changed type to return a const AtomicString& instead
of a String.
* html/HTMLFieldSetElement.cpp: (WebCore::HTMLFieldSetElement::type): Ditto.
* html/HTMLKeygenElement.h: Ditto.
* html/HTMLKeygenElement.cpp: (WebCore::HTMLKeygenElement::type): Ditto.
* html/HTMLLegendElement.h: Ditto.
* html/HTMLLegendElement.cpp: (WebCore::HTMLLegendElement::type):
* html/HTMLOptGroupElement.h: Ditto.
* html/HTMLOptGroupElement.cpp: (WebCore::HTMLOptGroupElement::type): Ditto.
* html/HTMLOptionElement.h: Ditto.
* html/HTMLOptionElement.cpp: (WebCore::HTMLOptionElement::type): Ditto.
* ksvg2/svg/SVGAnimationElement.cpp: (SVGAnimationElement::closeRenderer):
Added missing call to base class.
* rendering/render_form.h: Removed element() functions that cast to the
appropriate derived element class. They do make some bits of code slightly
more readable, but they also require including too many headers. Removed
the includes of HTMLInputElement.h, HTMLSelectElement.h, HTMLTextAreaElement.h,
and KWQLineEdit.h, and added an include of GraphicsTypes.h.
* rendering/render_form.cpp:
(WebCore::RenderFormElement::updateFromElement): Changed use of element()
to instead use node() and cast.
(WebCore::RenderFormElement::clicked): Ditto.
(WebCore::RenderLineEdit::selectionChanged): Ditto.
(WebCore::RenderLineEdit::returnPressed): Ditto.
(WebCore::RenderLineEdit::performSearch): Ditto.
(WebCore::RenderLineEdit::addSearchResult): Ditto.
(WebCore::RenderLineEdit::calcMinMaxWidth): Ditto.
(WebCore::RenderLineEdit::setStyle): Ditto.
(WebCore::RenderLineEdit::updateFromElement): Ditto.
(WebCore::RenderLineEdit::valueChanged): Ditto.
(WebCore::RenderFileButton::calcMinMaxWidth): Ditto.
(WebCore::RenderFileButton::updateFromElement): Ditto.
(WebCore::RenderFileButton::returnPressed): Ditto.
(WebCore::RenderFileButton::valueChanged): Ditto.
(WebCore::RenderSelect::updateFromElement): Ditto.
(WebCore::RenderSelect::layout): Ditto.
(WebCore::RenderSelect::valueChanged): Ditto.
(WebCore::RenderSelect::selectionChanged): Ditto.
(WebCore::RenderSelect::updateSelection): Ditto.
(WebCore::RenderTextArea::destroy): Ditto.
(WebCore::RenderTextArea::calcMinMaxWidth): Ditto.
(WebCore::RenderTextArea::setStyle): Ditto.
(WebCore::RenderTextArea::updateFromElement): Ditto.
(WebCore::RenderTextArea::valueChanged): Ditto.
(WebCore::RenderTextArea::selectionChanged): Ditto.
(WebCore::RenderSlider::updateFromElement): Ditto.
(WebCore::RenderSlider::valueChanged): Ditto.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14207
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-05-05 Darin Adler <darin@apple.com>
+
+ Reviewed by Adele.
+
+ - fixed data structure used to save/restore form element state to remove the
+ O(n^2) algorithm and remove anomalies in how it works
+ - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=8683
+ REGRESSION: imdb search button has "Submit" overload after going back
+
+ * manual-tests/form-value-restore.html: Added.
+
+ * bridge/mac/WebCoreFrameBridge.mm:
+ (-[WebCoreFrameBridge saveDocumentState]): Rewrote to call the new formElementsState
+ function on the document and also to convert null strings to NSNull instead of empty
+ NSString objects.
+ (-[WebCoreFrameBridge restoreDocumentState]): Ditto, with the setStateForNewFormElements
+ function.
+
+ * dom/Document.h: Added FormElementKey, FormElementKeyHash, and FormElementKeyHashTraits
+ for use in the hash map. Made readyState, inputEncoding, defaultCharset, charset,
+ characterSet, getElementByAccessKey, haveStylesheetsLoaded, usesDescendantRules,
+ usesSiblingRules, inCompatMode, inAlmostStrictMode, inStrictMode, preferredStylesheetSet,
+ selectedStylesheetSet, and getCSSTarget all const member functions. Removed the unused
+ nextState function. Renamed registerMaintainsState and deregisterMaintainsState to
+ registerFormElementWithState and HTMLGenericFormElement and changed them to use form
+ elements rather than arbitrary DOM nodes. Replaced docState with formElementsState and
+ setRestoreState and restoreState with setStateForNewFormElements, hasStateForNewFormElements,
+ and takeStateForFormElement. Replaced m_maintainsState with m_formElementsWithState,
+ m_state with m_stateForNewFormElements. Made m_elementsByAccessKey and m_accessKeyMapValid
+ mutable. Removed unused m_elementNames, m_elementNameAlloc, m_elementNameCount, m_attrNames,
+ m_attrNameAlloc, m_attrNameCount, m_namespaceURIs, m_namespaceURIAlloc, m_namespaceURICount.
+
+ * dom/Document.cpp:
+ (WebCore::Document::Document): Remove initialization of long-obsolete m_elementNames and
+ m_attrNames.
+ (WebCore::Document::~Document): Remove destruction of same.
+ (WebCore::Document::readyState): Made const.
+ (WebCore::Document::inputEncoding): Ditto.
+ (WebCore::Document::defaultCharset): Ditto.
+ (WebCore::Document::getElementByAccessKey): Ditto.
+ (WebCore::Document::preferredStylesheetSet): Ditto.
+ (WebCore::Document::selectedStylesheetSet): Ditto.
+ (WebCore::Document::getCSSTarget): Ditto.
+ (WebCore::Document::formElementsState): Added. Replaces the old docState function.
+ Builds a vector of strings, with 3 strings for each form element containing the
+ name, type, and state value.
+ (WebCore::Document::setStateForNewFormElements): Added. Converts the state vector
+ into a hash map, considering the scheme with 3 strings for form element used above.
+ (WebCore::Document::hasStateForNewFormElements): Added.
+ (WebCore::Document::takeStateForFormElement): Added. Given a name and type, looks
+ up the values in the hash map and "peels off" the last one.
+ (WebCore::FormElementKey::FormElementKey): Added.
+ (WebCore::FormElementKey::~FormElementKey): Added.
+ (WebCore::FormElementKey::operator=): Added.
+ (WebCore::FormElementKey::ref): Added.
+ (WebCore::FormElementKey::deref): Added.
+ (WebCore::FormElementKeyHash::hash): Added.
+ (WebCore::FormElementKeyHashTraits::deletedValue): Added.
+
+ * dom/Element.h: Removed state function.
+ * dom/Node.h: Removed maintainsState, state, and restoreState functions.
+ * dom/Node.cpp: Ditto.
+
+ * dom/QualifiedName.cpp: Reformatted.
+ (WebCore::hashComponents): Removed code to handle buffers that are not multiples
+ of 4 bytes, since a QualifiedName is guaranteed to be; also asserted that fact.
+
+ * html/HTMLParser.cpp:
+ (WebCore::HTMLParser::insertNode): Remove code to restore state; that's now handled
+ by closeRenderer.
+ (WebCore::HTMLParser::popOneBlock): Ditto.
+
+ * html/HTMLFormElement.cpp: Added include of HTMLInputElement.h.
+
+ * html/HTMLGenericFormElement.h: Changed form to be a const member function.
+ Changed type function to return a const AtomicString& instead of a String.
+ Added an override of closeRenderer. Removed state and findMatchingState functions.
+ Added stateValue and restoreState functions. Made m_form, m_disabled, and m_readOnly
+ be private instead of protected. Removed m_inited. Changed booleans to not use bit
+ fields since there are only two of them.
+ * html/HTMLGenericFormElement.cpp: Removed encodedElementName, state, and
+ findMatchingState functions.
+ (WebCore::HTMLGenericFormElement::stateValue): Added. No implementation. This will only be
+ called for subclasses that call registerFormElementWithState, and those will override and
+ implement it.
+ (WebCore::HTMLGenericFormElement::restoreState): Ditto.
+ (WebCore::HTMLGenericFormElement::closeRenderer): Added. Replaces code that was in the
+ HTML parser. Calls takeStateForFormElement, passing in the name and type, and if a
+ state is found, calls restoreState.
+
+ * html/HTMLButtonElement.h: Changed type to return a const AtomicString& instead
+ of a String.
+ * html/HTMLButtonElement.cpp:
+ (WebCore::HTMLButtonElement::type): Return a const AtomicString& instead of a
+ String.
+ (WebCore::HTMLButtonElement::defaultEventHandler): Use form() instead of m_form.
+ (WebCore::HTMLButtonElement::isSuccessfulSubmitButton): Use disabled() instead of
+ m_disabled.
+
+ * html/HTMLInputElement.h: Changed type to return a const AtomicString& instead
+ of a String. Removed maintainsState, state, and restoreState functions, and added
+ new stateValue and restoreState functions. Added m_inited (moved here from the generic
+ form element base class).
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::init): Call registerFormElementWithState. This was
+ formerly done by the HTML parser.
+ (WebCore::HTMLInputElement::~HTMLInputElement): Call deregisterFormElementWithState
+ by its new name.
+ (WebCore::HTMLInputElement::isKeyboardFocusable): Use form() instead of m_form.
+ (WebCore::HTMLInputElement::setType): Ditto.
+ (WebCore::HTMLInputElement::setInputType): Ditto. Also call inputType() != PASSWORD
+ instead of maintainsState(), since this is the only function that needs to know
+ the rule and it's no longer a function in the base class. Also call register and
+ deregister functions by their new names.
+ (WebCore::HTMLInputElement::type): Changed to return const AtomicString& instead
+ of String.
+ (WebCore::HTMLInputElement::stateValue): Renamed from state and changed to no
+ longer include the name and type, formerly obtained by calling the base class's
+ HTMLGenericFormElement::state, and to no longer modify the value() string by
+ adding a ".", which gets in the way of distinguishing null and empty values
+ and is slower and unnecessary.
+ (WebCore::HTMLInputElement::restoreState): Changed because it takes a single
+ state and doesn't need to call findMatchingState, and also to no longer remove the last
+ character from the value when restoring state.
+ (WebCore::HTMLInputElement::parseMappedAttribute): Use form() instead of m_form.
+ (WebCore::HTMLInputElement::isSuccessfulSubmitButton): Use disabled() instead of
+ m_disabled.
+ (WebCore::HTMLInputElement::setChecked): Use form() instead of m_form.
+ (WebCore::HTMLInputElement::preDispatchEventHandler): Ditto.
+ (WebCore::HTMLInputElement::defaultEventHandler): Ditto.
+
+ * html/HTMLSelectElement.h: Changed type to return a const AtomicString& instead
+ of a String.
+ * html/HTMLSelectElement.cpp:
+ (WebCore::HTMLSelectElement::HTMLSelectElement): Call registerFormElementWithState.
+ This was formerly done by the HTML parser.
+ (WebCore::HTMLSelectElement::~HTMLSelectElement): Call deregisterFormElementWithState
+ by its new name.
+ (WebCore::HTMLSelectElement::type): Changed to return const AtomicString& instead
+ of String.
+ (WebCore::HTMLSelectElement::stateValue): Renamed from state and changed to no
+ longer include the name and type, formerly obtained by calling the base class's
+ HTMLGenericFormElement::state, and to build the string in a Vector<char> instead of
+ appending characters one at a time to a string.
+ (WebCore::HTMLSelectElement::restoreState): Changed because it takes a single
+ state and doesn't need to call findMatchingState.
+ (WebCore::HTMLSelectElement::defaultEventHandler): Use form() instead of m_form.
+
+ * html/HTMLTextAreaElement.h: Changed type to return a const AtomicString& instead
+ of a String. Removed maintainsState, state, and restoreState functions, and added
+ new stateValue and restoreState functions.
+ * html/HTMLTextAreaElement.cpp:
+ (WebCore::HTMLTextAreaElement::HTMLTextAreaElement): Call registerFormElementWithState.
+ This was formerly done by the HTML parser. Also use member initialization instead of
+ assignment.
+ (WebCore::HTMLTextAreaElement::~HTMLTextAreaElement): Call deregisterFormElementWithState
+ by its new name.
+ (WebCore::HTMLTextAreaElement::type): Changed to return const AtomicString& instead
+ of String.
+ (WebCore::HTMLTextAreaElement::stateValue): Renamed from state and changed to no
+ longer include the name and type, formerly obtained by calling the base class's
+ HTMLGenericFormElement::state, and to no longer modify the value() string by
+ adding a ".", which is unnecessary.
+ (WebCore::HTMLTextAreaElement::restoreState): Changed because it takes a single
+ state and doesn't need to call findMatchingState, and also to no longer remove the last
+ character from the value when restoring state.
+ (WebCore::HTMLTextAreaElement::updateValue): Changed to const.
+ (WebCore::HTMLTextAreaElement::value): Ditto.
+ (WebCore::HTMLTextAreaElement::defaultValue): Ditto.
+
+ * html/HTMLFieldSetElement.h: Changed type to return a const AtomicString& instead
+ of a String.
+ * html/HTMLFieldSetElement.cpp: (WebCore::HTMLFieldSetElement::type): Ditto.
+ * html/HTMLKeygenElement.h: Ditto.
+ * html/HTMLKeygenElement.cpp: (WebCore::HTMLKeygenElement::type): Ditto.
+ * html/HTMLLegendElement.h: Ditto.
+ * html/HTMLLegendElement.cpp: (WebCore::HTMLLegendElement::type):
+ * html/HTMLOptGroupElement.h: Ditto.
+ * html/HTMLOptGroupElement.cpp: (WebCore::HTMLOptGroupElement::type): Ditto.
+ * html/HTMLOptionElement.h: Ditto.
+ * html/HTMLOptionElement.cpp: (WebCore::HTMLOptionElement::type): Ditto.
+
+ * ksvg2/svg/SVGAnimationElement.cpp: (SVGAnimationElement::closeRenderer):
+ Added missing call to base class.
+
+ * rendering/render_form.h: Removed element() functions that cast to the
+ appropriate derived element class. They do make some bits of code slightly
+ more readable, but they also require including too many headers. Removed
+ the includes of HTMLInputElement.h, HTMLSelectElement.h, HTMLTextAreaElement.h,
+ and KWQLineEdit.h, and added an include of GraphicsTypes.h.
+ * rendering/render_form.cpp:
+ (WebCore::RenderFormElement::updateFromElement): Changed use of element()
+ to instead use node() and cast.
+ (WebCore::RenderFormElement::clicked): Ditto.
+ (WebCore::RenderLineEdit::selectionChanged): Ditto.
+ (WebCore::RenderLineEdit::returnPressed): Ditto.
+ (WebCore::RenderLineEdit::performSearch): Ditto.
+ (WebCore::RenderLineEdit::addSearchResult): Ditto.
+ (WebCore::RenderLineEdit::calcMinMaxWidth): Ditto.
+ (WebCore::RenderLineEdit::setStyle): Ditto.
+ (WebCore::RenderLineEdit::updateFromElement): Ditto.
+ (WebCore::RenderLineEdit::valueChanged): Ditto.
+ (WebCore::RenderFileButton::calcMinMaxWidth): Ditto.
+ (WebCore::RenderFileButton::updateFromElement): Ditto.
+ (WebCore::RenderFileButton::returnPressed): Ditto.
+ (WebCore::RenderFileButton::valueChanged): Ditto.
+ (WebCore::RenderSelect::updateFromElement): Ditto.
+ (WebCore::RenderSelect::layout): Ditto.
+ (WebCore::RenderSelect::valueChanged): Ditto.
+ (WebCore::RenderSelect::selectionChanged): Ditto.
+ (WebCore::RenderSelect::updateSelection): Ditto.
+ (WebCore::RenderTextArea::destroy): Ditto.
+ (WebCore::RenderTextArea::calcMinMaxWidth): Ditto.
+ (WebCore::RenderTextArea::setStyle): Ditto.
+ (WebCore::RenderTextArea::updateFromElement): Ditto.
+ (WebCore::RenderTextArea::valueChanged): Ditto.
+ (WebCore::RenderTextArea::selectionChanged): Ditto.
+ (WebCore::RenderSlider::updateFromElement): Ditto.
+ (WebCore::RenderSlider::valueChanged): Ditto.
+
2006-05-05 Matt Gough <matt@softchaos.com>
Reviewed by Darin.
* ksvg2/css/KSVGCSSParser.cpp: Changed to compile as separate
file instead of being included in cssparser.cpp.
- (WebCore::CSSParser::parseSVGPaint): Take out unnnecessary check
+ (WebCore::CSSParser::parseSVGPaint): Take out unnecessary check
of number of args. Everything works fine without that check, and
otherwise I'd have to change it for the change in data structure.
(WebCore::CSSParser::parseSVGColor): Ditto.
- (void)saveDocumentState
{
- Document* doc = m_frame->document();
- if (doc) {
- DeprecatedStringList list = doc->docState();
- NSMutableArray* documentState = [[NSMutableArray alloc] init];
- DeprecatedStringList::const_iterator end = list.constEnd();
- for (DeprecatedStringList::const_iterator i = list.constBegin(); i != end; ++i) {
- const DeprecatedString& s = *i;
- [documentState addObject:[NSString stringWithCharacters:(const unichar *)s.unicode() length:s.length()]];
- }
- [self saveDocumentState:documentState];
- [documentState release];
+ Vector<String> stateVector;
+ if (Document* doc = m_frame->document())
+ stateVector = doc->formElementsState();
+ size_t size = stateVector.size();
+ NSMutableArray* stateArray = [[NSMutableArray alloc] initWithCapacity:size];
+ for (size_t i = 0; i < size; ++i) {
+ NSString* s = stateVector[i];
+ id o = s ? (id)s : (id)[NSNull null];
+ [stateArray addObject:o];
}
+ [self saveDocumentState:stateArray];
+ [stateArray release];
}
- (void)restoreDocumentState
{
- Document *doc = m_frame->document();
- if (doc) {
- NSArray *documentState = [self documentState];
-
- DeprecatedStringList s;
- for (unsigned i = 0; i < [documentState count]; i++) {
- NSString *string = [documentState objectAtIndex: i];
- s.append(DeprecatedString::fromNSString(string));
- }
-
- doc->setRestoreState(s);
+ Document* doc = m_frame->document();
+ if (!doc)
+ return;
+ NSArray* stateArray = [self documentState];
+ size_t size = [stateArray count];
+ Vector<String> stateVector;
+ stateVector.reserveCapacity(size);
+ for (size_t i = 0; i < size; ++i) {
+ id o = [stateArray objectAtIndex:i];
+ NSString* s = [o isKindOfClass:[NSString class]] ? o : 0;
+ stateVector.append(s);
}
+ doc->setStateForNewFormElements(stateVector);
}
- (void)scrollToAnchorWithURL:(NSURL *)URL
#include "MouseEventWithHitTestResults.h"
#include "NameNodeList.h"
#include "PlatformKeyboardEvent.h"
+#include "RegularExpression.h"
#include "RenderArena.h"
#include "RenderCanvas.h"
#include "SegmentedString.h"
#include "SelectionController.h"
+#include "StringHash.h"
#include "SystemTime.h"
#include "TextIterator.h"
#include "css_valueimpl.h"
#include "render_frames.h"
#include "xml_tokenizer.h"
#include "xmlhttprequest.h"
-#include "RegularExpression.h"
#ifdef KHTML_XSLT
#include "XSLTProcessor.h"
// Use 1 to represent the document's default form.
HTMLFormElement* const defaultForm = (HTMLFormElement*) 1;
+// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
+static const unsigned PHI = 0x9e3779b9U;
+
// DOM Level 2 says (letters added):
//
// a) Name start characters must have one of the categories Ll, Lu, Lo, Lt, Nl.
pMode = Strict;
hMode = XHtml;
m_textColor = Color::black;
- m_elementNames = 0;
- m_elementNameAlloc = 0;
- m_elementNameCount = 0;
- m_attrNames = 0;
- m_attrNameAlloc = 0;
- m_attrNameCount = 0;
m_listenerTypes = 0;
m_inDocument = true;
m_styleSelectorDirty = false;
delete m_styleSelector;
delete m_docLoader;
- if (m_elementNames) {
- for (unsigned short id = 0; id < m_elementNameCount; id++)
- m_elementNames[id]->deref();
- delete [] m_elementNames;
- }
- if (m_attrNames) {
- for (unsigned short id = 0; id < m_attrNameCount; id++)
- m_attrNames[id]->deref();
- delete [] m_attrNames;
- }
-
if (m_renderArena) {
delete m_renderArena;
m_renderArena = 0;
return 0;
}
-String Document::readyState()
+String Document::readyState() const
{
- if (Frame *f = frame()) {
+ if (Frame* f = frame()) {
if (f->isComplete())
return "complete";
if (parsing())
return "loading";
return "loaded";
- // FIXME: What does the interactive value mean ?
- // FIXME: Missing support for "uninitialized"
+ // FIXME: What does "interactive" mean?
+ // FIXME: Missing support for "uninitialized".
}
return String();
}
-String Document::inputEncoding()
+String Document::inputEncoding() const
{
if (Decoder* d = decoder())
return d->encodingName();
return String();
}
-String Document::defaultCharset()
+String Document::defaultCharset() const
{
- if (Frame *f = frame())
+ if (Frame* f = frame())
return f->settings()->encoding();
return String();
}
m_duplicateIds.remove(elementId.impl());
}
-Element* Document::getElementByAccessKey(const String& key)
+Element* Document::getElementByAccessKey(const String& key) const
{
- if (!key.length())
+ if (key.isEmpty())
return 0;
if (!m_accessKeyMapValid) {
- for (Node* n = this; n; n = n->traverseNextNode()) {
+ for (Node* n = firstChild(); n; n = n->traverseNextNode()) {
if (!n->isElementNode())
continue;
- Element* element = static_cast<Element *>(n);
+ Element* element = static_cast<Element*>(n);
const AtomicString& accessKey = element->getAttribute(accesskeyAttr);
if (!accessKey.isEmpty())
m_elementsByAccessKey.set(accessKey.impl(), element);
void Document::updateTitle()
{
- Frame *p = frame();
- if (!p)
- return;
-
- p->setTitle(m_title);
+ if (Frame* f = frame())
+ f->setTitle(m_title);
}
void Document::setTitle(const String& title, Node* titleElement)
updateTitle();
}
-void Document::removeTitle(Node *titleElement)
+void Document::removeTitle(Node* titleElement)
{
if (m_titleElement != titleElement)
return;
return DOCUMENT_NODE;
}
-DeprecatedString Document::nextState()
-{
- DeprecatedString state;
- if (!m_state.isEmpty()) {
- state = m_state.first();
- m_state.remove(m_state.begin());
- }
- return state;
-}
-
-DeprecatedStringList Document::docState()
-{
- DeprecatedStringList s;
- for (DeprecatedPtrListIterator<Node> it(m_maintainsState); it.current(); ++it)
- s.append(it.current()->state());
-
- return s;
-}
-
-Frame *Document::frame() const
+Frame* Document::frame() const
{
return m_view ? m_view->frame() : 0;
}
void Document::removeAllDisconnectedNodeEventListeners()
{
- NodeSet::iterator end = m_disconnectedNodesWithEventListeners.end();
- for (NodeSet::iterator i = m_disconnectedNodesWithEventListeners.begin(); i != end; ++i)
- EventTargetNodeCast((*i))->removeAllEventListeners();
+ HashSet<Node*>::iterator end = m_disconnectedNodesWithEventListeners.end();
+ for (HashSet<Node*>::iterator i = m_disconnectedNodesWithEventListeners.begin(); i != end; ++i)
+ EventTargetNodeCast(*i)->removeAllEventListeners();
m_disconnectedNodesWithEventListeners.clear();
}
return m_styleSheets.get();
}
-String Document::preferredStylesheetSet()
+String Document::preferredStylesheetSet() const
{
return m_preferredStylesheetSet;
}
-String Document::selectedStylesheetSet()
+String Document::selectedStylesheetSet() const
{
return m_selectedStylesheetSet;
}
n->setChanged();
}
-Node* Document::getCSSTarget()
+Node* Document::getCSSTarget() const
{
return m_cssTarget;
}
f->finishedParsing();
}
+Vector<String> Document::formElementsState() const
+{
+ Vector<String> stateVector(m_formElementsWithState.size() * 3);
+ typedef HashSet<HTMLGenericFormElement*>::const_iterator Iterator;
+ Iterator end = m_formElementsWithState.end();
+ for (Iterator it = m_formElementsWithState.begin(); it != end; ++it) {
+ HTMLGenericFormElement* e = *it;
+ stateVector.append(e->name().domString());
+ stateVector.append(e->type().domString());
+ stateVector.append(e->stateValue());
+ }
+ return stateVector;
+}
+
+void Document::setStateForNewFormElements(const Vector<String>& stateVector)
+{
+ // Walk the state vector backwards so that the value to use for each
+ // name/type pair first is the one at the end of each individual vector
+ // in the FormElementStateMap. We're using them like stacks.
+ typedef FormElementStateMap::iterator Iterator;
+ m_formElementsWithState.clear();
+ for (size_t i = stateVector.size() / 3 * 3; i; i -= 3) {
+ AtomicString a = stateVector[i - 3];
+ AtomicString b = stateVector[i - 2];
+ const String& c = stateVector[i - 1];
+ FormElementKey key(a.impl(), b.impl());
+ Iterator it = m_stateForNewFormElements.find(key);
+ if (it != m_stateForNewFormElements.end())
+ it->second.append(c);
+ else {
+ Vector<String> v(1);
+ v[0] = c;
+ m_stateForNewFormElements.set(key, v);
+ }
+ }
+}
+
+bool Document::hasStateForNewFormElements() const
+{
+ return !m_stateForNewFormElements.isEmpty();
+}
+
+bool Document::takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state)
+{
+ typedef FormElementStateMap::iterator Iterator;
+ Iterator it = m_stateForNewFormElements.find(FormElementKey(name, type));
+ if (it == m_stateForNewFormElements.end())
+ return false;
+ ASSERT(it->second.size());
+ state = it->second.last();
+ if (it->second.size() > 1)
+ it->second.removeLast();
+ else
+ m_stateForNewFormElements.remove(it);
+ return true;
+}
+
+FormElementKey::FormElementKey(AtomicStringImpl* name, AtomicStringImpl* type)
+ : m_name(name), m_type(type)
+{
+ ref();
+}
+
+FormElementKey::~FormElementKey()
+{
+ deref();
+}
+
+FormElementKey::FormElementKey(const FormElementKey& other)
+ : m_name(other.name()), m_type(other.type())
+{
+ ref();
+}
+
+FormElementKey& FormElementKey::operator=(const FormElementKey& other)
+{
+ other.ref();
+ deref();
+ m_name = other.name();
+ m_type = other.type();
+ return *this;
+}
+
+void FormElementKey::ref() const
+{
+ if (name() && name() != HashTraits<AtomicStringImpl*>::deletedValue())
+ name()->ref();
+ if (type())
+ type()->ref();
+}
+
+void FormElementKey::deref() const
+{
+ if (name() && name() != HashTraits<AtomicStringImpl*>::deletedValue())
+ name()->deref();
+ if (type())
+ type()->deref();
+}
+
+unsigned FormElementKeyHash::hash(const FormElementKey& k)
+{
+ ASSERT(sizeof(k) % (sizeof(uint16_t) * 2) == 0);
+
+ unsigned l = sizeof(k) / (sizeof(uint16_t) * 2);
+ const uint16_t* s = reinterpret_cast<const uint16_t*>(&k);
+ uint32_t hash = PHI;
+
+ // Main loop
+ for (; l > 0; l--) {
+ hash += s[0];
+ uint32_t tmp = (s[1] << 11) ^ hash;
+ hash = (hash << 16) ^ tmp;
+ s += 2;
+ hash += hash >> 11;
+ }
+
+ // Force "avalanching" of final 127 bits
+ hash ^= hash << 3;
+ hash += hash >> 5;
+ hash ^= hash << 2;
+ hash += hash >> 15;
+ hash ^= hash << 10;
+
+ // this avoids ever returning a hash code of 0, since that is used to
+ // signal "hash not computed yet", using a value that is likely to be
+ // effectively the same as 0 when the low bits are masked
+ if (hash == 0)
+ hash = 0x80000000;
+
+ return hash;
+}
+
+FormElementKey FormElementKeyHashTraits::deletedValue()
+{
+ return HashTraits<AtomicStringImpl*>::deletedValue();
+}
+
}
class HTMLDocument;
class HTMLElement;
class HTMLFormElement;
+ class HTMLGenericFormElement;
class HTMLImageLoader;
class HTMLInputElement;
class HTMLMapElement;
class SVGDocumentExtensions;
#endif
-class Document : public ContainerNode
-{
+class FormElementKey {
+public:
+ FormElementKey(AtomicStringImpl* = 0, AtomicStringImpl* = 0);
+ ~FormElementKey();
+ FormElementKey(const FormElementKey&);
+ FormElementKey& operator=(const FormElementKey&);
+ AtomicStringImpl* name() const { return m_name; }
+ AtomicStringImpl* type() const { return m_type; }
+private:
+ void ref() const;
+ void deref() const;
+ AtomicStringImpl* m_name;
+ AtomicStringImpl* m_type;
+};
+
+inline bool operator==(const FormElementKey& a, const FormElementKey& b)
+ { return a.name() == b.name() && a.type() == b.type(); }
+
+struct FormElementKeyHash {
+ static unsigned hash(const FormElementKey&);
+ static bool equal(const FormElementKey& a, const FormElementKey& b) { return a == b; }
+};
+
+struct FormElementKeyHashTraits : KXMLCore::GenericHashTraits<FormElementKey> {
+ static FormElementKey deletedValue();
+};
+
+class Document : public ContainerNode {
public:
Document(DOMImplementation*, FrameView*);
~Document();
Element* getElementById(const AtomicString&) const;
Element* elementFromPoint(int x, int y) const;
- String readyState();
- String inputEncoding();
- String defaultCharset();
+ String readyState() const;
+ String inputEncoding() const;
+ String defaultCharset() const;
- String charset() { return inputEncoding(); }
- String characterSet() { return inputEncoding(); }
+ String charset() const { return inputEncoding(); }
+ String characterSet() const { return inputEncoding(); }
void setCharset(const String&);
// Actually part of JSHTMLDocument, but used for giving XML documents a window title as well
String title() const { return m_title; }
- void setTitle(const String&, Node *titleElement = 0);
- void removeTitle(Node *titleElement);
+ void setTitle(const String&, Node* titleElement = 0);
+ void removeTitle(Node* titleElement);
PassRefPtr<HTMLCollection> images();
PassRefPtr<HTMLCollection> embeds();
CSSStyleSelector* styleSelector() const { return m_styleSelector; }
- Element* getElementByAccessKey(const String& key);
+ Element* getElementByAccessKey(const String& key) const;
/**
* Updates the pending sheet count and then calls updateStyleSelector.
* This method returns true if all top-level stylesheets have loaded (including
* any @imports that they may be loading).
*/
- bool haveStylesheetsLoaded() { return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets; }
+ bool haveStylesheetsLoaded() const { return m_pendingStylesheets <= 0 || m_ignorePendingStylesheets; }
/**
* Increments the number of pending sheets. The <link> elements
void recalcStyleSelector();
- bool usesDescendantRules() { return m_usesDescendantRules; }
+ bool usesDescendantRules() const { return m_usesDescendantRules; }
void setUsesDescendantRules(bool b) { m_usesDescendantRules = b; }
- bool usesSiblingRules() { return m_usesSiblingRules; }
- void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; }\
-
- DeprecatedString nextState();
+ bool usesSiblingRules() const { return m_usesSiblingRules; }
+ void setUsesSiblingRules(bool b) { m_usesSiblingRules = b; }
- // Query all registered elements for their state
- DeprecatedStringList docState();
- void registerMaintainsState(Node* e) { m_maintainsState.append(e); }
- void deregisterMaintainsState(Node* e) { m_maintainsState.removeRef(e); }
-
- // Set the state the document should restore to
- void setRestoreState(const DeprecatedStringList& s) { m_state = s; }
- DeprecatedStringList& restoreState( ) { return m_state; }
+ // Machinery for saving and restoring state when you leave and then go back to a page.
+ void registerFormElementWithState(HTMLGenericFormElement* e) { m_formElementsWithState.add(e); }
+ void deregisterFormElementWithState(HTMLGenericFormElement* e) { m_formElementsWithState.remove(e); }
+ Vector<String> formElementsState() const;
+ void setStateForNewFormElements(const Vector<String>&);
+ bool hasStateForNewFormElements() const;
+ bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
FrameView* view() const { return m_view; }
Frame* frame() const;
bool printing() const { return m_printing; }
void setPrinting(bool p) { m_printing = p; }
- enum HTMLMode {
- Html3,
- Html4,
- XHtml
- };
-
- enum ParseMode {
- Compat,
- AlmostStrict,
- Strict
- };
+ enum ParseMode { Compat, AlmostStrict, Strict };
virtual void determineParseMode( const DeprecatedString &str );
- void setParseMode( ParseMode m ) { pMode = m; }
+ void setParseMode(ParseMode m) { pMode = m; }
ParseMode parseMode() const { return pMode; }
- bool inCompatMode() { return pMode == Compat; }
- bool inAlmostStrictMode() { return pMode == AlmostStrict; }
- bool inStrictMode() { return pMode == Strict; }
+ bool inCompatMode() const { return pMode == Compat; }
+ bool inAlmostStrictMode() const { return pMode == AlmostStrict; }
+ bool inStrictMode() const { return pMode == Strict; }
- void setHTMLMode( HTMLMode m ) { hMode = m; }
+ enum HTMLMode { Html3, Html4, XHtml };
+
+ void setHTMLMode(HTMLMode m) { hMode = m; }
HTMLMode htmlMode() const { return hMode; }
- void setParsing(bool b);
+ void setParsing(bool);
bool parsing() const { return m_bParsing; }
int minimumLayoutDelay();
bool shouldScheduleLayout();
stylesheets using the DOM. May be subject to change as
spec matures. - dwh
*/
- String preferredStylesheetSet();
- String selectedStylesheetSet();
+ String preferredStylesheetSet() const;
+ String selectedStylesheetSet() const;
void setSelectedStylesheetSet(const String&);
DeprecatedStringList availableStyleSheets() const;
// Updates for :target (CSS3 selector).
void setCSSTarget(Node*);
- Node* getCSSTarget();
+ Node* getCSSTarget() const;
void setDocumentChanged(bool);
void finishedParsing();
protected:
- CSSStyleSelector *m_styleSelector;
- FrameView *m_view;
- DeprecatedStringList m_state;
+ CSSStyleSelector* m_styleSelector;
+ FrameView* m_view;
- DocLoader *m_docLoader;
- Tokenizer *m_tokenizer;
+ DocLoader* m_docLoader;
+ Tokenizer* m_tokenizer;
DeprecatedString m_url;
DeprecatedString m_baseURL;
String m_baseTarget;
unsigned m_domtree_version;
- // ### replace with something more efficient in lookup and insertion
- StringImpl** m_elementNames;
- unsigned short m_elementNameAlloc;
- unsigned short m_elementNameCount;
-
- StringImpl** m_attrNames;
- unsigned short m_attrNameAlloc;
- unsigned short m_attrNameCount;
-
- StringImpl** m_namespaceURIs;
- unsigned short m_namespaceURIAlloc;
- unsigned short m_namespaceURICount;
-
DeprecatedPtrList<NodeIterator> m_nodeIterators;
unsigned short m_listenerTypes;
RefPtr<StyleSheetList> m_styleSheets;
DeprecatedPtrList<RegisteredEventListener> m_windowEventListeners;
- DeprecatedPtrList<Node> m_maintainsState;
+
+ typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
+ HashSet<HTMLGenericFormElement*> m_formElementsWithState;
+ FormElementStateMap m_stateForNewFormElements;
Color m_linkColor;
Color m_visitedLinkColor;
String m_policyBaseURL;
- typedef HashSet<Node*> NodeSet;
- NodeSet m_disconnectedNodesWithEventListeners;
+ HashSet<Node*> m_disconnectedNodesWithEventListeners;
int m_docID; // A unique document identifier used for things like document-specific mapped attributes.
void removeAllDisconnectedNodeEventListeners();
void imageLoadEventTimerFired(Timer<Document>*);
- JSEditor *jsEditor();
+ JSEditor* jsEditor();
- JSEditor *m_jsEditor;
+ JSEditor* m_jsEditor;
bool relinquishesEditingFocus(Node*);
bool acceptsEditingFocus(Node*);
void didBeginEditing();
void didEndEditing();
mutable String m_domain;
- RenderObject *m_savedRenderer;
+ RenderObject* m_savedRenderer;
int m_passwordFields;
int m_secureForms;
mutable HashMap<AtomicStringImpl*, Element*> m_elementsById;
mutable HashCountedSet<AtomicStringImpl*> m_duplicateIds;
- HashMap<StringImpl*, Element*, CaseInsensitiveHash> m_elementsByAccessKey;
+ mutable HashMap<StringImpl*, Element*, CaseInsensitiveHash> m_elementsByAccessKey;
InheritedBool m_designMode;
bool m_dashboardRegionsDirty;
#endif
- bool m_accessKeyMapValid;
+ mutable bool m_accessKeyMapValid;
bool m_createRenderers;
bool m_inPageCache;
};
void setAttributeMap(NamedAttrMap*);
virtual void copyNonAttributeProperties(const Element *source) {}
-
- // State of the element.
- virtual DeprecatedString state() { return DeprecatedString::null; }
virtual void attach();
virtual RenderStyle *createStyleForRenderer(RenderObject *parent);
m_inDetach = false;
}
-bool Node::maintainsState()
-{
- return false;
-}
-
-DeprecatedString Node::state()
-{
- return DeprecatedString::null;
-}
-
-void Node::restoreState(DeprecatedStringList &/*states*/)
-{
-}
-
void Node::insertedIntoDocument()
{
setInDocument(true);
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
// -----------------------------------------------------------------------------
- // Methods for maintaining the state of the element between history navigation
-
- /**
- * Indicates whether or not this type of node maintains it's state. If so, the state of the node will be stored when
- * the user goes to a different page using the state() method, and restored using the restoreState() method if the
- * user returns (e.g. using the back button). This is used to ensure that user-changeable elements such as form
- * controls maintain their contents when the user returns to a previous page in the history.
- */
- virtual bool maintainsState();
-
- /**
- * Returns the state of this node represented as a string. This string will be passed to restoreState() if the user
- * returns to the page.
- *
- * @return State information about the node represented as a string
- */
- virtual DeprecatedString state();
-
- /**
- * Sets the state of the element based on strings previously returned by state(). This is used to initialize form
- * controls with their old values when the user returns to the page in their history. The receiver
- * should remove the string from the list that it uses for its restore.
- *
- * @param states The strings previously returned by nodes' state methods.
- */
- virtual void restoreState(DeprecatedStringList& stateList);
-
- // -----------------------------------------------------------------------------
- // Notification of document stucture changes
+ // Notification of document structure changes
/**
* Notifies the node that it has been inserted into the document. This is called during document parsing, and also
/**
* This file is part of the DOM implementation for KDE.
*
- * Copyright (C) 2005 Apple Computer, Inc.
+ * Copyright (C) 2005, 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
#include "QualifiedName.h"
#include "StaticConstructors.h"
+#include <kxmlcore/Assertions.h>
#include <kxmlcore/HashSet.h>
namespace WebCore {
struct QualifiedNameComponents {
- StringImpl *m_prefix;
- StringImpl *m_localName;
- StringImpl *m_namespace;
+ StringImpl* m_prefix;
+ StringImpl* m_localName;
+ StringImpl* m_namespace;
};
// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
inline unsigned hashComponents(const QualifiedNameComponents& buf)
{
- unsigned l = sizeof(QualifiedNameComponents) / sizeof(uint16_t);
- const uint16_t *s = reinterpret_cast<const uint16_t*>(&buf);
+ ASSERT(sizeof(QualifiedNameComponents) % (sizeof(uint16_t) * 2) == 0);
+
+ unsigned l = sizeof(QualifiedNameComponents) / (sizeof(uint16_t) * 2);
+ const uint16_t* s = reinterpret_cast<const uint16_t*>(&buf);
uint32_t hash = PHI;
- uint32_t tmp;
-
- int rem = l & 1;
- l >>= 1;
-
+
// Main loop
for (; l > 0; l--) {
hash += s[0];
- tmp = (s[1] << 11) ^ hash;
+ uint32_t tmp = (s[1] << 11) ^ hash;
hash = (hash << 16) ^ tmp;
s += 2;
hash += hash >> 11;
}
-
- // Handle end case
- if (rem) {
- hash += s[0];
- hash ^= hash << 11;
- hash += hash >> 17;
- }
// Force "avalanching" of final 127 bits
hash ^= hash << 3;
hash ^= hash << 2;
hash += hash >> 15;
hash ^= hash << 10;
-
+
// this avoids ever returning a hash code of 0, since that is used to
// signal "hash not computed yet", using a value that is likely to be
// effectively the same as 0 when the low bits are masked
if (hash == 0)
hash = 0x80000000;
-
+
return hash;
}
struct QNameHash {
- static unsigned hash(const QualifiedName::QualifiedNameImpl *name) {
- QualifiedNameComponents components = { name->m_prefix.impl(),
- name->m_localName.impl(),
- name->m_namespace.impl() };
- return hashComponents(components);
+ static unsigned hash(const QualifiedName::QualifiedNameImpl* name) {
+ QualifiedNameComponents c = { name->m_prefix.impl(), name->m_localName.impl(), name->m_namespace.impl() };
+ return hashComponents(c);
}
- static bool equal(const QualifiedName::QualifiedNameImpl *a, const QualifiedName::QualifiedNameImpl *b) { return a == b; }
+ static bool equal(const QualifiedName::QualifiedNameImpl* a, const QualifiedName::QualifiedNameImpl* b) { return a == b; }
};
typedef HashSet<QualifiedName::QualifiedNameImpl*, QNameHash> QNameSet;
-static QNameSet *gNameCache;
-
struct QNameComponentsTranslator {
- static unsigned hash(const QualifiedNameComponents& components)
- {
+ static unsigned hash(const QualifiedNameComponents& components) {
return hashComponents(components);
}
-
- static bool equal(QualifiedName::QualifiedNameImpl *name, const QualifiedNameComponents& components)
- {
- return components.m_localName == name->m_localName.impl() &&
- components.m_namespace == name->m_namespace.impl() &&
- components.m_prefix == name->m_prefix.impl();
+ static bool equal(QualifiedName::QualifiedNameImpl* name, const QualifiedNameComponents& c) {
+ return c.m_prefix == name->m_prefix.impl() && c.m_localName == name->m_localName.impl() && c.m_namespace == name->m_namespace.impl();
}
-
- static void translate(QualifiedName::QualifiedNameImpl*& location, const QualifiedNameComponents& components, unsigned hash)
- {
+ static void translate(QualifiedName::QualifiedNameImpl*& location, const QualifiedNameComponents& components, unsigned hash) {
location = new QualifiedName::QualifiedNameImpl(components.m_prefix, components.m_localName, components.m_namespace);
}
};
+static QNameSet* gNameCache;
+
QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const AtomicString& n)
: m_impl(0)
{
{
if (m_impl->hasOneRef())
gNameCache->remove(m_impl);
-
m_impl->deref();
}
return new (arena) RenderButton(this);
}
-String HTMLButtonElement::type() const
+const AtomicString& HTMLButtonElement::type() const
{
return getAttribute(typeAttr);
}
void HTMLButtonElement::defaultEventHandler(Event *evt)
{
if (m_type != BUTTON && (evt->type() == DOMActivateEvent)) {
-
- if(m_form && m_type == SUBMIT) {
+ if (form() && m_type == SUBMIT) {
m_activeSubmit = true;
- m_form->prepareSubmit();
+ form()->prepareSubmit();
m_activeSubmit = false; // in case we were canceled
}
- if(m_form && m_type == RESET) m_form->reset();
+ if (form() && m_type == RESET)
+ form()->reset();
}
HTMLGenericFormElement::defaultEventHandler(evt);
}
// differently and can use different buttons than the
// author intended.
// Remove the name constraint for now.
- // Was: m_type == SUBMIT && !m_disabled && !name().isEmpty()
- return m_type == SUBMIT && !m_disabled;
+ // Was: m_type == SUBMIT && !disabled() && !name().isEmpty()
+ return m_type == SUBMIT && !disabled();
}
bool HTMLButtonElement::isActivatedSubmit() const
HTMLButtonElement(Document *doc, HTMLFormElement *f = 0);
virtual ~HTMLButtonElement();
- enum typeEnum {
- SUBMIT,
- RESET,
- BUTTON
- };
+ enum typeEnum { SUBMIT, RESET, BUTTON };
- String type() const;
+ virtual const AtomicString& type() const;
virtual WebCore::RenderObject *createRenderer(RenderArena*, WebCore::RenderStyle*);
return false;
}
-String HTMLFieldSetElement::type() const
+const AtomicString& HTMLFieldSetElement::type() const
{
- return "fieldset";
+ static const AtomicString fieldset("fieldset");
+ return fieldset;
}
RenderObject* HTMLFieldSetElement::createRenderer(RenderArena* arena, RenderStyle* style)
* Boston, MA 02111-1307, USA.
*
*/
+
#ifndef KHTML_HTMLFieldSetElementImpl_H
#define KHTML_HTMLFieldSetElementImpl_H
class Document;
class Node;
-class HTMLFieldSetElement : public HTMLGenericFormElement
-{
+class HTMLFieldSetElement : public HTMLGenericFormElement {
public:
- HTMLFieldSetElement(Document *doc, HTMLFormElement *f = 0);
+ HTMLFieldSetElement(Document*, HTMLFormElement* = 0);
virtual ~HTMLFieldSetElement();
virtual int tagPriority() const { return 3; }
virtual bool checkDTD(const Node* newChild);
virtual bool isFocusable() const;
-
- virtual WebCore::RenderObject *createRenderer(RenderArena *, WebCore::RenderStyle *);
-
- virtual String type() const;
+ virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
+ virtual const AtomicString& type() const;
};
} //namespace
#include "Frame.h"
#include "HTMLDocument.h"
#include "HTMLFormCollection.h"
+#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "csshelper.h"
#include "html_imageimpl.h"
return false;
}
-// Special chars used to encode form state strings.
-// We pick chars that are unlikely to be used in an HTML attr, so we rarely have to really encode.
-const char stateSeparator = '&';
-const char stateEscape = '<';
-static const char stateSeparatorMarker[] = "<A";
-static const char stateEscapeMarker[] = "<<";
-
-// Encode an element name so we can put it in a state string without colliding
-// with our separator char.
-static DeprecatedString encodedElementName(DeprecatedString str)
+String HTMLGenericFormElement::stateValue() const
{
- int sepLoc = str.find(stateSeparator);
- int escLoc = str.find(stateSeparator);
- if (sepLoc >= 0 || escLoc >= 0) {
- DeprecatedString newStr = str;
- // replace "<" with "<<"
- while (escLoc >= 0) {
- newStr.replace(escLoc, 1, stateEscapeMarker);
- escLoc = str.find(stateSeparator, escLoc+1);
- }
- // replace "&" with "<A"
- while (sepLoc >= 0) {
- newStr.replace(sepLoc, 1, stateSeparatorMarker);
- sepLoc = str.find(stateSeparator, sepLoc+1);
- }
- return newStr;
- } else {
- return str;
- }
+ // Should only reach here if object is inserted into the "form element with
+ // state" set. If so, the derived class is responsible for implementing this function.
+ ASSERT_NOT_REACHED();
+ return String();
}
-DeprecatedString HTMLGenericFormElement::state( )
+void HTMLGenericFormElement::restoreState(const String&)
{
- // Build a string that contains ElementName&ElementType&
- return encodedElementName(name().deprecatedString()) + stateSeparator + type().deprecatedString() + stateSeparator;
+ // Should only reach here if object of this type was once inserted into the
+ // "form element with state" set. If so, the derived class is responsible for
+ // implementing this function.
+ ASSERT_NOT_REACHED();
}
-DeprecatedString HTMLGenericFormElement::findMatchingState(DeprecatedStringList &states)
+void HTMLGenericFormElement::closeRenderer()
{
- DeprecatedString encName = encodedElementName(name().deprecatedString());
- DeprecatedString typeStr = type().deprecatedString();
- for (DeprecatedStringList::Iterator it = states.begin(); it != states.end(); ++it) {
- DeprecatedString state = *it;
- int sep1 = state.find(stateSeparator);
- int sep2 = state.find(stateSeparator, sep1+1);
- assert(sep1 >= 0);
- assert(sep2 >= 0);
-
- String nameAndType = state.left(sep2);
- if (encName.length() + typeStr.length() + 1 == (unsigned)sep2
- && nameAndType.startsWith(encName)
- && nameAndType.endsWith(typeStr)) {
- states.remove(it);
- return state.mid(sep2+1);
- }
+ Document* doc = document();
+ if (doc->hasStateForNewFormElements()) {
+ String state;
+ if (doc->takeStateForFormElement(name().impl(), type().impl(), state))
+ restoreState(state);
}
- return DeprecatedString::null;
}
int HTMLGenericFormElement::tabIndex() const
* Boston, MA 02111-1307, USA.
*
*/
+
#ifndef HTML_HTMLGenericFormElementImpl_h
#define HTML_HTMLGenericFormElementImpl_h
#include "HTMLElement.h"
-namespace WebCore {
- class RenderFormElement;
-}
-
namespace WebCore {
class FormDataList;
class HTMLFormElement;
+class RenderFormElement;
class HTMLGenericFormElement : public HTMLElement
{
friend class HTMLFormElement;
- friend class WebCore::RenderFormElement;
+ friend class RenderFormElement;
public:
- HTMLGenericFormElement(const QualifiedName& tagName, Document *doc, HTMLFormElement *f = 0);
+ HTMLGenericFormElement(const QualifiedName& tagName, Document*, HTMLFormElement* = 0);
virtual ~HTMLGenericFormElement();
virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; }
virtual int tagPriority() const { return 1; }
- HTMLFormElement *form() { return m_form; }
+ HTMLFormElement* form() const { return m_form; }
- virtual String type() const = 0;
+ virtual const AtomicString& type() const = 0;
virtual bool isControl() const { return true; }
virtual bool isEnabled() const { return !disabled(); }
- virtual void parseMappedAttribute(MappedAttribute *attr);
+ virtual void parseMappedAttribute(MappedAttribute*);
virtual void attach();
virtual void insertedIntoTree(bool deep);
virtual void removedFromTree(bool deep);
+ virtual void closeRenderer();
virtual void reset() {}
void onChange();
bool disabled() const;
- void setDisabled(bool _disabled);
+ void setDisabled(bool);
virtual bool isFocusable() const;
virtual bool isKeyboardFocusable() const;
virtual bool isEnumeratable() const { return false; }
virtual bool isReadOnlyControl() const { return m_readOnly; }
- void setReadOnly(bool _readOnly);
+ void setReadOnly(bool);
- virtual void recalcStyle( StyleChange );
+ virtual void recalcStyle(StyleChange);
virtual const AtomicString& name() const;
void setName(const AtomicString& name);
virtual bool isGenericFormElement() const { return true; }
virtual bool isRadioButton() const { return false; }
- /*
- * override in derived classes to get the encoded name=value pair
- * for submitting
- * return true for a successful control (see HTML4-17.13.2)
+ /* Override in derived classes to get the encoded name=value pair for submitting.
+ * Return true for a successful control (see HTML4-17.13.2).
*/
virtual bool appendFormData(FormDataList&, bool) { return false; }
- virtual DeprecatedString state();
- DeprecatedString findMatchingState(DeprecatedStringList &states);
+ virtual String stateValue() const;
+ virtual void restoreState(const String& value);
virtual bool isSuccessfulSubmitButton() const { return false; }
virtual bool isActivatedSubmit() const { return false; }
void setTabIndex(int);
protected:
- HTMLFormElement *getForm() const;
+ HTMLFormElement* getForm() const;
- HTMLFormElement *m_form;
- bool m_disabled : 1;
- bool m_readOnly: 1;
- bool m_inited : 1;
+private:
+ HTMLFormElement* m_form;
+ bool m_disabled;
+ bool m_readOnly;
};
} //namespace
m_maxResults = -1;
- if (m_form)
- m_autocomplete = m_form->autoComplete();
+ if (form())
+ m_autocomplete = form()->autoComplete();
+
+ document()->registerFormElementWithState(this);
}
HTMLInputElement::~HTMLInputElement()
{
- document()->deregisterMaintainsState(this);
+ document()->deregisterFormElementWithState(this);
delete m_imageLoader;
}
Node* currentFocusNode = document()->focusNode();
if (currentFocusNode && currentFocusNode->hasTagName(inputTag)) {
HTMLInputElement* focusedInput = static_cast<HTMLInputElement*>(currentFocusNode);
- if (focusedInput->inputType() == RADIO && focusedInput->form() == m_form &&
+ if (focusedInput->inputType() == RADIO && focusedInput->form() == form() &&
focusedInput->name() == name())
return false;
}
// Allow keyboard focus if we're checked or if nothing in the group is checked.
- return checked() || !document()->checkedRadioButtonForGroup(name().impl(), m_form);
+ return checked() || !document()->checkedRadioButtonForGroup(name().impl(), form());
}
return true;
if (t.isEmpty()) {
int exccode;
removeAttribute(typeAttr, exccode);
- }
- else
+ } else
setAttribute(typeAttr, t);
}
setAttribute(typeAttr, type());
} else {
if (inputType() == RADIO && !name().isEmpty()) {
- if (document()->checkedRadioButtonForGroup(name().impl(), m_form) == this)
- document()->removeRadioButtonGroup(name().impl(), m_form);
+ if (document()->checkedRadioButtonForGroup(name().impl(), form()) == this)
+ document()->removeRadioButtonGroup(name().impl(), form());
}
bool wasAttached = m_attached;
if (wasAttached)
detach();
bool didStoreValue = storesValueSeparateFromAttribute();
- bool didMaintainState = maintainsState();
+ bool didMaintainState = inputType() != PASSWORD;
m_type = newType;
bool willStoreValue = storesValueSeparateFromAttribute();
- bool willMaintainState = maintainsState();
+ bool willMaintainState = inputType() != PASSWORD;
if (didStoreValue && !willStoreValue && !m_value.isNull()) {
setAttribute(valueAttr, m_value);
m_value = String();
else
recheckValue();
if (willMaintainState && !didMaintainState)
- document()->registerMaintainsState(this);
+ document()->registerFormElementWithState(this);
else if (!willMaintainState && didMaintainState)
- document()->deregisterMaintainsState(this);
+ document()->deregisterFormElementWithState(this);
if (wasAttached)
attach();
// If our type morphs into a radio button and we are checked, then go ahead
// and signal this to the form.
if (inputType() == RADIO && checked())
- document()->radioButtonChecked(this, m_form);
+ document()->radioButtonChecked(this, form());
}
}
m_haveType = true;
}
}
-String HTMLInputElement::type() const
+const AtomicString& HTMLInputElement::type() const
{
// needs to be lowercase according to DOM spec
switch (inputType()) {
- case BUTTON:
- return "button";
- case CHECKBOX:
- return "checkbox";
- case FILE:
- return "file";
- case HIDDEN:
- return "hidden";
- case IMAGE:
- return "image";
+ case BUTTON: {
+ static const AtomicString button("button");
+ return button;
+ }
+ case CHECKBOX: {
+ static const AtomicString checkbox("checkbox");
+ return checkbox;
+ }
+ case FILE: {
+ static const AtomicString file("file");
+ return file;
+ }
+ case HIDDEN: {
+ static const AtomicString hidden("hidden");
+ return hidden;
+ }
+ case IMAGE: {
+ static const AtomicString image("image");
+ return image;
+ }
case ISINDEX:
- return "";
- case PASSWORD:
- return "password";
- case RADIO:
- return "radio";
- case RANGE:
- return "range";
- case RESET:
- return "reset";
- case SEARCH:
- return "search";
- case SUBMIT:
- return "submit";
- case TEXT:
- return "text";
+ return emptyAtom;
+ case PASSWORD: {
+ static const AtomicString password("password");
+ return password;
+ }
+ case RADIO: {
+ static const AtomicString radio("radio");
+ return radio;
+ }
+ case RANGE: {
+ static const AtomicString range("range");
+ return range;
+ }
+ case RESET: {
+ static const AtomicString reset("reset");
+ return reset;
+ }
+ case SEARCH: {
+ static const AtomicString search("search");
+ return search;
+ }
+ case SUBMIT: {
+ static const AtomicString submit("submit");
+ return submit;
+ }
+ case TEXT: {
+ static const AtomicString text("text");
+ return text;
+ }
}
- return "";
+ return emptyAtom;
}
-DeprecatedString HTMLInputElement::state()
+String HTMLInputElement::stateValue() const
{
- assert(inputType() != PASSWORD); // should never save/restore password fields
-
- DeprecatedString state = HTMLGenericFormElement::state();
+ ASSERT(inputType() != PASSWORD); // should never save/restore password fields
switch (inputType()) {
case BUTTON:
case FILE:
case SEARCH:
case SUBMIT:
case TEXT:
- return state + value().deprecatedString() + '.'; // Add "." to make sure string is not empty.
+ return value();
case CHECKBOX:
case RADIO:
- return state + (checked() ? "on" : "off");
+ return checked() ? "on" : "off";
case PASSWORD:
break;
}
- return DeprecatedString();
+ return String();
}
-void HTMLInputElement::restoreState(DeprecatedStringList &states)
+void HTMLInputElement::restoreState(const String& state)
{
- assert(inputType() != PASSWORD); // should never save/restore password fields
-
- DeprecatedString state = HTMLGenericFormElement::findMatchingState(states);
- if (state.isNull())
- return;
-
+ ASSERT(inputType() != PASSWORD); // should never save/restore password fields
switch (inputType()) {
case BUTTON:
case FILE:
case SEARCH:
case SUBMIT:
case TEXT:
- setValue(state.left(state.length() - 1));
+ setValue(state);
break;
case CHECKBOX:
case RADIO:
if (inputType() == RADIO && checked()) {
// Remove the radio from its old group.
if (!m_name.isEmpty())
- document()->removeRadioButtonGroup(m_name.impl(), m_form);
+ document()->removeRadioButtonGroup(m_name.impl(), form());
}
// Update our cached reference to the name.
setChecked(m_defaultChecked);
// Add the button to its new group.
if (checked())
- document()->radioButtonChecked(this, m_form);
+ document()->radioButtonChecked(this, form());
}
} else if (attr->name() == autocompleteAttr) {
m_autocomplete = !equalIgnoringCase(attr->value(), "off");
{
// HTML spec says that buttons must have names to be considered successful.
// However, other browsers do not impose this constraint. So we do likewise.
- return !m_disabled && (inputType() == IMAGE || inputType() == SUBMIT);
+ return !disabled() && (inputType() == IMAGE || inputType() == SUBMIT);
}
bool HTMLInputElement::isActivatedSubmit() const
return;
if (inputType() == RADIO && nowChecked)
- document()->radioButtonChecked(this, m_form);
+ document()->radioButtonChecked(this, form());
m_useDefaultChecked = false;
m_checked = nowChecked;
// We really want radio groups to end up in sane states, i.e., to have something checked.
// Therefore if nothing is currently selected, we won't allow this action to be "undone", since
// we want some object in the radio group to actually get selected.
- HTMLInputElement* currRadio = document()->checkedRadioButtonForGroup(name().impl(), m_form);
+ HTMLInputElement* currRadio = document()->checkedRadioButtonForGroup(name().impl(), form());
if (currRadio) {
// We have a radio button selected that is not us. Cache it in our result field and ref it so
// that it can't be destroyed.
// must dispatch a DOMActivate event - a click event will not do the job.
if (evt->type() == DOMActivateEvent) {
if (inputType() == IMAGE || inputType() == SUBMIT || inputType() == RESET) {
- if (!m_form)
+ if (!form())
return;
if (inputType() == RESET)
- m_form->reset();
+ form()->reset();
else {
m_activeSubmit = true;
- if (!m_form->prepareSubmit()) {
+ if (!form()->prepareSubmit()) {
xPos = 0;
yPos = 0;
}
// Look for more radio buttons.
if (n->hasTagName(inputTag)) {
HTMLInputElement* elt = static_cast<HTMLInputElement*>(n);
- if (elt->form() != m_form)
+ if (elt->form() != form())
break;
if (n->hasTagName(inputTag)) {
HTMLInputElement* inputElt = static_cast<HTMLInputElement*>(n);
if (clickElement) {
click(false);
evt->setDefaultHandled();
- } else if (clickDefaultFormButton && m_form) {
- m_form->submitClick();
+ } else if (clickDefaultFormButton && form()) {
+ form()->submitClick();
evt->setDefaultHandled();
}
}
void setIndeterminate(bool);
int maxLength() const { return m_maxLen; }
int size() const { return m_size; }
- String type() const;
+ virtual const AtomicString& type() const;
void setType(const String&);
String value() const;
bool valueMatchesRenderer() const { return m_valueMatchesRenderer; }
void setValueMatchesRenderer() { m_valueMatchesRenderer = true; }
- virtual bool maintainsState() { return m_type != PASSWORD; }
- virtual DeprecatedString state();
- virtual void restoreState(DeprecatedStringList&);
+ virtual String stateValue() const;
+ virtual void restoreState(const String&);
bool canHaveSelection() const;
int selectionStart() const;
bool m_autocomplete : 1;
bool m_valueMatchesRenderer : 1;
bool m_autofilled : 1;
+ bool m_inited : 1;
};
} //namespace
}
}
-String HTMLKeygenElement::type() const
+const AtomicString& HTMLKeygenElement::type() const
{
- return "keygen";
+ static const AtomicString keygen("keygen");
+ return keygen;
}
void HTMLKeygenElement::parseMappedAttribute(MappedAttribute* attr)
* Boston, MA 02111-1307, USA.
*
*/
+
#ifndef HTML_HTMLKeygenElementImpl_H
#define HTML_HTMLKeygenElementImpl_H
namespace WebCore {
-class FormDataList;
-class MappedAttribute;
-
-class HTMLKeygenElement : public HTMLSelectElement
-{
+class HTMLKeygenElement : public HTMLSelectElement {
public:
- HTMLKeygenElement(Document *doc, HTMLFormElement *f = 0);
+ HTMLKeygenElement(Document*, HTMLFormElement* = 0);
virtual int tagPriority() const { return 0; }
-
- String type() const;
-
- // ### this is just a rough guess
+ virtual const AtomicString& type() const;
virtual bool isEnumeratable() const { return false; }
-
- virtual void parseMappedAttribute(MappedAttribute *attr);
+ virtual void parseMappedAttribute(MappedAttribute*);
virtual bool appendFormData(FormDataList&, bool);
-protected:
+
+private:
AtomicString m_challenge;
AtomicString m_keyType;
};
return new (arena) RenderLegend(this);
}
-String HTMLLegendElement::type() const
+const AtomicString& HTMLLegendElement::type() const
{
- return "legend";
+ static const AtomicString legend("legend");
+ return legend;
}
String HTMLLegendElement::accessKey() const
* Boston, MA 02111-1307, USA.
*
*/
+
#ifndef HTML_HTMLLegendElementImpl_H
#define HTML_HTMLLegendElementImpl_H
namespace WebCore {
-class HTMLFormElement;
-
-class HTMLLegendElement : public HTMLGenericFormElement
-{
+class HTMLLegendElement : public HTMLGenericFormElement {
public:
- HTMLLegendElement(Document *doc, HTMLFormElement *f = 0);
+ HTMLLegendElement(Document*, HTMLFormElement* = 0);
virtual ~HTMLLegendElement();
virtual bool isFocusable() const;
-
- virtual WebCore::RenderObject *createRenderer(RenderArena *, WebCore::RenderStyle *);
-
- virtual String type() const;
-
+ virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
+ virtual const AtomicString& type() const;
virtual void accessKeyAction(bool sendToAnyElement);
/**
* The first form element in the legend's fieldset
*/
- Element *formElement();
+ Element* formElement();
String accessKey() const;
void setAccessKey(const String &);
return false;
}
-String HTMLOptGroupElement::type() const
+const AtomicString& HTMLOptGroupElement::type() const
{
- return "optgroup";
+ static const AtomicString optgroup("optgroup");
+ return optgroup;
}
bool HTMLOptGroupElement::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec)
namespace WebCore {
-class HTMLOptGroupElement : public HTMLGenericFormElement
-{
+class HTMLOptGroupElement : public HTMLGenericFormElement {
public:
HTMLOptGroupElement(Document*, HTMLFormElement* = 0);
virtual ~HTMLOptGroupElement();
virtual bool checkDTD(const Node*);
- virtual String type() const;
+ virtual const AtomicString& type() const;
virtual bool isFocusable() const;
virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&);
virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&);
#include "Document.h"
#include "ExceptionCode.h"
+#include "HTMLSelectElement.h"
#include "Text.h"
#include "render_form.h"
return false;
}
-String HTMLOptionElement::type() const
+const AtomicString& HTMLOptionElement::type() const
{
- return "option";
+ static const AtomicString option("option");
+ return option;
}
String HTMLOptionElement::text() const
#include "HTMLGenericFormElement.h"
#include "HTMLNames.h"
-namespace WebCore {
- class RenderSelect;
-}
-
namespace WebCore {
class HTMLSelectElement;
class HTMLFormElement;
class MappedAttribute;
+class RenderSelect;
class HTMLOptionElement : public HTMLGenericFormElement
{
- friend class WebCore::RenderSelect;
- friend class WebCore::HTMLSelectElement;
+ friend class RenderSelect;
+ friend class HTMLSelectElement;
public:
- HTMLOptionElement(Document *doc, HTMLFormElement *f = 0);
+ HTMLOptionElement(Document*, HTMLFormElement* = 0);
virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; }
virtual int tagPriority() const { return 2; }
virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode() || newChild->hasTagName(HTMLNames::scriptTag); }
-
virtual bool isFocusable() const;
- String type() const;
+ virtual const AtomicString& type() const;
String text() const;
void setText(const String &, ExceptionCode&);
int index() const;
void setIndex(int, ExceptionCode&);
- virtual void parseMappedAttribute(MappedAttribute *attr);
+ virtual void parseMappedAttribute(MappedAttribute*);
String value() const;
- void setValue(const String &);
+ void setValue(const String&);
bool selected() const { return m_selected; }
- void setSelected(bool _selected);
+ void setSelected(bool);
- HTMLSelectElement *getSelect() const;
+ HTMLSelectElement* getSelect() const;
virtual void childrenChanged();
bool defaultSelected() const;
- void setDefaultSelected( bool );
+ void setDefaultSelected(bool);
String label() const;
- void setLabel( const String & );
+ void setLabel(const String&);
-protected:
+private:
String m_value;
bool m_selected;
};
} else {
if (parentAttached && !n->attached() && !m_fragment)
n->attach();
- if (n->maintainsState()) {
- doc()->registerMaintainsState(n);
- DeprecatedStringList &states = doc()->restoreState();
- if (!states.isEmpty())
- n->restoreState(states);
- }
n->closeRenderer();
}
void HTMLParser::popOneBlock(bool delBlock)
{
- HTMLStackElem *Elem = blockStack;
+ HTMLStackElem* elem = blockStack;
- // we should never get here, but some bad html might cause it.
- if (!Elem) return;
-
- if (current && Elem->node != current) {
- if (current->maintainsState() && doc()) {
- doc()->registerMaintainsState(current);
- DeprecatedStringList &states = doc()->restoreState();
- if (!states.isEmpty())
- current->restoreState(states);
- }
-
- // A few elements (<applet>, <object>) need to know when all child elements (<param>s) are available:
+ // Form elements restore their state during the parsing process.
+ // Also, a few elements (<applet>, <object>) need to know when all child elements (<param>s) are available.
+ if (current && elem->node != current)
current->closeRenderer();
- }
- blockStack = Elem->next;
- setCurrent(Elem->node.get());
+ blockStack = elem->next;
+ setCurrent(elem->node.get());
- if (Elem->strayTableContent)
+ if (elem->strayTableContent)
inStrayTableContent--;
if (delBlock)
- delete Elem;
+ delete elem;
}
void HTMLParser::popInlineBlocks()
using namespace EventNames;
using namespace HTMLNames;
-HTMLSelectElement::HTMLSelectElement(Document *doc, HTMLFormElement *f)
+HTMLSelectElement::HTMLSelectElement(Document* doc, HTMLFormElement* f)
: HTMLGenericFormElement(selectTag, doc, f), m_minwidth(0), m_size(0), m_multiple(false), m_recalcListItems(false)
{
+ document()->registerFormElementWithState(this);
}
-HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document *doc, HTMLFormElement *f)
- : HTMLGenericFormElement(tagName, doc, f)
+HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f)
+ : HTMLGenericFormElement(tagName, doc, f), m_minwidth(0), m_size(0), m_multiple(false), m_recalcListItems(false)
{
+ document()->registerFormElementWithState(this);
}
HTMLSelectElement::~HTMLSelectElement()
{
- document()->deregisterMaintainsState(this);
+ document()->deregisterFormElementWithState(this);
}
bool HTMLSelectElement::checkDTD(const Node* newChild)
}
-String HTMLSelectElement::type() const
+const AtomicString& HTMLSelectElement::type() const
{
- return (m_multiple ? "select-multiple" : "select-one");
+ static const AtomicString selectMultiple("select-multiple");
+ static const AtomicString selectOne("select-one");
+ return m_multiple ? selectMultiple : selectOne;
}
int HTMLSelectElement::selectedIndex() const
}
}
-DeprecatedString HTMLSelectElement::state()
+String HTMLSelectElement::stateValue() const
{
DeprecatedArray<HTMLElement*> items = listItems();
-
int l = items.count();
- DeprecatedString state;
- for(int i = 0; i < l; i++)
- if(items[i]->hasLocalName(optionTag) && static_cast<HTMLOptionElement*>(items[i])->selected())
- state += 'X';
- else
- state += '.';
-
- return HTMLGenericFormElement::state() + state;
+ Vector<char, 1024> characters(l);
+ for (int i = 0; i < l; ++i) {
+ HTMLElement* e = items[i];
+ bool selected = e->hasLocalName(optionTag) && static_cast<HTMLOptionElement*>(e)->selected();
+ characters[i] = selected ? 'X' : '.';
+ }
+ return String(characters, l);
}
-void HTMLSelectElement::restoreState(DeprecatedStringList &_states)
+void HTMLSelectElement::restoreState(const String& state)
{
- DeprecatedString _state = HTMLGenericFormElement::findMatchingState(_states);
- if (_state.isNull()) return;
-
recalcListItems();
- DeprecatedString state = _state;
- if(!state.isEmpty() && !state.contains('X') && !m_multiple) {
- // KWQString doesn't support this operation. Should never get here anyway.
- //state[0] = 'X';
- }
-
DeprecatedArray<HTMLElement*> items = listItems();
-
int l = items.count();
- for (int i = 0; i < l; i++) {
- if (items[i]->hasLocalName(optionTag)) {
- HTMLOptionElement* oe = static_cast<HTMLOptionElement*>(items[i]);
- oe->setSelected(state[i] == 'X');
- }
- }
+ for (int i = 0; i < l; i++)
+ if (items[i]->hasLocalName(optionTag))
+ static_cast<HTMLOptionElement*>(items[i])->setSelected(state[i] == 'X');
setChanged(true);
}
// Use key press event here since sending simulated mouse events
// on key down blocks the proper sending of the key press event.
if (evt->type() == keypressEvent) {
-
- if (!m_form || !renderer() || !evt->isKeyboardEvent())
+ if (!form() || !renderer() || !evt->isKeyboardEvent())
return;
-
- String key = static_cast<KeyboardEvent *>(evt)->keyIdentifier();
-
- if (key == "Enter") {
- m_form->submitClick();
+ if (static_cast<KeyboardEvent*>(evt)->keyIdentifier() == "Enter") {
+ form()->submitClick();
evt->setDefaultHandled();
}
}
virtual int tagPriority() const { return 6; }
virtual bool checkDTD(const Node* newChild);
- String type() const;
+ virtual const AtomicString& type() const;
virtual void recalcStyle(StyleChange);
PassRefPtr<HTMLOptionsCollection> options();
- virtual bool maintainsState() { return true; }
- virtual DeprecatedString state();
- virtual void restoreState(DeprecatedStringList &);
+ virtual String stateValue() const;
+ virtual void restoreState(const String&);
virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&);
virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&);
HTMLTextAreaElement::HTMLTextAreaElement(Document *doc, HTMLFormElement *f)
: HTMLGenericFormElement(textareaTag, doc, f)
+ , m_rows(2)
+ , m_cols(20)
+ , m_wrap(ta_Virtual)
, m_valueMatchesRenderer(true)
{
- // DTD requires rows & cols be specified, but we will provide reasonable defaults
- m_rows = 2;
- m_cols = 20;
- m_wrap = ta_Virtual;
+ document()->registerFormElementWithState(this);
}
HTMLTextAreaElement::~HTMLTextAreaElement()
{
- document()->deregisterMaintainsState(this);
+ document()->deregisterFormElementWithState(this);
}
-String HTMLTextAreaElement::type() const
+const AtomicString& HTMLTextAreaElement::type() const
{
- return "textarea";
+ static const AtomicString textarea("textarea");
+ return textarea;
}
-DeprecatedString HTMLTextAreaElement::state( )
+String HTMLTextAreaElement::stateValue() const
{
- // Make sure the string is not empty!
- return HTMLGenericFormElement::state() + value().deprecatedString()+'.';
+ return value();
}
-void HTMLTextAreaElement::restoreState(DeprecatedStringList &states)
+void HTMLTextAreaElement::restoreState(const String& state)
{
- DeprecatedString state = HTMLGenericFormElement::findMatchingState(states);
- if (state.isNull()) return;
- setDefaultValue(state.left(state.length()-1));
- // the close() in the rendertree will take care of transferring defaultvalue to 'value'
+ setDefaultValue(state);
}
int HTMLTextAreaElement::selectionStart()
updateValue();
}
-void HTMLTextAreaElement::updateValue()
+void HTMLTextAreaElement::updateValue() const
{
if (!m_valueMatchesRenderer) {
ASSERT(renderer());
}
}
-String HTMLTextAreaElement::value()
+String HTMLTextAreaElement::value() const
{
updateValue();
return m_value;
setChanged(true);
}
-String HTMLTextAreaElement::defaultValue()
+String HTMLTextAreaElement::defaultValue() const
{
String val = "";
+
// there may be comments - just grab the text nodes
- Node *n;
- for (n = firstChild(); n; n = n->nextSibling())
+ for (Node* n = firstChild(); n; n = n->nextSibling())
if (n->isTextNode())
val += static_cast<Text*>(n)->data();
-
+
// FIXME: We should only drop the first carriage return for the default
// value in the original source, not defaultValues set from JS.
if (val.length() >= 2 && val[0] == '\r' && val[1] == '\n')
* Boston, MA 02111-1307, USA.
*
*/
+
#ifndef HTML_HTMLTextAreaElementImpl_H
#define HTML_HTMLTextAreaElementImpl_H
#include "HTMLGenericFormElement.h"
namespace WebCore {
- class RenderTextArea;
-}
-namespace WebCore {
+class RenderTextArea;
-class HTMLTextAreaElement : public HTMLGenericFormElement
-{
- friend class WebCore::RenderTextArea;
+class HTMLTextAreaElement : public HTMLGenericFormElement {
+ friend class RenderTextArea;
public:
- enum WrapMethod {
- ta_NoWrap,
- ta_Virtual,
- ta_Physical
- };
+ enum WrapMethod { ta_NoWrap, ta_Virtual, ta_Physical };
- HTMLTextAreaElement(Document *doc, HTMLFormElement *f = 0);
+ HTMLTextAreaElement(Document*, HTMLFormElement* = 0);
~HTMLTextAreaElement();
virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); }
virtual bool isEnumeratable() const { return true; }
- String type() const;
+ virtual const AtomicString& type() const;
- virtual bool maintainsState() { return true; }
- virtual DeprecatedString state();
- virtual void restoreState(DeprecatedStringList &);
+ virtual String stateValue() const;
+ virtual void restoreState(const String&);
bool readOnly() const { return isReadOnlyControl(); }
void setSelectionStart(int);
void setSelectionEnd(int);
- void select ( );
+ void select();
void setSelectionRange(int, int);
virtual void childrenChanged();
- virtual void parseMappedAttribute(MappedAttribute *attr);
- virtual WebCore::RenderObject *createRenderer(RenderArena *, WebCore::RenderStyle *);
+ virtual void parseMappedAttribute(MappedAttribute*);
+ virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
virtual bool appendFormData(FormDataList&, bool);
virtual void reset();
- String value();
- void setValue(const String &value);
- String defaultValue();
- void setDefaultValue(const String &value);
+ String value() const;
+ void setValue(const String&);
+ String defaultValue() const;
+ void setDefaultValue(const String&);
void invalidateValue() { m_valueMatchesRenderer = false; }
void rendererWillBeDestroyed();
virtual void accessKeyAction(bool sendToAnyElement);
String accessKey() const;
- void setAccessKey(const String &);
+ void setAccessKey(const String&);
void setCols(int);
-
void setRows(int);
-protected:
+private:
+ void updateValue() const;
+
int m_rows;
int m_cols;
WrapMethod m_wrap;
- String m_value;
- bool m_valueMatchesRenderer;
-
-private:
- void updateValue();
+ mutable String m_value;
+ mutable bool m_valueMatchesRenderer;
};
} //namespace
void SVGAnimationElement::closeRenderer()
{
document()->accessSVGExtensions()->timeScheduler()->addTimer(this, lround(getStartTime()));
+ SVGElement::closeRenderer();
}
String SVGAnimationElement::targetAttribute() const
--- /dev/null
+<p>This tests if form values get their values properly restored when you go back.
+To test, use the Debug menu to turn off "Use Back/Forward Cache".
+Then, type "a" into the first field below, type "b" into the second field, and select both "c" and "d" in the list box.
+Then, click on <a href="about:blank">this link</a> to go to a blank page.
+Then go back.
+Check that the form elements have the values that selected.</p>
+<div><input type="text" name="text-input"></div>
+<div><textarea></textarea></div>
+<div><select multiple size=5><option>a</option><option>b</option><option>c</option><option>d</option><option>e</option><option>f</option><option>g</option></select></div>
#include "HTMLTextAreaElement.h"
#include "KWQComboBox.h"
#include "KWQFileButton.h"
+#include "KWQLineEdit.h"
#include "KWQSlider.h"
#include "KWQTextEdit.h"
#include "PlatformMouseEvent.h"
void RenderFormElement::updateFromElement()
{
- m_widget->setEnabled(!element()->disabled());
+ m_widget->setEnabled(!static_cast<HTMLGenericFormElement*>(node())->disabled());
}
void RenderFormElement::layout()
{
RenderArena* arena = ref();
PlatformMouseEvent event; // gets "current event"
- if (element())
- element()->dispatchMouseEvent(event, clickEvent, event.clickCount());
+ if (node())
+ static_cast<EventTargetNode*>(node())->dispatchMouseEvent(event, clickEvent, event.clickCount());
deref(arena);
}
// We only want to call onselect if there actually is a selection
QLineEdit* w = static_cast<QLineEdit*>(m_widget);
if (w->hasSelectedText())
- element()->onSelect();
+ static_cast<HTMLGenericFormElement*>(node())->onSelect();
}
void RenderLineEdit::returnPressed(Widget*)
// Works but might not be enough, dirk said he had another solution at
// hand (can't remember which) - David
if (isTextField() && isEdited()) {
- element()->onChange();
+ static_cast<HTMLGenericFormElement*>(node())->onChange();
setEdited(false);
}
- if (HTMLFormElement* fe = element()->form())
+ if (HTMLFormElement* fe = static_cast<HTMLGenericFormElement*>(node())->form())
fe->submitClick();
}
void RenderLineEdit::performSearch(Widget*)
{
// Fire the "search" DOM event.
- element()->dispatchHTMLEvent(searchEvent, true, false);
+ static_cast<EventTargetNode*>(node())->dispatchHTMLEvent(searchEvent, true, false);
}
void RenderLineEdit::addSearchResult()
{
if (widget())
- widget()->addSearchResult();
+ static_cast<QLineEdit*>(widget())->addSearchResult();
}
void RenderLineEdit::calcMinMaxWidth()
{
- KHTMLAssert( !minMaxKnown() );
+ KHTMLAssert(!minMaxKnown());
// Let the widget tell us how big it wants to be.
m_updating = true;
- int size = element()->size();
- IntSize s(widget()->sizeForCharacterWidth(size > 0 ? size : 20));
+ int size = static_cast<HTMLInputElement*>(node())->size();
+ IntSize s(static_cast<QLineEdit*>(widget())->sizeForCharacterWidth(size > 0 ? size : 20));
m_updating = false;
- setIntrinsicWidth( s.width() );
- setIntrinsicHeight( s.height() );
+ setIntrinsicWidth(s.width());
+ setIntrinsicHeight(s.height());
RenderFormElement::calcMinMaxWidth();
}
{
RenderFormElement::setStyle(s);
- QLineEdit *w = widget();
+ QLineEdit* w = static_cast<QLineEdit*>(widget());
w->setAlignment(textAlignment());
w->setWritingDirection(style()->direction() == RTL ? RTL : LTR);
}
void RenderLineEdit::updateFromElement()
{
- HTMLInputElement *e = element();
- QLineEdit *w = widget();
+ HTMLInputElement* e = static_cast<HTMLInputElement*>(node());
+ QLineEdit* w = static_cast<QLineEdit*>(widget());
int ml = e->maxLength();
- if ( ml <= 0 || ml > 1024 )
+ if (ml <= 0 || ml > 1024)
ml = 1024;
- if ( w->maxLength() != ml )
- w->setMaxLength( ml );
+ if (w->maxLength() != ml)
+ w->setMaxLength(ml);
if (!e->valueMatchesRenderer()) {
String widgetText = w->text();
if (m_updating) // Don't alter the value if we are in the middle of initing the control, since
return; // we are getting the value from the DOM and it's not user input.
- String newText = widget()->text();
+ String newText = static_cast<QLineEdit*>(widget())->text();
// A null string value is used to indicate that the form control has not altered the original
// default value. That means that we should never use the null string value when the user
newText = "";
newText.replace(backslashAsCurrencySymbol(), '\\');
- element()->setValueFromRenderer(newText);
+ static_cast<HTMLInputElement*>(node())->setValueFromRenderer(newText);
}
int RenderLineEdit::selectionStart()
void RenderFileButton::calcMinMaxWidth()
{
- KHTMLAssert( !minMaxKnown() );
+ KHTMLAssert(!minMaxKnown());
// Let the widget tell us how big it wants to be.
- int size = element()->size();
+ int size = static_cast<HTMLInputElement*>(node())->size();
IntSize s(static_cast<KWQFileButton *>(widget())->sizeForCharacterWidth(size > 0 ? size : 20));
- setIntrinsicWidth( s.width() );
- setIntrinsicHeight( s.height() );
+ setIntrinsicWidth(s.width());
+ setIntrinsicHeight(s.height());
RenderFormElement::calcMinMaxWidth();
}
void RenderFileButton::updateFromElement()
{
- static_cast<KWQFileButton *>(widget())->setFilename(element()->value().deprecatedString());
+ static_cast<KWQFileButton*>(widget())->setFilename(
+ static_cast<HTMLInputElement*>(node())->value().deprecatedString());
RenderFormElement::updateFromElement();
}
void RenderFileButton::returnPressed(Widget*)
{
- if (element()->form())
- element()->form()->prepareSubmit();
+ if (static_cast<HTMLInputElement*>(node())->form())
+ static_cast<HTMLInputElement*>(node())->form()->prepareSubmit();
}
void RenderFileButton::valueChanged(Widget*)
{
- element()->setValueFromRenderer(static_cast<KWQFileButton*>(widget())->filename());
- element()->onChange();
+ static_cast<HTMLInputElement*>(node())->setValueFromRenderer(static_cast<KWQFileButton*>(widget())->filename());
+ static_cast<HTMLInputElement*>(node())->onChange();
}
void RenderFileButton::select()
unsigned oldSize = m_size;
bool oldListbox = m_useListBox;
- m_multiple = element()->multiple();
- m_size = element()->size();
+ m_multiple = static_cast<HTMLSelectElement*>(node())->multiple();
+ m_size = static_cast<HTMLSelectElement*>(node())->size();
m_useListBox = (m_multiple || m_size > 1);
if (oldMultiple != m_multiple || oldSize != m_size) {
// update contents listbox/combobox based on options in m_element
if ( m_optionsChanged ) {
- if (element()->m_recalcListItems)
- element()->recalcListItems();
- DeprecatedArray<HTMLElement*> listItems = element()->listItems();
+ if (static_cast<HTMLSelectElement*>(node())->m_recalcListItems)
+ static_cast<HTMLSelectElement*>(node())->recalcListItems();
+ DeprecatedArray<HTMLElement*> listItems = static_cast<HTMLSelectElement*>(node())->listItems();
int listIndex;
if (m_useListBox)
RenderFormElement::layout();
// and now disable the widget in case there is no <option> given
- DeprecatedArray<HTMLElement*> listItems = element()->listItems();
+ DeprecatedArray<HTMLElement*> listItems = static_cast<HTMLSelectElement*>(node())->listItems();
bool foundOption = false;
for (unsigned i = 0; i < listItems.size() && !foundOption; i++)
foundOption = (listItems[i]->hasTagName(optionTag));
- m_widget->setEnabled(foundOption && ! element()->disabled());
+ m_widget->setEnabled(foundOption && ! static_cast<HTMLSelectElement*>(node())->disabled());
}
void RenderSelect::valueChanged(Widget*)
int index = static_cast<QComboBox*>(m_widget)->currentItem();
- DeprecatedArray<HTMLElement*> listItems = element()->listItems();
+ DeprecatedArray<HTMLElement*> listItems = static_cast<HTMLSelectElement*>(node())->listItems();
if (index >= 0 && index < (int)listItems.size()) {
bool found = listItems[index]->hasTagName(optionTag);
if (!found) {
}
}
- element()->onChange();
+ static_cast<HTMLSelectElement*>(node())->onChange();
}
// don't use listItems() here as we have to avoid recalculations - changing the
// option list will make use update options not in the way the user expects them
- DeprecatedArray<HTMLElement*> listItems = element()->m_listItems;
+ DeprecatedArray<HTMLElement*> listItems = static_cast<HTMLSelectElement*>(node())->m_listItems;
int j = 0;
for (unsigned i = 0; i < listItems.count(); i++) {
// don't use setSelected() here because it will cause us to be called
if (listItems[i]->hasTagName(optionTag) || listItems[i]->hasTagName(optgroupTag))
++j;
}
- element()->onChange();
+ static_cast<HTMLSelectElement*>(node())->onChange();
}
void RenderSelect::updateSelection()
{
- DeprecatedArray<HTMLElement*> listItems = element()->listItems();
+ DeprecatedArray<HTMLElement*> listItems = static_cast<HTMLSelectElement*>(node())->listItems();
int i;
if (m_useListBox) {
// if multi-select, we select only the new selected index
void RenderTextArea::destroy()
{
- element()->rendererWillBeDestroyed();
+ static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
RenderFormElement::destroy();
}
KHTMLAssert( !minMaxKnown() );
QTextEdit* w = static_cast<QTextEdit*>(m_widget);
- IntSize size(w->sizeWithColumnsAndRows(max(element()->cols(), 1), max(element()->rows(), 1)));
+ IntSize size(w->sizeWithColumnsAndRows(
+ max(static_cast<HTMLTextAreaElement*>(node())->cols(), 1),
+ max(static_cast<HTMLTextAreaElement*>(node())->rows(), 1)));
setIntrinsicWidth( size.width() );
setIntrinsicHeight( size.height() );
break;
}
ScrollBarMode horizontalScrollMode = scrollMode;
- if (element()->wrap() != HTMLTextAreaElement::ta_NoWrap)
+ if (static_cast<HTMLTextAreaElement*>(node())->wrap() != HTMLTextAreaElement::ta_NoWrap)
horizontalScrollMode = ScrollBarAlwaysOff;
w->setScrollBarModes(horizontalScrollMode, scrollMode);
void RenderTextArea::updateFromElement()
{
- HTMLTextAreaElement *e = element();
+ HTMLTextAreaElement* e = static_cast<HTMLTextAreaElement*>(node());
QTextEdit* w = static_cast<QTextEdit*>(m_widget);
w->setReadOnly(e->isReadOnlyControl());
{
if (m_updating)
return;
- element()->invalidateValue();
+ static_cast<HTMLTextAreaElement*>(node())->invalidateValue();
m_dirty = true;
}
if (!w->hasSelectedText())
return;
- element()->onSelect();
+ static_cast<HTMLTextAreaElement*>(node())->onSelect();
}
// ---------------------------------------------------------------------------
void RenderSlider::updateFromElement()
{
- String value = element()->value();
- const AtomicString& minStr = element()->getAttribute(minAttr);
- const AtomicString& maxStr = element()->getAttribute(maxAttr);
- const AtomicString& precision = element()->getAttribute(precisionAttr);
+ String value = static_cast<HTMLInputElement*>(node())->value();
+ const AtomicString& minStr = static_cast<HTMLInputElement*>(node())->getAttribute(minAttr);
+ const AtomicString& maxStr = static_cast<HTMLInputElement*>(node())->getAttribute(maxAttr);
+ const AtomicString& precision = static_cast<HTMLInputElement*>(node())->getAttribute(precisionAttr);
double minVal = minStr.isNull() ? 0.0 : minStr.deprecatedString().toDouble();
double maxVal = maxStr.isNull() ? 100.0 : maxStr.deprecatedString().toDouble();
if (!equalIgnoringCase(precision, "float"))
val = (int)(val + 0.5);
- element()->setValue(String::number(val));
+ static_cast<HTMLInputElement*>(node())->setValue(String::number(val));
QSlider* slider = (QSlider*)widget();
QSlider* slider = static_cast<QSlider*>(widget());
double val = slider->value();
- const AtomicString& precision = element()->getAttribute(precisionAttr);
+ const AtomicString& precision = static_cast<HTMLInputElement*>(node())->getAttribute(precisionAttr);
// Force integer value if not float.
if (!equalIgnoringCase(precision, "float"))
val = (int)(val + 0.5);
- element()->setValue(String::number(val));
+ static_cast<HTMLInputElement*>(node())->setValue(String::number(val));
// Fire the "input" DOM event.
- element()->dispatchHTMLEvent(inputEvent, true, false);
+ static_cast<HTMLInputElement*>(node())->dispatchHTMLEvent(inputEvent, true, false);
}
}
#ifndef RENDER_FORM_H
#define RENDER_FORM_H
-#include "HTMLInputElement.h"
-#include "HTMLSelectElement.h"
-#include "HTMLTextAreaElement.h"
-#include "KWQLineEdit.h"
+#include "GraphicsTypes.h"
#include "RenderBlock.h"
#include "RenderImage.h"
class DocLoader;
class HTMLFormElement;
class HTMLGenericFormElement;
+class HTMLInputElement;
+class HTMLSelectElement;
+class HTMLTextAreaElement;
// -------------------------------------------------------------------------
-class RenderFormElement : public WebCore::RenderWidget
+class RenderFormElement : public RenderWidget
{
public:
RenderFormElement(HTMLGenericFormElement* node);
virtual void layout();
virtual short baselinePosition( bool, bool ) const;
- HTMLGenericFormElement *element() const
- { return static_cast<HTMLGenericFormElement*>(RenderObject::element()); }
-
private:
virtual void clicked(Widget*);
protected:
virtual bool isEditable() const { return false; }
- WebCore::HorizontalAlignment textAlignment() const;
+ HorizontalAlignment textAlignment() const;
};
// -------------------------------------------------------------------------
class RenderImageButton : public RenderImage
{
public:
- RenderImageButton(HTMLInputElement *element);
+ RenderImageButton(HTMLInputElement*);
virtual const char *renderName() const { return "RenderImageButton"; }
virtual bool isImageButton() const { return true; }
class RenderLineEdit : public RenderFormElement
{
public:
- RenderLineEdit(HTMLInputElement *element);
+ RenderLineEdit(HTMLInputElement*);
virtual void calcMinMaxWidth();
int calcReplacedHeight() const { return intrinsicHeight(); }
void select();
void setSelectionRange(int, int);
- QLineEdit *widget() const { return static_cast<QLineEdit*>(m_widget); }
- HTMLInputElement* element() const
- { return static_cast<HTMLInputElement*>(RenderObject::element()); }
-
public:
void addSearchResult();
class RenderFileButton : public RenderFormElement
{
public:
- RenderFileButton(HTMLInputElement *element);
+ RenderFileButton(HTMLInputElement*);
virtual const char *renderName() const { return "RenderFileButton"; }
virtual void calcMinMaxWidth();
int calcReplacedHeight() const { return intrinsicHeight(); }
- HTMLInputElement *element() const
- { return static_cast<HTMLInputElement*>(RenderObject::element()); }
-
void click(bool sendMouseEvents);
protected:
class RenderSelect : public RenderFormElement
{
public:
- RenderSelect(HTMLSelectElement *element);
+ RenderSelect(HTMLSelectElement*);
virtual const char *renderName() const { return "RenderSelect"; }
void updateSelection();
- HTMLSelectElement *element() const
- { return static_cast<HTMLSelectElement*>(RenderObject::element()); }
-
protected:
QListBox *createListBox();
void setWidgetWritingDirection();
class RenderTextArea : public RenderFormElement
{
public:
- RenderTextArea(HTMLTextAreaElement *element);
+ RenderTextArea(HTMLTextAreaElement*);
virtual void destroy();
bool isEdited() const { return m_dirty; }
void setEdited (bool);
- // don't even think about making this method virtual!
- HTMLTextAreaElement* element() const
- { return static_cast<HTMLTextAreaElement*>(RenderObject::element()); }
-
String text();
String textWithHardLineBreaks();
class RenderSlider : public RenderFormElement
{
public:
- RenderSlider(HTMLInputElement *element);
+ RenderSlider(HTMLInputElement*);
- HTMLInputElement* element() const
- { return static_cast<HTMLInputElement*>(RenderObject::element()); }
-
virtual const char *renderName() const { return "RenderSlider"; }
virtual bool canHaveIntrinsicMargins() const { return true; }
virtual void calcMinMaxWidth();