Changeset 52673 in webkit
- Timestamp:
- Dec 30, 2009 3:08:58 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r52672 r52673 1 2009-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 1 40 2009-12-30 Nate Chapin <japhet@chromium.org> 2 41 -
trunk/WebCore/platform/PopupMenuClient.h
r48370 r52673 38 38 virtual ~PopupMenuClient() {} 39 39 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) = 0; 40 40 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) = 0; 41 41 virtual String itemText(unsigned listIndex) const = 0; 42 42 virtual String itemToolTip(unsigned listIndex) const = 0; … … 50 50 virtual int listSize() const = 0; 51 51 virtual int selectedIndex() const = 0; 52 virtual void popupDidHide( ) = 0;52 virtual void popupDidHide(bool acceptSuggestions) = 0; 53 53 virtual bool itemIsSeparator(unsigned listIndex) const = 0; 54 54 virtual bool itemIsLabel(unsigned listIndex) const = 0; -
trunk/WebCore/platform/chromium/PopupMenuChromium.cpp
r52519 r52673 107 107 108 108 // Hides the popup. 109 void hidePopup( );109 void hidePopup(bool acceptSuggestions); 110 110 111 111 // Updates our internal list to match the client. … … 382 382 void PopupContainer::hidePopup() 383 383 { 384 listBox()->hidePopup( );384 listBox()->hidePopup(true); 385 385 } 386 386 … … 632 632 case VKEY_RETURN: 633 633 if (m_selectedIndex == -1) { 634 hidePopup( );634 hidePopup(false); 635 635 // Don't eat the enter if nothing is selected. 636 636 return false; … … 885 885 m_selectedIndex = m_originalIndex; 886 886 887 hidePopup( );887 hidePopup(false); 888 888 889 889 if (m_acceptedIndexOnAbandon >= 0) { … … 918 918 if (m_popupClient) { 919 919 // Enter pressed with no selection, just close the popup. 920 hidePopup( );920 hidePopup(false); 921 921 } 922 922 return; … … 927 927 928 928 // Hide ourselves first since valueChanged may have numerous side-effects. 929 hidePopup( );929 hidePopup(true); 930 930 931 931 // Tell the <select> PopupMenuClient what index was selected. … … 945 945 946 946 scrollToRevealSelection(); 947 m_popupClient->selectionChanged(m_selectedIndex); 947 948 } 948 949 } … … 1006 1007 invalidateRow(m_selectedIndex); 1007 1008 m_selectedIndex = -1; 1009 m_popupClient->selectionChanged(m_selectedIndex); 1008 1010 } 1009 1011 } … … 1073 1075 } 1074 1076 1075 void PopupListBox::hidePopup( )1077 void PopupListBox::hidePopup(bool acceptSuggestions) 1076 1078 { 1077 1079 if (parent()) { … … 1081 1083 } 1082 1084 1083 m_popupClient->popupDidHide( );1085 m_popupClient->popupDidHide(acceptSuggestions); 1084 1086 } 1085 1087 -
trunk/WebCore/platform/gtk/PopupMenuGtk.cpp
r52258 r52673 134 134 { 135 135 ASSERT(that->client()); 136 that->client()->popupDidHide( );136 that->client()->popupDidHide(true); 137 137 } 138 138 -
trunk/WebCore/platform/mac/PopupMenuMac.mm
r52314 r52673 109 109 if (numItems <= 0) { 110 110 if (client()) 111 client()->popupDidHide( );111 client()->popupDidHide(true); 112 112 return; 113 113 } … … 166 166 if (client()) { 167 167 int newIndex = [m_popup.get() indexOfSelectedItem]; 168 client()->popupDidHide( );168 client()->popupDidHide(true); 169 169 170 170 // Adjust newIndex for hidden first item. -
trunk/WebCore/platform/qt/QtFallbackWebPopup.cpp
r52223 r52673 104 104 105 105 m_popupVisible = false; 106 client()->popupDidHide( );106 client()->popupDidHide(true); 107 107 } 108 108 -
trunk/WebCore/platform/win/PopupMenuWin.cpp
r52314 r52673 275 275 276 276 if (client()) 277 client()->popupDidHide( );277 client()->popupDidHide(true); 278 278 279 279 // Post a WM_NULL message to wake up the message pump if necessary. -
trunk/WebCore/platform/wx/PopupMenuWx.cpp
r48370 r52673 89 89 if (client()) { 90 90 client()->valueChanged(event.GetId() - s_menuStartId); 91 client()->popupDidHide( );91 client()->popupDidHide(true); 92 92 } 93 93 // 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 428 428 } 429 429 430 void RenderMenuList::popupDidHide( )430 void RenderMenuList::popupDidHide(bool) 431 431 { 432 432 m_popupIsVisible = false; -
trunk/WebCore/rendering/RenderMenuList.h
r48370 r52673 83 83 virtual int listSize() const; 84 84 virtual int selectedIndex() const; 85 virtual void popupDidHide( );85 virtual void popupDidHide(bool acceptSuggestions); 86 86 virtual bool itemIsSeparator(unsigned listIndex) const; 87 87 virtual bool itemIsLabel(unsigned listIndex) const; … … 91 91 virtual bool shouldPopOver() const { return !POPUP_MENU_PULLS_DOWN; } 92 92 virtual void valueChanged(unsigned listIndex, bool fireOnChange = true); 93 virtual void selectionChanged(unsigned, bool) {} 93 94 virtual FontSelector* fontSelector() const; 94 95 virtual HostWindow* hostWindow() const; -
trunk/WebCore/rendering/RenderTextControlSingleLine.cpp
r52204 r52673 729 729 } 730 730 731 void RenderTextControlSingleLine::popupDidHide( )731 void RenderTextControlSingleLine::popupDidHide(bool) 732 732 { 733 733 m_searchPopupIsVisible = false; -
trunk/WebCore/rendering/RenderTextControlSingleLine.h
r48971 r52673 99 99 // PopupMenuClient methods 100 100 virtual void valueChanged(unsigned listIndex, bool fireEvents = true); 101 virtual void selectionChanged(unsigned, bool) {} 101 102 virtual String itemText(unsigned listIndex) const; 102 103 virtual String itemToolTip(unsigned) const { return String(); } … … 110 111 virtual int listSize() const; 111 112 virtual int selectedIndex() const; 112 virtual void popupDidHide( );113 virtual void popupDidHide(bool acceptSuggestion); 113 114 virtual bool itemIsSeparator(unsigned listIndex) const; 114 115 virtual bool itemIsLabel(unsigned listIndex) const; -
trunk/WebKit/chromium/ChangeLog
r52608 r52673 1 2009-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 1 24 2009-12-28 Kinuko Yasuda <kinuko@chromium.org> 2 25 -
trunk/WebKit/chromium/src/AutocompletePopupMenuClient.cpp
r50740 r52673 60 60 int defaultSuggestionIndex) 61 61 { 62 if (!m_lastFieldValues) 63 m_lastFieldValues.set(new FieldValuesMap); 62 64 ASSERT(defaultSuggestionIndex < static_cast<int>(suggestions.size())); 63 65 m_textField = textField; 66 m_typedFieldValue = textField->value(); 64 67 m_selectedIndex = defaultSuggestionIndex; 65 68 setSuggestions(suggestions); 69 70 setInitialAutocompleteValue(); 66 71 67 72 FontDescription fontDescription; … … 80 85 } 81 86 87 88 void 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 82 121 void AutocompletePopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents) 83 122 { … … 90 129 } 91 130 131 void 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 92 146 String AutocompletePopupMenuClient::itemText(unsigned listIndex) const 93 147 { … … 119 173 } 120 174 121 void AutocompletePopupMenuClient::popupDidHide() 122 { 175 void 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(); 123 185 m_webView->autoCompletePopupDidHide(); 124 186 } … … 127 189 { 128 190 m_textField->setValue(m_suggestions[listIndex]); 191 resetLastFieldValue(); 192 } 193 194 void 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()); 129 200 } 130 201 -
trunk/WebKit/chromium/src/AutocompletePopupMenuClient.h
r50740 r52673 59 59 // WebCore::PopupMenuClient methods: 60 60 virtual void valueChanged(unsigned listIndex, bool fireEvents = true); 61 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true); 61 62 virtual WebCore::String itemText(unsigned listIndex) const; 62 63 virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); } … … 70 71 virtual int listSize() const { return m_suggestions.size(); } 71 72 virtual int selectedIndex() const { return m_selectedIndex; } 72 virtual void popupDidHide( );73 virtual void popupDidHide(bool acceptSuggestion); 73 74 virtual bool itemIsSeparator(unsigned listIndex) const { return false; } 74 75 virtual bool itemIsLabel(unsigned listIndex) const { return false; } … … 86 87 private: 87 88 WebCore::RenderStyle* textFieldStyle() const; 89 void setInitialAutocompleteValue(); 90 void resetLastFieldValue(); 88 91 89 92 RefPtr<WebCore::HTMLInputElement> m_textField; … … 91 94 int m_selectedIndex; 92 95 WebViewImpl* m_webView; 96 WebCore::String m_typedFieldValue; 93 97 OwnPtr<WebCore::PopupMenuStyle> m_style; 98 typedef HashMap<WebCore::String, WebCore::String> FieldValuesMap; 99 OwnPtr<FieldValuesMap> m_lastFieldValues; 94 100 }; 95 101
Note: See TracChangeset
for help on using the changeset viewer.