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

Unified Diff: ash/system/fractional_view/scale_view.cc

Issue 2849953004: SV Test
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/fractional_view/scale_view.cc
diff --git a/ash/system/fractional_view/scale_view.cc b/ash/system/fractional_view/scale_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..230a8eb3819e1227aebadb1f93773b85290465f2
--- /dev/null
+++ b/ash/system/fractional_view/scale_view.cc
@@ -0,0 +1,126 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/fractional_view/scale_view.h"
+
+#include <algorithm>
+
+#include "ash/resources/vector_icons/vector_icons.h"
+#include "ash/shell.h"
+#include "ash/shell_port.h"
+#include "ash/strings/grit/ash_strings.h"
+#include "ash/system/tray/actionable_view.h"
+#include "ash/system/tray/system_tray_item.h"
+#include "ash/system/tray/tray_constants.h"
+#include "ash/system/tray/tray_popup_utils.h"
+#include "ash/system/tray/tri_view.h"
+#include "base/command_line.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chromeos/audio/cras_audio_handler.h"
+#include "ui/accessibility/ax_node_data.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/display/display.h"
+#include "ui/display/display_switches.h"
+#include "ui/display/manager/display_manager.h"
+#include "ui/gfx/paint_vector_icon.h"
+#include "ui/views/background.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/button/custom_button.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/controls/slider.h"
+#include "ui/views/layout/fill_layout.h"
+
+using chromeos::CrasAudioHandler;
+
+namespace ash {
+namespace tray {
+namespace {
+
+std::string GetStringValue(double value) {
+ std::string str_value = base::DoubleToString(value);
+ if (str_value.length() > 4)
+ str_value.erase(str_value.begin() + 4, str_value.end());
+ return str_value;
+}
+
+} // namespace
+
+ScaleView::ScaleView(SystemTrayItem* owner, bool is_default_view)
+ : owner_(owner),
+ tri_view_(TrayPopupUtils::CreateMultiTargetRowView()),
+ more_button_(nullptr),
+ label_(nullptr),
+ slider_(nullptr),
+ is_default_view_(is_default_view) {
+ SetLayoutManager(new views::FillLayout);
+ AddChildView(tri_view_);
+
+ label_ = new views::Label(base::UTF8ToUTF16(
+ GetStringValue(display::Display::GetForcedDeviceScaleFactor())));
+ tri_view_->AddView(TriView::Container::START, label_);
+
+ slider_ = TrayPopupUtils::CreateSlider(this);
+ slider_->SetValue((display::Display::GetForcedDeviceScaleFactor() - 1.f) / 2);
+ slider_->SetAccessibleName(
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VOLUME));
+ tri_view_->AddView(TriView::Container::CENTER, slider_);
+
+ // set_background(views::Background::CreateSolidBackground(kBackgroundColor));
+
+ if (!is_default_view_) {
+ tri_view_->SetContainerVisible(TriView::Container::END, false);
+ Update();
+ return;
+ }
+
+ more_button_ = new ButtonListenerActionableView(
+ owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this);
+ TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
+
+ more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
+ more_button_->SetBorder(
+ views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupButtonEndMargin)));
+ tri_view_->AddView(TriView::Container::END, more_button_);
+
+ more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView());
+ more_button_->SetAccessibleName(
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO));
+ Update();
+}
+
+ScaleView::~ScaleView() {}
+
+void ScaleView::Update() {
+ slider_->UpdateState(!CrasAudioHandler::Get()->IsOutputMuted());
+ Layout();
+}
+
+void ScaleView::ButtonPressed(views::Button* sender, const ui::Event& event) {
+ if (sender == more_button_)
+ owner_->TransitionDetailedView();
+}
+
+void ScaleView::SliderValueChanged(views::Slider* sender,
+ float value,
+ float old_value,
+ views::SliderChangeReason reason) {
+ if (reason == views::VALUE_CHANGED_BY_USER) {
+ float new_scale = 1.f + value * 2.0f;
+ std::string str_value = GetStringValue(new_scale);
+ label_->SetText(base::UTF8ToUTF16(str_value));
+ }
+}
+
+void ScaleView::SliderDragEnded(views::Slider* sender) {
+ display::Display::ResetForceDeviceScaleFactorForTesting();
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kForceDeviceScaleFactor,
+ GetStringValue(1.f + slider_->value() * 2.0f));
+ ash::Shell::Get()->display_manager()->UpdateDisplays();
+}
+
+} // namespace tray
+} // namespace ash
« 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