• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "platform/PopupMenuClient.h"
35 
36 namespace WebCore {
37 class FontSelector;
38 class HTMLInputElement;
39 class PopupMenuStyle;
40 class RenderStyle;
41 }
42 
43 namespace blink {
44 class WebString;
45 class WebViewImpl;
46 template <typename T> class WebVector;
47 
48 // The Autofill suggestions popup menu client, used to display name suggestions
49 // with right-justified labels.
50 class AutofillPopupMenuClient : public WebCore::PopupMenuClient {
51 public:
52     AutofillPopupMenuClient();
53     virtual ~AutofillPopupMenuClient();
54 
55     // Returns the number of suggestions available.
56     virtual unsigned getSuggestionsCount() const;
57 
58     // Returns the suggestion at |listIndex|.
59     virtual WebString getSuggestion(unsigned listIndex) const;
60 
61     // Returns the label at |listIndex|.
62     virtual WebString getLabel(unsigned listIndex) const;
63 
64     // Returns the icon at |listIndex|.
65     virtual WebString getIcon(unsigned listIndex) const;
66 
67     // Removes the suggestion at |listIndex| from the list of suggestions.
68     virtual void removeSuggestionAtIndex(unsigned listIndex);
69 
70     // Returns true if the suggestion at |listIndex| can be removed.
71     bool canRemoveSuggestionAtIndex(unsigned listIndex);
72 
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;
itemToolTip(unsigned lastIndex)80     virtual WTF::String itemToolTip(unsigned lastIndex) const { return WTF::String(); }
itemAccessibilityText(unsigned lastIndex)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;
clientInsetLeft()85     virtual int clientInsetLeft() const { return 0; }
clientInsetRight()86     virtual int clientInsetRight() const { return 0; }
87     virtual WebCore::LayoutUnit clientPaddingLeft() const;
88     virtual WebCore::LayoutUnit clientPaddingRight() const;
listSize()89     virtual int listSize() const { return getSuggestionsCount(); }
selectedIndex()90     virtual int selectedIndex() const { return m_selectedIndex; }
91     virtual void popupDidHide();
92     virtual bool itemIsSeparator(unsigned listIndex) const;
itemIsLabel(unsigned listIndex)93     virtual bool itemIsLabel(unsigned listIndex) const { return false; }
itemIsSelected(unsigned listIndex)94     virtual bool itemIsSelected(unsigned listIndex) const { return false; }
valueShouldChangeOnHotTrack()95     virtual bool valueShouldChangeOnHotTrack() const { return false; }
96     virtual void setTextFromItem(unsigned listIndex);
97     virtual WebCore::FontSelector* fontSelector() const;
98     virtual WebCore::HostWindow* hostWindow() const;
99     virtual PassRefPtr<WebCore::Scrollbar> createScrollbar(
100         WebCore::ScrollableArea* client,
101         WebCore::ScrollbarOrientation orientation,
102         WebCore::ScrollbarControlSize size);
103 
104     void initialize(WebCore::HTMLInputElement*,
105                     const WebVector<WebString>& names,
106                     const WebVector<WebString>& labels,
107                     const WebVector<WebString>& icons,
108                     const WebVector<int>& itemIDs,
109                     int separatorIndex);
110 
111     void setSuggestions(const WebVector<WebString>& names,
112                         const WebVector<WebString>& labels,
113                         const WebVector<WebString>& icons,
114                         const WebVector<int>& itemIDs);
115 
116 private:
117     WebViewImpl* getWebView() const;
getTextField()118     WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); }
119     WebCore::RenderStyle* textFieldStyle() const;
120 
getSelectedIndex()121     int getSelectedIndex() const { return m_selectedIndex; }
setSelectedIndex(int index)122     void setSelectedIndex(int index) { m_selectedIndex = index; }
123 
124     bool itemIsWarning(unsigned listIndex) const;
125 
126     // The names, labels and icons that make up the contents of the menu items.
127     Vector<WTF::String> m_names;
128     Vector<WTF::String> m_labels;
129     Vector<WTF::String> m_icons;
130     Vector<int> m_itemIDs;
131 
132     // The index of the selected item.  -1 if there is no selected item.
133     int m_selectedIndex;
134 
135     RefPtr<WebCore::HTMLInputElement> m_textField;
136     OwnPtr<WebCore::PopupMenuStyle> m_regularStyle;
137     OwnPtr<WebCore::PopupMenuStyle> m_warningStyle;
138 
139     // Use legacy behavior while the chromium side hasn't been updated.
140     bool m_useLegacyBehavior;
141 };
142 
143 } // namespace blink
144 
145 #endif
146