| OLD | NEW |
| (Empty) |
| 1 | |
| 2 /* | |
| 3 * Copyright (c) 2011, Google Inc. All rights reserved. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are | |
| 7 * met: | |
| 8 * | |
| 9 * * Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * * Redistributions in binary form must reproduce the above | |
| 12 * copyright notice, this list of conditions and the following disclaimer | |
| 13 * in the documentation and/or other materials provided with the | |
| 14 * distribution. | |
| 15 * * Neither the name of Google Inc. nor the names of its | |
| 16 * contributors may be used to endorse or promote products derived from | |
| 17 * this software without specific prior written permission. | |
| 18 * | |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 30 */ | |
| 31 | |
| 32 #ifndef PopupContainer_h | |
| 33 #define PopupContainer_h | |
| 34 | |
| 35 #include "platform/PopupMenuStyle.h" | |
| 36 #include "platform/geometry/FloatQuad.h" | |
| 37 #include "platform/heap/Handle.h" | |
| 38 #include "web/PopupListBox.h" | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 class ChromeClient; | |
| 43 class FrameView; | |
| 44 class PopupContainerClient; | |
| 45 class PopupMenuClient; | |
| 46 struct WebPopupMenuInfo; | |
| 47 | |
| 48 // This class wraps a PopupListBox. It positions the popup, paints the border | |
| 49 // around it, and forwards input events. | |
| 50 // FIXME(skobes): This class can probably be combined with PopupListBox. | |
| 51 class PopupContainer final : public Widget { | |
| 52 public: | |
| 53 static PassRefPtrWillBeRawPtr<PopupContainer> create(PopupMenuClient*, bool
deviceSupportsTouch); | |
| 54 | |
| 55 // Whether a key event should be sent to this popup. | |
| 56 bool isInterestedInEventForKey(int keyCode); | |
| 57 | |
| 58 // Widget | |
| 59 virtual void paint(GraphicsContext*, const IntRect&) override; | |
| 60 virtual void hide() override; | |
| 61 virtual HostWindow* hostWindow() const override; | |
| 62 virtual void invalidateRect(const IntRect&) override; | |
| 63 virtual IntPoint convertChildToSelf(const Widget* child, const IntPoint&) co
nst override; | |
| 64 virtual IntPoint convertSelfToChild(const Widget* child, const IntPoint&) co
nst override; | |
| 65 | |
| 66 // PopupContainer methods | |
| 67 | |
| 68 bool handleMouseDownEvent(const PlatformMouseEvent&); | |
| 69 bool handleMouseMoveEvent(const PlatformMouseEvent&); | |
| 70 bool handleMouseReleaseEvent(const PlatformMouseEvent&); | |
| 71 bool handleWheelEvent(const PlatformWheelEvent&); | |
| 72 bool handleKeyEvent(const PlatformKeyboardEvent&); | |
| 73 bool handleTouchEvent(const PlatformTouchEvent&); | |
| 74 bool handleGestureEvent(const PlatformGestureEvent&); | |
| 75 | |
| 76 PopupContainerClient* client() const { return m_client; } | |
| 77 void setClient(PopupContainerClient* client) { m_client = client; } | |
| 78 | |
| 79 // Show the popup | |
| 80 void showPopup(FrameView*); | |
| 81 | |
| 82 // Show the popup in the specified rect for the specified frame. | |
| 83 // Note: this code was somehow arbitrarily factored-out of the Popup class | |
| 84 // so WebViewImpl can create a PopupContainer. This method is used for | |
| 85 // displaying auto complete popup menus on Mac Chromium, and for all | |
| 86 // popups on other platforms. | |
| 87 void showInRect(const FloatQuad& controlPosition, const IntSize& controlSize
, FrameView*, int index); | |
| 88 | |
| 89 // Hides the popup. | |
| 90 void hidePopup(); | |
| 91 | |
| 92 // The popup was hidden. | |
| 93 void notifyPopupHidden(); | |
| 94 | |
| 95 PopupListBox* listBox() const { return m_listBox.get(); } | |
| 96 | |
| 97 bool isRTL() const; | |
| 98 | |
| 99 // Gets the index of the item that the user is currently moused-over or | |
| 100 // has selected with the keyboard up/down arrows. | |
| 101 int selectedIndex() const; | |
| 102 | |
| 103 // Refresh the popup values from the PopupMenuClient. | |
| 104 IntRect refresh(const IntRect& targetControlRect); | |
| 105 | |
| 106 // The menu per-item data. | |
| 107 const Vector<PopupItem*>& popupData() const; | |
| 108 | |
| 109 // The height of a row in the menu. | |
| 110 int menuItemHeight() const; | |
| 111 | |
| 112 // The size of the font being used. | |
| 113 int menuItemFontSize() const; | |
| 114 | |
| 115 // The style of the menu being used. | |
| 116 PopupMenuStyle menuStyle() const; | |
| 117 | |
| 118 // While hovering popup menu window, we want to show tool tip message. | |
| 119 String getSelectedItemToolTip(); | |
| 120 | |
| 121 // This is public for testing. | |
| 122 static IntRect layoutAndCalculateWidgetRectInternal(IntRect widgetRectInScre
en, int targetControlHeight, const FloatRect& windowRect, const FloatRect& scree
n, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& tra
nsformOffset, PopupContent*, bool& needToResizeView); | |
| 123 | |
| 124 void disconnectClient() { m_listBox->disconnectClient(); } | |
| 125 | |
| 126 void updateFromElement() { m_listBox->updateFromElement(); } | |
| 127 | |
| 128 virtual void trace(Visitor*) override; | |
| 129 | |
| 130 private: | |
| 131 friend class WTF::RefCounted<PopupContainer>; | |
| 132 | |
| 133 PopupContainer(PopupMenuClient*, bool deviceSupportsTouch); | |
| 134 virtual ~PopupContainer(); | |
| 135 | |
| 136 // Paint the border. | |
| 137 void paintBorder(GraphicsContext*, const IntRect&); | |
| 138 | |
| 139 // Layout and calculate popup widget size and location and returns it as Int
Rect. | |
| 140 IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const IntSize&
transformOffset, const IntPoint& popupInitialCoordinate); | |
| 141 | |
| 142 void fitToListBox(); | |
| 143 | |
| 144 void popupOpened(const IntRect& bounds); | |
| 145 void getPopupMenuInfo(WebPopupMenuInfo*); | |
| 146 | |
| 147 // Returns the ChromeClient of the page this popup is associated with. | |
| 148 ChromeClient& chromeClient(); | |
| 149 | |
| 150 RefPtrWillBeMember<PopupListBox> m_listBox; | |
| 151 RefPtrWillBeMember<FrameView> m_frameView; | |
| 152 | |
| 153 // m_controlPosition contains the transformed position of the | |
| 154 // <select>/<input> associated with this popup. m_controlSize is the size | |
| 155 // of the <select>/<input> without transform. | |
| 156 // The popup menu will be positioned as follows: | |
| 157 // LTR : If the popup is positioned down it will align with the bottom left | |
| 158 // of m_controlPosition (p4) | |
| 159 // If the popup is positioned up it will align with the top left of | |
| 160 // m_controlPosition (p1) | |
| 161 // RTL : If the popup is positioned down it will align with the bottom right | |
| 162 // of m_controlPosition (p3) | |
| 163 // If the popup is positioned up it will align with the top right of | |
| 164 // m_controlPosition (p2) | |
| 165 FloatQuad m_controlPosition; | |
| 166 IntSize m_controlSize; | |
| 167 | |
| 168 // Whether the popup is currently open. | |
| 169 bool m_popupOpen; | |
| 170 | |
| 171 PopupContainerClient* m_client; | |
| 172 }; | |
| 173 | |
| 174 } // namespace blink | |
| 175 | |
| 176 #endif | |
| OLD | NEW |