Bug 1735078 - Clean up some unused LookAndFeel code on Windows. r=mhowell

Differential Revision: https://phabricator.services.mozilla.com/D128025
This commit is contained in:
Emilio Cobos Alvarez 2021-10-11 17:11:27 +00:00
Родитель d62c73236f
Коммит 067255ed45
9 изменённых файлов: 41 добавлений и 126 удалений

Просмотреть файл

@ -202,10 +202,6 @@ class LookAndFeel {
* If this metric != 0, support window dragging on the menubar.
*/
MenuBarDrag,
/**
* Return the appropriate WindowsThemeIdentifier for the current theme.
*/
WindowsThemeIdentifier,
/**
* Return an appropriate os version identifier.
*/
@ -358,21 +354,6 @@ class LookAndFeel {
return GetInt(IntID::UseOverlayScrollbars);
}
/**
* Windows themes we currently detect.
*/
enum WindowsTheme {
eWindowsTheme_Generic = 0, // unrecognized theme
eWindowsTheme_Classic,
eWindowsTheme_Aero,
eWindowsTheme_LunaBlue,
eWindowsTheme_LunaOlive,
eWindowsTheme_LunaSilver,
eWindowsTheme_Royale,
eWindowsTheme_Zune,
eWindowsTheme_AeroLite
};
/**
* Operating system versions.
*/

Просмотреть файл

@ -361,7 +361,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
break;
case IntID::WindowsDefaultTheme:
case IntID::WindowsThemeIdentifier:
case IntID::OperatingSystemVersionIdentifier:
aResult = 0;
rv = NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -480,7 +480,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
case IntID::DWMCompositor:
case IntID::WindowsClassic:
case IntID::WindowsDefaultTheme:
case IntID::WindowsThemeIdentifier:
case IntID::OperatingSystemVersionIdentifier:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -764,7 +764,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
case IntID::DWMCompositor:
case IntID::WindowsClassic:
case IntID::WindowsDefaultTheme:
case IntID::WindowsThemeIdentifier:
case IntID::OperatingSystemVersionIdentifier:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -227,7 +227,6 @@ nsresult HeadlessLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
case IntID::MenuBarDrag:
aResult = 0;
break;
case IntID::WindowsThemeIdentifier:
case IntID::OperatingSystemVersionIdentifier:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -150,7 +150,6 @@ static const char sIntPrefs[][43] = {
"ui.IMESelectedConvertedTextUnderlineStyle",
"ui.SpellCheckerUnderlineStyle",
"ui.menuBarDrag",
"ui.windowsThemeIdentifier",
"ui.operatingSystemVersionIdentifier",
"ui.scrollbarButtonAutoRepeatBehavior",
"ui.tooltipDelay",

Просмотреть файл

@ -457,9 +457,6 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
case IntID::WindowsDefaultTheme:
aResult = nsUXThemeData::IsDefaultWindowTheme();
break;
case IntID::WindowsThemeIdentifier:
aResult = nsUXThemeData::GetNativeThemeId();
break;
case IntID::OperatingSystemVersionIdentifier: {
aResult = int32_t(GetOperatingSystemVersion());
break;

Просмотреть файл

@ -29,6 +29,21 @@ bool nsUXThemeData::sCommandButtonBoxMetricsInitialized = false;
bool nsUXThemeData::sTitlebarInfoPopulatedAero = false;
bool nsUXThemeData::sTitlebarInfoPopulatedThemed = false;
/**
* Windows themes we currently detect.
*/
enum class WindowsTheme {
Generic = 0, // unrecognized theme
Classic,
Aero,
Luna,
Royale,
Zune,
AeroLite
};
static WindowsTheme sThemeId = WindowsTheme::Generic;
nsUXThemeData::ThemeHandle::~ThemeHandle() { Close(); }
void nsUXThemeData::ThemeHandle::OpenOnce(HWND aWindow, LPCWSTR aClassList) {
@ -50,7 +65,7 @@ void nsUXThemeData::ThemeHandle::Close() {
}
nsUXThemeData::ThemeHandle::operator HANDLE() {
return mHandle.isSome() ? mHandle.value() : nullptr;
return mHandle.valueOr(nullptr);
}
void nsUXThemeData::Invalidate() {
@ -219,8 +234,8 @@ void nsUXThemeData::UpdateTitlebarInfo(HWND aWnd) {
// We try to avoid activating this window, but on Aero basic (aero without
// compositor) and aero lite (special theme for win server 2012/2013) we may
// get the wrong information if the window isn't activated, so we have to:
if (sThemeId == LookAndFeel::eWindowsTheme_AeroLite ||
(sThemeId == LookAndFeel::eWindowsTheme_Aero &&
if (sThemeId == WindowsTheme::AeroLite ||
(sThemeId == WindowsTheme::Aero &&
!gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled())) {
showType = SW_SHOW;
}
@ -265,30 +280,18 @@ void nsUXThemeData::UpdateTitlebarInfo(HWND aWnd) {
// theme color (silver, olive, blue)
// system colors
struct THEMELIST {
const struct {
LPCWSTR name;
int type;
};
const THEMELIST knownThemes[] = {{L"aero.msstyles", WINTHEME_AERO},
{L"aerolite.msstyles", WINTHEME_AERO_LITE},
{L"luna.msstyles", WINTHEME_LUNA},
{L"zune.msstyles", WINTHEME_ZUNE},
{L"royale.msstyles", WINTHEME_ROYALE}};
const THEMELIST knownColors[] = {{L"normalcolor", WINTHEMECOLOR_NORMAL},
{L"homestead", WINTHEMECOLOR_HOMESTEAD},
{L"metallic", WINTHEMECOLOR_METALLIC}};
LookAndFeel::WindowsTheme nsUXThemeData::sThemeId =
LookAndFeel::eWindowsTheme_Generic;
WindowsTheme type;
} kKnownThemes[] = {{L"aero.msstyles", WindowsTheme::Aero},
{L"aerolite.msstyles", WindowsTheme::AeroLite},
{L"luna.msstyles", WindowsTheme::Luna},
{L"zune.msstyles", WindowsTheme::Zune},
{L"royale.msstyles", WindowsTheme::Royale}};
bool nsUXThemeData::sIsDefaultWindowsTheme = false;
bool nsUXThemeData::sIsHighContrastOn = false;
// static
LookAndFeel::WindowsTheme nsUXThemeData::GetNativeThemeId() { return sThemeId; }
// static
bool nsUXThemeData::IsDefaultWindowTheme() { return sIsDefaultWindowsTheme; }
@ -300,7 +303,7 @@ void nsUXThemeData::UpdateNativeThemeInfo() {
sTitlebarInfoPopulatedThemed = false;
sIsDefaultWindowsTheme = false;
sThemeId = LookAndFeel::eWindowsTheme_Generic;
sThemeId = WindowsTheme::Generic;
HIGHCONTRAST highContrastInfo;
highContrastInfo.cbSize = sizeof(HIGHCONTRAST);
@ -311,7 +314,7 @@ void nsUXThemeData::UpdateNativeThemeInfo() {
}
if (!nsUXThemeData::IsAppThemed()) {
sThemeId = LookAndFeel::eWindowsTheme_Classic;
sThemeId = WindowsTheme::Classic;
return;
}
@ -319,77 +322,34 @@ void nsUXThemeData::UpdateNativeThemeInfo() {
WCHAR themeColor[MAX_PATH + 1];
if (FAILED(GetCurrentThemeName(themeFileName, MAX_PATH, themeColor, MAX_PATH,
nullptr, 0))) {
sThemeId = LookAndFeel::eWindowsTheme_Classic;
sThemeId = WindowsTheme::Classic;
return;
}
LPCWSTR themeName = wcsrchr(themeFileName, L'\\');
themeName = themeName ? themeName + 1 : themeFileName;
WindowsTheme theme = WINTHEME_UNRECOGNIZED;
for (size_t i = 0; i < ArrayLength(knownThemes); ++i) {
if (!lstrcmpiW(themeName, knownThemes[i].name)) {
theme = (WindowsTheme)knownThemes[i].type;
break;
sThemeId = [&] {
for (const auto& theme : kKnownThemes) {
if (!lstrcmpiW(themeName, theme.name)) {
return theme.type;
}
}
if (theme == WINTHEME_UNRECOGNIZED) return;
return WindowsTheme::Generic;
}();
// We're using the default theme if we're using any of Aero, Aero Lite, or
// luna. However, on Win8, GetCurrentThemeName (see above) returns
// AeroLite.msstyles for the 4 builtin highcontrast themes as well. Those
// themes "don't count" as default themes, so we specifically check for high
// contrast mode in that situation.
if (!(IsWin8OrLater() && sIsHighContrastOn) &&
(theme == WINTHEME_AERO || theme == WINTHEME_AERO_LITE ||
theme == WINTHEME_LUNA)) {
sIsDefaultWindowsTheme = true;
}
if (theme != WINTHEME_LUNA) {
switch (theme) {
case WINTHEME_AERO:
sThemeId = LookAndFeel::eWindowsTheme_Aero;
return;
case WINTHEME_AERO_LITE:
sThemeId = LookAndFeel::eWindowsTheme_AeroLite;
return;
case WINTHEME_ZUNE:
sThemeId = LookAndFeel::eWindowsTheme_Zune;
return;
case WINTHEME_ROYALE:
sThemeId = LookAndFeel::eWindowsTheme_Royale;
return;
default:
NS_WARNING("unhandled theme type.");
return;
}
}
// calculate the luna color scheme
WindowsThemeColor color = WINTHEMECOLOR_UNRECOGNIZED;
for (size_t i = 0; i < ArrayLength(knownColors); ++i) {
if (!lstrcmpiW(themeColor, knownColors[i].name)) {
color = (WindowsThemeColor)knownColors[i].type;
break;
}
}
switch (color) {
case WINTHEMECOLOR_NORMAL:
sThemeId = LookAndFeel::eWindowsTheme_LunaBlue;
return;
case WINTHEMECOLOR_HOMESTEAD:
sThemeId = LookAndFeel::eWindowsTheme_LunaOlive;
return;
case WINTHEMECOLOR_METALLIC:
sThemeId = LookAndFeel::eWindowsTheme_LunaSilver;
return;
default:
NS_WARNING("unhandled theme color.");
return;
sIsDefaultWindowsTheme = [&] {
if (sIsHighContrastOn && IsWin8OrLater()) {
return false;
}
return sThemeId == WindowsTheme::Aero ||
sThemeId == WindowsTheme::AeroLite || sThemeId == WindowsTheme::Luna;
}();
}
// static

Просмотреть файл

@ -41,22 +41,6 @@ enum nsUXThemeClass {
eUXNumClasses
};
// Native windows style constants
enum WindowsTheme {
WINTHEME_UNRECOGNIZED = 0,
WINTHEME_CLASSIC = 1, // no theme
WINTHEME_AERO = 2,
WINTHEME_LUNA = 3,
WINTHEME_ROYALE = 4,
WINTHEME_ZUNE = 5,
WINTHEME_AERO_LITE = 6
};
enum WindowsThemeColor {
WINTHEMECOLOR_UNRECOGNIZED = 0,
WINTHEMECOLOR_NORMAL = 1,
WINTHEMECOLOR_HOMESTEAD = 2,
WINTHEMECOLOR_METALLIC = 3
};
enum CmdButtonIdx {
CMDBUTTONIDX_MINIMIZE = 0,
CMDBUTTONIDX_RESTORE,
@ -103,7 +87,6 @@ class nsUXThemeData {
public:
static bool sTitlebarInfoPopulatedAero;
static bool sTitlebarInfoPopulatedThemed;
static mozilla::LookAndFeel::WindowsTheme sThemeId;
static bool sIsDefaultWindowsTheme;
static bool sIsHighContrastOn;
@ -123,7 +106,6 @@ class nsUXThemeData {
return sCommandButtonBoxMetrics;
}
static void UpdateNativeThemeInfo();
static mozilla::LookAndFeel::WindowsTheme GetNativeThemeId();
static bool IsDefaultWindowTheme();
static bool IsHighContrastOn();