1 /* 2 * Copyright (C) 2010 Apple 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 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef WebPopupMenuProxyWin_h 27 #define WebPopupMenuProxyWin_h 28 29 #include "PlatformPopupMenuData.h" 30 #include "WebPopupItem.h" 31 #include "WebPopupMenuProxy.h" 32 #include <WebCore/Scrollbar.h> 33 #include <WebCore/ScrollableArea.h> 34 35 typedef struct HWND__* HWND; 36 typedef struct HDC__* HDC; 37 typedef struct HBITMAP__* HBITMAP; 38 39 namespace WebKit { 40 41 class WebView; 42 43 class WebPopupMenuProxyWin : public WebPopupMenuProxy, private WebCore::ScrollableArea { 44 public: create(WebView * webView,WebPopupMenuProxy::Client * client)45 static PassRefPtr<WebPopupMenuProxyWin> create(WebView* webView, WebPopupMenuProxy::Client* client) 46 { 47 return adoptRef(new WebPopupMenuProxyWin(webView, client)); 48 } 49 ~WebPopupMenuProxyWin(); 50 51 virtual void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, double scaleFactor, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex); 52 virtual void hidePopupMenu(); 53 54 bool setFocusedIndex(int index, bool hotTracking = false); 55 hide()56 void hide() { hidePopupMenu(); } 57 58 private: 59 WebPopupMenuProxyWin(WebView*, WebPopupMenuProxy::Client*); 60 scrollbar()61 WebCore::Scrollbar* scrollbar() const { return m_scrollbar.get(); } 62 63 // ScrollableArea 64 virtual int scrollSize(WebCore::ScrollbarOrientation) const; 65 virtual int scrollPosition(WebCore::Scrollbar*) const; 66 virtual void setScrollOffset(const WebCore::IntPoint&); 67 virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&); invalidateScrollCornerRect(const WebCore::IntRect &)68 virtual void invalidateScrollCornerRect(const WebCore::IntRect&) { } isActive()69 virtual bool isActive() const { return true; } isScrollCornerVisible()70 virtual bool isScrollCornerVisible() const { return false; } scrollCornerRect()71 virtual WebCore::IntRect scrollCornerRect() const { return WebCore::IntRect(); } verticalScrollbar()72 virtual WebCore::Scrollbar* verticalScrollbar() const { return m_scrollbar.get(); } 73 74 // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea. 75 void scrollTo(int offset); 76 77 static bool registerWindowClass(); 78 static LRESULT CALLBACK WebPopupMenuProxyWndProc(HWND, UINT, WPARAM, LPARAM); 79 LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 80 81 // Message pump messages. 82 LRESULT onMouseActivate(HWND, UINT message, WPARAM, LPARAM, bool& handled); 83 LRESULT onSize(HWND, UINT message, WPARAM, LPARAM, bool& handled); 84 LRESULT onKeyDown(HWND, UINT message, WPARAM, LPARAM, bool& handled); 85 LRESULT onChar(HWND, UINT message, WPARAM, LPARAM, bool& handled); 86 LRESULT onMouseMove(HWND, UINT message, WPARAM, LPARAM, bool& handled); 87 LRESULT onLButtonDown(HWND, UINT message, WPARAM, LPARAM, bool& handled); 88 LRESULT onLButtonUp(HWND, UINT message, WPARAM, LPARAM, bool& handled); 89 LRESULT onMouseWheel(HWND, UINT message, WPARAM, LPARAM, bool& handled); 90 LRESULT onPaint(HWND, UINT message, WPARAM, LPARAM, bool& handled); 91 LRESULT onPrintClient(HWND, UINT message, WPARAM, LPARAM, bool& handled); 92 93 void calculatePositionAndSize(const WebCore::IntRect&); 94 WebCore::IntRect clientRect() const; 95 void invalidateItem(int index); 96 itemHeight()97 int itemHeight() const { return m_itemHeight; } windowRect()98 const WebCore::IntRect& windowRect() const { return m_windowRect; } wheelDelta()99 int wheelDelta() const { return m_wheelDelta; } 100 void setWasClicked(bool b = true) { m_wasClicked = b; } wasClicked()101 bool wasClicked() const { return m_wasClicked; } setScrollOffset(int offset)102 void setScrollOffset(int offset) { m_scrollOffset = offset; } scrollOffset()103 int scrollOffset() const { return m_scrollOffset; } scrollbarCapturingMouse()104 bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; } setScrollbarCapturingMouse(bool b)105 void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; } 106 107 108 bool up(unsigned lines = 1); 109 bool down(unsigned lines = 1); 110 111 void paint(const WebCore::IntRect& damageRect, HDC = 0); 112 int visibleItems() const; 113 int listIndexAtPoint(const WebCore::IntPoint&) const; 114 int focusedIndex() const; 115 void focusFirst(); 116 void focusLast(); 117 bool scrollToRevealSelection(); 118 void incrementWheelDelta(int delta); 119 void reduceWheelDelta(int delta); 120 121 WebView* m_webView; 122 Vector<WebPopupItem> m_items; 123 PlatformPopupMenuData m_data; 124 int m_newSelectedIndex; 125 126 RefPtr<WebCore::Scrollbar> m_scrollbar; 127 HWND m_popup; 128 HDC m_DC; 129 HBITMAP m_bmp; 130 WebCore::IntRect m_windowRect; 131 132 int m_itemHeight; 133 int m_scrollOffset; 134 int m_wheelDelta; 135 int m_focusedIndex; 136 bool m_wasClicked; 137 bool m_scrollbarCapturingMouse; 138 bool m_showPopup; 139 }; 140 141 } // namespace WebKit 142 143 #endif // WebPopupMenuProxyWin_h 144