Changeset 60985 in webkit


Ignore:
Timestamp:
Jun 10, 2010 5:51:36 PM (14 years ago)
Author:
jhawkins@chromium.org
Message:

2010-06-09 James Hawkins <jhawkins@chromium.org>

Reviewed by Darin Fisher.

[Chromium] Add the ability to specify a separator in
AutoFillPopupMenuClient.

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

  • public/WebViewClient.h: (WebKit::WebViewClient::didAcceptAutoFillSuggestion):
  • src/AutoFillPopupMenuClient.cpp: (WebKit::AutoFillPopupMenuClient::getSuggestionsCount): (WebKit::AutoFillPopupMenuClient::getSuggestion): (WebKit::AutoFillPopupMenuClient::valueChanged): (WebKit::AutoFillPopupMenuClient::selectionChanged): (WebKit::AutoFillPopupMenuClient::itemIsSeparator): (WebKit::AutoFillPopupMenuClient::initialize): (WebKit::AutoFillPopupMenuClient::setSuggestions):
  • src/AutoFillPopupMenuClient.h:
  • src/WebViewImpl.cpp: (WebKit::WebViewImpl::applyAutoFillSuggestions):
  • src/WebViewImpl.h:
Location:
trunk/WebKit/chromium
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r60977 r60985  
     12010-06-09  James Hawkins  <jhawkins@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [Chromium] Add the ability to specify a separator in
     6        AutoFillPopupMenuClient.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=40397
     9
     10        * public/WebViewClient.h:
     11        (WebKit::WebViewClient::didAcceptAutoFillSuggestion):
     12        * src/AutoFillPopupMenuClient.cpp:
     13        (WebKit::AutoFillPopupMenuClient::getSuggestionsCount):
     14        (WebKit::AutoFillPopupMenuClient::getSuggestion):
     15        (WebKit::AutoFillPopupMenuClient::valueChanged):
     16        (WebKit::AutoFillPopupMenuClient::selectionChanged):
     17        (WebKit::AutoFillPopupMenuClient::itemIsSeparator):
     18        (WebKit::AutoFillPopupMenuClient::initialize):
     19        (WebKit::AutoFillPopupMenuClient::setSuggestions):
     20        * src/AutoFillPopupMenuClient.h:
     21        * src/WebViewImpl.cpp:
     22        (WebKit::WebViewImpl::applyAutoFillSuggestions):
     23        * src/WebViewImpl.h:
     24
    1252010-06-10  Dmitry Titov  <dimich@chromium.org>
    226
  • trunk/WebKit/chromium/public/WebViewClient.h

    r60934 r60985  
    277277
    278278
    279     // Autofill ------------------------------------------------------------
     279    // AutoFill ------------------------------------------------------------
    280280
    281281    // Queries the browser for suggestions to be shown for the form text
     
    286286                                          const WebString& value) { }
    287287
    288     // Instructs the browser to remove the autofill entry specified from
     288    // Instructs the browser to remove the Autocomplete entry specified from
    289289    // its DB.
     290    // FIXME: This method should be named removeAutocompleteSugestion.
    290291    virtual void removeAutofillSuggestions(const WebString& name,
    291292                                           const WebString& value) { }
     
    293294    // Informs the browser that the user has accepted an AutoFill suggestion for
    294295    // a WebNode.  |name| and |label| form a key into the set of AutoFill
    295     // profiles.
     296    // profiles.  |index| is an index of the selected suggestion in the list of
     297    // suggestions provided by the client
    296298    virtual void didAcceptAutoFillSuggestion(const WebNode&,
    297299                                             const WebString& name,
    298                                              const WebString& label) { }
     300                                             const WebString& label,
     301                                             unsigned index) { }
    299302
    300303    // Informs the browser that the user has selected an AutoFill suggestion for
  • trunk/WebKit/chromium/src/AutoFillPopupMenuClient.cpp

    r60514 r60985  
    4545unsigned AutoFillPopupMenuClient::getSuggestionsCount() const
    4646{
    47     return m_names.size();
     47    return m_names.size() + ((m_separatorIndex == -1) ? 0 : 1);
    4848}
    4949
    5050WebString AutoFillPopupMenuClient::getSuggestion(unsigned listIndex) const
    5151{
     52    if (listIndex == m_separatorIndex)
     53        return WebString();
     54
     55    if (m_separatorIndex != -1 && listIndex > m_separatorIndex)
     56        --listIndex;
     57
    5258    // FIXME: Modify the PopupMenu to add the label in gray right-justified.
    5359    ASSERT(listIndex >= 0 && listIndex < m_names.size());
    54     return m_names[listIndex] + String(" (") + m_labels[listIndex] + String(")");
     60
     61    WebString suggestion = m_names[listIndex];
     62    if (m_labels[listIndex].isEmpty())
     63        return suggestion;
     64
     65    return suggestion + String(" (") + m_labels[listIndex] + String(")");
    5566}
    5667
     
    6576void AutoFillPopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents)
    6677{
    67     ASSERT(listIndex >= 0 && listIndex < m_names.size());
    68 
    6978    WebViewImpl* webView = getWebView();
    7079    if (!webView)
    7180        return;
    7281
     82    if (m_separatorIndex != -1 && listIndex > m_separatorIndex)
     83        --listIndex;
     84
     85    ASSERT(listIndex >= 0 && listIndex < m_names.size());
     86
    7387    webView->client()->didAcceptAutoFillSuggestion(WebNode(getTextField()),
    7488                                                   m_names[listIndex],
    75                                                    m_labels[listIndex]);
     89                                                   m_labels[listIndex],
     90                                                   listIndex);
    7691}
    7792
    7893void AutoFillPopupMenuClient::selectionChanged(unsigned listIndex, bool fireEvents)
    7994{
    80     ASSERT(listIndex >= 0 && listIndex < m_names.size());
    81 
    8295    WebViewImpl* webView = getWebView();
    8396    if (!webView)
    8497        return;
     98
     99    if (m_separatorIndex != -1 && listIndex > m_separatorIndex)
     100        --listIndex;
     101
     102    ASSERT(listIndex >= 0 && listIndex < m_names.size());
    85103
    86104    webView->client()->didSelectAutoFillSuggestion(WebNode(getTextField()),
     
    93111    WebViewImpl* webView = getWebView();
    94112    if (!webView)
    95       return;
     113        return;
    96114
    97115    webView->client()->didClearAutoFillSelection(WebNode(getTextField()));
     
    104122    WebViewImpl* webView = getWebView();
    105123    if (!webView)
    106       return;
     124        return;
    107125
    108126    webView->client()->didClearAutoFillSelection(WebNode(getTextField()));
     127}
     128
     129bool AutoFillPopupMenuClient::itemIsSeparator(unsigned listIndex) const
     130{
     131    return (m_separatorIndex != -1 && m_separatorIndex == listIndex);
    109132}
    110133
     
    113136    const WebVector<WebString>& names,
    114137    const WebVector<WebString>& labels,
    115     int defaultSuggestionIndex)
     138    int separatorIndex)
    116139{
    117140    ASSERT(names.size() == labels.size());
    118     ASSERT(defaultSuggestionIndex < static_cast<int>(names.size()));
     141    ASSERT(separatorIndex < static_cast<int>(names.size()));
    119142
    120143    // The suggestions must be set before initializing the
    121144    // SuggestionsPopupMenuClient.
    122     setSuggestions(names, labels);
     145    setSuggestions(names, labels, separatorIndex);
    123146
    124     SuggestionsPopupMenuClient::initialize(textField, defaultSuggestionIndex);
     147    SuggestionsPopupMenuClient::initialize(textField, -1);
    125148}
    126149
    127150void AutoFillPopupMenuClient::setSuggestions(const WebVector<WebString>& names,
    128                                              const WebVector<WebString>& labels)
     151                                             const WebVector<WebString>& labels,
     152                                             int separatorIndex)
    129153{
    130154    ASSERT(names.size() == labels.size());
     155    ASSERT(separatorIndex < static_cast<int>(names.size()));
    131156
    132157    m_names.clear();
     
    137162    }
    138163
     164    m_separatorIndex = separatorIndex;
     165
    139166    // Try to preserve selection if possible.
    140167    if (getSelectedIndex() >= static_cast<int>(names.size()))
  • trunk/WebKit/chromium/src/AutoFillPopupMenuClient.h

    r60514 r60985  
    5656    virtual void selectionCleared();
    5757    virtual void popupDidHide();
     58    virtual bool itemIsSeparator(unsigned listIndex) const;
    5859
    5960    void initialize(WebCore::HTMLInputElement*,
    6061                    const WebVector<WebString>& names,
    6162                    const WebVector<WebString>& labels,
    62                     int defaultSuggestionIndex);
     63                    int separatorIndex);
    6364
    6465    void setSuggestions(const WebVector<WebString>& names,
    65                         const WebVector<WebString>& labels);
     66                        const WebVector<WebString>& labels,
     67                        int separatorIndex);
    6668
    6769private:
    6870    Vector<WebCore::String> m_names;
    6971    Vector<WebCore::String> m_labels;
     72
     73    // The index of the separator.  -1 if there is no separator.
     74    int m_separatorIndex;
    7075};
    7176
  • trunk/WebKit/chromium/src/WebViewImpl.cpp

    r60651 r60985  
    17871787    const WebVector<WebString>& names,
    17881788    const WebVector<WebString>& labels,
    1789     int defaultSuggestionIndex)
     1789    int separatorIndex)
    17901790{
    17911791    ASSERT(names.size() == labels.size());
    1792     ASSERT(defaultSuggestionIndex < static_cast<int>(names.size()));
     1792    ASSERT(separatorIndex < static_cast<int>(names.size()));
    17931793
    17941794    if (names.isEmpty()) {
     
    18151815
    18161816    m_autoFillPopupClient->initialize(inputElem, names, labels,
    1817                                       defaultSuggestionIndex);
     1817                                      separatorIndex);
    18181818
    18191819    if (m_suggestionsPopupClient != m_autoFillPopupClient.get()) {
     
    18321832
    18331833    if (m_suggestionsPopupShowing) {
    1834         m_autoFillPopupClient->setSuggestions(names, labels);
     1834        m_autoFillPopupClient->setSuggestions(names, labels, separatorIndex);
    18351835        refreshSuggestionsPopup();
    18361836    } else {
  • trunk/WebKit/chromium/src/WebViewImpl.h

    r60651 r60985  
    167167        const WebVector<WebString>& names,
    168168        const WebVector<WebString>& labels,
    169         int defaultSuggestionIndex);
     169        int separatorIndex);
    170170    virtual void applyAutocompleteSuggestions(
    171171        const WebNode&,
Note: See TracChangeset for help on using the changeset viewer.