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 #include "PopupMenuClient.h" 32 33 #ifndef SuggestionsPopupMenuClient_h 34 #define SuggestionsPopupMenuClient_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 Suggestions popup menu client, used to display a list of suggestions. 48 class SuggestionsPopupMenuClient : public WebCore::PopupMenuClient { 49 public: 50 SuggestionsPopupMenuClient(); 51 virtual ~SuggestionsPopupMenuClient(); 52 53 // Returns the number of suggestions available. 54 virtual unsigned getSuggestionsCount() const = 0; 55 56 // Returns the suggestion at |listIndex|. 57 virtual WebString getSuggestion(unsigned listIndex) const = 0; 58 59 // Removes the suggestion at |listIndex| from the list of suggestions. 60 virtual void removeSuggestionAtIndex(unsigned listIndex) = 0; 61 62 // WebCore::PopupMenuClient methods: 63 virtual void valueChanged(unsigned listIndex, bool fireEvents = true); 64 virtual WebCore::String itemText(unsigned listIndex) const; itemToolTip(unsigned lastIndex)65 virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); } itemIsEnabled(unsigned listIndex)66 virtual bool itemIsEnabled(unsigned listIndex) const { return true; } 67 virtual WebCore::PopupMenuStyle itemStyle(unsigned listIndex) const; 68 virtual WebCore::PopupMenuStyle menuStyle() const; clientInsetLeft()69 virtual int clientInsetLeft() const { return 0; } clientInsetRight()70 virtual int clientInsetRight() const { return 0; } 71 virtual int clientPaddingLeft() const; 72 virtual int clientPaddingRight() const; listSize()73 virtual int listSize() const { return getSuggestionsCount(); } selectedIndex()74 virtual int selectedIndex() const { return m_selectedIndex; } 75 virtual void popupDidHide(); itemIsSeparator(unsigned listIndex)76 virtual bool itemIsSeparator(unsigned listIndex) const { return false; } itemIsLabel(unsigned listIndex)77 virtual bool itemIsLabel(unsigned listIndex) const { return false; } itemIsSelected(unsigned listIndex)78 virtual bool itemIsSelected(unsigned listIndex) const { return false; } shouldPopOver()79 virtual bool shouldPopOver() const { return false; } valueShouldChangeOnHotTrack()80 virtual bool valueShouldChangeOnHotTrack() const { return false; } 81 virtual void setTextFromItem(unsigned listIndex); 82 virtual WebCore::FontSelector* fontSelector() const; 83 virtual WebCore::HostWindow* hostWindow() const; 84 virtual PassRefPtr<WebCore::Scrollbar> createScrollbar( 85 WebCore::ScrollbarClient* client, 86 WebCore::ScrollbarOrientation orientation, 87 WebCore::ScrollbarControlSize size); 88 89 protected: 90 void initialize(WebCore::HTMLInputElement* textField, 91 int defaultSuggestionIndex); 92 getSelectedIndex()93 int getSelectedIndex() const { return m_selectedIndex; } setSelectedIndex(int index)94 void setSelectedIndex(int index) { m_selectedIndex = index; } 95 96 WebViewImpl* getWebView() const; getTextField()97 WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); } 98 99 private: 100 WebCore::RenderStyle* textFieldStyle() const; 101 102 RefPtr<WebCore::HTMLInputElement> m_textField; 103 int m_selectedIndex; 104 OwnPtr<WebCore::PopupMenuStyle> m_style; 105 }; 106 107 } // namespace WebKit 108 109 #endif 110