• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #ifndef PopupMenu_h
22 #define PopupMenu_h
23 
24 #include "IntRect.h"
25 #include "PopupMenuClient.h"
26 #include <wtf/PassRefPtr.h>
27 #include <wtf/RefCounted.h>
28 
29 #if PLATFORM(MAC)
30 #include <wtf/RetainPtr.h>
31 #ifdef __OBJC__
32 @class NSPopUpButtonCell;
33 #else
34 class NSPopUpButtonCell;
35 #endif
36 #elif PLATFORM(WIN)
37 #include "Scrollbar.h"
38 #include "ScrollbarClient.h"
39 #include <wtf/RefPtr.h>
40 typedef struct HWND__* HWND;
41 typedef struct HDC__* HDC;
42 typedef struct HBITMAP__* HBITMAP;
43 #elif PLATFORM(QT)
44 namespace WebCore {
45     class QWebPopup;
46 }
47 #elif PLATFORM(GTK)
48 typedef struct _GtkMenu GtkMenu;
49 typedef struct _GtkMenuItem GtkMenuItem;
50 typedef struct _GtkWidget GtkWidget;
51 #include <wtf/HashMap.h>
52 #include <glib.h>
53 #elif PLATFORM(WX)
54 #ifdef __WXMSW__
55 #include <wx/msw/winundef.h>
56 #endif
57 class wxMenu;
58 #include <wx/defs.h>
59 #include <wx/event.h>
60 #elif PLATFORM(CHROMIUM)
61 #include "PopupMenuPrivate.h"
62 #endif
63 
64 namespace WebCore {
65 
66 class FrameView;
67 class Scrollbar;
68 
69 class PopupMenu : public RefCounted<PopupMenu>
70 #if PLATFORM(WIN)
71                 , private ScrollbarClient
72 #endif
73 #if PLATFORM(WX)
74                 , public wxEvtHandler
75 #endif
76 {
77 public:
create(PopupMenuClient * client)78     static PassRefPtr<PopupMenu> create(PopupMenuClient* client) { return adoptRef(new PopupMenu(client)); }
79     ~PopupMenu();
80 
disconnectClient()81     void disconnectClient() { m_popupClient = 0; }
82 
83     void show(const IntRect&, FrameView*, int index);
84     void hide();
85 
86     void updateFromElement();
87 
client()88     PopupMenuClient* client() const { return m_popupClient; }
89 
90     static bool itemWritingDirectionIsNatural();
91 
92 #if PLATFORM(WIN)
scrollbar()93     Scrollbar* scrollbar() const { return m_scrollbar.get(); }
94 
95     bool up(unsigned lines = 1);
96     bool down(unsigned lines = 1);
97 
itemHeight()98     int itemHeight() const { return m_itemHeight; }
windowRect()99     const IntRect& windowRect() const { return m_windowRect; }
100     IntRect clientRect() const;
101 
102     int visibleItems() const;
103 
104     int listIndexAtPoint(const IntPoint&) const;
105 
106     bool setFocusedIndex(int index, bool hotTracking = false);
107     int focusedIndex() const;
108     void focusFirst();
109     void focusLast();
110 
111     void paint(const IntRect& damageRect, HDC = 0);
112 
popupHandle()113     HWND popupHandle() const { return m_popup; }
114 
115     void setWasClicked(bool b = true) { m_wasClicked = b; }
wasClicked()116     bool wasClicked() const { return m_wasClicked; }
117 
setScrollOffset(int offset)118     void setScrollOffset(int offset) { m_scrollOffset = offset; }
scrollOffset()119     int scrollOffset() const { return m_scrollOffset; }
120 
121     bool scrollToRevealSelection();
122 
123     void incrementWheelDelta(int delta);
124     void reduceWheelDelta(int delta);
wheelDelta()125     int wheelDelta() const { return m_wheelDelta; }
126 
scrollbarCapturingMouse()127     bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; }
setScrollbarCapturingMouse(bool b)128     void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; }
129 #endif
130 
131 protected:
132     PopupMenu(PopupMenuClient*);
133 
134 private:
135     PopupMenuClient* m_popupClient;
136 
137 #if PLATFORM(MAC)
138     void clear();
139     void populate();
140 
141     RetainPtr<NSPopUpButtonCell> m_popup;
142 #elif PLATFORM(QT)
143     void clear();
144     void populate(const IntRect&);
145     QWebPopup* m_popup;
146 #elif PLATFORM(WIN)
147     // ScrollBarClient
148     virtual void valueChanged(Scrollbar*);
149     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
isActive()150     virtual bool isActive() const { return true; }
scrollbarCornerPresent()151     virtual bool scrollbarCornerPresent() const { return false; }
152 
153     void calculatePositionAndSize(const IntRect&, FrameView*);
154     void invalidateItem(int index);
155 
156     RefPtr<Scrollbar> m_scrollbar;
157     HWND m_popup;
158     HDC m_DC;
159     HBITMAP m_bmp;
160     bool m_wasClicked;
161     IntRect m_windowRect;
162     int m_itemHeight;
163     int m_scrollOffset;
164     int m_wheelDelta;
165     int m_focusedIndex;
166     bool m_scrollbarCapturingMouse;
167 #elif PLATFORM(GTK)
168     IntPoint m_menuPosition;
169     GtkMenu* m_popup;
170     HashMap<GtkWidget*, int> m_indexMap;
171     static void menuItemActivated(GtkMenuItem* item, PopupMenu*);
172     static void menuUnmapped(GtkWidget*, PopupMenu*);
173     static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, PopupMenu*);
174     static void menuRemoveItem(GtkWidget*, PopupMenu*);
175 #elif PLATFORM(WX)
176     wxMenu* m_menu;
177     void OnMenuItemSelected(wxCommandEvent&);
178 #elif PLATFORM(CHROMIUM)
179     PopupMenuPrivate p;
180 #endif
181 
182 };
183 
184 }
185 
186 #endif
187