[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / ash / touch / touch_observer_hud.cc
blob1ace7fd85d3df042a1e0620993e0935377f2040e
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
3 // found in the LICENSE file.
5 #include "ash/touch/touch_observer_hud.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/root_window_settings.h"
9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h"
11 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/gfx/display.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/screen.h"
16 #include "ui/views/widget/widget.h"
18 namespace ash {
20 TouchObserverHUD::TouchObserverHUD(aura::Window* initial_root)
21 : display_id_(GetRootWindowSettings(initial_root)->display_id),
22 root_window_(initial_root),
23 widget_(NULL) {
24 const gfx::Display& display =
25 Shell::GetInstance()->display_manager()->GetDisplayForId(display_id_);
27 views::View* content = new views::View;
29 const gfx::Size& display_size = display.size();
30 content->SetSize(display_size);
32 widget_ = new views::Widget();
33 views::Widget::InitParams
34 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
35 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
36 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
37 params.accept_events = false;
38 params.bounds = display.bounds();
39 params.parent =
40 Shell::GetContainer(root_window_, kShellWindowId_OverlayContainer);
41 widget_->Init(params);
42 widget_->SetContentsView(content);
43 widget_->StackAtTop();
44 widget_->Show();
46 widget_->AddObserver(this);
48 // Observe changes in display size and mode to update touch HUD.
49 Shell::GetScreen()->AddObserver(this);
50 #if defined(OS_CHROMEOS)
51 Shell::GetInstance()->display_configurator()->AddObserver(this);
52 #endif // defined(OS_CHROMEOS)
54 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
55 root_window_->AddPreTargetHandler(this);
58 TouchObserverHUD::~TouchObserverHUD() {
59 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
61 #if defined(OS_CHROMEOS)
62 Shell::GetInstance()->display_configurator()->RemoveObserver(this);
63 #endif // defined(OS_CHROMEOS)
64 Shell::GetScreen()->RemoveObserver(this);
66 widget_->RemoveObserver(this);
69 void TouchObserverHUD::Clear() {
72 void TouchObserverHUD::Remove() {
73 root_window_->RemovePreTargetHandler(this);
75 RootWindowController* controller = GetRootWindowController(root_window_);
76 UnsetHudForRootWindowController(controller);
78 widget_->CloseNow();
81 void TouchObserverHUD::OnTouchEvent(ui::TouchEvent* /*event*/) {
84 void TouchObserverHUD::OnWidgetDestroying(views::Widget* widget) {
85 DCHECK_EQ(widget, widget_);
86 delete this;
89 void TouchObserverHUD::OnDisplayAdded(const gfx::Display& new_display) {}
91 void TouchObserverHUD::OnDisplayRemoved(const gfx::Display& old_display) {
92 if (old_display.id() != display_id_)
93 return;
94 widget_->CloseNow();
97 void TouchObserverHUD::OnDisplayMetricsChanged(const gfx::Display& display,
98 uint32_t metrics) {
99 if (display.id() != display_id_ || !(metrics & DISPLAY_METRIC_BOUNDS))
100 return;
102 widget_->SetSize(display.size());
105 #if defined(OS_CHROMEOS)
106 void TouchObserverHUD::OnDisplayModeChanged(
107 const ui::DisplayConfigurator::DisplayStateList& outputs) {
108 // Clear touch HUD for any change in display mode (single, dual extended, dual
109 // mirrored, ...).
110 Clear();
112 #endif // defined(OS_CHROMEOS)
114 void TouchObserverHUD::OnDisplaysInitialized() {
115 OnDisplayConfigurationChanged();
118 void TouchObserverHUD::OnDisplayConfigurationChanging() {
119 if (!root_window_)
120 return;
122 root_window_->RemovePreTargetHandler(this);
124 RootWindowController* controller = GetRootWindowController(root_window_);
125 UnsetHudForRootWindowController(controller);
127 views::Widget::ReparentNativeView(
128 widget_->GetNativeView(),
129 Shell::GetContainer(root_window_,
130 kShellWindowId_UnparentedControlContainer));
132 root_window_ = NULL;
135 void TouchObserverHUD::OnDisplayConfigurationChanged() {
136 if (root_window_)
137 return;
139 root_window_ = Shell::GetInstance()
140 ->window_tree_host_manager()
141 ->GetRootWindowForDisplayId(display_id_);
143 views::Widget::ReparentNativeView(
144 widget_->GetNativeView(),
145 Shell::GetContainer(root_window_, kShellWindowId_OverlayContainer));
147 RootWindowController* controller = GetRootWindowController(root_window_);
148 SetHudForRootWindowController(controller);
150 root_window_->AddPreTargetHandler(this);
153 } // namespace ash