Commit 9ced1ed5 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Delete unused things from Painter:

- HorizontalPainter
- Painter::CreateVerticalGradient

Bug: none
Change-Id: I4070406a1dc1c557bea2a73faaf8255e2ac45e84
Reviewed-on: https://chromium-review.googlesource.com/518382
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476360}
parent 721fa86c
......@@ -75,6 +75,7 @@ component("views_examples_lib") {
deps = [
"//base",
"//cc/paint",
"//skia",
"//third_party/icu",
"//ui/base",
......
......@@ -7,12 +7,14 @@
#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "cc/paint/paint_flags.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/skia_paint_util.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/painter.h"
#include "ui/views/view.h"
using base::ASCIIToUTF16;
......@@ -30,16 +32,9 @@ class ScrollViewExample::ScrollableView : public View {
AddChildView(new RadioButton(ASCIIToUTF16("Radio Button"), 0));
}
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(width(), height());
}
void SetColor(SkColor from, SkColor to) {
Background* background = Background::CreateBackgroundPainter(
Painter::CreateVerticalGradient(from, to));
background->SetNativeControlColor(
color_utils::AlphaBlend(from, to, 128));
set_background(background);
from_color_ = from;
to_color_ = to;
}
void PlaceChildY(int index, int y) {
......@@ -48,13 +43,29 @@ class ScrollViewExample::ScrollableView : public View {
view->SetBounds(0, y, size.width(), size.height());
}
// View
void Layout() override {
PlaceChildY(0, 0);
PlaceChildY(1, height() / 2);
SizeToPreferredSize();
}
void OnPaintBackground(gfx::Canvas* canvas) override {
cc::PaintFlags flags;
flags.setShader(
gfx::CreateGradientShader(0, height(), from_color_, to_color_));
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawRect(GetLocalBounds(), flags);
}
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(width(), height());
}
private:
SkColor from_color_;
SkColor to_color_;
DISALLOW_COPY_AND_ASSIGN(ScrollableView);
};
......
......@@ -4,25 +4,13 @@
#include "ui/views/painter.h"
#include <memory>
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "cc/paint/paint_shader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/pathops/SkPathOps.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/insets_f.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/nine_image_painter.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/view.h"
......@@ -154,71 +142,6 @@ void SolidFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
canvas->DrawSolidFocusRect(rect, color_, thickness_);
}
// GradientPainter ------------------------------------------------------------
class GradientPainter : public Painter {
public:
GradientPainter(bool horizontal,
SkColor* colors,
SkScalar* pos,
size_t count);
~GradientPainter() override;
// Painter:
gfx::Size GetMinimumSize() const override;
void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
private:
// If |horizontal_| is true then the gradient is painted horizontally.
bool horizontal_;
// The gradient colors.
std::unique_ptr<SkColor[]> colors_;
// The relative positions of the corresponding gradient colors.
std::unique_ptr<SkScalar[]> pos_;
// The number of elements in |colors_| and |pos_|.
size_t count_;
DISALLOW_COPY_AND_ASSIGN(GradientPainter);
};
GradientPainter::GradientPainter(bool horizontal,
SkColor* colors,
SkScalar* pos,
size_t count)
: horizontal_(horizontal),
colors_(new SkColor[count]),
pos_(new SkScalar[count]),
count_(count) {
for (size_t i = 0; i < count_; ++i) {
pos_[i] = pos[i];
colors_[i] = colors[i];
}
}
GradientPainter::~GradientPainter() {
}
gfx::Size GradientPainter::GetMinimumSize() const {
return gfx::Size();
}
void GradientPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
cc::PaintFlags flags;
SkPoint p[2];
p[0].iset(0, 0);
if (horizontal_)
p[1].iset(size.width(), 0);
else
p[1].iset(0, size.height());
flags.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear(
p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode)));
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->sk_canvas()->drawRect(SkRect::MakeIWH(size.width(), size.height()),
flags);
}
// ImagePainter ---------------------------------------------------------------
// ImagePainter stores and paints nine images as a scalable grid.
......@@ -310,16 +233,6 @@ std::unique_ptr<Painter> Painter::CreateRoundRectWith1PxBorderPainter(
radius);
}
// static
std::unique_ptr<Painter> Painter::CreateVerticalGradient(SkColor c1,
SkColor c2) {
SkColor colors[2];
colors[0] = c1;
colors[1] = c2;
SkScalar pos[] = {0, 1};
return base::MakeUnique<GradientPainter>(false, colors, pos, 2);
}
// static
std::unique_ptr<Painter> Painter::CreateImagePainter(
const gfx::ImageSkia& image,
......@@ -364,36 +277,4 @@ std::unique_ptr<Painter> Painter::CreateSolidFocusPainter(
return base::MakeUnique<SolidFocusPainter>(color, thickness, insets);
}
// HorizontalPainter ----------------------------------------------------------
HorizontalPainter::HorizontalPainter(const int image_resource_names[]) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
for (int i = 0; i < 3; ++i)
images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia();
DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height());
DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height());
}
HorizontalPainter::~HorizontalPainter() {
}
gfx::Size HorizontalPainter::GetMinimumSize() const {
return gfx::Size(
images_[LEFT]->width() + images_[CENTER]->width() +
images_[RIGHT]->width(), images_[LEFT]->height());
}
void HorizontalPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
if (size.width() < GetMinimumSize().width())
return; // No room to paint.
canvas->DrawImageInt(*images_[LEFT], 0, 0);
canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(),
0);
canvas->TileImageInt(
*images_[CENTER], images_[LEFT]->width(), 0,
size.width() - images_[LEFT]->width() - images_[RIGHT]->width(),
images_[LEFT]->height());
}
} // namespace views
......@@ -60,10 +60,6 @@ class VIEWS_EXPORT Painter {
SkColor stroke_color,
float radius);
// TODO(estade): remove. The last client (table_header.cc) is going away soon.
static std::unique_ptr<Painter> CreateVerticalGradient(SkColor c1,
SkColor c2);
// Creates a painter that divides |image| into nine regions. The four corners
// are rendered at the size specified in insets (eg. the upper-left corner is
// rendered at 0 x 0 with a size of insets.left() x insets.top()). The center
......@@ -104,35 +100,6 @@ class VIEWS_EXPORT Painter {
DISALLOW_COPY_AND_ASSIGN(Painter);
};
// HorizontalPainter paints 3 images into a box: left, center and right. The
// left and right images are drawn to size at the left/right edges of the
// region. The center is tiled in the remaining space. All images must have the
// same height.
class VIEWS_EXPORT HorizontalPainter : public Painter {
public:
// Constructs a new HorizontalPainter loading the specified image names.
// The images must be in the order left, right and center.
explicit HorizontalPainter(const int image_resource_names[]);
~HorizontalPainter() override;
// Painter:
gfx::Size GetMinimumSize() const override;
void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
private:
// The image chunks.
enum BorderElements {
LEFT,
CENTER,
RIGHT
};
// NOTE: the images are owned by ResourceBundle. Don't free them.
const gfx::ImageSkia* images_[3];
DISALLOW_COPY_AND_ASSIGN(HorizontalPainter);
};
} // namespace views
#endif // UI_VIEWS_PAINTER_H_
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