Commit 50d39d13 authored by Sajad Maysam's avatar Sajad Maysam Committed by Commit Bot

Add background with rounded corners.

Will be used to implement a scrollview that does not extend beyond the
boundaries of a widget with rounded corners. Necessary because
scrollviews paint on a layer so they will paint over the parent view's
bounds. Also similar code creating rounded backgrounds happens in a
bunch of places in the codebase and could be simplified to use a single
common background factory method (example: bubble background code).

Change-Id: Ie885ca9f71f2722680e6fb709fe3091e71ad88fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1524910
Commit-Queue: Sajad Maysam <sajadm@google.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644468}
parent 93409376
......@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "build/build_config.h"
#include "cc/paint/paint_flags.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
......@@ -39,6 +40,28 @@ class SolidBackground : public Background {
DISALLOW_COPY_AND_ASSIGN(SolidBackground);
};
// RoundedRectBackground is a filled solid colored background that has
// rounded corners.
class RoundedRectBackground : public Background {
public:
RoundedRectBackground(SkColor color, float radius) : radius_(radius) {
SetNativeControlColor(color);
}
void Paint(gfx::Canvas* canvas, View* view) const override {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setColor(get_color());
canvas->DrawRoundRect(gfx::RectF(view->GetLocalBounds()), radius_, flags);
}
private:
float radius_;
DISALLOW_COPY_AND_ASSIGN(RoundedRectBackground);
};
// ThemedSolidBackground is a solid background that stays in sync with a view's
// native theme.
class ThemedSolidBackground : public SolidBackground, public ViewObserver {
......@@ -97,6 +120,11 @@ std::unique_ptr<Background> CreateSolidBackground(SkColor color) {
return std::make_unique<SolidBackground>(color);
}
std::unique_ptr<Background> CreateRoundedRectBackground(SkColor color,
float radius) {
return std::make_unique<RoundedRectBackground>(color, radius);
}
std::unique_ptr<Background> CreateThemedSolidBackground(
View* view,
ui::NativeTheme::ColorId color_id) {
......
......@@ -67,6 +67,11 @@ class VIEWS_EXPORT Background {
// Creates a background that fills the canvas in the specified color.
VIEWS_EXPORT std::unique_ptr<Background> CreateSolidBackground(SkColor color);
// Creates a background that fills the canvas with rounded corners.
VIEWS_EXPORT std::unique_ptr<Background> CreateRoundedRectBackground(
SkColor color,
float radius);
// Creates a background that fills the canvas in the color specified by the
// view's NativeTheme and the given color identifier.
VIEWS_EXPORT std::unique_ptr<Background> CreateThemedSolidBackground(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment