Bug 719983 - Replace uses of nsUXThemeData::sIsVistaOrLater and sIsXPOrLater with WinUtils version routines. r=neil

This commit is contained in:
Jim Mathies 2012-02-15 13:10:17 -06:00
parent 8e0ae48a6c
commit 33e7a38652
5 changed files with 51 additions and 58 deletions

View File

@ -46,6 +46,9 @@
#include "nsStyleConsts.h"
#include "nsUXThemeData.h"
#include "nsUXThemeConstants.h"
#include "WinUtils.h"
using namespace mozilla::widget;
typedef UINT (CALLBACK *SHAppBarMessagePtr)(DWORD, PAPPBARDATA);
SHAppBarMessagePtr gSHAppBarMessage = NULL;
@ -199,7 +202,8 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
idx = COLOR_HIGHLIGHT;
break;
case eColorID__moz_menubarhovertext:
if (!nsUXThemeData::sIsVistaOrLater || !nsUXThemeData::isAppThemed())
if (WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION ||
!nsUXThemeData::isAppThemed())
{
idx = nsUXThemeData::sFlatMenus ?
COLOR_HIGHLIGHTTEXT :
@ -208,7 +212,8 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
}
// Fall through
case eColorID__moz_menuhovertext:
if (nsUXThemeData::IsAppThemed() && nsUXThemeData::sIsVistaOrLater)
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
nsUXThemeData::IsAppThemed())
{
res = ::GetColorFromTheme(eUXMenu,
MENU_POPUPITEM, MPI_HOT, TMT_TEXTCOLOR, aColor);
@ -284,7 +289,8 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
idx = COLOR_3DFACE;
break;
case eColorID__moz_win_mediatext:
if (nsUXThemeData::IsAppThemed() && nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
nsUXThemeData::IsAppThemed()) {
res = ::GetColorFromTheme(eUXMediaToolbar,
TP_BUTTON, TS_NORMAL, TMT_TEXTCOLOR, aColor);
if (NS_SUCCEEDED(res))
@ -294,7 +300,8 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
idx = COLOR_WINDOWTEXT;
break;
case eColorID__moz_win_communicationstext:
if (nsUXThemeData::IsAppThemed() && nsUXThemeData::sIsVistaOrLater)
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
nsUXThemeData::IsAppThemed())
{
res = ::GetColorFromTheme(eUXCommunicationsToolbar,
TP_BUTTON, TS_NORMAL, TMT_TEXTCOLOR, aColor);
@ -519,11 +526,5 @@ PRUnichar
nsLookAndFeel::GetPasswordCharacterImpl()
{
#define UNICODE_BLACK_CIRCLE_CHAR 0x25cf
static PRUnichar passwordCharacter = 0;
if (!passwordCharacter) {
passwordCharacter = '*';
if (nsUXThemeData::sIsXPOrLater)
passwordCharacter = UNICODE_BLACK_CIRCLE_CHAR;
}
return passwordCharacter;
return UNICODE_BLACK_CIRCLE_CHAR;
}

View File

@ -412,7 +412,7 @@ static void OffsetBackgroundRect(RECT& rect, CaptionButton button) {
HANDLE
nsNativeThemeWin::GetTheme(PRUint8 aWidgetType)
{
if (!nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION) {
// On XP or earlier, render dropdowns as textfields;
// doing it the right way works fine with the MS themes,
// but breaks on a lot of custom themes (presumably because MS
@ -431,8 +431,9 @@ nsNativeThemeWin::GetTheme(PRUint8 aWidgetType)
case NS_THEME_TEXTFIELD_MULTILINE:
return nsUXThemeData::GetTheme(eUXEdit);
case NS_THEME_TOOLTIP:
// BUG #161600: XP/2K3 should force a classic treatment of tooltips
return nsUXThemeData::sIsVistaOrLater ? nsUXThemeData::GetTheme(eUXTooltip) : NULL;
// XP/2K3 should force a classic treatment of tooltips
return WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION ?
NULL : nsUXThemeData::GetTheme(eUXTooltip);
case NS_THEME_TOOLBOX:
return nsUXThemeData::GetTheme(eUXRebar);
case NS_THEME_WIN_MEDIA_TOOLBOX:
@ -557,7 +558,7 @@ nsresult
nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
PRInt32& aPart, PRInt32& aState)
{
if (!nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION) {
// See GetTheme
if (aWidgetType == NS_THEME_DROPDOWN)
aWidgetType = NS_THEME_TEXTFIELD;
@ -634,7 +635,7 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
case NS_THEME_TEXTFIELD_MULTILINE: {
nsEventStates eventState = GetContentState(aFrame, aWidgetType);
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
/* Note: the NOSCROLL type has a rounded corner in each
* corner. The more specific HSCROLL, VSCROLL, HVSCROLL types
* have side and/or top/bottom edges rendered as straight
@ -701,9 +702,11 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
// we have to return aPart = -1.
aPart = -1;
} else if (IsVerticalProgress(stateFrame)) {
aPart = nsUXThemeData::sIsVistaOrLater ? PP_FILLVERT : PP_CHUNKVERT;
aPart = WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION ?
PP_FILLVERT : PP_CHUNKVERT;
} else {
aPart = nsUXThemeData::sIsVistaOrLater ? PP_FILL : PP_CHUNK;
aPart = WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION ?
PP_FILL : PP_CHUNK;
}
aState = TS_NORMAL;
@ -776,7 +779,8 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
aState += TS_ACTIVE;
else if (eventState.HasState(NS_EVENT_STATE_HOVER))
aState += TS_HOVER;
else if (nsUXThemeData::sIsVistaOrLater && parentState.HasState(NS_EVENT_STATE_HOVER))
else if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
parentState.HasState(NS_EVENT_STATE_HOVER))
aState = (aWidgetType - NS_THEME_SCROLLBAR_BUTTON_UP) + SP_BUTTON_IMPLICIT_HOVER_BASE;
else
aState += TS_NORMAL;
@ -864,7 +868,7 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
case NS_THEME_SCROLLBAR:
case NS_THEME_SCROLLBAR_SMALL: {
aState = 0;
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
// On vista, they have a part
aPart = RP_BACKGROUND;
} else {
@ -996,7 +1000,8 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
aFrame = parentFrame;
nsEventStates eventState = GetContentState(aFrame, aWidgetType);
aPart = nsUXThemeData::sIsVistaOrLater ? CBP_DROPMARKER_VISTA : CBP_DROPMARKER;
aPart = WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION ?
CBP_DROPMARKER_VISTA : CBP_DROPMARKER;
// For HTML controls with author styling, we should fall
// back to the old dropmarker style to avoid clashes with
@ -1016,7 +1021,7 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
else
isOpen = IsOpenButton(aFrame);
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
if (isHTML || IsMenuListEditable(aFrame)) {
if (isOpen) {
/* Hover is propagated, but we need to know whether we're
@ -1487,7 +1492,8 @@ RENDER_AGAIN:
// On vista, choose our own colors and draw an XP style half focus rect
// for focused checkboxes and a full rect when active.
if (nsUXThemeData::sIsVistaOrLater && aWidgetType == NS_THEME_CHECKBOX) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
aWidgetType == NS_THEME_CHECKBOX) {
LOGBRUSH lb;
lb.lbStyle = BS_SOLID;
lb.lbColor = RGB(255,255,255);
@ -1596,7 +1602,8 @@ RENDER_AGAIN:
bool indeterminate = IsIndeterminateProgress(stateFrame, eventStates);
bool vertical = IsVerticalProgress(stateFrame);
if (indeterminate || nsUXThemeData::sIsVistaOrLater) {
if (indeterminate ||
WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 30)) {
NS_WARNING("unable to animate progress widget!");
}
@ -1608,7 +1615,7 @@ RENDER_AGAIN:
* indeterminate progress bars.
*/
PRInt32 overlaySize;
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
if (vertical) {
overlaySize = indeterminate ? kProgressVerticalIndeterminateOverlaySize
: kProgressVerticalOverlaySize;
@ -1652,13 +1659,14 @@ RENDER_AGAIN:
PRInt32 overlayPart;
if (vertical) {
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
overlayPart = indeterminate ? PP_MOVEOVERLAY : PP_MOVEOVERLAYVERT;
} else {
overlayPart = PP_CHUNKVERT;
}
} else {
overlayPart = nsUXThemeData::sIsVistaOrLater ? PP_MOVEOVERLAY : PP_CHUNK;
overlayPart = WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION ?
PP_MOVEOVERLAY : PP_CHUNK;
}
nsUXThemeData::drawThemeBG(theme, hdc, overlayPart, state, &overlayRect,
@ -1823,7 +1831,7 @@ nsNativeThemeWin::GetWidgetPadding(nsDeviceContext* aContext,
return true;
}
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
if (aWidgetType == NS_THEME_TEXTFIELD ||
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
aWidgetType == NS_THEME_DROPDOWN)
@ -1916,7 +1924,7 @@ nsNativeThemeWin::GetWidgetOverflow(nsDeviceContext* aContext,
* a border only shows up if the widget is being hovered.
*/
#if 0
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
/* We explicitly draw dropdown buttons in HTML content 1px bigger
* up, right, and bottom so that they overlap the dropdown's border
* like they're supposed to.
@ -2042,7 +2050,7 @@ nsNativeThemeWin::GetMinimumWidgetSize(nsRenderingContext* aContext, nsIFrame* a
*aIsOverridable = false;
// on Vista, GetThemePartAndState returns odd values for
// scale thumbs, so use a hardcoded size instead.
if (nsUXThemeData::sIsVistaOrLater) {
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION) {
if (aWidgetType == NS_THEME_SCALE_THUMB_HORIZONTAL) {
aResult->width = 12;
aResult->height = 20;
@ -2217,7 +2225,7 @@ nsNativeThemeWin::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
}
// On Vista, the scrollbar buttons need to change state when the track has/doesn't have hover
if (!nsUXThemeData::sIsVistaOrLater &&
if (WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION &&
(aWidgetType == NS_THEME_SCROLLBAR_TRACK_VERTICAL ||
aWidgetType == NS_THEME_SCROLLBAR_TRACK_HORIZONTAL)) {
*aShouldRepaint = false;
@ -2226,7 +2234,7 @@ nsNativeThemeWin::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
// We need to repaint the dropdown arrow in vista HTML combobox controls when
// the control is closed to get rid of the hover effect.
if (nsUXThemeData::sIsVistaOrLater &&
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
(aWidgetType == NS_THEME_DROPDOWN || aWidgetType == NS_THEME_DROPDOWN_BUTTON) &&
IsHTMLContent(aFrame))
{

View File

@ -69,10 +69,6 @@ nsUXThemeData::sDwmDLL = NULL;
BOOL
nsUXThemeData::sFlatMenus = FALSE;
bool
nsUXThemeData::sIsXPOrLater = false;
bool
nsUXThemeData::sIsVistaOrLater = false;
bool nsUXThemeData::sTitlebarInfoPopulatedAero = false;
bool nsUXThemeData::sTitlebarInfoPopulatedThemed = false;
@ -121,10 +117,6 @@ nsUXThemeData::Initialize()
::ZeroMemory(sThemes, sizeof(sThemes));
NS_ASSERTION(!sThemeDLL, "nsUXThemeData being initialized twice!");
WinUtils::WinVersion version = WinUtils::GetWindowsVersion();
sIsXPOrLater = version >= WinUtils::WINXP_VERSION;
sIsVistaOrLater = version >= WinUtils::VISTA_VERSION;
if (GetThemeDLL()) {
openTheme = (OpenThemeDataPtr)GetProcAddress(sThemeDLL, "OpenThemeData");
closeTheme = (CloseThemeDataPtr)GetProcAddress(sThemeDLL, "CloseThemeData");
@ -166,17 +158,9 @@ nsUXThemeData::Invalidate() {
sThemes[i] = NULL;
}
}
if (sIsXPOrLater) {
BOOL useFlat = false;
sFlatMenus = ::SystemParametersInfo(SPI_GETFLATMENU, 0, &useFlat, 0) ?
useFlat : false;
} else {
// Contrary to Microsoft's documentation, SPI_GETFLATMENU will not fail
// on Windows 2000, and it is also possible (though unlikely) for WIN2K
// to be misconfigured in such a way that it would return true, so we
// shall give WIN2K special treatment
sFlatMenus = false;
}
BOOL useFlat = false;
sFlatMenus = ::SystemParametersInfo(SPI_GETFLATMENU, 0, &useFlat, 0) ?
useFlat : false;
}
HANDLE
@ -193,7 +177,7 @@ nsUXThemeData::GetTheme(nsUXThemeClass cls) {
HMODULE
nsUXThemeData::GetThemeDLL() {
if (!sThemeDLL && sIsXPOrLater)
if (!sThemeDLL)
sThemeDLL = ::LoadLibraryW(kThemeLibraryName);
return sThemeDLL;
}
@ -201,7 +185,7 @@ nsUXThemeData::GetThemeDLL() {
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
HMODULE
nsUXThemeData::GetDwmDLL() {
if (!sDwmDLL && sIsVistaOrLater)
if (!sDwmDLL && WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION)
sDwmDLL = ::LoadLibraryW(kDwmLibraryName);
return sDwmDLL;
}

View File

@ -128,8 +128,6 @@ public:
static const PRUnichar kDwmLibraryName[];
#endif
static BOOL sFlatMenus;
static bool sIsXPOrLater;
static bool sIsVistaOrLater;
static bool sTitlebarInfoPopulatedAero;
static bool sTitlebarInfoPopulatedThemed;
static SIZE sCommandButtons[4];

View File

@ -1273,7 +1273,8 @@ NS_METHOD nsWindow::IsVisible(bool & bState)
// transparency. These routines are called on size and move operations.
void nsWindow::ClearThemeRegion()
{
if (nsUXThemeData::sIsVistaOrLater && !HasGlass() &&
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
!HasGlass() &&
(mWindowType == eWindowType_popup && !IsPopupWithTitleBar() &&
(mPopupType == ePopupTypeTooltip || mPopupType == ePopupTypePanel))) {
SetWindowRgn(mWnd, NULL, false);
@ -1287,7 +1288,8 @@ void nsWindow::SetThemeRegion()
// so default constants are used for part and state. At some point we might need part and
// state values from nsNativeThemeWin's GetThemePartAndState, but currently windows that
// change shape based on state haven't come up.
if (nsUXThemeData::sIsVistaOrLater && !HasGlass() &&
if (WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
!HasGlass() &&
(mWindowType == eWindowType_popup && !IsPopupWithTitleBar() &&
(mPopupType == ePopupTypeTooltip || mPopupType == ePopupTypePanel))) {
HRGN hRgn = nsnull;
@ -6357,7 +6359,7 @@ nsWindow::InitMouseWheelScrollData()
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0,
&sMouseWheelScrollChars, 0)) {
NS_ASSERTION(!nsUXThemeData::sIsVistaOrLater,
NS_ASSERTION(WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION,
"Failed to get SPI_GETWHEELSCROLLCHARS");
sMouseWheelScrollChars = 1;
} else if (sMouseWheelScrollChars > WHEEL_DELTA) {