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