OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/common/system/tray/system_tray_bubble.h" | 5 #include "ash/common/system/tray/system_tray_bubble.h" |
6 | 6 |
7 #include <utility> | |
8 #include <vector> | |
9 | |
7 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
8 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
9 #include "ash/common/system/tray/system_tray_item.h" | 12 #include "ash/common/system/tray/system_tray_item.h" |
10 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 13 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
11 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
12 #include "ash/common/system/tray/tray_popup_item_container.h" | 15 #include "ash/common/system/tray/tray_popup_item_container.h" |
13 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
17 #include "base/metrics/histogram_macros.h" | |
14 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
15 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
16 #include "ui/compositor/layer_animation_observer.h" | 20 #include "ui/compositor/layer_animation_observer.h" |
17 #include "ui/compositor/scoped_layer_animation_settings.h" | 21 #include "ui/compositor/scoped_layer_animation_settings.h" |
18 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
19 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
20 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
21 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
22 | 26 |
23 using views::TrayBubbleView; | 27 using views::TrayBubbleView; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 | 61 |
58 } // namespace | 62 } // namespace |
59 | 63 |
60 // SystemTrayBubble | 64 // SystemTrayBubble |
61 | 65 |
62 SystemTrayBubble::SystemTrayBubble( | 66 SystemTrayBubble::SystemTrayBubble( |
63 ash::SystemTray* tray, | 67 ash::SystemTray* tray, |
64 const std::vector<ash::SystemTrayItem*>& items, | 68 const std::vector<ash::SystemTrayItem*>& items, |
65 BubbleType bubble_type) | 69 BubbleType bubble_type) |
66 : tray_(tray), | 70 : tray_(tray), |
67 bubble_view_(NULL), | 71 bubble_view_(nullptr), |
68 items_(items), | 72 items_(items), |
69 bubble_type_(bubble_type), | 73 bubble_type_(bubble_type), |
70 autoclose_delay_(0) {} | 74 autoclose_delay_(0) {} |
71 | 75 |
72 SystemTrayBubble::~SystemTrayBubble() { | 76 SystemTrayBubble::~SystemTrayBubble() { |
73 DestroyItemViews(); | 77 DestroyItemViews(); |
74 // Reset the host pointer in bubble_view_ in case its destruction is deferred. | 78 // Reset the host pointer in bubble_view_ in case its destruction is deferred. |
75 if (bubble_view_) | 79 if (bubble_view_) |
76 bubble_view_->reset_delegate(); | 80 bubble_view_->reset_delegate(); |
77 } | 81 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 if (bubble_view_->CanActivate()) { | 200 if (bubble_view_->CanActivate()) { |
197 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 201 bubble_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
198 } | 202 } |
199 } | 203 } |
200 | 204 |
201 void SystemTrayBubble::FocusDefaultIfNeeded() { | 205 void SystemTrayBubble::FocusDefaultIfNeeded() { |
202 views::FocusManager* manager = bubble_view_->GetFocusManager(); | 206 views::FocusManager* manager = bubble_view_->GetFocusManager(); |
203 if (!manager || manager->GetFocusedView()) | 207 if (!manager || manager->GetFocusedView()) |
204 return; | 208 return; |
205 | 209 |
206 views::View* view = manager->GetNextFocusableView(NULL, NULL, false, false); | 210 views::View* view = |
211 manager->GetNextFocusableView(nullptr, nullptr, false, false); | |
207 if (view) | 212 if (view) |
208 view->RequestFocus(); | 213 view->RequestFocus(); |
209 } | 214 } |
210 | 215 |
211 void SystemTrayBubble::DestroyItemViews() { | 216 void SystemTrayBubble::DestroyItemViews() { |
212 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); | 217 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
213 it != items_.end(); ++it) { | 218 it != items_.end(); ++it) { |
214 switch (bubble_type_) { | 219 switch (bubble_type_) { |
215 case BUBBLE_TYPE_DEFAULT: | 220 case BUBBLE_TYPE_DEFAULT: |
216 (*it)->DestroyDefaultView(); | 221 (*it)->DestroyDefaultView(); |
217 break; | 222 break; |
218 case BUBBLE_TYPE_DETAILED: | 223 case BUBBLE_TYPE_DETAILED: |
219 (*it)->DestroyDetailedView(); | 224 (*it)->DestroyDetailedView(); |
220 break; | 225 break; |
221 case BUBBLE_TYPE_NOTIFICATION: | 226 case BUBBLE_TYPE_NOTIFICATION: |
222 (*it)->DestroyNotificationView(); | 227 (*it)->DestroyNotificationView(); |
223 break; | 228 break; |
224 } | 229 } |
225 } | 230 } |
226 } | 231 } |
227 | 232 |
228 void SystemTrayBubble::BubbleViewDestroyed() { | 233 void SystemTrayBubble::BubbleViewDestroyed() { |
229 bubble_view_ = NULL; | 234 bubble_view_ = nullptr; |
230 } | 235 } |
231 | 236 |
232 void SystemTrayBubble::StartAutoCloseTimer(int seconds) { | 237 void SystemTrayBubble::StartAutoCloseTimer(int seconds) { |
233 autoclose_.Stop(); | 238 autoclose_.Stop(); |
234 autoclose_delay_ = seconds; | 239 autoclose_delay_ = seconds; |
235 if (autoclose_delay_) { | 240 if (autoclose_delay_) { |
236 autoclose_.Start(FROM_HERE, base::TimeDelta::FromSeconds(autoclose_delay_), | 241 autoclose_.Start(FROM_HERE, base::TimeDelta::FromSeconds(autoclose_delay_), |
237 this, &SystemTrayBubble::Close); | 242 this, &SystemTrayBubble::Close); |
238 } | 243 } |
239 } | 244 } |
(...skipping 27 matching lines...) Expand all Loading... | |
267 | 272 |
268 bool SystemTrayBubble::ShouldShowShelf() const { | 273 bool SystemTrayBubble::ShouldShowShelf() const { |
269 for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); | 274 for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); |
270 it != items_.end(); ++it) { | 275 it != items_.end(); ++it) { |
271 if ((*it)->ShouldShowShelf()) | 276 if ((*it)->ShouldShowShelf()) |
272 return true; | 277 return true; |
273 } | 278 } |
274 return false; | 279 return false; |
275 } | 280 } |
276 | 281 |
282 void SystemTrayBubble::RecordVisibleRowMetrics() { | |
283 if (bubble_type_ != BUBBLE_TYPE_DEFAULT) { | |
James Cook
2016/07/20 20:13:49
nit: no {}
bruthig
2016/07/21 14:34:58
Done.
| |
284 return; | |
285 } | |
286 | |
287 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : | |
288 tray_item_view_map_) { | |
289 if (pair.second->visible()) { | |
290 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", | |
291 pair.first, SystemTrayItem::COUNT); | |
292 } | |
293 } | |
294 } | |
295 | |
277 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 296 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
278 std::vector<views::View*> item_views; | 297 tray_item_view_map_.clear(); |
298 | |
279 // If a system modal dialog is present, create the same tray as | 299 // If a system modal dialog is present, create the same tray as |
280 // in locked state. | 300 // in locked state. |
281 if (WmShell::Get()->IsSystemModalWindowOpen() && | 301 if (WmShell::Get()->IsSystemModalWindowOpen() && |
282 login_status != LoginStatus::NOT_LOGGED_IN) { | 302 login_status != LoginStatus::NOT_LOGGED_IN) { |
283 login_status = LoginStatus::LOCKED; | 303 login_status = LoginStatus::LOCKED; |
284 } | 304 } |
285 | 305 |
286 views::View* focus_view = NULL; | 306 views::View* focus_view = nullptr; |
307 const bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; | |
287 for (size_t i = 0; i < items_.size(); ++i) { | 308 for (size_t i = 0; i < items_.size(); ++i) { |
288 views::View* view = NULL; | 309 views::View* item_view = nullptr; |
James Cook
2016/07/20 20:13:49
item_view is a better name, thanks for changing it
| |
289 switch (bubble_type_) { | 310 switch (bubble_type_) { |
290 case BUBBLE_TYPE_DEFAULT: | 311 case BUBBLE_TYPE_DEFAULT: |
291 view = items_[i]->CreateDefaultView(login_status); | 312 item_view = items_[i]->CreateDefaultView(login_status); |
292 if (items_[i]->restore_focus()) | 313 if (items_[i]->restore_focus()) |
293 focus_view = view; | 314 focus_view = item_view; |
294 break; | 315 break; |
295 case BUBBLE_TYPE_DETAILED: | 316 case BUBBLE_TYPE_DETAILED: |
296 view = items_[i]->CreateDetailedView(login_status); | 317 item_view = items_[i]->CreateDetailedView(login_status); |
297 break; | 318 break; |
298 case BUBBLE_TYPE_NOTIFICATION: | 319 case BUBBLE_TYPE_NOTIFICATION: |
299 view = items_[i]->CreateNotificationView(login_status); | 320 item_view = items_[i]->CreateNotificationView(login_status); |
300 break; | 321 break; |
301 } | 322 } |
302 if (view) | 323 if (item_view) { |
303 item_views.push_back(view); | 324 views::View* tray_popup_item_container = new TrayPopupItemContainer( |
325 item_view, is_default_bubble, is_default_bubble); | |
326 bubble_view_->AddChildView(tray_popup_item_container); | |
327 tray_item_view_map_[items_[i]->uma_type()] = tray_popup_item_container; | |
328 } | |
304 } | 329 } |
305 | 330 |
306 bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; | 331 // For default view, draw bottom border for each item, except the last |
307 for (size_t i = 0; i < item_views.size(); ++i) { | 332 // 2 items, which are the bottom header row and the one just above it. |
308 // For default view, draw bottom border for each item, except the last | 333 const int view_count = bubble_view_->child_count(); |
309 // 2 items, which are the bottom header row and the one just above it. | 334 if (is_default_bubble && view_count > 1) { |
310 bubble_view_->AddChildView(new TrayPopupItemContainer( | 335 bubble_view_->child_at(view_count - 1) |
311 item_views[i], is_default_bubble, | 336 ->SetBorder(views::Border::NullBorder()); |
James Cook
2016/07/20 20:13:49
It seems a bit wasteful to create the last 2 items
bruthig
2016/07/21 14:34:58
Done.
| |
312 is_default_bubble && (i < item_views.size() - 2))); | 337 if (view_count > 2) { |
338 bubble_view_->child_at(view_count - 2) | |
339 ->SetBorder(views::Border::NullBorder()); | |
340 } | |
313 } | 341 } |
342 | |
314 if (focus_view) | 343 if (focus_view) |
315 focus_view->RequestFocus(); | 344 focus_view->RequestFocus(); |
316 } | 345 } |
317 | 346 |
318 } // namespace ash | 347 } // namespace ash |
OLD | NEW |