render_widget_host_view_mac.h revision 116680a4aac90f2aa7413d9095a592090648e557
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.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
6#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
7
8#import <Cocoa/Cocoa.h>
9#include <IOSurface/IOSurfaceAPI.h>
10#include <list>
11#include <map>
12#include <string>
13#include <utility>
14#include <vector>
15
16#include "base/mac/scoped_nsobject.h"
17#include "base/memory/scoped_ptr.h"
18#include "base/memory/weak_ptr.h"
19#include "base/time/time.h"
20#include "content/browser/compositor/browser_compositor_view_mac.h"
21#include "content/browser/compositor/delegated_frame_host.h"
22#include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
23#include "content/browser/renderer_host/display_link_mac.h"
24#include "content/browser/renderer_host/render_widget_host_view_base.h"
25#include "content/browser/renderer_host/software_frame_manager.h"
26#include "content/common/content_export.h"
27#include "content/common/cursors/webcursor.h"
28#include "content/common/edit_command.h"
29#import "content/public/browser/render_widget_host_view_mac_base.h"
30#include "ipc/ipc_sender.h"
31#include "third_party/WebKit/public/web/WebCompositionUnderline.h"
32#include "ui/base/cocoa/base_view.h"
33#include "ui/base/cocoa/remote_layer_api.h"
34
35struct ViewHostMsg_TextInputState_Params;
36
37namespace content {
38class BrowserCompositorviewMac;
39class CompositingIOSurfaceMac;
40class CompositingIOSurfaceContext;
41class RenderWidgetHostViewMac;
42class RenderWidgetHostViewMacEditCommandHelper;
43class WebContents;
44}
45
46namespace ui {
47class Compositor;
48class Layer;
49}
50
51@class CompositingIOSurfaceLayer;
52@class FullscreenWindowManager;
53@protocol RenderWidgetHostViewMacDelegate;
54@class SoftwareLayer;
55@class ToolTip;
56
57@protocol RenderWidgetHostViewMacOwner
58- (content::RenderWidgetHostViewMac*)renderWidgetHostViewMac;
59@end
60
61// This is the view that lives in the Cocoa view hierarchy. In Windows-land,
62// RenderWidgetHostViewWin is both the view and the delegate. We split the roles
63// but that means that the view needs to own the delegate and will dispose of it
64// when it's removed from the view system.
65@interface RenderWidgetHostViewCocoa
66    : BaseView <RenderWidgetHostViewMacBase,
67                RenderWidgetHostViewMacOwner,
68                NSTextInputClient> {
69 @private
70  scoped_ptr<content::RenderWidgetHostViewMac> renderWidgetHostView_;
71  // This ivar is the cocoa delegate of the NSResponder.
72  base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate>>
73      responderDelegate_;
74  BOOL canBeKeyView_;
75  BOOL takesFocusOnlyOnMouseDown_;
76  BOOL closeOnDeactivate_;
77  scoped_ptr<content::RenderWidgetHostViewMacEditCommandHelper>
78      editCommand_helper_;
79
80  // These are part of the magic tooltip code from WebKit's WebHTMLView:
81  id trackingRectOwner_;              // (not retained)
82  void* trackingRectUserData_;
83  NSTrackingRectTag lastToolTipTag_;
84  base::scoped_nsobject<NSString> toolTip_;
85
86  // Is YES if there was a mouse-down as yet unbalanced with a mouse-up.
87  BOOL hasOpenMouseDown_;
88
89  NSWindow* lastWindow_;  // weak
90
91  // The cursor for the page. This is passed up from the renderer.
92  base::scoped_nsobject<NSCursor> currentCursor_;
93
94  // Variables used by our implementaion of the NSTextInput protocol.
95  // An input method of Mac calls the methods of this protocol not only to
96  // notify an application of its status, but also to retrieve the status of
97  // the application. That is, an application cannot control an input method
98  // directly.
99  // This object keeps the status of a composition of the renderer and returns
100  // it when an input method asks for it.
101  // We need to implement Objective-C methods for the NSTextInput protocol. On
102  // the other hand, we need to implement a C++ method for an IPC-message
103  // handler which receives input-method events from the renderer.
104
105  // Represents the input-method attributes supported by this object.
106  base::scoped_nsobject<NSArray> validAttributesForMarkedText_;
107
108  // Indicates if we are currently handling a key down event.
109  BOOL handlingKeyDown_;
110
111  // Indicates if there is any marked text.
112  BOOL hasMarkedText_;
113
114  // Indicates if unmarkText is called or not when handling a keyboard
115  // event.
116  BOOL unmarkTextCalled_;
117
118  // The range of current marked text inside the whole content of the DOM node
119  // being edited.
120  // TODO(suzhe): This is currently a fake value, as we do not support accessing
121  // the whole content yet.
122  NSRange markedRange_;
123
124  // The selected range, cached from a message sent by the renderer.
125  NSRange selectedRange_;
126
127  // Text to be inserted which was generated by handling a key down event.
128  base::string16 textToBeInserted_;
129
130  // Marked text which was generated by handling a key down event.
131  base::string16 markedText_;
132
133  // Underline information of the |markedText_|.
134  std::vector<blink::WebCompositionUnderline> underlines_;
135
136  // Indicates if doCommandBySelector method receives any edit command when
137  // handling a key down event.
138  BOOL hasEditCommands_;
139
140  // Contains edit commands received by the -doCommandBySelector: method when
141  // handling a key down event, not including inserting commands, eg. insertTab,
142  // etc.
143  content::EditCommands editCommands_;
144
145  // The plugin that currently has focus (-1 if no plugin has focus).
146  int focusedPluginIdentifier_;
147
148  // Whether or not plugin IME is currently enabled active.
149  BOOL pluginImeActive_;
150
151  // Whether the previous mouse event was ignored due to hitTest check.
152  BOOL mouseEventWasIgnored_;
153
154  // Event monitor for scroll wheel end event.
155  id endWheelMonitor_;
156
157  // OpenGL Support:
158
159  // recursive globalFrameDidChange protection:
160  BOOL handlingGlobalFrameDidChange_;
161
162  // The scale factor of the display this view is in.
163  float deviceScaleFactor_;
164
165  // If true then escape key down events are suppressed until the first escape
166  // key up event. (The up event is suppressed as well). This is used by the
167  // flash fullscreen code to avoid sending a key up event without a matching
168  // key down event.
169  BOOL suppressNextEscapeKeyUp_;
170}
171
172@property(nonatomic, readonly) NSRange selectedRange;
173@property(nonatomic, readonly) BOOL suppressNextEscapeKeyUp;
174
175- (void)setCanBeKeyView:(BOOL)can;
176- (void)setTakesFocusOnlyOnMouseDown:(BOOL)b;
177- (void)setCloseOnDeactivate:(BOOL)b;
178- (void)setToolTipAtMousePoint:(NSString *)string;
179// True for always-on-top special windows (e.g. Balloons and Panels).
180- (BOOL)acceptsMouseEventsWhenInactive;
181// Cancel ongoing composition (abandon the marked text).
182- (void)cancelComposition;
183// Confirm ongoing composition.
184- (void)confirmComposition;
185// Enables or disables plugin IME.
186- (void)setPluginImeActive:(BOOL)active;
187// Updates the current plugin focus state.
188- (void)pluginFocusChanged:(BOOL)focused forPlugin:(int)pluginId;
189// Evaluates the event in the context of plugin IME, if plugin IME is enabled.
190// Returns YES if the event was handled.
191- (BOOL)postProcessEventForPluginIme:(NSEvent*)event;
192- (void)updateCursor:(NSCursor*)cursor;
193- (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
194                             actualRange:(NSRangePointer)actualRange;
195@end
196
197namespace content {
198class RenderWidgetHostImpl;
199
200///////////////////////////////////////////////////////////////////////////////
201// RenderWidgetHostViewMac
202//
203//  An object representing the "View" of a rendered web page. This object is
204//  responsible for displaying the content of the web page, and integrating with
205//  the Cocoa view system. It is the implementation of the RenderWidgetHostView
206//  that the cross-platform RenderWidgetHost object uses
207//  to display the data.
208//
209//  Comment excerpted from render_widget_host.h:
210//
211//    "The lifetime of the RenderWidgetHost* is tied to the render process.
212//     If the render process dies, the RenderWidgetHost* goes away and all
213//     references to it must become NULL."
214//
215// RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
216class CONTENT_EXPORT RenderWidgetHostViewMac
217    : public RenderWidgetHostViewBase,
218      public DelegatedFrameHostClient,
219      public BrowserCompositorViewMacClient,
220      public IPC::Sender,
221      public SoftwareFrameManagerClient,
222      public CompositingIOSurfaceLayerClient {
223 public:
224  // The view will associate itself with the given widget. The native view must
225  // be hooked up immediately to the view hierarchy, or else when it is
226  // deleted it will delete this out from under the caller.
227  explicit RenderWidgetHostViewMac(RenderWidgetHost* widget);
228  virtual ~RenderWidgetHostViewMac();
229
230  RenderWidgetHostViewCocoa* cocoa_view() const { return cocoa_view_; }
231
232  // |delegate| is used to separate out the logic from the NSResponder delegate.
233  // |delegate| is retained by this class.
234  // |delegate| should be set at most once.
235  CONTENT_EXPORT void SetDelegate(
236    NSObject<RenderWidgetHostViewMacDelegate>* delegate);
237  void SetAllowOverlappingViews(bool overlapping);
238  void SetAllowPauseForResizeOrRepaint(bool allow);
239
240  // RenderWidgetHostView implementation.
241  virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
242  virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
243  virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
244  virtual void SetSize(const gfx::Size& size) OVERRIDE;
245  virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
246  virtual gfx::NativeView GetNativeView() const OVERRIDE;
247  virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
248  virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
249  virtual bool HasFocus() const OVERRIDE;
250  virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
251  virtual void Show() OVERRIDE;
252  virtual void Hide() OVERRIDE;
253  virtual bool IsShowing() OVERRIDE;
254  virtual gfx::Rect GetViewBounds() const OVERRIDE;
255  virtual void SetShowingContextMenu(bool showing) OVERRIDE;
256  virtual void SetActive(bool active) OVERRIDE;
257  virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
258  virtual void SetWindowVisibility(bool visible) OVERRIDE;
259  virtual void WindowFrameChanged() OVERRIDE;
260  virtual void ShowDefinitionForSelection() OVERRIDE;
261  virtual bool SupportsSpeech() const OVERRIDE;
262  virtual void SpeakSelection() OVERRIDE;
263  virtual bool IsSpeaking() const OVERRIDE;
264  virtual void StopSpeaking() OVERRIDE;
265  virtual void SetBackgroundOpaque(bool opaque) OVERRIDE;
266
267  // Implementation of RenderWidgetHostViewBase.
268  virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
269                           const gfx::Rect& pos) OVERRIDE;
270  virtual void InitAsFullscreen(
271      RenderWidgetHostView* reference_host_view) OVERRIDE;
272  virtual void WasShown() OVERRIDE;
273  virtual void WasHidden() OVERRIDE;
274  virtual void MovePluginWindows(
275      const std::vector<WebPluginGeometry>& moves) OVERRIDE;
276  virtual void Focus() OVERRIDE;
277  virtual void Blur() OVERRIDE;
278  virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
279  virtual void SetIsLoading(bool is_loading) OVERRIDE;
280  virtual void TextInputStateChanged(
281      const ViewHostMsg_TextInputState_Params& params) OVERRIDE;
282  virtual void ImeCancelComposition() OVERRIDE;
283  virtual void ImeCompositionRangeChanged(
284      const gfx::Range& range,
285      const std::vector<gfx::Rect>& character_bounds) OVERRIDE;
286  virtual void RenderProcessGone(base::TerminationStatus status,
287                                 int error_code) OVERRIDE;
288  virtual void Destroy() OVERRIDE;
289  virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
290  virtual void SelectionChanged(const base::string16& text,
291                                size_t offset,
292                                const gfx::Range& range) OVERRIDE;
293  virtual void SelectionBoundsChanged(
294      const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
295  virtual void ScrollOffsetChanged() OVERRIDE;
296  virtual void CopyFromCompositingSurface(
297      const gfx::Rect& src_subrect,
298      const gfx::Size& dst_size,
299      const base::Callback<void(bool, const SkBitmap&)>& callback,
300      SkColorType color_type) OVERRIDE;
301  virtual void CopyFromCompositingSurfaceToVideoFrame(
302      const gfx::Rect& src_subrect,
303      const scoped_refptr<media::VideoFrame>& target,
304      const base::Callback<void(bool)>& callback) OVERRIDE;
305  virtual bool CanCopyToVideoFrame() const OVERRIDE;
306  virtual bool CanSubscribeFrame() const OVERRIDE;
307  virtual void BeginFrameSubscription(
308      scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE;
309  virtual void EndFrameSubscription() OVERRIDE;
310  virtual void OnSwapCompositorFrame(
311      uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) OVERRIDE;
312  virtual void AcceleratedSurfaceInitialized(int host_id,
313                                             int route_id) OVERRIDE;
314  virtual BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
315      BrowserAccessibilityDelegate* delegate) OVERRIDE;
316  virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds)
317      OVERRIDE;
318  virtual void AccessibilityShowMenu(const gfx::Point& point) OVERRIDE;
319  virtual bool PostProcessEventForPluginIme(
320      const NativeWebKeyboardEvent& event) OVERRIDE;
321
322  virtual void AcceleratedSurfaceBuffersSwapped(
323      const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
324      int gpu_host_id) OVERRIDE;
325  virtual void AcceleratedSurfacePostSubBuffer(
326      const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
327      int gpu_host_id) OVERRIDE;
328  virtual void AcceleratedSurfaceSuspend() OVERRIDE;
329  virtual void AcceleratedSurfaceRelease() OVERRIDE;
330  virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
331  virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
332  virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
333  virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
334
335  virtual bool LockMouse() OVERRIDE;
336  virtual void UnlockMouse() OVERRIDE;
337  virtual void WheelEventAck(const blink::WebMouseWheelEvent& event,
338                             InputEventAckState ack_result) OVERRIDE;
339
340  // IPC::Sender implementation.
341  virtual bool Send(IPC::Message* message) OVERRIDE;
342
343  // SoftwareFrameManagerClient implementation:
344  virtual void SoftwareFrameWasFreed(
345      uint32 output_surface_id, unsigned frame_id) OVERRIDE;
346  virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE;
347
348  virtual SkColorType PreferredReadbackFormat() OVERRIDE;
349
350  // CompositingIOSurfaceLayerClient implementation.
351  virtual void AcceleratedLayerDidDrawFrame(bool succeeded) OVERRIDE;
352
353  // Forwards the mouse event to the renderer.
354  void ForwardMouseEvent(const blink::WebMouseEvent& event);
355
356  void KillSelf();
357
358  void SetTextInputActive(bool active);
359
360  // Sends completed plugin IME notification and text back to the renderer.
361  void PluginImeCompositionCompleted(const base::string16& text, int plugin_id);
362
363  const std::string& selected_text() const { return selected_text_; }
364
365  // Update the IOSurface to be drawn and call setNeedsDisplay on
366  // |cocoa_view_|.
367  void CompositorSwapBuffers(IOSurfaceID surface_handle,
368                             const gfx::Size& size,
369                             float scale_factor,
370                             const std::vector<ui::LatencyInfo>& latency_info);
371
372  // Called when a GPU error is detected. Posts a task to destroy all
373  // compositing state.
374  void GotAcceleratedCompositingError();
375
376  // Returns true and stores first rectangle for character range if the
377  // requested |range| is already cached, otherwise returns false.
378  // Exposed for testing.
379  CONTENT_EXPORT bool GetCachedFirstRectForCharacterRange(
380      NSRange range, NSRect* rect, NSRange* actual_range);
381
382  // Returns true if there is line break in |range| and stores line breaking
383  // point to |line_breaking_point|. The |line_break_point| is valid only if
384  // this function returns true.
385  bool GetLineBreakIndex(const std::vector<gfx::Rect>& bounds,
386                         const gfx::Range& range,
387                         size_t* line_break_point);
388
389  // Returns composition character boundary rectangle. The |range| is
390  // composition based range. Also stores |actual_range| which is corresponding
391  // to actually used range for returned rectangle.
392  gfx::Rect GetFirstRectForCompositionRange(const gfx::Range& range,
393                                            gfx::Range* actual_range);
394
395  // Converts from given whole character range to composition oriented range. If
396  // the conversion failed, return gfx::Range::InvalidRange.
397  gfx::Range ConvertCharacterRangeToCompositionRange(
398      const gfx::Range& request_range);
399
400  WebContents* GetWebContents();
401
402  // These member variables should be private, but the associated ObjC class
403  // needs access to them and can't be made a friend.
404
405  // The associated Model.  Can be NULL if Destroy() is called when
406  // someone (other than superview) has retained |cocoa_view_|.
407  RenderWidgetHostImpl* render_widget_host_;
408
409  // Current text input type.
410  ui::TextInputType text_input_type_;
411  bool can_compose_inline_;
412
413  // The background CoreAnimation layer which is hosted by |cocoa_view_|.
414  base::scoped_nsobject<CALayer> background_layer_;
415
416  // A flipped layer, which acts as the parent of the compositing and software
417  // layers. This layer is flipped so that the we don't need to recompute the
418  // origin for sub-layers when their position changes (this is impossible when
419  // using remote layers, as their size change cannot be synchronized with the
420  // window). This indirection is needed because flipping hosted layers (like
421  // |background_layer_|) leads to unpredictable behavior.
422  base::scoped_nsobject<CALayer> flipped_layer_;
423
424  // The CoreAnimation layer hosted by the GPU process.
425  base::scoped_nsobject<CALayerHost> remote_layer_host_;
426
427  // The CoreAnimation layer for software compositing. This should be NULL
428  // when software compositing is not in use.
429  base::scoped_nsobject<SoftwareLayer> software_layer_;
430
431  // Accelerated compositing structures. These may be dynamically created and
432  // destroyed together in Create/DestroyCompositedIOSurfaceAndLayer.
433  base::scoped_nsobject<CompositingIOSurfaceLayer> compositing_iosurface_layer_;
434  scoped_refptr<CompositingIOSurfaceMac> compositing_iosurface_;
435  scoped_refptr<CompositingIOSurfaceContext> compositing_iosurface_context_;
436
437  // Delegated frame management and compositior.
438  scoped_ptr<DelegatedFrameHost> delegated_frame_host_;
439  scoped_ptr<ui::Layer> root_layer_;
440
441  // Container for the NSView drawn by the browser compositor.
442  scoped_ptr<BrowserCompositorViewMac> browser_compositor_view_;
443
444  // Placeholder that is allocated while browser_compositor_view_ is NULL,
445  // indicating that a BrowserCompositorViewMac may be allocated. This is to
446  // help in recycling the internals of BrowserCompositorViewMac.
447  scoped_ptr<BrowserCompositorViewPlaceholderMac>
448      browser_compositor_view_placeholder_;
449
450  // This holds the current software compositing framebuffer, if any.
451  scoped_ptr<SoftwareFrameManager> software_frame_manager_;
452
453  // Latency info to send back when the next frame appears on the
454  // screen.
455  std::vector<ui::LatencyInfo> pending_latency_info_;
456
457  NSWindow* pepper_fullscreen_window() const {
458    return pepper_fullscreen_window_;
459  }
460
461  CONTENT_EXPORT void release_pepper_fullscreen_window_for_testing();
462
463  RenderWidgetHostViewMac* fullscreen_parent_host_view() const {
464    return fullscreen_parent_host_view_;
465  }
466
467  RenderWidgetHostViewFrameSubscriber* frame_subscriber() const {
468    return frame_subscriber_.get();
469  }
470
471  int window_number() const;
472
473  // The scale factor for the screen that the view is currently on.
474  float ViewScaleFactor() const;
475
476  // Update the scale factor for the backing store and for any CALayers.
477  void UpdateBackingStoreScaleFactor();
478
479  // Ensure that the display link is associated with the correct display.
480  void UpdateDisplayLink();
481
482  // The scale factor of the backing store. Note that this is updated based on
483  // ViewScaleFactor with some delay.
484  float backing_store_scale_factor_;
485
486  void AddPendingLatencyInfo(
487      const std::vector<ui::LatencyInfo>& latency_info);
488  void SendPendingLatencyInfoToHost();
489
490  void SendPendingSwapAck();
491
492  void PauseForPendingResizeOrRepaintsAndDraw();
493
494  // The geometric arrangement of the layers depends on cocoa_view's size, the
495  // compositing IOSurface's rounded size, and the software frame size. Update
496  // all of them using this function when any of those parameters changes. Also
497  // update the scale factor of the layers.
498  void LayoutLayers();
499
500  // DelegatedFrameHostClient implementation.
501  virtual ui::Compositor* GetCompositor() const OVERRIDE;
502  virtual ui::Layer* GetLayer() OVERRIDE;
503  virtual RenderWidgetHostImpl* GetHost() OVERRIDE;
504  virtual void SchedulePaintInRect(
505      const gfx::Rect& damage_rect_in_dip) OVERRIDE;
506  virtual bool IsVisible() OVERRIDE;
507  virtual scoped_ptr<ResizeLock> CreateResizeLock(
508      bool defer_compositor_lock) OVERRIDE;
509  virtual gfx::Size DesiredFrameSize() OVERRIDE;
510  virtual float CurrentDeviceScaleFactor() OVERRIDE;
511  virtual gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) OVERRIDE;
512  virtual DelegatedFrameHost* GetDelegatedFrameHost() const OVERRIDE;
513
514  // BrowserCompositorViewMacClient implementation.
515  virtual void BrowserCompositorViewFrameSwapped(
516      const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
517  virtual NSView* BrowserCompositorSuperview() OVERRIDE;
518  virtual ui::Layer* BrowserCompositorRootLayer() OVERRIDE;
519
520 private:
521  friend class RenderWidgetHostViewMacTest;
522
523  struct PendingSwapAck {
524    PendingSwapAck(int32 route_id, int gpu_host_id, int32 renderer_id)
525        : route_id(route_id),
526          gpu_host_id(gpu_host_id),
527          renderer_id(renderer_id) {}
528    int32 route_id;
529    int gpu_host_id;
530    int32 renderer_id;
531  };
532  scoped_ptr<PendingSwapAck> pending_swap_ack_;
533  void AddPendingSwapAck(int32 route_id, int gpu_host_id, int32 renderer_id);
534
535  // Returns whether this render view is a popup (autocomplete window).
536  bool IsPopup() const;
537
538  // Shuts down the render_widget_host_.  This is a separate function so we can
539  // invoke it from the message loop.
540  void ShutdownHost();
541
542  void EnsureBrowserCompositorView();
543  void DestroyBrowserCompositorView();
544
545  void EnsureSoftwareLayer();
546  void DestroySoftwareLayer();
547
548  bool EnsureCompositedIOSurface() WARN_UNUSED_RESULT;
549  void EnsureCompositedIOSurfaceLayer();
550  enum DestroyCompositedIOSurfaceLayerBehavior {
551    kLeaveLayerInHierarchy,
552    kRemoveLayerFromHierarchy,
553  };
554  void DestroyCompositedIOSurfaceLayer(
555      DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior);
556  void DestroyCompositedIOSurfaceAndLayer();
557
558  void DestroyCompositingStateOnError();
559
560  // Called when a GPU SwapBuffers is received.
561  void GotAcceleratedFrame();
562
563  // Called when a software DIB is received.
564  void GotSoftwareFrame();
565
566  // IPC message handlers.
567  void OnPluginFocusChanged(bool focused, int plugin_id);
568  void OnStartPluginIme();
569
570  // Convert |rect| from the views coordinate (upper-left origin) into
571  // the OpenGL coordinate (lower-left origin) and scale for HiDPI displays.
572  gfx::Rect GetScaledOpenGLPixelRect(const gfx::Rect& rect);
573
574  // Send updated vsync parameters to the renderer.
575  void SendVSyncParametersToRenderer();
576
577  // The associated view. This is weak and is inserted into the view hierarchy
578  // to own this RenderWidgetHostViewMac object. Set to nil at the start of the
579  // destructor.
580  RenderWidgetHostViewCocoa* cocoa_view_;
581
582  // Indicates if the page is loading.
583  bool is_loading_;
584
585  // Whether it's allowed to pause waiting for a new frame.
586  bool allow_pause_for_resize_or_repaint_;
587
588  // The text to be shown in the tooltip, supplied by the renderer.
589  base::string16 tooltip_text_;
590
591  // Factory used to safely scope delayed calls to ShutdownHost().
592  base::WeakPtrFactory<RenderWidgetHostViewMac> weak_factory_;
593
594  // selected text on the renderer.
595  std::string selected_text_;
596
597  // The window used for popup widgets.
598  base::scoped_nsobject<NSWindow> popup_window_;
599
600  // The fullscreen window used for pepper flash.
601  base::scoped_nsobject<NSWindow> pepper_fullscreen_window_;
602  base::scoped_nsobject<FullscreenWindowManager> fullscreen_window_manager_;
603  // Our parent host view, if this is fullscreen.  NULL otherwise.
604  RenderWidgetHostViewMac* fullscreen_parent_host_view_;
605
606  // Display link for getting vsync info.
607  scoped_refptr<DisplayLinkMac> display_link_;
608
609  // The current composition character range and its bounds.
610  gfx::Range composition_range_;
611  std::vector<gfx::Rect> composition_bounds_;
612
613  // The current caret bounds.
614  gfx::Rect caret_rect_;
615
616  // Subscriber that listens to frame presentation events.
617  scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
618
619  base::WeakPtrFactory<RenderWidgetHostViewMac>
620      software_frame_weak_ptr_factory_;
621  DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMac);
622};
623
624}  // namespace content
625
626#endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
627