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

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

Issue 2855143004: Implements a display scale tray setting behind a chrome switch (Closed)
Patch Set: Sync with ToT 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/display_scale/scale_view.h ('k') | ash/system/display_scale/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/display_scale/scale_view.h"
6
7 #include <algorithm>
8
9 #include "ash/shell.h"
10 #include "ash/strings/grit/ash_strings.h"
11 #include "ash/system/tray/actionable_view.h"
12 #include "ash/system/tray/system_tray_item.h"
13 #include "ash/system/tray/tray_constants.h"
14 #include "ash/system/tray/tray_popup_utils.h"
15 #include "ash/system/tray/tri_view.h"
16 #include "base/command_line.h"
17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/display/display.h"
21 #include "ui/display/manager/display_manager.h"
22 #include "ui/native_theme/native_theme.h"
23 #include "ui/views/background.h"
24 #include "ui/views/border.h"
25 #include "ui/views/controls/image_view.h"
26 #include "ui/views/controls/label.h"
27 #include "ui/views/controls/slider.h"
28 #include "ui/views/layout/fill_layout.h"
29
30 namespace ash {
31 namespace tray {
32
33 ScaleView::ScaleView(SystemTrayItem* owner, bool is_default_view)
34 : owner_(owner),
35 tri_view_(TrayPopupUtils::CreateMultiTargetRowView()),
36 more_button_(nullptr),
37 label_(nullptr),
38 slider_(nullptr),
39 is_default_view_(is_default_view) {
40 SetLayoutManager(new views::FillLayout);
41 AddChildView(tri_view_);
42
43 label_ = new views::Label(base::UTF8ToUTF16(base::StringPrintf(
44 "%.2f", display::Display::GetForcedDeviceScaleFactor())));
45 tri_view_->AddView(TriView::Container::START, label_);
46
47 slider_ = TrayPopupUtils::CreateSlider(this);
48 slider_->SetValue((display::Display::GetForcedDeviceScaleFactor() - 1.f) / 2);
49 slider_->SetAccessibleName(
50 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCALE_SLIDER));
51 tri_view_->AddView(TriView::Container::CENTER, slider_);
52
53 set_background(views::Background::CreateThemedSolidBackground(
54 this, ui::NativeTheme::kColorId_BubbleBackground));
55
56 if (!is_default_view_) {
57 tri_view_->SetContainerVisible(TriView::Container::END, false);
58 Layout();
59 return;
60 }
61
62 more_button_ = new ButtonListenerActionableView(
63 owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this);
64 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_);
65
66 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON);
67 more_button_->SetBorder(
68 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupButtonEndMargin)));
69 tri_view_->AddView(TriView::Container::END, more_button_);
70
71 more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView());
72 more_button_->SetAccessibleName(
73 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCALE));
74 Layout();
75 }
76
77 ScaleView::~ScaleView() {}
78
79 void ScaleView::ButtonPressed(views::Button* sender, const ui::Event& event) {
80 if (sender == more_button_)
81 owner_->TransitionDetailedView();
82 }
83
84 void ScaleView::SliderValueChanged(views::Slider* sender,
85 float value,
86 float old_value,
87 views::SliderChangeReason reason) {
88 if (reason == views::VALUE_CHANGED_BY_USER) {
89 label_->SetText(
90 base::UTF8ToUTF16(base::StringPrintf("%.2f", 1.f + value * 2.0f)));
91 }
92 }
93
94 void ScaleView::SliderDragEnded(views::Slider* sender) {
95 display::Display::SetForceDeviceScaleFactor(1.f + slider_->value() * 2.0f);
96 ash::Shell::Get()->display_manager()->UpdateDisplays();
97 }
98
99 } // namespace tray
100 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/display_scale/scale_view.h ('k') | ash/system/display_scale/tray_scale.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698