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

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

Issue 1971333002: Views: factor out Combobox background and const-ify style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ios build break Created 4 years, 7 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/style/mac/combobox_background_mac.h ('k') | ui/views/style/platform_style.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/gfx/scoped_canvas.h"
10 #include "ui/native_theme/native_theme_mac.h" 11 #include "ui/native_theme/native_theme_mac.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; 14 using ui::NativeThemeMac;
15 15
16 namespace views { 16 namespace views {
17 17
18 ComboboxBackgroundMac::ComboboxBackgroundMac() {} 18 ComboboxBackgroundMac::ComboboxBackgroundMac(int container_width)
19 : container_width_(container_width) {}
19 20
20 ComboboxBackgroundMac::~ComboboxBackgroundMac() {} 21 ComboboxBackgroundMac::~ComboboxBackgroundMac() {}
21 22
22 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const { 23 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const {
23 DCHECK_EQ(view->GetClassName(), Combobox::kViewClassName); 24 gfx::RectF bounds(view->GetLocalBounds());
24 Combobox* combobox = static_cast<Combobox*>(view); 25 gfx::ScopedRTLFlipCanvas scoped_canvas(canvas, view->bounds());
25 26
26 gfx::RectF bounds(combobox->GetLocalBounds());
27 // 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
28 // 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
29 // paint outside the border. 29 // paint outside the border.
30 bounds.Inset(bounds.width() - combobox->GetArrowButtonWidth(), 0.5, 0.5, 0.5); 30 bounds.Inset(bounds.width() - container_width_, 0.5, 0.5, 0.5);
31 31
32 // TODO(tapted): Check whether the Widget is active, and use the NORMAL 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 33 // BackgroundType if it is inactive. Handling this properly also requires the
34 // control to observe the Widget for activation changes and invalidate. 34 // control to observe the Widget for activation changes and invalidate.
35 NativeThemeMac::ButtonBackgroundType type = 35 NativeThemeMac::ButtonBackgroundType type =
36 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED; 36 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED;
37 if (!combobox->enabled()) 37 if (!view->enabled())
38 type = NativeThemeMac::ButtonBackgroundType::DISABLED; 38 type = NativeThemeMac::ButtonBackgroundType::DISABLED;
39 39
40 SkPaint paint; 40 SkPaint paint;
41 paint.setShader( 41 paint.setShader(
42 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height())); 42 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height()));
43 paint.setStyle(SkPaint::kFill_Style); 43 paint.setStyle(SkPaint::kFill_Style);
44 paint.setAntiAlias(true); 44 paint.setAntiAlias(true);
45 45
46 SkPoint no_curve = SkPoint::Make(0, 0); 46 SkPoint no_curve = SkPoint::Make(0, 0);
47 SkPoint curve = SkPoint::Make( 47 SkPoint curve = SkPoint::Make(
48 ui::NativeThemeMac::kComboboxCornerRadius, 48 ui::NativeThemeMac::kComboboxCornerRadius,
49 ui::NativeThemeMac::kComboboxCornerRadius); 49 ui::NativeThemeMac::kComboboxCornerRadius);
50 SkVector curves[4] = { no_curve, curve, curve, no_curve }; 50 SkVector curves[4] = { no_curve, curve, curve, no_curve };
51 51
52 SkRRect fill_rect; 52 SkRRect fill_rect;
53 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); 53 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves);
54 54
55 SkPath path; 55 SkPath path;
56 path.addRRect(fill_rect); 56 path.addRRect(fill_rect);
57 57
58 canvas->DrawPath(path, paint); 58 canvas->DrawPath(path, paint);
59 } 59 }
60 60
61 } // namespace views 61 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/style/mac/combobox_background_mac.h ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698