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

Side by Side Diff: chrome/browser/ui/views/harmony/chrome_views_layout_delegate.cc

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: Deleted LayoutDelegate and HarmonyLayoutDelegate. 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 unified diff | Download patch
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 "chrome/browser/ui/views/harmony/chrome_views_layout_delegate.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
10 #include "chrome/browser/ui/views/harmony/harmony_views_layout_delegate.h"
11 #include "ui/base/material_design/material_design_controller.h"
12 #include "ui/views/layout/layout_constants.h"
13
14 namespace {
15
Peter Kasting 2017/04/04 02:08:52 Nit: Remove blank line
16 ChromeViewsLayoutDelegate* layout_delegate_ = nullptr;
Peter Kasting 2017/04/04 02:08:53 Nit: I'd name this |g_layout_delegate| since it's
17 }
18
19 ChromeViewsLayoutDelegate::ChromeViewsLayoutDelegate() {
20 layout_delegate_ = this;
21 }
22
23 ChromeViewsLayoutDelegate::~ChromeViewsLayoutDelegate() {
24 if (this == layout_delegate_)
25 layout_delegate_ = nullptr;
26 }
27
28 // static
29 ChromeViewsLayoutDelegate* ChromeViewsLayoutDelegate::Get() {
30 return layout_delegate_;
31 }
32
33 // static
34 std::unique_ptr<views::ViewsLayoutDelegate>
35 ChromeViewsLayoutDelegate::CreateLayoutDelegate() {
36 return ui::MaterialDesignController::IsSecondaryUiMaterial()
37 ? base::MakeUnique<HarmonyViewsLayoutDelegate>()
38 : base::MakeUnique<ChromeViewsLayoutDelegate>();
39 }
40
41 gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
42 ChromeInsetsMetric metric) const {
43 switch (metric) {
44 case ChromeInsetsMetric::DIALOG_BUTTON:
45 case ChromeInsetsMetric::DIALOG_FRAME_VIEW:
46 case ChromeInsetsMetric::BUBBLE_DIALOG:
47 case ChromeInsetsMetric::VECTOR_IMAGE_BUTTON:
48 return views::ViewsLayoutDelegate::GetInsetsMetric(
49 static_cast<views::InsetsMetric>(metric));
Peter Kasting 2017/04/04 02:08:52 Nit: A blank line below this top group (in each of
50 case ChromeInsetsMetric::PANEL_LAYOUT:
51 return gfx::Insets(views::kPanelHorizMargin,
Peter Kasting 2017/04/04 02:08:53 Nit: Shouldn't this be kPanelVertMargin?
kylix_rd 2017/04/04 20:28:23 Maybe... however, this is copied from layout_utils
Peter Kasting 2017/04/05 19:30:10 kPanelVertMargin and kPanelHorizMargin had the sam
52 views::kButtonHEdgeMarginNew);
Peter Kasting 2017/04/04 02:08:53 Nit: Seems like these should use GetDistanceMetric
53 }
54 NOTREACHED();
55 return gfx::Insets();
56 }
57
58 int ChromeViewsLayoutDelegate::GetDistanceMetric(
59 ChromeDistanceMetric metric) const {
60 switch (metric) {
61 case ChromeDistanceMetric::BUTTON_HORIZONTAL_PADDING:
62 case ChromeDistanceMetric::CLOSE_BUTTON_MARGIN:
63 case ChromeDistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
64 case ChromeDistanceMetric::RELATED_BUTTON_HORIZONTAL:
65 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL:
66 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL:
67 return views::ViewsLayoutDelegate::GetDistanceMetric(
68 static_cast<views::DistanceMetric>(metric));
69 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL_SMALL:
70 return views::kRelatedControlSmallHorizontalSpacing;
71 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL:
72 return views::kRelatedControlSmallVerticalSpacing;
73 case ChromeDistanceMetric::DIALOG_BUTTON_MARGIN:
74 return views::kButtonHEdgeMarginNew;
75 case ChromeDistanceMetric::DIALOG_BUTTON_TOP:
76 return 0;
77 case ChromeDistanceMetric::BUTTON_MAX_LINKABLE_WIDTH:
78 return 0;
79 case ChromeDistanceMetric::BUTTON_MINIMUM_WIDTH:
80 return views::kMinimumButtonWidth;
Peter Kasting 2017/04/04 02:08:53 I think after this patch this constant is only pre
kylix_rd 2017/04/04 20:28:23 Eventually, all the views::kXXXX constants will be
81 case ChromeDistanceMetric::RELATED_LABEL_HORIZONTAL:
82 return views::kItemLabelSpacing;
83 case ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT:
84 return views::kCheckboxIndent;
85 case ChromeDistanceMetric::PANEL_CONTENT_MARGIN:
86 return views::kPanelHorizMargin;
87 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL:
88 return views::kUnrelatedControlHorizontalSpacing;
89 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL_LARGE:
90 return views::kUnrelatedControlLargeHorizontalSpacing;
91 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL:
92 return views::kUnrelatedControlVerticalSpacing;
93 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE:
94 return views::kUnrelatedControlLargeVerticalSpacing;
95 }
96 NOTREACHED();
97 return 0;
98 }
99
100 const views::TypographyProvider&
101 ChromeViewsLayoutDelegate::GetTypographyProvider() const {
102 // This is not a data member because then HarmonyLayoutDelegate would inherit
103 // it, even when it provides its own.
104 CR_DEFINE_STATIC_LOCAL(LegacyTypographyProvider, legacy_provider, ());
105 return legacy_provider;
106 }
107
108 views::GridLayout::Alignment
109 ChromeViewsLayoutDelegate::GetControlLabelGridAlignment() const {
110 return views::GridLayout::TRAILING;
111 }
112
113 bool ChromeViewsLayoutDelegate::UseExtraDialogPadding() const {
114 return true;
115 }
116
117 bool ChromeViewsLayoutDelegate::ShouldShowWindowIcon() const {
118 return true;
119 }
120
121 bool ChromeViewsLayoutDelegate::IsHarmonyMode() const {
122 return false;
123 }
124
125 int ChromeViewsLayoutDelegate::GetDialogPreferredWidth(
126 DialogWidth width) const {
127 return 0;
128 }
129
130 int ChromeViewsLayoutDelegate::GetDefaultDistanceMetric(
131 views::DistanceMetric metric) const {
132 return views::ViewsLayoutDelegate::GetDistanceMetric(metric);
133 }
134
135 gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
136 views::InsetsMetric metric) const {
137 return GetInsetsMetric(static_cast<ChromeInsetsMetric>(metric));
138 }
139
140 int ChromeViewsLayoutDelegate::GetDistanceMetric(
141 views::DistanceMetric metric) const {
142 return GetDistanceMetric(static_cast<ChromeDistanceMetric>(metric));
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698