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 34 #include "platform/PopupMenuStyle.h" 35 #include "platform/geometry/FloatQuad.h" 36 #include "platform/scroll/FramelessScrollView.h" 37 #include "web/PopupListBox.h" 38 39 namespace WebCore { 40 class ChromeClient; 41 class FrameView; 42 class PopupMenuClient; 43 } 44 45 namespace blink { 46 47 struct WebPopupMenuInfo; 48 49 class PopupContainer FINAL : public WebCore::FramelessScrollView { 50 public: 51 static PassRefPtr<PopupContainer> create(WebCore::PopupMenuClient*, bool deviceSupportsTouch); 52 53 // Whether a key event should be sent to this popup. 54 bool isInterestedInEventForKey(int keyCode); 55 56 // FramelessScrollView 57 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE; 58 virtual void hide() OVERRIDE; 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; 66 67 // PopupContainer methods 68 69 // Show the popup 70 void showPopup(WebCore::FrameView*); 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. 77 void showInRect(const WebCore::FloatQuad& controlPosition, const WebCore::IntSize& controlSize, WebCore::FrameView*, int index); 78 79 // Hides the popup. 80 void hidePopup(); 81 82 // The popup was hidden. 83 void notifyPopupHidden(); 84 listBox()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. 94 WebCore::IntRect refresh(const WebCore::IntRect& targetControlRect); 95 96 // The menu per-item data. 97 const Vector<PopupItem*>& popupData() const; 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. 106 WebCore::PopupMenuStyle menuStyle() const; 107 108 // While hovering popup menu window, we want to show tool tip message. 109 String getSelectedItemToolTip(); 110 111 // This is public for testing. 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); 113 114 private: 115 friend class WTF::RefCounted<PopupContainer>; 116 117 PopupContainer(WebCore::PopupMenuClient*, bool deviceSupportsTouch); 118 virtual ~PopupContainer(); 119 120 // Paint the border. 121 void paintBorder(WebCore::GraphicsContext*, const WebCore::IntRect&); 122 123 // Layout and calculate popup widget size and location and returns it as IntRect. 124 WebCore::IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const WebCore::IntSize& transformOffset, const WebCore::IntPoint& popupInitialCoordinate); 125 126 void fitToListBox(); 127 128 void popupOpened(const WebCore::IntRect& bounds); 129 void getPopupMenuInfo(WebPopupMenuInfo*); 130 131 // Returns the ChromeClient of the page this popup is associated with. 132 WebCore::ChromeClient& chromeClient(); 133 134 RefPtr<PopupListBox> m_listBox; 135 RefPtr<WebCore::FrameView> m_frameView; 136 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. 140 // The popup menu will be positioned as follows: 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) 149 WebCore::FloatQuad m_controlPosition; 150 WebCore::IntSize m_controlSize; 151 152 // Whether the popup is currently open. 153 bool m_popupOpen; 154 }; 155 156 } // namespace WebCore 157 158 #endif 159