1 /* 2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef PopupMenuWin_h 22 #define PopupMenuWin_h 23 24 #include "IntRect.h" 25 #include "PopupMenu.h" 26 #include "PopupMenuClient.h" 27 #include "ScrollableArea.h" 28 #include "Scrollbar.h" 29 #include <wtf/PassRefPtr.h> 30 #include <wtf/RefCounted.h> 31 #include <wtf/RefPtr.h> 32 33 typedef struct HWND__* HWND; 34 typedef struct HDC__* HDC; 35 typedef struct HBITMAP__* HBITMAP; 36 37 namespace WebCore { 38 39 class FrameView; 40 class Scrollbar; 41 42 class PopupMenuWin : public PopupMenu, private ScrollableArea { 43 public: 44 PopupMenuWin(PopupMenuClient*); 45 ~PopupMenuWin(); 46 47 virtual void show(const IntRect&, FrameView*, int index); 48 virtual void hide(); 49 virtual void updateFromElement(); 50 virtual void disconnectClient(); 51 52 static LPCWSTR popupClassName(); 53 54 private: client()55 PopupMenuClient* client() const { return m_popupClient; } 56 scrollbar()57 Scrollbar* scrollbar() const { return m_scrollbar.get(); } 58 59 bool up(unsigned lines = 1); 60 bool down(unsigned lines = 1); 61 itemHeight()62 int itemHeight() const { return m_itemHeight; } windowRect()63 const IntRect& windowRect() const { return m_windowRect; } 64 IntRect clientRect() const; 65 66 int visibleItems() const; 67 68 int listIndexAtPoint(const IntPoint&) const; 69 70 bool setFocusedIndex(int index, bool hotTracking = false); 71 int focusedIndex() const; 72 void focusFirst(); 73 void focusLast(); 74 75 void paint(const IntRect& damageRect, HDC = 0); 76 popupHandle()77 HWND popupHandle() const { return m_popup; } 78 79 void setWasClicked(bool b = true) { m_wasClicked = b; } wasClicked()80 bool wasClicked() const { return m_wasClicked; } 81 scrollOffset()82 int scrollOffset() const { return m_scrollOffset; } 83 84 bool scrollToRevealSelection(); 85 86 void incrementWheelDelta(int delta); 87 void reduceWheelDelta(int delta); wheelDelta()88 int wheelDelta() const { return m_wheelDelta; } 89 scrollbarCapturingMouse()90 bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; } setScrollbarCapturingMouse(bool b)91 void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; } 92 93 // ScrollableArea 94 virtual int scrollSize(ScrollbarOrientation orientation) const; 95 virtual int scrollPosition(Scrollbar*) const; 96 virtual void setScrollOffset(const IntPoint&); 97 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&); invalidateScrollCornerRect(const WebCore::IntRect &)98 virtual void invalidateScrollCornerRect(const WebCore::IntRect&) { } isActive()99 virtual bool isActive() const { return true; } isScrollCornerVisible()100 virtual bool isScrollCornerVisible() const { return false; } scrollCornerRect()101 virtual WebCore::IntRect scrollCornerRect() const { return WebCore::IntRect(); } verticalScrollbar()102 virtual Scrollbar* verticalScrollbar() const { return m_scrollbar.get(); } 103 104 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea. 105 void scrollTo(int offset); 106 107 void calculatePositionAndSize(const IntRect&, FrameView*); 108 void invalidateItem(int index); 109 110 static LRESULT CALLBACK PopupMenuWndProc(HWND, UINT, WPARAM, LPARAM); 111 LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 112 static void registerClass(); 113 114 PopupMenuClient* m_popupClient; 115 RefPtr<Scrollbar> m_scrollbar; 116 HWND m_popup; 117 HDC m_DC; 118 HBITMAP m_bmp; 119 bool m_wasClicked; 120 IntRect m_windowRect; 121 int m_itemHeight; 122 int m_scrollOffset; 123 int m_wheelDelta; 124 int m_focusedIndex; 125 bool m_scrollbarCapturingMouse; 126 bool m_showPopup; 127 }; 128 129 } // namespace WebCore 130 131 #endif // PopupMenuWin_h 132