File: LayoutTheme.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (299 lines) | stat: -rw-r--r-- 11,994 bytes parent folder | download
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
291
292
293
294
295
296
297
298
299
/*
 * 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 LayoutTheme_h
#define LayoutTheme_h

#include "core/CSSValueKeywords.h"
#include "core/CoreExport.h"
#include "platform/ThemeTypes.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontTraits.h"
#include "platform/graphics/Color.h"
#include "platform/scroll/ScrollTypes.h"
#include "platform/text/PlatformLocale.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/text/WTFString.h"

namespace blink {

class ComputedStyle;
class Element;
class FileList;
class HostWindow;
class HTMLInputElement;
class LayoutObject;
class Theme;
class ThemePainter;

class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
 protected:
  explicit LayoutTheme(Theme*);

 public:
  virtual ~LayoutTheme() {}

  static LayoutTheme& theme();

  virtual ThemePainter& painter() = 0;

  // This function is called after associated WebThemeEngine instance
  // was replaced. This is called only in tests.
  virtual void didChangeThemeEngine() {}

  static void setSizeIfAuto(ComputedStyle&, const IntSize&);

  // 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(ComputedStyle&, Element*);

  // The remaining methods should be implemented by the platform-specific
  // portion of the theme, e.g., LayoutThemeMac.cpp for Mac OS X.

  // These methods return the theme's extra style sheets rules, to let each
  // platform adjust the default CSS rules in html.css, quirks.css or
  // mediaControls.css.
  virtual String extraDefaultStyleSheet();
  virtual String extraQuirksStyleSheet() { return String(); }
  virtual String extraMediaControlsStyleSheet() { return String(); }
  virtual String extraFullscreenStyleSheet() { return String(); }

  // A method to obtain the baseline position for a "leaf" control. This will
  // only be used if a baseline position cannot be determined by examining child
  // content. Checkboxes and radio buttons are examples of controls that need to
  // do this.
  virtual int baselinePosition(const LayoutObject*) const;

  // A method for asking if a control is a container or not.  Leaf controls have
  // to have some special behavior (like the baseline position API above).
  bool isControlContainer(ControlPart) const;

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

  // Some controls may spill out of their containers (e.g., the check on an OSX
  // 10.9 checkbox). Add this "visual overflow" to the object's border box rect.
  virtual void addVisualOverflow(const LayoutObject&, IntRect& borderBox);

  // This method is called whenever a control state changes on a particular
  // themed object, e.g., the mouse becomes pressed or a control becomes
  // disabled. The ControlState parameter indicates which state has changed
  // (from having to not having, or vice versa).
  bool controlStateChanged(LayoutObject&, ControlState) const;

  bool shouldDrawDefaultFocusRing(const LayoutObject&) const;

  // A method asking if the theme's controls actually care about redrawing when
  // hovered.
  virtual bool supportsHover(const ComputedStyle&) const { return false; }

  // A method asking if the platform is able to show a calendar picker for a
  // given input type.
  virtual bool supportsCalendarPicker(const AtomicString&) const;

  // Text selection colors.
  Color activeSelectionBackgroundColor() const;
  Color inactiveSelectionBackgroundColor() const;
  Color activeSelectionForegroundColor() const;
  Color inactiveSelectionForegroundColor() const;

  // List box selection colors
  Color activeListBoxSelectionBackgroundColor() const;
  Color activeListBoxSelectionForegroundColor() const;
  Color inactiveListBoxSelectionBackgroundColor() const;
  Color inactiveListBoxSelectionForegroundColor() const;

  // Highlight and text colors for TextMatches.
  Color platformTextSearchHighlightColor(bool activeMatch) const;
  Color platformTextSearchColor(bool activeMatch) const;

  Color focusRingColor() const;
  virtual Color platformFocusRingColor() const { return Color(0, 0, 0); }
  void setCustomFocusRingColor(const Color&);
  static Color tapHighlightColor();
  virtual Color platformTapHighlightColor() const {
    return LayoutTheme::defaultTapHighlightColor;
  }
  virtual Color platformDefaultCompositionBackgroundColor() const {
    return defaultCompositionBackgroundColor;
  }
  virtual void platformColorsDidChange();

  void setCaretBlinkInterval(double);
  virtual double caretBlinkInterval() const;

  // System fonts and colors for CSS.
  virtual void systemFont(CSSValueID systemFontID,
                          FontStyle&,
                          FontWeight&,
                          float& fontSize,
                          AtomicString& fontFamily) const = 0;
  void systemFont(CSSValueID systemFontID, FontDescription&);
  virtual Color systemColor(CSSValueID) const;

  // Whether the default system font should have its average character width
  // adjusted to match MS Shell Dlg.
  virtual bool needsHackForTextControlWithFontFamily(
      const AtomicString&) const {
    return false;
  }

  virtual int minimumMenuListSize(const ComputedStyle&) const { return 0; }

  virtual void adjustSliderThumbSize(ComputedStyle&) const;

  virtual int popupInternalPaddingStart(const ComputedStyle&) const {
    return 0;
  }
  virtual int popupInternalPaddingEnd(const HostWindow*,
                                      const ComputedStyle&) const {
    return 0;
  }
  virtual int popupInternalPaddingTop(const ComputedStyle&) const { return 0; }
  virtual int popupInternalPaddingBottom(const ComputedStyle&) const {
    return 0;
  }

  virtual ScrollbarControlSize scrollbarControlSizeForPart(ControlPart) {
    return RegularScrollbar;
  }

  virtual void adjustProgressBarBounds(ComputedStyle& style) const {}

  // Returns the repeat interval of the animation for the progress bar.
  virtual double animationRepeatIntervalForProgressBar() const;
  // Returns the duration of the animation for the progress bar.
  virtual double animationDurationForProgressBar() const;

  // Media controls
  String formatMediaControlsTime(float time) const;
  String formatMediaControlsCurrentTime(float currentTime,
                                        float duration) const;

  // 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 IntSize sliderTickSize() const = 0;
  // Returns the distance of slider tick origin from the slider track center.
  virtual int sliderTickOffsetFromTrackCenter() const = 0;

  virtual bool shouldHaveSpinButton(HTMLInputElement*) const;

  // Functions for <select> elements.
  virtual bool delegatesMenuListRendering() const { return false; }
  virtual bool popsMenuByArrowKeys() const { return false; }
  virtual bool popsMenuBySpaceKey() const { return false; }
  virtual bool popsMenuByReturnKey() const { return false; }
  virtual bool popsMenuByAltDownUpOrF4Key() const { return false; }

  virtual String fileListNameForWidth(Locale&,
                                      const FileList*,
                                      const Font&,
                                      int width) const;

  virtual bool shouldOpenPickerWithF4Key() const;

  virtual bool supportsSelectionForegroundColors() const { return true; }

  virtual bool isModalColorChooser() const { return true; }

  virtual bool shouldUseFallbackTheme(const ComputedStyle&) const;

 protected:
  // The platform selection color.
  virtual Color platformActiveSelectionBackgroundColor() const;
  virtual Color platformInactiveSelectionBackgroundColor() const;
  virtual Color platformActiveSelectionForegroundColor() const;
  virtual Color platformInactiveSelectionForegroundColor() const;

  virtual Color platformActiveListBoxSelectionBackgroundColor() const;
  virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
  virtual Color platformActiveListBoxSelectionForegroundColor() const;
  virtual Color platformInactiveListBoxSelectionForegroundColor() const;

  virtual bool themeDrawsFocusRing(const ComputedStyle&) const = 0;

  // Methods for each appearance value.
  virtual void adjustCheckboxStyle(ComputedStyle&) const;
  virtual void setCheckboxSize(ComputedStyle&) const {}

  virtual void adjustRadioStyle(ComputedStyle&) const;
  virtual void setRadioSize(ComputedStyle&) const {}

  virtual void adjustButtonStyle(ComputedStyle&) const;
  virtual void adjustInnerSpinButtonStyle(ComputedStyle&) const;

  virtual void adjustMenuListStyle(ComputedStyle&, Element*) const;
  virtual void adjustMenuListButtonStyle(ComputedStyle&, Element*) const;
  virtual void adjustSliderContainerStyle(ComputedStyle&, Element*) const;
  virtual void adjustSliderThumbStyle(ComputedStyle&) const;
  virtual void adjustSearchFieldStyle(ComputedStyle&) const;
  virtual void adjustSearchFieldCancelButtonStyle(ComputedStyle&) const;
  void adjustStyleUsingFallbackTheme(ComputedStyle&);
  void adjustCheckboxStyleUsingFallbackTheme(ComputedStyle&) const;
  void adjustRadioStyleUsingFallbackTheme(ComputedStyle&) const;

  bool hasPlatformTheme() const { return m_platformTheme; }

 public:
  // Methods for state querying
  static ControlStates controlStatesForLayoutObject(const LayoutObject&);
  static bool isActive(const LayoutObject&);
  static bool isChecked(const LayoutObject&);
  static bool isIndeterminate(const LayoutObject&);
  static bool isEnabled(const LayoutObject&);
  static bool isFocused(const LayoutObject&);
  static bool isPressed(const LayoutObject&);
  static bool isSpinUpButtonPartPressed(const LayoutObject&);
  static bool isHovered(const LayoutObject&);
  static bool isSpinUpButtonPartHovered(const LayoutObject&);
  static bool isReadOnlyControl(const LayoutObject&);

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

  Color m_customFocusRingColor;
  bool m_hasCustomFocusRingColor;
  double m_caretBlinkInterval = 0.5;

  // This color is expected to be drawn on a semi-transparent overlay,
  // making it more transparent than its alpha value indicates.
  static const RGBA32 defaultTapHighlightColor = 0x66000000;

  static const RGBA32 defaultCompositionBackgroundColor = 0xFFFFDD55;

  Theme* m_platformTheme;  // The platform-specific theme.
};

}  // namespace blink

#endif  // LayoutTheme_h