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 | |
552 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
553 // RenderWidgetHostViewAura, public: | 446 // RenderWidgetHostViewAura, public: |
554 | 447 |
555 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) | 448 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
556 : host_(RenderWidgetHostImpl::From(host)), | 449 : host_(RenderWidgetHostImpl::From(host)), |
557 window_(new aura::Window(this)), | 450 window_(new aura::Window(this)), |
558 in_shutdown_(false), | 451 in_shutdown_(false), |
559 is_fullscreen_(false), | 452 is_fullscreen_(false), |
560 popup_parent_host_view_(NULL), | 453 popup_parent_host_view_(NULL), |
561 popup_child_host_view_(NULL), | 454 popup_child_host_view_(NULL), |
(...skipping 15 matching lines...) Expand all Loading... |
577 touch_editing_client_(NULL), | 470 touch_editing_client_(NULL), |
578 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), | 471 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
579 weak_ptr_factory_(this) { | 472 weak_ptr_factory_(this) { |
580 host_->SetView(this); | 473 host_->SetView(this); |
581 window_observer_.reset(new WindowObserver(this)); | 474 window_observer_.reset(new WindowObserver(this)); |
582 aura::client::SetTooltipText(window_, &tooltip_); | 475 aura::client::SetTooltipText(window_, &tooltip_); |
583 aura::client::SetActivationDelegate(window_, this); | 476 aura::client::SetActivationDelegate(window_, this); |
584 aura::client::SetActivationChangeObserver(window_, this); | 477 aura::client::SetActivationChangeObserver(window_, this); |
585 aura::client::SetFocusChangeObserver(window_, this); | 478 aura::client::SetFocusChangeObserver(window_, this); |
586 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 479 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
587 #if defined(OS_WIN) | |
588 transient_observer_.reset(new TransientWindowObserver(this)); | |
589 #endif | |
590 software_frame_manager_.reset(new SoftwareFrameManager( | 480 software_frame_manager_.reset(new SoftwareFrameManager( |
591 weak_ptr_factory_.GetWeakPtr())); | 481 weak_ptr_factory_.GetWeakPtr())); |
592 } | 482 } |
593 | 483 |
594 //////////////////////////////////////////////////////////////////////////////// | 484 //////////////////////////////////////////////////////////////////////////////// |
595 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 485 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
596 | 486 |
597 void RenderWidgetHostViewAura::InitAsChild( | 487 void RenderWidgetHostViewAura::InitAsChild( |
598 gfx::NativeView parent_view) { | 488 gfx::NativeView parent_view) { |
599 window_->Init(ui::LAYER_TEXTURED); | 489 window_->Init(ui::LAYER_TEXTURED); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && | 567 if (!current_surface_.get() && host_->is_accelerated_compositing_active() && |
678 !released_front_lock_.get()) { | 568 !released_front_lock_.get()) { |
679 ui::Compositor* compositor = GetCompositor(); | 569 ui::Compositor* compositor = GetCompositor(); |
680 if (compositor) | 570 if (compositor) |
681 released_front_lock_ = compositor->GetCompositorLock(); | 571 released_front_lock_ = compositor->GetCompositorLock(); |
682 } | 572 } |
683 | 573 |
684 #if defined(OS_WIN) | 574 #if defined(OS_WIN) |
685 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 575 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
686 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 576 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
687 transient_observer_->SendPluginCutoutRects(); | |
688 #endif | 577 #endif |
689 } | 578 } |
690 | 579 |
691 void RenderWidgetHostViewAura::WasHidden() { | 580 void RenderWidgetHostViewAura::WasHidden() { |
692 if (!host_ || host_->is_hidden()) | 581 if (!host_ || host_->is_hidden()) |
693 return; | 582 return; |
694 host_->WasHidden(); | 583 host_->WasHidden(); |
695 software_frame_manager_->SetVisibility(false); | 584 software_frame_manager_->SetVisibility(false); |
696 delegated_frame_evictor_->SetVisible(false); | 585 delegated_frame_evictor_->SetVisible(false); |
697 released_front_lock_ = NULL; | 586 released_front_lock_ = NULL; |
698 | 587 |
699 #if defined(OS_WIN) | 588 #if defined(OS_WIN) |
| 589 constrained_rects_.clear(); |
700 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); | 590 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
701 if (dispatcher) { | 591 if (dispatcher) { |
702 HWND parent = dispatcher->GetAcceleratedWidget(); | 592 HWND parent = dispatcher->GetAcceleratedWidget(); |
703 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 593 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
704 | 594 |
705 EnumChildWindows(parent, HideWindowsCallback, lparam); | 595 EnumChildWindows(parent, HideWindowsCallback, lparam); |
706 } | 596 } |
707 #endif | 597 #endif |
708 } | 598 } |
709 | 599 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 moves[i].window_rect.OffsetFromOrigin() + scroll_offset); | 774 moves[i].window_rect.OffsetFromOrigin() + scroll_offset); |
885 clip.Offset(view_port_offset); | 775 clip.Offset(view_port_offset); |
886 clip.Intersect(view_port); | 776 clip.Intersect(view_port); |
887 clip.Offset(-view_port_offset); | 777 clip.Offset(-view_port_offset); |
888 moves[i].clip_rect = clip; | 778 moves[i].clip_rect = clip; |
889 | 779 |
890 moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin()); | 780 moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin()); |
891 | 781 |
892 plugin_window_moves_[moves[i].window] = moves[i]; | 782 plugin_window_moves_[moves[i].window] = moves[i]; |
893 | 783 |
894 // transient_rects_ and constrained_rects_ are relative to the root window. | 784 // constrained_rects_ are relative to the root window. We want to convert |
895 // We want to convert them to be relative to the plugin window. | 785 // them to be relative to the plugin window. |
896 std::vector<gfx::Rect> cutout_rects; | 786 for (size_t j = 0; j < constrained_rects_.size(); ++j) { |
897 cutout_rects.assign(transient_rects_.begin(), transient_rects_.end()); | 787 gfx::Rect offset_cutout = constrained_rects_[j]; |
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]; | |
902 offset_cutout -= moves[i].window_rect.OffsetFromOrigin(); | 788 offset_cutout -= moves[i].window_rect.OffsetFromOrigin(); |
903 moves[i].cutout_rects.push_back(offset_cutout); | 789 moves[i].cutout_rects.push_back(offset_cutout); |
904 } | 790 } |
905 } | 791 } |
906 | 792 |
907 MovePluginWindowsHelper(parent, moves); | 793 MovePluginWindowsHelper(parent, moves); |
908 | 794 |
909 // Make sure each plugin window (or its wrapper if it exists) has a pointer to | 795 // Make sure each plugin window (or its wrapper if it exists) has a pointer to |
910 // |this|. | 796 // |this|. |
911 for (size_t i = 0; i < moves.size(); ++i) { | 797 for (size_t i = 0; i < moves.size(); ++i) { |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 &frame, &callback)) { | 1241 &frame, &callback)) { |
1356 CopyFromCompositingSurfaceToVideoFrame( | 1242 CopyFromCompositingSurfaceToVideoFrame( |
1357 gfx::Rect(current_frame_size_), | 1243 gfx::Rect(current_frame_size_), |
1358 frame, | 1244 frame, |
1359 base::Bind(callback, present_time)); | 1245 base::Bind(callback, present_time)); |
1360 } | 1246 } |
1361 } | 1247 } |
1362 } | 1248 } |
1363 | 1249 |
1364 #if defined(OS_WIN) | 1250 #if defined(OS_WIN) |
1365 void RenderWidgetHostViewAura::UpdateTransientRects( | |
1366 const std::vector<gfx::Rect>& rects) { | |
1367 transient_rects_ = rects; | |
1368 UpdateCutoutRects(); | |
1369 } | |
1370 | |
1371 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( | 1251 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( |
1372 const std::vector<gfx::Rect>& rects) { | 1252 const std::vector<gfx::Rect>& rects) { |
1373 constrained_rects_ = rects; | 1253 constrained_rects_ = rects; |
1374 UpdateCutoutRects(); | 1254 UpdateCutoutRects(); |
1375 } | 1255 } |
1376 | 1256 |
1377 void RenderWidgetHostViewAura::UpdateCutoutRects() { | 1257 void RenderWidgetHostViewAura::UpdateCutoutRects() { |
1378 if (!window_->GetRootWindow()) | 1258 if (!window_->GetRootWindow()) |
1379 return; | 1259 return; |
1380 HWND parent = window_->GetDispatcher()->GetAcceleratedWidget(); | 1260 HWND parent = window_->GetDispatcher()->GetAcceleratedWidget(); |
1381 CutoutRectsParams params; | 1261 CutoutRectsParams params; |
1382 params.widget = this; | 1262 params.widget = this; |
1383 params.cutout_rects.assign(transient_rects_.begin(), transient_rects_.end()); | 1263 params.cutout_rects = constrained_rects_; |
1384 params.cutout_rects.insert(params.cutout_rects.end(), | |
1385 constrained_rects_.begin(), | |
1386 constrained_rects_.end()); | |
1387 params.geometry = &plugin_window_moves_; | 1264 params.geometry = &plugin_window_moves_; |
1388 LPARAM lparam = reinterpret_cast<LPARAM>(¶ms); | 1265 LPARAM lparam = reinterpret_cast<LPARAM>(¶ms); |
1389 EnumChildWindows(parent, SetCutoutRectsCallback, lparam); | 1266 EnumChildWindows(parent, SetCutoutRectsCallback, lparam); |
1390 } | 1267 } |
1391 #endif | 1268 #endif |
1392 | 1269 |
1393 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( | 1270 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
1394 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 1271 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
1395 int gpu_host_id) { | 1272 int gpu_host_id) { |
1396 BufferPresentedCallback ack_callback = base::Bind( | 1273 BufferPresentedCallback ack_callback = base::Bind( |
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3202 if (paint_observer_) | 3079 if (paint_observer_) |
3203 paint_observer_->OnViewDestroyed(); | 3080 paint_observer_->OnViewDestroyed(); |
3204 if (touch_editing_client_) | 3081 if (touch_editing_client_) |
3205 touch_editing_client_->OnViewDestroyed(); | 3082 touch_editing_client_->OnViewDestroyed(); |
3206 if (!shared_surface_handle_.is_null()) { | 3083 if (!shared_surface_handle_.is_null()) { |
3207 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 3084 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
3208 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 3085 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
3209 factory->RemoveObserver(this); | 3086 factory->RemoveObserver(this); |
3210 } | 3087 } |
3211 window_observer_.reset(); | 3088 window_observer_.reset(); |
3212 #if defined(OS_WIN) | |
3213 transient_observer_.reset(); | |
3214 #endif | |
3215 if (window_->GetDispatcher()) | 3089 if (window_->GetDispatcher()) |
3216 window_->GetDispatcher()->RemoveRootWindowObserver(this); | 3090 window_->GetDispatcher()->RemoveRootWindowObserver(this); |
3217 UnlockMouse(); | 3091 UnlockMouse(); |
3218 if (popup_parent_host_view_) { | 3092 if (popup_parent_host_view_) { |
3219 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 3093 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
3220 popup_parent_host_view_->popup_child_host_view_ == this); | 3094 popup_parent_host_view_->popup_child_host_view_ == this); |
3221 popup_parent_host_view_->popup_child_host_view_ = NULL; | 3095 popup_parent_host_view_->popup_child_host_view_ = NULL; |
3222 } | 3096 } |
3223 if (popup_child_host_view_) { | 3097 if (popup_child_host_view_) { |
3224 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || | 3098 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3441 RenderWidgetHost* widget) { | 3315 RenderWidgetHost* widget) { |
3442 return new RenderWidgetHostViewAura(widget); | 3316 return new RenderWidgetHostViewAura(widget); |
3443 } | 3317 } |
3444 | 3318 |
3445 // static | 3319 // static |
3446 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3320 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3447 GetScreenInfoForWindow(results, NULL); | 3321 GetScreenInfoForWindow(results, NULL); |
3448 } | 3322 } |
3449 | 3323 |
3450 } // namespace content | 3324 } // namespace content |
OLD | NEW |