| 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 30 matching lines...) Expand all Loading... |
| 41 #include "content/browser/frame_host/render_frame_host_impl.h" | 41 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 42 #include "content/browser/gpu/compositor_util.h" | 42 #include "content/browser/gpu/compositor_util.h" |
| 43 #import "content/browser/renderer_host/input/synthetic_gesture_target_mac.h" | 43 #import "content/browser/renderer_host/input/synthetic_gesture_target_mac.h" |
| 44 #include "content/browser/renderer_host/input/web_input_event_builders_mac.h" | 44 #include "content/browser/renderer_host/input/web_input_event_builders_mac.h" |
| 45 #include "content/browser/renderer_host/render_view_host_impl.h" | 45 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 46 #include "content/browser/renderer_host/render_widget_helper.h" | 46 #include "content/browser/renderer_host/render_widget_helper.h" |
| 47 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 47 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 48 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 48 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 49 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he
lper.h" | 49 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he
lper.h" |
| 50 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" | 50 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" |
| 51 #include "content/browser/renderer_host/resize_lock.h" | |
| 52 #import "content/browser/renderer_host/text_input_client_mac.h" | 51 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 53 #include "content/common/accessibility_messages.h" | 52 #include "content/common/accessibility_messages.h" |
| 54 #include "content/common/edit_command.h" | 53 #include "content/common/edit_command.h" |
| 55 #include "content/common/input_messages.h" | 54 #include "content/common/input_messages.h" |
| 56 #include "content/common/site_isolation_policy.h" | 55 #include "content/common/site_isolation_policy.h" |
| 57 #include "content/common/text_input_state.h" | 56 #include "content/common/text_input_state.h" |
| 58 #include "content/common/view_messages.h" | 57 #include "content/common/view_messages.h" |
| 59 #include "content/public/browser/browser_context.h" | 58 #include "content/public/browser/browser_context.h" |
| 60 #include "content/public/browser/browser_plugin_guest_manager.h" | 59 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 61 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 content::RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display); | 395 content::RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display); |
| 397 | 396 |
| 398 return results; | 397 return results; |
| 399 } | 398 } |
| 400 | 399 |
| 401 } // namespace | 400 } // namespace |
| 402 | 401 |
| 403 namespace content { | 402 namespace content { |
| 404 | 403 |
| 405 //////////////////////////////////////////////////////////////////////////////// | 404 //////////////////////////////////////////////////////////////////////////////// |
| 406 // DelegatedFrameHost, public: | 405 // BrowserCompositorMacClient, public: |
| 407 | 406 |
| 408 ui::Layer* RenderWidgetHostViewMac::DelegatedFrameHostGetLayer() const { | 407 NSView* RenderWidgetHostViewMac::BrowserCompositorMacGetNSView() const { |
| 409 return browser_compositor_->GetRootLayer(); | 408 return cocoa_view_; |
| 410 } | 409 } |
| 411 | 410 |
| 412 bool RenderWidgetHostViewMac::DelegatedFrameHostIsVisible() const { | 411 bool RenderWidgetHostViewMac::BrowserCompositorMacIsVisible() const { |
| 413 return !render_widget_host_->is_hidden(); | 412 return !render_widget_host_->is_hidden(); |
| 414 } | 413 } |
| 415 | 414 |
| 416 SkColor RenderWidgetHostViewMac::DelegatedFrameHostGetGutterColor( | 415 SkColor RenderWidgetHostViewMac::BrowserCompositorMacGetGutterColor( |
| 417 SkColor color) const { | 416 SkColor color) const { |
| 418 // When making an element on the page fullscreen the element's background | 417 // When making an element on the page fullscreen the element's background |
| 419 // may not match the page's, so use black as the gutter color to avoid | 418 // may not match the page's, so use black as the gutter color to avoid |
| 420 // flashes of brighter colors during the transition. | 419 // flashes of brighter colors during the transition. |
| 421 if (render_widget_host_->delegate() && | 420 if (render_widget_host_->delegate() && |
| 422 render_widget_host_->delegate()->IsFullscreenForCurrentTab()) { | 421 render_widget_host_->delegate()->IsFullscreenForCurrentTab()) { |
| 423 return SK_ColorBLACK; | 422 return SK_ColorBLACK; |
| 424 } | 423 } |
| 425 return color; | 424 return color; |
| 426 } | 425 } |
| 427 | 426 |
| 428 gfx::Size RenderWidgetHostViewMac::DelegatedFrameHostDesiredSizeInDIP() const { | 427 void RenderWidgetHostViewMac::BrowserCompositorMacSendCompositorSwapAck( |
| 429 return GetViewBounds().size(); | |
| 430 } | |
| 431 | |
| 432 bool RenderWidgetHostViewMac::DelegatedFrameCanCreateResizeLock() const { | |
| 433 // Mac uses the RenderWidgetResizeHelper instead of a resize lock. | |
| 434 return false; | |
| 435 } | |
| 436 | |
| 437 std::unique_ptr<ResizeLock> | |
| 438 RenderWidgetHostViewMac::DelegatedFrameHostCreateResizeLock( | |
| 439 bool defer_compositor_lock) { | |
| 440 NOTREACHED(); | |
| 441 return std::unique_ptr<ResizeLock>(); | |
| 442 } | |
| 443 | |
| 444 void RenderWidgetHostViewMac::DelegatedFrameHostResizeLockWasReleased() { | |
| 445 NOTREACHED(); | |
| 446 } | |
| 447 | |
| 448 void RenderWidgetHostViewMac::DelegatedFrameHostSendCompositorSwapAck( | |
| 449 int output_surface_id, | 428 int output_surface_id, |
| 450 const cc::CompositorFrameAck& ack) { | 429 const cc::CompositorFrameAck& ack) { |
| 451 render_widget_host_->Send(new ViewMsg_SwapCompositorFrameAck( | 430 render_widget_host_->Send(new ViewMsg_SwapCompositorFrameAck( |
| 452 render_widget_host_->GetRoutingID(), output_surface_id, ack)); | 431 render_widget_host_->GetRoutingID(), output_surface_id, ack)); |
| 453 } | 432 } |
| 454 | 433 |
| 455 void RenderWidgetHostViewMac::DelegatedFrameHostSendReclaimCompositorResources( | 434 void RenderWidgetHostViewMac:: |
| 456 int output_surface_id, | 435 BrowserCompositorMacSendReclaimCompositorResources( |
| 457 const cc::CompositorFrameAck& ack) { | 436 int output_surface_id, |
| 437 const cc::CompositorFrameAck& ack) { |
| 458 render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources( | 438 render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 459 render_widget_host_->GetRoutingID(), output_surface_id, ack)); | 439 render_widget_host_->GetRoutingID(), output_surface_id, ack)); |
| 460 } | 440 } |
| 461 | 441 |
| 462 void RenderWidgetHostViewMac::DelegatedFrameHostOnLostCompositorResources() { | 442 void RenderWidgetHostViewMac::BrowserCompositorMacOnLostCompositorResources() { |
| 463 render_widget_host_->ScheduleComposite(); | 443 render_widget_host_->ScheduleComposite(); |
| 464 } | 444 } |
| 465 | 445 |
| 466 void RenderWidgetHostViewMac::DelegatedFrameHostUpdateVSyncParameters( | 446 void RenderWidgetHostViewMac::BrowserCompositorMacUpdateVSyncParameters( |
| 467 const base::TimeTicks& timebase, | 447 const base::TimeTicks& timebase, |
| 468 const base::TimeDelta& interval) { | 448 const base::TimeDelta& interval) { |
| 469 render_widget_host_->UpdateVSyncParameters(timebase, interval); | 449 render_widget_host_->UpdateVSyncParameters(timebase, interval); |
| 470 } | 450 } |
| 471 | 451 |
| 472 void RenderWidgetHostViewMac::SetBeginFrameSource( | 452 void RenderWidgetHostViewMac::BrowserCompositorMacSendBeginFrame( |
| 473 cc::BeginFrameSource* source) { | 453 const cc::BeginFrameArgs& args) { |
| 474 if (begin_frame_source_ && needs_begin_frames_) | 454 render_widget_host_->Send( |
| 475 begin_frame_source_->RemoveObserver(this); | 455 new ViewMsg_BeginFrame(render_widget_host_->GetRoutingID(), args)); |
| 476 begin_frame_source_ = source; | |
| 477 if (begin_frame_source_ && needs_begin_frames_) | |
| 478 begin_frame_source_->AddObserver(this); | |
| 479 } | 456 } |
| 480 | 457 |
| 481 //////////////////////////////////////////////////////////////////////////////// | 458 //////////////////////////////////////////////////////////////////////////////// |
| 482 // cc::BeginFrameSourceBase, public: | |
| 483 | |
| 484 void RenderWidgetHostViewMac::OnSetNeedsBeginFrames(bool needs_begin_frames) { | |
| 485 if (needs_begin_frames_ == needs_begin_frames) | |
| 486 return; | |
| 487 | |
| 488 needs_begin_frames_ = needs_begin_frames; | |
| 489 if (begin_frame_source_) { | |
| 490 if (needs_begin_frames_) | |
| 491 begin_frame_source_->AddObserver(this); | |
| 492 else | |
| 493 begin_frame_source_->RemoveObserver(this); | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 void RenderWidgetHostViewMac::OnBeginFrame( | |
| 498 const cc::BeginFrameArgs& args) { | |
| 499 browser_compositor_->GetDelegatedFrameHost()->SetVSyncParameters( | |
| 500 args.frame_time, args.interval); | |
| 501 render_widget_host_->Send( | |
| 502 new ViewMsg_BeginFrame(render_widget_host_->GetRoutingID(), args)); | |
| 503 last_begin_frame_args_ = args; | |
| 504 } | |
| 505 | |
| 506 const cc::BeginFrameArgs& RenderWidgetHostViewMac::LastUsedBeginFrameArgs() | |
| 507 const { | |
| 508 return last_begin_frame_args_; | |
| 509 } | |
| 510 | |
| 511 void RenderWidgetHostViewMac::OnBeginFrameSourcePausedChanged( | |
| 512 bool paused) { | |
| 513 // Only used on Android WebView. | |
| 514 } | |
| 515 | |
| 516 //////////////////////////////////////////////////////////////////////////////// | |
| 517 // AcceleratedWidgetMacNSView, public: | 459 // AcceleratedWidgetMacNSView, public: |
| 518 | 460 |
| 519 NSView* RenderWidgetHostViewMac::AcceleratedWidgetGetNSView() const { | 461 NSView* RenderWidgetHostViewMac::AcceleratedWidgetGetNSView() const { |
| 520 return cocoa_view_; | 462 return cocoa_view_; |
| 521 } | 463 } |
| 522 | 464 |
| 523 void RenderWidgetHostViewMac::AcceleratedWidgetGetVSyncParameters( | 465 void RenderWidgetHostViewMac::AcceleratedWidgetGetVSyncParameters( |
| 524 base::TimeTicks* timebase, base::TimeDelta* interval) const { | 466 base::TimeTicks* timebase, base::TimeDelta* interval) const { |
| 525 if (display_link_ && | 467 if (display_link_ && |
| 526 display_link_->GetVSyncParameters(timebase, interval)) | 468 display_link_->GetVSyncParameters(timebase, interval)) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 549 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, | 491 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, |
| 550 bool is_guest_view_hack) | 492 bool is_guest_view_hack) |
| 551 : render_widget_host_(RenderWidgetHostImpl::From(widget)), | 493 : render_widget_host_(RenderWidgetHostImpl::From(widget)), |
| 552 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 494 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 553 can_compose_inline_(true), | 495 can_compose_inline_(true), |
| 554 page_at_minimum_scale_(true), | 496 page_at_minimum_scale_(true), |
| 555 is_loading_(false), | 497 is_loading_(false), |
| 556 allow_pause_for_resize_or_repaint_(true), | 498 allow_pause_for_resize_or_repaint_(true), |
| 557 is_guest_view_hack_(is_guest_view_hack), | 499 is_guest_view_hack_(is_guest_view_hack), |
| 558 fullscreen_parent_host_view_(nullptr), | 500 fullscreen_parent_host_view_(nullptr), |
| 559 begin_frame_source_(nullptr), | |
| 560 needs_begin_frames_(false), | |
| 561 weak_factory_(this) { | 501 weak_factory_(this) { |
| 562 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| | 502 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| |
| 563 // goes away. Since we autorelease it, our caller must put | 503 // goes away. Since we autorelease it, our caller must put |
| 564 // |GetNativeView()| into the view hierarchy right after calling us. | 504 // |GetNativeView()| into the view hierarchy right after calling us. |
| 565 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 505 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 566 initWithRenderWidgetHostViewMac:this] autorelease]; | 506 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 567 | 507 |
| 568 // Paint this view host with |background_color_| when there is no content | 508 // Paint this view host with |background_color_| when there is no content |
| 569 // ready to draw. | 509 // ready to draw. |
| 570 background_layer_.reset([[CALayer alloc] init]); | 510 background_layer_.reset([[CALayer alloc] init]); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 594 | 534 |
| 595 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 535 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 596 display::Screen::GetScreen()->RemoveObserver(this); | 536 display::Screen::GetScreen()->RemoveObserver(this); |
| 597 | 537 |
| 598 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 538 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 599 // pointer. | 539 // pointer. |
| 600 cocoa_view_ = nil; | 540 cocoa_view_ = nil; |
| 601 | 541 |
| 602 UnlockMouse(); | 542 UnlockMouse(); |
| 603 | 543 |
| 604 // Ensure that the browser compositor is destroyed in a safe order. | 544 browser_compositor_.reset(); |
| 605 browser_compositor_->Destroy(); | |
| 606 | 545 |
| 607 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 546 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the |
| 608 // RenderWidgetHost does we need to tell it not to hold a stale pointer to | 547 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
| 609 // us. | 548 // us. |
| 610 if (render_widget_host_) { | 549 if (render_widget_host_) { |
| 611 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the | 550 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the |
| 612 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's | 551 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's |
| 613 // view, the RenderWidgetHostViewGuest will do it. | 552 // view, the RenderWidgetHostViewGuest will do it. |
| 614 if (!is_guest_view_hack_) | 553 if (!is_guest_view_hack_) |
| 615 render_widget_host_->SetView(NULL); | 554 render_widget_host_->SetView(NULL); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 fullscreen_window_manager_.reset(); | 944 fullscreen_window_manager_.reset(); |
| 1006 [pepper_fullscreen_window_ close]; | 945 [pepper_fullscreen_window_ close]; |
| 1007 | 946 |
| 1008 // This can be called as part of processing the window's responder | 947 // This can be called as part of processing the window's responder |
| 1009 // chain, for instance |-performKeyEquivalent:|. In that case the | 948 // chain, for instance |-performKeyEquivalent:|. In that case the |
| 1010 // object needs to survive until the stack unwinds. | 949 // object needs to survive until the stack unwinds. |
| 1011 pepper_fullscreen_window_.autorelease(); | 950 pepper_fullscreen_window_.autorelease(); |
| 1012 | 951 |
| 1013 // Delete the delegated frame state, which will reach back into | 952 // Delete the delegated frame state, which will reach back into |
| 1014 // render_widget_host_. | 953 // render_widget_host_. |
| 1015 browser_compositor_->Destroy(); | 954 browser_compositor_.reset(); |
| 1016 | 955 |
| 1017 // Make sure none of our observers send events for us to process after | 956 // Make sure none of our observers send events for us to process after |
| 1018 // we release render_widget_host_. | 957 // we release render_widget_host_. |
| 1019 NotifyObserversAboutShutdown(); | 958 NotifyObserversAboutShutdown(); |
| 1020 | 959 |
| 1021 // We get this call just before |render_widget_host_| deletes | 960 // We get this call just before |render_widget_host_| deletes |
| 1022 // itself. But we are owned by |cocoa_view_|, which may be retained | 961 // itself. But we are owned by |cocoa_view_|, which may be retained |
| 1023 // by some other code. Examples are WebContentsViewMac's | 962 // by some other code. Examples are WebContentsViewMac's |
| 1024 // |latent_focus_view_| and TabWindowController's | 963 // |latent_focus_view_| and TabWindowController's |
| 1025 // |cachedContentView_|. | 964 // |cachedContentView_|. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { | 1126 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { |
| 1188 if (render_widget_host_) | 1127 if (render_widget_host_) |
| 1189 render_widget_host_->ForwardMouseEvent(event); | 1128 render_widget_host_->ForwardMouseEvent(event); |
| 1190 | 1129 |
| 1191 if (event.type == WebInputEvent::MouseLeave) { | 1130 if (event.type == WebInputEvent::MouseLeave) { |
| 1192 [cocoa_view_ setToolTipAtMousePoint:nil]; | 1131 [cocoa_view_ setToolTipAtMousePoint:nil]; |
| 1193 tooltip_text_.clear(); | 1132 tooltip_text_.clear(); |
| 1194 } | 1133 } |
| 1195 } | 1134 } |
| 1196 | 1135 |
| 1136 void RenderWidgetHostViewMac::OnSetNeedsBeginFrames(bool needs_begin_frames) { |
| 1137 browser_compositor_->SetNeedsBeginFrames(needs_begin_frames); |
| 1138 } |
| 1139 |
| 1197 void RenderWidgetHostViewMac::KillSelf() { | 1140 void RenderWidgetHostViewMac::KillSelf() { |
| 1198 if (!weak_factory_.HasWeakPtrs()) { | 1141 if (!weak_factory_.HasWeakPtrs()) { |
| 1199 [cocoa_view_ setHidden:YES]; | 1142 [cocoa_view_ setHidden:YES]; |
| 1200 base::MessageLoop::current()->PostTask(FROM_HERE, | 1143 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 1201 base::Bind(&RenderWidgetHostViewMac::ShutdownHost, | 1144 base::Bind(&RenderWidgetHostViewMac::ShutdownHost, |
| 1202 weak_factory_.GetWeakPtr())); | 1145 weak_factory_.GetWeakPtr())); |
| 1203 } | 1146 } |
| 1204 } | 1147 } |
| 1205 | 1148 |
| 1206 bool RenderWidgetHostViewMac::GetLineBreakIndex( | 1149 bool RenderWidgetHostViewMac::GetLineBreakIndex( |
| (...skipping 2095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3302 | 3245 |
| 3303 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3246 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3304 // regions that are not draggable. (See ControlRegionView in | 3247 // regions that are not draggable. (See ControlRegionView in |
| 3305 // native_app_window_cocoa.mm). This requires the render host view to be | 3248 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3306 // draggable by default. | 3249 // draggable by default. |
| 3307 - (BOOL)mouseDownCanMoveWindow { | 3250 - (BOOL)mouseDownCanMoveWindow { |
| 3308 return YES; | 3251 return YES; |
| 3309 } | 3252 } |
| 3310 | 3253 |
| 3311 @end | 3254 @end |
| OLD | NEW |