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

Side by Side Diff: chrome/browser/ui/views/chrome_views_delegate.cc

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: Fix Bookmark and Global error unittests Created 3 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/chrome_views_delegate.h" 5 #include "chrome/browser/ui/views/chrome_views_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // multi-profile environment. 50 // multi-profile environment.
51 PrefService* GetPrefsForWindow(const views::Widget* window) { 51 PrefService* GetPrefsForWindow(const views::Widget* window) {
52 Profile* profile = GetProfileForWindow(window); 52 Profile* profile = GetProfileForWindow(window);
53 if (!profile) { 53 if (!profile) {
54 // Use local state for windows that have no explicit profile. 54 // Use local state for windows that have no explicit profile.
55 return g_browser_process->local_state(); 55 return g_browser_process->local_state();
56 } 56 }
57 return profile->GetPrefs(); 57 return profile->GetPrefs();
58 } 58 }
59 59
60 ChromeViewsDelegate* views_delegate = nullptr; 60 // ChromeViewsDelegate* views_delegate = nullptr;
61 61
62 } // namespace 62 } // namespace
63 63
64 64
65 // ChromeViewsDelegate -------------------------------------------------------- 65 // ChromeViewsDelegate --------------------------------------------------------
66 66
67 #if defined(OS_WIN) 67 #if !defined(OS_WIN)
68 ChromeViewsDelegate::ChromeViewsDelegate() 68 ChromeViewsDelegate::ChromeViewsDelegate() {}
69 : in_autohide_edges_callback_(false), weak_factory_(this) {
70 #else
71 ChromeViewsDelegate::ChromeViewsDelegate() {
72 #endif 69 #endif
73 DCHECK(!views_delegate);
74 views_delegate = this;
75 }
76 70
77 ChromeViewsDelegate::~ChromeViewsDelegate() { 71 ChromeViewsDelegate::~ChromeViewsDelegate() {
78 DCHECK_EQ(0u, ref_count_); 72 DCHECK_EQ(0u, ref_count_);
79
80 DCHECK_EQ(this, views_delegate);
81 views_delegate = nullptr;
82 }
83
84 ChromeViewsDelegate* ChromeViewsDelegate::GetInstance() {
85 return views_delegate;
86 } 73 }
87 74
88 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, 75 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window,
89 const std::string& window_name, 76 const std::string& window_name,
90 const gfx::Rect& bounds, 77 const gfx::Rect& bounds,
91 ui::WindowShowState show_state) { 78 ui::WindowShowState show_state) {
92 PrefService* prefs = GetPrefsForWindow(window); 79 PrefService* prefs = GetPrefsForWindow(window);
93 if (!prefs) 80 if (!prefs)
94 return; 81 return;
95 82
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 189
203 std::string ChromeViewsDelegate::GetApplicationName() { 190 std::string ChromeViewsDelegate::GetApplicationName() {
204 return version_info::GetProductName(); 191 return version_info::GetProductName();
205 } 192 }
206 193
207 scoped_refptr<base::TaskRunner> 194 scoped_refptr<base::TaskRunner>
208 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { 195 ChromeViewsDelegate::GetBlockingPoolTaskRunner() {
209 return content::BrowserThread::GetBlockingPool(); 196 return content::BrowserThread::GetBlockingPool();
210 } 197 }
211 198
212 gfx::Insets ChromeViewsDelegate::GetInsetsMetric(
213 views::InsetsMetric metric) const {
214 const LayoutDelegate* layout_delegate = LayoutDelegate::Get();
215 switch (metric) {
216 case views::InsetsMetric::DIALOG_BUTTON: {
217 const int top = layout_delegate->GetMetric(
218 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING);
219 const int margin = layout_delegate->GetMetric(
220 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
221 return gfx::Insets(top, margin, margin, margin);
222 }
223 case views::InsetsMetric::DIALOG_FRAME_VIEW: {
224 const int top = layout_delegate->GetMetric(
225 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
226 const int side = layout_delegate->GetMetric(
227 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
228 // Titles are inset at the top and sides, but not at the bottom.
229 return gfx::Insets(top, side, 0, side);
230 }
231 case views::InsetsMetric::BUBBLE_DIALOG:
232 return gfx::Insets(layout_delegate->GetMetric(
233 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN));
234 }
235 NOTREACHED();
236 return gfx::Insets();
237 }
238
239 int ChromeViewsDelegate::GetDistanceMetric(views::DistanceMetric metric) const {
240 switch (metric) {
241 case views::DistanceMetric::CLOSE_BUTTON_MARGIN:
242 return LayoutDelegate::Get()->GetMetric(
243 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN);
244 case views::DistanceMetric::RELATED_BUTTON_HORIZONTAL:
245 return LayoutDelegate::Get()->GetMetric(
246 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING);
247 case views::DistanceMetric::RELATED_CONTROL_HORIZONTAL:
248 return LayoutDelegate::Get()->GetMetric(
249 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING);
250 case views::DistanceMetric::RELATED_CONTROL_VERTICAL:
251 return LayoutDelegate::Get()->GetMetric(
252 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING);
253 case views::DistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
254 return LayoutDelegate::Get()->GetMetric(
255 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH);
256 case views::DistanceMetric::BUTTON_HORIZONTAL_PADDING:
257 return LayoutDelegate::Get()->GetMetric(
258 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING);
259 }
260 NOTREACHED();
261 return 0;
262 }
263
264 const views::TypographyProvider& ChromeViewsDelegate::GetTypographyProvider()
265 const {
266 return LayoutDelegate::Get()->GetTypographyProvider();
267 }
268
269 int ChromeViewsDelegate::GetDefaultDistanceMetric(
270 views::DistanceMetric metric) {
271 return views_delegate
272 ? views_delegate->InternalGetDefaultDistanceMetric(metric)
273 : views::ViewsDelegate::GetInstance()->GetDistanceMetric(metric);
274 }
275
276 int ChromeViewsDelegate::InternalGetDefaultDistanceMetric(
277 views::DistanceMetric metric) const {
278 return views::ViewsDelegate::GetDistanceMetric(metric);
279 }
280
281 #if !defined(OS_CHROMEOS) 199 #if !defined(OS_CHROMEOS)
282 views::Widget::InitParams::WindowOpacity 200 views::Widget::InitParams::WindowOpacity
283 ChromeViewsDelegate::GetOpacityForInitParams( 201 ChromeViewsDelegate::GetOpacityForInitParams(
284 const views::Widget::InitParams& params) { 202 const views::Widget::InitParams& params) {
285 return views::Widget::InitParams::OPAQUE_WINDOW; 203 return views::Widget::InitParams::OPAQUE_WINDOW;
286 } 204 }
287 #endif 205 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698