| 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/chromeos/power/power_status_view.h" | 5 #include "ash/common/system/chromeos/power/power_status_view.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/chromeos/power/power_status.h" | 8 #include "ash/common/system/chromeos/power/power_status.h" |
| 9 #include "ash/common/system/chromeos/power/tray_power.h" | 9 #include "ash/common/system/chromeos/power/tray_power.h" |
| 10 #include "ash/common/system/tray/fixed_sized_image_view.h" | 10 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace ash { | 26 namespace ash { |
| 27 | 27 |
| 28 // Padding between battery status text and battery icon on default view. | 28 // Padding between battery status text and battery icon on default view. |
| 29 const int kPaddingBetweenBatteryStatusAndIcon = 3; | 29 const int kPaddingBetweenBatteryStatusAndIcon = 3; |
| 30 | 30 |
| 31 PowerStatusView::PowerStatusView(bool default_view_right_align) | 31 PowerStatusView::PowerStatusView(bool default_view_right_align) |
| 32 : default_view_right_align_(default_view_right_align), | 32 : default_view_right_align_(default_view_right_align), |
| 33 percentage_label_(new views::Label), | 33 percentage_label_(new views::Label), |
| 34 separator_label_(new views::Label), | 34 separator_label_(new views::Label), |
| 35 time_status_label_(new views::Label), | 35 time_status_label_(new views::Label) { |
| 36 icon_(nullptr) { | |
| 37 if (MaterialDesignController::IsSystemTrayMenuMaterial()) | 36 if (MaterialDesignController::IsSystemTrayMenuMaterial()) |
| 38 SetFocusBehavior(FocusBehavior::ALWAYS); | 37 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 39 | 38 |
| 40 percentage_label_->SetEnabledColor(kHeaderTextColorNormal); | 39 percentage_label_->SetEnabledColor(kHeaderTextColorNormal); |
| 41 separator_label_->SetEnabledColor(kHeaderTextColorNormal); | 40 separator_label_->SetEnabledColor(kHeaderTextColorNormal); |
| 42 separator_label_->SetText(base::ASCIIToUTF16(" - ")); | 41 separator_label_->SetText(base::ASCIIToUTF16(" - ")); |
| 43 LayoutView(); | 42 LayoutView(); |
| 44 PowerStatus::Get()->AddObserver(this); | 43 PowerStatus::Get()->AddObserver(this); |
| 45 OnPowerStatusChanged(); | 44 OnPowerStatusChanged(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 PowerStatusView::~PowerStatusView() { | 47 PowerStatusView::~PowerStatusView() { |
| 49 PowerStatus::Get()->RemoveObserver(this); | 48 PowerStatus::Get()->RemoveObserver(this); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void PowerStatusView::OnPowerStatusChanged() { | 51 void PowerStatusView::OnPowerStatusChanged() { |
| 53 UpdateText(); | 52 UpdateText(); |
| 54 | |
| 55 // We do not show a battery icon in the material design system menu. | |
| 56 // TODO(tdanderson): Remove the non-MD code and the IconSet enum once | |
| 57 // material design is enabled by default. See crbug.com/614453. | |
| 58 if (MaterialDesignController::UseMaterialDesignSystemIcons()) | |
| 59 return; | |
| 60 | |
| 61 const PowerStatus::BatteryImageInfo info = | |
| 62 PowerStatus::Get()->GetBatteryImageInfo(PowerStatus::ICON_DARK); | |
| 63 if (info != previous_battery_image_info_) { | |
| 64 icon_->SetImage(PowerStatus::Get()->GetBatteryImage(info)); | |
| 65 icon_->SetVisible(true); | |
| 66 previous_battery_image_info_ = info; | |
| 67 } | |
| 68 } | 53 } |
| 69 | 54 |
| 70 void PowerStatusView::LayoutView() { | 55 void PowerStatusView::LayoutView() { |
| 71 if (default_view_right_align_) { | 56 if (default_view_right_align_) { |
| 72 views::BoxLayout* layout = | 57 views::BoxLayout* layout = |
| 73 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 58 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
| 74 kPaddingBetweenBatteryStatusAndIcon); | 59 kPaddingBetweenBatteryStatusAndIcon); |
| 75 SetLayoutManager(layout); | 60 SetLayoutManager(layout); |
| 76 | 61 |
| 77 AddChildView(percentage_label_); | 62 AddChildView(percentage_label_); |
| 78 AddChildView(separator_label_); | 63 AddChildView(separator_label_); |
| 79 AddChildView(time_status_label_); | 64 AddChildView(time_status_label_); |
| 80 | 65 AddChildView(new views::ImageView); |
| 81 icon_ = new views::ImageView; | |
| 82 AddChildView(icon_); | |
| 83 | 66 |
| 84 return; | 67 return; |
| 85 } | 68 } |
| 86 | 69 |
| 87 // TODO(tdanderson): Tweak padding values for material design. | 70 // TODO(tdanderson): Tweak padding values for material design. |
| 88 const bool material_design = | 71 const bool material_design = |
| 89 MaterialDesignController::IsSystemTrayMenuMaterial(); | 72 MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 90 views::BoxLayout* layout = new views::BoxLayout( | 73 views::BoxLayout* layout = new views::BoxLayout( |
| 91 views::BoxLayout::kHorizontal, material_design ? 12 : 0, 0, | 74 views::BoxLayout::kHorizontal, material_design ? 12 : 0, 0, |
| 92 kTrayPopupPaddingBetweenItems); | 75 kTrayPopupPaddingBetweenItems); |
| 93 SetLayoutManager(layout); | 76 SetLayoutManager(layout); |
| 94 | 77 |
| 95 if (!material_design) { | 78 if (!material_design) |
| 96 icon_ = TrayPopupUtils::CreateMainImageView(); | 79 AddChildView(TrayPopupUtils::CreateMainImageView()); |
| 97 AddChildView(icon_); | |
| 98 } | |
| 99 | 80 |
| 100 AddChildView(percentage_label_); | 81 AddChildView(percentage_label_); |
| 101 AddChildView(separator_label_); | 82 AddChildView(separator_label_); |
| 102 AddChildView(time_status_label_); | 83 AddChildView(time_status_label_); |
| 103 } | 84 } |
| 104 | 85 |
| 105 void PowerStatusView::UpdateText() { | 86 void PowerStatusView::UpdateText() { |
| 106 const PowerStatus& status = *PowerStatus::Get(); | 87 const PowerStatus& status = *PowerStatus::Get(); |
| 107 base::string16 battery_percentage; | 88 base::string16 battery_percentage; |
| 108 base::string16 battery_time_status; | 89 base::string16 battery_time_status; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 152 |
| 172 void PowerStatusView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 153 void PowerStatusView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 173 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) | 154 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) |
| 174 return; | 155 return; |
| 175 | 156 |
| 176 node_data->role = ui::AX_ROLE_LABEL_TEXT; | 157 node_data->role = ui::AX_ROLE_LABEL_TEXT; |
| 177 node_data->SetName(accessible_name_); | 158 node_data->SetName(accessible_name_); |
| 178 } | 159 } |
| 179 | 160 |
| 180 } // namespace ash | 161 } // namespace ash |
| OLD | NEW |