Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
|
oshima
2017/05/06 19:50:22
ditto
malaykeshav
2017/05/08 19:18:06
Done
| |
| 2 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 3 // Use of this source code is governed by a BSD-style license that can be | |
| 4 // found in the LICENSE file. | |
| 5 | |
| 6 #include "ash/system/display_scale/scale_view.h" | |
| 7 | |
| 8 #include <algorithm> | |
| 9 | |
| 10 #include "ash/shell.h" | |
| 11 #include "ash/strings/grit/ash_strings.h" | |
| 12 #include "ash/system/tray/actionable_view.h" | |
| 13 #include "ash/system/tray/system_tray_item.h" | |
| 14 #include "ash/system/tray/tray_constants.h" | |
| 15 #include "ash/system/tray/tray_popup_utils.h" | |
| 16 #include "ash/system/tray/tri_view.h" | |
| 17 #include "base/command_line.h" | |
| 18 #include "base/strings/string_number_conversions.h" | |
| 19 #include "base/strings/utf_string_conversions.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 21 #include "ui/display/display.h" | |
| 22 #include "ui/display/manager/display_manager.h" | |
| 23 #include "ui/native_theme/native_theme.h" | |
| 24 #include "ui/views/background.h" | |
| 25 #include "ui/views/border.h" | |
| 26 #include "ui/views/controls/image_view.h" | |
| 27 #include "ui/views/controls/label.h" | |
| 28 #include "ui/views/controls/slider.h" | |
| 29 #include "ui/views/layout/fill_layout.h" | |
| 30 | |
| 31 namespace ash { | |
| 32 namespace tray { | |
| 33 namespace { | |
| 34 | |
| 35 std::string GetStringValue(double value) { | |
| 36 std::string str_value = base::DoubleToString(value); | |
| 37 if (str_value.length() > 4) | |
| 38 str_value.erase(str_value.begin() + 4, str_value.end()); | |
| 39 return str_value; | |
|
oshima
2017/05/06 19:50:22
can you use StringPrintf instead?
malaykeshav
2017/05/08 19:18:06
Done
| |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 ScaleView::ScaleView(SystemTrayItem* owner, bool is_default_view) | |
| 45 : owner_(owner), | |
| 46 tri_view_(TrayPopupUtils::CreateMultiTargetRowView()), | |
| 47 more_button_(nullptr), | |
| 48 label_(nullptr), | |
| 49 slider_(nullptr), | |
| 50 is_default_view_(is_default_view) { | |
| 51 SetLayoutManager(new views::FillLayout); | |
| 52 AddChildView(tri_view_); | |
| 53 | |
| 54 label_ = new views::Label(base::UTF8ToUTF16( | |
| 55 GetStringValue(display::Display::GetForcedDeviceScaleFactor()))); | |
| 56 tri_view_->AddView(TriView::Container::START, label_); | |
| 57 | |
| 58 slider_ = TrayPopupUtils::CreateSlider(this); | |
| 59 slider_->SetValue((display::Display::GetForcedDeviceScaleFactor() - 1.f) / 2); | |
| 60 slider_->SetAccessibleName( | |
| 61 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCALE_SLIDER)); | |
| 62 tri_view_->AddView(TriView::Container::CENTER, slider_); | |
| 63 | |
| 64 set_background(views::Background::CreateThemedSolidBackground( | |
| 65 this, ui::NativeTheme::kColorId_BubbleBackground)); | |
| 66 | |
| 67 if (!is_default_view_) { | |
| 68 tri_view_->SetContainerVisible(TriView::Container::END, false); | |
| 69 Layout(); | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 more_button_ = new ButtonListenerActionableView( | |
| 74 owner_, TrayPopupInkDropStyle::INSET_BOUNDS, this); | |
| 75 TrayPopupUtils::ConfigureContainer(TriView::Container::END, more_button_); | |
| 76 | |
| 77 more_button_->SetInkDropMode(views::InkDropHostView::InkDropMode::ON); | |
| 78 more_button_->SetBorder( | |
| 79 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupButtonEndMargin))); | |
| 80 tri_view_->AddView(TriView::Container::END, more_button_); | |
| 81 | |
| 82 more_button_->AddChildView(TrayPopupUtils::CreateMoreImageView()); | |
| 83 more_button_->SetAccessibleName( | |
| 84 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SCALE)); | |
| 85 Layout(); | |
| 86 } | |
| 87 | |
| 88 ScaleView::~ScaleView() {} | |
| 89 | |
| 90 void ScaleView::ButtonPressed(views::Button* sender, const ui::Event& event) { | |
| 91 if (sender == more_button_) | |
| 92 owner_->TransitionDetailedView(); | |
| 93 } | |
| 94 | |
| 95 void ScaleView::SliderValueChanged(views::Slider* sender, | |
| 96 float value, | |
| 97 float old_value, | |
| 98 views::SliderChangeReason reason) { | |
| 99 if (reason == views::VALUE_CHANGED_BY_USER) | |
| 100 label_->SetText(base::UTF8ToUTF16(GetStringValue(1.f + value * 2.0f))); | |
| 101 } | |
| 102 | |
| 103 void ScaleView::SliderDragEnded(views::Slider* sender) { | |
| 104 display::Display::SetForceDeviceScaleFactor(1.f + slider_->value() * 2.0f); | |
| 105 ash::Shell::Get()->display_manager()->UpdateDisplays(); | |
| 106 } | |
| 107 | |
| 108 } // namespace tray | |
| 109 } // namespace ash | |
| OLD | NEW |