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

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

Issue 1569113002: MacViews: Style BUTTON_STYLE buttons using the "modern" UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: respond to comments Created 4 years, 8 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
« no previous file with comments | « ui/views/examples/button_example.cc ('k') | ui/views/style/mac/dialog_button_border_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/views/style/mac/combobox_background_mac.h" 5 #include "ui/views/style/mac/combobox_background_mac.h"
6 6
7 #include "third_party/skia/include/core/SkPath.h" 7 #include "third_party/skia/include/core/SkPath.h"
8 #include "third_party/skia/include/core/SkRRect.h" 8 #include "third_party/skia/include/core/SkRRect.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/native_theme/native_theme_mac.h" 10 #include "ui/native_theme/native_theme_mac.h"
11 #include "ui/views/controls/combobox/combobox.h" 11 #include "ui/views/controls/combobox/combobox.h"
12 #include "ui/views/view.h" 12 #include "ui/views/view.h"
13 13
14 using ui::NativeThemeMac;
15
14 namespace views { 16 namespace views {
15 17
16 ComboboxBackgroundMac::ComboboxBackgroundMac() {} 18 ComboboxBackgroundMac::ComboboxBackgroundMac() {}
17 19
18 ComboboxBackgroundMac::~ComboboxBackgroundMac() {} 20 ComboboxBackgroundMac::~ComboboxBackgroundMac() {}
19 21
20 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const { 22 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const {
21 DCHECK_EQ(view->GetClassName(), Combobox::kViewClassName); 23 DCHECK_EQ(view->GetClassName(), Combobox::kViewClassName);
22 Combobox* combobox = static_cast<Combobox*>(view); 24 Combobox* combobox = static_cast<Combobox*>(view);
23 25
24 gfx::RectF bounds(combobox->GetLocalBounds()); 26 gfx::RectF bounds(combobox->GetLocalBounds());
25 // Inset the left side far enough to draw only the arrow button, and inset the 27 // Inset the left side far enough to draw only the arrow button, and inset the
26 // other three sides by half a pixel so the edge of the background doesn't 28 // other three sides by half a pixel so the edge of the background doesn't
27 // paint outside the border. 29 // paint outside the border.
28 bounds.Inset(bounds.width() - combobox->GetArrowButtonWidth(), 0.5, 0.5, 0.5); 30 bounds.Inset(bounds.width() - combobox->GetArrowButtonWidth(), 0.5, 0.5, 0.5);
29 31
30 ui::NativeTheme::State state = ui::NativeTheme::kNormal; 32 // TODO(tapted): Check whether the Widget is active, and use the NORMAL
33 // BackgroundType if it is inactive. Handling this properly also requires the
34 // control to observe the Widget for activation changes and invalidate.
35 NativeThemeMac::ButtonBackgroundType type =
36 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED;
31 if (!combobox->enabled()) 37 if (!combobox->enabled())
32 state = ui::NativeTheme::kDisabled; 38 type = NativeThemeMac::ButtonBackgroundType::DISABLED;
33 39
34 SkPaint paint; 40 SkPaint paint;
35 paint.setShader( 41 paint.setShader(
36 ui::NativeThemeMac::GetButtonBackgroundShader( 42 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height()));
37 state,
38 bounds.height()));
39 paint.setStyle(SkPaint::kFill_Style); 43 paint.setStyle(SkPaint::kFill_Style);
40 paint.setAntiAlias(true); 44 paint.setAntiAlias(true);
41 45
42 SkPoint no_curve = SkPoint::Make(0, 0); 46 SkPoint no_curve = SkPoint::Make(0, 0);
43 SkPoint curve = SkPoint::Make( 47 SkPoint curve = SkPoint::Make(
44 ui::NativeThemeMac::kComboboxCornerRadius, 48 ui::NativeThemeMac::kComboboxCornerRadius,
45 ui::NativeThemeMac::kComboboxCornerRadius); 49 ui::NativeThemeMac::kComboboxCornerRadius);
46 SkVector curves[4] = { no_curve, curve, curve, no_curve }; 50 SkVector curves[4] = { no_curve, curve, curve, no_curve };
47 51
48 SkRRect fill_rect; 52 SkRRect fill_rect;
49 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); 53 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves);
50 54
51 SkPath path; 55 SkPath path;
52 path.addRRect(fill_rect); 56 path.addRRect(fill_rect);
53 57
54 canvas->DrawPath(path, paint); 58 canvas->DrawPath(path, paint);
55 } 59 }
56 60
57 } // namespace views 61 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/button_example.cc ('k') | ui/views/style/mac/dialog_button_border_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698