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 "core/platform/chromium/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 41 namespace WebCore { 42 class Frame; 43 class FramelessScrollView; 44 class KeyboardEvent; 45 class Page; 46 class PlatformKeyboardEvent; 47 class Range; 48 class Widget; 49 } 50 51 namespace WebKit { 52 class WebGestureEvent; 53 class WebKeyboardEvent; 54 class WebMouseEvent; 55 class WebMouseWheelEvent; 56 class WebRange; 57 struct WebRect; 58 class WebTouchEvent; 59 60 class WebPopupMenuImpl : public WebPopupMenu, 61 public WebCore::FramelessScrollViewClient, 62 public RefCounted<WebPopupMenuImpl> { 63 WTF_MAKE_FAST_ALLOCATED; 64 public: 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 90 // WebPopupMenuImpl 91 void initialize(WebCore::FramelessScrollView* widget, const WebRect& bounds); 92 93 WebWidgetClient* client() { return m_client; } 94 95 void handleMouseMove(const WebMouseEvent&); 96 void handleMouseLeave(const WebMouseEvent&); 97 void handleMouseDown(const WebMouseEvent&); 98 void handleMouseUp(const WebMouseEvent&); 99 void handleMouseDoubleClick(const WebMouseEvent&); 100 void handleMouseWheel(const WebMouseWheelEvent&); 101 bool handleGestureEvent(const WebGestureEvent&); 102 bool handleTouchEvent(const WebTouchEvent&); 103 bool handleKeyEvent(const WebKeyboardEvent&); 104 105 protected: 106 friend class WebPopupMenu; // For WebPopupMenu::create. 107 friend class WTF::RefCounted<WebPopupMenuImpl>; 108 109 WebPopupMenuImpl(WebWidgetClient*); 110 ~WebPopupMenuImpl(); 111 112 // WebCore::HostWindow methods: 113 virtual void invalidateContentsAndRootView(const WebCore::IntRect&) OVERRIDE; 114 virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&) OVERRIDE; 115 virtual void scheduleAnimation() OVERRIDE; 116 virtual void scroll( 117 const WebCore::IntSize& scrollDelta, const WebCore::IntRect& scrollRect, 118 const WebCore::IntRect& clipRect) OVERRIDE; 119 virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const OVERRIDE; 120 virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const OVERRIDE; 121 virtual WebScreenInfo screenInfo() const OVERRIDE; 122 virtual void setCursor(const WebCore::Cursor&) 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 137 } // namespace WebKit 138 139 #endif 140