1/* 2 * Copyright (C) 2009 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 WebPopupMenuImpl_h 32#define WebPopupMenuImpl_h 33 34#include "WebPopupMenu.h" 35#include "platform/scroll/FramelessScrollViewClient.h" 36#include "public/platform/WebPoint.h" 37#include "public/platform/WebSize.h" 38#include "wtf/OwnPtr.h" 39#include "wtf/RefCounted.h" 40 41namespace WebCore { 42class Frame; 43class FramelessScrollView; 44class KeyboardEvent; 45class Page; 46class PlatformKeyboardEvent; 47class Range; 48class Widget; 49} 50 51namespace blink { 52class WebGestureEvent; 53class WebKeyboardEvent; 54class WebMouseEvent; 55class WebMouseWheelEvent; 56class WebRange; 57struct WebRect; 58class WebTouchEvent; 59 60class WebPopupMenuImpl : public WebPopupMenu, 61 public WebCore::FramelessScrollViewClient, 62 public RefCounted<WebPopupMenuImpl> { 63 WTF_MAKE_FAST_ALLOCATED; 64public: 65 // WebWidget functions: 66 virtual void close() OVERRIDE; 67 virtual WebSize size() OVERRIDE { return m_size; } 68 virtual void willStartLiveResize() OVERRIDE; 69 virtual void resize(const WebSize&) OVERRIDE; 70 virtual void willEndLiveResize() OVERRIDE; 71 virtual void animate(double frameBeginTime) OVERRIDE; 72 virtual void layout() OVERRIDE; 73 virtual void paint(WebCanvas*, const WebRect&, PaintOptions = ReadbackFromCompositorIfAvailable) OVERRIDE; 74 virtual void themeChanged() OVERRIDE; 75 virtual bool handleInputEvent(const WebInputEvent&) OVERRIDE; 76 virtual void mouseCaptureLost() OVERRIDE; 77 virtual void setFocus(bool enable) OVERRIDE; 78 virtual bool setComposition( 79 const WebString& text, 80 const WebVector<WebCompositionUnderline>& underlines, 81 int selectionStart, int selectionEnd) OVERRIDE; 82 virtual bool confirmComposition() OVERRIDE; 83 virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) OVERRIDE; 84 virtual bool confirmComposition(const WebString& text) OVERRIDE; 85 virtual bool compositionRange(size_t* location, size_t* length) OVERRIDE; 86 virtual bool caretOrSelectionRange(size_t* location, size_t* length) OVERRIDE; 87 virtual void setTextDirection(WebTextDirection) OVERRIDE; 88 virtual bool isAcceleratedCompositingActive() const OVERRIDE { return false; } 89 virtual bool isPopupMenu() const OVERRIDE { return true; } 90 91 // WebPopupMenuImpl 92 void initialize(WebCore::FramelessScrollView* widget, const WebRect& bounds); 93 94 WebWidgetClient* client() { return m_client; } 95 96 void handleMouseMove(const WebMouseEvent&); 97 void handleMouseLeave(const WebMouseEvent&); 98 void handleMouseDown(const WebMouseEvent&); 99 void handleMouseUp(const WebMouseEvent&); 100 void handleMouseDoubleClick(const WebMouseEvent&); 101 void handleMouseWheel(const WebMouseWheelEvent&); 102 bool handleGestureEvent(const WebGestureEvent&); 103 bool handleTouchEvent(const WebTouchEvent&); 104 bool handleKeyEvent(const WebKeyboardEvent&); 105 106 protected: 107 friend class WebPopupMenu; // For WebPopupMenu::create. 108 friend class WTF::RefCounted<WebPopupMenuImpl>; 109 110 WebPopupMenuImpl(WebWidgetClient*); 111 ~WebPopupMenuImpl(); 112 113 // WebCore::HostWindow methods: 114 virtual void invalidateContentsAndRootView(const WebCore::IntRect&) OVERRIDE; 115 virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&) OVERRIDE; 116 virtual void scheduleAnimation() OVERRIDE; 117 virtual void scroll( 118 const WebCore::IntSize& scrollDelta, const WebCore::IntRect& scrollRect, 119 const WebCore::IntRect& clipRect) OVERRIDE; 120 virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const OVERRIDE; 121 virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const OVERRIDE; 122 virtual WebScreenInfo screenInfo() const OVERRIDE; 123 124 // WebCore::FramelessScrollViewClient methods: 125 virtual void popupClosed(WebCore::FramelessScrollView*) OVERRIDE; 126 127 WebWidgetClient* m_client; 128 WebSize m_size; 129 130 WebPoint m_lastMousePosition; 131 132 // This is a non-owning ref. The popup will notify us via popupClosed() 133 // before it is destroyed. 134 WebCore::FramelessScrollView* m_widget; 135}; 136 137inline WebPopupMenuImpl* toWebPopupMenuImpl(WebWidget* widget) 138{ 139 ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isPopupMenu()); 140 return static_cast<WebPopupMenuImpl*>(widget); 141} 142 143inline WebPopupMenuImpl* toWebPopupMenuImpl(WebCore::FramelessScrollViewClient* client) 144{ 145 // WebPopupMenuImpl is the only implementation of FramelessScrollViewClient, 146 // so no need for further checking. 147 return static_cast<WebPopupMenuImpl*>(client); 148} 149 150} // namespace blink 151 152#endif 153