| OLD | NEW |
| (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_detailed_view.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/strings/grit/ash_strings.h" |
| 9 #include "ash/system/tray/hover_highlight_view.h" |
| 10 #include "ash/system/tray/tray_popup_utils.h" |
| 11 #include "base/command_line.h" |
| 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/display/display.h" |
| 15 #include "ui/display/display_switches.h" |
| 16 #include "ui/display/manager/display_manager.h" |
| 17 #include "ui/views/controls/scroll_view.h" |
| 18 |
| 19 namespace ash { |
| 20 namespace tray { |
| 21 namespace { |
| 22 |
| 23 const double scales[] = {1.0f, 1.25f, 1.33f, 1.5f, 1.66f, |
| 24 1.75f, 1.9f, 2.0f, 2.25f, 2.5f}; |
| 25 constexpr double kEpsilon = 0.01; |
| 26 |
| 27 bool IsSameScaleFactor(double new_value) { |
| 28 return (std::abs(display::Display::GetForcedDeviceScaleFactor() - new_value) < |
| 29 kEpsilon); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
| 34 ScaleDetailedView::ScaleDetailedView(SystemTrayItem* owner) |
| 35 : TrayDetailsView(owner) { |
| 36 CreateScrollableList(); |
| 37 CreateTitleRow(IDS_ASH_STATUS_TRAY_SCALE); |
| 38 UpdateScrollableList(); |
| 39 Layout(); |
| 40 } |
| 41 |
| 42 ScaleDetailedView::~ScaleDetailedView() {} |
| 43 |
| 44 HoverHighlightView* ScaleDetailedView::AddScrollListItem( |
| 45 const base::string16& text, |
| 46 bool highlight, |
| 47 bool checked) { |
| 48 HoverHighlightView* container = new HoverHighlightView(this); |
| 49 |
| 50 container->AddLabelRow(text); |
| 51 TrayPopupUtils::InitializeAsCheckableRow(container, checked); |
| 52 |
| 53 scroll_content()->AddChildView(container); |
| 54 return container; |
| 55 } |
| 56 |
| 57 void ScaleDetailedView::UpdateScrollableList() { |
| 58 scroll_content()->RemoveAllChildViews(true); |
| 59 view_to_scale_.clear(); |
| 60 |
| 61 for (double scale : scales) { |
| 62 HoverHighlightView* container = AddScrollListItem( |
| 63 base::UTF8ToUTF16(base::StringPrintf("%.2f", scale)), |
| 64 false /* highlight */, IsSameScaleFactor(scale) /* checkmark icon */); |
| 65 view_to_scale_[container] = scale; |
| 66 } |
| 67 } |
| 68 |
| 69 void ScaleDetailedView::HandleViewClicked(views::View* view) { |
| 70 // The selected dsf is already active. |
| 71 double new_scale = view_to_scale_[view]; |
| 72 if (IsSameScaleFactor(new_scale)) |
| 73 return; |
| 74 display::Display::SetForceDeviceScaleFactor(new_scale); |
| 75 ash::Shell::Get()->display_manager()->UpdateDisplays(); |
| 76 UpdateScrollableList(); |
| 77 Layout(); |
| 78 } |
| 79 |
| 80 } // namespace tray |
| 81 } // namespace ash |
| OLD | NEW |