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

Side by Side Diff: ui/views/style/mac/dialog_button_border_mac.cc

Issue 2358913006: views: remove PlatformStyle::CreateLabelButtonBorder (Closed)
Patch Set: remove DialogButtonBorderMac too Created 4 years, 2 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/style/mac/dialog_button_border_mac.h"
6
7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkDrawLooper.h"
10 #include "third_party/skia/include/core/SkPaint.h"
11 #include "third_party/skia/include/core/SkPath.h"
12 #include "third_party/skia/include/effects/SkGradientShader.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/native_theme/native_theme_mac.h"
15 #include "ui/views/border.h"
16 #include "ui/views/controls/button/custom_button.h"
17 #include "ui/views/controls/button/label_button.h"
18
19 using ui::NativeThemeMac;
20
21 namespace views {
22 namespace {
23
24 // Default border insets, to provide text padding.
25 const int kPaddingX = 19;
26 const int kPaddingY = 7;
27
28 NativeThemeMac::ButtonBackgroundType PaintTypeFromButton(
29 const LabelButton& button) {
30 if (!button.enabled() || button.state() == Button::STATE_DISABLED)
31 return NativeThemeMac::ButtonBackgroundType::DISABLED;
32 if (button.state() == Button::STATE_PRESSED)
33 return NativeThemeMac::ButtonBackgroundType::PRESSED;
34 if (DialogButtonBorderMac::ShouldRenderDefault(button))
35 return NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED;
36 return NativeThemeMac::ButtonBackgroundType::NORMAL;
37 }
38
39 } // namespace
40
41 DialogButtonBorderMac::DialogButtonBorderMac() {
42 set_insets(gfx::Insets(kPaddingY, kPaddingX, kPaddingY, kPaddingX));
43 }
44
45 DialogButtonBorderMac::~DialogButtonBorderMac() {}
46
47 // static
48 bool DialogButtonBorderMac::ShouldRenderDefault(const LabelButton& button) {
49 // TODO(tapted): Check whether the Widget is active, and only return true here
50 // if it is. Plumbing this requires default buttons to also observe Widget
51 // activations to ensure text and background colors are properly invalidated.
52 return button.is_default();
53 }
54
55 void DialogButtonBorderMac::Paint(const View& view, gfx::Canvas* canvas) {
56 // Actually, |view| should be a LabelButton as well, but don't rely too much
57 // on RTTI.
58 DCHECK(CustomButton::AsCustomButton(&view));
59 const LabelButton& button = static_cast<const LabelButton&>(view);
60
61 ui::NativeThemeMac::PaintStyledGradientButton(
62 canvas->sk_canvas(), view.GetLocalBounds(), PaintTypeFromButton(button),
63 true, true, button.HasFocus());
64 }
65
66 gfx::Size DialogButtonBorderMac::GetMinimumSize() const {
67 // Overridden by PlatformStyle. Here, just ensure the minimum size is
68 // consistent with the padding.
69 return gfx::Size(2 * kPaddingX, 2 * kPaddingY);
70 }
71
72 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/style/mac/dialog_button_border_mac.h ('k') | ui/views/style/mac/dialog_button_border_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698