Bug 1882714 [wpt PR 44850] - Update wpt metadata, a=testonly
[gecko.git] / widget / windows / nsUXThemeData.cpp
blobb3f9e6fce90b1eefc0ef833b7eefaa2dda90ae01
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 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 eUXRebar:
66 return L"Rebar";
67 case eUXToolbar:
68 return L"Toolbar";
69 case eUXProgress:
70 return L"Progress";
71 case eUXTab:
72 return L"Tab";
73 case eUXTrackbar:
74 return L"Trackbar";
75 case eUXCombobox:
76 return L"Combobox";
77 case eUXHeader:
78 return L"Header";
79 case eUXListview:
80 return L"Listview";
81 case eUXMenu:
82 return L"Menu";
83 default:
84 MOZ_ASSERT_UNREACHABLE("unknown uxtheme class");
85 return L"";
89 bool nsUXThemeData::sIsHighContrastOn = false;
91 // static
92 void nsUXThemeData::UpdateNativeThemeInfo() {
93 HIGHCONTRAST highContrastInfo;
94 highContrastInfo.cbSize = sizeof(HIGHCONTRAST);
95 sIsHighContrastOn =
96 SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &highContrastInfo, 0) &&
97 highContrastInfo.dwFlags & HCF_HIGHCONTRASTON;