Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, 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 | #ifndef PopupContainer_h |
| 32 | #define PopupContainer_h |
| 33 | |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 34 | #include "PopupListBox.h" |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 35 | #include "platform/PopupMenuStyle.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 36 | #include "platform/geometry/FloatQuad.h" |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 37 | #include "platform/scroll/FramelessScrollView.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 38 | |
| 39 | namespace WebCore { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 40 | class ChromeClient; |
| 41 | class FrameView; |
| 42 | class PopupMenuClient; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 43 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 44 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 45 | namespace blink { |
| 46 | |
| 47 | struct WebPopupMenuInfo; |
| 48 | |
| 49 | class PopupContainer FINAL : public WebCore::FramelessScrollView { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 50 | public: |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 51 | static PassRefPtr<PopupContainer> create(WebCore::PopupMenuClient*, bool deviceSupportsTouch); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 52 | |
| 53 | // Whether a key event should be sent to this popup. |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 54 | bool isInterestedInEventForKey(int keyCode); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 55 | |
| 56 | // FramelessScrollView |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 57 | virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE; |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 58 | virtual void hide() OVERRIDE; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 59 | virtual bool handleMouseDownEvent(const WebCore::PlatformMouseEvent&) OVERRIDE; |
| 60 | virtual bool handleMouseMoveEvent(const WebCore::PlatformMouseEvent&) OVERRIDE; |
| 61 | virtual bool handleMouseReleaseEvent(const WebCore::PlatformMouseEvent&) OVERRIDE; |
| 62 | virtual bool handleWheelEvent(const WebCore::PlatformWheelEvent&) OVERRIDE; |
| 63 | virtual bool handleKeyEvent(const WebCore::PlatformKeyboardEvent&) OVERRIDE; |
| 64 | virtual bool handleTouchEvent(const WebCore::PlatformTouchEvent&) OVERRIDE; |
| 65 | virtual bool handleGestureEvent(const WebCore::PlatformGestureEvent&) OVERRIDE; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 66 | |
| 67 | // PopupContainer methods |
| 68 | |
| 69 | // Show the popup |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 70 | void showPopup(WebCore::FrameView*); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 71 | |
| 72 | // Show the popup in the specified rect for the specified frame. |
| 73 | // Note: this code was somehow arbitrarily factored-out of the Popup class |
| 74 | // so WebViewImpl can create a PopupContainer. This method is used for |
| 75 | // displaying auto complete popup menus on Mac Chromium, and for all |
| 76 | // popups on other platforms. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 77 | void showInRect(const WebCore::FloatQuad& controlPosition, const WebCore::IntSize& controlSize, WebCore::FrameView*, int index); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 78 | |
| 79 | // Hides the popup. |
| 80 | void hidePopup(); |
| 81 | |
| 82 | // The popup was hidden. |
| 83 | void notifyPopupHidden(); |
| 84 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 85 | PopupListBox* listBox() const { return m_listBox.get(); } |
| 86 | |
| 87 | bool isRTL() const; |
| 88 | |
| 89 | // Gets the index of the item that the user is currently moused-over or |
| 90 | // has selected with the keyboard up/down arrows. |
| 91 | int selectedIndex() const; |
| 92 | |
| 93 | // Refresh the popup values from the PopupMenuClient. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 94 | WebCore::IntRect refresh(const WebCore::IntRect& targetControlRect); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 95 | |
| 96 | // The menu per-item data. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 97 | const Vector<PopupItem*>& popupData() const; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 98 | |
| 99 | // The height of a row in the menu. |
| 100 | int menuItemHeight() const; |
| 101 | |
| 102 | // The size of the font being used. |
| 103 | int menuItemFontSize() const; |
| 104 | |
| 105 | // The style of the menu being used. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 106 | WebCore::PopupMenuStyle menuStyle() const; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 107 | |
| 108 | // While hovering popup menu window, we want to show tool tip message. |
| 109 | String getSelectedItemToolTip(); |
| 110 | |
| 111 | // This is public for testing. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 112 | static WebCore::IntRect layoutAndCalculateWidgetRectInternal(WebCore::IntRect widgetRectInScreen, int targetControlHeight, const WebCore::FloatRect& windowRect, const WebCore::FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const WebCore::IntSize& transformOffset, PopupContent*, bool& needToResizeView); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 113 | |
| 114 | private: |
| 115 | friend class WTF::RefCounted<PopupContainer>; |
| 116 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 117 | PopupContainer(WebCore::PopupMenuClient*, bool deviceSupportsTouch); |
| 118 | virtual ~PopupContainer(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 119 | |
| 120 | // Paint the border. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 121 | void paintBorder(WebCore::GraphicsContext*, const WebCore::IntRect&); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 122 | |
| 123 | // Layout and calculate popup widget size and location and returns it as IntRect. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 124 | WebCore::IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const WebCore::IntSize& transformOffset, const WebCore::IntPoint& popupInitialCoordinate); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 125 | |
| 126 | void fitToListBox(); |
| 127 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 128 | void popupOpened(const WebCore::IntRect& bounds); |
| 129 | void getPopupMenuInfo(WebPopupMenuInfo*); |
| 130 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 131 | // Returns the ChromeClient of the page this popup is associated with. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 132 | WebCore::ChromeClient& chromeClient(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 133 | |
| 134 | RefPtr<PopupListBox> m_listBox; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 135 | RefPtr<WebCore::FrameView> m_frameView; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 136 | |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 137 | // m_controlPosition contains the transformed position of the |
| 138 | // <select>/<input> associated with this popup. m_controlSize is the size |
| 139 | // of the <select>/<input> without transform. |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 140 | // The popup menu will be positioned as follows: |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 141 | // LTR : If the popup is positioned down it will align with the bottom left |
| 142 | // of m_controlPosition (p4) |
| 143 | // If the popup is positioned up it will align with the top left of |
| 144 | // m_controlPosition (p1) |
| 145 | // RTL : If the popup is positioned down it will align with the bottom right |
| 146 | // of m_controlPosition (p3) |
| 147 | // If the popup is positioned up it will align with the top right of |
| 148 | // m_controlPosition (p2) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 149 | WebCore::FloatQuad m_controlPosition; |
| 150 | WebCore::IntSize m_controlSize; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 151 | |
| 152 | // Whether the popup is currently open. |
| 153 | bool m_popupOpen; |
| 154 | }; |
| 155 | |
| 156 | } // namespace WebCore |
| 157 | |
| 158 | #endif |