File: highlight_border.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (122 lines) | stat: -rw-r--r-- 4,887 bytes parent folder | download | duplicates (11)
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
122
// Copyright 2022 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_HIGHLIGHT_BORDER_H_
#define UI_VIEWS_HIGHLIGHT_BORDER_H_

#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/border.h"
#include "ui/views/views_export.h"

namespace gfx {
class Rect;
}  // namespace gfx

namespace views {

constexpr int kHighlightBorderThickness = 1;

// A rounded rectangle border that has inner (highlight) and outer color.
// Useful when go/cros-launcher-spec mentions "BorderHighlight".
class VIEWS_EXPORT HighlightBorder : public views::Border {
 public:
  // TODO(crbug/1319944): Change these type names to something more descriptive.
  enum class Type {
    // The highlight border for the UI without a shadow.
    kHighlightBorderNoShadow,
    // The highlight border for the UI with a shadow.
    kHighlightBorderOnShadow,
    // TODO(b/271009119): Clean up these old types after MaterialNext is fully
    // launched.
    // A higher contrast highlight border than the `kHighlightBorder2` used
    // for floating components that do not have a shield below.
    kHighlightBorder1,
    // A less contrast highlight border for components that float above a
    // shield.
    kHighlightBorder2,
    // Has same inner border color as `kHighlightBorder1`. The outer color is
    // same in dark and light mode with low opacity. This type is mainly used
    // with `HighlightBorderLayerOverlay` whose outer border is outside the
    // window contents. For more information, refer to the comment of
    // `HighlightBorderOverlay`.
    kHighlightBorder3,
  };

  // The type of insets created by this highlight border. The insets shrink the
  // content view.
  enum class InsetsType {
    // The border does not add insets that shrink the content, so the content
    // around the edge of the view can be overlapped with the border.
    kNoInsets,
    // Insetting by half of the border size pushes the content inside the outer
    // color of the border so the content bounds is surrounded by outer color
    // of the border.
    kHalfInsets,
    // Insetting by full border size makes sure that contents in the view
    // start inside the inner color of the highlight border, so there is no
    // overlap between content.
    kFullInsets,
  };

  // Paints the highlight border onto `canvas` with given highlight and border
  // border color. Note that directly using this function won't set the insets
  // on any view so it acts like setting kNoInsets when using HighlightBorder
  // class.
  static void PaintBorderToCanvas(gfx::Canvas* canvas,
                                  SkColor highlight_color,
                                  SkColor border_color,
                                  const gfx::Rect& bounds,
                                  const gfx::RoundedCornersF& corner_radii,
                                  Type type);

  // Paints the highlight border onto `canvas` for the specified `view`. The
  // color of the border will be determined using `view`'s color provider. Note
  // that directly using this function won't set the insets on any view so it
  // acts like setting kNoInsets when using HighlightBorder class.
  static void PaintBorderToCanvas(gfx::Canvas* canvas,
                                  const views::View& view,
                                  const gfx::Rect& bounds,
                                  const gfx::RoundedCornersF& corner_radii,
                                  Type type);

  // Returns the inner highlight color used to paint highlight border.
  static SkColor GetHighlightColor(const views::View& view,
                                   HighlightBorder::Type type);

  // Returns the outer border color used to paint highlight border.
  static SkColor GetBorderColor(const views::View& view,
                                HighlightBorder::Type type);

  HighlightBorder(int corner_radius,
                  Type type,
                  InsetsType insets_type = InsetsType::kNoInsets);

  HighlightBorder(const gfx::RoundedCornersF& rounded_corners,
                  Type type,
                  InsetsType insets_type = InsetsType::kNoInsets);

  HighlightBorder(const HighlightBorder&) = delete;
  HighlightBorder& operator=(const HighlightBorder&) = delete;

  ~HighlightBorder() override = default;

  // views::Border:
  void Paint(const views::View& view, gfx::Canvas* canvas) override;
  void OnViewThemeChanged(views::View* view) override;
  gfx::Insets GetInsets() const override;
  gfx::Size GetMinimumSize() const override;

 private:
  // The rounded corners of this border.
  const gfx::RoundedCornersF rounded_corners_;

  const Type type_;

  // Used by `GetInsets()` to calculate the insets.
  const InsetsType insets_type_;
};

}  // namespace views

#endif  // UI_VIEWS_HIGHLIGHT_BORDER_H_