Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: ash/common/system/chromeos/brightness/tray_brightness.cc

Issue 2482043002: [ash-md] Updated layout of Brightness and Audio system menu rows to the material design spec. (Closed)
Patch Set: Fixed the volume slider to transition to the detailed view on <return> keypress. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/audio/volume_view.cc ('k') | ash/common/system/tray/actionable_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 with the
102 // same insets.
103 TriView* tri_view = TrayPopupUtils::CreateMultiTargetRowView();
104 AddChildView(tri_view);
105 105
106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
107 views::ImageView* icon = 107 views::ImageView* icon = TrayPopupUtils::CreateMainImageView();
108 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
109 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 108 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
110 icon->SetImage( 109 icon->SetImage(
111 gfx::CreateVectorIcon(kSystemMenuBrightnessIcon, kMenuIconColor)); 110 gfx::CreateVectorIcon(kSystemMenuBrightnessIcon, kMenuIconColor));
112 } else { 111 } else {
113 icon->SetImage( 112 icon->SetImage(
114 rb.GetImageNamed(IDR_AURA_UBER_TRAY_BRIGHTNESS).ToImageSkia()); 113 rb.GetImageNamed(IDR_AURA_UBER_TRAY_BRIGHTNESS).ToImageSkia());
115 } 114 }
116 AddChildView(icon); 115 tri_view->AddView(TriView::Container::START, icon);
117 slider_ = views::Slider::CreateSlider( 116
118 ash::MaterialDesignController::IsSystemTrayMenuMaterial(), this); 117 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)); 118 slider_->SetValue(static_cast<float>(initial_percent / 100.0));
125 slider_->SetAccessibleName( 119 slider_->SetAccessibleName(
126 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BRIGHTNESS)); 120 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BRIGHTNESS));
127 AddChildView(slider_); 121 tri_view->AddView(TriView::Container::CENTER, slider_);
128 122
129 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 123 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
130 SetVisible(true); 124 SetVisible(true);
131 } else { 125 } else {
132 if (is_default_view_) { 126 if (is_default_view_) {
133 WmShell::Get()->AddShellObserver(this); 127 WmShell::Get()->AddShellObserver(this);
134 SetVisible(WmShell::Get() 128 SetVisible(WmShell::Get()
135 ->maximize_mode_controller() 129 ->maximize_mode_controller()
136 ->IsMaximizeModeWindowManagerEnabled()); 130 ->IsMaximizeModeWindowManagerEnabled());
137 } 131 }
138 } 132 }
133
134 if (!is_default_view_)
135 tri_view->SetContainerVisible(TriView::Container::END, false);
139 } 136 }
140 137
141 BrightnessView::~BrightnessView() { 138 BrightnessView::~BrightnessView() {
142 if (is_default_view_) 139 if (is_default_view_)
143 WmShell::Get()->RemoveShellObserver(this); 140 WmShell::Get()->RemoveShellObserver(this);
144 } 141 }
145 142
146 void BrightnessView::SetBrightnessPercent(double percent) { 143 void BrightnessView::SetBrightnessPercent(double percent) {
147 last_percent_ = percent; 144 last_percent_ = percent;
148 if (!dragging_) 145 if (!dragging_)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 if (!display::Display::HasInternalDisplay()) 288 if (!display::Display::HasInternalDisplay())
292 return; 289 return;
293 290
294 if (brightness_view_) 291 if (brightness_view_)
295 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds); 292 SetDetailedViewCloseDelay(kTrayPopupAutoCloseDelayInSeconds);
296 else 293 else
297 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false); 294 PopupDetailedView(kTrayPopupAutoCloseDelayInSeconds, false);
298 } 295 }
299 296
300 } // namespace ash 297 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/audio/volume_view.cc ('k') | ash/common/system/tray/actionable_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698