OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/browser/cast_content_window_linux.h" | 5 #include "chromecast/browser/cast_content_window_linux.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "chromecast/base/metrics/cast_metrics_helper.h" | 10 #include "chromecast/base/metrics/cast_metrics_helper.h" |
| 11 #include "chromecast/base/version.h" |
11 #include "chromecast/browser/cast_browser_process.h" | 12 #include "chromecast/browser/cast_browser_process.h" |
12 #include "chromecast/graphics/cast_vsync_settings.h" | 13 #include "chromecast/graphics/cast_vsync_settings.h" |
13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/render_widget_host.h" | 15 #include "content/public/browser/render_widget_host.h" |
15 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
18 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
19 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
20 | 21 |
21 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
22 #include "chromecast/graphics/cast_screen.h" | 23 #include "chromecast/graphics/cast_screen.h" |
23 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
24 #include "ui/aura/layout_manager.h" | 25 #include "ui/aura/layout_manager.h" |
25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
26 #include "ui/aura/window_tree_host.h" | 27 #include "ui/aura/window_tree_host.h" |
| 28 #include "ui/aura/window_tree_host_platform.h" |
| 29 #include "ui/base/ime/input_method.h" |
27 #endif | 30 #endif |
28 | 31 |
29 namespace chromecast { | 32 namespace chromecast { |
30 namespace shell { | 33 namespace shell { |
31 | 34 |
32 #if defined(USE_AURA) | 35 #if defined(USE_AURA) |
33 class CastFillLayout : public aura::LayoutManager { | 36 class CastFillLayout : public aura::LayoutManager { |
34 public: | 37 public: |
35 explicit CastFillLayout(aura::Window* root) : root_(root) {} | 38 explicit CastFillLayout(aura::Window* root) : root_(root) {} |
36 ~CastFillLayout() override {} | 39 ~CastFillLayout() override {} |
(...skipping 14 matching lines...) Expand all Loading... |
51 | 54 |
52 void SetChildBounds(aura::Window* child, | 55 void SetChildBounds(aura::Window* child, |
53 const gfx::Rect& requested_bounds) override { | 56 const gfx::Rect& requested_bounds) override { |
54 SetChildBoundsDirect(child, requested_bounds); | 57 SetChildBoundsDirect(child, requested_bounds); |
55 } | 58 } |
56 | 59 |
57 aura::Window* root_; | 60 aura::Window* root_; |
58 | 61 |
59 DISALLOW_COPY_AND_ASSIGN(CastFillLayout); | 62 DISALLOW_COPY_AND_ASSIGN(CastFillLayout); |
60 }; | 63 }; |
| 64 |
| 65 // An aura::WindowTreeHost that correctly converts input events. |
| 66 class CastWindowTreeHost : public aura::WindowTreeHostPlatform { |
| 67 public: |
| 68 CastWindowTreeHost(bool enable_input, const gfx::Rect& bounds); |
| 69 ~CastWindowTreeHost() override; |
| 70 |
| 71 // aura::WindowTreeHostPlatform implementation: |
| 72 void DispatchEvent(ui::Event* event) override; |
| 73 |
| 74 private: |
| 75 const bool enable_input_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(CastWindowTreeHost); |
| 78 }; |
| 79 |
| 80 CastWindowTreeHost::CastWindowTreeHost(bool enable_input, |
| 81 const gfx::Rect& bounds) |
| 82 : WindowTreeHostPlatform(bounds), enable_input_(enable_input) {} |
| 83 |
| 84 CastWindowTreeHost::~CastWindowTreeHost() {} |
| 85 |
| 86 void CastWindowTreeHost::DispatchEvent(ui::Event* event) { |
| 87 if (!enable_input_) { |
| 88 return; |
| 89 } |
| 90 |
| 91 if (event->IsKeyEvent()) { |
| 92 // Convert a RawKeyDown into a character insertion; otherwise |
| 93 // the WebContents will ignore most keyboard input. |
| 94 GetInputMethod()->DispatchKeyEvent(event->AsKeyEvent()); |
| 95 } else { |
| 96 WindowTreeHostPlatform::DispatchEvent(event); |
| 97 } |
| 98 } |
61 #endif | 99 #endif |
62 | 100 |
63 // static | 101 // static |
64 std::unique_ptr<CastContentWindow> CastContentWindow::Create( | 102 std::unique_ptr<CastContentWindow> CastContentWindow::Create( |
65 CastContentWindow::Delegate* delegate) { | 103 CastContentWindow::Delegate* delegate) { |
66 DCHECK(delegate); | 104 DCHECK(delegate); |
67 return base::WrapUnique(new CastContentWindowLinux()); | 105 return base::WrapUnique(new CastContentWindowLinux()); |
68 } | 106 } |
69 | 107 |
70 CastContentWindowLinux::CastContentWindowLinux() : transparent_(false) {} | 108 CastContentWindowLinux::CastContentWindowLinux() : transparent_(false) {} |
(...skipping 13 matching lines...) Expand all Loading... |
84 } | 122 } |
85 | 123 |
86 void CastContentWindowLinux::ShowWebContents( | 124 void CastContentWindowLinux::ShowWebContents( |
87 content::WebContents* web_contents) { | 125 content::WebContents* web_contents) { |
88 #if defined(USE_AURA) | 126 #if defined(USE_AURA) |
89 // Aura initialization | 127 // Aura initialization |
90 DCHECK(display::Screen::GetScreen()); | 128 DCHECK(display::Screen::GetScreen()); |
91 gfx::Size display_size = | 129 gfx::Size display_size = |
92 display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel(); | 130 display::Screen::GetScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
93 CHECK(aura::Env::GetInstance()); | 131 CHECK(aura::Env::GetInstance()); |
94 window_tree_host_.reset( | 132 window_tree_host_.reset(new CastWindowTreeHost( |
95 aura::WindowTreeHost::Create(gfx::Rect(display_size))); | 133 CAST_IS_DEBUG_BUILD() /* enable input */, gfx::Rect(display_size))); |
96 window_tree_host_->InitHost(); | 134 window_tree_host_->InitHost(); |
97 window_tree_host_->window()->Show(); | 135 window_tree_host_->window()->Show(); |
98 window_tree_host_->window()->SetLayoutManager( | 136 window_tree_host_->window()->SetLayoutManager( |
99 new CastFillLayout(window_tree_host_->window())); | 137 new CastFillLayout(window_tree_host_->window())); |
100 | 138 |
101 if (transparent_) { | 139 if (transparent_) { |
102 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); | 140 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
103 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); | 141 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
104 } else { | 142 } else { |
105 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); | 143 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 209 } |
172 | 210 |
173 void CastContentWindowLinux::OnVSyncIntervalChanged(base::TimeDelta interval) { | 211 void CastContentWindowLinux::OnVSyncIntervalChanged(base::TimeDelta interval) { |
174 #if defined(USE_AURA) | 212 #if defined(USE_AURA) |
175 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); | 213 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); |
176 #endif | 214 #endif |
177 } | 215 } |
178 | 216 |
179 } // namespace shell | 217 } // namespace shell |
180 } // namespace chromecast | 218 } // namespace chromecast |
OLD | NEW |