|
1 /* |
|
2 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions are |
|
6 * met: |
|
7 * |
|
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 |
|
13 * distribution. |
|
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. |
|
17 * |
|
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. |
|
29 */ |
|
30 |
|
31 #ifndef AutoFillPopupMenuClient_h |
|
32 #define AutoFillPopupMenuClient_h |
|
33 |
|
34 #include "PopupMenuClient.h" |
|
35 |
|
36 namespace WebCore { |
|
37 class HTMLInputElement; |
|
38 class PopupMenuStyle; |
|
39 class RenderStyle; |
|
40 } |
|
41 |
|
42 namespace WebKit { |
|
43 class WebString; |
|
44 class WebViewImpl; |
|
45 template <typename T> class WebVector; |
|
46 |
|
47 // The AutoFill suggestions popup menu client, used to display name suggestions |
|
48 // with right-justified labels. |
|
49 class AutoFillPopupMenuClient : public WebCore::PopupMenuClient { |
|
50 public: |
|
51 AutoFillPopupMenuClient(); |
|
52 virtual ~AutoFillPopupMenuClient(); |
|
53 |
|
54 // Returns the number of suggestions available. |
|
55 virtual unsigned getSuggestionsCount() const; |
|
56 |
|
57 // Returns the suggestion at |listIndex|. |
|
58 virtual WebString getSuggestion(unsigned listIndex) const; |
|
59 |
|
60 // Returns the label at |listIndex|. |
|
61 virtual WebString getLabel(unsigned listIndex) const; |
|
62 |
|
63 // Removes the suggestion at |listIndex| from the list of suggestions. |
|
64 virtual void removeSuggestionAtIndex(unsigned listIndex); |
|
65 |
|
66 // Returns true if the suggestion at |listIndex| can be removed. |
|
67 bool canRemoveSuggestionAtIndex(unsigned listIndex); |
|
68 |
|
69 // WebCore::PopupMenuClient methods: |
|
70 virtual void valueChanged(unsigned listIndex, bool fireEvents = true); |
|
71 virtual void selectionChanged(unsigned, bool); |
|
72 virtual void selectionCleared(); |
|
73 virtual WebCore::String itemText(unsigned listIndex) const; |
|
74 virtual WebCore::String itemLabel(unsigned listIndex) const; |
|
75 virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); } |
|
76 virtual WebCore::String itemAccessibilityText(unsigned lastIndex) const { return WebCore::String(); } |
|
77 virtual bool itemIsEnabled(unsigned listIndex) const { return true; } |
|
78 virtual WebCore::PopupMenuStyle itemStyle(unsigned listIndex) const; |
|
79 virtual WebCore::PopupMenuStyle menuStyle() const; |
|
80 virtual int clientInsetLeft() const { return 0; } |
|
81 virtual int clientInsetRight() const { return 0; } |
|
82 virtual int clientPaddingLeft() const; |
|
83 virtual int clientPaddingRight() const; |
|
84 virtual int listSize() const { return getSuggestionsCount(); } |
|
85 virtual int selectedIndex() const { return m_selectedIndex; } |
|
86 virtual void popupDidHide(); |
|
87 virtual bool itemIsSeparator(unsigned listIndex) const; |
|
88 virtual bool itemIsLabel(unsigned listIndex) const { return false; } |
|
89 virtual bool itemIsSelected(unsigned listIndex) const { return false; } |
|
90 virtual bool shouldPopOver() const { return false; } |
|
91 virtual bool valueShouldChangeOnHotTrack() const { return false; } |
|
92 virtual void setTextFromItem(unsigned listIndex); |
|
93 virtual WebCore::FontSelector* fontSelector() const; |
|
94 virtual WebCore::HostWindow* hostWindow() const; |
|
95 virtual PassRefPtr<WebCore::Scrollbar> createScrollbar( |
|
96 WebCore::ScrollbarClient* client, |
|
97 WebCore::ScrollbarOrientation orientation, |
|
98 WebCore::ScrollbarControlSize size); |
|
99 |
|
100 void initialize(WebCore::HTMLInputElement*, |
|
101 const WebVector<WebString>& names, |
|
102 const WebVector<WebString>& labels, |
|
103 const WebVector<int>& uniqueIDs, |
|
104 int separatorIndex); |
|
105 |
|
106 void setSuggestions(const WebVector<WebString>& names, |
|
107 const WebVector<WebString>& labels, |
|
108 const WebVector<int>& uniqueIDs, |
|
109 int separatorIndex); |
|
110 |
|
111 // DEPRECATED: Will be removed once Autocomplete and AutoFill merge is |
|
112 // complete. |
|
113 void setAutocompleteMode(bool enabled) { m_AutocompleteModeEnabled = enabled; } |
|
114 |
|
115 private: |
|
116 // Convert the specified index from an index into the visible list (which might |
|
117 // include a separator entry) to an index to |m_names| and |m_labels|. |
|
118 // Returns -1 if the given index points to the separator. |
|
119 int convertListIndexToInternalIndex(unsigned) const; |
|
120 WebViewImpl* getWebView() const; |
|
121 WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); } |
|
122 WebCore::RenderStyle* textFieldStyle() const; |
|
123 |
|
124 int getSelectedIndex() const { return m_selectedIndex; } |
|
125 void setSelectedIndex(int index) { m_selectedIndex = index; } |
|
126 |
|
127 // The names and labels that make up the text of the menu items. |
|
128 Vector<WebCore::String> m_names; |
|
129 Vector<WebCore::String> m_labels; |
|
130 Vector<int> m_uniqueIDs; |
|
131 |
|
132 // The index of the separator. -1 if there is no separator. |
|
133 int m_separatorIndex; |
|
134 |
|
135 // The index of the selected item. -1 if there is no selected item. |
|
136 int m_selectedIndex; |
|
137 |
|
138 RefPtr<WebCore::HTMLInputElement> m_textField; |
|
139 OwnPtr<WebCore::PopupMenuStyle> m_style; |
|
140 |
|
141 // DEPRECATED: Will be removed once Autocomplete and AutoFill merge is |
|
142 // complete. |
|
143 bool m_AutocompleteModeEnabled; |
|
144 }; |
|
145 |
|
146 } // namespace WebKit |
|
147 |
|
148 #endif |