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"
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/rect.h"
14 #include "ui/gfx/screen.h"
15 #include "ui/gfx/size.h"
16 #include "ui/views/widget/widget.h"
20 TouchObserverHUD::TouchObserverHUD(aura::Window
* initial_root
)
21 : display_id_(GetRootWindowSettings(initial_root
)->display_id
),
22 root_window_(initial_root
),
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();
40 Shell::GetContainer(root_window_
, kShellWindowId_OverlayContainer
);
41 widget_
->Init(params
);
42 widget_
->SetContentsView(content
);
43 widget_
->StackAtTop();
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()->display_controller()->AddObserver(this);
55 root_window_
->AddPreTargetHandler(this);
58 TouchObserverHUD::~TouchObserverHUD() {
59 Shell::GetInstance()->display_controller()->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
);
81 void TouchObserverHUD::OnTouchEvent(ui::TouchEvent
* /*event*/) {
84 void TouchObserverHUD::OnWidgetDestroying(views::Widget
* widget
) {
85 DCHECK_EQ(widget
, widget_
);
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_
)
97 void TouchObserverHUD::OnDisplayMetricsChanged(const gfx::Display
& display
,
99 if (display
.id() != display_id_
|| !(metrics
& DISPLAY_METRIC_BOUNDS
))
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
112 #endif // defined(OS_CHROMEOS)
114 void TouchObserverHUD::OnDisplaysInitialized() {
115 OnDisplayConfigurationChanged();
118 void TouchObserverHUD::OnDisplayConfigurationChanging() {
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
));
135 void TouchObserverHUD::OnDisplayConfigurationChanged() {
139 root_window_
= Shell::GetInstance()->display_controller()->
140 GetRootWindowForDisplayId(display_id_
);
142 views::Widget::ReparentNativeView(
143 widget_
->GetNativeView(),
144 Shell::GetContainer(root_window_
, kShellWindowId_OverlayContainer
));
146 RootWindowController
* controller
= GetRootWindowController(root_window_
);
147 SetHudForRootWindowController(controller
);
149 root_window_
->AddPreTargetHandler(this);