| 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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 61 |
| 60 } // namespace | 62 } // namespace |
| 61 | 63 |
| 62 | 64 |
| 63 // ChromeViewsDelegate -------------------------------------------------------- | 65 // ChromeViewsDelegate -------------------------------------------------------- |
| 64 | 66 |
| 65 #if !defined(OS_WIN) | 67 #if defined(OS_WIN) |
| 66 ChromeViewsDelegate::ChromeViewsDelegate() {} | 68 ChromeViewsDelegate::ChromeViewsDelegate() |
| 69 : in_autohide_edges_callback_(false), weak_factory_(this) { |
| 70 #else |
| 71 ChromeViewsDelegate::ChromeViewsDelegate() { |
| 67 #endif | 72 #endif |
| 73 DCHECK(!views_delegate); |
| 74 views_delegate = this; |
| 75 } |
| 68 | 76 |
| 69 ChromeViewsDelegate::~ChromeViewsDelegate() { | 77 ChromeViewsDelegate::~ChromeViewsDelegate() { |
| 70 DCHECK_EQ(0u, ref_count_); | 78 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; |
| 71 } | 86 } |
| 72 | 87 |
| 73 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, | 88 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, |
| 74 const std::string& window_name, | 89 const std::string& window_name, |
| 75 const gfx::Rect& bounds, | 90 const gfx::Rect& bounds, |
| 76 ui::WindowShowState show_state) { | 91 ui::WindowShowState show_state) { |
| 77 PrefService* prefs = GetPrefsForWindow(window); | 92 PrefService* prefs = GetPrefsForWindow(window); |
| 78 if (!prefs) | 93 if (!prefs) |
| 79 return; | 94 return; |
| 80 | 95 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 204 |
| 190 std::string ChromeViewsDelegate::GetApplicationName() { | 205 std::string ChromeViewsDelegate::GetApplicationName() { |
| 191 return version_info::GetProductName(); | 206 return version_info::GetProductName(); |
| 192 } | 207 } |
| 193 | 208 |
| 194 scoped_refptr<base::TaskRunner> | 209 scoped_refptr<base::TaskRunner> |
| 195 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { | 210 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { |
| 196 return content::BrowserThread::GetBlockingPool(); | 211 return content::BrowserThread::GetBlockingPool(); |
| 197 } | 212 } |
| 198 | 213 |
| 199 gfx::Insets ChromeViewsDelegate::GetDialogButtonInsets() const { | 214 gfx::Insets ChromeViewsDelegate::GetInsetsMetric( |
| 215 views::InsetsMetric metric) const { |
| 200 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | 216 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); |
| 201 const int top = layout_delegate->GetMetric( | 217 switch (metric) { |
| 202 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING); | 218 case views::InsetsMetric::DIALOG_BUTTON: { |
| 203 const int margin = layout_delegate->GetMetric( | 219 const int top = layout_delegate->GetMetric( |
| 204 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | 220 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING); |
| 205 return gfx::Insets(top, margin, margin, margin); | 221 const int margin = layout_delegate->GetMetric( |
| 222 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); |
| 223 return gfx::Insets(top, margin, margin, margin); |
| 224 } |
| 225 case views::InsetsMetric::DIALOG_FRAME_VIEW: { |
| 226 const int top = layout_delegate->GetMetric( |
| 227 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); |
| 228 const int side = layout_delegate->GetMetric( |
| 229 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); |
| 230 // Titles are inset at the top and sides, but not at the bottom. |
| 231 return gfx::Insets(top, side, 0, side); |
| 232 } |
| 233 case views::InsetsMetric::BUBBLE_DIALOG: |
| 234 return gfx::Insets(layout_delegate->GetMetric( |
| 235 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); |
| 236 } |
| 237 NOTREACHED(); |
| 238 return gfx::Insets(); |
| 206 } | 239 } |
| 207 | 240 |
| 208 int ChromeViewsDelegate::GetDialogCloseButtonMargin() const { | 241 int ChromeViewsDelegate::GetDistanceMetric(views::DistanceMetric metric) const { |
| 209 return LayoutDelegate::Get()->GetMetric( | 242 switch (metric) { |
| 210 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); | 243 case views::DistanceMetric::CLOSE_BUTTON_MARGIN: |
| 244 return LayoutDelegate::Get()->GetMetric( |
| 245 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); |
| 246 case views::DistanceMetric::RELATED_BUTTON_HORIZONTAL: |
| 247 return LayoutDelegate::Get()->GetMetric( |
| 248 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); |
| 249 case views::DistanceMetric::RELATED_CONTROL_HORIZONTAL: |
| 250 return LayoutDelegate::Get()->GetMetric( |
| 251 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING); |
| 252 case views::DistanceMetric::RELATED_CONTROL_VERTICAL: |
| 253 return LayoutDelegate::Get()->GetMetric( |
| 254 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); |
| 255 case views::DistanceMetric::DIALOG_BUTTON_MINIMUM_WIDTH: |
| 256 return LayoutDelegate::Get()->GetMetric( |
| 257 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH); |
| 258 case views::DistanceMetric::BUTTON_HORIZONTAL_PADDING: |
| 259 return LayoutDelegate::Get()->GetMetric( |
| 260 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING); |
| 261 } |
| 262 NOTREACHED(); |
| 263 return 0; |
| 211 } | 264 } |
| 212 | 265 |
| 213 int ChromeViewsDelegate::GetDialogRelatedButtonHorizontalSpacing() const { | 266 int ChromeViewsDelegate::GetDefaultDistanceMetric( |
| 214 return LayoutDelegate::Get()->GetMetric( | 267 views::DistanceMetric metric) const { |
| 215 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); | 268 return views::ViewsDelegate::GetDistanceMetric(metric); |
| 216 } | |
| 217 | |
| 218 int ChromeViewsDelegate::GetDialogRelatedControlVerticalSpacing() const { | |
| 219 return LayoutDelegate::Get()->GetMetric( | |
| 220 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); | |
| 221 } | |
| 222 | |
| 223 gfx::Insets ChromeViewsDelegate::GetDialogFrameViewInsets() const { | |
| 224 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | |
| 225 const int top = layout_delegate->GetMetric( | |
| 226 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); | |
| 227 const int side = layout_delegate->GetMetric( | |
| 228 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | |
| 229 // Titles are inset at the top and sides, but not at the bottom. | |
| 230 return gfx::Insets(top, side, 0, side); | |
| 231 } | |
| 232 | |
| 233 gfx::Insets ChromeViewsDelegate::GetBubbleDialogMargins() const { | |
| 234 return gfx::Insets(LayoutDelegate::Get()->GetMetric( | |
| 235 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); | |
| 236 } | |
| 237 | |
| 238 int ChromeViewsDelegate::GetButtonMinimumWidth() const { | |
| 239 return LayoutDelegate::Get()->GetMetric( | |
| 240 LayoutDelegate::Metric::BUTTON_MINIMUM_WIDTH); | |
| 241 } | |
| 242 | |
| 243 int ChromeViewsDelegate::GetDialogButtonMinimumWidth() const { | |
| 244 return LayoutDelegate::Get()->GetMetric( | |
| 245 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH); | |
| 246 } | |
| 247 | |
| 248 int ChromeViewsDelegate::GetButtonHorizontalPadding() const { | |
| 249 return LayoutDelegate::Get()->GetMetric( | |
| 250 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING); | |
| 251 } | 269 } |
| 252 | 270 |
| 253 #if !defined(OS_CHROMEOS) | 271 #if !defined(OS_CHROMEOS) |
| 254 views::Widget::InitParams::WindowOpacity | 272 views::Widget::InitParams::WindowOpacity |
| 255 ChromeViewsDelegate::GetOpacityForInitParams( | 273 ChromeViewsDelegate::GetOpacityForInitParams( |
| 256 const views::Widget::InitParams& params) { | 274 const views::Widget::InitParams& params) { |
| 257 return views::Widget::InitParams::OPAQUE_WINDOW; | 275 return views::Widget::InitParams::OPAQUE_WINDOW; |
| 258 } | 276 } |
| 259 #endif | 277 #endif |
| OLD | NEW |