cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / browser / frame_host / render_widget_host_view_guest.h
blob4c16d35ce07672f6b97837ea4ead305d9a098aff
1 // Copyright 2014 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_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
12 #include "content/common/content_export.h"
13 #include "content/common/cursors/webcursor.h"
14 #include "ui/events/event.h"
15 #include "ui/events/gestures/gesture_recognizer.h"
16 #include "ui/events/gestures/gesture_types.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/vector2d_f.h"
21 namespace content {
22 class BrowserPluginGuest;
23 class RenderWidgetHost;
24 class RenderWidgetHostImpl;
25 struct NativeWebKeyboardEvent;
27 // See comments in render_widget_host_view.h about this class and its members.
28 // This version is for the BrowserPlugin which handles a lot of the
29 // functionality in a diffent place and isn't platform specific.
30 // The BrowserPlugin is currently a special case for out-of-process rendered
31 // content and therefore inherits from RenderWidgetHostViewChildFrame.
32 // Eventually all RenderWidgetHostViewGuest code will be subsumed by
33 // RenderWidgetHostViewChildFrame and this class will be removed.
35 // Some elements that are platform specific will be deal with by delegating
36 // the relevant calls to the platform view.
37 class CONTENT_EXPORT RenderWidgetHostViewGuest
38 : public RenderWidgetHostViewChildFrame,
39 public ui::GestureConsumer,
40 public ui::GestureEventHelper {
41 public:
42 RenderWidgetHostViewGuest(
43 RenderWidgetHost* widget,
44 BrowserPluginGuest* guest,
45 base::WeakPtr<RenderWidgetHostViewBase> platform_view);
46 ~RenderWidgetHostViewGuest() override;
48 bool OnMessageReceivedFromEmbedder(const IPC::Message& message,
49 RenderWidgetHostImpl* embedder);
51 // RenderWidgetHostView implementation.
52 bool OnMessageReceived(const IPC::Message& msg) override;
53 void InitAsChild(gfx::NativeView parent_view) override;
54 void SetSize(const gfx::Size& size) override;
55 void SetBounds(const gfx::Rect& rect) override;
56 void Focus() override;
57 bool HasFocus() const override;
58 gfx::NativeView GetNativeView() const override;
59 gfx::NativeViewId GetNativeViewId() const override;
60 gfx::NativeViewAccessible GetNativeViewAccessible() override;
61 gfx::Rect GetViewBounds() const override;
62 void SetBackgroundColor(SkColor color) override;
63 gfx::Size GetPhysicalBackingSize() const override;
64 base::string16 GetSelectedText() const override;
66 // RenderWidgetHostViewBase implementation.
67 void InitAsPopup(RenderWidgetHostView* parent_host_view,
68 const gfx::Rect& pos) override;
69 void InitAsFullscreen(RenderWidgetHostView* reference_host_view) override;
70 void WasShown() override;
71 void WasHidden() override;
72 void MovePluginWindows(const std::vector<WebPluginGeometry>& moves) override;
73 void UpdateCursor(const WebCursor& cursor) override;
74 void SetIsLoading(bool is_loading) override;
75 void TextInputTypeChanged(ui::TextInputType type,
76 ui::TextInputMode input_mode,
77 bool can_compose_inline,
78 int flags) override;
79 void ImeCancelComposition() override;
80 #if defined(OS_MACOSX) || defined(USE_AURA)
81 void ImeCompositionRangeChanged(
82 const gfx::Range& range,
83 const std::vector<gfx::Rect>& character_bounds) override;
84 #endif
85 void RenderProcessGone(base::TerminationStatus status,
86 int error_code) override;
87 void Destroy() override;
88 void SetTooltipText(const base::string16& tooltip_text) override;
89 void SelectionChanged(const base::string16& text,
90 size_t offset,
91 const gfx::Range& range) override;
92 void SelectionBoundsChanged(
93 const ViewHostMsg_SelectionBounds_Params& params) override;
94 void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
95 const gfx::Size& dst_size,
96 CopyFromCompositingSurfaceCallback& callback,
97 const SkColorType color_type) override;
98 void OnSwapCompositorFrame(uint32 output_surface_id,
99 scoped_ptr<cc::CompositorFrame> frame) override;
100 #if defined(USE_AURA)
101 virtual void ProcessAckedTouchEvent(
102 const TouchEventWithLatencyInfo& touch,
103 InputEventAckState ack_result) override;
104 #endif
105 bool LockMouse() override;
106 void UnlockMouse() override;
107 void GetScreenInfo(blink::WebScreenInfo* results) override;
109 #if defined(OS_MACOSX)
110 // RenderWidgetHostView implementation.
111 void SetActive(bool active) override;
112 void SetWindowVisibility(bool visible) override;
113 void WindowFrameChanged() override;
114 void ShowDefinitionForSelection() override;
115 bool SupportsSpeech() const override;
116 void SpeakSelection() override;
117 bool IsSpeaking() const override;
118 void StopSpeaking() override;
120 // RenderWidgetHostViewBase implementation.
121 bool PostProcessEventForPluginIme(
122 const NativeWebKeyboardEvent& event) override;
123 #endif // defined(OS_MACOSX)
125 #if defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
126 // RenderWidgetHostViewBase implementation.
127 virtual void ShowDisambiguationPopup(const gfx::Rect& rect_pixels,
128 const SkBitmap& zoomed_bitmap) override;
129 #endif // defined(OS_ANDROID) || defined(TOOLKIT_VIEWS)
131 #if defined(OS_ANDROID)
132 virtual void LockCompositingSurface() override;
133 virtual void UnlockCompositingSurface() override;
134 #endif // defined(OS_ANDROID)
136 #if defined(OS_WIN)
137 virtual void SetParentNativeViewAccessible(
138 gfx::NativeViewAccessible accessible_parent) override;
139 virtual gfx::NativeViewId GetParentForWindowlessPlugin() const override;
140 #endif
142 // Overridden from ui::GestureEventHelper.
143 bool CanDispatchToConsumer(ui::GestureConsumer* consumer) override;
144 void DispatchGestureEvent(ui::GestureEvent* event) override;
145 void DispatchCancelTouchEvent(ui::TouchEvent* event) override;
147 SkColorType PreferredReadbackFormat() override;
149 protected:
150 friend class RenderWidgetHostView;
152 private:
153 // Destroys this view without calling |Destroy| on |platform_view_|.
154 void DestroyGuestView();
156 // Builds and forwards a WebKitGestureEvent to the renderer.
157 bool ForwardGestureEventToRenderer(ui::GestureEvent* gesture);
159 // Process all of the given gestures (passes them on to renderer)
160 void ProcessGestures(ui::GestureRecognizer::Gestures* gestures);
162 RenderWidgetHostViewBase* GetGuestRenderWidgetHostView() const;
164 void OnHandleInputEvent(RenderWidgetHostImpl* embedder,
165 int browser_plugin_instance_id,
166 const gfx::Rect& guest_window_rect,
167 const blink::WebInputEvent* event);
169 // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied
170 // to one another, therefore we access |guest_| through WeakPtr.
171 base::WeakPtr<BrowserPluginGuest> guest_;
172 gfx::Size size_;
173 // The platform view for this RenderWidgetHostView.
174 // RenderWidgetHostViewGuest mostly only cares about stuff related to
175 // compositing, the rest are directly forwared to this |platform_view_|.
176 base::WeakPtr<RenderWidgetHostViewBase> platform_view_;
177 #if defined(USE_AURA)
178 scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
179 #endif
180 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest);
183 } // namespace content
185 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_