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

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

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix RTL support 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
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/controls/combobox/combobox.h"
tapted 2016/04/21 06:06:46 can this be removed now? (or replaced with view.h?
Elly Fong-Jones 2016/04/21 15:30:26 Done.
12 #include "ui/views/view.h" 13 #include "ui/views/view.h"
13 14
14 using ui::NativeThemeMac; 15 using ui::NativeThemeMac;
15 16
16 namespace views { 17 namespace views {
17 18
18 ComboboxBackgroundMac::ComboboxBackgroundMac() {} 19 ComboboxBackgroundMac::ComboboxBackgroundMac(int width) : width_(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::ScopedCanvas scoped_canvas(canvas);
25 26
26 gfx::RectF bounds(combobox->GetLocalBounds()); 27 if (base::i18n::IsRTL()) {
tapted 2016/04/21 06:06:46 Should we plonk this on gfx::ScopedCanvas - Maybe
Elly Fong-Jones 2016/04/21 15:30:26 Done.
28 canvas->Translate(gfx::Vector2d(bounds.width(), 0));
29 canvas->Scale(-1, 1);
30 }
31
27 // Inset the left side far enough to draw only the arrow button, and inset the 32 // 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 33 // other three sides by half a pixel so the edge of the background doesn't
29 // paint outside the border. 34 // paint outside the border.
30 bounds.Inset(bounds.width() - combobox->GetArrowButtonWidth(), 0.5, 0.5, 0.5); 35 bounds.Inset(bounds.width() - width_, 0.5, 0.5, 0.5);
31 36
32 // TODO(tapted): Check whether the Widget is active, and use the NORMAL 37 // TODO(tapted): Check whether the Widget is active, and use the NORMAL
33 // BackgroundType if it is inactive. Handling this properly also requires the 38 // BackgroundType if it is inactive. Handling this properly also requires the
34 // control to observe the Widget for activation changes and invalidate. 39 // control to observe the Widget for activation changes and invalidate.
35 NativeThemeMac::ButtonBackgroundType type = 40 NativeThemeMac::ButtonBackgroundType type =
36 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED; 41 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED;
37 if (!combobox->enabled()) 42 if (!view->enabled())
38 type = NativeThemeMac::ButtonBackgroundType::DISABLED; 43 type = NativeThemeMac::ButtonBackgroundType::DISABLED;
39 44
40 SkPaint paint; 45 SkPaint paint;
41 paint.setShader( 46 paint.setShader(
42 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height())); 47 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height()));
43 paint.setStyle(SkPaint::kFill_Style); 48 paint.setStyle(SkPaint::kFill_Style);
44 paint.setAntiAlias(true); 49 paint.setAntiAlias(true);
45 50
46 SkPoint no_curve = SkPoint::Make(0, 0); 51 SkPoint no_curve = SkPoint::Make(0, 0);
47 SkPoint curve = SkPoint::Make( 52 SkPoint curve = SkPoint::Make(
48 ui::NativeThemeMac::kComboboxCornerRadius, 53 ui::NativeThemeMac::kComboboxCornerRadius,
49 ui::NativeThemeMac::kComboboxCornerRadius); 54 ui::NativeThemeMac::kComboboxCornerRadius);
50 SkVector curves[4] = { no_curve, curve, curve, no_curve }; 55 SkVector curves[4] = { no_curve, curve, curve, no_curve };
51 56
52 SkRRect fill_rect; 57 SkRRect fill_rect;
53 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); 58 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves);
54 59
55 SkPath path; 60 SkPath path;
56 path.addRRect(fill_rect); 61 path.addRRect(fill_rect);
57 62
58 canvas->DrawPath(path, paint); 63 canvas->DrawPath(path, paint);
59 } 64 }
60 65
61 } // namespace views 66 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698