Add client callbacks to notify of changes of associated from controls

https://bugs.webkit.org/show_bug.cgi?id=110375

Patch by Dane Wallinga <dgwallinga@chromium.org> on 2013-03-22
Reviewed by Ryosuke Niwa.

Source/WebCore:

Hook FormAssociatedElement, HTMLFormElement to notify EditorClient of form changes after a page has loaded.
Will be used to add autofill support for ajax-y webpages. e.g if while filling out a form, new fields
are dynamically created, autofill can know to re-query the autofill server and keep going.
https://bugs.webkit.org/show_bug.cgi?id=110375

* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::didAssociateFormControl):
(WebCore):
(WebCore::Document::didAssociateFormControlsTimerFired):
* dom/Document.h:
(Document):
added method didAssociateFormControl, which batches form changes
and calls out to ChromeClient on a timer.
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::resetFormOwner):
(WebCore::FormAssociatedElement::formAttributeChanged):
(WebCore):
* html/FormAssociatedElement.h:
(FormAssociatedElement):
add calls to Document::didAssociateFormControl when form changes
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::insertedInto):
(WebCore):
* html/HTMLFormElement.h:
add call to Document::didAssociateFormControl
* loader/EmptyClients.h:
(EmptyChromeClient):
(WebCore::EmptyChromeClient::didAssociateFormControls):
(WebCore::EmptyChromeClient::shouldNotifyOnFormChanges):
* page/ChromeClient.h:
(ChromeClient):
add new method didAssociateFormControls

Source/WebKit/chromium:

Implement form association methods of ChromeClient
to inform autofill of form changes after a page has loaded

* public/WebAutofillClient.h:
(WebAutofillClient):
(WebKit::WebAutofillClient::didAssociateInput):
(WebKit::WebAutofillClient::didAddForm):
(WebKit::WebAutofillClient::didAssociateFormControls):
* src/ChromeClientImpl.cpp:
(WebKit::ChromeClientImpl::didAssociateFormControls):
(WebKit):
(WebKit::ChromeClientImpl::shouldNotifyOnFormChanges):
* src/ChromeClientImpl.h:
(ChromeClientImpl):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@146672 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9e72d68b
2013-03-22 Dane Wallinga <dgwallinga@chromium.org>
Add client callbacks to notify of changes of associated from controls
https://bugs.webkit.org/show_bug.cgi?id=110375
Reviewed by Ryosuke Niwa.
Hook FormAssociatedElement, HTMLFormElement to notify EditorClient of form changes after a page has loaded.
Will be used to add autofill support for ajax-y webpages. e.g if while filling out a form, new fields
are dynamically created, autofill can know to re-query the autofill server and keep going.
https://bugs.webkit.org/show_bug.cgi?id=110375
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::didAssociateFormControl):
(WebCore):
(WebCore::Document::didAssociateFormControlsTimerFired):
* dom/Document.h:
(Document):
added method didAssociateFormControl, which batches form changes
and calls out to ChromeClient on a timer.
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::resetFormOwner):
(WebCore::FormAssociatedElement::formAttributeChanged):
(WebCore):
* html/FormAssociatedElement.h:
(FormAssociatedElement):
add calls to Document::didAssociateFormControl when form changes
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::insertedInto):
(WebCore):
* html/HTMLFormElement.h:
add call to Document::didAssociateFormControl
* loader/EmptyClients.h:
(EmptyChromeClient):
(WebCore::EmptyChromeClient::didAssociateFormControls):
(WebCore::EmptyChromeClient::shouldNotifyOnFormChanges):
* page/ChromeClient.h:
(ChromeClient):
add new method didAssociateFormControls
2013-03-22 Alexey Proskuryakov <ap@apple.com>
Split ResourceHandleMac into multiple files
......@@ -496,6 +496,7 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
#if ENABLE(FONT_LOAD_EVENTS)
, m_fontloader(0)
#endif
, m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsTimerFired)
{
m_printing = false;
m_paginatedForScreen = false;
......@@ -6160,4 +6161,26 @@ PassRefPtr<FontLoader> Document::fontloader()
}
#endif
void Document::didAssociateFormControl(Element* element)
{
if (!frame() || !frame()->page() || !frame()->page()->chrome()->client()->shouldNotifyOnFormChanges())
return;
m_associatedFormControls.add(element);
if (!m_didAssociateFormControlsTimer.isActive())
m_didAssociateFormControlsTimer.startOneShot(0);
}
void Document::didAssociateFormControlsTimerFired(Timer<Document>* timer)
{
ASSERT_UNUSED(timer, timer == &m_didAssociateFormControlsTimer);
if (!frame() || !frame()->page())
return;
Vector<Element*> associatedFormControls;
copyToVector(m_associatedFormControls, associatedFormControls);
frame()->page()->chrome()->client()->didAssociateFormControls(associatedFormControls);
m_associatedFormControls.clear();
}
} // namespace WebCore
......@@ -52,6 +52,7 @@
#include "ViewportArguments.h"
#include <wtf/Deque.h>
#include <wtf/FixedArray.h>
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
......@@ -1209,6 +1210,8 @@ public:
Document* templateDocumentHost() { return m_templateDocumentHost; }
#endif
void didAssociateFormControl(Element*);
virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0);
virtual const SecurityOrigin* topOrigin() const OVERRIDE;
......@@ -1297,6 +1300,8 @@ private:
void addListenerType(ListenerType listenerType) { m_listenerTypes |= listenerType; }
void addMutationEventListenerTypeIfEnabled(ListenerType);
void didAssociateFormControlsTimerFired(Timer<Document>*);
void styleResolverThrowawayTimerFired(Timer<Document>*);
Timer<Document> m_styleResolverThrowawayTimer;
double m_lastStyleResolverAccessTime;
......@@ -1592,6 +1597,10 @@ private:
#if ENABLE(FONT_LOAD_EVENTS)
RefPtr<FontLoader> m_fontloader;
#endif
Timer<Document> m_didAssociateFormControlsTimer;
HashSet<Element*> m_associatedFormControls;
};
inline void Document::notifyRemovePendingSheetIfNeeded()
......
......@@ -25,7 +25,9 @@
#include "config.h"
#include "FormAssociatedElement.h"
#include "EditorClient.h"
#include "FormController.h"
#include "Frame.h"
#include "HTMLFormControlElement.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
......@@ -157,7 +159,11 @@ void FormAssociatedElement::formWillBeDestroyed()
void FormAssociatedElement::resetFormOwner()
{
HTMLFormElement* originalForm = m_form;
setForm(findAssociatedForm(toHTMLElement(this), m_form));
HTMLElement* element = toHTMLElement(this);
if (m_form && m_form != originalForm && m_form->inDocument())
element->document()->didAssociateFormControl(element);
}
void FormAssociatedElement::formAttributeChanged()
......@@ -165,7 +171,11 @@ void FormAssociatedElement::formAttributeChanged()
HTMLElement* element = toHTMLElement(this);
if (!element->fastHasAttribute(formAttr)) {
// The form attribute removed. We need to reset form owner here.
HTMLFormElement* originalForm = m_form;
setForm(element->findFormAncestor());
HTMLElement* element = toHTMLElement(this);
if (m_form && m_form != originalForm && m_form->inDocument())
element->document()->didAssociateFormControl(element);
m_formAttributeTargetObserver = nullptr;
} else {
resetFormOwner();
......
......@@ -139,6 +139,8 @@ bool HTMLFormElement::rendererIsNeeded(const NodeRenderingContext& context)
Node::InsertionNotificationRequest HTMLFormElement::insertedInto(ContainerNode* insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
if (insertionPoint->inDocument())
this->document()->didAssociateFormControl(this);
return InsertionDone;
}
......
......@@ -208,6 +208,9 @@ public:
virtual bool shouldRubberBandInDirection(WebCore::ScrollDirection) const { return false; }
virtual bool isEmptyChromeClient() const { return true; }
virtual void didAssociateFormControls(const Vector<Element*>&) { }
virtual bool shouldNotifyOnFormChanges() { return false; }
};
class EmptyFrameLoaderClient : public FrameLoaderClient {
......
......@@ -382,6 +382,9 @@ public:
// FIXME: Port should return true using heuristic based on scrollable(RenderBox).
virtual bool shouldAutoscrollForDragAndDrop(RenderBox*) const { return false; }
virtual void didAssociateFormControls(const Vector<Element*>&) { };
virtual bool shouldNotifyOnFormChanges() { return false; };
protected:
virtual ~ChromeClient() { }
};
......
2013-03-22 Dane Wallinga <dgwallinga@chromium.org>
Add client callbacks to notify of changes of associated from controls
https://bugs.webkit.org/show_bug.cgi?id=110375
Reviewed by Ryosuke Niwa.
Implement form association methods of ChromeClient
to inform autofill of form changes after a page has loaded
* public/WebAutofillClient.h:
(WebAutofillClient):
(WebKit::WebAutofillClient::didAssociateInput):
(WebKit::WebAutofillClient::didAddForm):
(WebKit::WebAutofillClient::didAssociateFormControls):
* src/ChromeClientImpl.cpp:
(WebKit::ChromeClientImpl::didAssociateFormControls):
(WebKit):
(WebKit::ChromeClientImpl::shouldNotifyOnFormChanges):
* src/ChromeClientImpl.h:
(ChromeClientImpl):
2013-03-22 Alec Flett <alecflett@chromium.org>
[chromium] Support Quota API in Worker
......
......@@ -40,6 +40,8 @@ class WebKeyboardEvent;
class WebNode;
class WebString;
template <typename T> class WebVector;
class WebAutofillClient {
public:
enum {
......@@ -93,6 +95,8 @@ public:
// Informs the client whether or not any subsequent text changes should be ignored.
virtual void setIgnoreTextChanges(bool ignore) { }
virtual void didAssociateFormControls(const WebVector<WebNode>&) { }
protected:
virtual ~WebAutofillClient() { }
};
......
......@@ -77,6 +77,7 @@
#include "Settings.h"
#include "TextFieldDecorationElement.h"
#include "WebAccessibilityObject.h"
#include "WebAutofillClient.h"
#if ENABLE(INPUT_TYPE_COLOR)
#include "WebColorChooser.h"
#endif
......@@ -1144,6 +1145,22 @@ void ChromeClientImpl::annotatedRegionsChanged()
}
#endif
void ChromeClientImpl::didAssociateFormControls(const Vector<Element*>& elements)
{
if (!m_webView->autofillClient())
return;
WebVector<WebNode> elementVector(static_cast<size_t>(elements.size()));
size_t elementsCount = elements.size();
for (size_t i = 0; i < elementsCount; ++i)
elementVector[i] = elements[i];
m_webView->autofillClient()->didAssociateFormControls(elementVector);
}
bool ChromeClientImpl::shouldNotifyOnFormChanges()
{
return true;
}
#if ENABLE(NAVIGATOR_CONTENT_UTILS)
PassOwnPtr<NavigatorContentUtilsClientImpl> NavigatorContentUtilsClientImpl::create(WebViewImpl* webView)
{
......
......@@ -234,6 +234,9 @@ public:
virtual bool isPointerLocked();
#endif
virtual void didAssociateFormControls(const Vector<WebCore::Element*>&) OVERRIDE;
virtual bool shouldNotifyOnFormChanges() OVERRIDE;
private:
WebNavigationPolicy getNavigationPolicy();
void getPopupMenuInfo(WebCore::PopupContainer*, WebPopupMenuInfo*);
......
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