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