| 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) |
| 284 return; |
| 285 |
| 286 for (const std::pair<SystemTrayItem::UmaType, views::View*>& pair : |
| 287 tray_item_view_map_) { |
| 288 if (pair.second->visible() && |
| 289 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { |
| 290 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", |
| 291 pair.first, SystemTrayItem::UMA_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 std::vector<TrayPopupItemContainer*> item_containers; |
| 307 views::View* focus_view = nullptr; |
| 308 const bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; |
| 287 for (size_t i = 0; i < items_.size(); ++i) { | 309 for (size_t i = 0; i < items_.size(); ++i) { |
| 288 views::View* view = NULL; | 310 views::View* item_view = nullptr; |
| 289 switch (bubble_type_) { | 311 switch (bubble_type_) { |
| 290 case BUBBLE_TYPE_DEFAULT: | 312 case BUBBLE_TYPE_DEFAULT: |
| 291 view = items_[i]->CreateDefaultView(login_status); | 313 item_view = items_[i]->CreateDefaultView(login_status); |
| 292 if (items_[i]->restore_focus()) | 314 if (items_[i]->restore_focus()) |
| 293 focus_view = view; | 315 focus_view = item_view; |
| 294 break; | 316 break; |
| 295 case BUBBLE_TYPE_DETAILED: | 317 case BUBBLE_TYPE_DETAILED: |
| 296 view = items_[i]->CreateDetailedView(login_status); | 318 item_view = items_[i]->CreateDetailedView(login_status); |
| 297 break; | 319 break; |
| 298 case BUBBLE_TYPE_NOTIFICATION: | 320 case BUBBLE_TYPE_NOTIFICATION: |
| 299 view = items_[i]->CreateNotificationView(login_status); | 321 item_view = items_[i]->CreateNotificationView(login_status); |
| 300 break; | 322 break; |
| 301 } | 323 } |
| 302 if (view) | 324 if (item_view) { |
| 303 item_views.push_back(view); | 325 TrayPopupItemContainer* tray_popup_item_container = |
| 326 new TrayPopupItemContainer(item_view, is_default_bubble); |
| 327 bubble_view_->AddChildView(tray_popup_item_container); |
| 328 item_containers.push_back(tray_popup_item_container); |
| 329 tray_item_view_map_[items_[i]->uma_type()] = tray_popup_item_container; |
| 330 } |
| 304 } | 331 } |
| 305 | 332 |
| 306 bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; | 333 // For default view, draw bottom border for each item, except the last |
| 307 for (size_t i = 0; i < item_views.size(); ++i) { | 334 // 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 | 335 if (is_default_bubble) { |
| 309 // 2 items, which are the bottom header row and the one just above it. | 336 const int last_item_with_border = |
| 310 bubble_view_->AddChildView(new TrayPopupItemContainer( | 337 static_cast<int>(item_containers.size()) - 2; |
| 311 item_views[i], is_default_bubble, | 338 for (int i = 0; i < last_item_with_border; ++i) |
| 312 is_default_bubble && (i < item_views.size() - 2))); | 339 item_containers.at(i)->SetDrawBorder(true); |
| 313 } | 340 } |
| 341 |
| 314 if (focus_view) | 342 if (focus_view) |
| 315 focus_view->RequestFocus(); | 343 focus_view->RequestFocus(); |
| 316 } | 344 } |
| 317 | 345 |
| 318 } // namespace ash | 346 } // namespace ash |
| OLD | NEW |