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

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: Final feedback addressed 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
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"
11 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/lifetime/keep_alive_types.h" 15 #include "chrome/browser/lifetime/keep_alive_types.h"
16 #include "chrome/browser/lifetime/scoped_keep_alive.h" 16 #include "chrome/browser/lifetime/scoped_keep_alive.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser_window_state.h" 18 #include "chrome/browser/ui/browser_window_state.h"
19 #include "chrome/browser/ui/views/harmony/layout_delegate.h"
20 #include "components/prefs/pref_service.h" 19 #include "components/prefs/pref_service.h"
21 #include "components/prefs/scoped_user_pref_update.h" 20 #include "components/prefs/scoped_user_pref_update.h"
22 #include "components/version_info/version_info.h" 21 #include "components/version_info/version_info.h"
23 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/context_factory.h" 23 #include "content/public/browser/context_factory.h"
25 #include "ui/display/display.h" 24 #include "ui/display/display.h"
26 #include "ui/display/screen.h" 25 #include "ui/display/screen.h"
27 #include "ui/gfx/geometry/rect.h" 26 #include "ui/gfx/geometry/rect.h"
28 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
29 28
(...skipping 20 matching lines...) Expand all
50 // multi-profile environment. 49 // multi-profile environment.
51 PrefService* GetPrefsForWindow(const views::Widget* window) { 50 PrefService* GetPrefsForWindow(const views::Widget* window) {
52 Profile* profile = GetProfileForWindow(window); 51 Profile* profile = GetProfileForWindow(window);
53 if (!profile) { 52 if (!profile) {
54 // Use local state for windows that have no explicit profile. 53 // Use local state for windows that have no explicit profile.
55 return g_browser_process->local_state(); 54 return g_browser_process->local_state();
56 } 55 }
57 return profile->GetPrefs(); 56 return profile->GetPrefs();
58 } 57 }
59 58
60 ChromeViewsDelegate* views_delegate = nullptr;
61
62 } // namespace 59 } // namespace
63 60
64 61
65 // ChromeViewsDelegate -------------------------------------------------------- 62 // ChromeViewsDelegate --------------------------------------------------------
66 63
67 #if defined(OS_WIN) 64 ChromeViewsDelegate::ChromeViewsDelegate() {}
68 ChromeViewsDelegate::ChromeViewsDelegate()
69 : in_autohide_edges_callback_(false), weak_factory_(this) {
70 #else
71 ChromeViewsDelegate::ChromeViewsDelegate() {
72 #endif
73 DCHECK(!views_delegate);
74 views_delegate = this;
75 }
76 65
77 ChromeViewsDelegate::~ChromeViewsDelegate() { 66 ChromeViewsDelegate::~ChromeViewsDelegate() {
78 DCHECK_EQ(0u, ref_count_); 67 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 } 68 }
87 69
88 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, 70 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window,
89 const std::string& window_name, 71 const std::string& window_name,
90 const gfx::Rect& bounds, 72 const gfx::Rect& bounds,
91 ui::WindowShowState show_state) { 73 ui::WindowShowState show_state) {
92 PrefService* prefs = GetPrefsForWindow(window); 74 PrefService* prefs = GetPrefsForWindow(window);
93 if (!prefs) 75 if (!prefs)
94 return; 76 return;
95 77
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 184
203 std::string ChromeViewsDelegate::GetApplicationName() { 185 std::string ChromeViewsDelegate::GetApplicationName() {
204 return version_info::GetProductName(); 186 return version_info::GetProductName();
205 } 187 }
206 188
207 scoped_refptr<base::TaskRunner> 189 scoped_refptr<base::TaskRunner>
208 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { 190 ChromeViewsDelegate::GetBlockingPoolTaskRunner() {
209 return content::BrowserThread::GetBlockingPool(); 191 return content::BrowserThread::GetBlockingPool();
210 } 192 }
211 193
212 gfx::Insets ChromeViewsDelegate::GetInsetsMetric(
213 views::InsetsMetric metric) const {
214 const LayoutDelegate* layout_delegate = LayoutDelegate::Get();
215 switch (metric) {
216 case views::InsetsMetric::BUBBLE_CONTENTS:
217 return gfx::Insets(layout_delegate->GetMetric(
218 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN));
219 case views::InsetsMetric::DIALOG_BUTTON: {
220 const int top = layout_delegate->GetMetric(
221 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING);
222 const int margin = layout_delegate->GetMetric(
223 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
224 return gfx::Insets(top, margin, margin, margin);
225 }
226 case views::InsetsMetric::DIALOG_TITLE: {
227 const int top = layout_delegate->GetMetric(
228 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
229 const int side = layout_delegate->GetMetric(
230 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
231 // Titles are inset at the top and sides, but not at the bottom.
232 return gfx::Insets(top, side, 0, side);
233 }
234 case views::InsetsMetric::PANEL:
235 return gfx::Insets(layout_delegate->GetMetric(
236 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN),
237 layout_delegate->GetMetric(
238 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN));
239 case views::InsetsMetric::VECTOR_IMAGE_BUTTON_PADDING:
240 return gfx::Insets(layout_delegate->GetMetric(
241 LayoutDelegate::Metric::VECTOR_IMAGE_BUTTON_PADDING));
242 }
243 NOTREACHED();
244 return gfx::Insets();
245 }
246
247 int ChromeViewsDelegate::GetDistanceMetric(views::DistanceMetric metric) const {
248 switch (metric) {
249 case views::DistanceMetric::CLOSE_BUTTON_MARGIN:
250 return LayoutDelegate::Get()->GetMetric(
251 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN);
252 case views::DistanceMetric::RELATED_BUTTON_HORIZONTAL:
253 return LayoutDelegate::Get()->GetMetric(
254 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING);
255 case views::DistanceMetric::RELATED_CONTROL_HORIZONTAL:
256 return LayoutDelegate::Get()->GetMetric(
257 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING);
258 case views::DistanceMetric::RELATED_CONTROL_VERTICAL:
259 return LayoutDelegate::Get()->GetMetric(
260 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING);
261 case views::DistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
262 return LayoutDelegate::Get()->GetMetric(
263 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH);
264 case views::DistanceMetric::BUTTON_HORIZONTAL_PADDING:
265 return LayoutDelegate::Get()->GetMetric(
266 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING);
267 }
268 NOTREACHED();
269 return 0;
270 }
271
272 const views::TypographyProvider& ChromeViewsDelegate::GetTypographyProvider()
273 const {
274 return LayoutDelegate::Get()->GetTypographyProvider();
275 }
276
277 int ChromeViewsDelegate::GetDefaultDistanceMetric(
278 views::DistanceMetric metric) {
279 return views_delegate
280 ? views_delegate->InternalGetDefaultDistanceMetric(metric)
281 : views::ViewsDelegate::GetInstance()->GetDistanceMetric(metric);
282 }
283
284 int ChromeViewsDelegate::InternalGetDefaultDistanceMetric(
285 views::DistanceMetric metric) const {
286 return views::ViewsDelegate::GetDistanceMetric(metric);
287 }
288
289 #if !defined(OS_CHROMEOS) 194 #if !defined(OS_CHROMEOS)
290 views::Widget::InitParams::WindowOpacity 195 views::Widget::InitParams::WindowOpacity
291 ChromeViewsDelegate::GetOpacityForInitParams( 196 ChromeViewsDelegate::GetOpacityForInitParams(
292 const views::Widget::InitParams& params) { 197 const views::Widget::InitParams& params) {
293 return views::Widget::InitParams::OPAQUE_WINDOW; 198 return views::Widget::InitParams::OPAQUE_WINDOW;
294 } 199 }
295 #endif 200 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/chrome_views_delegate.h ('k') | chrome/browser/ui/views/collected_cookies_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698