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"
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()) {
29 mHandle
= Some(OpenThemeData(aWindow
, aClassList
));
32 void nsUXThemeData::ThemeHandle::Close() {
33 if (mHandle
.isNothing()) {
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
) {
53 nsUXThemeData::GetTheme(nsUXThemeClass cls
) {
54 NS_ASSERTION(cls
< eUXNumClasses
, "Invalid theme class!");
55 sThemes
[cls
].OpenOnce(nullptr, GetClassName(cls
));
59 const wchar_t* nsUXThemeData::GetClassName(nsUXThemeClass cls
) {
82 MOZ_ASSERT_UNREACHABLE("unknown uxtheme class");
87 bool nsUXThemeData::sIsHighContrastOn
= false;
90 void nsUXThemeData::UpdateNativeThemeInfo() {
91 HIGHCONTRAST highContrastInfo
;
92 highContrastInfo
.cbSize
= sizeof(HIGHCONTRAST
);
94 SystemParametersInfo(SPI_GETHIGHCONTRAST
, 0, &highContrastInfo
, 0) &&
95 highContrastInfo
.dwFlags
& HCF_HIGHCONTRASTON
;