OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromecast/browser/cast_window_manager_aura.h" |
| 6 |
| 7 #include "content/public/browser/web_contents.h" |
| 8 #include "ui/aura/env.h" |
| 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_tree_host.h" |
| 11 #include "ui/display/display.h" |
| 12 #include "ui/display/screen.h" |
| 13 |
| 14 namespace chromecast { |
| 15 namespace shell { |
| 16 |
| 17 CastWindowManagerAura::CastWindowManagerAura() { } |
| 18 |
| 19 CastWindowManagerAura::~CastWindowManagerAura() { |
| 20 CastVSyncSettings::GetInstance()->RemoveObserver(this); |
| 21 window_tree_host_.reset(); |
| 22 } |
| 23 |
| 24 void CastWindowManagerAura::StartWindowManager() { |
| 25 DCHECK(!window_tree_host_.get()); |
| 26 DCHECK(display::Screen::GetScreen()); |
| 27 |
| 28 gfx::Size display_size = |
| 29 display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
| 30 CHECK(aura::Env::GetInstance()); |
| 31 window_tree_host_.reset( |
| 32 aura::WindowTreeHost::Create(gfx::Rect(display_size))); |
| 33 window_tree_host_->InitHost(); |
| 34 window_tree_host_->window()->SetLayoutManager(this); |
| 35 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); |
| 36 |
| 37 CastVSyncSettings::GetInstance()->AddObserver(this); |
| 38 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval( |
| 39 CastVSyncSettings::GetInstance()->GetVSyncInterval()); |
| 40 |
| 41 window_tree_host_->Show(); |
| 42 } |
| 43 |
| 44 void CastWindowManagerAura::AddWebContents(content::WebContents* web_contents, |
| 45 bool is_overlay, |
| 46 bool is_transparent) { |
| 47 if (window_tree_host_.get() == nullptr) { |
| 48 StartWindowManager(); |
| 49 } |
| 50 |
| 51 aura::Window* child = web_contents->GetNativeView(); |
| 52 aura::Window* parent = window_tree_host_->window(); |
| 53 if (!parent->Contains(child)) { |
| 54 parent->AddChild(child); |
| 55 } |
| 56 if (is_overlay) { |
| 57 parent->StackChildAtTop(child); |
| 58 } else { |
| 59 parent->StackChildAtBottom(child); |
| 60 |
| 61 // The transparency of the root window depends on the bottom window's |
| 62 // transparency setting. |
| 63 if (is_transparent) { |
| 64 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 65 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
| 66 } else { |
| 67 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); |
| 68 } |
| 69 } |
| 70 child->SetTransparent(is_transparent); |
| 71 child->SetBounds(window_tree_host_->window()->bounds()); |
| 72 child->Show(); |
| 73 } |
| 74 |
| 75 void CastWindowManagerAura::OnVSyncIntervalChanged(base::TimeDelta interval) { |
| 76 DCHECK(window_tree_host_.get()); |
| 77 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); |
| 78 } |
| 79 |
| 80 void CastWindowManagerAura::OnWindowResized() { |
| 81 } |
| 82 |
| 83 void CastWindowManagerAura::OnWindowAddedToLayout(aura::Window* child) { |
| 84 } |
| 85 |
| 86 void CastWindowManagerAura::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 87 } |
| 88 |
| 89 void CastWindowManagerAura::OnWindowRemovedFromLayout(aura::Window* child) { |
| 90 } |
| 91 |
| 92 void CastWindowManagerAura::OnChildWindowVisibilityChanged(aura::Window* child, |
| 93 bool visible) { |
| 94 } |
| 95 |
| 96 void CastWindowManagerAura::SetChildBounds(aura::Window* child, |
| 97 const gfx::Rect& requested_bounds) { |
| 98 SetChildBoundsDirect(child, requested_bounds); |
| 99 } |
| 100 |
| 101 } // namespace shell |
| 102 } // namespace chromecast |
OLD | NEW |