Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/brightness/tray_brightness.h" | 5 #include "ash/common/system/chromeos/brightness/tray_brightness.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/ash_constants.h" | |
| 10 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/shell_observer.h" | 10 #include "ash/common/shell_observer.h" |
| 12 #include "ash/common/system/brightness_control_delegate.h" | 11 #include "ash/common/system/brightness_control_delegate.h" |
| 13 #include "ash/common/system/tray/fixed_sized_image_view.h" | |
| 14 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 15 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 14 #include "ash/common/system/tray/tri_view.h" | |
| 16 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 15 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 17 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 18 #include "ash/resources/vector_icons/vector_icons.h" | 17 #include "ash/resources/vector_icons/vector_icons.h" |
| 19 #include "base/bind.h" | 18 #include "base/bind.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/power_manager_client.h" | 22 #include "chromeos/dbus/power_manager_client.h" |
| 24 #include "grit/ash_resources.h" | 23 #include "grit/ash_resources.h" |
| 25 #include "grit/ash_strings.h" | 24 #include "grit/ash_strings.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/display/display.h" | 26 #include "ui/display/display.h" |
| 28 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 29 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
| 30 #include "ui/views/border.h" | |
| 31 #include "ui/views/controls/button/image_button.h" | |
| 32 #include "ui/views/controls/image_view.h" | 29 #include "ui/views/controls/image_view.h" |
| 33 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
| 34 #include "ui/views/controls/slider.h" | 31 #include "ui/views/controls/slider.h" |
| 35 #include "ui/views/layout/box_layout.h" | 32 #include "ui/views/layout/fill_layout.h" |
| 36 #include "ui/views/view.h" | 33 #include "ui/views/view.h" |
| 37 | 34 |
| 38 namespace ash { | 35 namespace ash { |
| 39 namespace tray { | 36 namespace tray { |
| 40 namespace { | 37 namespace { |
| 41 | 38 |
| 42 // We don't let the screen brightness go lower than this when it's being | 39 // We don't let the screen brightness go lower than this when it's being |
| 43 // adjusted via the slider. Otherwise, if the user doesn't know about the | 40 // adjusted via the slider. Otherwise, if the user doesn't know about the |
| 44 // brightness keys, they may turn the backlight off and not know how to turn it | 41 // brightness keys, they may turn the backlight off and not know how to turn it |
| 45 // back on. | 42 // back on. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // Last brightness level that we observed, in the range [0.0, 100.0]. | 89 // Last brightness level that we observed, in the range [0.0, 100.0]. |
| 93 double last_percent_; | 90 double last_percent_; |
| 94 | 91 |
| 95 DISALLOW_COPY_AND_ASSIGN(BrightnessView); | 92 DISALLOW_COPY_AND_ASSIGN(BrightnessView); |
| 96 }; | 93 }; |
| 97 | 94 |
| 98 BrightnessView::BrightnessView(bool default_view, double initial_percent) | 95 BrightnessView::BrightnessView(bool default_view, double initial_percent) |
| 99 : dragging_(false), | 96 : dragging_(false), |
| 100 is_default_view_(default_view), | 97 is_default_view_(default_view), |
| 101 last_percent_(initial_percent) { | 98 last_percent_(initial_percent) { |
| 102 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 99 SetLayoutManager(new views::FillLayout); |
| 103 kTrayPopupPaddingHorizontal, 0, | 100 // Use CreateMultiTargetRowView() instead of CreateDefaultRowView() because |
| 104 kTrayPopupPaddingBetweenItems)); | 101 // that's what the audio row uses and we want the two rows to layout the same. |
|
tdanderson
2016/11/09 01:38:33
I interpret this as "the sliders should be the sam
bruthig
2016/11/10 02:54:54
Done.
| |
| 102 TriView* tri_view = TrayPopupUtils::CreateMultiTargetRowView(); | |
| 103 AddChildView(tri_view); | |
| 105 | 104 |
| 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 105 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 107 views::ImageView* icon = | 106 views::ImageView* icon = TrayPopupUtils::CreateMainImageView(); |
| 108 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
| 109 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 107 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 110 icon->SetImage( | 108 icon->SetImage( |
| 111 gfx::CreateVectorIcon(kSystemMenuBrightnessIcon, kMenuIconColor)); | 109 gfx::CreateVectorIcon(kSystemMenuBrightnessIcon, kMenuIconColor)); |
| 112 } else { | 110 } else { |
| 113 icon->SetImage( | 111 icon->SetImage( |
| 114 rb.GetImageNamed(IDR_AURA_UBER_TRAY_BRIGHTNESS).ToImageSkia()); | 112 rb.GetImageNamed(IDR_AURA_UBER_TRAY_BRIGHTNESS).ToImageSkia()); |
| 115 } | 113 } |
| 116 AddChildView(icon); | 114 tri_view->AddView(TriView::Container::START, icon); |
| 117 slider_ = views::Slider::CreateSlider( | 115 |
| 118 ash::MaterialDesignController::IsSystemTrayMenuMaterial(), this); | 116 slider_ = TrayPopupUtils::CreateSlider(this); |
| 119 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { | |
| 120 slider_->SetBorder(views::CreateEmptyBorder( | |
| 121 gfx::Insets(0, kTrayPopupSliderPaddingMD) + slider_->GetInsets())); | |
| 122 } | |
| 123 slider_->set_focus_border_color(kFocusBorderColor); | |
| 124 slider_->SetValue(static_cast<float>(initial_percent / 100.0)); | 117 slider_->SetValue(static_cast<float>(initial_percent / 100.0)); |
| 125 slider_->SetAccessibleName( | 118 slider_->SetAccessibleName( |
| 126 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BRIGHTNESS)); | 119 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BRIGHTNESS)); |
| 127 AddChildView(slider_); | 120 tri_view->AddView(TriView::Container::CENTER, slider_); |
| 128 | 121 |
| 129 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 122 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 130 SetVisible(true); | 123 SetVisible(true); |
| 131 } else { | 124 } else { |
| 132 if (is_default_view_) { | 125 if (is_default_view_) { |
| 133 WmShell::Get()->AddShellObserver(this); | 126 WmShell::Get()->AddShellObserver(this); |
| 134 SetVisible(WmShell::Get() | 127 SetVisible(WmShell::Get() |
| 135 ->maximize_mode_controller() | 128 ->maximize_mode_controller() |
| 136 ->IsMaximizeModeWindowManagerEnabled()); | 129 ->IsMaximizeModeWindowManagerEnabled()); |
| 137 } | 130 } |
| 138 } | 131 } |
| 132 | |
| 133 if (!is_default_view_) | |
| 134 tri_view->SetContainerVisible(TriView::Container::END, false); | |
| 139 } | 135 } |
| 140 | 136 |
| 141 BrightnessView::~BrightnessView() { | 137 BrightnessView::~BrightnessView() { |
| 142 if (is_default_view_) | 138 if (is_default_view_) |
| 143 WmShell::Get()->RemoveShellObserver(this); | 139 WmShell::Get()->RemoveShellObserver(this); |
| 144 } | 140 } |
| 145 | 141 |
| 146 void BrightnessView::SetBrightnessPercent(double percent) { | 142 void BrightnessView::SetBrightnessPercent(double percent) { |
| 147 last_percent_ = percent; | 143 last_percent_ = percent; |
| 148 if (!dragging_) | 144 if (!dragging_) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 if (!display::Display::HasInternalDisplay()) | 287 if (!display::Display::HasInternalDisplay()) |
| 292 return; | 288 return; |
| 293 | 289 |
| 294 if (brightness_view_) | 290 if (brightness_view_) |
| 295 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 291 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
| 296 else | 292 else |
| 297 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 293 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
| 298 } | 294 } |
| 299 | 295 |
| 300 } // namespace ash | 296 } // namespace ash |
| OLD | NEW |