| 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 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 405 |
| 406 //////////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////////// |
| 407 // DelegatedFrameHost, public: | 407 // DelegatedFrameHost, public: |
| 408 | 408 |
| 409 int RenderWidgetHostViewMac::DelegatedFrameHostGetGpuMemoryBufferClientId() | 409 int RenderWidgetHostViewMac::DelegatedFrameHostGetGpuMemoryBufferClientId() |
| 410 const { | 410 const { |
| 411 return render_widget_host_->GetProcess()->GetID(); | 411 return render_widget_host_->GetProcess()->GetID(); |
| 412 } | 412 } |
| 413 | 413 |
| 414 ui::Layer* RenderWidgetHostViewMac::DelegatedFrameHostGetLayer() const { | 414 ui::Layer* RenderWidgetHostViewMac::DelegatedFrameHostGetLayer() const { |
| 415 return root_layer_.get(); | 415 return browser_compositor_->GetRootLayer(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 bool RenderWidgetHostViewMac::DelegatedFrameHostIsVisible() const { | 418 bool RenderWidgetHostViewMac::DelegatedFrameHostIsVisible() const { |
| 419 return !render_widget_host_->is_hidden(); | 419 return !render_widget_host_->is_hidden(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 SkColor RenderWidgetHostViewMac::DelegatedFrameHostGetGutterColor( | 422 SkColor RenderWidgetHostViewMac::DelegatedFrameHostGetGutterColor( |
| 423 SkColor color) const { | 423 SkColor color) const { |
| 424 // When making an element on the page fullscreen the element's background | 424 // When making an element on the page fullscreen the element's background |
| 425 // may not match the page's, so use black as the gutter color to avoid | 425 // may not match the page's, so use black as the gutter color to avoid |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 if (begin_frame_source_) { | 495 if (begin_frame_source_) { |
| 496 if (needs_begin_frames_) | 496 if (needs_begin_frames_) |
| 497 begin_frame_source_->AddObserver(this); | 497 begin_frame_source_->AddObserver(this); |
| 498 else | 498 else |
| 499 begin_frame_source_->RemoveObserver(this); | 499 begin_frame_source_->RemoveObserver(this); |
| 500 } | 500 } |
| 501 } | 501 } |
| 502 | 502 |
| 503 void RenderWidgetHostViewMac::OnBeginFrame( | 503 void RenderWidgetHostViewMac::OnBeginFrame( |
| 504 const cc::BeginFrameArgs& args) { | 504 const cc::BeginFrameArgs& args) { |
| 505 delegated_frame_host_->SetVSyncParameters(args.frame_time, args.interval); | 505 browser_compositor_->GetDelegatedFrameHost()->SetVSyncParameters( |
| 506 args.frame_time, args.interval); |
| 506 render_widget_host_->Send( | 507 render_widget_host_->Send( |
| 507 new ViewMsg_BeginFrame(render_widget_host_->GetRoutingID(), args)); | 508 new ViewMsg_BeginFrame(render_widget_host_->GetRoutingID(), args)); |
| 508 last_begin_frame_args_ = args; | 509 last_begin_frame_args_ = args; |
| 509 } | 510 } |
| 510 | 511 |
| 511 const cc::BeginFrameArgs& RenderWidgetHostViewMac::LastUsedBeginFrameArgs() | 512 const cc::BeginFrameArgs& RenderWidgetHostViewMac::LastUsedBeginFrameArgs() |
| 512 const { | 513 const { |
| 513 return last_begin_frame_args_; | 514 return last_begin_frame_args_; |
| 514 } | 515 } |
| 515 | 516 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 550 } |
| 550 | 551 |
| 551 /////////////////////////////////////////////////////////////////////////////// | 552 /////////////////////////////////////////////////////////////////////////////// |
| 552 // RenderWidgetHostViewMac, public: | 553 // RenderWidgetHostViewMac, public: |
| 553 | 554 |
| 554 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 555 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
| 555 bool is_guest_view_hack) | 556 bool is_guest_view_hack) |
| 556 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 557 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 557 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 558 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 558 can_compose_inline_(true), | 559 can_compose_inline_(true), |
| 559 browser_compositor_state_(BrowserCompositorDestroyed), | |
| 560 browser_compositor_placeholder_(new BrowserCompositorMacPlaceholder), | |
| 561 page_at_minimum_scale_(true), | 560 page_at_minimum_scale_(true), |
| 562 is_loading_(false), | 561 is_loading_(false), |
| 563 allow_pause_for_resize_or_repaint_(true), | 562 allow_pause_for_resize_or_repaint_(true), |
| 564 is_guest_view_hack_(is_guest_view_hack), | 563 is_guest_view_hack_(is_guest_view_hack), |
| 565 fullscreen_parent_host_view_(nullptr), | 564 fullscreen_parent_host_view_(nullptr), |
| 566 begin_frame_source_(nullptr), | 565 begin_frame_source_(nullptr), |
| 567 needs_begin_frames_(false), | 566 needs_begin_frames_(false), |
| 568 weak_factory_(this) { | 567 weak_factory_(this) { |
| 569 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 568 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
| 570 // goes away. Since we autorelease it, our caller must put | 569 // goes away. Since we autorelease it, our caller must put |
| 571 // |GetNativeView()| into the view hierarchy right after calling us. | 570 // |GetNativeView()| into the view hierarchy right after calling us. |
| 572 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 571 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 573 initWithRenderWidgetHostViewMac:this] autorelease]; | 572 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 574 | 573 |
| 575 // Paint this view host with |background_color_| when there is no content | 574 // Paint this view host with |background_color_| when there is no content |
| 576 // ready to draw. | 575 // ready to draw. |
| 577 background_layer_.reset([[CALayer alloc] init]); | 576 background_layer_.reset([[CALayer alloc] init]); |
| 578 // Set the default color to be white. This is the wrong thing to do, but many | 577 // Set the default color to be white. This is the wrong thing to do, but many |
| 579 // UI components expect this view to be opaque. | 578 // UI components expect this view to be opaque. |
| 580 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 579 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
| 581 [cocoa_view_ setLayer:background_layer_]; | 580 [cocoa_view_ setLayer:background_layer_]; |
| 582 [cocoa_view_ setWantsLayer:YES]; | 581 [cocoa_view_ setWantsLayer:YES]; |
| 583 | 582 |
| 584 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 583 browser_compositor_.reset(new BrowserCompositorMac( |
| 585 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | 584 this, this, render_widget_host_->is_hidden(), [cocoa_view_ window])); |
| 586 | 585 |
| 587 display::Screen::GetScreen()->AddObserver(this); | 586 display::Screen::GetScreen()->AddObserver(this); |
| 588 | 587 |
| 589 if (!is_guest_view_hack_) | 588 if (!is_guest_view_hack_) |
| 590 render_widget_host_->SetView(this); | 589 render_widget_host_->SetView(this); |
| 591 | 590 |
| 592 // Let the page-level input event router know about our surface ID | 591 // Let the page-level input event router know about our surface ID |
| 593 // namespace for surface-based hit testing. | 592 // namespace for surface-based hit testing. |
| 594 if (render_widget_host_->delegate() && | 593 if (render_widget_host_->delegate() && |
| 595 render_widget_host_->delegate()->GetInputEventRouter()) { | 594 render_widget_host_->delegate()->GetInputEventRouter()) { |
| 596 render_widget_host_->delegate() | 595 render_widget_host_->delegate() |
| 597 ->GetInputEventRouter() | 596 ->GetInputEventRouter() |
| 598 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); | 597 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); |
| 599 } | 598 } |
| 600 | |
| 601 if (!render_widget_host_->is_hidden()) | |
| 602 EnsureBrowserCompositorView(); | |
| 603 } | 599 } |
| 604 | 600 |
| 605 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 601 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 606 display::Screen::GetScreen()->RemoveObserver(this); | 602 display::Screen::GetScreen()->RemoveObserver(this); |
| 607 | 603 |
| 608 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 604 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 609 // pointer. | 605 // pointer. |
| 610 cocoa_view_ = nil; | 606 cocoa_view_ = nil; |
| 611 | 607 |
| 612 UnlockMouse(); | 608 UnlockMouse(); |
| 613 | 609 |
| 614 // Ensure that the browser compositor is destroyed in a safe order. | 610 // Ensure that the browser compositor is destroyed in a safe order. |
| 615 ShutdownBrowserCompositor(); | 611 browser_compositor_->Destroy(); |
| 616 | 612 |
| 617 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 613 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the |
| 618 // RenderWidgetHost does we need to tell it not to hold a stale pointer to | 614 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
| 619 // us. | 615 // us. |
| 620 if (render_widget_host_) { | 616 if (render_widget_host_) { |
| 621 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the | 617 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the |
| 622 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's | 618 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's |
| 623 // view, the RenderWidgetHostViewGuest will do it. | 619 // view, the RenderWidgetHostViewGuest will do it. |
| 624 if (!is_guest_view_hack_) | 620 if (!is_guest_view_hack_) |
| 625 render_widget_host_->SetView(NULL); | 621 render_widget_host_->SetView(NULL); |
| 626 } | 622 } |
| 627 } | 623 } |
| 628 | 624 |
| 629 void RenderWidgetHostViewMac::SetDelegate( | 625 void RenderWidgetHostViewMac::SetDelegate( |
| 630 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { | 626 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { |
| 631 [cocoa_view_ setResponderDelegate:delegate]; | 627 [cocoa_view_ setResponderDelegate:delegate]; |
| 632 } | 628 } |
| 633 | 629 |
| 634 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { | 630 void RenderWidgetHostViewMac::SetAllowPauseForResizeOrRepaint(bool allow) { |
| 635 allow_pause_for_resize_or_repaint_ = allow; | 631 allow_pause_for_resize_or_repaint_ = allow; |
| 636 } | 632 } |
| 637 | 633 |
| 638 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { | 634 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { |
| 639 return delegated_frame_host_->SurfaceIdForTesting(); | 635 return browser_compositor_->GetDelegatedFrameHost()->SurfaceIdForTesting(); |
| 640 } | 636 } |
| 641 | 637 |
| 642 /////////////////////////////////////////////////////////////////////////////// | 638 /////////////////////////////////////////////////////////////////////////////// |
| 643 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 639 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| 644 | 640 |
| 645 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { | |
| 646 TRACE_EVENT0("browser", | |
| 647 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); | |
| 648 | |
| 649 // Create the view, to transition from Destroyed -> Suspended. | |
| 650 if (browser_compositor_state_ == BrowserCompositorDestroyed) { | |
| 651 browser_compositor_ = BrowserCompositorMac::Create(); | |
| 652 browser_compositor_->compositor()->SetRootLayer(root_layer_.get()); | |
| 653 browser_compositor_->compositor()->SetHostHasTransparentBackground( | |
| 654 !GetBackgroundOpaque()); | |
| 655 browser_compositor_->accelerated_widget_mac()->SetNSView(this); | |
| 656 browser_compositor_state_ = BrowserCompositorSuspended; | |
| 657 } | |
| 658 | |
| 659 // Show the DelegatedFrameHost to transition from Suspended -> Active. | |
| 660 if (browser_compositor_state_ == BrowserCompositorSuspended) { | |
| 661 delegated_frame_host_->SetCompositor(browser_compositor_->compositor()); | |
| 662 delegated_frame_host_->WasShown(ui::LatencyInfo()); | |
| 663 // Unsuspend the browser compositor after showing the delegated frame host. | |
| 664 // If there is not a saved delegated frame, then the delegated frame host | |
| 665 // will keep the compositor locked until a delegated frame is swapped. | |
| 666 float scale_factor = ViewScaleFactor(); | |
| 667 browser_compositor_->compositor()->SetScaleAndSize( | |
| 668 scale_factor, | |
| 669 gfx::ConvertSizeToPixel(scale_factor, GetViewBounds().size())); | |
| 670 browser_compositor_->Unsuspend(); | |
| 671 browser_compositor_state_ = BrowserCompositorActive; | |
| 672 } | |
| 673 } | |
| 674 | |
| 675 void RenderWidgetHostViewMac::SuspendBrowserCompositorView() { | |
| 676 TRACE_EVENT0("browser", | |
| 677 "RenderWidgetHostViewMac::SuspendBrowserCompositorView"); | |
| 678 | |
| 679 // Hide the DelegatedFrameHost to transition from Active -> Suspended. | |
| 680 if (browser_compositor_state_ == BrowserCompositorActive) { | |
| 681 // Ensure that any changes made to the ui::Compositor do not result in new | |
| 682 // frames being produced. | |
| 683 browser_compositor_->Suspend(); | |
| 684 // Marking the DelegatedFrameHost as removed from the window hierarchy is | |
| 685 // necessary to remove all connections to its old ui::Compositor. | |
| 686 delegated_frame_host_->WasHidden(); | |
| 687 delegated_frame_host_->ResetCompositor(); | |
| 688 browser_compositor_state_ = BrowserCompositorSuspended; | |
| 689 } | |
| 690 } | |
| 691 | |
| 692 void RenderWidgetHostViewMac::DestroyBrowserCompositorView() { | |
| 693 TRACE_EVENT0("browser", | |
| 694 "RenderWidgetHostViewMac::DestroyBrowserCompositorView"); | |
| 695 | |
| 696 // Transition from Active -> Suspended if need be. | |
| 697 SuspendBrowserCompositorView(); | |
| 698 | |
| 699 // Destroy the BrowserCompositorView to transition Suspended -> Destroyed. | |
| 700 if (browser_compositor_state_ == BrowserCompositorSuspended) { | |
| 701 browser_compositor_->accelerated_widget_mac()->ResetNSView(); | |
| 702 browser_compositor_->compositor()->SetScaleAndSize(1.0, gfx::Size(0, 0)); | |
| 703 browser_compositor_->compositor()->SetRootLayer(nullptr); | |
| 704 BrowserCompositorMac::Recycle(std::move(browser_compositor_)); | |
| 705 browser_compositor_state_ = BrowserCompositorDestroyed; | |
| 706 } | |
| 707 } | |
| 708 | |
| 709 void RenderWidgetHostViewMac::DestroySuspendedBrowserCompositorViewIfNeeded() { | |
| 710 if (browser_compositor_state_ != BrowserCompositorSuspended) | |
| 711 return; | |
| 712 | |
| 713 // If this view is in a window that is visible, keep around the suspended | |
| 714 // BrowserCompositorView in case |cocoa_view_| is suddenly revealed (so that | |
| 715 // we don't flash white). | |
| 716 NSWindow* window = [cocoa_view_ window]; | |
| 717 if (window) | |
| 718 return; | |
| 719 | |
| 720 // This should only be reached if |render_widget_host_| is hidden, destroyed, | |
| 721 // or in the process of being destroyed. | |
| 722 DestroyBrowserCompositorView(); | |
| 723 } | |
| 724 | |
| 725 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 641 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
| 726 bool handled = true; | 642 bool handled = true; |
| 727 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 643 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
| 728 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 644 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
| 729 OnGetRenderedTextCompleted) | 645 OnGetRenderedTextCompleted) |
| 730 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, | 646 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, |
| 731 OnSetNeedsBeginFrames) | 647 OnSetNeedsBeginFrames) |
| 732 IPC_MESSAGE_UNHANDLED(handled = false) | 648 IPC_MESSAGE_UNHANDLED(handled = false) |
| 733 IPC_END_MESSAGE_MAP() | 649 IPC_END_MESSAGE_MAP() |
| 734 return handled; | 650 return handled; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { | 776 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { |
| 861 if (!render_widget_host_ || !display_link_.get()) | 777 if (!render_widget_host_ || !display_link_.get()) |
| 862 return; | 778 return; |
| 863 | 779 |
| 864 if (!display_link_->GetVSyncParameters(&vsync_timebase_, &vsync_interval_)) { | 780 if (!display_link_->GetVSyncParameters(&vsync_timebase_, &vsync_interval_)) { |
| 865 vsync_timebase_ = base::TimeTicks(); | 781 vsync_timebase_ = base::TimeTicks(); |
| 866 vsync_interval_ = base::TimeDelta(); | 782 vsync_interval_ = base::TimeDelta(); |
| 867 return; | 783 return; |
| 868 } | 784 } |
| 869 | 785 |
| 870 if (browser_compositor_) { | 786 browser_compositor_->UpdateVSyncParameters(vsync_timebase_, vsync_interval_); |
| 871 browser_compositor_->compositor()->vsync_manager()->UpdateVSyncParameters( | |
| 872 vsync_timebase_, vsync_interval_); | |
| 873 } | |
| 874 } | 787 } |
| 875 | 788 |
| 876 void RenderWidgetHostViewMac::SpeakText(const std::string& text) { | 789 void RenderWidgetHostViewMac::SpeakText(const std::string& text) { |
| 877 [NSApp speakString:base::SysUTF8ToNSString(text)]; | 790 [NSApp speakString:base::SysUTF8ToNSString(text)]; |
| 878 } | 791 } |
| 879 | 792 |
| 880 void RenderWidgetHostViewMac::UpdateBackingStoreProperties() { | 793 void RenderWidgetHostViewMac::UpdateBackingStoreProperties() { |
| 881 if (!render_widget_host_) | 794 if (!render_widget_host_) |
| 882 return; | 795 return; |
| 883 render_widget_host_->NotifyScreenInfoChanged(); | 796 render_widget_host_->NotifyScreenInfoChanged(); |
| 884 } | 797 } |
| 885 | 798 |
| 886 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 799 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
| 887 return render_widget_host_; | 800 return render_widget_host_; |
| 888 } | 801 } |
| 889 | 802 |
| 890 void RenderWidgetHostViewMac::Show() { | 803 void RenderWidgetHostViewMac::Show() { |
| 891 ScopedCAActionDisabler disabler; | 804 ScopedCAActionDisabler disabler; |
| 892 [cocoa_view_ setHidden:NO]; | 805 [cocoa_view_ setHidden:NO]; |
| 893 | 806 |
| 894 // Re-create the browser compositor. If the DelegatedFrameHost has a cached | 807 browser_compositor_->SetRenderWidgetHostIsHidden(false); |
| 895 // frame from the last time it was visible, then it will immediately be | |
| 896 // drawn. If not, then the compositor will remain locked until a new delegated | |
| 897 // frame is swapped. | |
| 898 EnsureBrowserCompositorView(); | |
| 899 | 808 |
| 900 if (!render_widget_host_->is_hidden()) | 809 ui::LatencyInfo renderer_latency_info; |
| 901 return; | 810 renderer_latency_info.AddLatencyNumber( |
| 902 | 811 ui::TAB_SHOW_COMPONENT, render_widget_host_->GetLatencyComponentId(), 0); |
| 903 WasUnOccluded(); | 812 render_widget_host_->WasShown(renderer_latency_info); |
| 904 | 813 |
| 905 // If there is not a frame being currently drawn, kick one, so that the below | 814 // If there is not a frame being currently drawn, kick one, so that the below |
| 906 // pause will have a frame to wait on. | 815 // pause will have a frame to wait on. |
| 907 render_widget_host_->ScheduleComposite(); | 816 render_widget_host_->ScheduleComposite(); |
| 908 PauseForPendingResizeOrRepaintsAndDraw(); | 817 PauseForPendingResizeOrRepaintsAndDraw(); |
| 909 } | 818 } |
| 910 | 819 |
| 911 void RenderWidgetHostViewMac::Hide() { | 820 void RenderWidgetHostViewMac::Hide() { |
| 912 ScopedCAActionDisabler disabler; | 821 ScopedCAActionDisabler disabler; |
| 913 [cocoa_view_ setHidden:YES]; | 822 [cocoa_view_ setHidden:YES]; |
| 914 if (!render_widget_host_->is_hidden()) { | 823 |
| 915 // Note that the following call to WasHidden() can trigger thumbnail | 824 render_widget_host_->WasHidden(); |
| 916 // generation on behalf of the NTP, and that cannot succeed if the browser | 825 browser_compositor_->SetRenderWidgetHostIsHidden(true); |
| 917 // compositor view has been suspended. Therefore these two statements must | |
| 918 // occur in this specific order. However, because thumbnail generation is | |
| 919 // asychronous, that operation won't run before | |
| 920 // SuspendBrowserCompositorView() | |
| 921 // completes. As a result you won't get a thumbnail for the page unless you | |
| 922 // execute these two statements in this specific order. | |
| 923 render_widget_host_->WasHidden(); | |
| 924 SuspendBrowserCompositorView(); | |
| 925 } | |
| 926 DestroySuspendedBrowserCompositorViewIfNeeded(); | |
| 927 } | 826 } |
| 928 | 827 |
| 929 void RenderWidgetHostViewMac::WasUnOccluded() { | 828 void RenderWidgetHostViewMac::WasUnOccluded() { |
| 930 if (!render_widget_host_->is_hidden()) | 829 browser_compositor_->SetRenderWidgetHostIsHidden(false); |
| 931 return; | 830 render_widget_host_->WasShown(ui::LatencyInfo()); |
| 932 | |
| 933 ui::LatencyInfo renderer_latency_info; | |
| 934 renderer_latency_info.AddLatencyNumber( | |
| 935 ui::TAB_SHOW_COMPONENT, | |
| 936 render_widget_host_->GetLatencyComponentId(), | |
| 937 0); | |
| 938 render_widget_host_->WasShown(renderer_latency_info); | |
| 939 } | 831 } |
| 940 | 832 |
| 941 void RenderWidgetHostViewMac::WasOccluded() { | 833 void RenderWidgetHostViewMac::WasOccluded() { |
| 942 if (render_widget_host_->is_hidden()) | |
| 943 return; | |
| 944 | |
| 945 // Ignore occlusion when in fullscreen low power mode, because the occlusion | 834 // Ignore occlusion when in fullscreen low power mode, because the occlusion |
| 946 // is likely coming from the fullscreen low power window. | 835 // is likely coming from the fullscreen low power window. |
| 947 if (browser_compositor_) { | 836 ui::AcceleratedWidgetMac* accelerated_widget_mac = |
| 948 if (browser_compositor_->accelerated_widget_mac() | 837 browser_compositor_->GetAcceleratedWidgetMac(); |
| 949 ->MightBeInFullscreenLowPowerMode()) | 838 if (accelerated_widget_mac && |
| 950 return; | 839 accelerated_widget_mac->MightBeInFullscreenLowPowerMode()) { |
| 840 return; |
| 951 } | 841 } |
| 952 | 842 |
| 953 // Note the importance of ordering of these calls is the same in the Hide | |
| 954 // function. | |
| 955 render_widget_host_->WasHidden(); | 843 render_widget_host_->WasHidden(); |
| 956 SuspendBrowserCompositorView(); | 844 browser_compositor_->SetRenderWidgetHostIsHidden(true); |
| 957 } | 845 } |
| 958 | 846 |
| 959 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { | 847 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |
| 960 gfx::Rect rect = GetViewBounds(); | 848 gfx::Rect rect = GetViewBounds(); |
| 961 rect.set_size(size); | 849 rect.set_size(size); |
| 962 SetBounds(rect); | 850 SetBounds(rect); |
| 963 } | 851 } |
| 964 | 852 |
| 965 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { | 853 void RenderWidgetHostViewMac::SetBounds(const gfx::Rect& rect) { |
| 966 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, | 854 // |rect.size()| is view coordinates, |rect.origin| is screen coordinates, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 | 912 |
| 1025 void RenderWidgetHostViewMac::Focus() { | 913 void RenderWidgetHostViewMac::Focus() { |
| 1026 [[cocoa_view_ window] makeFirstResponder:cocoa_view_]; | 914 [[cocoa_view_ window] makeFirstResponder:cocoa_view_]; |
| 1027 } | 915 } |
| 1028 | 916 |
| 1029 bool RenderWidgetHostViewMac::HasFocus() const { | 917 bool RenderWidgetHostViewMac::HasFocus() const { |
| 1030 return [[cocoa_view_ window] firstResponder] == cocoa_view_; | 918 return [[cocoa_view_ window] firstResponder] == cocoa_view_; |
| 1031 } | 919 } |
| 1032 | 920 |
| 1033 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { | 921 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { |
| 1034 DCHECK(delegated_frame_host_); | 922 return browser_compositor_->GetDelegatedFrameHost()->CanCopyToBitmap(); |
| 1035 return delegated_frame_host_->CanCopyToBitmap(); | |
| 1036 } | 923 } |
| 1037 | 924 |
| 1038 bool RenderWidgetHostViewMac::IsShowing() { | 925 bool RenderWidgetHostViewMac::IsShowing() { |
| 1039 return ![cocoa_view_ isHidden]; | 926 return ![cocoa_view_ isHidden]; |
| 1040 } | 927 } |
| 1041 | 928 |
| 1042 gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const { | 929 gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const { |
| 1043 NSRect bounds = [cocoa_view_ bounds]; | 930 NSRect bounds = [cocoa_view_ bounds]; |
| 1044 // TODO(shess): In case of !window, the view has been removed from | 931 // TODO(shess): In case of !window, the view has been removed from |
| 1045 // the view hierarchy because the tab isn't main. Could retrieve | 932 // the view hierarchy because the tab isn't main. Could retrieve |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 fullscreen_window_manager_.reset(); | 1011 fullscreen_window_manager_.reset(); |
| 1125 [pepper_fullscreen_window_ close]; | 1012 [pepper_fullscreen_window_ close]; |
| 1126 | 1013 |
| 1127 // This can be called as part of processing the window's responder | 1014 // This can be called as part of processing the window's responder |
| 1128 // chain, for instance |-performKeyEquivalent:|. In that case the | 1015 // chain, for instance |-performKeyEquivalent:|. In that case the |
| 1129 // object needs to survive until the stack unwinds. | 1016 // object needs to survive until the stack unwinds. |
| 1130 pepper_fullscreen_window_.autorelease(); | 1017 pepper_fullscreen_window_.autorelease(); |
| 1131 | 1018 |
| 1132 // Delete the delegated frame state, which will reach back into | 1019 // Delete the delegated frame state, which will reach back into |
| 1133 // render_widget_host_. | 1020 // render_widget_host_. |
| 1134 ShutdownBrowserCompositor(); | 1021 browser_compositor_->Destroy(); |
| 1135 | 1022 |
| 1136 // Make sure none of our observers send events for us to process after | 1023 // Make sure none of our observers send events for us to process after |
| 1137 // we release render_widget_host_. | 1024 // we release render_widget_host_. |
| 1138 NotifyObserversAboutShutdown(); | 1025 NotifyObserversAboutShutdown(); |
| 1139 | 1026 |
| 1140 // We get this call just before |render_widget_host_| deletes | 1027 // We get this call just before |render_widget_host_| deletes |
| 1141 // itself. But we are owned by |cocoa_view_|, which may be retained | 1028 // itself. But we are owned by |cocoa_view_|, which may be retained |
| 1142 // by some other code. Examples are WebContentsViewMac's | 1029 // by some other code. Examples are WebContentsViewMac's |
| 1143 // |latent_focus_view_| and TabWindowController's | 1030 // |latent_focus_view_| and TabWindowController's |
| 1144 // |cachedContentView_|. | 1031 // |cachedContentView_|. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 | 1152 |
| 1266 bool RenderWidgetHostViewMac::IsPopup() const { | 1153 bool RenderWidgetHostViewMac::IsPopup() const { |
| 1267 return popup_type_ != blink::WebPopupTypeNone; | 1154 return popup_type_ != blink::WebPopupTypeNone; |
| 1268 } | 1155 } |
| 1269 | 1156 |
| 1270 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 1157 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
| 1271 const gfx::Rect& src_subrect, | 1158 const gfx::Rect& src_subrect, |
| 1272 const gfx::Size& dst_size, | 1159 const gfx::Size& dst_size, |
| 1273 const ReadbackRequestCallback& callback, | 1160 const ReadbackRequestCallback& callback, |
| 1274 const SkColorType preferred_color_type) { | 1161 const SkColorType preferred_color_type) { |
| 1275 DCHECK(delegated_frame_host_); | 1162 browser_compositor_->CopyFromCompositingSurface( |
| 1276 delegated_frame_host_->CopyFromCompositingSurface( | |
| 1277 src_subrect, dst_size, callback, preferred_color_type); | 1163 src_subrect, dst_size, callback, preferred_color_type); |
| 1278 } | 1164 } |
| 1279 | 1165 |
| 1280 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( | 1166 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( |
| 1281 const gfx::Rect& src_subrect, | 1167 const gfx::Rect& src_subrect, |
| 1282 const scoped_refptr<media::VideoFrame>& target, | 1168 const scoped_refptr<media::VideoFrame>& target, |
| 1283 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 1169 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 1284 DCHECK(delegated_frame_host_); | 1170 browser_compositor_->CopyFromCompositingSurfaceToVideoFrame(src_subrect, |
| 1285 delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame( | 1171 target, callback); |
| 1286 src_subrect, target, callback); | |
| 1287 } | 1172 } |
| 1288 | 1173 |
| 1289 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { | 1174 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { |
| 1290 DCHECK(delegated_frame_host_); | 1175 return browser_compositor_->GetDelegatedFrameHost()->CanCopyToVideoFrame(); |
| 1291 return delegated_frame_host_->CanCopyToVideoFrame(); | |
| 1292 } | 1176 } |
| 1293 | 1177 |
| 1294 void RenderWidgetHostViewMac::BeginFrameSubscription( | 1178 void RenderWidgetHostViewMac::BeginFrameSubscription( |
| 1295 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1179 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
| 1296 DCHECK(delegated_frame_host_); | 1180 browser_compositor_->GetDelegatedFrameHost()->BeginFrameSubscription( |
| 1297 delegated_frame_host_->BeginFrameSubscription(std::move(subscriber)); | 1181 std::move(subscriber)); |
| 1298 } | 1182 } |
| 1299 | 1183 |
| 1300 void RenderWidgetHostViewMac::EndFrameSubscription() { | 1184 void RenderWidgetHostViewMac::EndFrameSubscription() { |
| 1301 DCHECK(delegated_frame_host_); | 1185 browser_compositor_->GetDelegatedFrameHost()->EndFrameSubscription(); |
| 1302 delegated_frame_host_->EndFrameSubscription(); | |
| 1303 } | 1186 } |
| 1304 | 1187 |
| 1305 ui::AcceleratedWidgetMac* RenderWidgetHostViewMac::GetAcceleratedWidgetMac() | 1188 ui::AcceleratedWidgetMac* RenderWidgetHostViewMac::GetAcceleratedWidgetMac() |
| 1306 const { | 1189 const { |
| 1307 if (browser_compositor_) | 1190 return browser_compositor_->GetAcceleratedWidgetMac(); |
| 1308 return browser_compositor_->accelerated_widget_mac(); | |
| 1309 return nullptr; | |
| 1310 } | 1191 } |
| 1311 | 1192 |
| 1312 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { | 1193 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { |
| 1313 if (render_widget_host_) | 1194 if (render_widget_host_) |
| 1314 render_widget_host_->ForwardMouseEvent(event); | 1195 render_widget_host_->ForwardMouseEvent(event); |
| 1315 | 1196 |
| 1316 if (event.type == WebInputEvent::MouseLeave) { | 1197 if (event.type == WebInputEvent::MouseLeave) { |
| 1317 [cocoa_view_ setToolTipAtMousePoint:nil]; | 1198 [cocoa_view_ setToolTipAtMousePoint:nil]; |
| 1318 tooltip_text_.clear(); | 1199 tooltip_text_.clear(); |
| 1319 } | 1200 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 if (actual_range) { | 1345 if (actual_range) { |
| 1465 *actual_range = gfx::Range( | 1346 *actual_range = gfx::Range( |
| 1466 composition_range_.start() + ui_actual_range.start(), | 1347 composition_range_.start() + ui_actual_range.start(), |
| 1467 composition_range_.start() + ui_actual_range.end()).ToNSRange(); | 1348 composition_range_.start() + ui_actual_range.end()).ToNSRange(); |
| 1468 } | 1349 } |
| 1469 return true; | 1350 return true; |
| 1470 } | 1351 } |
| 1471 | 1352 |
| 1472 bool RenderWidgetHostViewMac::HasAcceleratedSurface( | 1353 bool RenderWidgetHostViewMac::HasAcceleratedSurface( |
| 1473 const gfx::Size& desired_size) { | 1354 const gfx::Size& desired_size) { |
| 1474 if (browser_compositor_) { | 1355 ui::AcceleratedWidgetMac* accelerated_widget_mac = |
| 1475 return browser_compositor_->accelerated_widget_mac()->HasFrameOfSize( | 1356 browser_compositor_->GetAcceleratedWidgetMac(); |
| 1476 desired_size); | 1357 if (accelerated_widget_mac) |
| 1477 } | 1358 return accelerated_widget_mac->HasFrameOfSize(desired_size); |
| 1478 return false; | 1359 return false; |
| 1479 } | 1360 } |
| 1480 | 1361 |
| 1481 void RenderWidgetHostViewMac::OnSwapCompositorFrame(uint32_t output_surface_id, | 1362 void RenderWidgetHostViewMac::OnSwapCompositorFrame(uint32_t output_surface_id, |
| 1482 cc::CompositorFrame frame) { | 1363 cc::CompositorFrame frame) { |
| 1483 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1364 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
| 1484 | 1365 |
| 1485 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1366 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 1486 | 1367 |
| 1487 page_at_minimum_scale_ = | 1368 page_at_minimum_scale_ = |
| 1488 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; | 1369 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; |
| 1489 | |
| 1490 if (frame.delegated_frame_data) { | 1370 if (frame.delegated_frame_data) { |
| 1491 float scale_factor = frame.metadata.device_scale_factor; | 1371 // TODO(ccameron): This would not be needed if BrowserCompostiorMac were to |
| 1492 | 1372 // correctly subscribe to the show and hide notifications for |
| 1493 // Compute the frame size based on the root render pass rect size. | 1373 // RenderWidgetHostImpl. We do not correctly subscribe to these |
| 1494 cc::RenderPass* root_pass = | 1374 // notifications because we want to set the hide property property only |
| 1495 frame.delegated_frame_data->render_pass_list.back().get(); | 1375 // after all notifications (the thumbnailer in particular) have all |
| 1496 gfx::Size pixel_size = root_pass->output_rect.size(); | 1376 // completed. |
| 1497 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 1377 browser_compositor_->SetRenderWidgetHostIsHidden( |
| 1498 | 1378 render_widget_host_->is_hidden()); |
| 1499 root_layer_->SetBounds(gfx::Rect(dip_size)); | 1379 browser_compositor_->SwapCompositorFrame(output_surface_id, |
| 1500 if (!render_widget_host_->is_hidden()) { | 1380 std::move(frame)); |
| 1501 EnsureBrowserCompositorView(); | |
| 1502 browser_compositor_->compositor()->SetScaleAndSize( | |
| 1503 scale_factor, pixel_size); | |
| 1504 } | |
| 1505 | |
| 1506 SendVSyncParametersToRenderer(); | 1381 SendVSyncParametersToRenderer(); |
| 1507 | |
| 1508 delegated_frame_host_->SwapDelegatedFrame(output_surface_id, | |
| 1509 std::move(frame)); | |
| 1510 } else { | 1382 } else { |
| 1511 DLOG(ERROR) << "Received unexpected frame type."; | 1383 DLOG(ERROR) << "Received unexpected frame type."; |
| 1512 bad_message::ReceivedBadMessage(render_widget_host_->GetProcess(), | 1384 bad_message::ReceivedBadMessage(render_widget_host_->GetProcess(), |
| 1513 bad_message::RWHVM_UNEXPECTED_FRAME_TYPE); | 1385 bad_message::RWHVM_UNEXPECTED_FRAME_TYPE); |
| 1514 } | 1386 } |
| 1515 } | 1387 } |
| 1516 | 1388 |
| 1517 void RenderWidgetHostViewMac::ClearCompositorFrame() { | 1389 void RenderWidgetHostViewMac::ClearCompositorFrame() { |
| 1518 delegated_frame_host_->ClearDelegatedFrame(); | 1390 browser_compositor_->GetDelegatedFrameHost()->ClearDelegatedFrame(); |
| 1519 } | 1391 } |
| 1520 | 1392 |
| 1521 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { | 1393 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { |
| 1522 *results = GetWebScreenInfo(GetNativeView()); | 1394 *results = GetWebScreenInfo(GetNativeView()); |
| 1523 } | 1395 } |
| 1524 | 1396 |
| 1525 gfx::Rect RenderWidgetHostViewMac::GetBoundsInRootWindow() { | 1397 gfx::Rect RenderWidgetHostViewMac::GetBoundsInRootWindow() { |
| 1526 // TODO(shess): In case of !window, the view has been removed from | 1398 // TODO(shess): In case of !window, the view has been removed from |
| 1527 // the view hierarchy because the tab isn't main. Could retrieve | 1399 // the view hierarchy because the tab isn't main. Could retrieve |
| 1528 // the information from the main tab for our window. | 1400 // the information from the main tab for our window. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 | 1460 |
| 1589 std::unique_ptr<SyntheticGestureTarget> | 1461 std::unique_ptr<SyntheticGestureTarget> |
| 1590 RenderWidgetHostViewMac::CreateSyntheticGestureTarget() { | 1462 RenderWidgetHostViewMac::CreateSyntheticGestureTarget() { |
| 1591 RenderWidgetHostImpl* host = | 1463 RenderWidgetHostImpl* host = |
| 1592 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | 1464 RenderWidgetHostImpl::From(GetRenderWidgetHost()); |
| 1593 return std::unique_ptr<SyntheticGestureTarget>( | 1465 return std::unique_ptr<SyntheticGestureTarget>( |
| 1594 new SyntheticGestureTargetMac(host, cocoa_view_)); | 1466 new SyntheticGestureTargetMac(host, cocoa_view_)); |
| 1595 } | 1467 } |
| 1596 | 1468 |
| 1597 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() { | 1469 uint32_t RenderWidgetHostViewMac::GetSurfaceIdNamespace() { |
| 1598 DCHECK(delegated_frame_host_); | 1470 return browser_compositor_->GetDelegatedFrameHost()->GetSurfaceIdNamespace(); |
| 1599 return delegated_frame_host_->GetSurfaceIdNamespace(); | |
| 1600 } | 1471 } |
| 1601 | 1472 |
| 1602 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint( | 1473 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint( |
| 1603 cc::SurfaceHittestDelegate* delegate, | 1474 cc::SurfaceHittestDelegate* delegate, |
| 1604 const gfx::Point& point, | 1475 const gfx::Point& point, |
| 1605 gfx::Point* transformed_point) { | 1476 gfx::Point* transformed_point) { |
| 1606 // The surface hittest happens in device pixels, so we need to convert the | 1477 // The surface hittest happens in device pixels, so we need to convert the |
| 1607 // |point| from DIPs to pixels before hittesting. | 1478 // |point| from DIPs to pixels before hittesting. |
| 1608 float scale_factor = display::Screen::GetScreen() | 1479 float scale_factor = display::Screen::GetScreen() |
| 1609 ->GetDisplayNearestWindow(cocoa_view_) | 1480 ->GetDisplayNearestWindow(cocoa_view_) |
| 1610 .device_scale_factor(); | 1481 .device_scale_factor(); |
| 1611 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | 1482 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); |
| 1612 cc::SurfaceId id = delegated_frame_host_->SurfaceIdAtPoint( | 1483 cc::SurfaceId id = |
| 1613 delegate, point_in_pixels, transformed_point); | 1484 browser_compositor_->GetDelegatedFrameHost()->SurfaceIdAtPoint( |
| 1485 delegate, point_in_pixels, transformed_point); |
| 1614 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1486 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); |
| 1615 | 1487 |
| 1616 // It is possible that the renderer has not yet produced a surface, in which | 1488 // It is possible that the renderer has not yet produced a surface, in which |
| 1617 // case we return our current namespace. | 1489 // case we return our current namespace. |
| 1618 if (id.is_null()) | 1490 if (id.is_null()) |
| 1619 return GetSurfaceIdNamespace(); | 1491 return GetSurfaceIdNamespace(); |
| 1620 return id.id_namespace(); | 1492 return id.id_namespace(); |
| 1621 } | 1493 } |
| 1622 | 1494 |
| 1623 bool RenderWidgetHostViewMac::ShouldRouteEvent( | 1495 bool RenderWidgetHostViewMac::ShouldRouteEvent( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 void RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( | 1530 void RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( |
| 1659 const gfx::Point& point, | 1531 const gfx::Point& point, |
| 1660 cc::SurfaceId original_surface, | 1532 cc::SurfaceId original_surface, |
| 1661 gfx::Point* transformed_point) { | 1533 gfx::Point* transformed_point) { |
| 1662 // Transformations use physical pixels rather than DIP, so conversion | 1534 // Transformations use physical pixels rather than DIP, so conversion |
| 1663 // is necessary. | 1535 // is necessary. |
| 1664 float scale_factor = display::Screen::GetScreen() | 1536 float scale_factor = display::Screen::GetScreen() |
| 1665 ->GetDisplayNearestWindow(cocoa_view_) | 1537 ->GetDisplayNearestWindow(cocoa_view_) |
| 1666 .device_scale_factor(); | 1538 .device_scale_factor(); |
| 1667 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | 1539 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); |
| 1668 delegated_frame_host_->TransformPointToLocalCoordSpace( | 1540 browser_compositor_->GetDelegatedFrameHost()->TransformPointToLocalCoordSpace( |
| 1669 point_in_pixels, original_surface, transformed_point); | 1541 point_in_pixels, original_surface, transformed_point); |
| 1670 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1542 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); |
| 1671 } | 1543 } |
| 1672 | 1544 |
| 1673 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { | 1545 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { |
| 1674 if (render_widget_host_) | 1546 if (render_widget_host_) |
| 1675 return render_widget_host_->Send(message); | 1547 return render_widget_host_->Send(message); |
| 1676 delete message; | 1548 delete message; |
| 1677 return false; | 1549 return false; |
| 1678 } | 1550 } |
| 1679 | 1551 |
| 1680 void RenderWidgetHostViewMac::ShutdownHost() { | 1552 void RenderWidgetHostViewMac::ShutdownHost() { |
| 1681 weak_factory_.InvalidateWeakPtrs(); | 1553 weak_factory_.InvalidateWeakPtrs(); |
| 1682 render_widget_host_->ShutdownAndDestroyWidget(true); | 1554 render_widget_host_->ShutdownAndDestroyWidget(true); |
| 1683 // Do not touch any members at this point, |this| has been deleted. | 1555 // Do not touch any members at this point, |this| has been deleted. |
| 1684 } | 1556 } |
| 1685 | 1557 |
| 1686 void RenderWidgetHostViewMac::ShutdownBrowserCompositor() { | |
| 1687 DestroyBrowserCompositorView(); | |
| 1688 delegated_frame_host_.reset(); | |
| 1689 root_layer_.reset(); | |
| 1690 browser_compositor_placeholder_.reset(); | |
| 1691 } | |
| 1692 | |
| 1693 void RenderWidgetHostViewMac::SetActive(bool active) { | 1558 void RenderWidgetHostViewMac::SetActive(bool active) { |
| 1694 if (render_widget_host_) { | 1559 if (render_widget_host_) { |
| 1695 render_widget_host_->SetActive(active); | 1560 render_widget_host_->SetActive(active); |
| 1696 if (active) { | 1561 if (active) { |
| 1697 if (HasFocus()) | 1562 if (HasFocus()) |
| 1698 render_widget_host_->Focus(); | 1563 render_widget_host_->Focus(); |
| 1699 } else { | 1564 } else { |
| 1700 render_widget_host_->Blur(); | 1565 render_widget_host_->Blur(); |
| 1701 } | 1566 } |
| 1702 } | 1567 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1715 if (color == background_color_) | 1580 if (color == background_color_) |
| 1716 return; | 1581 return; |
| 1717 | 1582 |
| 1718 RenderWidgetHostViewBase::SetBackgroundColor(color); | 1583 RenderWidgetHostViewBase::SetBackgroundColor(color); |
| 1719 bool opaque = GetBackgroundOpaque(); | 1584 bool opaque = GetBackgroundOpaque(); |
| 1720 | 1585 |
| 1721 if (render_widget_host_) | 1586 if (render_widget_host_) |
| 1722 render_widget_host_->SetBackgroundOpaque(opaque); | 1587 render_widget_host_->SetBackgroundOpaque(opaque); |
| 1723 | 1588 |
| 1724 [cocoa_view_ setOpaque:opaque]; | 1589 [cocoa_view_ setOpaque:opaque]; |
| 1725 if (browser_compositor_state_ != BrowserCompositorDestroyed) | 1590 |
| 1726 browser_compositor_->compositor()->SetHostHasTransparentBackground(!opaque); | 1591 browser_compositor_->SetHasTransparentBackground(!opaque); |
| 1727 | 1592 |
| 1728 ScopedCAActionDisabler disabler; | 1593 ScopedCAActionDisabler disabler; |
| 1729 base::ScopedCFTypeRef<CGColorRef> cg_color( | 1594 base::ScopedCFTypeRef<CGColorRef> cg_color( |
| 1730 skia::CGColorCreateFromSkColor(color)); | 1595 skia::CGColorCreateFromSkColor(color)); |
| 1731 [background_layer_ setBackgroundColor:cg_color]; | 1596 [background_layer_ setBackgroundColor:cg_color]; |
| 1732 } | 1597 } |
| 1733 | 1598 |
| 1734 BrowserAccessibilityManager* | 1599 BrowserAccessibilityManager* |
| 1735 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager( | 1600 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager( |
| 1736 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 1601 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2671 [super setFrameSize:newSize]; | 2536 [super setFrameSize:newSize]; |
| 2672 | 2537 |
| 2673 if (!renderWidgetHostView_->render_widget_host_) | 2538 if (!renderWidgetHostView_->render_widget_host_) |
| 2674 return; | 2539 return; |
| 2675 | 2540 |
| 2676 if (renderWidgetHostView_->render_widget_host_->delegate()) | 2541 if (renderWidgetHostView_->render_widget_host_->delegate()) |
| 2677 renderWidgetHostView_->render_widget_host_->delegate()->SendScreenRects(); | 2542 renderWidgetHostView_->render_widget_host_->delegate()->SendScreenRects(); |
| 2678 else | 2543 else |
| 2679 renderWidgetHostView_->render_widget_host_->SendScreenRects(); | 2544 renderWidgetHostView_->render_widget_host_->SendScreenRects(); |
| 2680 renderWidgetHostView_->render_widget_host_->WasResized(); | 2545 renderWidgetHostView_->render_widget_host_->WasResized(); |
| 2681 if (renderWidgetHostView_->delegated_frame_host_) | 2546 renderWidgetHostView_->browser_compositor_->GetDelegatedFrameHost() |
| 2682 renderWidgetHostView_->delegated_frame_host_->WasResized(); | 2547 ->WasResized(); |
| 2683 | 2548 |
| 2684 // Wait for the frame that WasResize might have requested. If the view is | 2549 // Wait for the frame that WasResize might have requested. If the view is |
| 2685 // being made visible at a new size, then this call will have no effect | 2550 // being made visible at a new size, then this call will have no effect |
| 2686 // because the view widget is still hidden, and the pause call in WasShown | 2551 // because the view widget is still hidden, and the pause call in WasShown |
| 2687 // will have this effect for us. | 2552 // will have this effect for us. |
| 2688 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); | 2553 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); |
| 2689 } | 2554 } |
| 2690 | 2555 |
| 2691 - (BOOL)canBecomeKeyView { | 2556 - (BOOL)canBecomeKeyView { |
| 2692 if (!renderWidgetHostView_->render_widget_host_) | 2557 if (!renderWidgetHostView_->render_widget_host_) |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 hasMarkedText_ = NO; | 3107 hasMarkedText_ = NO; |
| 3243 } | 3108 } |
| 3244 | 3109 |
| 3245 - (void)insertText:(id)string { | 3110 - (void)insertText:(id)string { |
| 3246 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; | 3111 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; |
| 3247 } | 3112 } |
| 3248 | 3113 |
| 3249 - (void)viewDidMoveToWindow { | 3114 - (void)viewDidMoveToWindow { |
| 3250 if ([self window]) { | 3115 if ([self window]) { |
| 3251 [self updateScreenProperties]; | 3116 [self updateScreenProperties]; |
| 3252 } else { | |
| 3253 // If the RenderWidgetHostViewCocoa is being removed from its window, tear | |
| 3254 // down its browser compositor resources, if needed. | |
| 3255 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded(); | |
| 3256 } | 3117 } |
| 3118 renderWidgetHostView_->browser_compositor_->SetNSViewAttachedToWindow( |
| 3119 [self window]); |
| 3257 | 3120 |
| 3258 // If we switch windows (or are removed from the view hierarchy), cancel any | 3121 // If we switch windows (or are removed from the view hierarchy), cancel any |
| 3259 // open mouse-downs. | 3122 // open mouse-downs. |
| 3260 if (hasOpenMouseDown_) { | 3123 if (hasOpenMouseDown_) { |
| 3261 WebMouseEvent event; | 3124 WebMouseEvent event; |
| 3262 event.type = WebInputEvent::MouseUp; | 3125 event.type = WebInputEvent::MouseUp; |
| 3263 event.button = WebMouseEvent::ButtonLeft; | 3126 event.button = WebMouseEvent::ButtonLeft; |
| 3264 renderWidgetHostView_->ForwardMouseEvent(event); | 3127 renderWidgetHostView_->ForwardMouseEvent(event); |
| 3265 | 3128 |
| 3266 hasOpenMouseDown_ = NO; | 3129 hasOpenMouseDown_ = NO; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3438 | 3301 |
| 3439 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3302 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3440 // regions that are not draggable. (See ControlRegionView in | 3303 // regions that are not draggable. (See ControlRegionView in |
| 3441 // native_app_window_cocoa.mm). This requires the render host view to be | 3304 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3442 // draggable by default. | 3305 // draggable by default. |
| 3443 - (BOOL)mouseDownCanMoveWindow { | 3306 - (BOOL)mouseDownCanMoveWindow { |
| 3444 return YES; | 3307 return YES; |
| 3445 } | 3308 } |
| 3446 | 3309 |
| 3447 @end | 3310 @end |
| OLD | NEW |