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

Side by Side Diff: ash/system/fractional_view/scale_view.cc

Issue 2849953004: SV Test
Patch Set: Created 3 years, 7 months 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/system/fractional_view/scale_view.h ('k') | ash/system/fractional_view/tray_scale.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/fractional_view/scale_view.h"
6
7 #include <algorithm>
8
9 #include "ash/resources/vector_icons/vector_icons.h"
10 #include "ash/shell.h"
11 #include "ash/shell_port.h"
12 #include "ash/strings/grit/ash_strings.h"
13 #include "ash/system/tray/actionable_view.h"
14 #include "ash/system/tray/system_tray_item.h"
15 #include "ash/system/tray/tray_constants.h"
16 #include "ash/system/tray/tray_popup_utils.h"
17 #include "ash/system/tray/tri_view.h"
18 #include "base/command_line.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "chromeos/audio/cras_audio_handler.h"
22 #include "ui/accessibility/ax_node_data.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/display/display.h"
25 #include "ui/display/display_switches.h"
26 #include "ui/display/manager/display_manager.h"
27 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/views/background.h"
29 #include "ui/views/border.h"
30 #include "ui/views/controls/button/custom_button.h"
31 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/label.h"
33 #include "ui/views/controls/slider.h"
34 #include "ui/views/layout/fill_layout.h"
35
36 using chromeos::CrasAudioHandler;
37
38 namespace ash {
39 namespace tray {
40 namespace {
41
42 std::string GetStringValue(double value) {
43 std::string str_value = base::DoubleToString(value);
44 if (str_value.length() > 4)
45 str_value.erase(str_value.begin() + 4, str_value.end());
46 return str_value;
47 }
48
49 } // namespace
50
51 ScaleView::ScaleView(SystemTrayItem* owner, bool is_default_view)
52 : owner_(owner),
53 tri_view_(TrayPopupUtils::CreateMultiTargetRowView()),
54 more_button_(nullptr),
55 label_(nullptr),
56 slider_(nullptr),
57 is_default_view_(is_default_view) {
58 SetLayoutManager(new views::FillLayout);
59 AddChildView(tri_view_);
60
61 label_ = new views::Label(base::UTF8ToUTF16(
62 GetStringValue(display::Display::GetForcedDeviceScaleFactor())));
63 tri_view_->AddView(TriView::Container::START, label_);
64
65 slider_ = TrayPopupUtils::CreateSlider(this);
66 slider_->SetValue((display::Display::GetForcedDeviceScaleFactor() - 1.f) / 2);
67 slider_->SetAccessibleName(
68 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VOLUME));
69 tri_view_->AddView(TriView::Container::CENTER, slider_);
70
71 // set_background(views::Background::CreateSolidBackground(kBackgroundColor));
72
73 if (!is_default_view_) {
74 tri_view_->SetContainerVisible(TriView::Container::END, false);
75 Update();
76 return;
77 }
78
79 more_button_ = new ButtonListenerActionableView(
80 owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this);
81 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
82
83 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
84 more_button_->SetBorder(
85 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupButtonEndMargin)));
86 tri_view_->AddView(TriView::Container::END, more_button_);
87
88 more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView());
89 more_button_->SetAccessibleName(
90 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO));
91 Update();
92 }
93
94 ScaleView::~ScaleView() {}
95
96 void ScaleView::Update() {
97 slider_->UpdateState(!CrasAudioHandler::Get()->IsOutputMuted());
98 Layout();
99 }
100
101 void ScaleView::ButtonPressed(views::Button* sender, const ui::Event& event) {
102 if (sender == more_button_)
103 owner_->TransitionDetailedView();
104 }
105
106 void ScaleView::SliderValueChanged(views::Slider* sender,
107 float value,
108 float old_value,
109 views::SliderChangeReason reason) {
110 if (reason == views::VALUE_CHANGED_BY_USER) {
111 float new_scale = 1.f + value * 2.0f;
112 std::string str_value = GetStringValue(new_scale);
113 label_->SetText(base::UTF8ToUTF16(str_value));
114 }
115 }
116
117 void ScaleView::SliderDragEnded(views::Slider* sender) {
118 display::Display::ResetForceDeviceScaleFactorForTesting();
119 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
120 switches::kForceDeviceScaleFactor,
121 GetStringValue(1.f + slider_->value() * 2.0f));
122 ash::Shell::Get()->display_manager()->UpdateDisplays();
123 }
124
125 } // namespace tray
126 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/fractional_view/scale_view.h ('k') | ash/system/fractional_view/tray_scale.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698