ink_drop_painted_layer_delegates.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Copyright 2015 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. #ifndef UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_
  5. #define UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_
  6. #include <vector>
  7. #include "third_party/skia/include/core/SkColor.h"
  8. #include "ui/compositor/layer_delegate.h"
  9. #include "ui/gfx/geometry/rect_f.h"
  10. #include "ui/gfx/geometry/size_f.h"
  11. #include "ui/gfx/geometry/vector2d_f.h"
  12. #include "ui/gfx/shadow_value.h"
  13. #include "ui/views/views_export.h"
  14. namespace views {
  15. // Base ui::LayerDelegate stub that can be extended to paint shapes of a
  16. // specific color.
  17. class VIEWS_EXPORT BasePaintedLayerDelegate : public ui::LayerDelegate {
  18. public:
  19. BasePaintedLayerDelegate(const BasePaintedLayerDelegate&) = delete;
  20. BasePaintedLayerDelegate& operator=(const BasePaintedLayerDelegate&) = delete;
  21. ~BasePaintedLayerDelegate() override;
  22. // Defines the bounds of the layer that the delegate will paint into.
  23. virtual gfx::RectF GetPaintedBounds() const = 0;
  24. // Defines how to place the layer by providing an offset from the origin of
  25. // the parent to the visual center of the layer.
  26. virtual gfx::Vector2dF GetCenteringOffset() const;
  27. // ui::LayerDelegate:
  28. void OnDeviceScaleFactorChanged(float old_device_scale_factor,
  29. float new_device_scale_factor) override;
  30. SkColor color() const { return color_; }
  31. void set_color(SkColor color) { color_ = color; }
  32. protected:
  33. explicit BasePaintedLayerDelegate(SkColor color);
  34. private:
  35. // The color to paint.
  36. SkColor color_;
  37. };
  38. // A BasePaintedLayerDelegate that paints a circle of a specified color and
  39. // radius.
  40. class VIEWS_EXPORT CircleLayerDelegate : public BasePaintedLayerDelegate {
  41. public:
  42. CircleLayerDelegate(SkColor color, int radius);
  43. CircleLayerDelegate(const CircleLayerDelegate&) = delete;
  44. CircleLayerDelegate& operator=(const CircleLayerDelegate&) = delete;
  45. ~CircleLayerDelegate() override;
  46. int radius() const { return radius_; }
  47. // BasePaintedLayerDelegate:
  48. gfx::RectF GetPaintedBounds() const override;
  49. void OnPaintLayer(const ui::PaintContext& context) override;
  50. private:
  51. // The radius of the circle.
  52. int radius_;
  53. };
  54. // A BasePaintedLayerDelegate that paints a rectangle of a specified color and
  55. // size.
  56. class VIEWS_EXPORT RectangleLayerDelegate : public BasePaintedLayerDelegate {
  57. public:
  58. RectangleLayerDelegate(SkColor color, gfx::SizeF size);
  59. RectangleLayerDelegate(const RectangleLayerDelegate&) = delete;
  60. RectangleLayerDelegate& operator=(const RectangleLayerDelegate&) = delete;
  61. ~RectangleLayerDelegate() override;
  62. const gfx::SizeF& size() const { return size_; }
  63. // BasePaintedLayerDelegate:
  64. gfx::RectF GetPaintedBounds() const override;
  65. void OnPaintLayer(const ui::PaintContext& context) override;
  66. private:
  67. // The size of the rectangle.
  68. gfx::SizeF size_;
  69. };
  70. // A BasePaintedLayerDelegate that paints a rounded rectangle of a specified
  71. // color, size and corner radius.
  72. class VIEWS_EXPORT RoundedRectangleLayerDelegate
  73. : public BasePaintedLayerDelegate {
  74. public:
  75. RoundedRectangleLayerDelegate(SkColor color,
  76. const gfx::SizeF& size,
  77. int corner_radius);
  78. RoundedRectangleLayerDelegate(const RoundedRectangleLayerDelegate&) = delete;
  79. RoundedRectangleLayerDelegate& operator=(
  80. const RoundedRectangleLayerDelegate&) = delete;
  81. ~RoundedRectangleLayerDelegate() override;
  82. const gfx::SizeF& size() const { return size_; }
  83. // BasePaintedLayerDelegate:
  84. gfx::RectF GetPaintedBounds() const override;
  85. void OnPaintLayer(const ui::PaintContext& context) override;
  86. private:
  87. // The size of the rectangle.
  88. gfx::SizeF size_;
  89. // The radius of the corners.
  90. int corner_radius_;
  91. };
  92. // A BasePaintedLayerDelegate that paints a shadow around the outside of a
  93. // specified roundrect, and also fills the round rect.
  94. class VIEWS_EXPORT BorderShadowLayerDelegate : public BasePaintedLayerDelegate {
  95. public:
  96. BorderShadowLayerDelegate(const std::vector<gfx::ShadowValue>& shadows,
  97. const gfx::Rect& shadowed_area_bounds,
  98. SkColor fill_color,
  99. int corner_radius);
  100. BorderShadowLayerDelegate(const BorderShadowLayerDelegate&) = delete;
  101. BorderShadowLayerDelegate& operator=(const BorderShadowLayerDelegate&) =
  102. delete;
  103. ~BorderShadowLayerDelegate() override;
  104. // BasePaintedLayerDelegate:
  105. gfx::RectF GetPaintedBounds() const override;
  106. gfx::Vector2dF GetCenteringOffset() const override;
  107. void OnPaintLayer(const ui::PaintContext& context) override;
  108. private:
  109. gfx::Rect GetTotalRect() const;
  110. const std::vector<gfx::ShadowValue> shadows_;
  111. // The bounds of the shadowed area.
  112. const gfx::Rect bounds_;
  113. const SkColor fill_color_;
  114. const int corner_radius_;
  115. };
  116. } // namespace views
  117. #endif // UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_