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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 if (window == view_->window_) | 435 if (window == view_->window_) |
436 view_->RemovingFromRootWindow(); | 436 view_->RemovingFromRootWindow(); |
437 } | 437 } |
438 | 438 |
439 private: | 439 private: |
440 RenderWidgetHostViewAura* view_; | 440 RenderWidgetHostViewAura* view_; |
441 | 441 |
442 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 442 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
443 }; | 443 }; |
444 | 444 |
| 445 #if defined(OS_WIN) |
| 446 // On Windows, we need to watch the top level window for changes to transient |
| 447 // windows because they can cover the view and we need to ensure that they're |
| 448 // rendered on top of windowed NPAPI plugins. |
| 449 class RenderWidgetHostViewAura::TransientWindowObserver |
| 450 : public aura::WindowObserver { |
| 451 public: |
| 452 explicit TransientWindowObserver(RenderWidgetHostViewAura* view) |
| 453 : view_(view), top_level_(NULL) { |
| 454 view_->window_->AddObserver(this); |
| 455 } |
| 456 |
| 457 virtual ~TransientWindowObserver() { |
| 458 view_->window_->RemoveObserver(this); |
| 459 StopObserving(); |
| 460 } |
| 461 |
| 462 // Overridden from aura::WindowObserver: |
| 463 virtual void OnWindowHierarchyChanged( |
| 464 const aura::WindowObserver::HierarchyChangeParams& params) OVERRIDE { |
| 465 aura::Window* top_level = GetToplevelWindow(); |
| 466 if (top_level == top_level_) |
| 467 return; |
| 468 |
| 469 StopObserving(); |
| 470 top_level_ = top_level; |
| 471 if (top_level_ && top_level_ != view_->window_) |
| 472 top_level_->AddObserver(this); |
| 473 } |
| 474 |
| 475 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| 476 if (window == top_level_) |
| 477 StopObserving(); |
| 478 } |
| 479 |
| 480 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 481 const gfx::Rect& old_bounds, |
| 482 const gfx::Rect& new_bounds) OVERRIDE { |
| 483 if (window->transient_parent()) |
| 484 SendPluginCutoutRects(); |
| 485 } |
| 486 |
| 487 virtual void OnWindowVisibilityChanged(aura::Window* window, |
| 488 bool visible) OVERRIDE { |
| 489 if (window->transient_parent()) |
| 490 SendPluginCutoutRects(); |
| 491 } |
| 492 |
| 493 virtual void OnAddTransientChild(aura::Window* window, |
| 494 aura::Window* transient) OVERRIDE { |
| 495 transient->AddObserver(this); |
| 496 // Just wait for the OnWindowBoundsChanged of the transient, since the size |
| 497 // is not known now. |
| 498 } |
| 499 |
| 500 virtual void OnRemoveTransientChild(aura::Window* window, |
| 501 aura::Window* transient) OVERRIDE { |
| 502 transient->RemoveObserver(this); |
| 503 SendPluginCutoutRects(); |
| 504 } |
| 505 |
| 506 aura::Window* GetToplevelWindow() { |
| 507 aura::Window* root = view_->window_->GetRootWindow(); |
| 508 if (!root) |
| 509 return NULL; |
| 510 aura::client::ActivationClient* activation_client = |
| 511 aura::client::GetActivationClient(root); |
| 512 if (!activation_client) |
| 513 return NULL; |
| 514 return activation_client->GetToplevelWindow(view_->window_); |
| 515 } |
| 516 |
| 517 void StopObserving() { |
| 518 if (!top_level_) |
| 519 return; |
| 520 |
| 521 const aura::Window::Windows& transients = top_level_->transient_children(); |
| 522 for (size_t i = 0; i < transients.size(); ++i) |
| 523 transients[i]->RemoveObserver(this); |
| 524 |
| 525 if (top_level_ != view_->window_) |
| 526 top_level_->RemoveObserver(this); |
| 527 top_level_ = NULL; |
| 528 } |
| 529 |
| 530 void SendPluginCutoutRects() { |
| 531 std::vector<gfx::Rect> cutouts; |
| 532 if (top_level_) { |
| 533 const aura::Window::Windows& transients = |
| 534 top_level_->transient_children(); |
| 535 for (size_t i = 0; i < transients.size(); ++i) { |
| 536 if (transients[i]->IsVisible()) |
| 537 cutouts.push_back(transients[i]->GetBoundsInRootWindow()); |
| 538 } |
| 539 } |
| 540 |
| 541 view_->UpdateTransientRects(cutouts); |
| 542 } |
| 543 private: |
| 544 RenderWidgetHostViewAura* view_; |
| 545 aura::Window* top_level_; |
| 546 |
| 547 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); |
| 548 }; |
| 549 |
| 550 #endif |
| 551 |
445 //////////////////////////////////////////////////////////////////////////////// | 552 //////////////////////////////////////////////////////////////////////////////// |
446 // RenderWidgetHostViewAura, public: | 553 // RenderWidgetHostViewAura, public: |
447 | 554 |
448 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) | 555 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
449 : host_(RenderWidgetHostImpl::From(host)), | 556 : host_(RenderWidgetHostImpl::From(host)), |
450 window_(new aura::Window(this)), | 557 window_(new aura::Window(this)), |
451 in_shutdown_(false), | 558 in_shutdown_(false), |
452 is_fullscreen_(false), | 559 is_fullscreen_(false), |
453 popup_parent_host_view_(NULL), | 560 popup_parent_host_view_(NULL), |
454 popup_child_host_view_(NULL), | 561 popup_child_host_view_(NULL), |
(...skipping 15 matching lines...) Expand all Loading... |
470 touch_editing_client_(NULL), | 577 touch_editing_client_(NULL), |
471 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), | 578 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
472 weak_ptr_factory_(this) { | 579 weak_ptr_factory_(this) { |
473 host_->SetView(this); | 580 host_->SetView(this); |
474 window_observer_.reset(new WindowObserver(this)); | 581 window_observer_.reset(new WindowObserver(this)); |
475 aura::client::SetTooltipText(window_, &tooltip_); | 582 aura::client::SetTooltipText(window_, &tooltip_); |
476 aura::client::SetActivationDelegate(window_, this); | 583 aura::client::SetActivationDelegate(window_, this); |
477 aura::client::SetActivationChangeObserver(window_, this); | 584 aura::client::SetActivationChangeObserver(window_, this); |
478 aura::client::SetFocusChangeObserver(window_, this); | 585 aura::client::SetFocusChangeObserver(window_, this); |
479 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 586 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
| 587 #if defined(OS_WIN) |
| 588 transient_observer_.reset(new TransientWindowObserver(this)); |
| 589 #endif |
480 software_frame_manager_.reset(new SoftwareFrameManager( | 590 software_frame_manager_.reset(new SoftwareFrameManager( |
481 weak_ptr_factory_.GetWeakPtr())); | 591 weak_ptr_factory_.GetWeakPtr())); |
482 } | 592 } |
483 | 593 |
484 //////////////////////////////////////////////////////////////////////////////// | 594 //////////////////////////////////////////////////////////////////////////////// |
485 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 595 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
486 | 596 |
487 void RenderWidgetHostViewAura::InitAsChild( | 597 void RenderWidgetHostViewAura::InitAsChild( |
488 gfx::NativeView parent_view) { | 598 gfx::NativeView parent_view) { |
489 window_->Init(ui::LAYER_TEXTURED); | 599 window_->Init(ui::LAYER_TEXTURED); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && | 677 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && |
568 !released_front_lock_.get()) { | 678 !released_front_lock_.get()) { |
569 ui::Compositor* compositor = GetCompositor(); | 679 ui::Compositor* compositor = GetCompositor(); |
570 if (compositor) | 680 if (compositor) |
571 released_front_lock_ = compositor->GetCompositorLock(); | 681 released_front_lock_ = compositor->GetCompositorLock(); |
572 } | 682 } |
573 | 683 |
574 #if defined(OS_WIN) | 684 #if defined(OS_WIN) |
575 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 685 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
576 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 686 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
| 687 transient_observer_->SendPluginCutoutRects(); |
577 #endif | 688 #endif |
578 } | 689 } |
579 | 690 |
580 void RenderWidgetHostViewAura::WasHidden() { | 691 void RenderWidgetHostViewAura::WasHidden() { |
581 if (!host_ || host_->is_hidden()) | 692 if (!host_ || host_->is_hidden()) |
582 return; | 693 return; |
583 host_->WasHidden(); | 694 host_->WasHidden(); |
584 software_frame_manager_->SetVisibility(false); | 695 software_frame_manager_->SetVisibility(false); |
585 delegated_frame_evictor_->SetVisible(false); | 696 delegated_frame_evictor_->SetVisible(false); |
586 released_front_lock_ = NULL; | 697 released_front_lock_ = NULL; |
587 | 698 |
588 #if defined(OS_WIN) | 699 #if defined(OS_WIN) |
589 constrained_rects_.clear(); | |
590 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); | 700 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
591 if (dispatcher) { | 701 if (dispatcher) { |
592 HWND parent = dispatcher->GetAcceleratedWidget(); | 702 HWND parent = dispatcher->GetAcceleratedWidget(); |
593 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 703 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
594 | 704 |
595 EnumChildWindows(parent, HideWindowsCallback, lparam); | 705 EnumChildWindows(parent, HideWindowsCallback, lparam); |
596 } | 706 } |
597 #endif | 707 #endif |
598 } | 708 } |
599 | 709 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 moves[i].window_rect.OffsetFromOrigin() + scroll_offset); | 884 moves[i].window_rect.OffsetFromOrigin() + scroll_offset); |
775 clip.Offset(view_port_offset); | 885 clip.Offset(view_port_offset); |
776 clip.Intersect(view_port); | 886 clip.Intersect(view_port); |
777 clip.Offset(-view_port_offset); | 887 clip.Offset(-view_port_offset); |
778 moves[i].clip_rect = clip; | 888 moves[i].clip_rect = clip; |
779 | 889 |
780 moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin()); | 890 moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin()); |
781 | 891 |
782 plugin_window_moves_[moves[i].window] = moves[i]; | 892 plugin_window_moves_[moves[i].window] = moves[i]; |
783 | 893 |
784 // constrained_rects_ are relative to the root window. We want to convert | 894 // transient_rects_ and constrained_rects_ are relative to the root window. |
785 // them to be relative to the plugin window. | 895 // We want to convert them to be relative to the plugin window. |
786 for (size_t j = 0; j < constrained_rects_.size(); ++j) { | 896 std::vector<gfx::Rect> cutout_rects; |
787 gfx::Rect offset_cutout = constrained_rects_[j]; | 897 cutout_rects.assign(transient_rects_.begin(), transient_rects_.end()); |
| 898 cutout_rects.insert(cutout_rects.end(), constrained_rects_.begin(), |
| 899 constrained_rects_.end()); |
| 900 for (size_t j = 0; j < cutout_rects.size(); ++j) { |
| 901 gfx::Rect offset_cutout = cutout_rects[j]; |
788 offset_cutout -= moves[i].window_rect.OffsetFromOrigin(); | 902 offset_cutout -= moves[i].window_rect.OffsetFromOrigin(); |
789 moves[i].cutout_rects.push_back(offset_cutout); | 903 moves[i].cutout_rects.push_back(offset_cutout); |
790 } | 904 } |
791 } | 905 } |
792 | 906 |
793 MovePluginWindowsHelper(parent, moves); | 907 MovePluginWindowsHelper(parent, moves); |
794 | 908 |
795 // Make sure each plugin window (or its wrapper if it exists) has a pointer to | 909 // Make sure each plugin window (or its wrapper if it exists) has a pointer to |
796 // |this|. | 910 // |this|. |
797 for (size_t i = 0; i < moves.size(); ++i) { | 911 for (size_t i = 0; i < moves.size(); ++i) { |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 &frame, &callback)) { | 1355 &frame, &callback)) { |
1242 CopyFromCompositingSurfaceToVideoFrame( | 1356 CopyFromCompositingSurfaceToVideoFrame( |
1243 gfx::Rect(current_frame_size_), | 1357 gfx::Rect(current_frame_size_), |
1244 frame, | 1358 frame, |
1245 base::Bind(callback, present_time)); | 1359 base::Bind(callback, present_time)); |
1246 } | 1360 } |
1247 } | 1361 } |
1248 } | 1362 } |
1249 | 1363 |
1250 #if defined(OS_WIN) | 1364 #if defined(OS_WIN) |
| 1365 void RenderWidgetHostViewAura::UpdateTransientRects( |
| 1366 const std::vector<gfx::Rect>& rects) { |
| 1367 transient_rects_ = rects; |
| 1368 UpdateCutoutRects(); |
| 1369 } |
| 1370 |
1251 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( | 1371 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( |
1252 const std::vector<gfx::Rect>& rects) { | 1372 const std::vector<gfx::Rect>& rects) { |
1253 constrained_rects_ = rects; | 1373 constrained_rects_ = rects; |
1254 UpdateCutoutRects(); | 1374 UpdateCutoutRects(); |
1255 } | 1375 } |
1256 | 1376 |
1257 void RenderWidgetHostViewAura::UpdateCutoutRects() { | 1377 void RenderWidgetHostViewAura::UpdateCutoutRects() { |
1258 if (!window_->GetRootWindow()) | 1378 if (!window_->GetRootWindow()) |
1259 return; | 1379 return; |
1260 HWND parent = window_->GetDispatcher()->GetAcceleratedWidget(); | 1380 HWND parent = window_->GetDispatcher()->GetAcceleratedWidget(); |
1261 CutoutRectsParams params; | 1381 CutoutRectsParams params; |
1262 params.widget = this; | 1382 params.widget = this; |
1263 params.cutout_rects = constrained_rects_; | 1383 params.cutout_rects.assign(transient_rects_.begin(), transient_rects_.end()); |
| 1384 params.cutout_rects.insert(params.cutout_rects.end(), |
| 1385 constrained_rects_.begin(), |
| 1386 constrained_rects_.end()); |
1264 params.geometry = &plugin_window_moves_; | 1387 params.geometry = &plugin_window_moves_; |
1265 LPARAM lparam = reinterpret_cast<LPARAM>(¶ms); | 1388 LPARAM lparam = reinterpret_cast<LPARAM>(¶ms); |
1266 EnumChildWindows(parent, SetCutoutRectsCallback, lparam); | 1389 EnumChildWindows(parent, SetCutoutRectsCallback, lparam); |
1267 } | 1390 } |
1268 #endif | 1391 #endif |
1269 | 1392 |
1270 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( | 1393 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
1271 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 1394 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
1272 int gpu_host_id) { | 1395 int gpu_host_id) { |
1273 BufferPresentedCallback ack_callback = base::Bind( | 1396 BufferPresentedCallback ack_callback = base::Bind( |
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3079 if (paint_observer_) | 3202 if (paint_observer_) |
3080 paint_observer_->OnViewDestroyed(); | 3203 paint_observer_->OnViewDestroyed(); |
3081 if (touch_editing_client_) | 3204 if (touch_editing_client_) |
3082 touch_editing_client_->OnViewDestroyed(); | 3205 touch_editing_client_->OnViewDestroyed(); |
3083 if (!shared_surface_handle_.is_null()) { | 3206 if (!shared_surface_handle_.is_null()) { |
3084 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 3207 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
3085 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 3208 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
3086 factory->RemoveObserver(this); | 3209 factory->RemoveObserver(this); |
3087 } | 3210 } |
3088 window_observer_.reset(); | 3211 window_observer_.reset(); |
| 3212 #if defined(OS_WIN) |
| 3213 transient_observer_.reset(); |
| 3214 #endif |
3089 if (window_->GetDispatcher()) | 3215 if (window_->GetDispatcher()) |
3090 window_->GetDispatcher()->RemoveRootWindowObserver(this); | 3216 window_->GetDispatcher()->RemoveRootWindowObserver(this); |
3091 UnlockMouse(); | 3217 UnlockMouse(); |
3092 if (popup_parent_host_view_) { | 3218 if (popup_parent_host_view_) { |
3093 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 3219 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
3094 popup_parent_host_view_->popup_child_host_view_ == this); | 3220 popup_parent_host_view_->popup_child_host_view_ == this); |
3095 popup_parent_host_view_->popup_child_host_view_ = NULL; | 3221 popup_parent_host_view_->popup_child_host_view_ = NULL; |
3096 } | 3222 } |
3097 if (popup_child_host_view_) { | 3223 if (popup_child_host_view_) { |
3098 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || | 3224 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3315 RenderWidgetHost* widget) { | 3441 RenderWidgetHost* widget) { |
3316 return new RenderWidgetHostViewAura(widget); | 3442 return new RenderWidgetHostViewAura(widget); |
3317 } | 3443 } |
3318 | 3444 |
3319 // static | 3445 // static |
3320 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3446 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3321 GetScreenInfoForWindow(results, NULL); | 3447 GetScreenInfoForWindow(results, NULL); |
3322 } | 3448 } |
3323 | 3449 |
3324 } // namespace content | 3450 } // namespace content |
OLD | NEW |