Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; | 59 // ChromeViewsDelegate* views_delegate = nullptr; |
|
Peter Kasting
2017/04/04 02:08:51
Remove entirely
kylix_rd
2017/04/04 20:28:23
Done.
| |
| 61 | 60 |
| 62 } // namespace | 61 } // namespace |
| 63 | 62 |
| 64 | 63 |
| 65 // ChromeViewsDelegate -------------------------------------------------------- | 64 // ChromeViewsDelegate -------------------------------------------------------- |
| 66 | 65 |
| 67 #if defined(OS_WIN) | 66 #if !defined(OS_WIN) |
|
Peter Kasting
2017/04/04 02:08:51
Nit: Can now probably kill this #ifdef by initiali
kylix_rd
2017/04/04 20:28:22
Not sure how to initialize weak_factory_ within th
Peter Kasting
2017/04/05 19:30:10
= base::WeakPtrFactory<ChromeViewsDelegate>(this);
kylix_rd
2017/04/06 16:48:19
That didn't work. "error: call to deleted construc
Peter Kasting
2017/04/06 20:05:33
Weird, I don't know what that error means in this
kylix_rd
2017/04/07 14:07:58
The implicit constructor is explicitly deleted wit
Peter Kasting
2017/04/07 18:02:39
Yeah, but we're calling the explicit (one-arg) con
kylix_rd
2017/04/12 00:03:33
That worked.
| |
| 68 ChromeViewsDelegate::ChromeViewsDelegate() | 67 ChromeViewsDelegate::ChromeViewsDelegate() {} |
| 69 : in_autohide_edges_callback_(false), weak_factory_(this) { | |
| 70 #else | |
| 71 ChromeViewsDelegate::ChromeViewsDelegate() { | |
| 72 #endif | 68 #endif |
| 73 DCHECK(!views_delegate); | |
| 74 views_delegate = this; | |
| 75 } | |
| 76 | 69 |
| 77 ChromeViewsDelegate::~ChromeViewsDelegate() { | 70 ChromeViewsDelegate::~ChromeViewsDelegate() { |
| 78 DCHECK_EQ(0u, ref_count_); | 71 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 } | 72 } |
| 87 | 73 |
| 88 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, | 74 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, |
| 89 const std::string& window_name, | 75 const std::string& window_name, |
| 90 const gfx::Rect& bounds, | 76 const gfx::Rect& bounds, |
| 91 ui::WindowShowState show_state) { | 77 ui::WindowShowState show_state) { |
| 92 PrefService* prefs = GetPrefsForWindow(window); | 78 PrefService* prefs = GetPrefsForWindow(window); |
| 93 if (!prefs) | 79 if (!prefs) |
| 94 return; | 80 return; |
| 95 | 81 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 | 188 |
| 203 std::string ChromeViewsDelegate::GetApplicationName() { | 189 std::string ChromeViewsDelegate::GetApplicationName() { |
| 204 return version_info::GetProductName(); | 190 return version_info::GetProductName(); |
| 205 } | 191 } |
| 206 | 192 |
| 207 scoped_refptr<base::TaskRunner> | 193 scoped_refptr<base::TaskRunner> |
| 208 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { | 194 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { |
| 209 return content::BrowserThread::GetBlockingPool(); | 195 return content::BrowserThread::GetBlockingPool(); |
| 210 } | 196 } |
| 211 | 197 |
| 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 case views::InsetsMetric::VECTOR_IMAGE_BUTTON_PADDING: | |
| 235 return gfx::Insets(layout_delegate->GetMetric( | |
| 236 LayoutDelegate::Metric::VECTOR_IMAGE_BUTTON_PADDING)); | |
| 237 } | |
| 238 NOTREACHED(); | |
| 239 return gfx::Insets(); | |
| 240 } | |
| 241 | |
| 242 int ChromeViewsDelegate::GetDistanceMetric(views::DistanceMetric metric) const { | |
| 243 switch (metric) { | |
| 244 case views::DistanceMetric::CLOSE_BUTTON_MARGIN: | |
| 245 return LayoutDelegate::Get()->GetMetric( | |
| 246 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); | |
| 247 case views::DistanceMetric::RELATED_BUTTON_HORIZONTAL: | |
| 248 return LayoutDelegate::Get()->GetMetric( | |
| 249 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); | |
| 250 case views::DistanceMetric::RELATED_CONTROL_HORIZONTAL: | |
| 251 return LayoutDelegate::Get()->GetMetric( | |
| 252 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING); | |
| 253 case views::DistanceMetric::RELATED_CONTROL_VERTICAL: | |
| 254 return LayoutDelegate::Get()->GetMetric( | |
| 255 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); | |
| 256 case views::DistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH: | |
| 257 return LayoutDelegate::Get()->GetMetric( | |
| 258 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH); | |
| 259 case views::DistanceMetric::BUTTON_HORIZONTAL_PADDING: | |
| 260 return LayoutDelegate::Get()->GetMetric( | |
| 261 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING); | |
| 262 } | |
| 263 NOTREACHED(); | |
| 264 return 0; | |
| 265 } | |
| 266 | |
| 267 const views::TypographyProvider& ChromeViewsDelegate::GetTypographyProvider() | |
| 268 const { | |
| 269 return LayoutDelegate::Get()->GetTypographyProvider(); | |
| 270 } | |
| 271 | |
| 272 int ChromeViewsDelegate::GetDefaultDistanceMetric( | |
| 273 views::DistanceMetric metric) { | |
| 274 return views_delegate | |
| 275 ? views_delegate->InternalGetDefaultDistanceMetric(metric) | |
| 276 : views::ViewsDelegate::GetInstance()->GetDistanceMetric(metric); | |
| 277 } | |
| 278 | |
| 279 int ChromeViewsDelegate::InternalGetDefaultDistanceMetric( | |
| 280 views::DistanceMetric metric) const { | |
| 281 return views::ViewsDelegate::GetDistanceMetric(metric); | |
| 282 } | |
| 283 | |
| 284 #if !defined(OS_CHROMEOS) | 198 #if !defined(OS_CHROMEOS) |
| 285 views::Widget::InitParams::WindowOpacity | 199 views::Widget::InitParams::WindowOpacity |
| 286 ChromeViewsDelegate::GetOpacityForInitParams( | 200 ChromeViewsDelegate::GetOpacityForInitParams( |
| 287 const views::Widget::InitParams& params) { | 201 const views::Widget::InitParams& params) { |
| 288 return views::Widget::InitParams::OPAQUE_WINDOW; | 202 return views::Widget::InitParams::OPAQUE_WINDOW; |
| 289 } | 203 } |
| 290 #endif | 204 #endif |
| OLD | NEW |