base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate>>
responderDelegate_;
BOOL canBeKeyView_;
- BOOL takesFocusOnlyOnMouseDown_;
BOOL closeOnDeactivate_;
scoped_ptr<content::RenderWidgetHostViewMacEditCommandHelper>
editCommand_helper_;
@property(nonatomic, readonly) BOOL suppressNextEscapeKeyUp;
- (void)setCanBeKeyView:(BOOL)can;
-- (void)setTakesFocusOnlyOnMouseDown:(BOOL)b;
- (void)setCloseOnDeactivate:(BOOL)b;
- (void)setToolTipAtMousePoint:(NSString *)string;
// True for always-on-top special windows (e.g. Balloons and Panels).
// The view will associate itself with the given widget. The native view must
// be hooked up immediately to the view hierarchy, or else when it is
// deleted it will delete this out from under the caller.
- explicit RenderWidgetHostViewMac(RenderWidgetHost* widget);
- virtual ~RenderWidgetHostViewMac();
+ //
+ // When |is_guest_view_hack| is true, this view isn't really the view for
+ // the |widget|, a RenderWidgetHostViewGuest is.
+ // TODO(lazyboy): Remove |is_guest_view_hack| once BrowserPlugin has migrated
+ // to use RWHVChildFrame (http://crbug.com/330264).
+ RenderWidgetHostViewMac(RenderWidgetHost* widget, bool is_guest_view_hack);
+ ~RenderWidgetHostViewMac() override;
RenderWidgetHostViewCocoa* cocoa_view() const { return cocoa_view_; }
void SetAllowPauseForResizeOrRepaint(bool allow);
// RenderWidgetHostView implementation.
- virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
- virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
- virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
- virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
- virtual gfx::Vector2dF GetLastScrollOffset() const OVERRIDE;
- virtual gfx::NativeView GetNativeView() const OVERRIDE;
- virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
- virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
- virtual bool HasFocus() const OVERRIDE;
- virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
- virtual void Show() OVERRIDE;
- virtual void Hide() OVERRIDE;
- virtual bool IsShowing() OVERRIDE;
- virtual gfx::Rect GetViewBounds() const OVERRIDE;
- virtual void SetShowingContextMenu(bool showing) OVERRIDE;
- virtual void SetActive(bool active) OVERRIDE;
- virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
- virtual void SetWindowVisibility(bool visible) OVERRIDE;
- virtual void WindowFrameChanged() OVERRIDE;
- virtual void ShowDefinitionForSelection() OVERRIDE;
- virtual bool SupportsSpeech() const OVERRIDE;
- virtual void SpeakSelection() OVERRIDE;
- virtual bool IsSpeaking() const OVERRIDE;
- virtual void StopSpeaking() OVERRIDE;
- virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
+ bool OnMessageReceived(const IPC::Message& msg) override;
+ void InitAsChild(gfx::NativeView parent_view) override;
+ RenderWidgetHost* GetRenderWidgetHost() const override;
+ void SetSize(const gfx::Size& size) override;
+ void SetBounds(const gfx::Rect& rect) override;
+ gfx::Vector2dF GetLastScrollOffset() const override;
+ gfx::NativeView GetNativeView() const override;
+ gfx::NativeViewId GetNativeViewId() const override;
+ gfx::NativeViewAccessible GetNativeViewAccessible() override;
+ bool HasFocus() const override;
+ bool IsSurfaceAvailableForCopy() const override;
+ void Show() override;
+ void Hide() override;
+ bool IsShowing() override;
+ gfx::Rect GetViewBounds() const override;
+ void SetShowingContextMenu(bool showing) override;
+ void SetActive(bool active) override;
+ void SetWindowVisibility(bool visible) override;
+ void WindowFrameChanged() override;
+ void ShowDefinitionForSelection() override;
+ bool SupportsSpeech() const override;
+ void SpeakSelection() override;
+ bool IsSpeaking() const override;
+ void StopSpeaking() override;
+ void SetBackgroundColor(SkColor color) override;
// Implementation of RenderWidgetHostViewBase.
- virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
- const gfx::Rect& pos) OVERRIDE;
- virtual void InitAsFullscreen(
- RenderWidgetHostView* reference_host_view) OVERRIDE;
- virtual void WasShown() OVERRIDE;
- virtual void WasHidden() OVERRIDE;
- virtual void MovePluginWindows(
- const std::vector<WebPluginGeometry>& moves) OVERRIDE;
- virtual void Focus() OVERRIDE;
- virtual void Blur() OVERRIDE;
- virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
- virtual void SetIsLoading(bool is_loading) OVERRIDE;
- virtual void TextInputTypeChanged(ui::TextInputType type,
- ui::TextInputMode input_mode,
- bool can_compose_inline) OVERRIDE;
- virtual void ImeCancelComposition() OVERRIDE;
- virtual void ImeCompositionRangeChanged(
+ void InitAsPopup(RenderWidgetHostView* parent_host_view,
+ const gfx::Rect& pos) override;
+ void InitAsFullscreen(RenderWidgetHostView* reference_host_view) override;
+ void WasShown() override;
+ void WasHidden() override;
+ void MovePluginWindows(const std::vector<WebPluginGeometry>& moves) override;
+ void Focus() override;
+ void Blur() override;
+ void UpdateCursor(const WebCursor& cursor) override;
+ void SetIsLoading(bool is_loading) override;
+ void TextInputTypeChanged(ui::TextInputType type,
+ ui::TextInputMode input_mode,
+ bool can_compose_inline,
+ int flags) override;
+ void ImeCancelComposition() override;
+ void ImeCompositionRangeChanged(
const gfx::Range& range,
- const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
- virtual void RenderProcessGone(base::TerminationStatus status,
- int error_code) OVERRIDE;
- virtual void RenderWidgetHostGone() OVERRIDE;
- virtual void Destroy() OVERRIDE;
- virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
- virtual void SelectionChanged(const base::string16& text,
- size_t offset,
- const gfx::Range& range) OVERRIDE;
- virtual void SelectionBoundsChanged(
- const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
- virtual void CopyFromCompositingSurface(
+ const std::vector<gfx::Rect>& character_bounds) override;
+ void RenderProcessGone(base::TerminationStatus status,
+ int error_code) override;
+ void RenderWidgetHostGone() override;
+ void Destroy() override;
+ void SetTooltipText(const base::string16& tooltip_text) override;
+ void SelectionChanged(const base::string16& text,
+ size_t offset,
+ const gfx::Range& range) override;
+ void SelectionBoundsChanged(
+ const ViewHostMsg_SelectionBounds_Params& params) override;
+ void CopyFromCompositingSurface(
const gfx::Rect& src_subrect,
const gfx::Size& dst_size,
const base::Callback<void(bool, const SkBitmap&)>& callback,
- SkColorType color_type) OVERRIDE;
- virtual void CopyFromCompositingSurfaceToVideoFrame(
+ SkColorType color_type) override;
+ void CopyFromCompositingSurfaceToVideoFrame(
const gfx::Rect& src_subrect,
const scoped_refptr<media::VideoFrame>& target,
- const base::Callback<void(bool)>& callback) OVERRIDE;
- virtual bool CanCopyToVideoFrame() const OVERRIDE;
- virtual bool CanSubscribeFrame() const OVERRIDE;
- virtual void BeginFrameSubscription(
- scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE;
- virtual void EndFrameSubscription() OVERRIDE;
- virtual void OnSwapCompositorFrame(
- uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
- virtual void AcceleratedSurfaceInitialized(int host_id,
- int route_id) OVERRIDE;
- virtual BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
- BrowserAccessibilityDelegate* delegate) OVERRIDE;
- virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds)
- OVERRIDE;
- virtual void AccessibilityShowMenu(const gfx::Point& point) OVERRIDE;
- virtual bool PostProcessEventForPluginIme(
- const NativeWebKeyboardEvent& event) OVERRIDE;
-
- virtual void AcceleratedSurfaceBuffersSwapped(
- const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
- int gpu_host_id) OVERRIDE;
- virtual void AcceleratedSurfacePostSubBuffer(
- const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
- int gpu_host_id) OVERRIDE;
- virtual void AcceleratedSurfaceSuspend() OVERRIDE;
- virtual void AcceleratedSurfaceRelease() OVERRIDE;
- virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
- virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
- virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
- virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
-
- virtual bool LockMouse() OVERRIDE;
- virtual void UnlockMouse() OVERRIDE;
- virtual void WheelEventAck(const blink::WebMouseWheelEvent& event,
- InputEventAckState ack_result) OVERRIDE;
+ const base::Callback<void(bool)>& callback) override;
+ bool CanCopyToVideoFrame() const override;
+ bool CanSubscribeFrame() const override;
+ void BeginFrameSubscription(
+ scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) override;
+ void EndFrameSubscription() override;
+ void OnSwapCompositorFrame(uint32 output_surface_id,
+ scoped_ptr<cc::CompositorFrame> frame) override;
+ BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
+ BrowserAccessibilityDelegate* delegate) override;
+ gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds) override;
+ void AccessibilityShowMenu(const gfx::Point& point) override;
+ bool PostProcessEventForPluginIme(
+ const NativeWebKeyboardEvent& event) override;
+
+ bool HasAcceleratedSurface(const gfx::Size& desired_size) override;
+ void GetScreenInfo(blink::WebScreenInfo* results) override;
+ gfx::Rect GetBoundsInRootWindow() override;
+ gfx::GLSurfaceHandle GetCompositingSurface() override;
+
+ bool LockMouse() override;
+ void UnlockMouse() override;
+ void WheelEventAck(const blink::WebMouseWheelEvent& event,
+ InputEventAckState ack_result) override;
// IPC::Sender implementation.
- virtual bool Send(IPC::Message* message) OVERRIDE;
+ bool Send(IPC::Message* message) override;
- virtual SkColorType PreferredReadbackFormat() OVERRIDE;
+ SkColorType PreferredReadbackFormat() override;
// gfx::DisplayObserver implementation.
- virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
- virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
- virtual void OnDisplayMetricsChanged(const gfx::Display& display,
- uint32_t metrics) OVERRIDE;
+ void OnDisplayAdded(const gfx::Display& new_display) override;
+ void OnDisplayRemoved(const gfx::Display& old_display) override;
+ void OnDisplayMetricsChanged(const gfx::Display& display,
+ uint32_t metrics) override;
// Forwards the mouse event to the renderer.
void ForwardMouseEvent(const blink::WebMouseEvent& event);
// The background CoreAnimation layer which is hosted by |cocoa_view_|.
base::scoped_nsobject<CALayer> background_layer_;
+ // The state of |delegated_frame_host_| and |browser_compositor_view_| to
+ // manage being visible, hidden, or occluded.
+ enum BrowserCompositorViewState {
+ // Effects:
+ // - |browser_compositor_view_| exists and |delegated_frame_host_| is
+ // visible.
+ // Happens when:
+ // - |render_widet_host_| is in the visible state (this includes when
+ // the tab isn't visible, but tab capture is enabled).
+ BrowserCompositorActive,
+ // Effects:
+ // - |browser_compositor_view_| exists, but |delegated_frame_host_| has
+ // been hidden.
+ // Happens when:
+ // - The |render_widget_host_| is hidden, but |cocoa_view_| is still in the
+ // NSWindow hierarchy.
+ // - This happens when |cocoa_view_| is hidden (minimized, on another
+ // occluded by other windows, etc). The |browser_compositor_view_| and
+ // its CALayers are kept around so that we will have content to show when
+ // we are un-occluded.
+ BrowserCompositorSuspended,
+ // Effects:
+ // - |browser_compositor_view_| has been destroyed and
+ // |delegated_frame_host_| has been hidden.
+ // Happens when:
+ // - The |render_widget_host_| is hidden or dead, and |cocoa_view_| is not
+ // attached to a NSWindow.
+ // - This happens for backgrounded tabs.
+ BrowserCompositorDestroyed,
+ };
+ BrowserCompositorViewState browser_compositor_state_;
+
// Delegated frame management and compositior.
scoped_ptr<DelegatedFrameHost> delegated_frame_host_;
scoped_ptr<ui::Layer> root_layer_;
- // Container for the NSView drawn by the browser compositor.
+ // Container for the CALayer tree drawn by the browser compositor.
scoped_ptr<BrowserCompositorViewMac> browser_compositor_view_;
// Placeholder that is allocated while browser_compositor_view_ is NULL,
void PauseForPendingResizeOrRepaintsAndDraw();
// DelegatedFrameHostClient implementation.
- virtual ui::Compositor* GetCompositor() const OVERRIDE;
- virtual ui::Layer* GetLayer() OVERRIDE;
- virtual RenderWidgetHostImpl* GetHost() OVERRIDE;
- virtual bool IsVisible() OVERRIDE;
- virtual scoped_ptr<ResizeLock> CreateResizeLock(
- bool defer_compositor_lock) OVERRIDE;
- virtual gfx::Size DesiredFrameSize() OVERRIDE;
- virtual float CurrentDeviceScaleFactor() OVERRIDE;
- virtual gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) OVERRIDE;
- virtual DelegatedFrameHost* GetDelegatedFrameHost() const OVERRIDE;
+ ui::Compositor* GetCompositor() const override;
+ ui::Layer* GetLayer() override;
+ RenderWidgetHostImpl* GetHost() override;
+ bool IsVisible() override;
+ scoped_ptr<ResizeLock> CreateResizeLock(bool defer_compositor_lock) override;
+ gfx::Size DesiredFrameSize() override;
+ float CurrentDeviceScaleFactor() override;
+ gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) override;
+ DelegatedFrameHost* GetDelegatedFrameHost() const override;
// BrowserCompositorViewMacClient implementation.
- virtual bool BrowserCompositorViewShouldAckImmediately() const OVERRIDE;
- virtual void BrowserCompositorViewFrameSwapped(
- const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
- virtual NSView* BrowserCompositorSuperview() OVERRIDE;
- virtual ui::Layer* BrowserCompositorRootLayer() OVERRIDE;
+ bool BrowserCompositorViewShouldAckImmediately() const override;
+ void BrowserCompositorViewFrameSwapped(
+ const std::vector<ui::LatencyInfo>& latency_info) override;
+
+ // Transition from being in the Suspended state to being in the Destroyed
+ // state, if appropriate (see BrowserCompositorViewState for details).
+ void DestroySuspendedBrowserCompositorViewIfNeeded();
private:
friend class RenderWidgetHostViewMacTest;
// ensure no dangling references.
void ShutdownBrowserCompositor();
+ // The state of the the browser compositor and delegated frame host. See
+ // BrowserCompositorViewState for details.
void EnsureBrowserCompositorView();
+ void SuspendBrowserCompositorView();
void DestroyBrowserCompositorView();
// IPC message handlers.
// The text to be shown in the tooltip, supplied by the renderer.
base::string16 tooltip_text_;
+ // True when this view acts as a platform view hack for a
+ // RenderWidgetHostViewGuest.
+ bool is_guest_view_hack_;
+
// Factory used to safely scope delayed calls to ShutdownHost().
base::WeakPtrFactory<RenderWidgetHostViewMac> weak_factory_;