2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef AutofillPopupMenuClient_h
32 #define AutofillPopupMenuClient_h
34 #include "PopupMenuClient.h"
38 class HTMLInputElement;
46 template <typename T> class WebVector;
48 // The Autofill suggestions popup menu client, used to display name suggestions
49 // with right-justified labels.
50 class AutofillPopupMenuClient : public WebCore::PopupMenuClient {
52 AutofillPopupMenuClient();
53 virtual ~AutofillPopupMenuClient();
55 // Returns the number of suggestions available.
56 virtual unsigned getSuggestionsCount() const;
58 // Returns the suggestion at |listIndex|.
59 virtual WebString getSuggestion(unsigned listIndex) const;
61 // Returns the label at |listIndex|.
62 virtual WebString getLabel(unsigned listIndex) const;
64 // Returns the icon at |listIndex|.
65 virtual WebString getIcon(unsigned listIndex) const;
67 // Removes the suggestion at |listIndex| from the list of suggestions.
68 virtual void removeSuggestionAtIndex(unsigned listIndex);
70 // Returns true if the suggestion at |listIndex| can be removed.
71 bool canRemoveSuggestionAtIndex(unsigned listIndex);
73 // WebCore::PopupMenuClient methods:
74 virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
75 virtual void selectionChanged(unsigned, bool);
76 virtual void selectionCleared();
77 virtual WTF::String itemText(unsigned listIndex) const;
78 virtual WTF::String itemLabel(unsigned listIndex) const;
79 virtual WTF::String itemIcon(unsigned listIndex) const;
80 virtual WTF::String itemToolTip(unsigned lastIndex) const { return WTF::String(); }
81 virtual WTF::String itemAccessibilityText(unsigned lastIndex) const { return WTF::String(); }
82 virtual bool itemIsEnabled(unsigned listIndex) const;
83 virtual WebCore::PopupMenuStyle itemStyle(unsigned listIndex) const;
84 virtual WebCore::PopupMenuStyle menuStyle() const;
85 virtual int clientInsetLeft() const { return 0; }
86 virtual int clientInsetRight() const { return 0; }
87 virtual WebCore::LayoutUnit clientPaddingLeft() const;
88 virtual WebCore::LayoutUnit clientPaddingRight() const;
89 virtual int listSize() const { return getSuggestionsCount(); }
90 virtual int selectedIndex() const { return m_selectedIndex; }
91 virtual void popupDidHide();
92 virtual bool itemIsSeparator(unsigned listIndex) const;
93 virtual bool itemIsLabel(unsigned listIndex) const { return false; }
94 virtual bool itemIsSelected(unsigned listIndex) const { return false; }
95 virtual bool shouldPopOver() const { return false; }
96 virtual bool valueShouldChangeOnHotTrack() const { return false; }
97 virtual void setTextFromItem(unsigned listIndex);
98 virtual WebCore::FontSelector* fontSelector() const;
99 virtual WebCore::HostWindow* hostWindow() const;
100 virtual PassRefPtr<WebCore::Scrollbar> createScrollbar(
101 WebCore::ScrollableArea* client,
102 WebCore::ScrollbarOrientation orientation,
103 WebCore::ScrollbarControlSize size);
105 void initialize(WebCore::HTMLInputElement*,
106 const WebVector<WebString>& names,
107 const WebVector<WebString>& labels,
108 const WebVector<WebString>& icons,
109 const WebVector<int>& itemIDs,
112 void setSuggestions(const WebVector<WebString>& names,
113 const WebVector<WebString>& labels,
114 const WebVector<WebString>& icons,
115 const WebVector<int>& itemIDs);
118 WebViewImpl* getWebView() const;
119 WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); }
120 WebCore::RenderStyle* textFieldStyle() const;
122 int getSelectedIndex() const { return m_selectedIndex; }
123 void setSelectedIndex(int index) { m_selectedIndex = index; }
125 bool itemIsWarning(unsigned listIndex) const;
127 // The names, labels and icons that make up the contents of the menu items.
128 Vector<WTF::String> m_names;
129 Vector<WTF::String> m_labels;
130 Vector<WTF::String> m_icons;
131 Vector<int> m_itemIDs;
133 // The index of the selected item. -1 if there is no selected item.
136 RefPtr<WebCore::HTMLInputElement> m_textField;
137 OwnPtr<WebCore::PopupMenuStyle> m_regularStyle;
138 OwnPtr<WebCore::PopupMenuStyle> m_warningStyle;
140 // Use legacy behavior while the chromium side hasn't been updated.
141 bool m_useLegacyBehavior;
144 } // namespace WebKit