summaryrefslogtreecommitdiffstats
path: root/widget/nsNativeBasicTheme.h
blob: 94b3cdc62e87bff0450be506e656f6fcbb26412a (plain)
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsNativeBasicTheme_h
#define nsNativeBasicTheme_h

#include "Units.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/HTMLMeterElement.h"
#include "mozilla/dom/HTMLProgressElement.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Rect.h"
#include "mozilla/gfx/Types.h"
#include "nsColorControlFrame.h"
#include "nsDateTimeControlFrame.h"
#include "nsDeviceContext.h"
#include "nsITheme.h"
#include "nsMeterFrame.h"
#include "nsNativeTheme.h"
#include "nsProgressFrame.h"
#include "nsRangeFrame.h"

namespace mozilla {
namespace widget {

static const gfx::sRGBColor sColorWhite(gfx::sRGBColor::OpaqueWhite());
static const gfx::sRGBColor sColorWhiteAlpha50(gfx::sRGBColor::White(0.5f));
static const gfx::sRGBColor sColorWhiteAlpha80(gfx::sRGBColor::White(0.8f));
static const gfx::sRGBColor sColorBlack(gfx::sRGBColor::OpaqueBlack());

static const gfx::sRGBColor sColorGrey10(
    gfx::sRGBColor::UnusualFromARGB(0xffe9e9ed));
static const gfx::sRGBColor sColorGrey10Alpha50(
    gfx::sRGBColor::UnusualFromARGB(0x7fe9e9ed));
static const gfx::sRGBColor sColorGrey20(
    gfx::sRGBColor::UnusualFromARGB(0xffd0d0d7));
static const gfx::sRGBColor sColorGrey30(
    gfx::sRGBColor::UnusualFromARGB(0xffb1b1b9));
static const gfx::sRGBColor sColorGrey40(
    gfx::sRGBColor::UnusualFromARGB(0xff8f8f9d));
static const gfx::sRGBColor sColorGrey40Alpha50(
    gfx::sRGBColor::UnusualFromARGB(0x7f8f8f9d));
static const gfx::sRGBColor sColorGrey50(
    gfx::sRGBColor::UnusualFromARGB(0xff676774));
static const gfx::sRGBColor sColorGrey50Alpha50(
    gfx::sRGBColor::UnusualFromARGB(0x7f676774));
static const gfx::sRGBColor sColorGrey60(
    gfx::sRGBColor::UnusualFromARGB(0xff484851));
static const gfx::sRGBColor sColorGrey60Alpha50(
    gfx::sRGBColor::UnusualFromARGB(0x7f484851));

static const gfx::sRGBColor sColorAccentLight(
    gfx::sRGBColor::UnusualFromARGB(0x4d008deb));
static const gfx::sRGBColor sColorAccent(
    gfx::sRGBColor::UnusualFromARGB(0xff0060df));
static const gfx::sRGBColor sColorAccentDark(
    gfx::sRGBColor::UnusualFromARGB(0xff0250bb));
static const gfx::sRGBColor sColorAccentDarker(
    gfx::sRGBColor::UnusualFromARGB(0xff054096));

static const gfx::sRGBColor sColorMeterGreen10(
    gfx::sRGBColor::UnusualFromARGB(0xff00ab60));
static const gfx::sRGBColor sColorMeterGreen20(
    gfx::sRGBColor::UnusualFromARGB(0xff056139));
static const gfx::sRGBColor sColorMeterYellow10(
    gfx::sRGBColor::UnusualFromARGB(0xffffbd4f));
static const gfx::sRGBColor sColorMeterYellow20(
    gfx::sRGBColor::UnusualFromARGB(0xffd2811e));
static const gfx::sRGBColor sColorMeterRed10(
    gfx::sRGBColor::UnusualFromARGB(0xffe22850));
static const gfx::sRGBColor sColorMeterRed20(
    gfx::sRGBColor::UnusualFromARGB(0xff810220));

static const gfx::sRGBColor sScrollbarColor(
    gfx::sRGBColor::UnusualFromARGB(0xfff0f0f0));
static const gfx::sRGBColor sScrollbarBorderColor(gfx::sRGBColor(1.0f, 1.0f,
                                                                 1.0f));
static const gfx::sRGBColor sScrollbarThumbColor(
    gfx::sRGBColor::UnusualFromARGB(0xffcdcdcd));
static const gfx::sRGBColor sScrollbarThumbColorActive(gfx::sRGBColor(0.375f,
                                                                      0.375f,
                                                                      0.375f));
static const gfx::sRGBColor sScrollbarThumbColorHover(gfx::sRGBColor(0.65f,
                                                                     0.65f,
                                                                     0.65f));
static const gfx::sRGBColor sScrollbarArrowColor(gfx::sRGBColor(0.375f, 0.375f,
                                                                0.375f));
static const gfx::sRGBColor sScrollbarArrowColorActive(gfx::sRGBColor(1.0f,
                                                                      1.0f,
                                                                      1.0f));
static const gfx::sRGBColor sScrollbarArrowColorHover(gfx::sRGBColor(0.0f, 0.0f,
                                                                     0.0f));
static const gfx::sRGBColor sScrollbarButtonColor(sScrollbarColor);
static const gfx::sRGBColor sScrollbarButtonActiveColor(gfx::sRGBColor(0.375f,
                                                                       0.375f,
                                                                       0.375f));
static const gfx::sRGBColor sScrollbarButtonHoverColor(gfx::sRGBColor(0.86f,
                                                                      0.86f,
                                                                      0.86f));

static const CSSCoord kMinimumWidgetSize = 14.0f;
static const CSSCoord kMinimumScrollbarSize = 17.0f;
static const CSSCoord kMinimumThinScrollbarSize = 6.0f;
static const CSSCoord kMinimumColorPickerHeight = 32.0f;
static const CSSCoord kMinimumRangeThumbSize = 20.0f;
static const CSSCoord kMinimumDropdownArrowButtonWidth = 18.0f;
static const CSSCoord kMinimumSpinnerButtonWidth = 18.0f;
static const CSSCoord kMinimumSpinnerButtonHeight = 9.0f;
static const CSSCoord kButtonBorderWidth = 1.0f;
static const CSSCoord kMenulistBorderWidth = 1.0f;
static const CSSCoord kTextFieldBorderWidth = 1.0f;
static const CSSCoord kSpinnerBorderWidth = 1.0f;
static const CSSCoord kRangeHeight = 6.0f;
static const CSSCoord kProgressbarHeight = 6.0f;
static const CSSCoord kMeterHeight = 12.0f;

// nsCheckboxRadioFrame takes the bottom of the content box as the baseline.
// This border-width makes its baseline 2px under the bottom, which is nice.
static const CSSCoord kCheckboxRadioBorderWidth = 2.0f;

}  // namespace widget
}  // namespace mozilla

class nsNativeBasicTheme : protected nsNativeTheme, public nsITheme {
 protected:
  using sRGBColor = mozilla::gfx::sRGBColor;
  using CSSCoord = mozilla::CSSCoord;
  using CSSPoint = mozilla::CSSPoint;
  using CSSIntCoord = mozilla::CSSIntCoord;
  using ComputedStyle = mozilla::ComputedStyle;
  using EventStates = mozilla::EventStates;
  using DrawTarget = mozilla::gfx::DrawTarget;
  using Path = mozilla::gfx::Path;
  using Rect = mozilla::gfx::Rect;
  using Point = mozilla::gfx::Point;
  using RectCornerRadii = mozilla::gfx::RectCornerRadii;
  using LayoutDeviceCoord = mozilla::LayoutDeviceCoord;
  using LayoutDeviceRect = mozilla::LayoutDeviceRect;

 public:
  using DPIRatio = mozilla::CSSToLayoutDeviceScale;

  NS_DECL_ISUPPORTS_INHERITED

  // The nsITheme interface.
  NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
                                  StyleAppearance aAppearance,
                                  const nsRect& aRect,
                                  const nsRect& aDirtyRect) override;
  /*bool CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder&
     aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, const
     mozilla::layers::StackingContextHelper& aSc,
                                        mozilla::layers::RenderRootStateManager*
     aManager, nsIFrame* aFrame, StyleAppearance aAppearance, const nsRect&
     aRect) override;*/
  [[nodiscard]] LayoutDeviceIntMargin GetWidgetBorder(
      nsDeviceContext* aContext, nsIFrame* aFrame,
      StyleAppearance aAppearance) override;
  bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
                        StyleAppearance aAppearance,
                        LayoutDeviceIntMargin* aResult) override;
  bool GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
                         StyleAppearance aAppearance,
                         nsRect* aOverflowRect) override;
  NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext, nsIFrame* aFrame,
                                  StyleAppearance aAppearance,
                                  mozilla::LayoutDeviceIntSize* aResult,
                                  bool* aIsOverridable) override;
  Transparency GetWidgetTransparency(nsIFrame* aFrame,
                                     StyleAppearance aAppearance) override;
  NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aAppearance,
                                nsAtom* aAttribute, bool* aShouldRepaint,
                                const nsAttrValue* aOldValue) override;
  NS_IMETHOD ThemeChanged() override;
  bool WidgetAppearanceDependsOnWindowFocus(
      StyleAppearance aAppearance) override;
  /*bool NeedToClearBackgroundBehindWidget(
      nsIFrame* aFrame, StyleAppearance aAppearance) override;*/
  ThemeGeometryType ThemeGeometryTypeForWidget(
      nsIFrame* aFrame, StyleAppearance aAppearance) override;
  bool ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
                           StyleAppearance aAppearance) override;
  bool WidgetIsContainer(StyleAppearance aAppearance) override;
  bool ThemeDrawsFocusForWidget(StyleAppearance aAppearance) override;
  bool ThemeNeedsComboboxDropmarker() override;

 protected:
  nsNativeBasicTheme() = default;
  virtual ~nsNativeBasicTheme() = default;

  static DPIRatio GetDPIRatio(nsIFrame* aFrame);
  static bool IsDateTimeResetButton(nsIFrame* aFrame);
  static bool IsDateTimeTextField(nsIFrame* aFrame);
  static bool IsColorPickerButton(nsIFrame* aFrame);
  static bool IsRootScrollbar(nsIFrame* aFrame);
  static LayoutDeviceRect FixAspectRatio(const LayoutDeviceRect& aRect);

  virtual std::pair<sRGBColor, sRGBColor> ComputeCheckboxColors(
      const EventStates& aState, StyleAppearance aAppearance);
  virtual sRGBColor ComputeCheckmarkColor(const EventStates& aState);
  virtual std::pair<sRGBColor, sRGBColor> ComputeRadioCheckmarkColors(
      const EventStates& aState);
  virtual sRGBColor ComputeBorderColor(const EventStates& aState);

  virtual std::pair<sRGBColor, sRGBColor> ComputeButtonColors(
      const EventStates& aState, nsIFrame* aFrame = nullptr);
  virtual std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(
      const EventStates& aState);
  virtual std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
      const EventStates& aState);
  virtual std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(
      const EventStates& aState);
  virtual std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(
      const EventStates& aState);
  virtual std::pair<sRGBColor, sRGBColor> ComputeProgressColors();
  virtual std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors();
  virtual std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
      const EventStates& aMeterState);
  virtual std::pair<sRGBColor, sRGBColor> ComputeMeterTrackColors();
  virtual sRGBColor ComputeMenulistArrowButtonColor(const EventStates& aState);
  virtual std::array<sRGBColor, 3> ComputeFocusRectColors();
  virtual std::pair<sRGBColor, sRGBColor> ComputeScrollbarColors(
      nsIFrame* aFrame, const ComputedStyle& aStyle,
      const EventStates& aDocumentState, bool aIsRoot);
  virtual sRGBColor ComputeScrollbarThumbColor(
      nsIFrame* aFrame, const ComputedStyle& aStyle,
      const EventStates& aElementState, const EventStates& aDocumentState);
  virtual std::array<sRGBColor, 3> ComputeScrollbarButtonColors(
      nsIFrame* aFrame, StyleAppearance aAppearance,
      const ComputedStyle& aStyle, const EventStates& aElementState,
      const EventStates& aDocumentState);

  void PaintRoundedFocusRect(DrawTarget* aDrawTarget,
                             const LayoutDeviceRect& aRect, DPIRatio aDpiRatio,
                             CSSCoord aRadius, CSSCoord aOffset);
  void PaintRoundedRect(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                        const sRGBColor& aBackgroundColor,
                        const sRGBColor& aBorderColor, CSSCoord aBorderWidth,
                        RectCornerRadii aDpiAdjustedRadii, DPIRatio aDpiRatio);
  void PaintRoundedRectWithRadius(DrawTarget* aDrawTarget,
                                  const LayoutDeviceRect& aRect,
                                  const sRGBColor& aBackgroundColor,
                                  const sRGBColor& aBorderColor,
                                  CSSCoord aBorderWidth, CSSCoord aRadius,
                                  DPIRatio aDpiRatio);
  void PaintCheckboxControl(DrawTarget* aDrawTarget,
                            const LayoutDeviceRect& aRect,
                            const EventStates& aState, DPIRatio aDpiRatio);
  void PaintCheckMark(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                      const EventStates& aState);
  void PaintIndeterminateMark(DrawTarget* aDrawTarget,
                              const LayoutDeviceRect& aRect,
                              const EventStates& aState);
  void PaintStrokedEllipse(DrawTarget* aDrawTarget,
                           const LayoutDeviceRect& aRect,
                           const sRGBColor& aBackgroundColor,
                           const sRGBColor& aBorderColor,
                           const CSSCoord aBorderWidth, DPIRatio aDpiRatio);
  void PaintEllipseShadow(DrawTarget* aDrawTarget,
                          const LayoutDeviceRect& aRect, float aShadowAlpha,
                          const CSSPoint& aShadowOffset,
                          CSSCoord aShadowBlurStdDev, DPIRatio aDpiRatio);
  void PaintRadioControl(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                         const EventStates& aState, DPIRatio aDpiRatio);
  void PaintRadioCheckmark(DrawTarget* aDrawTarget,
                           const LayoutDeviceRect& aRect,
                           const EventStates& aState, DPIRatio aDpiRatio);
  void PaintTextField(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                      const EventStates& aState, DPIRatio aDpiRatio);
  void PaintListbox(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                    const EventStates& aState, DPIRatio aDpiRatio);
  void PaintMenulist(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                     const EventStates& aState, DPIRatio aDpiRatio);
  void PaintArrow(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                  const float aArrowPolygonX[], const float aArrowPolygonY[],
                  const int32_t aArrowNumPoints, const sRGBColor aFillColor);
  void PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                                const LayoutDeviceRect& aRect,
                                const EventStates& aState);
  void PaintSpinnerButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                          const LayoutDeviceRect& aRect,
                          const EventStates& aState,
                          StyleAppearance aAppearance, DPIRatio aDpiRatio);
  void PaintRange(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                  const LayoutDeviceRect& aRect, const EventStates& aState,
                  DPIRatio aDpiRatio, bool aHorizontal);
  void PaintProgressBar(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                        const EventStates& aState, DPIRatio aDpiRatio);
  void PaintProgresschunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                          const LayoutDeviceRect& aRect,
                          const EventStates& aState, DPIRatio aDpiRatio);
  void PaintMeter(DrawTarget* aDrawTarget, const LayoutDeviceRect& aRect,
                  const EventStates& aState, DPIRatio aDpiRatio);
  void PaintMeterchunk(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                       const LayoutDeviceRect& aRect, DPIRatio aDpiRatio);
  void PaintButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
                   const LayoutDeviceRect& aRect, const EventStates& aState,
                   DPIRatio aDpiRatio);

  virtual void PaintScrollbarThumb(DrawTarget* aDrawTarget,
                                   const LayoutDeviceRect& aRect,
                                   bool aHorizontal, nsIFrame* aFrame,
                                   const ComputedStyle& aStyle,
                                   const EventStates& aElementState,
                                   const EventStates& aDocumentState,
                                   DPIRatio aDpiRatio);
  virtual void PaintScrollbar(DrawTarget* aDrawTarget,
                              const LayoutDeviceRect& aRect, bool aHorizontal,
                              nsIFrame* aFrame, const ComputedStyle& aStyle,
                              const EventStates& aDocumentState,
                              DPIRatio aDpiRatio, bool aIsRoot);
  virtual void PaintScrollbarTrack(DrawTarget* aDrawTarget,
                                   const LayoutDeviceRect& aRect,
                                   bool aHorizontal, nsIFrame* aFrame,
                                   const ComputedStyle& aStyle,
                                   const EventStates& aDocumentState,
                                   DPIRatio aDpiRatio, bool aIsRoot);
  virtual void PaintScrollCorner(DrawTarget* aDrawTarget,
                                 const LayoutDeviceRect& aRect,
                                 nsIFrame* aFrame, const ComputedStyle& aStyle,
                                 const EventStates& aDocumentState,
                                 DPIRatio aDpiRatio, bool aIsRoot);
  virtual void PaintScrollbarButton(
      DrawTarget* aDrawTarget, StyleAppearance aAppearance,
      const LayoutDeviceRect& aRect, nsIFrame* aFrame,
      const ComputedStyle& aStyle, const EventStates& aElementState,
      const EventStates& aDocumentState, DPIRatio aDpiRatio);
};

#endif