Changeset 146672 in webkit


Ignore:
Timestamp:
Mar 22, 2013 4:11:59 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

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):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r146667 r146672  
     12013-03-22  Dane Wallinga  <dgwallinga@chromium.org>
     2
     3        Add client callbacks to notify of changes of associated from controls
     4        https://bugs.webkit.org/show_bug.cgi?id=110375
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Hook FormAssociatedElement, HTMLFormElement to notify EditorClient of form changes after a page has loaded.
     9        Will be used to add autofill support for ajax-y webpages. e.g if while filling out a form, new fields
     10        are dynamically created, autofill can know to re-query the autofill server and keep going.
     11        https://bugs.webkit.org/show_bug.cgi?id=110375
     12
     13        * dom/Document.cpp:
     14        (WebCore::Document::Document):
     15        (WebCore::Document::didAssociateFormControl):
     16        (WebCore):
     17        (WebCore::Document::didAssociateFormControlsTimerFired):
     18        * dom/Document.h:
     19        (Document):
     20        added method didAssociateFormControl, which batches form changes
     21        and calls out to ChromeClient on a timer.
     22        * html/FormAssociatedElement.cpp:
     23        (WebCore::FormAssociatedElement::resetFormOwner):
     24        (WebCore::FormAssociatedElement::formAttributeChanged):
     25        (WebCore):
     26        * html/FormAssociatedElement.h:
     27        (FormAssociatedElement):
     28        add calls to Document::didAssociateFormControl when form changes
     29        * html/HTMLFormElement.cpp:
     30        (WebCore::HTMLFormElement::insertedInto):
     31        (WebCore):
     32        * html/HTMLFormElement.h:
     33        add call to Document::didAssociateFormControl
     34        * loader/EmptyClients.h:
     35        (EmptyChromeClient):
     36        (WebCore::EmptyChromeClient::didAssociateFormControls):
     37        (WebCore::EmptyChromeClient::shouldNotifyOnFormChanges):
     38        * page/ChromeClient.h:
     39        (ChromeClient):
     40        add new method didAssociateFormControls
     41
    1422013-03-22  Alexey Proskuryakov  <ap@apple.com>
    243
  • trunk/Source/WebCore/dom/Document.cpp

    r146583 r146672  
    497497    , m_fontloader(0)
    498498#endif
     499    , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsTimerFired)
    499500{
    500501    m_printing = false;
     
    61616162#endif
    61626163
     6164void Document::didAssociateFormControl(Element* element)
     6165{
     6166    if (!frame() || !frame()->page() || !frame()->page()->chrome()->client()->shouldNotifyOnFormChanges())
     6167        return;
     6168    m_associatedFormControls.add(element);
     6169    if (!m_didAssociateFormControlsTimer.isActive())
     6170        m_didAssociateFormControlsTimer.startOneShot(0);
     6171}
     6172
     6173void Document::didAssociateFormControlsTimerFired(Timer<Document>* timer)
     6174{
     6175    ASSERT_UNUSED(timer, timer == &m_didAssociateFormControlsTimer);
     6176    if (!frame() || !frame()->page())
     6177        return;
     6178
     6179    Vector<Element*> associatedFormControls;
     6180    copyToVector(m_associatedFormControls, associatedFormControls);
     6181
     6182    frame()->page()->chrome()->client()->didAssociateFormControls(associatedFormControls);
     6183    m_associatedFormControls.clear();
     6184}
     6185
    61636186} // namespace WebCore
  • trunk/Source/WebCore/dom/Document.h

    r146583 r146672  
    5353#include <wtf/Deque.h>
    5454#include <wtf/FixedArray.h>
     55#include <wtf/HashSet.h>
    5556#include <wtf/OwnPtr.h>
    5657#include <wtf/PassOwnPtr.h>
     
    12101211#endif
    12111212
     1213    void didAssociateFormControl(Element*);
     1214
    12121215    virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0);
    12131216
     
    12971300    void addListenerType(ListenerType listenerType) { m_listenerTypes |= listenerType; }
    12981301    void addMutationEventListenerTypeIfEnabled(ListenerType);
     1302
     1303    void didAssociateFormControlsTimerFired(Timer<Document>*);
    12991304
    13001305    void styleResolverThrowawayTimerFired(Timer<Document>*);
     
    15931598    RefPtr<FontLoader> m_fontloader;
    15941599#endif
     1600
     1601    Timer<Document> m_didAssociateFormControlsTimer;
     1602    HashSet<Element*> m_associatedFormControls;
     1603
    15951604};
    15961605
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

    r141002 r146672  
    2626#include "FormAssociatedElement.h"
    2727
     28#include "EditorClient.h"
    2829#include "FormController.h"
     30#include "Frame.h"
    2931#include "HTMLFormControlElement.h"
    3032#include "HTMLFormElement.h"
     
    158160void FormAssociatedElement::resetFormOwner()
    159161{
     162    HTMLFormElement* originalForm = m_form;
    160163    setForm(findAssociatedForm(toHTMLElement(this), m_form));
     164    HTMLElement* element = toHTMLElement(this);     
     165    if (m_form && m_form != originalForm && m_form->inDocument())
     166        element->document()->didAssociateFormControl(element);
    161167}
    162168
     
    166172    if (!element->fastHasAttribute(formAttr)) {
    167173        // The form attribute removed. We need to reset form owner here.
     174        HTMLFormElement* originalForm = m_form;
    168175        setForm(element->findFormAncestor());
     176        HTMLElement* element = toHTMLElement(this);
     177        if (m_form && m_form != originalForm && m_form->inDocument())
     178            element->document()->didAssociateFormControl(element);
    169179        m_formAttributeTargetObserver = nullptr;
    170180    } else {
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r146055 r146672  
    140140{
    141141    HTMLElement::insertedInto(insertionPoint);
     142    if (insertionPoint->inDocument())
     143        this->document()->didAssociateFormControl(this);
    142144    return InsertionDone;
    143145}
  • trunk/Source/WebCore/loader/EmptyClients.h

    r145914 r146672  
    209209   
    210210    virtual bool isEmptyChromeClient() const { return true; }
     211
     212    virtual void didAssociateFormControls(const Vector<Element*>&) { }
     213    virtual bool shouldNotifyOnFormChanges() { return false; }
    211214};
    212215
  • trunk/Source/WebCore/page/ChromeClient.h

    r145393 r146672  
    383383    virtual bool shouldAutoscrollForDragAndDrop(RenderBox*) const { return false; }
    384384
     385    virtual void didAssociateFormControls(const Vector<Element*>&) { };
     386    virtual bool shouldNotifyOnFormChanges() { return false; };
     387
    385388protected:
    386389    virtual ~ChromeClient() { }
  • trunk/Source/WebKit/chromium/ChangeLog

    r146633 r146672  
     12013-03-22  Dane Wallinga  <dgwallinga@chromium.org>
     2
     3        Add client callbacks to notify of changes of associated from controls
     4        https://bugs.webkit.org/show_bug.cgi?id=110375
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Implement form association methods of ChromeClient
     9        to inform autofill of form changes after a page has loaded
     10
     11        * public/WebAutofillClient.h:
     12        (WebAutofillClient):
     13        (WebKit::WebAutofillClient::didAssociateInput):
     14        (WebKit::WebAutofillClient::didAddForm):
     15        (WebKit::WebAutofillClient::didAssociateFormControls):
     16        * src/ChromeClientImpl.cpp:
     17        (WebKit::ChromeClientImpl::didAssociateFormControls):
     18        (WebKit):
     19        (WebKit::ChromeClientImpl::shouldNotifyOnFormChanges):
     20        * src/ChromeClientImpl.h:
     21        (ChromeClientImpl):
     22
    1232013-03-22  Alec Flett  <alecflett@chromium.org>
    224
  • trunk/Source/WebKit/chromium/public/WebAutofillClient.h

    r142927 r146672  
    4040class WebNode;
    4141class WebString;
     42
     43template <typename T> class WebVector;
    4244
    4345class WebAutofillClient {
     
    9496    virtual void setIgnoreTextChanges(bool ignore) { }
    9597
     98    virtual void didAssociateFormControls(const WebVector<WebNode>&) { }
     99
    96100protected:
    97101    virtual ~WebAutofillClient() { }
  • trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp

    r145562 r146672  
    7878#include "TextFieldDecorationElement.h"
    7979#include "WebAccessibilityObject.h"
     80#include "WebAutofillClient.h"
    8081#if ENABLE(INPUT_TYPE_COLOR)
    8182#include "WebColorChooser.h"
     
    11451146#endif
    11461147
     1148void ChromeClientImpl::didAssociateFormControls(const Vector<Element*>& elements)
     1149{
     1150    if (!m_webView->autofillClient())
     1151        return;
     1152    WebVector<WebNode> elementVector(static_cast<size_t>(elements.size()));
     1153    size_t elementsCount = elements.size();
     1154    for (size_t i = 0; i < elementsCount; ++i)
     1155        elementVector[i] = elements[i];
     1156    m_webView->autofillClient()->didAssociateFormControls(elementVector);
     1157}
     1158
     1159bool ChromeClientImpl::shouldNotifyOnFormChanges()
     1160{
     1161    return true;
     1162}
     1163
    11471164#if ENABLE(NAVIGATOR_CONTENT_UTILS)
    11481165PassOwnPtr<NavigatorContentUtilsClientImpl> NavigatorContentUtilsClientImpl::create(WebViewImpl* webView)
  • trunk/Source/WebKit/chromium/src/ChromeClientImpl.h

    r143917 r146672  
    235235#endif
    236236
     237    virtual void didAssociateFormControls(const Vector<WebCore::Element*>&) OVERRIDE;
     238    virtual bool shouldNotifyOnFormChanges() OVERRIDE;
     239
    237240private:
    238241    WebNavigationPolicy getNavigationPolicy();
Note: See TracChangeset for help on using the changeset viewer.