| OLD | NEW |
| 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 width) : width_(width) {} |
| 19 | 19 |
| 20 ComboboxBackgroundMac::~ComboboxBackgroundMac() {} | 20 ComboboxBackgroundMac::~ComboboxBackgroundMac() {} |
| 21 | 21 |
| 22 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const { | 22 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const { |
| 23 DCHECK_EQ(view->GetClassName(), Combobox::kViewClassName); | 23 gfx::RectF bounds(view->GetLocalBounds()); |
| 24 Combobox* combobox = static_cast<Combobox*>(view); | 24 gfx::ScopedRTLFlipCanvas scoped_canvas(canvas, view->bounds()); |
| 25 | 25 |
| 26 gfx::RectF bounds(combobox->GetLocalBounds()); | |
| 27 // Inset the left side far enough to draw only the arrow button, and inset the | 26 // 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 | 27 // other three sides by half a pixel so the edge of the background doesn't |
| 29 // paint outside the border. | 28 // paint outside the border. |
| 30 bounds.Inset(bounds.width() - combobox->GetArrowButtonWidth(), 0.5, 0.5, 0.5); | 29 bounds.Inset(bounds.width() - width_, 0.5, 0.5, 0.5); |
| 31 | 30 |
| 32 // TODO(tapted): Check whether the Widget is active, and use the NORMAL | 31 // TODO(tapted): Check whether the Widget is active, and use the NORMAL |
| 33 // BackgroundType if it is inactive. Handling this properly also requires the | 32 // BackgroundType if it is inactive. Handling this properly also requires the |
| 34 // control to observe the Widget for activation changes and invalidate. | 33 // control to observe the Widget for activation changes and invalidate. |
| 35 NativeThemeMac::ButtonBackgroundType type = | 34 NativeThemeMac::ButtonBackgroundType type = |
| 36 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED; | 35 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED; |
| 37 if (!combobox->enabled()) | 36 if (!view->enabled()) |
| 38 type = NativeThemeMac::ButtonBackgroundType::DISABLED; | 37 type = NativeThemeMac::ButtonBackgroundType::DISABLED; |
| 39 | 38 |
| 40 SkPaint paint; | 39 SkPaint paint; |
| 41 paint.setShader( | 40 paint.setShader( |
| 42 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height())); | 41 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height())); |
| 43 paint.setStyle(SkPaint::kFill_Style); | 42 paint.setStyle(SkPaint::kFill_Style); |
| 44 paint.setAntiAlias(true); | 43 paint.setAntiAlias(true); |
| 45 | 44 |
| 46 SkPoint no_curve = SkPoint::Make(0, 0); | 45 SkPoint no_curve = SkPoint::Make(0, 0); |
| 47 SkPoint curve = SkPoint::Make( | 46 SkPoint curve = SkPoint::Make( |
| 48 ui::NativeThemeMac::kComboboxCornerRadius, | 47 ui::NativeThemeMac::kComboboxCornerRadius, |
| 49 ui::NativeThemeMac::kComboboxCornerRadius); | 48 ui::NativeThemeMac::kComboboxCornerRadius); |
| 50 SkVector curves[4] = { no_curve, curve, curve, no_curve }; | 49 SkVector curves[4] = { no_curve, curve, curve, no_curve }; |
| 51 | 50 |
| 52 SkRRect fill_rect; | 51 SkRRect fill_rect; |
| 53 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); | 52 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); |
| 54 | 53 |
| 55 SkPath path; | 54 SkPath path; |
| 56 path.addRRect(fill_rect); | 55 path.addRRect(fill_rect); |
| 57 | 56 |
| 58 canvas->DrawPath(path, paint); | 57 canvas->DrawPath(path, paint); |
| 59 } | 58 } |
| 60 | 59 |
| 61 } // namespace views | 60 } // namespace views |
| OLD | NEW |