Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebFrameWidgetImpl.h
blobfb819fb6d4dc36d88e139f96b7b2714a173a8826
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef WebFrameWidgetImpl_h
32 #define WebFrameWidgetImpl_h
34 #include "platform/graphics/GraphicsLayer.h"
35 #include "platform/scroll/ScrollTypes.h"
36 #include "public/platform/WebPoint.h"
37 #include "public/platform/WebSize.h"
38 #include "public/web/WebFrameWidget.h"
39 #include "public/web/WebInputEvent.h"
40 #include "web/PageWidgetDelegate.h"
41 #include "web/WebLocalFrameImpl.h"
42 #include "web/WebViewImpl.h"
43 #include "wtf/Assertions.h"
44 #include "wtf/HashSet.h"
45 #include "wtf/OwnPtr.h"
46 #include "wtf/RefCounted.h"
48 namespace blink {
49 class Frame;
50 class Element;
51 class LocalFrame;
52 class Page;
53 class DeprecatedPaintLayerCompositor;
54 class UserGestureToken;
55 class WebCompositorAnimationTimeline;
56 class WebLayer;
57 class WebLayerTreeView;
58 class WebMouseEvent;
59 class WebMouseWheelEvent;
61 class WebFrameWidgetImpl final : public RefCountedWillBeGarbageCollectedFinalized<WebFrameWidgetImpl>
62 , public WebFrameWidget
63 , public PageWidgetEventHandler {
64 public:
65 static WebFrameWidgetImpl* create(WebWidgetClient*, WebLocalFrame*);
66 static HashSet<WebFrameWidgetImpl*>& allInstances();
68 // WebWidget functions:
69 void close() override;
70 WebSize size() override;
71 void willStartLiveResize() override;
72 void resize(const WebSize&) override;
73 void resizeVisualViewport(const WebSize&) override;
74 void resizePinchViewport(const WebSize&) override;
75 void willEndLiveResize() override;
76 void didEnterFullScreen() override;
77 void didExitFullScreen() override;
78 void beginFrame(const WebBeginFrameArgs&) override;
79 void layout() override;
80 void paint(WebCanvas*, const WebRect&) override;
81 void layoutAndPaintAsync(WebLayoutAndPaintAsyncCallback*) override;
82 void compositeAndReadbackAsync(WebCompositeAndReadbackAsyncCallback*) override;
83 void themeChanged() override;
84 bool handleInputEvent(const WebInputEvent&) override;
85 void setCursorVisibilityState(bool isVisible) override;
86 bool hasTouchEventHandlersAt(const WebPoint&) override;
88 void applyViewportDeltas(
89 const WebFloatSize& pinchViewportDelta,
90 const WebFloatSize& mainFrameDelta,
91 const WebFloatSize& elasticOverscrollDelta,
92 float pageScaleDelta,
93 float topControlsDelta) override;
94 void mouseCaptureLost() override;
95 void setFocus(bool enable) override;
96 bool setComposition(
97 const WebString& text,
98 const WebVector<WebCompositionUnderline>& underlines,
99 int selectionStart, int selectionEnd) override;
100 bool confirmComposition() override;
101 bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) override;
102 bool confirmComposition(const WebString& text) override;
103 bool compositionRange(size_t* location, size_t* length) override;
104 WebTextInputInfo textInputInfo() override;
105 WebColor backgroundColor() const override;
106 bool selectionBounds(WebRect& anchor, WebRect& focus) const override;
107 bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const override;
108 bool isSelectionAnchorFirst() const override;
109 bool caretOrSelectionRange(size_t* location, size_t* length) override;
110 void setTextDirection(WebTextDirection) override;
111 bool isAcceleratedCompositingActive() const override;
112 void willCloseLayerTreeView() override;
113 void didChangeWindowResizerRect() override;
115 WebWidgetClient* client() const { return m_client; }
117 Frame* focusedCoreFrame() const;
119 // Returns the currently focused Element or null if no element has focus.
120 Element* focusedElement() const;
122 void scheduleAnimation();
124 DeprecatedPaintLayerCompositor* compositor() const;
125 void setRootGraphicsLayer(GraphicsLayer*);
126 void attachCompositorAnimationTimeline(WebCompositorAnimationTimeline*);
127 void detachCompositorAnimationTimeline(WebCompositorAnimationTimeline*);
129 void setVisibilityState(WebPageVisibilityState, bool) override;
131 // Exposed for the purpose of overriding device metrics.
132 void sendResizeEventAndRepaint();
134 void updateMainFrameLayoutSize();
136 void setIgnoreInputEvents(bool newValue);
138 // Returns the page object associated with this widget. This may be null when
139 // the page is shutting down, but will be valid at all other times.
140 Page* page() const { return view()->page(); }
142 // Event related methods:
143 void mouseContextMenu(const WebMouseEvent&);
145 WebLayerTreeView* layerTreeView() const { return m_layerTreeView; }
147 // Returns true if the event leads to scrolling.
148 static bool mapKeyCodeForScroll(
149 int keyCode,
150 ScrollDirection*,
151 ScrollGranularity*);
153 DECLARE_TRACE();
155 private:
156 friend class WebFrameWidget; // For WebFrameWidget::create.
157 #if ENABLE(OILPAN)
158 friend class GarbageCollectedFinalized<WebFrameWidgetImpl>;
159 #else
160 friend class WTF::RefCounted<WebFrameWidgetImpl>;
161 #endif
163 explicit WebFrameWidgetImpl(WebWidgetClient*, WebLocalFrame*);
164 ~WebFrameWidgetImpl();
166 // Perform a hit test for a point relative to the root frame of the page.
167 HitTestResult hitTestResultForRootFramePos(const IntPoint& posInRootFrame);
169 // Returns true if the event was actually processed.
170 bool keyEventDefault(const WebKeyboardEvent&);
172 // Returns true if the view was scrolled.
173 bool scrollViewWithKeyboard(int keyCode, int modifiers);
175 void initializeLayerTreeView();
177 void setIsAcceleratedCompositingActive(bool);
178 void updateLayerTreeViewport();
179 void updateLayerTreeBackgroundColor();
180 void updateLayerTreeDeviceScaleFactor();
182 bool isTransparent() const;
184 // PageWidgetEventHandler functions
185 void handleMouseLeave(LocalFrame&, const WebMouseEvent&) override;
186 void handleMouseDown(LocalFrame&, const WebMouseEvent&) override;
187 void handleMouseUp(LocalFrame&, const WebMouseEvent&) override;
188 bool handleMouseWheel(LocalFrame&, const WebMouseWheelEvent&) override;
189 bool handleGestureEvent(const WebGestureEvent&) override;
190 bool handleKeyEvent(const WebKeyboardEvent&) override;
191 bool handleCharEvent(const WebKeyboardEvent&) override;
193 WebViewImpl* view() const { return m_localRoot->viewImpl(); }
195 WebWidgetClient* m_client;
197 // WebFrameWidget is associated with a subtree of the frame tree, corresponding to a maximal
198 // connected tree of LocalFrames. This member points to the root of that subtree.
199 RawPtrWillBeMember<WebLocalFrameImpl> m_localRoot;
201 WebSize m_size;
203 // If set, the (plugin) node which has mouse capture.
204 RefPtrWillBeMember<Node> m_mouseCaptureNode;
205 RefPtr<UserGestureToken> m_mouseCaptureGestureToken;
207 WebLayerTreeView* m_layerTreeView;
208 WebLayer* m_rootLayer;
209 GraphicsLayer* m_rootGraphicsLayer;
210 bool m_isAcceleratedCompositingActive;
211 bool m_layerTreeViewClosed;
213 bool m_suppressNextKeypressEvent;
215 bool m_ignoreInputEvents;
217 static const WebInputEvent* m_currentInputEvent;
219 #if ENABLE(OILPAN)
220 SelfKeepAlive<WebFrameWidgetImpl> m_selfKeepAlive;
221 #endif
224 DEFINE_TYPE_CASTS(WebFrameWidgetImpl, WebFrameWidget, widget, widget->forSubframe(), widget.forSubframe());
226 } // namespace blink
228 #endif