File: background.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (121 lines) | stat: -rw-r--r-- 4,076 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_VIEWS_BACKGROUND_H_
#define UI_VIEWS_BACKGROUND_H_

#include <stddef.h>

#include <memory>
#include <optional>

#include "build/build_config.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/themed_vector_icon.h"
#include "ui/color/color_id.h"
#include "ui/color/color_variant.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/views_export.h"

namespace gfx {
class Canvas;
}  // namespace gfx

namespace ui {
class ThemedVectorIcon;
}  // namespace ui

namespace views {

class Painter;
class View;

/////////////////////////////////////////////////////////////////////////////
//
// Background class
//
// A background implements a way for views to paint a background. The
// background can be either solid or based on a gradient. Of course,
// Background can be subclassed to implement various effects.
//
// Any View can have a background. See View::SetBackground() and
// View::OnPaintBackground()
//
/////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT Background {
 public:
  Background();
  Background(const Background&) = delete;
  Background& operator=(const Background&) = delete;
  virtual ~Background();

  // Render the background for the provided view
  virtual void Paint(gfx::Canvas* canvas, View* view) const = 0;

  // This is called by the View on which it is attached. This is overridden for
  // subclasses that depend on theme colors.
  virtual void OnViewThemeChanged(View* view);

  // Returns the rounded corner radii of the background. Returns `std::nullopt`
  // by default.
  virtual std::optional<gfx::RoundedCornersF> GetRoundedCornerRadii() const;

  // Returns the "background color".  After resolution, this color is the color
  // for solid backgrounds; for gradient backgrounds, it's the midpoint of the
  // gradient; for painter backgrounds, this is not useful (returns a default
  // color).
  ui::ColorVariant color() const { return color_; }

  // Set a solid color to be used when drawing backgrounds.
  virtual void SetColor(ui::ColorVariant color);

 private:
  ui::ColorVariant color_;
};

// Creates a background that fills the canvas in the specified color.
VIEWS_EXPORT std::unique_ptr<Background> CreateSolidBackground(
    ui::ColorVariant color);

// Creates a background that fills the canvas with rounded corners.
// If using a rounded rect border as well, pass its radius as `radius` and its
// thickness as `for_border_thickness`.  This will inset the background properly
// so it doesn't bleed through the border.
VIEWS_EXPORT std::unique_ptr<Background> CreateRoundedRectBackground(
    ui::ColorVariant color,
    float radius,
    int for_border_thickness = 0);

// Same as above except each corner radius can be different and customized.
VIEWS_EXPORT std::unique_ptr<Background> CreateRoundedRectBackground(
    ui::ColorVariant color,
    float top_radius,
    float bottom_radius,
    int for_border_thickness = 0);

// Same as above except each corner radius can be different and customized.
VIEWS_EXPORT std::unique_ptr<Background> CreateRoundedRectBackground(
    ui::ColorVariant color,
    const gfx::RoundedCornersF& radii,
    int for_border_thickness = 0);

// Same as above except the background is inset by the specified insets.
VIEWS_EXPORT std::unique_ptr<Background> CreateRoundedRectBackground(
    ui::ColorVariant color,
    const gfx::RoundedCornersF& radii,
    const gfx::Insets& insets);

// Creates a background from the specified Painter.
VIEWS_EXPORT std::unique_ptr<Background> CreateBackgroundFromPainter(
    std::unique_ptr<Painter> painter);

// Creates a background from the specified ThemedVectorIcon.
VIEWS_EXPORT std::unique_ptr<Background> CreateThemedVectorIconBackground(
    const ui::ThemedVectorIcon& icon);

}  // namespace views

#endif  // UI_VIEWS_BACKGROUND_H_