Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / widget / windows / nsNativeThemeWin.h
blob99370181977bf78725547f9a59ec3b577813ab05
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
10 #include <windows.h>
12 #include "mozilla/Maybe.h"
13 #include "mozilla/TimeStamp.h"
14 #include "Theme.h"
15 #include "nsUXThemeConstants.h"
16 #include "nsUXThemeData.h"
18 namespace mozilla::widget {
20 class nsNativeThemeWin : public Theme {
21 protected:
22 virtual ~nsNativeThemeWin();
24 public:
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 static bool IsWidgetAlwaysNonNative(nsIFrame*, StyleAppearance);
38 NonNative IsWidgetNonNative(nsIFrame*, StyleAppearance);
40 // The nsITheme interface.
41 NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
42 StyleAppearance aAppearance,
43 const nsRect& aRect, const nsRect& aDirtyRect,
44 DrawOverflow) override;
46 bool CreateWebRenderCommandsForWidget(wr::DisplayListBuilder&,
47 wr::IpcResourceUpdateQueue&,
48 const layers::StackingContextHelper&,
49 layers::RenderRootStateManager*,
50 nsIFrame*, StyleAppearance,
51 const nsRect&) override;
53 [[nodiscard]] LayoutDeviceIntMargin GetWidgetBorder(
54 nsDeviceContext* aContext, nsIFrame* aFrame,
55 StyleAppearance aAppearance) override;
57 bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
58 StyleAppearance aAppearance,
59 LayoutDeviceIntMargin* aResult) override;
61 virtual bool GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
62 StyleAppearance aAppearance,
63 nsRect* aOverflowRect) override;
65 LayoutDeviceIntSize GetMinimumWidgetSize(
66 nsPresContext* aPresContext, nsIFrame* aFrame,
67 StyleAppearance aAppearance) 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 ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) override;
83 bool ThemeWantsButtonInnerFocusRing() override { return true; }
85 bool ThemeNeedsComboboxDropmarker() override;
87 nsNativeThemeWin();
89 protected:
90 Maybe<nsUXThemeClass> GetThemeClass(StyleAppearance aAppearance);
91 HANDLE GetTheme(StyleAppearance aAppearance);
92 nsresult GetThemePartAndState(nsIFrame* aFrame, StyleAppearance aAppearance,
93 int32_t& aPart, int32_t& aState);
94 nsresult ClassicGetThemePartAndState(nsIFrame* aFrame,
95 StyleAppearance aAppearance,
96 int32_t& aPart, int32_t& aState,
97 bool& aFocused);
98 nsresult ClassicDrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
99 StyleAppearance aAppearance,
100 const nsRect& aRect,
101 const nsRect& aClipRect);
102 [[nodiscard]] LayoutDeviceIntMargin ClassicGetWidgetBorder(
103 nsDeviceContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance);
104 bool ClassicGetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
105 StyleAppearance aAppearance,
106 LayoutDeviceIntMargin* aResult);
107 LayoutDeviceIntSize ClassicGetMinimumWidgetSize(nsIFrame* aFrame,
108 StyleAppearance aAppearance);
109 bool ClassicThemeSupportsWidget(nsIFrame* aFrame,
110 StyleAppearance aAppearance);
111 void DrawCheckedRect(HDC hdc, const RECT& rc, int32_t fore, int32_t back,
112 HBRUSH defaultBack);
113 uint32_t GetWidgetNativeDrawingFlags(StyleAppearance aAppearance);
114 int32_t StandardGetState(nsIFrame* aFrame, StyleAppearance aAppearance,
115 bool wantFocused);
116 bool IsMenuActive(nsIFrame* aFrame, StyleAppearance aAppearance);
117 RECT CalculateProgressOverlayRect(nsIFrame* aFrame, RECT* aWidgetRect,
118 bool aIsVertical, bool aIsIndeterminate,
119 bool aIsClassic);
120 void DrawThemedProgressMeter(nsIFrame* aFrame, StyleAppearance aAppearance,
121 HANDLE aTheme, HDC aHdc, int aPart, int aState,
122 RECT* aWidgetRect, RECT* aClipRect);
124 [[nodiscard]] LayoutDeviceIntMargin GetCachedWidgetBorder(
125 HANDLE aTheme, nsUXThemeClass aThemeClass, StyleAppearance aAppearance,
126 int32_t aPart, int32_t aState);
128 nsresult GetCachedMinimumWidgetSize(nsIFrame* aFrame, HANDLE aTheme,
129 nsUXThemeClass aThemeClass,
130 StyleAppearance aAppearance,
131 int32_t aPart, int32_t aState,
132 THEMESIZE aSizeReq,
133 LayoutDeviceIntSize* aResult);
135 SIZE GetCachedGutterSize(HANDLE theme);
137 private:
138 TimeStamp mProgressDeterminateTimeStamp;
139 TimeStamp mProgressIndeterminateTimeStamp;
141 // eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT is about 800 at the time of
142 // writing this, and nsIntMargin is 16 bytes wide, which makes this cache (1/8
143 // + 16) * 800 bytes, or about ~12KB. We could probably reduce this cache to
144 // 3KB by caching on the aAppearance value instead, but there would be some
145 // uncacheable values, since we derive some theme parts from other arguments.
146 uint8_t
147 mBorderCacheValid[(eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT + 7) /
149 LayoutDeviceIntMargin
150 mBorderCache[eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT];
152 // See the above not for mBorderCache and friends. However
153 // LayoutDeviceIntSize is half the size of nsIntMargin, making the
154 // cache roughly half as large. In total the caches should come to about 18KB.
155 uint8_t mMinimumWidgetSizeCacheValid
156 [(eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT + 7) / 8];
157 LayoutDeviceIntSize
158 mMinimumWidgetSizeCache[eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT];
160 bool mGutterSizeCacheValid;
161 SIZE mGutterSizeCache;
164 } // namespace mozilla::widget
166 #endif