| 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> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/material_design/material_design_controller.h" | |
| 11 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
| 13 #include "ash/common/system/tray/system_tray_item.h" | 12 #include "ash/common/system/tray/system_tray_item.h" |
| 14 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 13 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 15 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
| 16 #include "ash/common/system/tray/tray_popup_item_container.h" | |
| 17 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
| 18 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 21 #include "ui/compositor/layer_animation_observer.h" | 19 #include "ui/compositor/layer_animation_observer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 20 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 24 #include "ui/views/border.h" | 22 #include "ui/views/border.h" |
| 25 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
| 26 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 tray_item_view_map_) { | 286 tray_item_view_map_) { |
| 289 if (pair.second->visible() && | 287 if (pair.second->visible() && |
| 290 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { | 288 pair.first != SystemTrayItem::UMA_NOT_RECORDED) { |
| 291 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", | 289 UMA_HISTOGRAM_ENUMERATION("Ash.SystemMenu.DefaultView.VisibleRows", |
| 292 pair.first, SystemTrayItem::UMA_COUNT); | 290 pair.first, SystemTrayItem::UMA_COUNT); |
| 293 } | 291 } |
| 294 } | 292 } |
| 295 } | 293 } |
| 296 | 294 |
| 297 void SystemTrayBubble::UpdateBottomPadding() { | 295 void SystemTrayBubble::UpdateBottomPadding() { |
| 298 if (bubble_type_ == BUBBLE_TYPE_DEFAULT && | 296 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) |
| 299 MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 300 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); | 297 bubble_view_->SetBottomPadding(kDefaultViewBottomPadding); |
| 301 } else { | 298 else |
| 302 bubble_view_->SetBottomPadding(0); | 299 bubble_view_->SetBottomPadding(0); |
| 303 } | |
| 304 } | 300 } |
| 305 | 301 |
| 306 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { | 302 void SystemTrayBubble::CreateItemViews(LoginStatus login_status) { |
| 307 tray_item_view_map_.clear(); | 303 tray_item_view_map_.clear(); |
| 308 | 304 |
| 309 // If a system modal dialog is present, create the same tray as | 305 // If a system modal dialog is present, create the same tray as |
| 310 // in locked state. | 306 // in locked state. |
| 311 if (WmShell::Get()->IsSystemModalWindowOpen() && | 307 if (WmShell::Get()->IsSystemModalWindowOpen() && |
| 312 login_status != LoginStatus::NOT_LOGGED_IN) { | 308 login_status != LoginStatus::NOT_LOGGED_IN) { |
| 313 login_status = LoginStatus::LOCKED; | 309 login_status = LoginStatus::LOCKED; |
| 314 } | 310 } |
| 315 | 311 |
| 316 std::vector<TrayPopupItemContainer*> item_containers; | |
| 317 views::View* focus_view = nullptr; | 312 views::View* focus_view = nullptr; |
| 318 const bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; | |
| 319 for (size_t i = 0; i < items_.size(); ++i) { | 313 for (size_t i = 0; i < items_.size(); ++i) { |
| 320 views::View* item_view = nullptr; | 314 views::View* item_view = nullptr; |
| 321 switch (bubble_type_) { | 315 switch (bubble_type_) { |
| 322 case BUBBLE_TYPE_DEFAULT: | 316 case BUBBLE_TYPE_DEFAULT: |
| 323 item_view = items_[i]->CreateDefaultView(login_status); | 317 item_view = items_[i]->CreateDefaultView(login_status); |
| 324 if (items_[i]->restore_focus()) | 318 if (items_[i]->restore_focus()) |
| 325 focus_view = item_view; | 319 focus_view = item_view; |
| 326 break; | 320 break; |
| 327 case BUBBLE_TYPE_DETAILED: | 321 case BUBBLE_TYPE_DETAILED: |
| 328 item_view = items_[i]->CreateDetailedView(login_status); | 322 item_view = items_[i]->CreateDetailedView(login_status); |
| 329 break; | 323 break; |
| 330 } | 324 } |
| 331 if (item_view) { | 325 if (item_view) { |
| 332 TrayPopupItemContainer* tray_popup_item_container = | 326 bubble_view_->AddChildView(item_view); |
| 333 new TrayPopupItemContainer( | 327 tray_item_view_map_[items_[i]->uma_type()] = item_view; |
| 334 item_view, | |
| 335 is_default_bubble && | |
| 336 !MaterialDesignController::IsSystemTrayMenuMaterial()); | |
| 337 bubble_view_->AddChildView(tray_popup_item_container); | |
| 338 item_containers.push_back(tray_popup_item_container); | |
| 339 tray_item_view_map_[items_[i]->uma_type()] = tray_popup_item_container; | |
| 340 } | 328 } |
| 341 } | 329 } |
| 342 | 330 |
| 343 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 344 // For default view, draw bottom border for each item, except the last | |
| 345 // 2 items, which are the bottom header row and the one just above it. | |
| 346 if (is_default_bubble) { | |
| 347 const int last_item_with_border = | |
| 348 static_cast<int>(item_containers.size()) - 2; | |
| 349 for (int i = 0; i < last_item_with_border; ++i) { | |
| 350 item_containers.at(i)->SetBorder( | |
| 351 views::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor)); | |
| 352 } | |
| 353 } | |
| 354 } | |
| 355 | |
| 356 if (focus_view) { | 331 if (focus_view) { |
| 357 tray_->ActivateBubble(); | 332 tray_->ActivateBubble(); |
| 358 focus_view->RequestFocus(); | 333 focus_view->RequestFocus(); |
| 359 } | 334 } |
| 360 } | 335 } |
| 361 | 336 |
| 362 } // namespace ash | 337 } // namespace ash |
| OLD | NEW |