| 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 #if !defined(OS_WIN) |
| 61 ChromeViewsDelegate* views_delegate = nullptr; |
| 62 #endif |
| 63 |
| 60 } // namespace | 64 } // namespace |
| 61 | 65 |
| 62 | 66 |
| 63 // ChromeViewsDelegate -------------------------------------------------------- | 67 // ChromeViewsDelegate -------------------------------------------------------- |
| 64 | 68 |
| 65 #if !defined(OS_WIN) | 69 #if !defined(OS_WIN) |
| 66 ChromeViewsDelegate::ChromeViewsDelegate() {} | 70 ChromeViewsDelegate::ChromeViewsDelegate() { |
| 67 #endif | 71 DCHECK(!views_delegate); |
| 72 views_delegate = this; |
| 73 } |
| 68 | 74 |
| 69 ChromeViewsDelegate::~ChromeViewsDelegate() { | 75 ChromeViewsDelegate::~ChromeViewsDelegate() { |
| 70 DCHECK_EQ(0u, ref_count_); | 76 DCHECK_EQ(0u, ref_count_); |
| 77 |
| 78 DCHECK_EQ(this, views_delegate); |
| 79 views_delegate = nullptr; |
| 71 } | 80 } |
| 72 | 81 |
| 82 ChromeViewsDelegate* ChromeViewsDelegate::GetInstance() { |
| 83 return views_delegate; |
| 84 } |
| 85 #endif |
| 86 |
| 73 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, | 87 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, |
| 74 const std::string& window_name, | 88 const std::string& window_name, |
| 75 const gfx::Rect& bounds, | 89 const gfx::Rect& bounds, |
| 76 ui::WindowShowState show_state) { | 90 ui::WindowShowState show_state) { |
| 77 PrefService* prefs = GetPrefsForWindow(window); | 91 PrefService* prefs = GetPrefsForWindow(window); |
| 78 if (!prefs) | 92 if (!prefs) |
| 79 return; | 93 return; |
| 80 | 94 |
| 81 std::unique_ptr<DictionaryPrefUpdate> pref_update = | 95 std::unique_ptr<DictionaryPrefUpdate> pref_update = |
| 82 chrome::GetWindowPlacementDictionaryReadWrite(window_name, prefs); | 96 chrome::GetWindowPlacementDictionaryReadWrite(window_name, prefs); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 203 |
| 190 std::string ChromeViewsDelegate::GetApplicationName() { | 204 std::string ChromeViewsDelegate::GetApplicationName() { |
| 191 return version_info::GetProductName(); | 205 return version_info::GetProductName(); |
| 192 } | 206 } |
| 193 | 207 |
| 194 scoped_refptr<base::TaskRunner> | 208 scoped_refptr<base::TaskRunner> |
| 195 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { | 209 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { |
| 196 return content::BrowserThread::GetBlockingPool(); | 210 return content::BrowserThread::GetBlockingPool(); |
| 197 } | 211 } |
| 198 | 212 |
| 199 gfx::Insets ChromeViewsDelegate::GetDialogButtonInsets() const { | 213 gfx::Insets ChromeViewsDelegate::GetInsetsMetric( |
| 214 views::InsetsMetric metric) const { |
| 200 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | 215 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); |
| 201 const int top = layout_delegate->GetMetric( | 216 switch (metric) { |
| 202 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING); | 217 case views::InsetsMetric::DIALOG_BUTTON: { |
| 203 const int margin = layout_delegate->GetMetric( | 218 const int top = layout_delegate->GetMetric( |
| 204 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | 219 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING); |
| 205 return gfx::Insets(top, margin, margin, margin); | 220 const int margin = layout_delegate->GetMetric( |
| 221 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); |
| 222 return gfx::Insets(top, margin, margin, margin); |
| 223 } |
| 224 case views::InsetsMetric::DIALOG_FRAME_VIEW: { |
| 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 case views::InsetsMetric::BUBBLE_DIALOG: |
| 233 return gfx::Insets(layout_delegate->GetMetric( |
| 234 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); |
| 235 } |
| 236 NOTREACHED(); |
| 237 return gfx::Insets(); |
| 206 } | 238 } |
| 207 | 239 |
| 208 int ChromeViewsDelegate::GetDialogCloseButtonMargin() const { | 240 int ChromeViewsDelegate::GetSpacingMetric(views::SpacingMetric metric) const { |
| 209 return LayoutDelegate::Get()->GetMetric( | 241 switch (metric) { |
| 210 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); | 242 case views::SpacingMetric::CLOSE_BUTTON_MARGIN: |
| 243 return LayoutDelegate::Get()->GetMetric( |
| 244 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); |
| 245 case views::SpacingMetric::ICON_TO_TEXT: |
| 246 return LayoutDelegate::Get()->GetMetric( |
| 247 LayoutDelegate::Metric::ICON_TEXT_SPACING); |
| 248 case views::SpacingMetric::RELATED_HORIZONTAL_BUTTON: |
| 249 return LayoutDelegate::Get()->GetMetric( |
| 250 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); |
| 251 case views::SpacingMetric::RELATED_VERTICAL_CONTROL: |
| 252 return LayoutDelegate::Get()->GetMetric( |
| 253 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); |
| 254 case views::SpacingMetric::DIALOG_BUTTON_MINIMUM_WIDTH: |
| 255 return LayoutDelegate::Get()->GetMetric( |
| 256 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH); |
| 257 case views::SpacingMetric::BUTTON_HORIZONTAL_PADDING: |
| 258 return LayoutDelegate::Get()->GetMetric( |
| 259 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING); |
| 260 } |
| 261 NOTREACHED(); |
| 262 return 0; |
| 211 } | 263 } |
| 212 | 264 |
| 213 int ChromeViewsDelegate::GetDialogRelatedButtonHorizontalSpacing() const { | 265 int ChromeViewsDelegate::GetDefaultSpacingMetric( |
| 214 return LayoutDelegate::Get()->GetMetric( | 266 views::SpacingMetric metric) const { |
| 215 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); | 267 return views::ViewsDelegate::GetSpacingMetric(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 } | 268 } |
| 252 | 269 |
| 253 #if !defined(OS_CHROMEOS) | 270 #if !defined(OS_CHROMEOS) |
| 254 views::Widget::InitParams::WindowOpacity | 271 views::Widget::InitParams::WindowOpacity |
| 255 ChromeViewsDelegate::GetOpacityForInitParams( | 272 ChromeViewsDelegate::GetOpacityForInitParams( |
| 256 const views::Widget::InitParams& params) { | 273 const views::Widget::InitParams& params) { |
| 257 return views::Widget::InitParams::OPAQUE_WINDOW; | 274 return views::Widget::InitParams::OPAQUE_WINDOW; |
| 258 } | 275 } |
| 259 #endif | 276 #endif |
| OLD | NEW |