1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsNativeThemeCocoa_h_
7 #define nsNativeThemeCocoa_h_
9 #import <Carbon/Carbon.h>
10 #import <Cocoa/Cocoa.h>
12 #include "mozilla/Variant.h"
15 #include "ThemeCocoa.h"
16 #include "mozilla/dom/RustTypes.h"
18 @
class MOZCellDrawWindow
;
19 @
class MOZCellDrawView
;
20 @
class MOZSearchFieldCell
;
21 @
class NSProgressBarCell
;
22 class nsDeviceContext
;
23 struct SegmentedControlRenderSettings
;
29 } // namespace mozilla
31 class nsNativeThemeCocoa
: public mozilla::widget::ThemeCocoa
{
32 using ThemeCocoa
= mozilla::widget::ThemeCocoa
;
35 enum class CheckboxOrRadioState
: uint8_t { eOff
, eOn
, eIndeterminate
};
37 enum class ButtonType
: uint8_t {
40 eSquareBezelPushButton
,
43 eTreeTwistyPointingRight
,
44 eTreeTwistyPointingDown
,
45 eDisclosureButtonClosed
,
49 enum class SpinButton
: uint8_t { eUp
, eDown
};
51 enum class SegmentType
: uint8_t { eToolbarButton
, eTab
};
53 enum class OptimumState
: uint8_t { eOptimum
, eSubOptimum
, eSubSubOptimum
};
55 struct ControlParams
{
58 insideActiveWindow(false),
64 bool insideActiveWindow
: 1;
70 struct CheckboxOrRadioParams
{
71 ControlParams controlParams
;
72 CheckboxOrRadioState state
= CheckboxOrRadioState::eOff
;
73 float verticalAlignFactor
= 0.5f
;
77 ControlParams controlParams
;
78 ButtonType button
= ButtonType::eRegularPushButton
;
81 struct DropdownParams
{
82 ControlParams controlParams
;
83 bool pullsDown
= false;
84 bool editable
= false;
87 struct SpinButtonParams
{
88 mozilla::Maybe
<SpinButton
> pressedButton
;
89 bool disabled
= false;
90 bool insideActiveWindow
= false;
93 struct SegmentParams
{
94 SegmentType segmentType
= SegmentType::eToolbarButton
;
95 bool insideActiveWindow
= false;
97 bool selected
= false;
99 bool atLeftEnd
= false;
100 bool atRightEnd
= false;
101 bool drawsLeftSeparator
= false;
102 bool drawsRightSeparator
= false;
106 struct TextFieldParams
{
107 float verticalAlignFactor
= 0.5f
;
108 bool insideToolbar
= false;
109 bool disabled
= false;
110 bool focused
= false;
114 struct ProgressParams
{
117 float verticalAlignFactor
= 0.5f
;
118 bool insideActiveWindow
= false;
119 bool indeterminate
= false;
120 bool horizontal
= false;
128 OptimumState optimumState
= OptimumState::eOptimum
;
129 float verticalAlignFactor
= 0.5f
;
130 bool horizontal
= true;
134 struct TreeHeaderCellParams
{
135 ControlParams controlParams
;
136 TreeSortDirection sortDirection
= eTreeSortDirection_Natural
;
137 bool lastTreeHeaderCell
= false;
144 bool insideActiveWindow
= false;
145 bool disabled
= false;
146 bool focused
= false;
147 bool horizontal
= true;
148 bool reverse
= false;
151 enum Widget
: uint8_t {
152 eColorFill
, // mozilla::gfx::sRGBColor
153 eCheckbox
, // CheckboxOrRadioParams
154 eRadio
, // CheckboxOrRadioParams
155 eButton
, // ButtonParams
156 eDropdown
, // DropdownParams
157 eSpinButtons
, // SpinButtonParams
158 eSpinButtonUp
, // SpinButtonParams
159 eSpinButtonDown
, // SpinButtonParams
160 eSegment
, // SegmentParams
164 eTextField
, // TextFieldParams
165 eSearchField
, // TextFieldParams
166 eProgressBar
, // ProgressParams
167 eMeter
, // MeterParams
168 eTreeHeaderCell
, // TreeHeaderCellParams
169 eScale
, // ScaleParams
170 eMultilineTextField
, // bool
176 static WidgetInfo
ColorFill(const mozilla::gfx::sRGBColor
& aParams
) {
177 return WidgetInfo(Widget::eColorFill
, aParams
);
179 static WidgetInfo
Checkbox(const CheckboxOrRadioParams
& aParams
) {
180 return WidgetInfo(Widget::eCheckbox
, aParams
);
182 static WidgetInfo
Radio(const CheckboxOrRadioParams
& aParams
) {
183 return WidgetInfo(Widget::eRadio
, aParams
);
185 static WidgetInfo
Button(const ButtonParams
& aParams
) {
186 return WidgetInfo(Widget::eButton
, aParams
);
188 static WidgetInfo
Dropdown(const DropdownParams
& aParams
) {
189 return WidgetInfo(Widget::eDropdown
, aParams
);
191 static WidgetInfo
SpinButtons(const SpinButtonParams
& aParams
) {
192 return WidgetInfo(Widget::eSpinButtons
, aParams
);
194 static WidgetInfo
SpinButtonUp(const SpinButtonParams
& aParams
) {
195 return WidgetInfo(Widget::eSpinButtonUp
, aParams
);
197 static WidgetInfo
SpinButtonDown(const SpinButtonParams
& aParams
) {
198 return WidgetInfo(Widget::eSpinButtonDown
, aParams
);
200 static WidgetInfo
Segment(const SegmentParams
& aParams
) {
201 return WidgetInfo(Widget::eSegment
, aParams
);
203 static WidgetInfo
Separator() {
204 return WidgetInfo(Widget::eSeparator
, false);
206 static WidgetInfo
StatusBar(bool aParams
) {
207 return WidgetInfo(Widget::eStatusBar
, aParams
);
209 static WidgetInfo
GroupBox() {
210 return WidgetInfo(Widget::eGroupBox
, false);
212 static WidgetInfo
TextField(const TextFieldParams
& aParams
) {
213 return WidgetInfo(Widget::eTextField
, aParams
);
215 static WidgetInfo
SearchField(const TextFieldParams
& aParams
) {
216 return WidgetInfo(Widget::eSearchField
, aParams
);
218 static WidgetInfo
ProgressBar(const ProgressParams
& aParams
) {
219 return WidgetInfo(Widget::eProgressBar
, aParams
);
221 static WidgetInfo
Meter(const MeterParams
& aParams
) {
222 return WidgetInfo(Widget::eMeter
, aParams
);
224 static WidgetInfo
TreeHeaderCell(const TreeHeaderCellParams
& aParams
) {
225 return WidgetInfo(Widget::eTreeHeaderCell
, aParams
);
227 static WidgetInfo
Scale(const ScaleParams
& aParams
) {
228 return WidgetInfo(Widget::eScale
, aParams
);
230 static WidgetInfo
MultilineTextField(bool aParams
) {
231 return WidgetInfo(Widget::eMultilineTextField
, aParams
);
233 static WidgetInfo
ListBox() { return WidgetInfo(Widget::eListBox
, false); }
234 static WidgetInfo
TabPanel(bool aParams
) {
235 return WidgetInfo(Widget::eTabPanel
, aParams
);
238 template <typename T
>
240 MOZ_RELEASE_ASSERT(mVariant
.is
<T
>());
241 return mVariant
.as
<T
>();
244 enum Widget
Widget() const { return mWidget
; }
247 template <typename T
>
248 WidgetInfo(enum Widget aWidget
, const T
& aParams
)
249 : mVariant(aParams
), mWidget(aWidget
) {}
251 mozilla::Variant
<mozilla::gfx::sRGBColor
, CheckboxOrRadioParams
,
252 ButtonParams
, DropdownParams
, SpinButtonParams
,
253 SegmentParams
, TextFieldParams
, ProgressParams
,
254 MeterParams
, TreeHeaderCellParams
, ScaleParams
, bool>
260 explicit nsNativeThemeCocoa();
262 NS_DECL_ISUPPORTS_INHERITED
264 // The nsITheme interface.
265 NS_IMETHOD
DrawWidgetBackground(gfxContext
* aContext
, nsIFrame
*,
266 StyleAppearance
, const nsRect
& aRect
,
267 const nsRect
& aDirtyRect
,
268 DrawOverflow
) override
;
269 bool CreateWebRenderCommandsForWidget(
270 mozilla::wr::DisplayListBuilder
& aBuilder
,
271 mozilla::wr::IpcResourceUpdateQueue
& aResources
,
272 const mozilla::layers::StackingContextHelper
& aSc
,
273 mozilla::layers::RenderRootStateManager
* aManager
, nsIFrame
*,
274 StyleAppearance
, const nsRect
& aRect
) override
;
275 [[nodiscard
]] LayoutDeviceIntMargin
GetWidgetBorder(nsDeviceContext
* aContext
,
277 StyleAppearance
) override
;
279 bool GetWidgetPadding(nsDeviceContext
* aContext
, nsIFrame
*, StyleAppearance
,
280 LayoutDeviceIntMargin
* aResult
) override
;
282 bool GetWidgetOverflow(nsDeviceContext
* aContext
, nsIFrame
*, StyleAppearance
,
283 nsRect
* aOverflowRect
) override
;
285 LayoutDeviceIntSize
GetMinimumWidgetSize(nsPresContext
*, nsIFrame
*,
286 StyleAppearance
) override
;
287 NS_IMETHOD
WidgetStateChanged(nsIFrame
*, StyleAppearance
, nsAtom
* aAttribute
,
288 bool* aShouldRepaint
,
289 const nsAttrValue
* aOldValue
) override
;
290 NS_IMETHOD
ThemeChanged() override
;
291 bool ThemeSupportsWidget(nsPresContext
* aPresContext
, nsIFrame
*,
292 StyleAppearance
) override
;
293 bool WidgetIsContainer(StyleAppearance
) override
;
294 bool ThemeDrawsFocusForWidget(nsIFrame
*, StyleAppearance
) override
;
295 bool ThemeNeedsComboboxDropmarker() override
;
296 bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance
) override
;
297 ThemeGeometryType
ThemeGeometryTypeForWidget(nsIFrame
*,
298 StyleAppearance
) override
;
299 Transparency
GetWidgetTransparency(nsIFrame
*, StyleAppearance
) override
;
300 mozilla::Maybe
<WidgetInfo
> ComputeWidgetInfo(nsIFrame
*, StyleAppearance
,
301 const nsRect
& aRect
);
302 void DrawProgress(CGContextRef context
, const HIRect
& inBoxRect
,
303 const ProgressParams
& aParams
);
306 virtual ~nsNativeThemeCocoa();
308 LayoutDeviceIntMargin
DirectionAwareMargin(const LayoutDeviceIntMargin
&,
310 nsIFrame
* SeparatorResponsibility(nsIFrame
* aBefore
, nsIFrame
* aAfter
);
311 ControlParams
ComputeControlParams(nsIFrame
*, mozilla::dom::ElementState
);
312 SegmentParams
ComputeSegmentParams(nsIFrame
*, mozilla::dom::ElementState
,
314 TextFieldParams
ComputeTextFieldParams(nsIFrame
*, mozilla::dom::ElementState
);
315 ProgressParams
ComputeProgressParams(nsIFrame
*, mozilla::dom::ElementState
,
317 MeterParams
ComputeMeterParams(nsIFrame
*);
318 TreeHeaderCellParams
ComputeTreeHeaderCellParams(nsIFrame
*,
319 mozilla::dom::ElementState
);
320 mozilla::Maybe
<ScaleParams
> ComputeHTMLScaleParams(
321 nsIFrame
*, mozilla::dom::ElementState
);
323 // HITheme drawing routines
324 void DrawMeter(CGContextRef context
, const HIRect
& inBoxRect
,
325 const MeterParams
& aParams
);
326 void DrawSegment(CGContextRef cgContext
, const HIRect
& inBoxRect
,
327 const SegmentParams
& aParams
);
328 void DrawSegmentBackground(CGContextRef cgContext
, const HIRect
& inBoxRect
,
329 const SegmentParams
& aParams
);
330 void DrawTabPanel(CGContextRef context
, const HIRect
& inBoxRect
,
331 bool aIsInsideActiveWindow
);
332 void DrawScale(CGContextRef context
, const HIRect
& inBoxRect
,
333 const ScaleParams
& aParams
);
334 void DrawCheckboxOrRadio(CGContextRef cgContext
, bool inCheckbox
,
335 const HIRect
& inBoxRect
,
336 const CheckboxOrRadioParams
& aParams
);
337 void DrawSearchField(CGContextRef cgContext
, const HIRect
& inBoxRect
,
338 const TextFieldParams
& aParams
);
339 void DrawTextField(CGContextRef cgContext
, const HIRect
& inBoxRect
,
340 const TextFieldParams
& aParams
);
341 void DrawPushButton(CGContextRef cgContext
, const HIRect
& inBoxRect
,
342 ButtonType aButtonType
, ControlParams aControlParams
);
343 void DrawSquareBezelPushButton(CGContextRef cgContext
,
344 const HIRect
& inBoxRect
,
345 ControlParams aControlParams
);
346 void DrawHelpButton(CGContextRef cgContext
, const HIRect
& inBoxRect
,
347 ControlParams aControlParams
);
348 void DrawDisclosureButton(CGContextRef cgContext
, const HIRect
& inBoxRect
,
349 ControlParams aControlParams
,
350 NSControlStateValue aState
);
351 void DrawHIThemeButton(CGContextRef cgContext
, const HIRect
& aRect
,
352 ThemeButtonKind aKind
, ThemeButtonValue aValue
,
353 ThemeDrawState aState
, ThemeButtonAdornment aAdornment
,
354 const ControlParams
& aParams
);
355 void DrawButton(CGContextRef context
, const HIRect
& inBoxRect
,
356 const ButtonParams
& aParams
);
357 void DrawTreeHeaderCell(CGContextRef context
, const HIRect
& inBoxRect
,
358 const TreeHeaderCellParams
& aParams
);
359 void DrawDropdown(CGContextRef context
, const HIRect
& inBoxRect
,
360 const DropdownParams
& aParams
);
361 HIThemeButtonDrawInfo
SpinButtonDrawInfo(ThemeButtonKind aKind
,
362 const SpinButtonParams
& aParams
);
363 void DrawSpinButtons(CGContextRef context
, const HIRect
& inBoxRect
,
364 const SpinButtonParams
& aParams
);
365 void DrawSpinButton(CGContextRef context
, const HIRect
& inBoxRect
,
366 SpinButton aDrawnButton
, const SpinButtonParams
& aParams
);
367 void DrawToolbar(CGContextRef cgContext
, const CGRect
& inBoxRect
,
369 void DrawStatusBar(CGContextRef cgContext
, const HIRect
& inBoxRect
,
371 void DrawMultilineTextField(CGContextRef cgContext
, const CGRect
& inBoxRect
,
373 void RenderWidget(const WidgetInfo
& aWidgetInfo
, mozilla::ColorScheme
,
374 mozilla::gfx::DrawTarget
& aDrawTarget
,
375 const mozilla::gfx::Rect
& aWidgetRect
,
376 const mozilla::gfx::Rect
& aDirtyRect
, float aScale
);
379 NSButtonCell
* mDisclosureButtonCell
;
380 NSButtonCell
* mHelpButtonCell
;
381 NSButtonCell
* mPushButtonCell
;
382 NSButtonCell
* mRadioButtonCell
;
383 NSButtonCell
* mCheckboxCell
;
384 NSTextFieldCell
* mTextFieldCell
;
385 MOZSearchFieldCell
* mSearchFieldCell
;
386 NSPopUpButtonCell
* mDropdownCell
;
387 NSComboBoxCell
* mComboBoxCell
;
388 NSProgressBarCell
* mProgressBarCell
;
389 NSLevelIndicatorCell
* mMeterBarCell
;
390 NSTableHeaderCell
* mTreeHeaderCell
;
391 MOZCellDrawWindow
* mCellDrawWindow
= nil
;
392 MOZCellDrawView
* mCellDrawView
;
395 #endif // nsNativeThemeCocoa_h_