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

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: Fix various unit-tests 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/layout_delegate.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
16 ChromeViewsLayoutDelegate* layout_delegate_ = nullptr;
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()
Peter Kasting 2017/03/30 00:49:04 It seems like this conditional shouldn't be here i
kylix_rd 2017/03/30 19:34:07 The plan is to eliminate the LayoutDelegate and in
Peter Kasting 2017/03/30 19:40:02 I'm OK with doing that in this CL if you want. I
37 ? base::MakeUnique<ChromeViewsLayoutDelegate>()
38 : base::MakeUnique<ChromeViewsLayoutDelegate>();
39 }
40
41 gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
42 ChromeInsetsMetric metric) const {
43 const LayoutDelegate* layout_delegate = LayoutDelegate::Get();
44 switch (metric) {
45 case ChromeInsetsMetric::DIALOG_BUTTON: {
46 const int top = layout_delegate->GetMetric(
47 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING);
48 const int margin = layout_delegate->GetMetric(
49 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
50 return gfx::Insets(top, margin, margin, margin);
51 }
52 case ChromeInsetsMetric::DIALOG_FRAME_VIEW: {
53 const int top = layout_delegate->GetMetric(
54 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
55 const int side = layout_delegate->GetMetric(
56 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
57 // Titles are inset at the top and sides, but not at the bottom.
58 return gfx::Insets(top, side, 0, side);
59 }
60 case ChromeInsetsMetric::BUBBLE_DIALOG:
61 return gfx::Insets(layout_delegate->GetMetric(
62 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN));
63 case ChromeInsetsMetric::PANEL_LAYOUT:
64 return gfx::Insets(
65 GetDistanceMetric(ChromeDistanceMetric::PANEL_CONTENT_MARGIN),
66 GetDistanceMetric(ChromeDistanceMetric::DIALOG_BUTTON_MARGIN));
67 }
68 NOTREACHED();
69 return gfx::Insets();
70 }
71
72 int ChromeViewsLayoutDelegate::GetDistanceMetric(
73 ChromeDistanceMetric metric) const {
74 switch (metric) {
75 case ChromeDistanceMetric::CLOSE_BUTTON_MARGIN:
76 return LayoutDelegate::Get()->GetMetric(
77 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN);
78 case ChromeDistanceMetric::RELATED_BUTTON_HORIZONTAL:
79 return LayoutDelegate::Get()->GetMetric(
80 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING);
81 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL:
82 return LayoutDelegate::Get()->GetMetric(
83 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING);
84 case ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL_SMALL:
85 return LayoutDelegate::Get()->GetMetric(
86 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING_SMALL);
87 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL:
88 return LayoutDelegate::Get()->GetMetric(
89 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING);
90 case ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL:
91 return LayoutDelegate::Get()->GetMetric(
92 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING_SMALL);
93 case ChromeDistanceMetric::DIALOG_BUTTON_MARGIN:
94 return LayoutDelegate::Get()->GetMetric(
95 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
96 case ChromeDistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
97 return LayoutDelegate::Get()->GetMetric(
98 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH);
99 case ChromeDistanceMetric::BUTTON_HORIZONTAL_PADDING:
100 return LayoutDelegate::Get()->GetMetric(
101 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING);
102 case ChromeDistanceMetric::BUTTON_MAX_LINKABLE_WIDTH:
103 return LayoutDelegate::Get()->GetMetric(
104 LayoutDelegate::Metric::BUTTON_MAX_LINKABLE_WIDTH);
105 case ChromeDistanceMetric::BUTTON_MINIMUM_WIDTH:
106 return LayoutDelegate::Get()->GetMetric(
107 LayoutDelegate::Metric::BUTTON_MINIMUM_WIDTH);
108 case ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT:
109 return LayoutDelegate::Get()->GetMetric(
110 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT);
111 case ChromeDistanceMetric::PANEL_CONTENT_MARGIN:
112 return LayoutDelegate::Get()->GetMetric(
113 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
114 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL:
115 return LayoutDelegate::Get()->GetMetric(
116 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING);
117 case ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL_LARGE:
118 return LayoutDelegate::Get()->GetMetric(
119 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING_LARGE);
120 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL:
121 return LayoutDelegate::Get()->GetMetric(
122 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING);
123 case ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE:
124 return LayoutDelegate::Get()->GetMetric(
125 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING_LARGE);
126 }
127 NOTREACHED();
128 return 0;
129 }
130
131 const views::TypographyProvider&
132 ChromeViewsLayoutDelegate::GetTypographyProvider() const {
133 return LayoutDelegate::Get()->GetTypographyProvider();
134 }
135
136 views::GridLayout::Alignment
137 ChromeViewsLayoutDelegate::GetControlLabelGridAlignment() const {
138 return LayoutDelegate::Get()->GetControlLabelGridAlignment();
139 }
140
141 bool ChromeViewsLayoutDelegate::UseExtraDialogPadding() const {
142 return LayoutDelegate::Get()->UseExtraDialogPadding();
143 }
144
145 bool ChromeViewsLayoutDelegate::ShouldShowWindowIcon() const {
146 return LayoutDelegate::Get()->ShouldShowWindowIcon();
147 }
148
149 bool ChromeViewsLayoutDelegate::IsHarmonyMode() const {
150 return false;
151 }
152
153 int ChromeViewsLayoutDelegate::GetDialogPreferredWidth(
154 DialogWidth width) const {
155 return LayoutDelegate::Get()->GetDialogPreferredWidth(
156 static_cast<LayoutDelegate::DialogWidth>(width));
157 }
158
159 int ChromeViewsLayoutDelegate::GetDefaultDistanceMetric(
160 views::DistanceMetric metric) const {
161 return views::ViewsLayoutDelegate::GetDistanceMetric(metric);
162 }
163
164 gfx::Insets ChromeViewsLayoutDelegate::GetInsetsMetric(
165 views::InsetsMetric metric) const {
166 return GetInsetsMetric(static_cast<ChromeInsetsMetric>(metric));
167 }
168
169 int ChromeViewsLayoutDelegate::GetDistanceMetric(
170 views::DistanceMetric metric) const {
171 return GetDistanceMetric(static_cast<ChromeDistanceMetric>(metric));
172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698