Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2156333002: Mac: Clean up visibility state tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 int RenderWidgetHostViewMac::DelegatedFrameHostGetGpuMemoryBufferClientId() 407 NSView* RenderWidgetHostViewMac::BrowserCompositorMacGetNSView() const {
409 const { 408 return cocoa_view_;
410 return render_widget_host_->GetProcess()->GetID();
411 } 409 }
412 410
413 ui::Layer* RenderWidgetHostViewMac::DelegatedFrameHostGetLayer() const { 411 SkColor RenderWidgetHostViewMac::BrowserCompositorMacGetGutterColor(
414 return browser_compositor_->GetRootLayer();
415 }
416
417 bool RenderWidgetHostViewMac::DelegatedFrameHostIsVisible() const {
418 return !render_widget_host_->is_hidden();
419 }
420
421 SkColor RenderWidgetHostViewMac::DelegatedFrameHostGetGutterColor(
422 SkColor color) const { 412 SkColor color) const {
423 // When making an element on the page fullscreen the element's background 413 // When making an element on the page fullscreen the element's background
424 // may not match the page's, so use black as the gutter color to avoid 414 // may not match the page's, so use black as the gutter color to avoid
425 // flashes of brighter colors during the transition. 415 // flashes of brighter colors during the transition.
426 if (render_widget_host_->delegate() && 416 if (render_widget_host_->delegate() &&
427 render_widget_host_->delegate()->IsFullscreenForCurrentTab()) { 417 render_widget_host_->delegate()->IsFullscreenForCurrentTab()) {
428 return SK_ColorBLACK; 418 return SK_ColorBLACK;
429 } 419 }
430 return color; 420 return color;
431 } 421 }
432 422
433 gfx::Size RenderWidgetHostViewMac::DelegatedFrameHostDesiredSizeInDIP() const { 423 void RenderWidgetHostViewMac::BrowserCompositorMacSendCompositorSwapAck(
434 return GetViewBounds().size();
435 }
436
437 bool RenderWidgetHostViewMac::DelegatedFrameCanCreateResizeLock() const {
438 // Mac uses the RenderWidgetResizeHelper instead of a resize lock.
439 return false;
440 }
441
442 std::unique_ptr<ResizeLock>
443 RenderWidgetHostViewMac::DelegatedFrameHostCreateResizeLock(
444 bool defer_compositor_lock) {
445 NOTREACHED();
446 return std::unique_ptr<ResizeLock>();
447 }
448
449 void RenderWidgetHostViewMac::DelegatedFrameHostResizeLockWasReleased() {
450 NOTREACHED();
451 }
452
453 void RenderWidgetHostViewMac::DelegatedFrameHostSendCompositorSwapAck(
454 int output_surface_id, 424 int output_surface_id,
455 const cc::CompositorFrameAck& ack) { 425 const cc::CompositorFrameAck& ack) {
456 render_widget_host_->Send(new ViewMsg_SwapCompositorFrameAck( 426 render_widget_host_->Send(new ViewMsg_SwapCompositorFrameAck(
457 render_widget_host_->GetRoutingID(), output_surface_id, ack)); 427 render_widget_host_->GetRoutingID(), output_surface_id, ack));
458 } 428 }
459 429
460 void RenderWidgetHostViewMac::DelegatedFrameHostSendReclaimCompositorResources( 430 void RenderWidgetHostViewMac::
461 int output_surface_id, 431 BrowserCompositorMacSendReclaimCompositorResources(
462 const cc::CompositorFrameAck& ack) { 432 int output_surface_id,
433 const cc::CompositorFrameAck& ack) {
463 render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources( 434 render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources(
464 render_widget_host_->GetRoutingID(), output_surface_id, ack)); 435 render_widget_host_->GetRoutingID(), output_surface_id, ack));
465 } 436 }
466 437
467 void RenderWidgetHostViewMac::DelegatedFrameHostOnLostCompositorResources() { 438 void RenderWidgetHostViewMac::BrowserCompositorMacOnLostCompositorResources() {
468 render_widget_host_->ScheduleComposite(); 439 render_widget_host_->ScheduleComposite();
469 } 440 }
470 441
471 void RenderWidgetHostViewMac::DelegatedFrameHostUpdateVSyncParameters( 442 void RenderWidgetHostViewMac::BrowserCompositorMacUpdateVSyncParameters(
472 const base::TimeTicks& timebase, 443 const base::TimeTicks& timebase,
473 const base::TimeDelta& interval) { 444 const base::TimeDelta& interval) {
474 render_widget_host_->UpdateVSyncParameters(timebase, interval); 445 render_widget_host_->UpdateVSyncParameters(timebase, interval);
475 } 446 }
476 447
477 void RenderWidgetHostViewMac::SetBeginFrameSource( 448 void RenderWidgetHostViewMac::BrowserCompositorMacSendBeginFrame(
478 cc::BeginFrameSource* source) { 449 const cc::BeginFrameArgs& args) {
479 if (begin_frame_source_ && needs_begin_frames_) 450 render_widget_host_->Send(
480 begin_frame_source_->RemoveObserver(this); 451 new ViewMsg_BeginFrame(render_widget_host_->GetRoutingID(), args));
481 begin_frame_source_ = source;
482 if (begin_frame_source_ && needs_begin_frames_)
483 begin_frame_source_->AddObserver(this);
484 } 452 }
485 453
486 //////////////////////////////////////////////////////////////////////////////// 454 ////////////////////////////////////////////////////////////////////////////////
487 // cc::BeginFrameSourceBase, public:
488
489 void RenderWidgetHostViewMac::OnSetNeedsBeginFrames(bool needs_begin_frames) {
490 if (needs_begin_frames_ == needs_begin_frames)
491 return;
492
493 needs_begin_frames_ = needs_begin_frames;
494 if (begin_frame_source_) {
495 if (needs_begin_frames_)
496 begin_frame_source_->AddObserver(this);
497 else
498 begin_frame_source_->RemoveObserver(this);
499 }
500 }
501
502 void RenderWidgetHostViewMac::OnBeginFrame(
503 const cc::BeginFrameArgs& args) {
504 browser_compositor_->GetDelegatedFrameHost()->SetVSyncParameters(
505 args.frame_time, args.interval);
506 render_widget_host_->Send(
507 new ViewMsg_BeginFrame(render_widget_host_->GetRoutingID(), args));
508 last_begin_frame_args_ = args;
509 }
510
511 const cc::BeginFrameArgs& RenderWidgetHostViewMac::LastUsedBeginFrameArgs()
512 const {
513 return last_begin_frame_args_;
514 }
515
516 void RenderWidgetHostViewMac::OnBeginFrameSourcePausedChanged(
517 bool paused) {
518 // Only used on Android WebView.
519 }
520
521 ////////////////////////////////////////////////////////////////////////////////
522 // AcceleratedWidgetMacNSView, public: 455 // AcceleratedWidgetMacNSView, public:
523 456
524 NSView* RenderWidgetHostViewMac::AcceleratedWidgetGetNSView() const { 457 NSView* RenderWidgetHostViewMac::AcceleratedWidgetGetNSView() const {
525 return cocoa_view_; 458 return cocoa_view_;
526 } 459 }
527 460
528 void RenderWidgetHostViewMac::AcceleratedWidgetGetVSyncParameters( 461 void RenderWidgetHostViewMac::AcceleratedWidgetGetVSyncParameters(
529 base::TimeTicks* timebase, base::TimeDelta* interval) const { 462 base::TimeTicks* timebase, base::TimeDelta* interval) const {
530 if (display_link_ && 463 if (display_link_ &&
531 display_link_->GetVSyncParameters(timebase, interval)) 464 display_link_->GetVSyncParameters(timebase, interval))
(...skipping 22 matching lines...) Expand all
554 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget, 487 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget,
555 bool is_guest_view_hack) 488 bool is_guest_view_hack)
556 : render_widget_host_(RenderWidgetHostImpl::From(widget)), 489 : render_widget_host_(RenderWidgetHostImpl::From(widget)),
557 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 490 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
558 can_compose_inline_(true), 491 can_compose_inline_(true),
559 page_at_minimum_scale_(true), 492 page_at_minimum_scale_(true),
560 is_loading_(false), 493 is_loading_(false),
561 allow_pause_for_resize_or_repaint_(true), 494 allow_pause_for_resize_or_repaint_(true),
562 is_guest_view_hack_(is_guest_view_hack), 495 is_guest_view_hack_(is_guest_view_hack),
563 fullscreen_parent_host_view_(nullptr), 496 fullscreen_parent_host_view_(nullptr),
564 begin_frame_source_(nullptr),
565 needs_begin_frames_(false),
566 weak_factory_(this) { 497 weak_factory_(this) {
567 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 498 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
568 // goes away. Since we autorelease it, our caller must put 499 // goes away. Since we autorelease it, our caller must put
569 // |GetNativeView()| into the view hierarchy right after calling us. 500 // |GetNativeView()| into the view hierarchy right after calling us.
570 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] 501 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc]
571 initWithRenderWidgetHostViewMac:this] autorelease]; 502 initWithRenderWidgetHostViewMac:this] autorelease];
572 503
573 // Paint this view host with |background_color_| when there is no content 504 // Paint this view host with |background_color_| when there is no content
574 // ready to draw. 505 // ready to draw.
575 background_layer_.reset([[CALayer alloc] init]); 506 background_layer_.reset([[CALayer alloc] init]);
(...skipping 23 matching lines...) Expand all
599 530
600 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 531 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
601 display::Screen::GetScreen()->RemoveObserver(this); 532 display::Screen::GetScreen()->RemoveObserver(this);
602 533
603 // This is being called from |cocoa_view_|'s destructor, so invalidate the 534 // This is being called from |cocoa_view_|'s destructor, so invalidate the
604 // pointer. 535 // pointer.
605 cocoa_view_ = nil; 536 cocoa_view_ = nil;
606 537
607 UnlockMouse(); 538 UnlockMouse();
608 539
609 // Ensure that the browser compositor is destroyed in a safe order. 540 browser_compositor_.reset();
610 browser_compositor_->Destroy();
611 541
612 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 542 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the
613 // RenderWidgetHost does we need to tell it not to hold a stale pointer to 543 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
614 // us. 544 // us.
615 if (render_widget_host_) { 545 if (render_widget_host_) {
616 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the 546 // If this is a RenderWidgetHostViewGuest's platform_view_, we're not the
617 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's 547 // RWH's view, the RenderWidgetHostViewGuest is. So don't reset the RWH's
618 // view, the RenderWidgetHostViewGuest will do it. 548 // view, the RenderWidgetHostViewGuest will do it.
619 if (!is_guest_view_hack_) 549 if (!is_guest_view_hack_)
620 render_widget_host_->SetView(NULL); 550 render_widget_host_->SetView(NULL);
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 fullscreen_window_manager_.reset(); 940 fullscreen_window_manager_.reset();
1011 [pepper_fullscreen_window_ close]; 941 [pepper_fullscreen_window_ close];
1012 942
1013 // This can be called as part of processing the window's responder 943 // This can be called as part of processing the window's responder
1014 // chain, for instance |-performKeyEquivalent:|. In that case the 944 // chain, for instance |-performKeyEquivalent:|. In that case the
1015 // object needs to survive until the stack unwinds. 945 // object needs to survive until the stack unwinds.
1016 pepper_fullscreen_window_.autorelease(); 946 pepper_fullscreen_window_.autorelease();
1017 947
1018 // Delete the delegated frame state, which will reach back into 948 // Delete the delegated frame state, which will reach back into
1019 // render_widget_host_. 949 // render_widget_host_.
1020 browser_compositor_->Destroy(); 950 browser_compositor_.reset();
1021 951
1022 // Make sure none of our observers send events for us to process after 952 // Make sure none of our observers send events for us to process after
1023 // we release render_widget_host_. 953 // we release render_widget_host_.
1024 NotifyObserversAboutShutdown(); 954 NotifyObserversAboutShutdown();
1025 955
1026 // We get this call just before |render_widget_host_| deletes 956 // We get this call just before |render_widget_host_| deletes
1027 // itself. But we are owned by |cocoa_view_|, which may be retained 957 // itself. But we are owned by |cocoa_view_|, which may be retained
1028 // by some other code. Examples are WebContentsViewMac's 958 // by some other code. Examples are WebContentsViewMac's
1029 // |latent_focus_view_| and TabWindowController's 959 // |latent_focus_view_| and TabWindowController's
1030 // |cachedContentView_|. 960 // |cachedContentView_|.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { 1122 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) {
1193 if (render_widget_host_) 1123 if (render_widget_host_)
1194 render_widget_host_->ForwardMouseEvent(event); 1124 render_widget_host_->ForwardMouseEvent(event);
1195 1125
1196 if (event.type == WebInputEvent::MouseLeave) { 1126 if (event.type == WebInputEvent::MouseLeave) {
1197 [cocoa_view_ setToolTipAtMousePoint:nil]; 1127 [cocoa_view_ setToolTipAtMousePoint:nil];
1198 tooltip_text_.clear(); 1128 tooltip_text_.clear();
1199 } 1129 }
1200 } 1130 }
1201 1131
1132 void RenderWidgetHostViewMac::OnSetNeedsBeginFrames(bool needs_begin_frames) {
1133 browser_compositor_->SetNeedsBeginFrames(needs_begin_frames);
1134 }
1135
1202 void RenderWidgetHostViewMac::KillSelf() { 1136 void RenderWidgetHostViewMac::KillSelf() {
1203 if (!weak_factory_.HasWeakPtrs()) { 1137 if (!weak_factory_.HasWeakPtrs()) {
1204 [cocoa_view_ setHidden:YES]; 1138 [cocoa_view_ setHidden:YES];
1205 base::MessageLoop::current()->PostTask(FROM_HERE, 1139 base::MessageLoop::current()->PostTask(FROM_HERE,
1206 base::Bind(&RenderWidgetHostViewMac::ShutdownHost, 1140 base::Bind(&RenderWidgetHostViewMac::ShutdownHost,
1207 weak_factory_.GetWeakPtr())); 1141 weak_factory_.GetWeakPtr()));
1208 } 1142 }
1209 } 1143 }
1210 1144
1211 bool RenderWidgetHostViewMac::GetLineBreakIndex( 1145 bool RenderWidgetHostViewMac::GetLineBreakIndex(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 1294
1361 void RenderWidgetHostViewMac::OnSwapCompositorFrame(uint32_t output_surface_id, 1295 void RenderWidgetHostViewMac::OnSwapCompositorFrame(uint32_t output_surface_id,
1362 cc::CompositorFrame frame) { 1296 cc::CompositorFrame frame) {
1363 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); 1297 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame");
1364 1298
1365 last_scroll_offset_ = frame.metadata.root_scroll_offset; 1299 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1366 1300
1367 page_at_minimum_scale_ = 1301 page_at_minimum_scale_ =
1368 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor; 1302 frame.metadata.page_scale_factor == frame.metadata.min_page_scale_factor;
1369 if (frame.delegated_frame_data) { 1303 if (frame.delegated_frame_data) {
1370 // TODO(ccameron): This would not be needed if BrowserCompostiorMac were to
1371 // correctly subscribe to the show and hide notifications for
1372 // RenderWidgetHostImpl. We do not correctly subscribe to these
1373 // notifications because we want to set the hide property property only
1374 // after all notifications (the thumbnailer in particular) have all
1375 // completed.
1376 browser_compositor_->SetRenderWidgetHostIsHidden(
1377 render_widget_host_->is_hidden());
1378 browser_compositor_->SwapCompositorFrame(output_surface_id, 1304 browser_compositor_->SwapCompositorFrame(output_surface_id,
1379 std::move(frame)); 1305 std::move(frame));
1380 SendVSyncParametersToRenderer(); 1306 SendVSyncParametersToRenderer();
1381 } else { 1307 } else {
1382 DLOG(ERROR) << "Received unexpected frame type."; 1308 DLOG(ERROR) << "Received unexpected frame type.";
1383 bad_message::ReceivedBadMessage(render_widget_host_->GetProcess(), 1309 bad_message::ReceivedBadMessage(render_widget_host_->GetProcess(),
1384 bad_message::RWHVM_UNEXPECTED_FRAME_TYPE); 1310 bad_message::RWHVM_UNEXPECTED_FRAME_TYPE);
1385 } 1311 }
1386 } 1312 }
1387 1313
(...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after
3300 3226
3301 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3227 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3302 // regions that are not draggable. (See ControlRegionView in 3228 // regions that are not draggable. (See ControlRegionView in
3303 // native_app_window_cocoa.mm). This requires the render host view to be 3229 // native_app_window_cocoa.mm). This requires the render host view to be
3304 // draggable by default. 3230 // draggable by default.
3305 - (BOOL)mouseDownCanMoveWindow { 3231 - (BOOL)mouseDownCanMoveWindow {
3306 return YES; 3232 return YES;
3307 } 3233 }
3308 3234
3309 @end 3235 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698