Chromium Code Reviews| Index: ash/system/display_scale/scale_detailed_view.cc |
| diff --git a/ash/system/display_scale/scale_detailed_view.cc b/ash/system/display_scale/scale_detailed_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..60bd8f8101faad0700e2488c354a4aa22085fe06 |
| --- /dev/null |
| +++ b/ash/system/display_scale/scale_detailed_view.cc |
| @@ -0,0 +1,73 @@ |
| +// 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/display_scale/scale_detailed_view.h" |
| + |
| +#include "ash/shell.h" |
| +#include "ash/strings/grit/ash_strings.h" |
| +#include "ash/system/tray/hover_highlight_view.h" |
| +#include "ash/system/tray/tray_popup_utils.h" |
| +#include "base/command_line.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/display_switches.h" |
| +#include "ui/display/manager/display_manager.h" |
| +#include "ui/views/controls/scroll_view.h" |
| + |
| +namespace ash { |
| +namespace tray { |
| +namespace { |
| + |
| +double scales[] = {1.0f, 1.25f, 1.33f, 1.5f, 1.66f, |
| + 1.75f, 1.9f, 2.0f, 2.25f, 2.5f}; |
| +double kEpsilon = 0.005; |
| + |
| +} // namespace |
| + |
| +ScaleDetailedView::ScaleDetailedView(SystemTrayItem* owner) |
| + : TrayDetailsView(owner) { |
| + CreateScrollableList(); |
| + CreateTitleRow(IDS_ASH_STATUS_TRAY_SCALE); |
| + UpdateScrollableList(); |
| + Layout(); |
| +} |
| + |
| +ScaleDetailedView::~ScaleDetailedView() {} |
| + |
| +HoverHighlightView* ScaleDetailedView::AddScrollListItem( |
| + const base::string16& text, |
| + bool highlight, |
| + bool checked) { |
| + HoverHighlightView* container = new HoverHighlightView(this); |
| + |
| + container->AddLabelRow(text); |
| + TrayPopupUtils::InitializeAsCheckableRow(container, checked); |
| + |
| + scroll_content()->AddChildView(container); |
| + return container; |
| +} |
| + |
| +void ScaleDetailedView::UpdateScrollableList() { |
| + scroll_content()->RemoveAllChildViews(true); |
| + view_to_scale_.clear(); |
| + |
| + for (double scale : scales) { |
| + HoverHighlightView* container = AddScrollListItem( |
| + base::UTF8ToUTF16(base::DoubleToString(scale)), false /* highlight */, |
| + std::abs(display::Display::GetForcedDeviceScaleFactor() - scale) < |
| + kEpsilon /* checkmark icon */); |
| + view_to_scale_[container] = scale; |
|
oshima
2017/05/06 19:50:22
optional: or you can parse it from the view.
malaykeshav
2017/05/08 19:18:06
Ack
|
| + } |
| +} |
| + |
| +void ScaleDetailedView::HandleViewClicked(views::View* view) { |
| + display::Display::SetForceDeviceScaleFactor(view_to_scale_[view]); |
| + ash::Shell::Get()->display_manager()->UpdateDisplays(); |
| + UpdateScrollableList(); |
| + Layout(); |
| +} |
| + |
| +} // namespace tray |
| +} // namespace ash |