Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
halliwell
2017/01/18 21:11:22
2017
Joshua LeVasseur
2017/01/19 00:56:33
Done.
| |
| 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/graphics/cast_window_manager_aura.h" | |
| 6 | |
| 7 #include "ui/aura/client/default_capture_client.h" | |
| 8 #include "ui/aura/env.h" | |
| 9 #include "ui/aura/layout_manager.h" | |
| 10 #include "ui/aura/window.h" | |
| 11 #include "ui/aura/window_tree_host_platform.h" | |
| 12 #include "ui/base/ime/input_method.h" | |
| 13 #include "ui/base/ime/input_method_factory.h" | |
| 14 #include "ui/display/display.h" | |
| 15 #include "ui/display/screen.h" | |
| 16 | |
| 17 namespace chromecast { | |
| 18 | |
| 19 // An aura::WindowTreeHost that correctly converts input events. | |
| 20 class CastWindowTreeHost : public aura::WindowTreeHostPlatform { | |
| 21 public: | |
| 22 CastWindowTreeHost(bool enable_input, const gfx::Rect& bounds); | |
| 23 ~CastWindowTreeHost() override; | |
| 24 | |
| 25 // aura::WindowTreeHostPlatform implementation: | |
| 26 void DispatchEvent(ui::Event* event) override; | |
| 27 | |
| 28 private: | |
| 29 const bool enable_input_; | |
| 30 | |
| 31 DISALLOW_COPY_AND_ASSIGN(CastWindowTreeHost); | |
| 32 }; | |
| 33 | |
| 34 CastWindowTreeHost::CastWindowTreeHost(bool enable_input, | |
| 35 const gfx::Rect& bounds) | |
| 36 : WindowTreeHostPlatform(bounds), enable_input_(enable_input) {} | |
| 37 | |
| 38 CastWindowTreeHost::~CastWindowTreeHost() {} | |
| 39 | |
| 40 void CastWindowTreeHost::DispatchEvent(ui::Event* event) { | |
| 41 if (!enable_input_) { | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 if (event->IsKeyEvent()) { | |
| 46 // Convert a RawKeyDown into a character insertion; otherwise | |
| 47 // the WebContents will ignore most keyboard input. | |
| 48 GetInputMethod()->DispatchKeyEvent(event->AsKeyEvent()); | |
| 49 } else { | |
| 50 WindowTreeHostPlatform::DispatchEvent(event); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 // A layout manager owned by the root window. | |
| 55 class CastLayoutManager : public aura::LayoutManager { | |
| 56 public: | |
| 57 CastLayoutManager(); | |
| 58 ~CastLayoutManager() override; | |
| 59 | |
| 60 private: | |
| 61 // aura::LayoutManager implementation: | |
| 62 void OnWindowResized() override; | |
| 63 void OnWindowAddedToLayout(aura::Window* child) override; | |
| 64 void OnWillRemoveWindowFromLayout(aura::Window* child) override; | |
| 65 void OnWindowRemovedFromLayout(aura::Window* child) override; | |
| 66 void OnChildWindowVisibilityChanged(aura::Window* child, | |
| 67 bool visible) override; | |
| 68 void SetChildBounds(aura::Window* child, | |
| 69 const gfx::Rect& requested_bounds) override; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(CastLayoutManager); | |
| 72 }; | |
| 73 | |
| 74 CastLayoutManager::CastLayoutManager() {} | |
| 75 CastLayoutManager::~CastLayoutManager() {} | |
| 76 | |
| 77 void CastLayoutManager::OnWindowResized() { | |
| 78 // Invoked when the root window of the window tree host has been resized. | |
| 79 } | |
| 80 | |
| 81 void CastLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | |
| 82 // Invoked when a window is added to the window tree host. | |
| 83 } | |
| 84 | |
| 85 void CastLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | |
| 86 // Invoked when the root window of the window tree host will be removed. | |
| 87 } | |
| 88 | |
| 89 void CastLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | |
| 90 // Invoked when the root window of the window tree host has been removed. | |
| 91 } | |
| 92 | |
| 93 void CastLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | |
| 94 bool visible) { | |
| 95 // Note: this is invoked for child windows of the root window. | |
| 96 } | |
| 97 | |
| 98 void CastLayoutManager::SetChildBounds(aura::Window* child, | |
| 99 const gfx::Rect& requested_bounds) { | |
| 100 SetChildBoundsDirect(child, requested_bounds); | |
| 101 } | |
| 102 | |
| 103 // static | |
| 104 std::unique_ptr<CastWindowManager> CastWindowManager::Create( | |
| 105 bool enable_input) { | |
| 106 return base::WrapUnique(new CastWindowManagerAura(enable_input)); | |
|
halliwell
2017/01/18 21:11:22
include ptr util header
Joshua LeVasseur
2017/01/19 00:56:33
Done.
| |
| 107 } | |
| 108 | |
| 109 CastWindowManagerAura::CastWindowManagerAura(bool enable_input) | |
| 110 : enable_input_(enable_input) {} | |
| 111 | |
| 112 CastWindowManagerAura::~CastWindowManagerAura() { | |
| 113 TearDown(); | |
| 114 } | |
| 115 | |
| 116 void CastWindowManagerAura::Setup() { | |
| 117 if (window_tree_host_) { | |
| 118 return; | |
| 119 } | |
| 120 DCHECK(display::Screen::GetScreen()); | |
| 121 | |
| 122 ui::InitializeInputMethodForTesting(); | |
| 123 | |
| 124 gfx::Size display_size = | |
| 125 display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel(); | |
| 126 LOG(INFO) << "Starting window manager, screen size: " << display_size.width() | |
| 127 << "x" << display_size.height(); | |
| 128 CHECK(aura::Env::GetInstance()); | |
| 129 window_tree_host_.reset( | |
| 130 new CastWindowTreeHost(enable_input_, gfx::Rect(display_size))); | |
| 131 window_tree_host_->InitHost(); | |
| 132 window_tree_host_->window()->SetLayoutManager(new CastLayoutManager()); | |
| 133 | |
| 134 // Allow seeing through to the hardware video plane: | |
| 135 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); | |
| 136 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); | |
| 137 | |
| 138 capture_client_.reset( | |
| 139 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | |
| 140 | |
| 141 CastVSyncSettings::GetInstance()->AddObserver(this); | |
| 142 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval( | |
| 143 CastVSyncSettings::GetInstance()->GetVSyncInterval()); | |
| 144 | |
| 145 window_tree_host_->Show(); | |
| 146 } | |
| 147 | |
| 148 void CastWindowManagerAura::TearDown() { | |
| 149 if (!window_tree_host_) { | |
| 150 return; | |
| 151 } | |
| 152 CastVSyncSettings::GetInstance()->RemoveObserver(this); | |
| 153 capture_client_.reset(); | |
| 154 window_tree_host_.reset(); | |
| 155 } | |
| 156 | |
| 157 void CastWindowManagerAura::AddAndShowWindow(gfx::NativeView child) { | |
| 158 AddWindow(child); | |
| 159 child->Show(); | |
| 160 } | |
| 161 | |
| 162 void CastWindowManagerAura::AddWindow(gfx::NativeView child) { | |
| 163 LOG(INFO) << "Adding window: " << child->id() << ": " << child->GetName(); | |
| 164 Setup(); | |
| 165 | |
| 166 DCHECK(child); | |
| 167 aura::Window* parent = window_tree_host_->window(); | |
| 168 if (!parent->Contains(child)) { | |
| 169 parent->AddChild(child); | |
| 170 } | |
| 171 | |
| 172 parent->StackChildAtTop(child); | |
| 173 child->SetBounds(window_tree_host_->window()->bounds()); | |
| 174 } | |
| 175 | |
| 176 void CastWindowManagerAura::OnVSyncIntervalChanged(base::TimeDelta interval) { | |
| 177 DCHECK(window_tree_host_.get()); | |
| 178 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); | |
| 179 } | |
| 180 | |
| 181 } // namespace chromecast | |
| OLD | NEW |