diff options
author | Ben Murdoch <benm@google.com> | 2010-07-22 15:37:06 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-07-27 10:20:25 +0100 |
commit | 967717af5423377c967781471ee106e2bb4e11c8 (patch) | |
tree | 1e701dc0a12f7f07cce1df4a7681717de77a211b /WebKit/chromium/src/AutoFillPopupMenuClient.cpp | |
parent | dcc30a9fca45f634b1d3a12b276d3a0ccce99fc3 (diff) | |
download | external_webkit-967717af5423377c967781471ee106e2bb4e11c8.zip external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.gz external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.bz2 |
Merge WebKit at r63859 : Initial merge by git.
Change-Id: Ie8096c63ec7c991c9a9cba8bdd9c3b74a3b8ed62
Diffstat (limited to 'WebKit/chromium/src/AutoFillPopupMenuClient.cpp')
-rw-r--r-- | WebKit/chromium/src/AutoFillPopupMenuClient.cpp | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/WebKit/chromium/src/AutoFillPopupMenuClient.cpp b/WebKit/chromium/src/AutoFillPopupMenuClient.cpp index 1294561..6b74f60 100644 --- a/WebKit/chromium/src/AutoFillPopupMenuClient.cpp +++ b/WebKit/chromium/src/AutoFillPopupMenuClient.cpp @@ -66,28 +66,47 @@ unsigned AutoFillPopupMenuClient::getSuggestionsCount() const WebString AutoFillPopupMenuClient::getSuggestion(unsigned listIndex) const { - if (listIndex == static_cast<unsigned>(m_separatorIndex)) + int index = convertListIndexToInternalIndex(listIndex); + if (index == -1) return WebString(); - if (m_separatorIndex != -1 && listIndex > static_cast<unsigned>(m_separatorIndex)) - --listIndex; - - // FIXME: Modify the PopupMenu to add the label in gray right-justified. - ASSERT(listIndex < m_names.size()); + ASSERT(index >= 0 && static_cast<size_t>(index) < m_names.size()); + return m_names[index]; +} - WebString suggestion = m_names[listIndex]; - if (m_labels[listIndex].isEmpty()) - return suggestion; +WebString AutoFillPopupMenuClient::getLabel(unsigned listIndex) const +{ + int index = convertListIndexToInternalIndex(listIndex); + if (index == -1) + return WebString(); - return suggestion + String(" (") + m_labels[listIndex] + String(")"); + ASSERT(index >= 0 && static_cast<size_t>(index) < m_labels.size()); + return m_labels[index]; } void AutoFillPopupMenuClient::removeSuggestionAtIndex(unsigned listIndex) { - // FIXME: Do we want to remove AutoFill suggestions? - ASSERT(listIndex < m_names.size()); - m_names.remove(listIndex); - m_labels.remove(listIndex); + if (!canRemoveSuggestionAtIndex(listIndex)) + return; + + int index = convertListIndexToInternalIndex(listIndex); + + ASSERT(static_cast<unsigned>(index) < m_names.size()); + + m_names.remove(index); + m_labels.remove(index); + + // Shift the separator index if necessary. + if (m_separatorIndex != -1) + m_separatorIndex--; +} + +bool AutoFillPopupMenuClient::canRemoveSuggestionAtIndex(unsigned listIndex) +{ + // Only allow deletion of items before the separator and those that don't + // have a label (autocomplete). + int index = convertListIndexToInternalIndex(listIndex); + return m_labels[index].isEmpty() && (m_separatorIndex == -1 || listIndex < static_cast<unsigned>(m_separatorIndex)); } void AutoFillPopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents) @@ -119,6 +138,7 @@ void AutoFillPopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents) webView->client()->didAcceptAutoFillSuggestion(WebNode(getTextField()), m_names[listIndex], m_labels[listIndex], + m_uniqueIDs[listIndex], listIndex); } } @@ -136,13 +156,15 @@ void AutoFillPopupMenuClient::selectionChanged(unsigned listIndex, bool fireEven webView->client()->didSelectAutoFillSuggestion(WebNode(getTextField()), m_names[listIndex], - m_labels[listIndex]); + m_labels[listIndex], + m_uniqueIDs[listIndex]); } void AutoFillPopupMenuClient::selectionCleared() { - // Same effect desired as popupDidHide, so call through. - popupDidHide(); + WebViewImpl* webView = getWebView(); + if (webView) + webView->client()->didClearAutoFillSelection(WebNode(getTextField())); } String AutoFillPopupMenuClient::itemText(unsigned listIndex) const @@ -150,6 +172,11 @@ String AutoFillPopupMenuClient::itemText(unsigned listIndex) const return getSuggestion(listIndex); } +String AutoFillPopupMenuClient::itemLabel(unsigned listIndex) const +{ + return getLabel(listIndex); +} + PopupMenuStyle AutoFillPopupMenuClient::itemStyle(unsigned listIndex) const { return *m_style; @@ -222,9 +249,11 @@ void AutoFillPopupMenuClient::initialize( HTMLInputElement* textField, const WebVector<WebString>& names, const WebVector<WebString>& labels, + const WebVector<int>& uniqueIDs, int separatorIndex) { ASSERT(names.size() == labels.size()); + ASSERT(names.size() == uniqueIDs.size()); ASSERT(separatorIndex < static_cast<int>(names.size())); m_selectedIndex = -1; @@ -232,7 +261,7 @@ void AutoFillPopupMenuClient::initialize( // The suggestions must be set before initializing the // AutoFillPopupMenuClient. - setSuggestions(names, labels, separatorIndex); + setSuggestions(names, labels, uniqueIDs, separatorIndex); FontDescription fontDescription; RenderTheme::defaultTheme()->systemFont(CSSValueWebkitControl, @@ -251,16 +280,20 @@ void AutoFillPopupMenuClient::initialize( void AutoFillPopupMenuClient::setSuggestions(const WebVector<WebString>& names, const WebVector<WebString>& labels, + const WebVector<int>& uniqueIDs, int separatorIndex) { ASSERT(names.size() == labels.size()); + ASSERT(names.size() == uniqueIDs.size()); ASSERT(separatorIndex < static_cast<int>(names.size())); m_names.clear(); m_labels.clear(); + m_uniqueIDs.clear(); for (size_t i = 0; i < names.size(); ++i) { m_names.append(names[i]); m_labels.append(labels[i]); + m_uniqueIDs.append(uniqueIDs[i]); } m_separatorIndex = separatorIndex; @@ -270,6 +303,16 @@ void AutoFillPopupMenuClient::setSuggestions(const WebVector<WebString>& names, setSelectedIndex(-1); } +int AutoFillPopupMenuClient::convertListIndexToInternalIndex(unsigned listIndex) const +{ + if (listIndex == static_cast<unsigned>(m_separatorIndex)) + return -1; + + if (m_separatorIndex == -1 || listIndex < static_cast<unsigned>(m_separatorIndex)) + return listIndex; + return listIndex - 1; +} + WebViewImpl* AutoFillPopupMenuClient::getWebView() const { Frame* frame = m_textField->document()->frame(); @@ -288,7 +331,7 @@ RenderStyle* AutoFillPopupMenuClient::textFieldStyle() const RenderStyle* style = m_textField->computedStyle(); if (!style) { // It seems we can only have a 0 style in a TextField if the - // node is detached, in which case we the popup shoud not be + // node is detached, in which case we the popup should not be // showing. Please report this in http://crbug.com/7708 and // include the page you were visiting. ASSERT_NOT_REACHED(); |