Upstream version 9.37.195.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   NSWindow* pepper_fullscreen_window() const {
446     return pepper_fullscreen_window_;
447   }
448
449   CONTENT_EXPORT void release_pepper_fullscreen_window_for_testing();
450
451   RenderWidgetHostViewMac* fullscreen_parent_host_view() const {
452     return fullscreen_parent_host_view_;
453   }
454
455   RenderWidgetHostViewFrameSubscriber* frame_subscriber() const {
456     return frame_subscriber_.get();
457   }
458
459   int window_number() const;
460
461   // The scale factor for the screen that the view is currently on.
462   float ViewScaleFactor() const;
463
464   // Update the scale factor for the backing store and for any CALayers.
465   void UpdateBackingStoreScaleFactor();
466
467   // Ensure that the display link is associated with the correct display.
468   void UpdateDisplayLink();
469
470   // The scale factor of the backing store. Note that this is updated based on
471   // ViewScaleFactor with some delay.
472   float backing_store_scale_factor_;
473
474   void AddPendingLatencyInfo(
475       const std::vector<ui::LatencyInfo>& latency_info);
476   void SendPendingLatencyInfoToHost();
477
478   void SendPendingSwapAck();
479
480   void PauseForPendingResizeOrRepaintsAndDraw();
481
482   // The geometric arrangement of the layers depends on cocoa_view's size, the
483   // compositing IOSurface's rounded size, and the software frame size. Update
484   // all of them using this function when any of those parameters changes. Also
485   // update the scale factor of the layers.
486   void LayoutLayers();
487
488   // DelegatedFrameHostClient implementation.
489   virtual ui::Compositor* GetCompositor() const OVERRIDE;
490   virtual ui::Layer* GetLayer() OVERRIDE;
491   virtual RenderWidgetHostImpl* GetHost() OVERRIDE;
492   virtual void SchedulePaintInRect(
493       const gfx::Rect& damage_rect_in_dip) OVERRIDE;
494   virtual bool IsVisible() OVERRIDE;
495   virtual scoped_ptr<ResizeLock> CreateResizeLock(
496       bool defer_compositor_lock) OVERRIDE;
497   virtual gfx::Size DesiredFrameSize() OVERRIDE;
498   virtual float CurrentDeviceScaleFactor() OVERRIDE;
499   virtual gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) OVERRIDE;
500   virtual DelegatedFrameHost* GetDelegatedFrameHost() const OVERRIDE;
501
502  private:
503   friend class RenderWidgetHostViewMacTest;
504
505   struct PendingSwapAck {
506     PendingSwapAck(int32 route_id, int gpu_host_id, int32 renderer_id)
507         : route_id(route_id),
508           gpu_host_id(gpu_host_id),
509           renderer_id(renderer_id) {}
510     int32 route_id;
511     int gpu_host_id;
512     int32 renderer_id;
513   };
514   scoped_ptr<PendingSwapAck> pending_swap_ack_;
515   void AddPendingSwapAck(int32 route_id, int gpu_host_id, int32 renderer_id);
516
517   // Returns whether this render view is a popup (autocomplete window).
518   bool IsPopup() const;
519
520   // Shuts down the render_widget_host_.  This is a separate function so we can
521   // invoke it from the message loop.
522   void ShutdownHost();
523
524   void EnsureSoftwareLayer();
525   void DestroySoftwareLayer();
526
527   bool EnsureCompositedIOSurface() WARN_UNUSED_RESULT;
528   void EnsureCompositedIOSurfaceLayer();
529   enum DestroyCompositedIOSurfaceLayerBehavior {
530     kLeaveLayerInHierarchy,
531     kRemoveLayerFromHierarchy,
532   };
533   void DestroyCompositedIOSurfaceLayer(
534       DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior);
535   void DestroyCompositedIOSurfaceAndLayer();
536
537   void DestroyCompositingStateOnError();
538
539   // Called when a GPU SwapBuffers is received.
540   void GotAcceleratedFrame();
541
542   // Called when a software DIB is received.
543   void GotSoftwareFrame();
544
545   // IPC message handlers.
546   void OnPluginFocusChanged(bool focused, int plugin_id);
547   void OnStartPluginIme();
548
549   // Convert |rect| from the views coordinate (upper-left origin) into
550   // the OpenGL coordinate (lower-left origin) and scale for HiDPI displays.
551   gfx::Rect GetScaledOpenGLPixelRect(const gfx::Rect& rect);
552
553   // Send updated vsync parameters to the renderer.
554   void SendVSyncParametersToRenderer();
555
556   // The associated view. This is weak and is inserted into the view hierarchy
557   // to own this RenderWidgetHostViewMac object. Set to nil at the start of the
558   // destructor.
559   RenderWidgetHostViewCocoa* cocoa_view_;
560
561   // Indicates if the page is loading.
562   bool is_loading_;
563
564   // The text to be shown in the tooltip, supplied by the renderer.
565   base::string16 tooltip_text_;
566
567   // Factory used to safely scope delayed calls to ShutdownHost().
568   base::WeakPtrFactory<RenderWidgetHostViewMac> weak_factory_;
569
570   // selected text on the renderer.
571   std::string selected_text_;
572
573   // The window used for popup widgets.
574   base::scoped_nsobject<NSWindow> popup_window_;
575
576   // The fullscreen window used for pepper flash.
577   base::scoped_nsobject<NSWindow> pepper_fullscreen_window_;
578   base::scoped_nsobject<FullscreenWindowManager> fullscreen_window_manager_;
579   // Our parent host view, if this is fullscreen.  NULL otherwise.
580   RenderWidgetHostViewMac* fullscreen_parent_host_view_;
581
582   // The overlay view which is rendered above this one in the same
583   // accelerated IOSurface.
584   // Overlay view has |underlay_view_| set to this view.
585   base::WeakPtr<RenderWidgetHostViewMac> overlay_view_;
586
587   // The underlay view which this view is rendered above in the same
588   // accelerated IOSurface.
589   // Underlay view has |overlay_view_| set to this view.
590   base::WeakPtr<RenderWidgetHostViewMac> underlay_view_;
591
592   // Factory used to safely reference overlay view set in SetOverlayView.
593   base::WeakPtrFactory<RenderWidgetHostViewMac>
594       overlay_view_weak_factory_;
595
596   // Display link for getting vsync info.
597   scoped_refptr<DisplayLinkMac> display_link_;
598
599   // The current composition character range and its bounds.
600   gfx::Range composition_range_;
601   std::vector<gfx::Rect> composition_bounds_;
602
603   // The current caret bounds.
604   gfx::Rect caret_rect_;
605
606   // Subscriber that listens to frame presentation events.
607   scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
608
609   base::WeakPtrFactory<RenderWidgetHostViewMac>
610       software_frame_weak_ptr_factory_;
611   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMac);
612 };
613
614 }  // namespace content
615
616 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_