Bug 1822382 [wpt PR 38995] - Fix html/semantics/embedded-content/the-video-element...
[gecko.git] / widget / windows / nsNativeThemeWin.h
blobf56e5f9bc70e9580408bcd600cecf9e7db46b25e
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 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 LayoutDeviceIntSize GetMinimumWidgetSize(
65 nsPresContext* aPresContext, nsIFrame* aFrame,
66 StyleAppearance aAppearance) override;
68 virtual Transparency GetWidgetTransparency(
69 nsIFrame* aFrame, StyleAppearance aAppearance) override;
71 NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aAppearance,
72 nsAtom* aAttribute, bool* aShouldRepaint,
73 const nsAttrValue* aOldValue) override;
75 NS_IMETHOD ThemeChanged() override;
77 bool ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
78 StyleAppearance aAppearance) override;
80 bool WidgetIsContainer(StyleAppearance aAppearance) override;
82 bool ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) override;
84 bool ThemeWantsButtonInnerFocusRing(nsIFrame*, StyleAppearance) override {
85 return true;
88 bool ThemeNeedsComboboxDropmarker() override;
90 bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance) override;
92 enum { eThemeGeometryTypeWindowButtons = eThemeGeometryTypeUnknown + 1 };
93 ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame*,
94 StyleAppearance) override;
96 nsNativeThemeWin();
98 protected:
99 Maybe<nsUXThemeClass> GetThemeClass(StyleAppearance aAppearance);
100 HANDLE GetTheme(StyleAppearance aAppearance);
101 nsresult GetThemePartAndState(nsIFrame* aFrame, StyleAppearance aAppearance,
102 int32_t& aPart, int32_t& aState);
103 nsresult ClassicGetThemePartAndState(nsIFrame* aFrame,
104 StyleAppearance aAppearance,
105 int32_t& aPart, int32_t& aState,
106 bool& aFocused);
107 nsresult ClassicDrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
108 StyleAppearance aAppearance,
109 const nsRect& aRect,
110 const nsRect& aClipRect);
111 [[nodiscard]] LayoutDeviceIntMargin ClassicGetWidgetBorder(
112 nsDeviceContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance);
113 bool ClassicGetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
114 StyleAppearance aAppearance,
115 LayoutDeviceIntMargin* aResult);
116 LayoutDeviceIntSize ClassicGetMinimumWidgetSize(nsIFrame* aFrame,
117 StyleAppearance aAppearance);
118 bool ClassicThemeSupportsWidget(nsIFrame* aFrame,
119 StyleAppearance aAppearance);
120 void DrawCheckedRect(HDC hdc, const RECT& rc, int32_t fore, int32_t back,
121 HBRUSH defaultBack);
122 uint32_t GetWidgetNativeDrawingFlags(StyleAppearance aAppearance);
123 int32_t StandardGetState(nsIFrame* aFrame, StyleAppearance aAppearance,
124 bool wantFocused);
125 bool IsMenuActive(nsIFrame* aFrame, StyleAppearance aAppearance);
126 RECT CalculateProgressOverlayRect(nsIFrame* aFrame, RECT* aWidgetRect,
127 bool aIsVertical, bool aIsIndeterminate,
128 bool aIsClassic);
129 void DrawThemedProgressMeter(nsIFrame* aFrame, StyleAppearance aAppearance,
130 HANDLE aTheme, HDC aHdc, int aPart, int aState,
131 RECT* aWidgetRect, RECT* aClipRect);
133 [[nodiscard]] LayoutDeviceIntMargin GetCachedWidgetBorder(
134 HANDLE aTheme, nsUXThemeClass aThemeClass, StyleAppearance aAppearance,
135 int32_t aPart, int32_t aState);
137 nsresult GetCachedMinimumWidgetSize(nsIFrame* aFrame, HANDLE aTheme,
138 nsUXThemeClass aThemeClass,
139 StyleAppearance aAppearance,
140 int32_t aPart, int32_t aState,
141 THEMESIZE aSizeReq,
142 LayoutDeviceIntSize* aResult);
144 SIZE GetCachedGutterSize(HANDLE theme);
146 private:
147 TimeStamp mProgressDeterminateTimeStamp;
148 TimeStamp mProgressIndeterminateTimeStamp;
150 // eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT is about 800 at the time of
151 // writing this, and nsIntMargin is 16 bytes wide, which makes this cache (1/8
152 // + 16) * 800 bytes, or about ~12KB. We could probably reduce this cache to
153 // 3KB by caching on the aAppearance value instead, but there would be some
154 // uncacheable values, since we derive some theme parts from other arguments.
155 uint8_t
156 mBorderCacheValid[(eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT + 7) /
158 LayoutDeviceIntMargin
159 mBorderCache[eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT];
161 // See the above not for mBorderCache and friends. However
162 // LayoutDeviceIntSize is half the size of nsIntMargin, making the
163 // cache roughly half as large. In total the caches should come to about 18KB.
164 uint8_t mMinimumWidgetSizeCacheValid
165 [(eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT + 7) / 8];
166 LayoutDeviceIntSize
167 mMinimumWidgetSizeCache[eUXNumClasses * THEME_PART_DISTINCT_VALUE_COUNT];
169 bool mGutterSizeCacheValid;
170 SIZE mGutterSizeCache;
173 } // namespace mozilla::widget
175 #endif