📄 renderthemeqt.cpp
字号:
/* * This file is part of the WebKit project. * * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * Copyright (C) 2006 Zack Rusin <zack@kde.org> * 2006 Dirk Mueller <mueller@kde.org> * 2006 Nikolas Zimmermann <zimmermann@kde.org> * Copyright (C) 2008 Holger Hans Peter Freyther * * All rights reserved. * * 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 "qwebpage.h"#include "RenderThemeQt.h"#include "ChromeClientQt.h"#include "NotImplemented.h"#include <QApplication>#include <QColor>#include <QDebug>#include <QFile>#include <QWidget>#include <QPainter>#include <QPushButton>#include <QStyleFactory>#include <QStyleOptionButton>#include <QStyleOptionFrameV2>#include "Color.h"#include "CSSStyleSelector.h"#include "CSSStyleSheet.h"#include "FontSelector.h"#include "Document.h"#include "Page.h"#include "Font.h"#include "RenderTheme.h"#include "GraphicsContext.h"#include "HTMLMediaElement.h"#include "HTMLNames.h"#include "RenderBox.h"namespace WebCore {using namespace HTMLNames;StylePainter::StylePainter(const RenderObject::PaintInfo& paintInfo){ init(paintInfo.context ? paintInfo.context : 0);}StylePainter::StylePainter(GraphicsContext* context){ init(context);}void StylePainter::init(GraphicsContext* context){ painter = static_cast<QPainter*>(context->platformContext()); widget = 0; QPaintDevice* dev = 0; if (painter) dev = painter->device(); if (dev && dev->devType() == QInternal::Widget) widget = static_cast<QWidget*>(dev); style = (widget ? widget->style() : QApplication::style()); if (painter) { // the styles often assume being called with a pristine painter where no brush is set, // so reset it manually oldBrush = painter->brush(); painter->setBrush(Qt::NoBrush); // painting the widget with anti-aliasing will make it blurry // disable it here and restore it later oldAntialiasing = painter->testRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing, false); }}StylePainter::~StylePainter(){ if (painter) { painter->setBrush(oldBrush); painter->setRenderHints(QPainter::Antialiasing, oldAntialiasing); }}RenderTheme* theme(){ static RenderThemeQt rt; return &rt;}RenderThemeQt::RenderThemeQt() : RenderTheme(){ QPushButton button; button.setAttribute(Qt::WA_MacSmallSize); QFont defaultButtonFont = QApplication::font(&button); QFontInfo fontInfo(defaultButtonFont); m_buttonFontFamily = defaultButtonFont.family();#ifdef Q_WS_MAC m_buttonFontPixelSize = fontInfo.pixelSize();#endif m_fallbackStyle = 0;}RenderThemeQt::~RenderThemeQt(){ delete m_fallbackStyle;}// for some widget painting, we need to fallback to Windows styleQStyle* RenderThemeQt::fallbackStyle(){ if(!m_fallbackStyle) m_fallbackStyle = QStyleFactory::create(QLatin1String("windows")); if(!m_fallbackStyle) m_fallbackStyle = QApplication::style(); return m_fallbackStyle;}bool RenderThemeQt::supportsHover(const RenderStyle*) const{ return true;}bool RenderThemeQt::supportsFocusRing(const RenderStyle* style) const{ return true; // Qt provides this through the style}int RenderThemeQt::baselinePosition(const RenderObject* o) const{ if (!o->isBox()) return 0; if (o->style()->appearance() == CheckboxPart || o->style()->appearance() == RadioPart) return toRenderBox(o)->marginTop() + toRenderBox(o)->height() - 2; // Same as in old khtml return RenderTheme::baselinePosition(o);}bool RenderThemeQt::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;}bool RenderThemeQt::supportsControlTints() const{ return true;}static QRect inflateButtonRect(const QRect& originalRect){ QStyleOptionButton option; option.state |= QStyle::State_Small; option.rect = originalRect; QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem, &option, 0); if (!layoutRect.isNull()) { int paddingLeft = layoutRect.left() - originalRect.left(); int paddingRight = originalRect.right() - layoutRect.right(); int paddingTop = layoutRect.top() - originalRect.top(); int paddingBottom = originalRect.bottom() - layoutRect.bottom(); return originalRect.adjusted(-paddingLeft, -paddingTop, paddingRight, paddingBottom); } else { return originalRect; }}void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& r){ switch (o->style()->appearance()) { case CheckboxPart: { break; } case RadioPart: { break; } case PushButtonPart: case ButtonPart: { QRect inflatedRect = inflateButtonRect(r); r = IntRect(inflatedRect.x(), inflatedRect.y(), inflatedRect.width(), inflatedRect.height()); break; } case MenulistPart: { break; } default: break; }}bool RenderThemeQt::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const{ if (style->appearance() == TextFieldPart || style->appearance() == TextAreaPart || style->appearance() == ListboxPart) { return style->border() != border; } return RenderTheme::isControlStyled(style, border, background, backgroundColor);}Color RenderThemeQt::platformActiveSelectionBackgroundColor() const{ QPalette pal = QApplication::palette(); return pal.brush(QPalette::Active, QPalette::Highlight).color();}Color RenderThemeQt::platformInactiveSelectionBackgroundColor() const{ QPalette pal = QApplication::palette(); return pal.brush(QPalette::Inactive, QPalette::Highlight).color();}Color RenderThemeQt::platformActiveSelectionForegroundColor() const{ QPalette pal = QApplication::palette(); return pal.brush(QPalette::Active, QPalette::HighlightedText).color();}Color RenderThemeQt::platformInactiveSelectionForegroundColor() const{ QPalette pal = QApplication::palette(); return pal.brush(QPalette::Inactive, QPalette::HighlightedText).color();}void RenderThemeQt::systemFont(int propId, FontDescription& fontDescription) const{ // no-op}int RenderThemeQt::minimumMenuListSize(RenderStyle*) const{ const QFontMetrics &fm = QApplication::fontMetrics(); return 7 * fm.width(QLatin1Char('x'));}static void computeSizeBasedOnStyle(RenderStyle* renderStyle){ // If the width and height are both specified, then we have nothing to do. if (!renderStyle->width().isIntrinsicOrAuto() && !renderStyle->height().isAuto()) return; QSize size(0, 0); const QFontMetrics fm(renderStyle->font().font()); QStyle* applicationStyle = QApplication::style(); switch (renderStyle->appearance()) { case CheckboxPart: { QStyleOption styleOption; styleOption.state |= QStyle::State_Small; int checkBoxWidth = applicationStyle->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption); size = QSize(checkBoxWidth, checkBoxWidth); break; } case RadioPart: { QStyleOption styleOption; styleOption.state |= QStyle::State_Small; int radioWidth = applicationStyle->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &styleOption); size = QSize(radioWidth, radioWidth); break; } case PushButtonPart: case ButtonPart: { QStyleOptionButton styleOption; styleOption.state |= QStyle::State_Small; QSize contentSize = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); QSize pushButtonSize = applicationStyle->sizeFromContents(QStyle::CT_PushButton, &styleOption, contentSize, 0); styleOption.rect = QRect(0, 0, pushButtonSize.width(), pushButtonSize.height()); QRect layoutRect = applicationStyle->subElementRect(QStyle::SE_PushButtonLayoutItem, &styleOption, 0); // If the style supports layout rects we use that, and // compensate accordingly in paintButton() below. if (!layoutRect.isNull()) { size.setHeight(layoutRect.height()); } else { size.setHeight(pushButtonSize.height()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -