| 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/gfx/scoped_canvas.h" | |
| 11 #include "ui/native_theme/native_theme_mac.h" | |
| 12 #include "ui/views/view.h" | |
| 13 | |
| 14 using ui::NativeThemeMac; | |
| 15 | |
| 16 namespace views { | |
| 17 | |
| 18 ComboboxBackgroundMac::ComboboxBackgroundMac(int container_width) | |
| 19 : container_width_(container_width) {} | |
| 20 | |
| 21 ComboboxBackgroundMac::~ComboboxBackgroundMac() {} | |
| 22 | |
| 23 void ComboboxBackgroundMac::Paint(gfx::Canvas* canvas, View* view) const { | |
| 24 gfx::RectF bounds(view->GetLocalBounds()); | |
| 25 gfx::ScopedRTLFlipCanvas scoped_canvas(canvas, view->width()); | |
| 26 | |
| 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 | |
| 29 // paint outside the border. | |
| 30 // Disabled comboboxes do not have a separate color for the arrow container; | |
| 31 // instead, the entire combobox is drawn with the disabled background shader. | |
| 32 if (view->enabled()) { | |
| 33 bounds.Inset(bounds.width() - container_width_, 0.5, 0.5, 0.5); | |
| 34 } else { | |
| 35 bounds.Inset(0.5, 0.5); | |
| 36 } | |
| 37 | |
| 38 // TODO(tapted): Check whether the Widget is active, and use the NORMAL | |
| 39 // BackgroundType if it is inactive. Handling this properly also requires the | |
| 40 // control to observe the Widget for activation changes and invalidate. | |
| 41 NativeThemeMac::ButtonBackgroundType type = | |
| 42 NativeThemeMac::ButtonBackgroundType::HIGHLIGHTED; | |
| 43 if (!view->enabled()) | |
| 44 type = NativeThemeMac::ButtonBackgroundType::DISABLED; | |
| 45 | |
| 46 SkPaint paint; | |
| 47 paint.setShader( | |
| 48 NativeThemeMac::GetButtonBackgroundShader(type, bounds.height())); | |
| 49 paint.setStyle(SkPaint::kFill_Style); | |
| 50 paint.setAntiAlias(true); | |
| 51 | |
| 52 SkPoint no_curve = SkPoint::Make(0, 0); | |
| 53 SkPoint curve = SkPoint::Make( | |
| 54 ui::NativeThemeMac::kButtonCornerRadius, | |
| 55 ui::NativeThemeMac::kButtonCornerRadius); | |
| 56 SkVector curves[4] = { no_curve, curve, curve, no_curve }; | |
| 57 | |
| 58 SkRRect fill_rect; | |
| 59 if (view->enabled()) | |
| 60 fill_rect.setRectRadii(gfx::RectFToSkRect(bounds), curves); | |
| 61 else | |
| 62 fill_rect.setRectXY(gfx::RectFToSkRect(bounds), curve.fX, curve.fY); | |
| 63 | |
| 64 SkPath path; | |
| 65 path.addRRect(fill_rect); | |
| 66 | |
| 67 canvas->DrawPath(path, paint); | |
| 68 } | |
| 69 | |
| 70 } // namespace views | |
| OLD | NEW |