| 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/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/accelerators/accelerator_controller.h" | |
| 10 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
| 11 #include "ash/common/shell_observer.h" | 10 #include "ash/common/shell_observer.h" |
| 11 #include "ash/common/system/brightness_control_delegate.h" |
| 12 #include "ash/common/system/tray/fixed_sized_image_view.h" | 12 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
| 14 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
| 15 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 15 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 16 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 17 #include "ash/shell.h" | |
| 18 #include "ash/system/brightness_control_delegate.h" | |
| 19 #include "base/bind.h" | 17 #include "base/bind.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/power_manager_client.h" | 21 #include "chromeos/dbus/power_manager_client.h" |
| 24 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
| 25 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/display/display.h" | 25 #include "ui/display/display.h" |
| 28 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 slider_->SetSize(gfx::Size(w, slider_->height())); | 142 slider_->SetSize(gfx::Size(w, slider_->height())); |
| 145 } | 143 } |
| 146 | 144 |
| 147 void BrightnessView::SliderValueChanged(views::Slider* sender, | 145 void BrightnessView::SliderValueChanged(views::Slider* sender, |
| 148 float value, | 146 float value, |
| 149 float old_value, | 147 float old_value, |
| 150 views::SliderChangeReason reason) { | 148 views::SliderChangeReason reason) { |
| 151 DCHECK_EQ(sender, slider_); | 149 DCHECK_EQ(sender, slider_); |
| 152 if (reason != views::VALUE_CHANGED_BY_USER) | 150 if (reason != views::VALUE_CHANGED_BY_USER) |
| 153 return; | 151 return; |
| 154 AcceleratorController* ac = Shell::GetInstance()->accelerator_controller(); | 152 BrightnessControlDelegate* brightness_control_delegate = |
| 155 if (ac->brightness_control_delegate()) { | 153 WmShell::Get()->brightness_control_delegate(); |
| 154 if (brightness_control_delegate) { |
| 156 double percent = std::max(value * 100.0, kMinBrightnessPercent); | 155 double percent = std::max(value * 100.0, kMinBrightnessPercent); |
| 157 ac->brightness_control_delegate()->SetBrightnessPercent(percent, true); | 156 brightness_control_delegate->SetBrightnessPercent(percent, true); |
| 158 } | 157 } |
| 159 } | 158 } |
| 160 | 159 |
| 161 void BrightnessView::SliderDragStarted(views::Slider* slider) { | 160 void BrightnessView::SliderDragStarted(views::Slider* slider) { |
| 162 DCHECK_EQ(slider, slider_); | 161 DCHECK_EQ(slider, slider_); |
| 163 dragging_ = true; | 162 dragging_ = true; |
| 164 } | 163 } |
| 165 | 164 |
| 166 void BrightnessView::SliderDragEnded(views::Slider* slider) { | 165 void BrightnessView::SliderDragEnded(views::Slider* slider) { |
| 167 DCHECK_EQ(slider, slider_); | 166 DCHECK_EQ(slider, slider_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( | 184 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( |
| 186 this); | 185 this); |
| 187 } | 186 } |
| 188 | 187 |
| 189 TrayBrightness::~TrayBrightness() { | 188 TrayBrightness::~TrayBrightness() { |
| 190 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( | 189 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
| 191 this); | 190 this); |
| 192 } | 191 } |
| 193 | 192 |
| 194 void TrayBrightness::GetInitialBrightness() { | 193 void TrayBrightness::GetInitialBrightness() { |
| 195 BrightnessControlDelegate* delegate = Shell::GetInstance() | 194 BrightnessControlDelegate* brightness_control_delegate = |
| 196 ->accelerator_controller() | 195 WmShell::Get()->brightness_control_delegate(); |
| 197 ->brightness_control_delegate(); | |
| 198 // Worrisome, but happens in unit tests, so don't log anything. | 196 // Worrisome, but happens in unit tests, so don't log anything. |
| 199 if (!delegate) | 197 if (!brightness_control_delegate) |
| 200 return; | 198 return; |
| 201 delegate->GetBrightnessPercent( | 199 brightness_control_delegate->GetBrightnessPercent( |
| 202 base::Bind(&TrayBrightness::HandleInitialBrightness, | 200 base::Bind(&TrayBrightness::HandleInitialBrightness, |
| 203 weak_ptr_factory_.GetWeakPtr())); | 201 weak_ptr_factory_.GetWeakPtr())); |
| 204 } | 202 } |
| 205 | 203 |
| 206 void TrayBrightness::HandleInitialBrightness(double percent) { | 204 void TrayBrightness::HandleInitialBrightness(double percent) { |
| 207 if (!got_current_percent_) | 205 if (!got_current_percent_) |
| 208 HandleBrightnessChanged(percent, false); | 206 HandleBrightnessChanged(percent, false); |
| 209 } | 207 } |
| 210 | 208 |
| 211 views::View* TrayBrightness::CreateTrayView(LoginStatus status) { | 209 views::View* TrayBrightness::CreateTrayView(LoginStatus status) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 if (!display::Display::HasInternalDisplay()) | 269 if (!display::Display::HasInternalDisplay()) |
| 272 return; | 270 return; |
| 273 | 271 |
| 274 if (brightness_view_) | 272 if (brightness_view_) |
| 275 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 273 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
| 276 else | 274 else |
| 277 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 275 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
| 278 } | 276 } |
| 279 | 277 |
| 280 } // namespace ash | 278 } // namespace ash |
| OLD | NEW |