| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 // These are not documented, so use only after checking -respondsToSelector:. | 112 // These are not documented, so use only after checking -respondsToSelector:. |
| 113 @interface NSApplication (UndocumentedSpeechMethods) | 113 @interface NSApplication (UndocumentedSpeechMethods) |
| 114 - (void)speakString:(NSString*)string; | 114 - (void)speakString:(NSString*)string; |
| 115 - (void)stopSpeaking:(id)sender; | 115 - (void)stopSpeaking:(id)sender; |
| 116 - (BOOL)isSpeaking; | 116 - (BOOL)isSpeaking; |
| 117 @end | 117 @end |
| 118 | 118 |
| 119 // Declare things that are part of the 10.7 SDK. | |
| 120 #if !defined(MAC_OS_X_VERSION_10_7) || \ | |
| 121 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | |
| 122 | |
| 123 static NSString* const NSWindowDidChangeBackingPropertiesNotification = | |
| 124 @"NSWindowDidChangeBackingPropertiesNotification"; | |
| 125 | |
| 126 #endif // 10.7 | |
| 127 | |
| 128 // This method will return YES for OS X versions 10.7.3 and later, and NO | 119 // This method will return YES for OS X versions 10.7.3 and later, and NO |
| 129 // otherwise. | 120 // otherwise. |
| 130 // Used to prevent a crash when building with the 10.7 SDK and accessing the | 121 // Used to prevent a crash when building with the 10.7 SDK and accessing the |
| 131 // notification below. See: http://crbug.com/260595. | 122 // notification below. See: http://crbug.com/260595. |
| 132 static BOOL SupportsBackingPropertiesChangedNotification() { | 123 static BOOL SupportsBackingPropertiesChangedNotification() { |
| 133 // windowDidChangeBackingProperties: method has been added to the | 124 // windowDidChangeBackingProperties: method has been added to the |
| 134 // NSWindowDelegate protocol in 10.7.3, at the same time as the | 125 // NSWindowDelegate protocol in 10.7.3, at the same time as the |
| 135 // NSWindowDidChangeBackingPropertiesNotification notification was added. | 126 // NSWindowDidChangeBackingPropertiesNotification notification was added. |
| 136 // If the protocol contains this method description, the notification should | 127 // If the protocol contains this method description, the notification should |
| 137 // be supported as well. | 128 // be supported as well. |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 388 } |
| 398 | 389 |
| 399 } // namespace | 390 } // namespace |
| 400 | 391 |
| 401 namespace content { | 392 namespace content { |
| 402 | 393 |
| 403 //////////////////////////////////////////////////////////////////////////////// | 394 //////////////////////////////////////////////////////////////////////////////// |
| 404 // DelegatedFrameHost, public: | 395 // DelegatedFrameHost, public: |
| 405 | 396 |
| 406 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { | 397 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { |
| 407 if (browser_compositor_view_) | 398 // When |browser_compositor_view_| is suspended or destroyed, the connection |
| 399 // between its ui::Compositor and |delegated_frame_host_| has been severed. |
| 400 if (browser_compositor_state_ == BrowserCompositorActive) |
| 408 return browser_compositor_view_->GetCompositor(); | 401 return browser_compositor_view_->GetCompositor(); |
| 409 return NULL; | 402 return NULL; |
| 410 } | 403 } |
| 411 | 404 |
| 412 ui::Layer* RenderWidgetHostViewMac::GetLayer() { | 405 ui::Layer* RenderWidgetHostViewMac::GetLayer() { |
| 413 return root_layer_.get(); | 406 return root_layer_.get(); |
| 414 } | 407 } |
| 415 | 408 |
| 416 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { | 409 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { |
| 417 return render_widget_host_; | 410 return render_widget_host_; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 505 } |
| 513 | 506 |
| 514 /////////////////////////////////////////////////////////////////////////////// | 507 /////////////////////////////////////////////////////////////////////////////// |
| 515 // RenderWidgetHostViewMac, public: | 508 // RenderWidgetHostViewMac, public: |
| 516 | 509 |
| 517 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 510 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
| 518 bool is_guest_view_hack) | 511 bool is_guest_view_hack) |
| 519 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 512 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 520 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 513 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 521 can_compose_inline_(true), | 514 can_compose_inline_(true), |
| 515 browser_compositor_state_(BrowserCompositorDestroyed), |
| 522 browser_compositor_view_placeholder_( | 516 browser_compositor_view_placeholder_( |
| 523 new BrowserCompositorViewPlaceholderMac), | 517 new BrowserCompositorViewPlaceholderMac), |
| 524 is_loading_(false), | 518 is_loading_(false), |
| 525 allow_pause_for_resize_or_repaint_(true), | 519 allow_pause_for_resize_or_repaint_(true), |
| 526 is_guest_view_hack_(is_guest_view_hack), | 520 is_guest_view_hack_(is_guest_view_hack), |
| 527 weak_factory_(this), | 521 weak_factory_(this), |
| 528 fullscreen_parent_host_view_(NULL) { | 522 fullscreen_parent_host_view_(NULL) { |
| 529 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 523 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
| 530 // goes away. Since we autorelease it, our caller must put | 524 // goes away. Since we autorelease it, our caller must put |
| 531 // |GetNativeView()| into the view hierarchy right after calling us. | 525 // |GetNativeView()| into the view hierarchy right after calling us. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 } | 575 } |
| 582 | 576 |
| 583 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { | 577 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { |
| 584 allow_pause_for_resize_or_repaint_ = allow; | 578 allow_pause_for_resize_or_repaint_ = allow; |
| 585 } | 579 } |
| 586 | 580 |
| 587 /////////////////////////////////////////////////////////////////////////////// | 581 /////////////////////////////////////////////////////////////////////////////// |
| 588 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 582 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| 589 | 583 |
| 590 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { | 584 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { |
| 591 if (browser_compositor_view_) | |
| 592 return; | |
| 593 | |
| 594 TRACE_EVENT0("browser", | 585 TRACE_EVENT0("browser", |
| 595 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); | 586 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); |
| 596 | 587 |
| 597 browser_compositor_view_.reset( | 588 // Create the view, to transition from Destroyed -> Suspended. |
| 598 new BrowserCompositorViewMac(this, cocoa_view_, root_layer_.get())); | 589 if (browser_compositor_state_ == BrowserCompositorDestroyed) { |
| 599 delegated_frame_host_->AddedToWindow(); | 590 browser_compositor_view_.reset( |
| 600 delegated_frame_host_->WasShown(ui::LatencyInfo()); | 591 new BrowserCompositorViewMac(this, cocoa_view_, root_layer_.get())); |
| 592 browser_compositor_state_ = BrowserCompositorSuspended; |
| 593 } |
| 594 |
| 595 // Show the DelegatedFrameHost to transition from Suspended -> Active. |
| 596 if (browser_compositor_state_ == BrowserCompositorSuspended) { |
| 597 delegated_frame_host_->AddedToWindow(); |
| 598 delegated_frame_host_->WasShown(ui::LatencyInfo()); |
| 599 browser_compositor_state_ = BrowserCompositorActive; |
| 600 } |
| 601 } |
| 602 |
| 603 void RenderWidgetHostViewMac::SuspendBrowserCompositorView() { |
| 604 TRACE_EVENT0("browser", |
| 605 "RenderWidgetHostViewMac::SuspendBrowserCompositorView"); |
| 606 |
| 607 // Hide the DelegatedFrameHost to transition from Active -> Suspended. |
| 608 if (browser_compositor_state_ == BrowserCompositorActive) { |
| 609 // Marking the DelegatedFrameHost as removed from the window hierarchy is |
| 610 // necessary to remove all connections to its old ui::Compositor. |
| 611 delegated_frame_host_->WasHidden(); |
| 612 delegated_frame_host_->RemovingFromWindow(); |
| 613 browser_compositor_state_ = BrowserCompositorSuspended; |
| 614 } |
| 601 } | 615 } |
| 602 | 616 |
| 603 void RenderWidgetHostViewMac::DestroyBrowserCompositorView() { | 617 void RenderWidgetHostViewMac::DestroyBrowserCompositorView() { |
| 604 TRACE_EVENT0("browser", | 618 TRACE_EVENT0("browser", |
| 605 "RenderWidgetHostViewMac::DestroyBrowserCompositorView"); | 619 "RenderWidgetHostViewMac::DestroyBrowserCompositorView"); |
| 606 if (!browser_compositor_view_) | 620 |
| 621 // Transition from Active -> Suspended if need be. |
| 622 SuspendBrowserCompositorView(); |
| 623 |
| 624 // Destroy the BrowserCompositorView to transition Suspended -> Destroyed. |
| 625 if (browser_compositor_state_ == BrowserCompositorSuspended) { |
| 626 browser_compositor_view_.reset(); |
| 627 browser_compositor_state_ = BrowserCompositorDestroyed; |
| 628 } |
| 629 } |
| 630 |
| 631 void RenderWidgetHostViewMac::DestroySuspendedBrowserCompositorViewIfNeeded() { |
| 632 if (browser_compositor_state_ != BrowserCompositorSuspended) |
| 607 return; | 633 return; |
| 608 | 634 |
| 609 // Marking the DelegatedFrameHost as removed from the window hierarchy is | 635 // If this view is in a window that is visible, keep around the suspended |
| 610 // necessary to remove all connections to its old ui::Compositor. | 636 // BrowserCompositorView in case |cocoa_view_| is suddenly revealed (so that |
| 611 delegated_frame_host_->WasHidden(); | 637 // we don't flash white). |
| 612 delegated_frame_host_->RemovingFromWindow(); | 638 NSWindow* window = [cocoa_view_ window]; |
| 613 browser_compositor_view_.reset(); | 639 if (window) |
| 640 return; |
| 641 |
| 642 // This should only be reached if |render_widget_host_| is hidden, destroyed, |
| 643 // or in the process of being destroyed. |
| 644 DestroyBrowserCompositorView(); |
| 614 } | 645 } |
| 615 | 646 |
| 616 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 647 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
| 617 bool handled = true; | 648 bool handled = true; |
| 618 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 649 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
| 619 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) | 650 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) |
| 620 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) | 651 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) |
| 621 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 652 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
| 622 OnGetRenderedTextCompleted) | 653 OnGetRenderedTextCompleted) |
| 623 IPC_MESSAGE_UNHANDLED(handled = false) | 654 IPC_MESSAGE_UNHANDLED(handled = false) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 // If there is not a frame being currently drawn, kick one, so that the below | 820 // If there is not a frame being currently drawn, kick one, so that the below |
| 790 // pause will have a frame to wait on. | 821 // pause will have a frame to wait on. |
| 791 render_widget_host_->ScheduleComposite(); | 822 render_widget_host_->ScheduleComposite(); |
| 792 PauseForPendingResizeOrRepaintsAndDraw(); | 823 PauseForPendingResizeOrRepaintsAndDraw(); |
| 793 } | 824 } |
| 794 | 825 |
| 795 void RenderWidgetHostViewMac::WasHidden() { | 826 void RenderWidgetHostViewMac::WasHidden() { |
| 796 if (render_widget_host_->is_hidden()) | 827 if (render_widget_host_->is_hidden()) |
| 797 return; | 828 return; |
| 798 | 829 |
| 799 DestroyBrowserCompositorView(); | |
| 800 | |
| 801 // If we have a renderer, then inform it that we are being hidden so it can | 830 // If we have a renderer, then inform it that we are being hidden so it can |
| 802 // reduce its resource utilization. | 831 // reduce its resource utilization. |
| 803 render_widget_host_->WasHidden(); | 832 render_widget_host_->WasHidden(); |
| 833 |
| 834 SuspendBrowserCompositorView(); |
| 835 DestroySuspendedBrowserCompositorViewIfNeeded(); |
| 804 } | 836 } |
| 805 | 837 |
| 806 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { | 838 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |
| 807 gfx::Rect rect = GetViewBounds(); | 839 gfx::Rect rect = GetViewBounds(); |
| 808 rect.set_size(size); | 840 rect.set_size(size); |
| 809 SetBounds(rect); | 841 SetBounds(rect); |
| 810 } | 842 } |
| 811 | 843 |
| 812 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { | 844 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { |
| 813 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, | 845 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, |
| (...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 | 3078 |
| 3047 // Inserting text will delete all marked text automatically. | 3079 // Inserting text will delete all marked text automatically. |
| 3048 hasMarkedText_ = NO; | 3080 hasMarkedText_ = NO; |
| 3049 } | 3081 } |
| 3050 | 3082 |
| 3051 - (void)insertText:(id)string { | 3083 - (void)insertText:(id)string { |
| 3052 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; | 3084 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; |
| 3053 } | 3085 } |
| 3054 | 3086 |
| 3055 - (void)viewDidMoveToWindow { | 3087 - (void)viewDidMoveToWindow { |
| 3056 if ([self window]) | 3088 if ([self window]) { |
| 3057 [self updateScreenProperties]; | 3089 [self updateScreenProperties]; |
| 3090 } else { |
| 3091 // If the RenderWidgetHostViewCocoa is being removed from its window, tear |
| 3092 // down its browser compositor resources, if needed. |
| 3093 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded(); |
| 3094 } |
| 3058 | 3095 |
| 3059 if (canBeKeyView_) { | 3096 if (canBeKeyView_) { |
| 3060 NSWindow* newWindow = [self window]; | 3097 NSWindow* newWindow = [self window]; |
| 3061 // Pointer comparison only, since we don't know if lastWindow_ is still | 3098 // Pointer comparison only, since we don't know if lastWindow_ is still |
| 3062 // valid. | 3099 // valid. |
| 3063 if (newWindow) { | 3100 if (newWindow) { |
| 3064 // If we move into a new window, refresh the frame information. We | 3101 // If we move into a new window, refresh the frame information. We |
| 3065 // don't need to do it if it was the same window as it used to be in, | 3102 // don't need to do it if it was the same window as it used to be in, |
| 3066 // since that case is covered by WasShown(). We only want to do this for | 3103 // since that case is covered by WasShown(). We only want to do this for |
| 3067 // real browser views, not popups. | 3104 // real browser views, not popups. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3308 | 3345 |
| 3309 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3346 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3310 // regions that are not draggable. (See ControlRegionView in | 3347 // regions that are not draggable. (See ControlRegionView in |
| 3311 // native_app_window_cocoa.mm). This requires the render host view to be | 3348 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3312 // draggable by default. | 3349 // draggable by default. |
| 3313 - (BOOL)mouseDownCanMoveWindow { | 3350 - (BOOL)mouseDownCanMoveWindow { |
| 3314 return YES; | 3351 return YES; |
| 3315 } | 3352 } |
| 3316 | 3353 |
| 3317 @end | 3354 @end |
| OLD | NEW |