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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 } | 503 } |
513 | 504 |
514 /////////////////////////////////////////////////////////////////////////////// | 505 /////////////////////////////////////////////////////////////////////////////// |
515 // RenderWidgetHostViewMac, public: | 506 // RenderWidgetHostViewMac, public: |
516 | 507 |
517 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 508 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
518 bool is_guest_view_hack) | 509 bool is_guest_view_hack) |
519 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 510 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
520 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 511 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
521 can_compose_inline_(true), | 512 can_compose_inline_(true), |
513 browser_compositor_state_(BrowserCompositorDestroyed), | |
522 browser_compositor_view_placeholder_( | 514 browser_compositor_view_placeholder_( |
523 new BrowserCompositorViewPlaceholderMac), | 515 new BrowserCompositorViewPlaceholderMac), |
524 is_loading_(false), | 516 is_loading_(false), |
525 allow_pause_for_resize_or_repaint_(true), | 517 allow_pause_for_resize_or_repaint_(true), |
526 is_guest_view_hack_(is_guest_view_hack), | 518 is_guest_view_hack_(is_guest_view_hack), |
527 weak_factory_(this), | 519 weak_factory_(this), |
528 fullscreen_parent_host_view_(NULL) { | 520 fullscreen_parent_host_view_(NULL) { |
529 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 521 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
530 // goes away. Since we autorelease it, our caller must put | 522 // goes away. Since we autorelease it, our caller must put |
531 // |GetNativeView()| into the view hierarchy right after calling us. | 523 // |GetNativeView()| into the view hierarchy right after calling us. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 } | 573 } |
582 | 574 |
583 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { | 575 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { |
584 allow_pause_for_resize_or_repaint_ = allow; | 576 allow_pause_for_resize_or_repaint_ = allow; |
585 } | 577 } |
586 | 578 |
587 /////////////////////////////////////////////////////////////////////////////// | 579 /////////////////////////////////////////////////////////////////////////////// |
588 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 580 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
589 | 581 |
590 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { | 582 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { |
591 if (browser_compositor_view_) | |
592 return; | |
593 | |
594 TRACE_EVENT0("browser", | 583 TRACE_EVENT0("browser", |
595 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); | 584 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); |
596 | 585 |
597 browser_compositor_view_.reset( | 586 // Create the view, to transition from Destroyed -> Suspended. |
598 new BrowserCompositorViewMac(this, cocoa_view_, root_layer_.get())); | 587 if (browser_compositor_state_ == BrowserCompositorDestroyed) { |
599 delegated_frame_host_->AddedToWindow(); | 588 browser_compositor_view_.reset( |
600 delegated_frame_host_->WasShown(ui::LatencyInfo()); | 589 new BrowserCompositorViewMac(this, cocoa_view_, root_layer_.get())); |
590 browser_compositor_state_ = BrowserCompositorSuspended; | |
591 } | |
592 | |
593 // Show the DelegatedFrameHost to transition from Suspended -> Active. | |
594 if (browser_compositor_state_ == BrowserCompositorSuspended) { | |
595 delegated_frame_host_->AddedToWindow(); | |
596 delegated_frame_host_->WasShown(ui::LatencyInfo()); | |
597 browser_compositor_state_ = BrowserCompositorActive; | |
598 } | |
599 } | |
600 | |
601 void RenderWidgetHostViewMac::SuspendBrowserCompositorView() { | |
602 TRACE_EVENT0("browser", | |
603 "RenderWidgetHostViewMac::SuspendBrowserCompositorView"); | |
604 | |
605 // Hide the DelegatedFrameHost to transition from Active -> Suspended. | |
606 if (browser_compositor_state_ == BrowserCompositorActive) { | |
607 // Marking the DelegatedFrameHost as removed from the window hierarchy is | |
608 // necessary to remove all connections to its old ui::Compositor. | |
609 delegated_frame_host_->WasHidden(); | |
610 delegated_frame_host_->RemovingFromWindow(); | |
611 browser_compositor_state_ = BrowserCompositorSuspended; | |
612 } | |
601 } | 613 } |
602 | 614 |
603 void RenderWidgetHostViewMac::DestroyBrowserCompositorView() { | 615 void RenderWidgetHostViewMac::DestroyBrowserCompositorView() { |
604 TRACE_EVENT0("browser", | 616 TRACE_EVENT0("browser", |
605 "RenderWidgetHostViewMac::DestroyBrowserCompositorView"); | 617 "RenderWidgetHostViewMac::DestroyBrowserCompositorView"); |
606 if (!browser_compositor_view_) | 618 |
619 // Transition from Active -> Suspended if need be. | |
620 SuspendBrowserCompositorView(); | |
621 | |
622 // Destroy the BrowserCompositorView to transition Suspended -> Destroyed. | |
623 if (browser_compositor_state_ == BrowserCompositorSuspended) { | |
624 browser_compositor_view_.reset(); | |
625 browser_compositor_state_ = BrowserCompositorDestroyed; | |
626 } | |
627 } | |
628 | |
629 void RenderWidgetHostViewMac::DestroySuspendedBrowserCompositorViewIfNeeded() { | |
630 if (browser_compositor_state_ != BrowserCompositorSuspended) | |
607 return; | 631 return; |
608 | 632 |
609 // Marking the DelegatedFrameHost as removed from the window hierarchy is | 633 // 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. | 634 // BrowserCompositorView in case |cocoa_view_| is suddenly revealed (so that |
611 delegated_frame_host_->WasHidden(); | 635 // we don't flash white). |
612 delegated_frame_host_->RemovingFromWindow(); | 636 NSWindow* window = [cocoa_view_ window]; |
613 browser_compositor_view_.reset(); | 637 if (window) |
638 return; | |
639 | |
640 // This should only be reached if |render_widget_host_| is hidden, destroyed, | |
641 // or in the process of being destroyed. | |
642 DestroyBrowserCompositorView(); | |
614 } | 643 } |
615 | 644 |
616 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 645 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
617 bool handled = true; | 646 bool handled = true; |
618 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 647 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
619 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) | 648 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) |
620 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) | 649 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) |
621 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 650 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
622 OnGetRenderedTextCompleted) | 651 OnGetRenderedTextCompleted) |
623 IPC_MESSAGE_UNHANDLED(handled = false) | 652 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 | 818 // If there is not a frame being currently drawn, kick one, so that the below |
790 // pause will have a frame to wait on. | 819 // pause will have a frame to wait on. |
791 render_widget_host_->ScheduleComposite(); | 820 render_widget_host_->ScheduleComposite(); |
792 PauseForPendingResizeOrRepaintsAndDraw(); | 821 PauseForPendingResizeOrRepaintsAndDraw(); |
793 } | 822 } |
794 | 823 |
795 void RenderWidgetHostViewMac::WasHidden() { | 824 void RenderWidgetHostViewMac::WasHidden() { |
796 if (render_widget_host_->is_hidden()) | 825 if (render_widget_host_->is_hidden()) |
797 return; | 826 return; |
798 | 827 |
799 DestroyBrowserCompositorView(); | |
800 | |
801 // If we have a renderer, then inform it that we are being hidden so it can | 828 // If we have a renderer, then inform it that we are being hidden so it can |
802 // reduce its resource utilization. | 829 // reduce its resource utilization. |
803 render_widget_host_->WasHidden(); | 830 render_widget_host_->WasHidden(); |
831 | |
832 SuspendBrowserCompositorView(); | |
833 DestroySuspendedBrowserCompositorViewIfNeeded(); | |
804 } | 834 } |
805 | 835 |
806 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { | 836 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |
807 gfx::Rect rect = GetViewBounds(); | 837 gfx::Rect rect = GetViewBounds(); |
808 rect.set_size(size); | 838 rect.set_size(size); |
809 SetBounds(rect); | 839 SetBounds(rect); |
810 } | 840 } |
811 | 841 |
812 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { | 842 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { |
813 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, | 843 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, |
(...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3046 | 3076 |
3047 // Inserting text will delete all marked text automatically. | 3077 // Inserting text will delete all marked text automatically. |
3048 hasMarkedText_ = NO; | 3078 hasMarkedText_ = NO; |
3049 } | 3079 } |
3050 | 3080 |
3051 - (void)insertText:(id)string { | 3081 - (void)insertText:(id)string { |
3052 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; | 3082 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; |
3053 } | 3083 } |
3054 | 3084 |
3055 - (void)viewDidMoveToWindow { | 3085 - (void)viewDidMoveToWindow { |
3056 if ([self window]) | 3086 if ([self window]) { |
3057 [self updateScreenProperties]; | 3087 [self updateScreenProperties]; |
3088 } else { | |
3089 // If the RenderWidgetHostViewCocoa is being removed its window, tear down | |
Avi (use Gerrit)
2014/10/30 19:32:52
s/removed its/removed from its/
ccameron
2014/10/30 19:52:10
Done.
| |
3090 // its browser compositor resources, if needed. | |
3091 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded(); | |
3092 } | |
3058 | 3093 |
3059 if (canBeKeyView_) { | 3094 if (canBeKeyView_) { |
3060 NSWindow* newWindow = [self window]; | 3095 NSWindow* newWindow = [self window]; |
3061 // Pointer comparison only, since we don't know if lastWindow_ is still | 3096 // Pointer comparison only, since we don't know if lastWindow_ is still |
3062 // valid. | 3097 // valid. |
3063 if (newWindow) { | 3098 if (newWindow) { |
3064 // If we move into a new window, refresh the frame information. We | 3099 // 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, | 3100 // 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 | 3101 // since that case is covered by WasShown(). We only want to do this for |
3067 // real browser views, not popups. | 3102 // real browser views, not popups. |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3308 | 3343 |
3309 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3344 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3310 // regions that are not draggable. (See ControlRegionView in | 3345 // regions that are not draggable. (See ControlRegionView in |
3311 // native_app_window_cocoa.mm). This requires the render host view to be | 3346 // native_app_window_cocoa.mm). This requires the render host view to be |
3312 // draggable by default. | 3347 // draggable by default. |
3313 - (BOOL)mouseDownCanMoveWindow { | 3348 - (BOOL)mouseDownCanMoveWindow { |
3314 return YES; | 3349 return YES; |
3315 } | 3350 } |
3316 | 3351 |
3317 @end | 3352 @end |
OLD | NEW |