Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 34 | #include "WebPopupMenu.h" |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 35 | #include "platform/scroll/FramelessScrollViewClient.h" |
| 36 | #include "public/platform/WebContentLayerClient.h" |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 37 | #include "public/platform/WebPoint.h" |
| 38 | #include "public/platform/WebSize.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 39 | #include "wtf/OwnPtr.h" |
| 40 | #include "wtf/RefCounted.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 41 | |
| 42 | namespace WebCore { |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 43 | class LocalFrame; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 44 | class FramelessScrollView; |
| 45 | class KeyboardEvent; |
| 46 | class Page; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 47 | class PlatformKeyboardEvent; |
| 48 | class Range; |
| 49 | class Widget; |
| 50 | } |
| 51 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 52 | namespace blink { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 53 | class WebContentLayer; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 54 | class WebGestureEvent; |
| 55 | class WebKeyboardEvent; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 56 | class WebLayerTreeView; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 57 | class WebMouseEvent; |
| 58 | class WebMouseWheelEvent; |
| 59 | class WebRange; |
| 60 | struct WebRect; |
| 61 | class WebTouchEvent; |
| 62 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 63 | class WebPopupMenuImpl : public WebPopupMenu, public WebCore::FramelessScrollViewClient, public WebContentLayerClient, public RefCounted<WebPopupMenuImpl> { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 64 | WTF_MAKE_FAST_ALLOCATED; |
| 65 | public: |
| 66 | // WebWidget functions: |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 67 | virtual void close() OVERRIDE FINAL; |
| 68 | virtual WebSize size() OVERRIDE FINAL { return m_size; } |
| 69 | virtual void willStartLiveResize() OVERRIDE FINAL; |
| 70 | virtual void resize(const WebSize&) OVERRIDE FINAL; |
| 71 | virtual void willEndLiveResize() OVERRIDE FINAL; |
| 72 | virtual void animate(double frameBeginTime) OVERRIDE FINAL; |
| 73 | virtual void layout() OVERRIDE FINAL; |
| 74 | virtual void enterForceCompositingMode(bool enable) OVERRIDE FINAL; |
| 75 | virtual void didExitCompositingMode() OVERRIDE FINAL; |
| 76 | virtual void paint(WebCanvas*, const WebRect&, PaintOptions = ReadbackFromCompositorIfAvailable) OVERRIDE FINAL; |
| 77 | virtual void themeChanged() OVERRIDE FINAL; |
| 78 | virtual bool handleInputEvent(const WebInputEvent&) OVERRIDE FINAL; |
| 79 | virtual void mouseCaptureLost() OVERRIDE FINAL; |
| 80 | virtual void setFocus(bool enable) OVERRIDE FINAL; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 81 | virtual bool setComposition( |
| 82 | const WebString& text, |
| 83 | const WebVector<WebCompositionUnderline>& underlines, |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 84 | int selectionStart, int selectionEnd) OVERRIDE FINAL; |
| 85 | virtual bool confirmComposition() OVERRIDE FINAL; |
| 86 | virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) OVERRIDE FINAL; |
| 87 | virtual bool confirmComposition(const WebString& text) OVERRIDE FINAL; |
| 88 | virtual bool compositionRange(size_t* location, size_t* length) OVERRIDE FINAL; |
| 89 | virtual bool caretOrSelectionRange(size_t* location, size_t* length) OVERRIDE FINAL; |
| 90 | virtual void setTextDirection(WebTextDirection) OVERRIDE FINAL; |
| 91 | virtual bool isAcceleratedCompositingActive() const OVERRIDE FINAL { return false; } |
| 92 | virtual bool isPopupMenu() const OVERRIDE FINAL { return true; } |
| 93 | virtual void willCloseLayerTreeView() OVERRIDE FINAL; |
| 94 | |
| 95 | // WebContentLayerClient |
| 96 | virtual void paintContents(WebCanvas*, const WebRect& clip, bool canPaintLCDTest, WebFloatRect& opaque) OVERRIDE FINAL; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 97 | |
| 98 | // WebPopupMenuImpl |
Torne (Richard Coles) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 99 | void initialize(WebCore::FramelessScrollView* widget, const WebRect& bounds); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 100 | |
| 101 | WebWidgetClient* client() { return m_client; } |
| 102 | |
| 103 | void handleMouseMove(const WebMouseEvent&); |
| 104 | void handleMouseLeave(const WebMouseEvent&); |
| 105 | void handleMouseDown(const WebMouseEvent&); |
| 106 | void handleMouseUp(const WebMouseEvent&); |
| 107 | void handleMouseDoubleClick(const WebMouseEvent&); |
| 108 | void handleMouseWheel(const WebMouseWheelEvent&); |
| 109 | bool handleGestureEvent(const WebGestureEvent&); |
| 110 | bool handleTouchEvent(const WebTouchEvent&); |
| 111 | bool handleKeyEvent(const WebKeyboardEvent&); |
| 112 | |
| 113 | protected: |
| 114 | friend class WebPopupMenu; // For WebPopupMenu::create. |
| 115 | friend class WTF::RefCounted<WebPopupMenuImpl>; |
| 116 | |
| 117 | WebPopupMenuImpl(WebWidgetClient*); |
| 118 | ~WebPopupMenuImpl(); |
| 119 | |
| 120 | // WebCore::HostWindow methods: |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 121 | virtual void invalidateContentsAndRootView(const WebCore::IntRect&) OVERRIDE FINAL; |
| 122 | virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&) OVERRIDE FINAL; |
| 123 | virtual void scheduleAnimation() OVERRIDE FINAL; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 124 | virtual void scroll( |
| 125 | const WebCore::IntSize& scrollDelta, const WebCore::IntRect& scrollRect, |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 126 | const WebCore::IntRect& clipRect) OVERRIDE FINAL; |
| 127 | virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const OVERRIDE FINAL; |
| 128 | virtual WebScreenInfo screenInfo() const OVERRIDE FINAL; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 129 | |
| 130 | // WebCore::FramelessScrollViewClient methods: |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 131 | virtual void popupClosed(WebCore::FramelessScrollView*) OVERRIDE FINAL; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 132 | |
| 133 | WebWidgetClient* m_client; |
| 134 | WebSize m_size; |
| 135 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 136 | WebLayerTreeView* m_layerTreeView; |
| 137 | OwnPtr<WebContentLayer> m_rootLayer; |
| 138 | bool m_isAcceleratedCompositingActive; |
| 139 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 140 | WebPoint m_lastMousePosition; |
| 141 | |
| 142 | // This is a non-owning ref. The popup will notify us via popupClosed() |
| 143 | // before it is destroyed. |
| 144 | WebCore::FramelessScrollView* m_widget; |
| 145 | }; |
| 146 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 147 | DEFINE_TYPE_CASTS(WebPopupMenuImpl, WebWidget, widget, widget->isPopupMenu(), widget.isPopupMenu()); |
| 148 | // WebPopupMenuImpl is the only implementation of FramelessScrollViewClient, so |
| 149 | // no need for further checking. |
| 150 | DEFINE_TYPE_CASTS(WebPopupMenuImpl, WebCore::FramelessScrollViewClient, client, true, true); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 151 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 152 | } // namespace blink |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 153 | |
| 154 | #endif |