OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
tdanderson
2016/09/12 15:54:49
nit: in the CL description say that the change is
yiyix
2016/09/12 17:31:24
Done.
| |
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" | 9 #include "ash/common/ash_constants.h" |
10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
11 #include "ash/common/shell_observer.h" | 11 #include "ash/common/shell_observer.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
40 namespace { | 40 namespace { |
41 | 41 |
42 // We don't let the screen brightness go lower than this when it's being | 42 // 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 | 43 // 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 | 44 // brightness keys, they may turn the backlight off and not know how to turn it |
45 // back on. | 45 // back on. |
46 const double kMinBrightnessPercent = 5.0; | 46 const double kMinBrightnessPercent = 5.0; |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 // TODO(yiyix|tdanderson): Once Chrome OS material design is enabled by default, | |
51 // BrightnessView does not need to be a ShellObserver to observe touch view mode | |
52 // changes. See crbug.com/614453. | |
tdanderson
2016/09/12 15:54:49
Good catch, and thanks for add this TODO.
yiyix
2016/09/12 17:31:24
:) thanks
| |
50 class BrightnessView : public ShellObserver, | 53 class BrightnessView : public ShellObserver, |
51 public views::View, | 54 public views::View, |
52 public views::SliderListener { | 55 public views::SliderListener { |
53 public: | 56 public: |
54 BrightnessView(bool default_view, double initial_percent); | 57 BrightnessView(bool default_view, double initial_percent); |
55 ~BrightnessView() override; | 58 ~BrightnessView() override; |
56 | 59 |
57 bool is_default_view() const { return is_default_view_; } | 60 bool is_default_view() const { return is_default_view_; } |
58 | 61 |
59 // |percent| is in the range [0.0, 100.0]. | 62 // |percent| is in the range [0.0, 100.0]. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { | 119 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { |
117 slider_->SetBorder(views::Border::CreateEmptyBorder( | 120 slider_->SetBorder(views::Border::CreateEmptyBorder( |
118 gfx::Insets(0, kTrayPopupSliderPaddingMD) + slider_->GetInsets())); | 121 gfx::Insets(0, kTrayPopupSliderPaddingMD) + slider_->GetInsets())); |
119 } | 122 } |
120 slider_->set_focus_border_color(kFocusBorderColor); | 123 slider_->set_focus_border_color(kFocusBorderColor); |
121 slider_->SetValue(static_cast<float>(initial_percent / 100.0)); | 124 slider_->SetValue(static_cast<float>(initial_percent / 100.0)); |
122 slider_->SetAccessibleName( | 125 slider_->SetAccessibleName( |
123 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BRIGHTNESS)); | 126 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BRIGHTNESS)); |
124 AddChildView(slider_); | 127 AddChildView(slider_); |
125 | 128 |
126 if (is_default_view_) { | 129 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
127 WmShell::Get()->AddShellObserver(this); | 130 bool show_icon = !icon->GetImage().isNull(); |
tdanderson
2016/09/12 15:54:49
I don't think this check is necessary; you just be
yiyix
2016/09/12 17:31:24
Done.
| |
128 SetVisible(WmShell::Get() | 131 SetVisible(show_icon); |
129 ->maximize_mode_controller() | 132 } else { |
130 ->IsMaximizeModeWindowManagerEnabled()); | 133 if (is_default_view_) { |
134 WmShell::Get()->AddShellObserver(this); | |
135 SetVisible(WmShell::Get() | |
136 ->maximize_mode_controller() | |
137 ->IsMaximizeModeWindowManagerEnabled()); | |
138 } | |
131 } | 139 } |
132 } | 140 } |
133 | 141 |
134 BrightnessView::~BrightnessView() { | 142 BrightnessView::~BrightnessView() { |
135 if (is_default_view_) | 143 if (is_default_view_) |
136 WmShell::Get()->RemoveShellObserver(this); | 144 WmShell::Get()->RemoveShellObserver(this); |
137 } | 145 } |
138 | 146 |
139 void BrightnessView::SetBrightnessPercent(double percent) { | 147 void BrightnessView::SetBrightnessPercent(double percent) { |
140 last_percent_ = percent; | 148 last_percent_ = percent; |
141 if (!dragging_) | 149 if (!dragging_) |
142 slider_->SetValue(static_cast<float>(percent / 100.0)); | 150 slider_->SetValue(static_cast<float>(percent / 100.0)); |
143 } | 151 } |
144 | 152 |
145 void BrightnessView::OnMaximizeModeStarted() { | 153 void BrightnessView::OnMaximizeModeStarted() { |
146 SetVisible(true); | 154 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) |
155 SetVisible(true); | |
147 } | 156 } |
148 | 157 |
149 void BrightnessView::OnMaximizeModeEnded() { | 158 void BrightnessView::OnMaximizeModeEnded() { |
150 SetVisible(false); | 159 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) |
160 SetVisible(false); | |
151 } | 161 } |
152 | 162 |
153 void BrightnessView::OnBoundsChanged(const gfx::Rect& old_bounds) { | 163 void BrightnessView::OnBoundsChanged(const gfx::Rect& old_bounds) { |
154 int w = width() - slider_->x(); | 164 int w = width() - slider_->x(); |
155 slider_->SetSize(gfx::Size(w, slider_->height())); | 165 slider_->SetSize(gfx::Size(w, slider_->height())); |
156 } | 166 } |
157 | 167 |
158 void BrightnessView::SliderValueChanged(views::Slider* sender, | 168 void BrightnessView::SliderValueChanged(views::Slider* sender, |
159 float value, | 169 float value, |
160 float old_value, | 170 float old_value, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 if (!display::Display::HasInternalDisplay()) | 292 if (!display::Display::HasInternalDisplay()) |
283 return; | 293 return; |
284 | 294 |
285 if (brightness_view_) | 295 if (brightness_view_) |
286 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); | 296 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); |
287 else | 297 else |
288 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); | 298 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); |
289 } | 299 } |
290 | 300 |
291 } // namespace ash | 301 } // namespace ash |
OLD | NEW |