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