Commit 7157c6d7 authored by timothy@apple.com's avatar timothy@apple.com
Browse files

WebCore: Expose a function to set the value of an input element on behalf of the user.

This function will dispatch the change event so the page is notified when autofill
happens. Also dispatch a change event when a select element is changed by autofill.

<rdar://problem/6760590> Would like a way to detect a login form AutoFill from JavaScript

Reviewed by Darin Adler.

* WebCore.xcodeproj/project.pbxproj: Added the DOMHTMLInputElementPrivate.h header.
* bindings/objc/DOMHTML.mm:
(-[DOMHTMLSelectElement _activateItemAtIndex:]): Call setSelectedIndexByUser instead so
a change event is fired. This method is called by Safari autofill.
* dom/Document.cpp:
(WebCore::Document::setFocusedNode): Use dispatchFormControlChangeEvent instead
of dispatching the change event directly to be consistent.
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLInputElement::setValueForUser): Added. Calls setValue with the sendChangeEvent
(WebCore::HTMLInputElement::setValue): Added the optional sendChangeEvent argument. Mimics setChecked.
* html/HTMLInputElement.h:
* html/HTMLInputElement.idl: Added setValueForUser for non-JS languages.
* html/InputElement.h: Added setValueForUser.

WebKit/mac: Migrate DOMHTMLInputElementPrivate.h as a private header.

Reviewed by Darin Adler.

* MigrateHeaders.make:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51602 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6cc49d07
2009-11-13 Timothy Hatcher <timothy@apple.com>
Expose a function to set the value of an input element on behalf of the user.
This function will dispatch the change event so the page is notified when autofill
happens. Also dispatch a change event when a select element is changed by autofill.
<rdar://problem/6760590> Would like a way to detect a login form AutoFill from JavaScript
Reviewed by Darin Adler.
* WebCore.xcodeproj/project.pbxproj: Added the DOMHTMLInputElementPrivate.h header.
* bindings/objc/DOMHTML.mm:
(-[DOMHTMLSelectElement _activateItemAtIndex:]): Call setSelectedIndexByUser instead so
a change event is fired. This method is called by Safari autofill.
* dom/Document.cpp:
(WebCore::Document::setFocusedNode): Use dispatchFormControlChangeEvent instead
of dispatching the change event directly to be consistent.
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLInputElement::setValueForUser): Added. Calls setValue with the sendChangeEvent
(WebCore::HTMLInputElement::setValue): Added the optional sendChangeEvent argument. Mimics setChecked.
* html/HTMLInputElement.h:
* html/HTMLInputElement.idl: Added setValueForUser for non-JS languages.
* html/InputElement.h: Added setValueForUser.
2009-12-02 Pavel Feldman <pfeldman@dhcp-172-28-174-220.spb.corp.google.com>
 
Reviewed by Timothy Hatcher.
......@@ -544,6 +544,7 @@
1CB4214B0AF2B2CA0085AD91 /* DOMElementInternal.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 85E711490AC5D5340053270F /* DOMElementInternal.h */; };
1CB4214C0AF2B2CA0085AD91 /* DOMHTMLElementInternal.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 85E711580AC5D5340053270F /* DOMHTMLElementInternal.h */; };
1CB4214D0AF2B2CA0085AD91 /* DOMRangeInternal.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 8538F05A0AD722F1006A81D1 /* DOMRangeInternal.h */; };
1CCA732210ADD44A00FD440D /* DOMHTMLInputElementPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 1CCA732110ADD43E00FD440D /* DOMHTMLInputElementPrivate.h */; };
1CDC14050DD3934C006EACD3 /* localizedStrings.js in Resources */ = {isa = PBXBuildFile; fileRef = BCC64F5F0DCFB84E0081EF3B /* localizedStrings.js */; };
1CE24F970D7CAF0E007E04C2 /* SchedulePairMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CE24F960D7CAF0E007E04C2 /* SchedulePairMac.mm */; };
1CE83AC30ADAFFD7009354F6 /* DeleteButtonController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C4C8EFF0AD85D87009475CE /* DeleteButtonController.cpp */; };
......@@ -4810,6 +4811,7 @@
dstPath = Versions/A/PrivateHeaders;
dstSubfolderSpec = 1;
files = (
1CCA732210ADD44A00FD440D /* DOMHTMLInputElementPrivate.h in Copy Generated Headers */,
5DF7F5C20F01F92A00526B4B /* CSSPropertyNames.h in Copy Generated Headers */,
8538F0300AD71CDB006A81D1 /* DOMAbstractView.h in Copy Generated Headers */,
1C11CCBC0AA6093700DADB20 /* DOMAttr.h in Copy Generated Headers */,
......@@ -5774,6 +5776,7 @@
1CAF347E0A6C405200ABE06E /* WebScriptObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObject.h; sourceTree = "<group>"; };
1CAF347F0A6C405200ABE06E /* WebScriptObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptObject.mm; sourceTree = "<group>"; };
1CAF34800A6C405200ABE06E /* WebScriptObjectPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObjectPrivate.h; sourceTree = "<group>"; };
1CCA732110ADD43E00FD440D /* DOMHTMLInputElementPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMHTMLInputElementPrivate.h; sourceTree = "<group>"; };
1CD0B6200AABDB5000D0A3FF /* PublicDOMInterfaces.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicDOMInterfaces.h; sourceTree = "<group>"; };
1CDD45E40BA9C84600F90147 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; };
1CDD45E50BA9C84600F90147 /* WebCore.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebCore.xcconfig; sourceTree = "<group>"; };
......@@ -12066,6 +12069,7 @@
85DF81230AA7787200486AD7 /* DOMHTMLImageElement.h */,
85DF81240AA7787200486AD7 /* DOMHTMLImageElement.mm */,
85F32AE40AA63B8700FF3184 /* DOMHTMLInputElement.h */,
1CCA732110ADD43E00FD440D /* DOMHTMLInputElementPrivate.h */,
85F32AE50AA63B8700FF3184 /* DOMHTMLInputElement.mm */,
859A9C410AA5E3BD00B694B2 /* DOMHTMLIsIndexElement.h */,
859A9C420AA5E3BD00B694B2 /* DOMHTMLIsIndexElement.mm */,
......@@ -156,8 +156,9 @@
- (void)_activateItemAtIndex:(int)index
{
// Use the setSelectedIndexByUser function so a change event will be fired. <rdar://problem/6760590>
if (WebCore::HTMLSelectElement* select = core(self))
select->setSelectedIndex(index);
select->setSelectedIndexByUser(index, true, true);
}
@end
......
......@@ -2662,11 +2662,11 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode)
oldFocusedNode->setActive(false);
oldFocusedNode->setFocus(false);
// Dispatch a change event for text fields or textareas that have been edited
RenderObject* r = oldFocusedNode->renderer();
if (r && r->isTextControl() && toRenderTextControl(r)->wasChangedSinceLastChangeEvent()) {
oldFocusedNode->dispatchEvent(Event::create(eventNames().changeEvent, true, false));
static_cast<Element*>(oldFocusedNode.get())->dispatchFormControlChangeEvent();
r = oldFocusedNode->renderer();
if (r && r->isTextControl())
toRenderTextControl(r)->setChangedSinceLastChangeEvent(false);
......
......@@ -48,7 +48,8 @@ public:
virtual int size() const = 0;
virtual String value() const = 0;
virtual void setValue(const String&) = 0;
virtual void setValue(const String&, bool sendChangeEvent = false) = 0;
virtual void setValueForUser(const String&) = 0;
virtual String sanitizeValue(const String&) const = 0;
virtual void setValueFromRenderer(const String&) = 0;
......
......@@ -1247,7 +1247,13 @@ String HTMLInputElement::valueWithDefault() const
return v;
}
void HTMLInputElement::setValue(const String& value)
void HTMLInputElement::setValueForUser(const String& value)
{
// Call setValue and make it send a change event.
setValue(value, true);
}
void HTMLInputElement::setValue(const String& value, bool sendChangeEvent)
{
// For security reasons, we don't allow setting the filename, but we do allow clearing it.
// The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't applicable to the file upload control
......@@ -1272,7 +1278,7 @@ void HTMLInputElement::setValue(const String& value)
setNeedsStyleRecalc();
} else
setAttribute(valueAttr, sanitizeValue(value));
if (isTextField()) {
unsigned max = m_data.value().length();
if (document()->focusedNode() == this)
......@@ -1280,6 +1286,12 @@ void HTMLInputElement::setValue(const String& value)
else
cacheSelection(max, max);
}
// Don't dispatch the change event when focused, it will be dispatched
// when the control loses focus.
if (sendChangeEvent && document()->focusedNode() != this)
dispatchFormControlChangeEvent();
InputElement::notifyFormStateChanged(this);
updateValidity();
}
......
......@@ -133,7 +133,8 @@ public:
void setType(const String&);
virtual String value() const;
virtual void setValue(const String&);
virtual void setValue(const String&, bool sendChangeEvent = false);
virtual void setValueForUser(const String&);
virtual String placeholder() const;
virtual void setPlaceholder(const String&);
......
......@@ -77,7 +77,11 @@ module html {
void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error);
void select();
void click();
#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT
void setValueForUser(in [ConvertNullToNullString] DOMString value);
#endif
// WinIE extension:
attribute boolean indeterminate;
......
2009-11-13 Timothy Hatcher <timothy@apple.com>
Migrate DOMHTMLInputElementPrivate.h as a private header.
Reviewed by Darin Adler.
* MigrateHeaders.make:
2009-12-01 Nikolas Zimmermann <nzimmermann@rim.com>
 
Reviewed by Simon Fraser.
......
......@@ -106,6 +106,7 @@ all : \
$(PUBLIC_HEADERS_DIR)/DOMHTMLIFrameElement.h \
$(PUBLIC_HEADERS_DIR)/DOMHTMLImageElement.h \
$(PUBLIC_HEADERS_DIR)/DOMHTMLInputElement.h \
$(PRIVATE_HEADERS_DIR)/DOMHTMLInputElementPrivate.h \
$(INTERNAL_HEADERS_DIR)/DOMHTMLInputElementInternal.h \
$(PUBLIC_HEADERS_DIR)/DOMHTMLIsIndexElement.h \
$(PUBLIC_HEADERS_DIR)/DOMHTMLLIElement.h \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment