| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/style/mac/combobox_background_mac.h" |
| 6 |
| 7 #include "third_party/skia/include/core/SkPath.h" |
| 8 #include "third_party/skia/include/core/SkRRect.h" |
| 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/native_theme/native_theme_mac.h" |
| 11 #include "ui/views/controls/combobox/combobox.h" |
| 12 #include "ui/views/view.h" |
| 13 |
| 14 namespace views { |
| 15 |
| 16 ComboboxBackgroundMac::ComboboxBackgroundMac() {} |
| 17 |
| 18 ComboboxBackgroundMac::~ComboboxBackgroundMac() {} |
| 19 |
| 20 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const { |
| 21 DCHECK_EQ(view->GetClassName(), Combobox::kViewClassName); |
| 22 Combobox* combobox = static_cast<Combobox*>(view); |
| 23 |
| 24 gfx::RectF bounds(combobox->GetLocalBounds()); |
| 25 // 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 |
| 27 // paint outside the border. |
| 28 bounds.Inset(bounds.width() - combobox->GetArrowButtonWidth(), 0.5, 0.5, 0.5); |
| 29 |
| 30 ui::NativeTheme::State state = ui::NativeTheme::kNormal; |
| 31 if (!combobox->enabled()) |
| 32 state = ui::NativeTheme::kDisabled; |
| 33 |
| 34 skia::RefPtr<SkShader> shader = |
| 35 ui::NativeThemeMac::GetButtonBackgroundShader( |
| 36 state, |
| 37 bounds.height()); |
| 38 SkPaint paint; |
| 39 paint.setShader(shader.get()); |
| 40 paint.setStyle(SkPaint::kFill_Style); |
| 41 paint.setAntiAlias(true); |
| 42 |
| 43 SkPoint no_curve = SkPoint::Make(0, 0); |
| 44 SkPoint curve = SkPoint::Make( |
| 45 ui::NativeThemeMac::kComboboxCornerRadius, |
| 46 ui::NativeThemeMac::kComboboxCornerRadius); |
| 47 SkVector curves[4] = { no_curve, curve, curve, no_curve }; |
| 48 |
| 49 SkRRect fill_rect; |
| 50 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); |
| 51 |
| 52 SkPath path; |
| 53 path.addRRect(fill_rect); |
| 54 |
| 55 canvas->DrawPath(path, paint); |
| 56 } |
| 57 |
| 58 } // namespace views |
| OLD | NEW |