Changeset 52673 in webkit


Ignore:
Timestamp:
Dec 30, 2009 3:08:58 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-30 Zelidrag Hornung <zelidrag@chromium.org>

Reviewed by Dimitri Glazkov.

Autocomplete in Chromium now offers suggestions within the input element as a user
a) types text that produces some autocomplete suggestions, and
b) scrolls through suggested values in the menu
The suggested value is rendered but not exposed through JS unti the
user makes the final selection.

No new tests since this new functionality (autocomplete suggestions)
is intentionally hidden from everything else than renderer.

  • src/AutocompletePopupMenuClient.cpp: (WebKit::AutocompletePopupMenuClient::initialize): (WebKit::AutocompletePopupMenuClient::setInitialAutocompleteValue): (WebKit::AutocompletePopupMenuClient::selectionChanged): (WebKit::AutocompletePopupMenuClient::popupDidHide): (WebKit::AutocompletePopupMenuClient::setTextFromItem): (WebKit::AutocompletePopupMenuClient::resetLastFieldValue):
  • src/AutocompletePopupMenuClient.h:

2009-12-30 Zelidrag Hornung <zelidrag@chromium.org>

Reviewed by Dimitri Glazkov.

Added ability for PopupMenuClient to signal when
a) selection changed, and
b) weather suggested value should be accepted when popup menu closes

No new tests since this new functionality (autocomplete suggestions)
is intentionally hidden from everything else than renderer.

  • platform/PopupMenuClient.h:
  • platform/chromium/PopupMenuChromium.cpp: (WebCore::PopupContainer::hidePopup): (WebCore::PopupListBox::handleKeyEvent): (WebCore::PopupListBox::abandon): (WebCore::PopupListBox::acceptIndex): (WebCore::PopupListBox::selectIndex): (WebCore::PopupListBox::clearSelection): (WebCore::PopupListBox::hidePopup):
  • platform/gtk/PopupMenuGtk.cpp: (WebCore::PopupMenu::menuUnmapped):
  • platform/mac/PopupMenuMac.mm: (WebCore::PopupMenu::show):
  • platform/qt/QtFallbackWebPopup.cpp: (WebCore::QtFallbackWebPopup::hidePopup):
  • platform/win/PopupMenuWin.cpp: (WebCore::PopupMenu::hide):
  • platform/wx/PopupMenuWx.cpp: (WebCore::PopupMenu::OnMenuItemSelected):
  • rendering/RenderMenuList.cpp: (WebCore::RenderMenuList::popupDidHide):
  • rendering/RenderMenuList.h: (WebCore::RenderMenuList::selectionChanged):
  • rendering/RenderTextControlSingleLine.cpp: (WebCore::RenderTextControlSingleLine::popupDidHide):
  • rendering/RenderTextControlSingleLine.h: (WebCore::RenderTextControlSingleLine::selectionChanged):
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r52672 r52673  
     12009-12-30  Zelidrag Hornung  <zelidrag@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Added ability for PopupMenuClient to signal when
     6        a) selection changed, and
     7        b) weather suggested value should be accepted when popup menu closes
     8
     9        No new tests since this new functionality (autocomplete suggestions)
     10        is intentionally hidden from everything else than renderer.
     11
     12        * platform/PopupMenuClient.h:
     13        * platform/chromium/PopupMenuChromium.cpp:
     14        (WebCore::PopupContainer::hidePopup):
     15        (WebCore::PopupListBox::handleKeyEvent):
     16        (WebCore::PopupListBox::abandon):
     17        (WebCore::PopupListBox::acceptIndex):
     18        (WebCore::PopupListBox::selectIndex):
     19        (WebCore::PopupListBox::clearSelection):
     20        (WebCore::PopupListBox::hidePopup):
     21        * platform/gtk/PopupMenuGtk.cpp:
     22        (WebCore::PopupMenu::menuUnmapped):
     23        * platform/mac/PopupMenuMac.mm:
     24        (WebCore::PopupMenu::show):
     25        * platform/qt/QtFallbackWebPopup.cpp:
     26        (WebCore::QtFallbackWebPopup::hidePopup):
     27        * platform/win/PopupMenuWin.cpp:
     28        (WebCore::PopupMenu::hide):
     29        * platform/wx/PopupMenuWx.cpp:
     30        (WebCore::PopupMenu::OnMenuItemSelected):
     31        * rendering/RenderMenuList.cpp:
     32        (WebCore::RenderMenuList::popupDidHide):
     33        * rendering/RenderMenuList.h:
     34        (WebCore::RenderMenuList::selectionChanged):
     35        * rendering/RenderTextControlSingleLine.cpp:
     36        (WebCore::RenderTextControlSingleLine::popupDidHide):
     37        * rendering/RenderTextControlSingleLine.h:
     38        (WebCore::RenderTextControlSingleLine::selectionChanged):
     39
    1402009-12-30  Nate Chapin  <japhet@chromium.org>
    241
  • trunk/WebCore/platform/PopupMenuClient.h

    r48370 r52673  
    3838    virtual ~PopupMenuClient() {}
    3939    virtual void valueChanged(unsigned listIndex, bool fireEvents = true) = 0;
    40 
     40    virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) = 0;
    4141    virtual String itemText(unsigned listIndex) const = 0;
    4242    virtual String itemToolTip(unsigned listIndex) const = 0;
     
    5050    virtual int listSize() const = 0;
    5151    virtual int selectedIndex() const = 0;
    52     virtual void popupDidHide() = 0;
     52    virtual void popupDidHide(bool acceptSuggestions) = 0;
    5353    virtual bool itemIsSeparator(unsigned listIndex) const = 0;
    5454    virtual bool itemIsLabel(unsigned listIndex) const = 0;
  • trunk/WebCore/platform/chromium/PopupMenuChromium.cpp

    r52519 r52673  
    107107
    108108    // Hides the popup.
    109     void hidePopup();
     109    void hidePopup(bool acceptSuggestions);
    110110
    111111    // Updates our internal list to match the client.
     
    382382void PopupContainer::hidePopup()
    383383{
    384     listBox()->hidePopup();
     384    listBox()->hidePopup(true);
    385385}
    386386
     
    632632    case VKEY_RETURN:
    633633        if (m_selectedIndex == -1)  {
    634             hidePopup();
     634            hidePopup(false);
    635635            // Don't eat the enter if nothing is selected.
    636636            return false;
     
    885885    m_selectedIndex = m_originalIndex;
    886886
    887     hidePopup();
     887    hidePopup(false);
    888888
    889889    if (m_acceptedIndexOnAbandon >= 0) {
     
    918918        if (m_popupClient) {
    919919            // Enter pressed with no selection, just close the popup.
    920             hidePopup();
     920            hidePopup(false);
    921921        }
    922922        return;
     
    927927
    928928        // Hide ourselves first since valueChanged may have numerous side-effects.
    929         hidePopup();
     929        hidePopup(true);
    930930
    931931        // Tell the <select> PopupMenuClient what index was selected.
     
    945945
    946946        scrollToRevealSelection();
     947        m_popupClient->selectionChanged(m_selectedIndex);
    947948    }
    948949}
     
    10061007        invalidateRow(m_selectedIndex);
    10071008        m_selectedIndex = -1;
     1009        m_popupClient->selectionChanged(m_selectedIndex);
    10081010    }
    10091011}
     
    10731075}
    10741076
    1075 void PopupListBox::hidePopup()
     1077void PopupListBox::hidePopup(bool acceptSuggestions)
    10761078{
    10771079    if (parent()) {
     
    10811083    }
    10821084
    1083     m_popupClient->popupDidHide();
     1085    m_popupClient->popupDidHide(acceptSuggestions);
    10841086}
    10851087
  • trunk/WebCore/platform/gtk/PopupMenuGtk.cpp

    r52258 r52673  
    134134{
    135135    ASSERT(that->client());
    136     that->client()->popupDidHide();
     136    that->client()->popupDidHide(true);
    137137}
    138138
  • trunk/WebCore/platform/mac/PopupMenuMac.mm

    r52314 r52673  
    109109    if (numItems <= 0) {
    110110        if (client())
    111             client()->popupDidHide();
     111            client()->popupDidHide(true);
    112112        return;
    113113    }
     
    166166    if (client()) {
    167167        int newIndex = [m_popup.get() indexOfSelectedItem];
    168         client()->popupDidHide();
     168        client()->popupDidHide(true);
    169169
    170170        // Adjust newIndex for hidden first item.
  • trunk/WebCore/platform/qt/QtFallbackWebPopup.cpp

    r52223 r52673  
    104104
    105105    m_popupVisible = false;
    106     client()->popupDidHide();
     106    client()->popupDidHide(true);
    107107}
    108108
  • trunk/WebCore/platform/win/PopupMenuWin.cpp

    r52314 r52673  
    275275
    276276    if (client())
    277         client()->popupDidHide();
     277        client()->popupDidHide(true);
    278278
    279279    // Post a WM_NULL message to wake up the message pump if necessary.
  • trunk/WebCore/platform/wx/PopupMenuWx.cpp

    r48370 r52673  
    8989    if (client()) {
    9090        client()->valueChanged(event.GetId() - s_menuStartId);
    91         client()->popupDidHide();
     91        client()->popupDidHide(true);
    9292    }
    9393    // TODO: Do we need to call Disconnect here? Do we have a ref to the native window still?
  • trunk/WebCore/rendering/RenderMenuList.cpp

    r48370 r52673  
    428428}
    429429
    430 void RenderMenuList::popupDidHide()
     430void RenderMenuList::popupDidHide(bool)
    431431{
    432432    m_popupIsVisible = false;
  • trunk/WebCore/rendering/RenderMenuList.h

    r48370 r52673  
    8383    virtual int listSize() const;
    8484    virtual int selectedIndex() const;
    85     virtual void popupDidHide();
     85    virtual void popupDidHide(bool acceptSuggestions);
    8686    virtual bool itemIsSeparator(unsigned listIndex) const;
    8787    virtual bool itemIsLabel(unsigned listIndex) const;
     
    9191    virtual bool shouldPopOver() const { return !POPUP_MENU_PULLS_DOWN; }
    9292    virtual void valueChanged(unsigned listIndex, bool fireOnChange = true);
     93    virtual void selectionChanged(unsigned, bool) {}
    9394    virtual FontSelector* fontSelector() const;
    9495    virtual HostWindow* hostWindow() const;
  • trunk/WebCore/rendering/RenderTextControlSingleLine.cpp

    r52204 r52673  
    729729}
    730730
    731 void RenderTextControlSingleLine::popupDidHide()
     731void RenderTextControlSingleLine::popupDidHide(bool)
    732732{
    733733    m_searchPopupIsVisible = false;
  • trunk/WebCore/rendering/RenderTextControlSingleLine.h

    r48971 r52673  
    9999    // PopupMenuClient methods
    100100    virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
     101    virtual void selectionChanged(unsigned, bool) {}
    101102    virtual String itemText(unsigned listIndex) const;
    102103    virtual String itemToolTip(unsigned) const { return String(); }
     
    110111    virtual int listSize() const;
    111112    virtual int selectedIndex() const;
    112     virtual void popupDidHide();
     113    virtual void popupDidHide(bool acceptSuggestion);
    113114    virtual bool itemIsSeparator(unsigned listIndex) const;
    114115    virtual bool itemIsLabel(unsigned listIndex) const;
  • trunk/WebKit/chromium/ChangeLog

    r52608 r52673  
     12009-12-30  Zelidrag Hornung  <zelidrag@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Autocomplete in Chromium now offers suggestions within the input element as a user
     6        a) types text that produces some autocomplete suggestions, and
     7        b) scrolls through suggested values in the menu
     8        The suggested value is rendered but not exposed through JS unti the
     9        user makes the final selection.
     10
     11        No new tests since this new functionality (autocomplete suggestions)
     12        is intentionally hidden from everything else than renderer.
     13
     14        * src/AutocompletePopupMenuClient.cpp:
     15        (WebKit::AutocompletePopupMenuClient::initialize):
     16        (WebKit::AutocompletePopupMenuClient::setInitialAutocompleteValue):
     17        (WebKit::AutocompletePopupMenuClient::selectionChanged):
     18        (WebKit::AutocompletePopupMenuClient::popupDidHide):
     19        (WebKit::AutocompletePopupMenuClient::setTextFromItem):
     20        (WebKit::AutocompletePopupMenuClient::resetLastFieldValue):
     21        * src/AutocompletePopupMenuClient.h:
     22
     23
    1242009-12-28  Kinuko Yasuda  <kinuko@chromium.org>
    225
  • trunk/WebKit/chromium/src/AutocompletePopupMenuClient.cpp

    r50740 r52673  
    6060    int defaultSuggestionIndex)
    6161{
     62    if (!m_lastFieldValues)
     63        m_lastFieldValues.set(new FieldValuesMap);
    6264    ASSERT(defaultSuggestionIndex < static_cast<int>(suggestions.size()));
    6365    m_textField = textField;
     66    m_typedFieldValue = textField->value();
    6467    m_selectedIndex = defaultSuggestionIndex;
    6568    setSuggestions(suggestions);
     69
     70    setInitialAutocompleteValue();
    6671
    6772    FontDescription fontDescription;
     
    8085}
    8186
     87
     88void AutocompletePopupMenuClient::setInitialAutocompleteValue()
     89{
     90    if (!m_suggestions.size() || !m_textField->name().length() || !m_typedFieldValue.length())
     91        return;
     92    int newIndex = m_selectedIndex >= 0 ? m_selectedIndex : 0;
     93    String suggestion = m_suggestions[newIndex];
     94    bool hasPreviousValue = m_lastFieldValues->contains(m_textField->name());
     95    String prevValue;
     96    if (hasPreviousValue)
     97        prevValue = m_lastFieldValues->get(m_textField->name());
     98    if (!hasPreviousValue || m_typedFieldValue.length() > m_lastFieldValues->get(m_textField->name()).length()) {
     99          int start = 0;
     100          String newSuggestion = suggestion;
     101          if (suggestion.startsWith(m_typedFieldValue))
     102              m_selectedIndex = newIndex;
     103          if (suggestion.startsWith(m_typedFieldValue, false)) {
     104              newSuggestion = m_typedFieldValue;
     105              if (suggestion.length() > m_typedFieldValue.length()) {
     106                  newSuggestion.append(suggestion.substring(m_typedFieldValue.length(),
     107                      suggestion.length() - m_typedFieldValue.length()));
     108              }
     109              start = m_typedFieldValue.length();
     110          }
     111          m_textField->setSuggestedValue(newSuggestion);
     112          m_textField->setSelectionRange(start, newSuggestion.length());
     113    }
     114    if (hasPreviousValue)
     115        m_lastFieldValues->set(m_textField->name(), m_typedFieldValue);
     116    else
     117        m_lastFieldValues->add(m_textField->name(), m_typedFieldValue);
     118}
     119
     120
    82121void AutocompletePopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents)
    83122{
     
    90129}
    91130
     131void AutocompletePopupMenuClient::selectionChanged(unsigned listIndex, bool fireEvents)
     132{
     133    if (listIndex != -1) {
     134        m_textField->setSuggestedValue(m_suggestions[listIndex]);
     135        m_textField->setSelectionRange(m_typedFieldValue.length(),
     136                                       m_suggestions[listIndex].length());
     137    } else {
     138      m_textField->setValue(m_typedFieldValue);
     139      if (m_lastFieldValues->contains(m_textField->name()))
     140          m_lastFieldValues->set(m_textField->name(), m_typedFieldValue);
     141      else
     142          m_lastFieldValues->add(m_textField->name(), m_typedFieldValue);
     143    }
     144}
     145
    92146String AutocompletePopupMenuClient::itemText(unsigned listIndex) const
    93147{
     
    119173}
    120174
    121 void AutocompletePopupMenuClient::popupDidHide()
    122 {
     175void AutocompletePopupMenuClient::popupDidHide(bool acceptSuggestions)
     176{
     177    if (acceptSuggestions) {
     178        String suggestedValue = m_textField->suggestedValue();
     179        if (!suggestedValue.isNull())
     180            m_textField->setValue(suggestedValue);
     181    } else
     182        m_textField->setValue(m_typedFieldValue);
     183
     184    resetLastFieldValue();
    123185    m_webView->autoCompletePopupDidHide();
    124186}
     
    127189{
    128190    m_textField->setValue(m_suggestions[listIndex]);
     191    resetLastFieldValue();
     192}
     193
     194void AutocompletePopupMenuClient::resetLastFieldValue()
     195{
     196    if (m_lastFieldValues->contains(m_textField->name()))
     197        m_lastFieldValues->set(m_textField->name(), m_textField->value());
     198    else
     199        m_lastFieldValues->add(m_textField->name(), m_textField->value());
    129200}
    130201
  • trunk/WebKit/chromium/src/AutocompletePopupMenuClient.h

    r50740 r52673  
    5959    // WebCore::PopupMenuClient methods:
    6060    virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
     61    virtual void selectionChanged(unsigned listIndex, bool fireEvents = true);
    6162    virtual WebCore::String itemText(unsigned listIndex) const;
    6263    virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); }
     
    7071    virtual int listSize() const { return m_suggestions.size(); }
    7172    virtual int selectedIndex() const { return m_selectedIndex; }
    72     virtual void popupDidHide();
     73    virtual void popupDidHide(bool acceptSuggestion);
    7374    virtual bool itemIsSeparator(unsigned listIndex) const { return false; }
    7475    virtual bool itemIsLabel(unsigned listIndex) const { return false; }
     
    8687private:
    8788    WebCore::RenderStyle* textFieldStyle() const;
     89    void setInitialAutocompleteValue();
     90    void resetLastFieldValue();
    8891
    8992    RefPtr<WebCore::HTMLInputElement> m_textField;
     
    9194    int m_selectedIndex;
    9295    WebViewImpl* m_webView;
     96    WebCore::String m_typedFieldValue;
    9397    OwnPtr<WebCore::PopupMenuStyle> m_style;
     98    typedef HashMap<WebCore::String, WebCore::String> FieldValuesMap;
     99    OwnPtr<FieldValuesMap> m_lastFieldValues;
    94100};
    95101
Note: See TracChangeset for help on using the changeset viewer.