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

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

Issue 2696263002: Refactor ViewsDelegate and MD-ify the icon-to-text spacing for checkbox and radiobutton (Closed)
Patch Set: Fix unit tests to use a ViewsDelegate to guard against crashes 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/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 #endif 191 #endif
192 192
193 #if defined(USE_ASH) 193 #if defined(USE_ASH)
194 void ProcessAcceleratorNow(const ui::Accelerator& accelerator) { 194 void ProcessAcceleratorNow(const ui::Accelerator& accelerator) {
195 // TODO(afakhry): See if we need here to send the accelerator to the 195 // TODO(afakhry): See if we need here to send the accelerator to the
196 // FocusManager of the active window in a follow-up CL. 196 // FocusManager of the active window in a follow-up CL.
197 ash::WmShell::Get()->accelerator_controller()->Process(accelerator); 197 ash::WmShell::Get()->accelerator_controller()->Process(accelerator);
198 } 198 }
199 #endif // defined(USE_ASH) 199 #endif // defined(USE_ASH)
200 200
201 ChromeViewsDelegate* views_delegate = nullptr;
202
201 } // namespace 203 } // namespace
202 204
203 205
204 // ChromeViewsDelegate -------------------------------------------------------- 206 // ChromeViewsDelegate --------------------------------------------------------
205 207
206 #if defined(OS_WIN) 208 #if defined(OS_WIN)
207 ChromeViewsDelegate::ChromeViewsDelegate() 209 ChromeViewsDelegate::ChromeViewsDelegate()
208 : in_autohide_edges_callback_(false), 210 : in_autohide_edges_callback_(false),
209 weak_factory_(this) { 211 weak_factory_(this) {
210 #else 212 #else
211 ChromeViewsDelegate::ChromeViewsDelegate() { 213 ChromeViewsDelegate::ChromeViewsDelegate() {
212 #endif 214 #endif
215 DCHECK(!views_delegate);
216 views_delegate = this;
213 } 217 }
214 218
215 ChromeViewsDelegate::~ChromeViewsDelegate() { 219 ChromeViewsDelegate::~ChromeViewsDelegate() {
216 DCHECK_EQ(0u, ref_count_); 220 DCHECK_EQ(0u, ref_count_);
221
222 DCHECK_EQ(this, views_delegate);
223 views_delegate = nullptr;
224 }
225
226 ChromeViewsDelegate* ChromeViewsDelegate::GetInstance() {
227 return views_delegate;
217 } 228 }
218 229
219 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, 230 void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window,
220 const std::string& window_name, 231 const std::string& window_name,
221 const gfx::Rect& bounds, 232 const gfx::Rect& bounds,
222 ui::WindowShowState show_state) { 233 ui::WindowShowState show_state) {
223 PrefService* prefs = GetPrefsForWindow(window); 234 PrefService* prefs = GetPrefsForWindow(window);
224 if (!prefs) 235 if (!prefs)
225 return; 236 return;
226 237
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 base::AutoReset<bool> in_callback_setter(&in_autohide_edges_callback_, true); 553 base::AutoReset<bool> in_callback_setter(&in_autohide_edges_callback_, true);
543 callback.Run(); 554 callback.Run();
544 } 555 }
545 #endif 556 #endif
546 557
547 scoped_refptr<base::TaskRunner> 558 scoped_refptr<base::TaskRunner>
548 ChromeViewsDelegate::GetBlockingPoolTaskRunner() { 559 ChromeViewsDelegate::GetBlockingPoolTaskRunner() {
549 return content::BrowserThread::GetBlockingPool(); 560 return content::BrowserThread::GetBlockingPool();
550 } 561 }
551 562
552 gfx::Insets ChromeViewsDelegate::GetDialogButtonInsets() const { 563 gfx::Insets ChromeViewsDelegate::GetInsetsMetric(
564 views::InsetsMetric metric) const {
553 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 565 const LayoutDelegate* layout_delegate = LayoutDelegate::Get();
554 const int top = layout_delegate->GetMetric( 566 switch (metric) {
555 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING); 567 case views::InsetsMetric::DIALOG_BUTTON: {
556 const int margin = layout_delegate->GetMetric( 568 const int top = layout_delegate->GetMetric(
557 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 569 LayoutDelegate::Metric::DIALOG_BUTTON_TOP_SPACING);
558 return gfx::Insets(top, margin, margin, margin); 570 const int margin = layout_delegate->GetMetric(
571 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
572 return gfx::Insets(top, margin, margin, margin);
573 }
574 case views::InsetsMetric::DIALOG_FRAME_VIEW: {
575 const int top = layout_delegate->GetMetric(
576 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN);
577 const int side = layout_delegate->GetMetric(
578 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN);
579 // Titles are inset at the top and sides, but not at the bottom.
580 return gfx::Insets(top, side, 0, side);
581 }
582 case views::InsetsMetric::BUBBLE_DIALOG:
583 return gfx::Insets(layout_delegate->GetMetric(
584 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN));
585 }
586 NOTREACHED();
587 return gfx::Insets();
559 } 588 }
560 589
561 int ChromeViewsDelegate::GetDialogCloseButtonMargin() const { 590 int ChromeViewsDelegate::GetSpacingMetric(views::SpacingMetric metric) const {
562 return LayoutDelegate::Get()->GetMetric( 591 switch (metric) {
563 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN); 592 case views::SpacingMetric::CLOSE_BUTTON_MARGIN:
564 } 593 return LayoutDelegate::Get()->GetMetric(
565 594 LayoutDelegate::Metric::DIALOG_CLOSE_BUTTON_MARGIN);
566 int ChromeViewsDelegate::GetDialogRelatedButtonHorizontalSpacing() const { 595 case views::SpacingMetric::RELATED_HORIZONTAL_BUTTON:
567 return LayoutDelegate::Get()->GetMetric( 596 return LayoutDelegate::Get()->GetMetric(
568 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING); 597 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING);
569 } 598 case views::SpacingMetric::RELATED_VERTICAL_CONTROL:
570 599 return LayoutDelegate::Get()->GetMetric(
571 int ChromeViewsDelegate::GetDialogRelatedControlVerticalSpacing() const { 600 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING);
572 return LayoutDelegate::Get()->GetMetric( 601 case views::SpacingMetric::ICON_TO_TEXT:
573 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 602 return LayoutDelegate::Get()->GetMetric(
574 } 603 LayoutDelegate::Metric::ICON_TEXT_SPACING);
575 604 case views::SpacingMetric::DIALOG_BUTTON_MINIMUM_WIDTH:
576 gfx::Insets ChromeViewsDelegate::GetDialogFrameViewInsets() const { 605 return LayoutDelegate::Get()->GetMetric(
577 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 606 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH);
578 const int top = layout_delegate->GetMetric( 607 case views::SpacingMetric::BUTTON_HORIZONTAL_PADDING:
579 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); 608 return LayoutDelegate::Get()->GetMetric(
580 const int side = layout_delegate->GetMetric( 609 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING);
581 LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 610 }
582 // Titles are inset at the top and sides, but not at the bottom. 611 NOTREACHED();
583 return gfx::Insets(top, side, 0, side); 612 return 0;
584 }
585
586 gfx::Insets ChromeViewsDelegate::GetBubbleDialogMargins() const {
587 return gfx::Insets(LayoutDelegate::Get()->GetMetric(
588 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN));
589 }
590
591 int ChromeViewsDelegate::GetButtonMinimumWidth() const {
592 return LayoutDelegate::Get()->GetMetric(
593 LayoutDelegate::Metric::BUTTON_MINIMUM_WIDTH);
594 }
595
596 int ChromeViewsDelegate::GetDialogButtonMinimumWidth() const {
597 return LayoutDelegate::Get()->GetMetric(
598 LayoutDelegate::Metric::DIALOG_BUTTON_MINIMUM_WIDTH);
599 }
600
601 int ChromeViewsDelegate::GetButtonHorizontalPadding() const {
602 return LayoutDelegate::Get()->GetMetric(
603 LayoutDelegate::Metric::BUTTON_HORIZONTAL_PADDING);
604 } 613 }
605 614
606 #if !defined(USE_ASH) 615 #if !defined(USE_ASH)
607 views::Widget::InitParams::WindowOpacity 616 views::Widget::InitParams::WindowOpacity
608 ChromeViewsDelegate::GetOpacityForInitParams( 617 ChromeViewsDelegate::GetOpacityForInitParams(
609 const views::Widget::InitParams& params) { 618 const views::Widget::InitParams& params) {
610 return views::Widget::InitParams::OPAQUE_WINDOW; 619 return views::Widget::InitParams::OPAQUE_WINDOW;
611 } 620 }
612 #endif 621 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698