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