Home | History | Annotate | Download | only in platform
      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 QtAbstractWebPopup;
     46 }
     47 #elif PLATFORM(GTK)
     48 typedef struct _GtkMenu GtkMenu;
     49 typedef struct _GtkMenuItem GtkMenuItem;
     50 typedef struct _GtkWidget GtkWidget;
     51 #include "GRefPtrGtk.h"
     52 #include <wtf/HashMap.h>
     53 #include <glib.h>
     54 #elif PLATFORM(WX)
     55 #ifdef __WXMSW__
     56 #include <wx/msw/winundef.h>
     57 #endif
     58 class wxMenu;
     59 #include <wx/defs.h>
     60 #include <wx/event.h>
     61 #elif PLATFORM(CHROMIUM)
     62 #include "PopupMenuPrivate.h"
     63 #elif PLATFORM(HAIKU)
     64 class BMenu;
     65 #endif
     66 
     67 namespace WebCore {
     68 
     69 class FrameView;
     70 class Scrollbar;
     71 
     72 class PopupMenu : public RefCounted<PopupMenu>
     73 #if PLATFORM(WIN)
     74                 , private ScrollbarClient
     75 #endif
     76 #if PLATFORM(WX)
     77                 , public wxEvtHandler
     78 #endif
     79 {
     80 public:
     81     static PassRefPtr<PopupMenu> create(PopupMenuClient* client) { return adoptRef(new PopupMenu(client)); }
     82     ~PopupMenu();
     83 
     84     void disconnectClient() { m_popupClient = 0; }
     85 
     86     void show(const IntRect&, FrameView*, int index);
     87     void hide();
     88 
     89     void updateFromElement();
     90 
     91     PopupMenuClient* client() const { return m_popupClient; }
     92 
     93     static bool itemWritingDirectionIsNatural();
     94 
     95 #if PLATFORM(WIN)
     96     Scrollbar* scrollbar() const { return m_scrollbar.get(); }
     97 
     98     static LPCTSTR popupClassName();
     99 
    100     bool up(unsigned lines = 1);
    101     bool down(unsigned lines = 1);
    102 
    103     int itemHeight() const { return m_itemHeight; }
    104     const IntRect& windowRect() const { return m_windowRect; }
    105     IntRect clientRect() const;
    106 
    107     int visibleItems() const;
    108 
    109     int listIndexAtPoint(const IntPoint&) const;
    110 
    111     bool setFocusedIndex(int index, bool hotTracking = false);
    112     int focusedIndex() const;
    113     void focusFirst();
    114     void focusLast();
    115 
    116     void paint(const IntRect& damageRect, HDC = 0);
    117 
    118     HWND popupHandle() const { return m_popup; }
    119 
    120     void setWasClicked(bool b = true) { m_wasClicked = b; }
    121     bool wasClicked() const { return m_wasClicked; }
    122 
    123     void setScrollOffset(int offset) { m_scrollOffset = offset; }
    124     int scrollOffset() const { return m_scrollOffset; }
    125 
    126     bool scrollToRevealSelection();
    127 
    128     void incrementWheelDelta(int delta);
    129     void reduceWheelDelta(int delta);
    130     int wheelDelta() const { return m_wheelDelta; }
    131 
    132     bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; }
    133     void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; }
    134 #endif
    135 
    136 protected:
    137     PopupMenu(PopupMenuClient*);
    138 
    139 private:
    140     PopupMenuClient* m_popupClient;
    141 
    142 #if PLATFORM(MAC)
    143     void clear();
    144     void populate();
    145 
    146     RetainPtr<NSPopUpButtonCell> m_popup;
    147 #elif PLATFORM(QT)
    148     QtAbstractWebPopup* m_popup;
    149 #elif PLATFORM(WIN)
    150     // ScrollBarClient
    151     virtual void valueChanged(Scrollbar*);
    152     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
    153     virtual bool isActive() const { return true; }
    154     virtual bool scrollbarCornerPresent() const { return false; }
    155 
    156     void calculatePositionAndSize(const IntRect&, FrameView*);
    157     void invalidateItem(int index);
    158 
    159     static LRESULT CALLBACK PopupMenuWndProc(HWND, UINT, WPARAM, LPARAM);
    160     LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    161     static void registerClass();
    162 
    163     RefPtr<Scrollbar> m_scrollbar;
    164     HWND m_popup;
    165     HDC m_DC;
    166     HBITMAP m_bmp;
    167     bool m_wasClicked;
    168     IntRect m_windowRect;
    169     int m_itemHeight;
    170     int m_scrollOffset;
    171     int m_wheelDelta;
    172     int m_focusedIndex;
    173     bool m_scrollbarCapturingMouse;
    174     bool m_showPopup;
    175 #elif PLATFORM(GTK)
    176     IntPoint m_menuPosition;
    177     GRefPtr<GtkMenu> m_popup;
    178     HashMap<GtkWidget*, int> m_indexMap;
    179     static void menuItemActivated(GtkMenuItem* item, PopupMenu*);
    180     static void menuUnmapped(GtkWidget*, PopupMenu*);
    181     static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, PopupMenu*);
    182     static void menuRemoveItem(GtkWidget*, PopupMenu*);
    183 #elif PLATFORM(WX)
    184     wxMenu* m_menu;
    185     void OnMenuItemSelected(wxCommandEvent&);
    186 #elif PLATFORM(CHROMIUM)
    187     PopupMenuPrivate p;
    188 #elif PLATFORM(HAIKU)
    189     BMenu* m_menu;
    190 #endif
    191 
    192 };
    193 
    194 }
    195 
    196 #endif
    197