1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsNativeThemeWin_h
8 #define nsNativeThemeWin_h
12 #include "mozilla/Maybe.h"
13 #include "mozilla/TimeStamp.h"
15 #include "nsUXThemeConstants.h"
16 #include "nsUXThemeData.h"
18 namespace mozilla::widget
{
20 class nsNativeThemeWin
: public Theme
{
22 virtual ~nsNativeThemeWin();
25 // Whether we draw a non-native widget.
27 // We always draw scrollbars as non-native so that all of Firefox has
28 // consistent scrollbar styles both in chrome and content (plus, the
29 // non-native scrollbars support scrollbar-width, auto-darkening...).
31 // We draw other widgets as non-native when their color-scheme is dark. In
32 // that case (`BecauseColorMismatch`) we don't call into the non-native theme
33 // for sizing information (GetWidgetPadding/Border and GetMinimumWidgetSize),
34 // to avoid subtle sizing changes. The non-native theme can basically draw at
35 // any size, so we prefer to have consistent sizing information.
36 enum class NonNative
{ No
, Always
, BecauseColorMismatch
};
37 NonNative
IsWidgetNonNative(nsIFrame
*, StyleAppearance
);
39 // The nsITheme interface.
40 NS_IMETHOD
DrawWidgetBackground(gfxContext
* aContext
, nsIFrame
* aFrame
,
41 StyleAppearance aAppearance
,
42 const nsRect
& aRect
, const nsRect
& aDirtyRect
,
43 DrawOverflow
) override
;
45 bool CreateWebRenderCommandsForWidget(wr::DisplayListBuilder
&,
46 wr::IpcResourceUpdateQueue
&,
47 const layers::StackingContextHelper
&,
48 layers::RenderRootStateManager
*,
49 nsIFrame
*, StyleAppearance
,
50 const nsRect
&) override
;
52 [[nodiscard
]] LayoutDeviceIntMargin
GetWidgetBorder(
53 nsDeviceContext
* aContext
, nsIFrame
* aFrame
,
54 StyleAppearance aAppearance
) override
;
56 bool GetWidgetPadding(nsDeviceContext
* aContext
, nsIFrame
* aFrame
,
57 StyleAppearance aAppearance
,
58 LayoutDeviceIntMargin
* aResult
) override
;
60 virtual bool GetWidgetOverflow(nsDeviceContext
* aContext
, nsIFrame
* aFrame
,
61 StyleAppearance aAppearance
,
62 nsRect
* aOverflowRect
) override
;
64 NS_IMETHOD
GetMinimumWidgetSize(nsPresContext
* aPresContext
, nsIFrame
* aFrame
,
65 StyleAppearance aAppearance
,
66 LayoutDeviceIntSize
* aResult
,
67 bool* aIsOverridable
) override
;
69 virtual Transparency
GetWidgetTransparency(
70 nsIFrame
* aFrame
, StyleAppearance aAppearance
) override
;
72 NS_IMETHOD
WidgetStateChanged(nsIFrame
* aFrame
, StyleAppearance aAppearance
,
73 nsAtom
* aAttribute
, bool* aShouldRepaint
,
74 const nsAttrValue
* aOldValue
) override
;
76 NS_IMETHOD
ThemeChanged() override
;
78 bool ThemeSupportsWidget(nsPresContext
* aPresContext
, nsIFrame
* aFrame
,
79 StyleAppearance aAppearance
) override
;
81 bool WidgetIsContainer(StyleAppearance aAppearance
) override
;
83 bool ThemeDrawsFocusForWidget(nsIFrame
*, StyleAppearance
) override
;
85 bool ThemeWantsButtonInnerFocusRing(nsIFrame
*, StyleAppearance
) override
{
89 bool ThemeNeedsComboboxDropmarker() override
;
91 bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance
) override
;
93 enum { eThemeGeometryTypeWindowButtons
= eThemeGeometryTypeUnknown
+ 1 };
94 ThemeGeometryType
ThemeGeometryTypeForWidget(nsIFrame
*,
95 StyleAppearance
) override
;
100 Maybe
<nsUXThemeClass
> GetThemeClass(StyleAppearance aAppearance
);
101 HANDLE
GetTheme(StyleAppearance aAppearance
);
102 nsresult
GetThemePartAndState(nsIFrame
* aFrame
, StyleAppearance aAppearance
,
103 int32_t& aPart
, int32_t& aState
);
104 nsresult
ClassicGetThemePartAndState(nsIFrame
* aFrame
,
105 StyleAppearance aAppearance
,
106 int32_t& aPart
, int32_t& aState
,
108 nsresult
ClassicDrawWidgetBackground(gfxContext
* aContext
, nsIFrame
* aFrame
,
109 StyleAppearance aAppearance
,
111 const nsRect
& aClipRect
);
112 [[nodiscard
]] LayoutDeviceIntMargin
ClassicGetWidgetBorder(
113 nsDeviceContext
* aContext
, nsIFrame
* aFrame
, StyleAppearance aAppearance
);
114 bool ClassicGetWidgetPadding(nsDeviceContext
* aContext
, nsIFrame
* aFrame
,
115 StyleAppearance aAppearance
,
116 LayoutDeviceIntMargin
* aResult
);
117 nsresult
ClassicGetMinimumWidgetSize(nsIFrame
* aFrame
,
118 StyleAppearance aAppearance
,
119 LayoutDeviceIntSize
* aResult
,
120 bool* aIsOverridable
);
121 bool ClassicThemeSupportsWidget(nsIFrame
* aFrame
,
122 StyleAppearance aAppearance
);
123 void DrawCheckedRect(HDC hdc
, const RECT
& rc
, int32_t fore
, int32_t back
,
125 uint32_t GetWidgetNativeDrawingFlags(StyleAppearance aAppearance
);
126 int32_t StandardGetState(nsIFrame
* aFrame
, StyleAppearance aAppearance
,
128 bool IsMenuActive(nsIFrame
* aFrame
, StyleAppearance aAppearance
);
129 RECT
CalculateProgressOverlayRect(nsIFrame
* aFrame
, RECT
* aWidgetRect
,
130 bool aIsVertical
, bool aIsIndeterminate
,
132 void DrawThemedProgressMeter(nsIFrame
* aFrame
, StyleAppearance aAppearance
,
133 HANDLE aTheme
, HDC aHdc
, int aPart
, int aState
,
134 RECT
* aWidgetRect
, RECT
* aClipRect
);
136 [[nodiscard
]] LayoutDeviceIntMargin
GetCachedWidgetBorder(
137 HANDLE aTheme
, nsUXThemeClass aThemeClass
, StyleAppearance aAppearance
,
138 int32_t aPart
, int32_t aState
);
140 nsresult
GetCachedMinimumWidgetSize(nsIFrame
* aFrame
, HANDLE aTheme
,
141 nsUXThemeClass aThemeClass
,
142 StyleAppearance aAppearance
,
143 int32_t aPart
, int32_t aState
,
145 LayoutDeviceIntSize
* aResult
);
147 SIZE
GetCachedGutterSize(HANDLE theme
);
150 TimeStamp mProgressDeterminateTimeStamp
;
151 TimeStamp mProgressIndeterminateTimeStamp
;
153 // eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT is about 800 at the time of
154 // writing this, and nsIntMargin is 16 bytes wide, which makes this cache (1/8
155 // + 16) * 800 bytes, or about ~12KB. We could probably reduce this cache to
156 // 3KB by caching on the aAppearance value instead, but there would be some
157 // uncacheable values, since we derive some theme parts from other arguments.
159 mBorderCacheValid
[(eUXNumClasses
* THEME_PART_DISTINCT_VALUE_COUNT
+ 7) /
161 LayoutDeviceIntMargin
162 mBorderCache
[eUXNumClasses
* THEME_PART_DISTINCT_VALUE_COUNT
];
164 // See the above not for mBorderCache and friends. However
165 // LayoutDeviceIntSize is half the size of nsIntMargin, making the
166 // cache roughly half as large. In total the caches should come to about 18KB.
167 uint8_t mMinimumWidgetSizeCacheValid
168 [(eUXNumClasses
* THEME_PART_DISTINCT_VALUE_COUNT
+ 7) / 8];
170 mMinimumWidgetSizeCache
[eUXNumClasses
* THEME_PART_DISTINCT_VALUE_COUNT
];
172 bool mGutterSizeCacheValid
;
173 SIZE mGutterSizeCache
;
176 } // namespace mozilla::widget