File: layout_theme.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 (290 lines) | stat: -rw-r--r-- 12,236 bytes parent folder | download | duplicates (3)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
 * This file is part of the theme implementation for form controls in WebCore.
 *
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_THEME_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_THEME_H_

#include "base/time/time.h"
#include "third_party/blink/public/mojom/frame/color_scheme.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/html/forms/input_type.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/theme_types.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/geometry/size.h"

namespace blink {

class ComputedStyle;
class ComputedStyleBuilder;
class Element;
class File;
class LocalFrame;
class Node;
class ThemePainter;

class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
  USING_FAST_MALLOC(LayoutTheme);

 protected:
  LayoutTheme();

 public:
  virtual ~LayoutTheme() = default;

  static LayoutTheme& GetTheme();

  virtual ThemePainter& Painter() = 0;

  // This method is called whenever style has been computed for an element and
  // the appearance property has been set to a value other than "none".
  // The theme should map in all of the appropriate metrics and defaults given
  // the contents of the style. This includes sophisticated operations like
  // selection of control size based off the font, the disabling of appearance
  // when certain other properties like "border" are set, or if the appearance
  // is not supported by the theme.
  void AdjustStyle(const Element*, ComputedStyleBuilder&);

  // The remaining methods should be implemented by the platform-specific
  // portion of the theme, e.g., layout_theme_mac.mm for macOS.

  // These methods return the theme's extra style sheets rules, to let each
  // platform adjust the default CSS rules in html.css or quirks.css
  virtual String ExtraDefaultStyleSheet();
  virtual String ExtraFullscreenStyleSheet();

  // Whether or not the control has been styled enough by the author to disable
  // the native appearance.
  virtual bool IsControlStyled(AppearanceValue appearance,
                               const ComputedStyleBuilder&) const;

  bool ShouldDrawDefaultFocusRing(const Node*, const ComputedStyle&) const;

  // A method asking if the platform is able to show a calendar picker for a
  // given input type.
  virtual bool SupportsCalendarPicker(InputType::Type) const;

  // Text selection colors.
  Color ActiveSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  Color InactiveSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  Color ActiveSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  Color InactiveSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual void SetSelectionColors(Color active_background_color,
                                  Color active_foreground_color,
                                  Color inactive_background_color,
                                  Color inactive_foreground_color) {}

  // List box selection colors
  Color ActiveListBoxSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  Color ActiveListBoxSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  Color InactiveListBoxSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  Color InactiveListBoxSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;

  virtual Color PlatformSpellingMarkerUnderlineColor() const;
  virtual Color PlatformGrammarMarkerUnderlineColor() const;

  Color PlatformActiveSpellingMarkerHighlightColor() const;

  // Highlight and text colors for TextMatches.
  Color PlatformTextSearchHighlightColor(
      bool active_match,
      bool in_forced_colors,
      mojom::blink::ColorScheme color_scheme,
      const ui::ColorProvider* color_provider,
      bool is_in_web_app_scope) const;
  Color PlatformTextSearchColor(bool active_match,
                                bool in_forced_colors,
                                mojom::blink::ColorScheme color_scheme,
                                const ui::ColorProvider* color_provider,
                                bool is_in_web_app_scope) const;

  virtual Color FocusRingColor(mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformFocusRingColor() const { return Color(0, 0, 0); }
  void SetCustomFocusRingColor(const Color&);
  static Color TapHighlightColor();

  virtual Color PlatformTapHighlightColor() const {
    return LayoutTheme::kDefaultTapHighlightColor;
  }
  virtual Color PlatformDefaultCompositionBackgroundColor() const {
    return kDefaultCompositionBackgroundColor;
  }
  void PlatformColorsDidChange();
  virtual void ColorSchemeDidChange();
  void ColorProvidersDidChange();

  void SetCaretBlinkInterval(base::TimeDelta);
  virtual base::TimeDelta CaretBlinkInterval() const;

  // System colors for CSS.
  virtual Color SystemColor(CSSValueID,
                            mojom::blink::ColorScheme color_scheme,
                            const ui::ColorProvider* color_provider,
                            bool is_in_web_app_scope) const;

  virtual void AdjustSliderThumbSize(ComputedStyleBuilder&) const;

  virtual int PopupInternalPaddingStart(const ComputedStyle&) const {
    return 0;
  }
  virtual int PopupInternalPaddingEnd(LocalFrame*, const ComputedStyle&) const {
    return 0;
  }
  virtual int PopupInternalPaddingTop(const ComputedStyle&) const { return 0; }
  virtual int PopupInternalPaddingBottom(const ComputedStyle&) const {
    return 0;
  }

  // Returns size of one slider tick mark for a horizontal track.
  // For vertical tracks we rotate it and use it. i.e. Width is always length
  // along the track.
  virtual gfx::Size SliderTickSize() const = 0;
  // Returns the distance of slider tick origin from the slider track center.
  virtual int SliderTickOffsetFromTrackCenter() const = 0;

  // Functions for <select> elements.
  virtual bool DelegatesMenuListRendering() const;
  // This function has no effect for LayoutThemeAndroid, of which
  // DelegatesMenuListRendering() always returns true.
  void SetDelegatesMenuListRenderingForTesting(bool flag);
  virtual bool PopsMenuByArrowKeys() const { return false; }
  virtual bool PopsMenuByReturnKey() const { return true; }

  virtual String DisplayNameForFile(const File& file) const;

  virtual bool SupportsSelectionForegroundColors() const { return true; }

  // Adjust style as per platform selection.
  virtual void AdjustControlPartStyle(ComputedStyleBuilder&);

  virtual bool IsAccentColorCustomized(
      mojom::blink::ColorScheme color_scheme) const;

  // GetSystemAccentColor returns transparent unless there is a special value
  // from the OS color scheme.
  virtual Color GetSystemAccentColor(
      mojom::blink::ColorScheme color_scheme) const;

  // GetAccentColorOrDefault will return GetAccentColor if there is a value from
  // the OS and if it is within an installed WebApp scope, otherwise it will
  // return the default accent color.
  Color GetAccentColorOrDefault(mojom::blink::ColorScheme color_scheme,
                                bool is_in_web_app_scope) const;
  // GetAccentColorText returns black or white depending on which can be
  // rendered with enough contrast on the result of GetAccentColorOrDefault.
  Color GetAccentColorText(mojom::blink::ColorScheme color_scheme,
                           bool is_in_web_app_scope) const;

  virtual Color SystemHighlightFromColorProvider(
      mojom::blink::ColorScheme color_scheme,
      const ui::ColorProvider* color_provider) const;

 protected:
  // The platform selection color.
  virtual Color PlatformActiveSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformInactiveSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformActiveSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformInactiveSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;

  virtual Color PlatformActiveListBoxSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformInactiveListBoxSelectionBackgroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformActiveListBoxSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;
  virtual Color PlatformInactiveListBoxSelectionForegroundColor(
      mojom::blink::ColorScheme color_scheme) const;

  // Methods for each appearance value.
  virtual void AdjustCheckboxStyle(ComputedStyleBuilder&) const;
  virtual void AdjustRadioStyle(ComputedStyleBuilder&) const;

  virtual void AdjustButtonStyle(ComputedStyleBuilder&) const;
  virtual void AdjustInnerSpinButtonStyle(ComputedStyleBuilder&) const;

  virtual void AdjustMenuListStyle(ComputedStyleBuilder&) const;
  virtual void AdjustMenuListButtonStyle(ComputedStyleBuilder&) const;
  virtual void AdjustSliderContainerStyle(const Element&,
                                          ComputedStyleBuilder&) const;
  virtual void AdjustSliderThumbStyle(ComputedStyleBuilder&) const;
  virtual void AdjustSearchFieldCancelButtonStyle(ComputedStyleBuilder&) const;

  bool HasCustomFocusRingColor() const;
  Color GetCustomFocusRingColor() const;

  Color DefaultSystemColor(CSSValueID,
                           mojom::blink::ColorScheme color_scheme,
                           const ui::ColorProvider* color_provider,
                           bool is_in_web_app_scope) const;
  Color SystemColorFromColorProvider(CSSValueID,
                                     mojom::blink::ColorScheme color_scheme,
                                     const ui::ColorProvider* color_provider,
                                     bool is_in_web_app_scope) const;

 private:
  // This function is to be implemented in your platform-specific theme
  // implementation to hand back the appropriate platform theme.
  static LayoutTheme& NativeTheme();

  AppearanceValue AdjustAppearanceWithAuthorStyle(
      AppearanceValue appearance,
      const ComputedStyleBuilder& style);

  AppearanceValue AdjustAppearanceWithElementType(const ComputedStyleBuilder&,
                                                  const Element*);

  void UpdateForcedColorsState();

  Color custom_focus_ring_color_;
  bool has_custom_focus_ring_color_;
  base::TimeDelta caret_blink_interval_ = base::Milliseconds(500);

  bool delegates_menu_list_rendering_ = false;

  // This color is expected to be drawn on a semi-transparent overlay,
  // making it more transparent than its alpha value indicates.
  static constexpr Color kDefaultTapHighlightColor =
      Color::FromRGBA32(0x66000000);

  static constexpr Color kDefaultCompositionBackgroundColor =
      Color::FromRGBA32(0xFFFFDD55);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_THEME_H_