📄 renderthemewin.cpp
字号:
/* * Copyright (C) 2006, 2007 Apple Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */#include "config.h"#include "RenderThemeWin.h"#include "CSSStyleSheet.h"#include "CSSValueKeywords.h"#include "Document.h"#include "GraphicsContext.h"#include "HTMLElement.h"#include "HTMLSelectElement.h"#include "Icon.h"#include "RenderSlider.h"#include "SoftLinking.h"#include "UserAgentStyleSheets.h"#include <tchar.h>/* * The following constants are used to determine how a widget is drawn using * Windows' Theme API. For more information on theme parts and states see * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp */// Generic state constants#define TS_NORMAL 1#define TS_HOVER 2#define TS_ACTIVE 3#define TS_DISABLED 4#define TS_FOCUSED 5// Button constants#define BP_BUTTON 1#define BP_RADIO 2#define BP_CHECKBOX 3// Textfield constants#define TFP_TEXTFIELD 1#define TFS_READONLY 6// ComboBox constants (from tmschema.h)#define CP_DROPDOWNBUTTON 1// TrackBar (slider) parts#define TKP_TRACK 1#define TKP_TRACKVERT 2// TrackBar (slider) thumb parts#define TKP_THUMBBOTTOM 4#define TKP_THUMBTOP 5#define TKP_THUMBLEFT 7#define TKP_THUMBRIGHT 8// Trackbar (slider) thumb states#define TUS_NORMAL 1#define TUS_HOT 2#define TUS_PRESSED 3#define TUS_FOCUSED 4#define TUS_DISABLED 5// button states#define PBS_NORMAL 1#define PBS_HOT 2#define PBS_PRESSED 3#define PBS_DISABLED 4#define PBS_DEFAULTED 5SOFT_LINK_LIBRARY(uxtheme)SOFT_LINK(uxtheme, OpenThemeData, HANDLE, WINAPI, (HWND hwnd, LPCWSTR pszClassList), (hwnd, pszClassList))SOFT_LINK(uxtheme, CloseThemeData, HRESULT, WINAPI, (HANDLE hTheme), (hTheme))SOFT_LINK(uxtheme, DrawThemeBackground, HRESULT, WINAPI, (HANDLE hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect), (hTheme, hdc, iPartId, iStateId, pRect, pClipRect))SOFT_LINK(uxtheme, IsThemeActive, BOOL, WINAPI, (), ())SOFT_LINK(uxtheme, IsThemeBackgroundPartiallyTransparent, BOOL, WINAPI, (HANDLE hTheme, int iPartId, int iStateId), (hTheme, iPartId, iStateId))static bool haveTheme;using namespace std;namespace WebCore {// This is the fixed width IE and Firefox use for buttons on dropdown menusstatic const int dropDownButtonWidth = 17;static const int shell32MagnifierIconIndex = 22;// Default font size to match Firefox.static const float defaultControlFontPixelSize = 13;static const float defaultCancelButtonSize = 9;static const float minCancelButtonSize = 5;static const float maxCancelButtonSize = 21;static const float defaultSearchFieldResultsDecorationSize = 13;static const float minSearchFieldResultsDecorationSize = 9;static const float maxSearchFieldResultsDecorationSize = 30;static const float defaultSearchFieldResultsButtonWidth = 18;static bool gWebKitIsBeingUnloaded;void RenderThemeWin::setWebKitIsBeingUnloaded(){ gWebKitIsBeingUnloaded = true;}#if !USE(SAFARI_THEME)RenderTheme* theme(){ static RenderThemeWin winTheme; return &winTheme;}#endifRenderThemeWin::RenderThemeWin() : m_buttonTheme(0) , m_textFieldTheme(0) , m_menuListTheme(0) , m_sliderTheme(0){ haveTheme = uxthemeLibrary() && IsThemeActive();}RenderThemeWin::~RenderThemeWin(){ // If WebKit is being unloaded, then uxtheme.dll is no longer available. if (gWebKitIsBeingUnloaded || !uxthemeLibrary()) return; close();}HANDLE RenderThemeWin::buttonTheme() const{ if (haveTheme && !m_buttonTheme) m_buttonTheme = OpenThemeData(0, L"Button"); return m_buttonTheme;}HANDLE RenderThemeWin::textFieldTheme() const{ if (haveTheme && !m_textFieldTheme) m_textFieldTheme = OpenThemeData(0, L"Edit"); return m_textFieldTheme;}HANDLE RenderThemeWin::menuListTheme() const{ if (haveTheme && !m_menuListTheme) m_menuListTheme = OpenThemeData(0, L"ComboBox"); return m_menuListTheme;}HANDLE RenderThemeWin::sliderTheme() const{ if (haveTheme && !m_sliderTheme) m_sliderTheme = OpenThemeData(0, L"TrackBar"); return m_sliderTheme;}void RenderThemeWin::close(){ // This method will need to be called when the OS theme changes to flush our cached themes. if (m_buttonTheme) CloseThemeData(m_buttonTheme); if (m_textFieldTheme) CloseThemeData(m_textFieldTheme); if (m_menuListTheme) CloseThemeData(m_menuListTheme); if (m_sliderTheme) CloseThemeData(m_sliderTheme); m_buttonTheme = m_textFieldTheme = m_menuListTheme = m_sliderTheme = 0; haveTheme = uxthemeLibrary() && IsThemeActive();}void RenderThemeWin::themeChanged(){ close();}String RenderThemeWin::extraDefaultStyleSheet(){ return String(themeWinUserAgentStyleSheet, sizeof(themeWinUserAgentStyleSheet));}String RenderThemeWin::extraQuirksStyleSheet(){ return String(themeWinQuirksUserAgentStyleSheet, sizeof(themeWinQuirksUserAgentStyleSheet));}bool RenderThemeWin::supportsHover(const RenderStyle*) const{ // The Classic/2k look has no hover effects. return haveTheme;}Color RenderThemeWin::platformActiveSelectionBackgroundColor() const{ COLORREF color = GetSysColor(COLOR_HIGHLIGHT); return Color(GetRValue(color), GetGValue(color), GetBValue(color));}Color RenderThemeWin::platformInactiveSelectionBackgroundColor() const{ // This color matches Firefox. return Color(176, 176, 176);}Color RenderThemeWin::platformActiveSelectionForegroundColor() const{ COLORREF color = GetSysColor(COLOR_HIGHLIGHTTEXT); return Color(GetRValue(color), GetGValue(color), GetBValue(color));}Color RenderThemeWin::platformInactiveSelectionForegroundColor() const{ return platformActiveSelectionForegroundColor();}static void fillFontDescription(FontDescription& fontDescription, LOGFONT& logFont, float fontSize){ fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::NoFamily); fontDescription.firstFamily().setFamily(String(logFont.lfFaceName)); fontDescription.setSpecifiedSize(fontSize); fontDescription.setWeight(logFont.lfWeight >= 700 ? FontWeightBold : FontWeightNormal); // FIXME: Use real weight. fontDescription.setItalic(logFont.lfItalic);}static void fillFontDescription(FontDescription& fontDescription, LOGFONT& logFont){ fillFontDescription(fontDescription, logFont, abs(logFont.lfHeight));}void RenderThemeWin::systemFont(int propId, FontDescription& fontDescription) const{ static FontDescription captionFont; static FontDescription controlFont; static FontDescription smallCaptionFont; static FontDescription menuFont; static FontDescription iconFont; static FontDescription messageBoxFont; static FontDescription statusBarFont; static FontDescription systemFont; static bool initialized; static NONCLIENTMETRICS ncm; if (!initialized) { initialized = true; ncm.cbSize = sizeof(NONCLIENTMETRICS); ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0); } switch (propId) { case CSSValueIcon: { if (!iconFont.isAbsoluteSize()) { LOGFONT logFont; ::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0); fillFontDescription(iconFont, logFont); } fontDescription = iconFont; break; } case CSSValueMenu: if (!menuFont.isAbsoluteSize()) fillFontDescription(menuFont, ncm.lfMenuFont); fontDescription = menuFont; break; case CSSValueMessageBox: if (!messageBoxFont.isAbsoluteSize()) fillFontDescription(messageBoxFont, ncm.lfMessageFont); fontDescription = messageBoxFont; break; case CSSValueStatusBar: if (!statusBarFont.isAbsoluteSize()) fillFontDescription(statusBarFont, ncm.lfStatusFont); fontDescription = statusBarFont; break; case CSSValueCaption: if (!captionFont.isAbsoluteSize()) fillFontDescription(captionFont, ncm.lfCaptionFont); fontDescription = captionFont; break; case CSSValueSmallCaption: if (!smallCaptionFont.isAbsoluteSize()) fillFontDescription(smallCaptionFont, ncm.lfSmCaptionFont); fontDescription = smallCaptionFont;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -