⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renderthemesafari.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* * Copyright (C) 2007, 2008 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#include "config.h"#include "RenderThemeSafari.h"#include "RenderThemeWin.h"#include "Settings.h"#if USE(SAFARI_THEME)#include "CSSValueKeywords.h"#include "Document.h"#include "Element.h"#include "Frame.h"#include "FrameView.h"#include "GraphicsContext.h"#include "FormControlElement.h"#include "HTMLInputElement.h"#include "HTMLMediaElement.h"#include "HTMLNames.h"#include "RenderSlider.h"#include "RenderView.h"#include "RetainPtr.h"#include "SoftLinking.h"#include "cssstyleselector.h"#include <CoreGraphics/CoreGraphics.h> using std::min;// FIXME: The platform-independent code in this class should be factored out and merged with RenderThemeMac.  namespace WebCore {using namespace HTMLNames;using namespace SafariTheme;enum {    topMargin,    rightMargin,    bottomMargin,    leftMargin};enum {    topPadding,    rightPadding,    bottomPadding,    leftPadding};RenderTheme* theme(){    static RenderThemeSafari safariTheme;    static RenderThemeWin windowsTheme;    if (Settings::shouldPaintNativeControls())        return &windowsTheme;    return &safariTheme;}#if !defined(NDEBUG) && defined(USE_DEBUG_SAFARI_THEME)SOFT_LINK_DEBUG_LIBRARY(SafariTheme)#elseSOFT_LINK_LIBRARY(SafariTheme)#endifSOFT_LINK(SafariTheme, paintThemePart, void, __stdcall, (ThemePart part, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state), (part, context, rect, size, state))#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2SOFT_LINK(SafariTheme, STPaintProgressIndicator, void, APIENTRY, (ProgressIndicatorType type, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state, float value), (type, context, rect, size, state, value))#endifThemeControlState RenderThemeSafari::determineState(RenderObject* o) const{    ThemeControlState result = 0;    if (isActive(o))        result |= SafariTheme::ActiveState;    if (isEnabled(o) && !isReadOnlyControl(o))        result |= SafariTheme::EnabledState;    if (isPressed(o))        result |= SafariTheme::PressedState;    if (isChecked(o))        result |= SafariTheme::CheckedState;    if (isIndeterminate(o))        result |= SafariTheme::IndeterminateCheckedState;    if (isFocused(o))        result |= SafariTheme::FocusedState;    if (isDefault(o))        result |= SafariTheme::DefaultState;    return result;}static NSControlSize controlSizeFromRect(const IntRect& rect, const IntSize sizes[]){    if (sizes[NSRegularControlSize].height() == rect.height())        return NSRegularControlSize;    else if (sizes[NSMiniControlSize].height() == rect.height())        return NSMiniControlSize;        return NSSmallControlSize;}RenderThemeSafari::RenderThemeSafari(){}RenderThemeSafari::~RenderThemeSafari(){}Color RenderThemeSafari::platformActiveSelectionBackgroundColor() const{    return Color(181, 213, 255);}Color RenderThemeSafari::platformInactiveSelectionBackgroundColor() const{    return Color(212, 212, 212);}Color RenderThemeSafari::activeListBoxSelectionBackgroundColor() const{    // FIXME: This should probably just be a darker version of the platformActiveSelectionBackgroundColor    return Color(56, 117, 215);}static float systemFontSizeForControlSize(NSControlSize controlSize){    static float sizes[] = { 13.0f, 11.0f, 9.0f };        return sizes[controlSize];}void RenderThemeSafari::systemFont(int propId, FontDescription& fontDescription) const{    static FontDescription systemFont;    static FontDescription smallSystemFont;    static FontDescription menuFont;    static FontDescription labelFont;    static FontDescription miniControlFont;    static FontDescription smallControlFont;    static FontDescription controlFont;    FontDescription* cachedDesc;    float fontSize = 0;    switch (propId) {        case CSSValueSmallCaption:            cachedDesc = &smallSystemFont;            if (!smallSystemFont.isAbsoluteSize())                fontSize = systemFontSizeForControlSize(NSSmallControlSize);            break;        case CSSValueMenu:            cachedDesc = &menuFont;            if (!menuFont.isAbsoluteSize())                fontSize = systemFontSizeForControlSize(NSRegularControlSize);            break;        case CSSValueStatusBar:            cachedDesc = &labelFont;            if (!labelFont.isAbsoluteSize())                fontSize = 10.0f;            break;        case CSSValueWebkitMiniControl:            cachedDesc = &miniControlFont;            if (!miniControlFont.isAbsoluteSize())                fontSize = systemFontSizeForControlSize(NSMiniControlSize);            break;        case CSSValueWebkitSmallControl:            cachedDesc = &smallControlFont;            if (!smallControlFont.isAbsoluteSize())                fontSize = systemFontSizeForControlSize(NSSmallControlSize);            break;        case CSSValueWebkitControl:            cachedDesc = &controlFont;            if (!controlFont.isAbsoluteSize())                fontSize = systemFontSizeForControlSize(NSRegularControlSize);            break;        default:            cachedDesc = &systemFont;            if (!systemFont.isAbsoluteSize())                fontSize = 13.0f;    }    if (fontSize) {        cachedDesc->setIsAbsoluteSize(true);        cachedDesc->setGenericFamily(FontDescription::NoFamily);        cachedDesc->firstFamily().setFamily("Lucida Grande");        cachedDesc->setSpecifiedSize(fontSize);        cachedDesc->setWeight(FontWeightNormal);        cachedDesc->setItalic(false);    }    fontDescription = *cachedDesc;}bool RenderThemeSafari::isControlStyled(const RenderStyle* style, const BorderData& border,                                     const FillLayer& background, const Color& backgroundColor) const{    // If we didn't find SafariTheme.dll we won't be able to paint any themed controls.    if (!SafariThemeLibrary())        return true;    if (style->appearance() == TextFieldPart || style->appearance() == TextAreaPart || style->appearance() == ListboxPart)        return style->border() != border;    return RenderTheme::isControlStyled(style, border, background, backgroundColor);}void RenderThemeSafari::adjustRepaintRect(const RenderObject* o, IntRect& r){    NSControlSize controlSize = controlSizeForFont(o->style());    switch (o->style()->appearance()) {        case CheckboxPart: {            // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox            // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.            r = inflateRect(r, checkboxSizes()[controlSize], checkboxMargins(controlSize));            break;        }        case RadioPart: {            // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox            // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.            r = inflateRect(r, radioSizes()[controlSize], radioMargins(controlSize));            break;        }        case PushButtonPart:        case DefaultButtonPart:        case ButtonPart: {            // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox            // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.            if (r.height() <= buttonSizes()[NSRegularControlSize].height())                r = inflateRect(r, buttonSizes()[controlSize], buttonMargins(controlSize));            break;        }        case MenulistPart: {            r = inflateRect(r, popupButtonSizes()[controlSize], popupButtonMargins(controlSize));            break;        }        default:            break;    }}IntRect RenderThemeSafari::inflateRect(const IntRect& r, const IntSize& size, const int* margins) const{    // Only do the inflation if the available width/height are too small.  Otherwise try to    // fit the glow/check space into the available box's width/height.    int widthDelta = r.width() - (size.width() + margins[leftMargin] + margins[rightMargin]);    int heightDelta = r.height() - (size.height() + margins[topMargin] + margins[bottomMargin]);    IntRect result(r);    if (widthDelta < 0) {        result.setX(result.x() - margins[leftMargin]);        result.setWidth(result.width() - widthDelta);    }    if (heightDelta < 0) {        result.setY(result.y() - margins[topMargin]);        result.setHeight(result.height() - heightDelta);    }    return result;}int RenderThemeSafari::baselinePosition(const RenderObject* o) const{    if (!o->isBox())        return 0;    if (o->style()->appearance() == CheckboxPart || o->style()->appearance() == RadioPart) {        const RenderBox* box = toRenderBox(o);        return box->marginTop() + box->height() - 2; // The baseline is 2px up from the bottom of the checkbox/radio in AppKit.    }    return RenderTheme::baselinePosition(o);}bool RenderThemeSafari::controlSupportsTints(const RenderObject* o) const{    if (!isEnabled(o))        return false;    // Checkboxes only have tint when checked.    if (o->style()->appearance() == CheckboxPart)        return isChecked(o);    // For now assume other controls have tint if enabled.    return true;}NSControlSize RenderThemeSafari::controlSizeForFont(RenderStyle* style) const{    int fontSize = style->fontSize();    if (fontSize >= 16)        return NSRegularControlSize;    if (fontSize >= 11)        return NSSmallControlSize;    return NSMiniControlSize;}/*void RenderThemeSafari::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -