Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_base.h
blobc858f5e650611d01c599f1983ffe3d0709df1c96
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_
8 #if defined(OS_MACOSX)
9 #include <OpenGL/OpenGL.h>
10 #endif
12 #include <string>
13 #include <vector>
15 #include "base/callback_forward.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/process/kill.h"
18 #include "base/timer/timer.h"
19 #include "cc/output/compositor_frame.h"
20 #include "content/browser/renderer_host/event_with_latency_info.h"
21 #include "content/common/content_export.h"
22 #include "content/common/input/input_event_ack_state.h"
23 #include "content/public/browser/readback_types.h"
24 #include "content/public/browser/render_widget_host_view.h"
25 #include "ipc/ipc_listener.h"
26 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
27 #include "third_party/WebKit/public/web/WebPopupType.h"
28 #include "third_party/WebKit/public/web/WebTextDirection.h"
29 #include "ui/base/ime/text_input_mode.h"
30 #include "ui/base/ime/text_input_type.h"
31 #include "ui/gfx/display.h"
32 #include "ui/gfx/geometry/rect.h"
33 #include "ui/gfx/native_widget_types.h"
34 #include "ui/gfx/range/range.h"
35 #include "ui/surface/transport_dib.h"
37 class SkBitmap;
39 struct AccessibilityHostMsg_EventParams;
40 struct ViewHostMsg_SelectionBounds_Params;
42 namespace media {
43 class VideoFrame;
46 namespace blink {
47 struct WebScreenInfo;
50 namespace content {
51 class BrowserAccessibilityDelegate;
52 class BrowserAccessibilityManager;
53 class SyntheticGesture;
54 class SyntheticGestureTarget;
55 class WebCursor;
56 struct DidOverscrollParams;
57 struct NativeWebKeyboardEvent;
58 struct WebPluginGeometry;
60 // Basic implementation shared by concrete RenderWidgetHostView subclasses.
61 class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView,
62 public IPC::Listener {
63 public:
64 ~RenderWidgetHostViewBase() override;
66 // RenderWidgetHostView implementation.
67 void SetBackgroundColor(SkColor color) override;
68 void SetBackgroundColorToDefault() final;
69 bool GetBackgroundOpaque() override;
70 ui::TextInputClient* GetTextInputClient() override;
71 void WasUnOccluded() override {}
72 void WasOccluded() override {}
73 bool IsShowingContextMenu() const override;
74 void SetShowingContextMenu(bool showing_menu) override;
75 base::string16 GetSelectedText() const override;
76 bool IsMouseLocked() override;
77 gfx::Size GetVisibleViewportSize() const override;
78 void SetInsets(const gfx::Insets& insets) override;
79 void BeginFrameSubscription(
80 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) override;
81 void EndFrameSubscription() override;
83 // IPC::Listener implementation:
84 bool OnMessageReceived(const IPC::Message& msg) override;
86 void SetPopupType(blink::WebPopupType popup_type);
88 blink::WebPopupType GetPopupType();
90 // Return a value that is incremented each time the renderer swaps a new frame
91 // to the view.
92 uint32 RendererFrameNumber();
94 // Called each time the RenderWidgetHost receives a new frame for display from
95 // the renderer.
96 void DidReceiveRendererFrame();
98 // Notification that a resize or move session ended on the native widget.
99 void UpdateScreenInfo(gfx::NativeView view);
101 // Tells if the display property (work area/scale factor) has
102 // changed since the last time.
103 bool HasDisplayPropertyChanged(gfx::NativeView view);
105 base::WeakPtr<RenderWidgetHostViewBase> GetWeakPtr();
107 //----------------------------------------------------------------------------
108 // The following methods can be overridden by derived classes.
110 // Notifies the View that the renderer text selection has changed.
111 virtual void SelectionChanged(const base::string16& text,
112 size_t offset,
113 const gfx::Range& range);
115 // The requested size of the renderer. May differ from GetViewBounds().size()
116 // when the view requires additional throttling.
117 virtual gfx::Size GetRequestedRendererSize() const;
119 // The size of the view's backing surface in non-DPI-adjusted pixels.
120 virtual gfx::Size GetPhysicalBackingSize() const;
122 // Whether or not Blink's viewport size should be shrunk by the height of the
123 // URL-bar.
124 virtual bool DoTopControlsShrinkBlinkSize() const;
126 // The height of the URL-bar top controls.
127 virtual float GetTopControlsHeight() const;
129 // Called prior to forwarding input event messages to the renderer, giving
130 // the view a chance to perform in-process event filtering or processing.
131 // Return values of |NOT_CONSUMED| or |UNKNOWN| will result in |input_event|
132 // being forwarded.
133 virtual InputEventAckState FilterInputEvent(
134 const blink::WebInputEvent& input_event);
136 // Called by the host when it requires an input flush; the flush call should
137 // by synchronized with BeginFrame.
138 virtual void OnSetNeedsFlushInput();
140 virtual void WheelEventAck(const blink::WebMouseWheelEvent& event,
141 InputEventAckState ack_result);
143 virtual void GestureEventAck(const blink::WebGestureEvent& event,
144 InputEventAckState ack_result);
146 // Create a platform specific SyntheticGestureTarget implementation that will
147 // be used to inject synthetic input events.
148 virtual scoped_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget();
150 // Return true if frame subscription is supported on this platform.
151 virtual bool CanSubscribeFrame() const;
153 // Create a BrowserAccessibilityManager for this view.
154 virtual BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
155 BrowserAccessibilityDelegate* delegate);
157 virtual void AccessibilityShowMenu(const gfx::Point& point);
158 virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds);
159 virtual gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget();
160 virtual gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible();
162 virtual SkColorType PreferredReadbackFormat();
164 // Informs that the focused DOM node has changed.
165 virtual void FocusedNodeChanged(bool is_editable_node) {}
167 virtual void OnSwapCompositorFrame(uint32 output_surface_id,
168 scoped_ptr<cc::CompositorFrame> frame) {}
170 // Because the associated remote WebKit instance can asynchronously
171 // prevent-default on a dispatched touch event, the touch events are queued in
172 // the GestureRecognizer until invocation of ProcessAckedTouchEvent releases
173 // it to be consumed (when |ack_result| is NOT_CONSUMED OR NO_CONSUMER_EXISTS)
174 // or ignored (when |ack_result| is CONSUMED).
175 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch,
176 InputEventAckState ack_result) {}
178 virtual void DidOverscroll(const DidOverscrollParams& params) {}
180 virtual void DidStopFlinging() {}
182 //----------------------------------------------------------------------------
183 // The following static methods are implemented by each platform.
185 static void GetDefaultScreenInfo(blink::WebScreenInfo* results);
187 //----------------------------------------------------------------------------
188 // The following pure virtual methods are implemented by derived classes.
190 // Perform all the initialization steps necessary for this object to represent
191 // a popup (such as a <select> dropdown), then shows the popup at |pos|.
192 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
193 const gfx::Rect& bounds) = 0;
195 // Perform all the initialization steps necessary for this object to represent
196 // a full screen window.
197 // |reference_host_view| is the view associated with the creating page that
198 // helps to position the full screen widget on the correct monitor.
199 virtual void InitAsFullscreen(RenderWidgetHostView* reference_host_view) = 0;
201 // Moves all plugin windows as described in the given list.
202 // |scroll_offset| is the scroll offset of the render view.
203 virtual void MovePluginWindows(
204 const std::vector<WebPluginGeometry>& moves) = 0;
206 // Take focus from the associated View component.
207 virtual void Blur() = 0;
209 // Sets the cursor to the one associated with the specified cursor_type
210 virtual void UpdateCursor(const WebCursor& cursor) = 0;
212 // Indicates whether the page has finished loading.
213 virtual void SetIsLoading(bool is_loading) = 0;
215 // Updates the type of the input method attached to the view.
216 virtual void TextInputTypeChanged(ui::TextInputType type,
217 ui::TextInputMode mode,
218 bool can_compose_inline,
219 int flags) = 0;
221 // Cancel the ongoing composition of the input method attached to the view.
222 virtual void ImeCancelComposition() = 0;
224 // Notifies the View that the renderer has ceased to exist.
225 virtual void RenderProcessGone(base::TerminationStatus status,
226 int error_code) = 0;
228 // Notifies the View that the renderer's host has ceased to exist.
229 // The default implementation of this is a no-op. This hack exists to fix
230 // a crash on the branch.
231 // TODO(ccameron): Clean this up.
232 // http://crbug.com/404828
233 virtual void RenderWidgetHostGone() {}
235 // Tells the View to destroy itself.
236 virtual void Destroy() = 0;
238 // Tells the View that the tooltip text for the current mouse position over
239 // the page has changed.
240 virtual void SetTooltipText(const base::string16& tooltip_text) = 0;
242 // Notifies the View that the renderer selection bounds has changed.
243 // |start_rect| and |end_rect| are the bounds end of the selection in the
244 // coordinate system of the render view. |start_direction| and |end_direction|
245 // indicates the direction at which the selection was made on touch devices.
246 virtual void SelectionBoundsChanged(
247 const ViewHostMsg_SelectionBounds_Params& params) = 0;
249 // Copies the contents of the compositing surface, providing a new SkBitmap
250 // result via an asynchronously-run |callback|. |src_subrect| is specified in
251 // layer space coordinates for the current platform (e.g., DIP for Aura/Mac,
252 // physical for Android), and is the region to be copied from this view. When
253 // |src_subrect| is empty then the whole surface will be copied. The copy is
254 // then scaled to a SkBitmap of size |dst_size|. If |dst_size| is empty then
255 // output will be unscaled. |callback| is run with true on success,
256 // false otherwise. A smaller region than |src_subrect| may be copied
257 // if the underlying surface is smaller than |src_subrect|.
258 virtual void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
259 const gfx::Size& dst_size,
260 ReadbackRequestCallback& callback,
261 const SkColorType color_type) = 0;
263 // Copies the contents of the compositing surface, populating the given
264 // |target| with YV12 image data. |src_subrect| is specified in layer space
265 // coordinates for the current platform (e.g., DIP for Aura/Mac, physical for
266 // Android), and is the region to be copied from this view. The copy is then
267 // scaled and letterboxed with black borders to fit |target|. Finally,
268 // |callback| is asynchronously run with true/false for
269 // success/failure. |target| must point to an allocated, YV12 video frame of
270 // the intended size. This operation will fail if there is no available
271 // compositing surface.
272 virtual void CopyFromCompositingSurfaceToVideoFrame(
273 const gfx::Rect& src_subrect,
274 const scoped_refptr<media::VideoFrame>& target,
275 const base::Callback<void(bool)>& callback) = 0;
277 // Returns true if CopyFromCompositingSurfaceToVideoFrame() is likely to
278 // succeed.
280 // TODO(nick): When VideoFrame copies are broadly implemented, this method
281 // should be renamed to HasCompositingSurface(), or unified with
282 // IsSurfaceAvailableForCopy() and HasAcceleratedSurface().
283 virtual bool CanCopyToVideoFrame() const = 0;
285 // DEPRECATED. Called when an accelerated compositing surface is initialized.
286 virtual void AcceleratedSurfaceInitialized(int route_id) {}
288 // Return true if the view has an accelerated surface that contains the last
289 // presented frame for the view. If |desired_size| is non-empty, true is
290 // returned only if the accelerated surface size matches.
291 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) = 0;
293 // Compute the orientation type of the display assuming it is a mobile device.
294 static blink::WebScreenOrientationType GetOrientationTypeForMobile(
295 const gfx::Display& display);
297 // Compute the orientation type of the display assuming it is a desktop.
298 static blink::WebScreenOrientationType GetOrientationTypeForDesktop(
299 const gfx::Display& display);
301 virtual void GetScreenInfo(blink::WebScreenInfo* results) = 0;
303 // Gets the bounds of the window, in screen coordinates.
304 virtual gfx::Rect GetBoundsInRootWindow() = 0;
306 virtual gfx::GLSurfaceHandle GetCompositingSurface() = 0;
308 // Called by the RenderFrameHost when it receives an IPC response to a
309 // TextSurroundingSelectionRequest.
310 virtual void OnTextSurroundingSelectionResponse(const base::string16& content,
311 size_t start_offset,
312 size_t end_offset);
314 // Called by the RenderWidgetHost when an ambiguous gesture is detected to
315 // show the disambiguation popup bubble.
316 virtual void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
317 const SkBitmap& zoomed_bitmap);
319 // Called by the WebContentsImpl when a user tries to navigate a new page on
320 // main frame.
321 virtual void OnDidNavigateMainFrameToNewPage();
323 #if defined(OS_ANDROID)
324 // Instructs the view to not drop the surface even when the view is hidden.
325 virtual void LockCompositingSurface() = 0;
326 virtual void UnlockCompositingSurface() = 0;
327 #endif
329 #if defined(OS_MACOSX)
330 // Does any event handling necessary for plugin IME; should be called after
331 // the plugin has already had a chance to process the event. If plugin IME is
332 // not enabled, this is a no-op, so it is always safe to call.
333 // Returns true if the event was handled by IME.
334 virtual bool PostProcessEventForPluginIme(
335 const NativeWebKeyboardEvent& event) = 0;
336 #endif
338 // Updates the range of the marked text in an IME composition.
339 virtual void ImeCompositionRangeChanged(
340 const gfx::Range& range,
341 const std::vector<gfx::Rect>& character_bounds) = 0;
343 #if defined(OS_WIN)
344 virtual void SetParentNativeViewAccessible(
345 gfx::NativeViewAccessible accessible_parent) = 0;
347 // Returns an HWND that's given as the parent window for windowless Flash to
348 // workaround crbug.com/301548.
349 virtual gfx::NativeViewId GetParentForWindowlessPlugin() const = 0;
351 // The callback that DetachPluginsHelper calls for each child window. Call
352 // this directly if you want to do custom filtering on plugin windows first.
353 static void DetachPluginWindowsCallback(HWND window);
354 #endif
356 protected:
357 // Interface class only, do not construct.
358 RenderWidgetHostViewBase();
360 #if defined(OS_WIN)
361 // Shared implementation of MovePluginWindows for use by win and aura/wina.
362 static void MovePluginWindowsHelper(
363 HWND parent,
364 const std::vector<WebPluginGeometry>& moves);
366 static void PaintPluginWindowsHelper(
367 HWND parent,
368 const gfx::Rect& damaged_screen_rect);
370 // Needs to be called before the HWND backing the view goes away to avoid
371 // crashes in Windowed plugins.
372 static void DetachPluginsHelper(HWND parent);
373 #endif
375 // Whether this view is a popup and what kind of popup it is (select,
376 // autofill...).
377 blink::WebPopupType popup_type_;
379 // The background color of the web content.
380 SkColor background_color_;
382 // While the mouse is locked, the cursor is hidden from the user. Mouse events
383 // are still generated. However, the position they report is the last known
384 // mouse position just as mouse lock was entered; the movement they report
385 // indicates what the change in position of the mouse would be had it not been
386 // locked.
387 bool mouse_locked_;
389 // Whether we are showing a context menu.
390 bool showing_context_menu_;
392 // A buffer containing the text inside and around the current selection range.
393 base::string16 selection_text_;
395 // The offset of the text stored in |selection_text_| relative to the start of
396 // the web page.
397 size_t selection_text_offset_;
399 // The current selection range relative to the start of the web page.
400 gfx::Range selection_range_;
402 protected:
403 // The scale factor of the display the renderer is currently on.
404 float current_device_scale_factor_;
406 // The orientation of the display the renderer is currently on.
407 gfx::Display::Rotation current_display_rotation_;
409 // Whether pinch-to-zoom should be enabled and pinch events forwarded to the
410 // renderer.
411 bool pinch_zoom_enabled_;
413 private:
414 void FlushInput();
416 gfx::Rect current_display_area_;
418 uint32 renderer_frame_number_;
420 base::OneShotTimer<RenderWidgetHostViewBase> flush_input_timer_;
422 base::WeakPtrFactory<RenderWidgetHostViewBase> weak_factory_;
424 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewBase);
427 } // namespace content
429 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_BASE_H_