Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / widget / windows / nsUXThemeData.cpp
blobfb0a1c89ab45ec6b36b57276c47a814a3423f56d
1 /* vim: se cin sw=2 ts=2 et : */
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/ArrayUtils.h"
9 #include "mozilla/WindowsVersion.h"
11 #include "nsUXThemeData.h"
12 #include "nsDebug.h"
13 #include "nsToolkit.h"
14 #include "nsUXThemeConstants.h"
15 #include "gfxWindowsPlatform.h"
17 using namespace mozilla;
18 using namespace mozilla::widget;
20 MOZ_RUNINIT nsUXThemeData::ThemeHandle nsUXThemeData::sThemes[eUXNumClasses];
22 nsUXThemeData::ThemeHandle::~ThemeHandle() { Close(); }
24 void nsUXThemeData::ThemeHandle::OpenOnce(HWND aWindow, LPCWSTR aClassList) {
25 if (mHandle.isSome()) {
26 return;
29 mHandle = Some(OpenThemeData(aWindow, aClassList));
32 void nsUXThemeData::ThemeHandle::Close() {
33 if (mHandle.isNothing()) {
34 return;
37 if (HANDLE rawHandle = mHandle.extract()) {
38 CloseThemeData(rawHandle);
42 nsUXThemeData::ThemeHandle::operator HANDLE() {
43 return mHandle.valueOr(nullptr);
46 void nsUXThemeData::Invalidate() {
47 for (auto& theme : sThemes) {
48 theme.Close();
52 HANDLE
53 nsUXThemeData::GetTheme(nsUXThemeClass cls) {
54 NS_ASSERTION(cls < eUXNumClasses, "Invalid theme class!");
55 sThemes[cls].OpenOnce(nullptr, GetClassName(cls));
56 return sThemes[cls];
59 const wchar_t* nsUXThemeData::GetClassName(nsUXThemeClass cls) {
60 switch (cls) {
61 case eUXButton:
62 return L"Button";
63 case eUXEdit:
64 return L"Edit";
65 case eUXToolbar:
66 return L"Toolbar";
67 case eUXProgress:
68 return L"Progress";
69 case eUXTab:
70 return L"Tab";
71 case eUXTrackbar:
72 return L"Trackbar";
73 case eUXCombobox:
74 return L"Combobox";
75 case eUXListview:
76 return L"Listview";
77 case eUXMenu:
78 return L"Menu";
79 default:
80 MOZ_ASSERT_UNREACHABLE("unknown uxtheme class");
81 return L"";
85 bool nsUXThemeData::sIsHighContrastOn = false;
87 // static
88 void nsUXThemeData::UpdateNativeThemeInfo() {
89 HIGHCONTRAST highContrastInfo;
90 highContrastInfo.cbSize = sizeof(HIGHCONTRAST);
91 sIsHighContrastOn =
92 SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &highContrastInfo, 0) &&
93 highContrastInfo.dwFlags & HCF_HIGHCONTRASTON;