File: native_theme_fluent.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 (132 lines) | stat: -rw-r--r-- 5,157 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
122
123
124
125
126
127
128
129
130
131
132
// 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_NATIVE_THEME_NATIVE_THEME_FLUENT_H_
#define UI_NATIVE_THEME_NATIVE_THEME_FLUENT_H_

#include <optional>

#include "base/component_export.h"
#include "ui/native_theme/native_theme_base.h"

namespace gfx {
class Rect;
class RectF;
}  // namespace gfx

template <typename T>
class sk_sp;
class SkTypeface;

namespace ui {

class COMPONENT_EXPORT(NATIVE_THEME) NativeThemeFluent
    : public NativeThemeBase {
 public:
  explicit NativeThemeFluent(bool should_only_use_dark_colors);

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

  ~NativeThemeFluent() override;

  static NativeThemeFluent* web_instance();

  void PaintArrowButton(
      cc::PaintCanvas* canvas,
      const ColorProvider* color_provider,
      const gfx::Rect& rect,
      Part direction,
      State state,
      ColorScheme color_scheme,
      bool in_forced_colors,
      const ScrollbarArrowExtraParams& extra_params) const override;
  void PaintScrollbarTrack(cc::PaintCanvas* canvas,
                           const ColorProvider* color_provider,
                           Part part,
                           State state,
                           const ScrollbarTrackExtraParams& extra_params,
                           const gfx::Rect& rect,
                           ColorScheme color_scheme,
                           bool in_forced_colors) const override;
  void PaintScrollbarThumb(cc::PaintCanvas* canvas,
                           const ColorProvider* color_provider,
                           Part part,
                           State state,
                           const gfx::Rect& rect,
                           const ScrollbarThumbExtraParams& extra_params,
                           ColorScheme color_scheme) const override;
  gfx::Insets GetScrollbarSolidColorThumbInsets(Part part) const override;
  SkColor4f GetScrollbarThumbColor(
      const ui::ColorProvider& color_provider,
      State state,
      const ScrollbarThumbExtraParams& extra) const override;
  void PaintScrollbarCorner(cc::PaintCanvas* canvas,
                            const ColorProvider* color_provider,
                            State state,
                            const gfx::Rect& rect,
                            const ScrollbarTrackExtraParams& extra_params,
                            ColorScheme color_scheme) const override;
  gfx::Size GetPartSize(Part part,
                        State state,
                        const ExtraParams& extra) const override;
  int GetPaintedScrollbarTrackInset() const override;
  float GetContrastRatioForState(State state, Part part) const override;

 private:
  friend class NativeThemeFluentTest;

  void PaintButton(cc::PaintCanvas* canvas,
                   const ColorProvider* color_provider,
                   const gfx::Rect& rect,
                   Part direction,
                   ColorScheme color_scheme,
                   bool in_forced_colors,
                   const ScrollbarArrowExtraParams& extra_params) const;
  void PaintArrow(cc::PaintCanvas* canvas,
                  const ColorProvider* color_provider,
                  const gfx::Rect& rect,
                  Part part,
                  State state,
                  ColorScheme color_scheme,
                  const ScrollbarArrowExtraParams& extra_params) const;

  // Calculates and returns the position and dimensions of the scaled arrow rect
  // within the scrollbar button rect. The goal is to keep the arrow in the
  // center of the button with the applied kFluentScrollbarArrowOffset. See
  // OffsetArrowRect method for more details.
  gfx::RectF GetArrowRect(const gfx::Rect& rect, Part part, State state) const;

  // An arrow rect is a square. Returns the side length based on the state and
  // the font availability.
  int GetArrowSideLength(State state) const;

  // By Fluent design, arrow rect is offset from the center to the side opposite
  // from the track rect border by kFluentScrollbarArrowOffset px.
  void OffsetArrowRect(gfx::RectF& arrow_rect,
                       Part part,
                       int max_arrow_rect_side) const;

  // Returns true if the font with arrow icons is present on the device.
  bool ArrowIconsAvailable() const {
    return typeface_.has_value() && typeface_.value().get();
  }

  const char* GetArrowCodePointForScrollbarPart(Part part) const;

  // Used by Overlay Fluent scrollbars to paint buttons with rounded corners.
  void PaintRoundedButton(cc::PaintCanvas* canvas,
                          SkRect rect,
                          cc::PaintFlags paint_flags,
                          NativeTheme::Part direction) const;

  // The value stores a shared pointer to SkTypeface with the font family, which
  // contains arrow icons. The typeface is lazily loaded the first time
  // PaintArrow is called.
  mutable std::optional<sk_sp<SkTypeface>> typeface_;
};

}  // namespace ui

#endif  // UI_NATIVE_THEME_NATIVE_THEME_FLUENT_H_