render_widget_host_view_guest.h revision a02191e04bc25c4935f804f2c080ae28663d096d
1e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// Copyright 2014 The Chromium Authors. All rights reserved. 2e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// Use of this source code is governed by a BSD-style license that can be 3e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// found in the LICENSE file. 4e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 5e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_ 6e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#define CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_ 7e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 8e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include <vector> 9e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 10e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "base/memory/scoped_ptr.h" 11e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "content/browser/frame_host/render_widget_host_view_child_frame.h" 12e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "content/common/content_export.h" 13e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "content/common/cursors/webcursor.h" 14e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "ui/events/event.h" 15e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "ui/events/gestures/gesture_recognizer.h" 16e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "ui/events/gestures/gesture_types.h" 17e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "ui/gfx/native_widget_types.h" 18e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "ui/gfx/rect.h" 19e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott#include "ui/gfx/vector2d_f.h" 20e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 21e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottnamespace content { 22e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottclass RenderWidgetHost; 23e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottclass RenderWidgetHostImpl; 24e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottclass BrowserPluginGuest; 25e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottstruct NativeWebKeyboardEvent; 26e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 27e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// See comments in render_widget_host_view.h about this class and its members. 28e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// This version is for the BrowserPlugin which handles a lot of the 29e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// functionality in a diffent place and isn't platform specific. 30e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// The BrowserPlugin is currently a special case for out-of-process rendered 31e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// content and therefore inherits from RenderWidgetHostViewChildFrame. 32e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// Eventually all RenderWidgetHostViewGuest code will be subsumed by 33e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// RenderWidgetHostViewChildFrame and this class will be removed. 34e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// 35e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// Some elements that are platform specific will be deal with by delegating 36e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott// the relevant calls to the platform view. 37e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scottclass CONTENT_EXPORT RenderWidgetHostViewGuest 38e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott : public RenderWidgetHostViewChildFrame, 39e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott public ui::GestureConsumer, 40e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott public ui::GestureEventHelper { 41e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott public: 42e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott RenderWidgetHostViewGuest(RenderWidgetHost* widget, 43e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott BrowserPluginGuest* guest, 44e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott RenderWidgetHostView* platform_view); 45e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott virtual ~RenderWidgetHostViewGuest(); 46e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott 47e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott // RenderWidgetHostView implementation. 48e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 49e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE; 50e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott virtual void SetSize(const gfx::Size& size) OVERRIDE; 51e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott virtual void SetBounds(const gfx::Rect& rect) OVERRIDE; 52e46c9386c4f79aa40185f79a19fc5b2a7ef528b3Patrick Scott virtual gfx::NativeView GetNativeView() const OVERRIDE; 53 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; 54 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; 55 virtual gfx::Rect GetViewBounds() const OVERRIDE; 56 virtual void SetBackground(const SkBitmap& background) OVERRIDE; 57 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE; 58 virtual base::string16 GetSelectedText() const OVERRIDE; 59 60 // RenderWidgetHostViewPort implementation. 61 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, 62 const gfx::Rect& pos) OVERRIDE; 63 virtual void InitAsFullscreen( 64 RenderWidgetHostView* reference_host_view) OVERRIDE; 65 virtual void WasShown() OVERRIDE; 66 virtual void WasHidden() OVERRIDE; 67 virtual void MovePluginWindows( 68 const gfx::Vector2d& scroll_offset, 69 const std::vector<WebPluginGeometry>& moves) OVERRIDE; 70 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE; 71 virtual void SetIsLoading(bool is_loading) OVERRIDE; 72 virtual void TextInputTypeChanged(ui::TextInputType type, 73 ui::TextInputMode input_mode, 74 bool can_compose_inline) OVERRIDE; 75 virtual void ImeCancelComposition() OVERRIDE; 76#if defined(OS_MACOSX) || defined(USE_AURA) 77 virtual void ImeCompositionRangeChanged( 78 const gfx::Range& range, 79 const std::vector<gfx::Rect>& character_bounds) OVERRIDE; 80#endif 81 virtual void DidUpdateBackingStore( 82 const gfx::Rect& scroll_rect, 83 const gfx::Vector2d& scroll_delta, 84 const std::vector<gfx::Rect>& copy_rects, 85 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE; 86 virtual void RenderProcessGone(base::TerminationStatus status, 87 int error_code) OVERRIDE; 88 virtual void Destroy() OVERRIDE; 89 virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE; 90 virtual void SelectionChanged(const base::string16& text, 91 size_t offset, 92 const gfx::Range& range) OVERRIDE; 93 virtual void SelectionBoundsChanged( 94 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE; 95#if defined(OS_ANDROID) 96 virtual void SelectionRootBoundsChanged(const gfx::Rect& bounds) OVERRIDE; 97#endif 98 virtual void CopyFromCompositingSurface( 99 const gfx::Rect& src_subrect, 100 const gfx::Size& dst_size, 101 const base::Callback<void(bool, const SkBitmap&)>& callback, 102 const SkBitmap::Config config) OVERRIDE; 103 virtual void AcceleratedSurfaceBuffersSwapped( 104 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 105 int gpu_host_id) OVERRIDE; 106 virtual void AcceleratedSurfacePostSubBuffer( 107 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 108 int gpu_host_id) OVERRIDE; 109 virtual void OnSwapCompositorFrame( 110 uint32 output_surface_id, 111 scoped_ptr<cc::CompositorFrame> frame) OVERRIDE; 112 virtual void SetHasHorizontalScrollbar( 113 bool has_horizontal_scrollbar) OVERRIDE; 114 virtual void SetScrollOffsetPinning( 115 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; 116#if defined(USE_AURA) 117 virtual void ProcessAckedTouchEvent( 118 const TouchEventWithLatencyInfo& touch, 119 InputEventAckState ack_result) OVERRIDE; 120#endif 121 virtual bool LockMouse() OVERRIDE; 122 virtual void UnlockMouse() OVERRIDE; 123 virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE; 124 125#if defined(OS_MACOSX) 126 // RenderWidgetHostView implementation. 127 virtual void SetActive(bool active) OVERRIDE; 128 virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE; 129 virtual void SetWindowVisibility(bool visible) OVERRIDE; 130 virtual void WindowFrameChanged() OVERRIDE; 131 virtual void ShowDefinitionForSelection() OVERRIDE; 132 virtual bool SupportsSpeech() const OVERRIDE; 133 virtual void SpeakSelection() OVERRIDE; 134 virtual bool IsSpeaking() const OVERRIDE; 135 virtual void StopSpeaking() OVERRIDE; 136 137 // RenderWidgetHostViewPort implementation. 138 virtual bool PostProcessEventForPluginIme( 139 const NativeWebKeyboardEvent& event) OVERRIDE; 140#endif // defined(OS_MACOSX) 141 142#if defined(OS_ANDROID) 143 // RenderWidgetHostViewPort implementation. 144 virtual void ShowDisambiguationPopup(const gfx::Rect& target_rect, 145 const SkBitmap& zoomed_bitmap) OVERRIDE; 146#endif // defined(OS_ANDROID) 147 148#if defined(OS_WIN) 149 virtual void SetParentNativeViewAccessible( 150 gfx::NativeViewAccessible accessible_parent) OVERRIDE; 151 virtual gfx::NativeViewId GetParentForWindowlessPlugin() const OVERRIDE; 152#endif 153 154 // Overridden from ui::GestureEventHelper. 155 virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE; 156 virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE; 157 virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE; 158 159 virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE; 160 161 protected: 162 friend class RenderWidgetHostView; 163 164 private: 165 // Destroys this view without calling |Destroy| on |platform_view_|. 166 void DestroyGuestView(); 167 168 // Builds and forwards a WebKitGestureEvent to the renderer. 169 bool ForwardGestureEventToRenderer(ui::GestureEvent* gesture); 170 171 // Process all of the given gestures (passes them on to renderer) 172 void ProcessGestures(ui::GestureRecognizer::Gestures* gestures); 173 174 // BrowserPluginGuest and RenderWidgetHostViewGuest's lifetimes are not tied 175 // to one another, therefore we access |guest_| through WeakPtr. 176 base::WeakPtr<BrowserPluginGuest> guest_; 177 gfx::Size size_; 178 // The platform view for this RenderWidgetHostView. 179 // RenderWidgetHostViewGuest mostly only cares about stuff related to 180 // compositing, the rest are directly forwared to this |platform_view_|. 181 RenderWidgetHostViewPort* platform_view_; 182#if defined(USE_AURA) 183 scoped_ptr<ui::GestureRecognizer> gesture_recognizer_; 184#endif 185 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuest); 186}; 187 188} // namespace content 189 190#endif // CONTENT_BROWSER_FRAME_HOST_RENDER_WIDGET_HOST_VIEW_GUEST_H_ 191