Fix keyboard accessibility feedback
[chromium-blink-merge.git] / chromecast / browser / cast_content_window.cc
blob6afba6de6a85668662c040407432d755d271a668
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
3 // found in the LICENSE file.
5 #include "chromecast/browser/cast_content_window.h"
7 #include "base/command_line.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "chromecast/base/chromecast_switches.h"
10 #include "chromecast/base/metrics/cast_metrics_helper.h"
11 #include "chromecast/browser/cast_browser_process.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ipc/ipc_message.h"
17 #if defined(USE_AURA)
18 #include "chromecast/graphics/cast_screen.h"
19 #include "ui/aura/env.h"
20 #include "ui/aura/layout_manager.h"
21 #include "ui/aura/window.h"
22 #include "ui/aura/window_tree_host.h"
23 #endif
25 namespace chromecast {
27 #if defined(USE_AURA)
28 class CastFillLayout : public aura::LayoutManager {
29 public:
30 explicit CastFillLayout(aura::Window* root) : root_(root) {}
31 ~CastFillLayout() override {}
33 private:
34 void OnWindowResized() override {}
36 void OnWindowAddedToLayout(aura::Window* child) override {
37 child->SetBounds(root_->bounds());
40 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
42 void OnWindowRemovedFromLayout(aura::Window* child) override {}
44 void OnChildWindowVisibilityChanged(aura::Window* child,
45 bool visible) override {}
47 void SetChildBounds(aura::Window* child,
48 const gfx::Rect& requested_bounds) override {
49 SetChildBoundsDirect(child, requested_bounds);
52 aura::Window* root_;
54 DISALLOW_COPY_AND_ASSIGN(CastFillLayout);
56 #endif
58 CastContentWindow::CastContentWindow() {}
60 CastContentWindow::~CastContentWindow() {
61 #if defined(USE_AURA)
62 window_tree_host_.reset();
63 // We don't delete the screen here to avoid a CHECK failure when
64 // the screen size is queried periodically for metric gathering. b/18101124
65 #endif
68 void CastContentWindow::CreateWindowTree(
69 const gfx::Size& initial_size,
70 content::WebContents* web_contents) {
71 #if defined(USE_AURA)
72 // Aura initialization
73 CastScreen* cast_screen =
74 shell::CastBrowserProcess::GetInstance()->cast_screen();
75 if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE))
76 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, cast_screen);
77 if (cast_screen->GetPrimaryDisplay().size() != initial_size)
78 cast_screen->UpdateDisplaySize(initial_size);
80 CHECK(aura::Env::GetInstance());
81 window_tree_host_.reset(
82 aura::WindowTreeHost::Create(gfx::Rect(initial_size)));
83 window_tree_host_->InitHost();
84 window_tree_host_->window()->SetLayoutManager(
85 new CastFillLayout(window_tree_host_->window()));
87 const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
88 if (command_line->HasSwitch(switches::kEnableTransparentBackground)) {
89 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
90 window_tree_host_->compositor()->SetHostHasTransparentBackground(true);
91 } else {
92 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorBLACK);
94 window_tree_host_->Show();
96 // Add and show content's view/window
97 aura::Window* content_window = web_contents->GetNativeView();
98 aura::Window* parent = window_tree_host_->window();
99 if (!parent->Contains(content_window)) {
100 parent->AddChild(content_window);
102 content_window->Show();
103 #endif
106 scoped_ptr<content::WebContents> CastContentWindow::CreateWebContents(
107 const gfx::Size& initial_size,
108 content::BrowserContext* browser_context) {
109 content::WebContents::CreateParams create_params(browser_context, NULL);
110 create_params.routing_id = MSG_ROUTING_NONE;
111 create_params.initial_size = initial_size;
112 content::WebContents* web_contents = content::WebContents::Create(
113 create_params);
114 content::WebContentsObserver::Observe(web_contents);
115 return make_scoped_ptr(web_contents);
118 void CastContentWindow::DidFirstVisuallyNonEmptyPaint() {
119 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint();
122 void CastContentWindow::MediaPaused() {
123 metrics::CastMetricsHelper::GetInstance()->LogMediaPause();
126 void CastContentWindow::MediaStartedPlaying() {
127 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay();
130 void CastContentWindow::RenderViewCreated(
131 content::RenderViewHost* render_view_host) {
132 const base::CommandLine* command_line(base::CommandLine::ForCurrentProcess());
133 if (command_line->HasSwitch(switches::kEnableTransparentBackground)) {
134 content::RenderWidgetHostView* view = render_view_host->GetView();
135 if (view)
136 view->SetBackgroundColor(SK_ColorTRANSPARENT);
140 } // namespace chromecast