Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: ash/system/status_area_widget.cc

Issue 2148593004: mash: Move StatusTray and StatusAreaWidget to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@traydisplay
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/status_area_widget.h ('k') | ash/system/tray/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ash/system/status_area_widget.h"
6
7 #include "ash/common/shelf/wm_shelf.h"
8 #include "ash/common/shell_window_ids.h"
9 #include "ash/common/system/overview/overview_button_tray.h"
10 #include "ash/common/system/status_area_widget_delegate.h"
11 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/web_notification/web_notification_tray.h"
13 #include "ash/common/wm_lookup.h"
14 #include "ash/common/wm_root_window_controller.h"
15 #include "ash/common/wm_shell.h"
16 #include "ash/common/wm_window.h"
17 #include "ash/system/tray/system_tray.h"
18 #include "base/i18n/time_formatting.h"
19
20 #if defined(OS_CHROMEOS)
21 #include "ash/common/system/chromeos/session/logout_button_tray.h"
22 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h"
23 #endif
24
25 namespace ash {
26
27 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container,
28 WmShelf* wm_shelf)
29 : status_area_widget_delegate_(new StatusAreaWidgetDelegate),
30 overview_button_tray_(NULL),
31 system_tray_(NULL),
32 web_notification_tray_(NULL),
33 #if defined(OS_CHROMEOS)
34 logout_button_tray_(NULL),
35 virtual_keyboard_tray_(NULL),
36 #endif
37 login_status_(LoginStatus::NOT_LOGGED_IN),
38 wm_shelf_(wm_shelf) {
39 views::Widget::InitParams params(
40 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
41 params.delegate = status_area_widget_delegate_;
42 params.name = "StatusAreaWidget";
43 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
44 status_container->GetRootWindowController()
45 ->ConfigureWidgetInitParamsForContainer(
46 this, status_container->GetShellWindowId(), &params);
47 Init(params);
48 set_focus_on_creation(false);
49 SetContentsView(status_area_widget_delegate_);
50 }
51
52 StatusAreaWidget::~StatusAreaWidget() {}
53
54 void StatusAreaWidget::CreateTrayViews() {
55 AddOverviewButtonTray();
56 AddSystemTray();
57 AddWebNotificationTray();
58 #if defined(OS_CHROMEOS)
59 AddLogoutButtonTray();
60 AddVirtualKeyboardTray();
61 #endif
62
63 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
64 DCHECK(delegate);
65 // Initialize after all trays have been created.
66 system_tray_->InitializeTrayItems(delegate, web_notification_tray_);
67 web_notification_tray_->Initialize();
68 #if defined(OS_CHROMEOS)
69 logout_button_tray_->Initialize();
70 virtual_keyboard_tray_->Initialize();
71 #endif
72 overview_button_tray_->Initialize();
73 SetShelfAlignment(system_tray_->shelf_alignment());
74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus());
75 }
76
77 void StatusAreaWidget::Shutdown() {
78 system_tray_->Shutdown();
79 // Destroy the trays early, causing them to be removed from the view
80 // hierarchy. Do not used scoped pointers since we don't want to destroy them
81 // in the destructor if Shutdown() is not called (e.g. in tests).
82 delete web_notification_tray_;
83 web_notification_tray_ = NULL;
84 // Must be destroyed after |web_notification_tray_|.
85 delete system_tray_;
86 system_tray_ = NULL;
87 #if defined(OS_CHROMEOS)
88 delete virtual_keyboard_tray_;
89 virtual_keyboard_tray_ = NULL;
90 delete logout_button_tray_;
91 logout_button_tray_ = NULL;
92 #endif
93 delete overview_button_tray_;
94 overview_button_tray_ = NULL;
95 }
96
97 bool StatusAreaWidget::ShouldShowShelf() const {
98 if ((system_tray_ && system_tray_->ShouldShowShelf()) ||
99 (web_notification_tray_ &&
100 web_notification_tray_->ShouldBlockShelfAutoHide()))
101 return true;
102
103 if (!wm_shelf_->IsVisible())
104 return false;
105
106 // If the shelf is currently visible, don't hide the shelf if the mouse
107 // is in any of the notification bubbles.
108 return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) ||
109 (web_notification_tray_ &&
110 web_notification_tray_->IsMouseInNotificationBubble());
111 }
112
113 bool StatusAreaWidget::IsMessageBubbleShown() const {
114 return ((system_tray_ && system_tray_->IsAnyBubbleVisible()) ||
115 (web_notification_tray_ &&
116 web_notification_tray_->IsMessageCenterBubbleVisible()));
117 }
118
119 void StatusAreaWidget::SchedulePaint() {
120 status_area_widget_delegate_->SchedulePaint();
121 web_notification_tray_->SchedulePaint();
122 system_tray_->SchedulePaint();
123 #if defined(OS_CHROMEOS)
124 virtual_keyboard_tray_->SchedulePaint();
125 logout_button_tray_->SchedulePaint();
126 #endif
127 overview_button_tray_->SchedulePaint();
128 }
129
130 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) {
131 Widget::OnNativeWidgetActivationChanged(active);
132 if (active)
133 status_area_widget_delegate_->SetPaneFocusAndFocusDefault();
134 }
135
136 void StatusAreaWidget::OnMouseEvent(ui::MouseEvent* event) {
137 Widget::OnMouseEvent(event);
138 wm_shelf_->UpdateAutoHideForMouseEvent(event);
139 }
140
141 void StatusAreaWidget::OnGestureEvent(ui::GestureEvent* event) {
142 Widget::OnGestureEvent(event);
143 wm_shelf_->UpdateAutoHideForGestureEvent(event);
144 }
145
146 void StatusAreaWidget::AddSystemTray() {
147 system_tray_ = new SystemTray(wm_shelf_);
148 status_area_widget_delegate_->AddTray(system_tray_);
149 }
150
151 void StatusAreaWidget::AddWebNotificationTray() {
152 DCHECK(system_tray_);
153 web_notification_tray_ = new WebNotificationTray(
154 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_);
155 status_area_widget_delegate_->AddTray(web_notification_tray_);
156 }
157
158 #if defined(OS_CHROMEOS)
159 void StatusAreaWidget::AddLogoutButtonTray() {
160 logout_button_tray_ = new LogoutButtonTray(wm_shelf_);
161 status_area_widget_delegate_->AddTray(logout_button_tray_);
162 }
163
164 void StatusAreaWidget::AddVirtualKeyboardTray() {
165 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_);
166 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_);
167 }
168 #endif
169
170 void StatusAreaWidget::AddOverviewButtonTray() {
171 overview_button_tray_ = new OverviewButtonTray(wm_shelf_);
172 status_area_widget_delegate_->AddTray(overview_button_tray_);
173 }
174
175 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
176 status_area_widget_delegate_->set_alignment(alignment);
177 if (system_tray_)
178 system_tray_->SetShelfAlignment(alignment);
179 if (web_notification_tray_)
180 web_notification_tray_->SetShelfAlignment(alignment);
181 #if defined(OS_CHROMEOS)
182 if (logout_button_tray_)
183 logout_button_tray_->SetShelfAlignment(alignment);
184 if (virtual_keyboard_tray_)
185 virtual_keyboard_tray_->SetShelfAlignment(alignment);
186 #endif
187 if (overview_button_tray_)
188 overview_button_tray_->SetShelfAlignment(alignment);
189 status_area_widget_delegate_->UpdateLayout();
190 }
191
192 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) {
193 if (login_status_ == login_status)
194 return;
195 login_status_ = login_status;
196 if (system_tray_)
197 system_tray_->UpdateAfterLoginStatusChange(login_status);
198 if (web_notification_tray_)
199 web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
200 #if defined(OS_CHROMEOS)
201 if (logout_button_tray_)
202 logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
203 #endif
204 if (overview_button_tray_)
205 overview_button_tray_->UpdateAfterLoginStatusChange(login_status);
206 }
207
208 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/status_area_widget.h ('k') | ash/system/tray/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698