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

📄 renderthemeqt.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        break;    }    case MenulistPart: {        QStyleOptionComboBox styleOption;        styleOption.state |= QStyle::State_Small;        int contentHeight = qMax(fm.lineSpacing(), 14) + 2;        QSize menuListSize = applicationStyle->sizeFromContents(QStyle::CT_ComboBox,                                                        &styleOption,                                                        QSize(0, contentHeight),                                                        0);        size.setHeight(menuListSize.height());        break;    }    case TextFieldPart: {        const int verticalMargin = 1;        const int horizontalMargin = 2;        int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin;        int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin;        QStyleOptionFrameV2 opt;        opt.lineWidth = applicationStyle->pixelMetric(QStyle::PM_DefaultFrameWidth,                                                           &opt, 0);        QSize sz = applicationStyle->sizeFromContents(QStyle::CT_LineEdit,                                                           &opt,                                                           QSize(w, h).expandedTo(QApplication::globalStrut()),                                                           0);        size.setHeight(sz.height());        break;    }    default:        break;    }    // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.    if (renderStyle->width().isIntrinsicOrAuto() && size.width() > 0)        renderStyle->setWidth(Length(size.width(), Fixed));    if (renderStyle->height().isAuto() && size.height() > 0)        renderStyle->setHeight(Length(size.height(), Fixed));}void RenderThemeQt::setCheckboxSize(RenderStyle* style) const{    computeSizeBasedOnStyle(style);}bool RenderThemeQt::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    return paintButton(o, i, r);}void RenderThemeQt::setRadioSize(RenderStyle* style) const{    computeSizeBasedOnStyle(style);}bool RenderThemeQt::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    return paintButton(o, i, r);}void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    // Ditch the border.    style->resetBorder();    // Height is locked to auto.    style->setHeight(Length(Auto));    // White-space is locked to pre    style->setWhiteSpace(PRE);    FontDescription fontDescription = style->fontDescription();    fontDescription.setIsAbsoluteSize(true);#ifdef Q_WS_MAC // Use fixed font size and family on Mac (like Safari does)    fontDescription.setSpecifiedSize(m_buttonFontPixelSize);    fontDescription.setComputedSize(m_buttonFontPixelSize);#else    fontDescription.setSpecifiedSize(style->fontSize());    fontDescription.setComputedSize(style->fontSize());#endif    FontFamily fontFamily;    fontFamily.setFamily(m_buttonFontFamily);    fontDescription.setFamily(fontFamily);    style->setFontDescription(fontDescription);    style->font().update(selector->fontSelector());    style->setLineHeight(RenderStyle::initialLineHeight());    setButtonSize(style);    setButtonPadding(style);    style->setColor(QApplication::palette().text().color());}void RenderThemeQt::setButtonSize(RenderStyle* style) const{    computeSizeBasedOnStyle(style);}void RenderThemeQt::setButtonPadding(RenderStyle* style) const{    QStyleOptionButton styleOption;    styleOption.state |= QStyle::State_Small;    // Fake a button rect here, since we're just computing deltas    QRect originalRect = QRect(0, 0, 100, 30);    styleOption.rect = originalRect;    // Default padding is based on the button margin pixel metric    int buttonMargin = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin,                                                          &styleOption, 0);    int paddingLeft = buttonMargin;    int paddingRight = buttonMargin;    int paddingTop = 1;    int paddingBottom = 0;    // Then check if the style uses layout margins    QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem,                                                                  &styleOption, 0);    if (!layoutRect.isNull()) {        QRect contentsRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonContents,                                                                  &styleOption, 0);        paddingLeft = contentsRect.left() - layoutRect.left();        paddingRight = layoutRect.right() - contentsRect.right();        paddingTop = contentsRect.top() - layoutRect.top();        // Can't use this right now because we don't have the baseline to compensate        // paddingBottom = layoutRect.bottom() - contentsRect.bottom();    }    style->setPaddingLeft(Length(paddingLeft, Fixed));    style->setPaddingRight(Length(paddingRight, Fixed));    style->setPaddingTop(Length(paddingTop, Fixed));    style->setPaddingBottom(Length(paddingBottom, Fixed));}bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    StylePainter p(i);    if (!p.isValid())       return true;    QStyleOptionButton option;    if (p.widget)       option.initFrom(p.widget);    option.rect = r;    option.state |= QStyle::State_Small;    ControlPart appearance = applyTheme(option, o);    if(appearance == PushButtonPart || appearance == ButtonPart) {        option.rect = inflateButtonRect(option.rect);        p.drawControl(QStyle::CE_PushButton, option);    } else if(appearance == RadioPart) {       p.drawControl(QStyle::CE_RadioButton, option);    } else if(appearance == CheckboxPart) {       p.drawControl(QStyle::CE_CheckBox, option);    }    return false;}void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    style->setBackgroundColor(Color::transparent);    style->setColor(QApplication::palette().text().color());}bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    StylePainter p(i);    if (!p.isValid())        return true;    QStyleOptionFrameV2 panel;    if (p.widget)        panel.initFrom(p.widget);    panel.rect = r;    panel.lineWidth = p.style->pixelMetric(QStyle::PM_DefaultFrameWidth, &panel, p.widget);    panel.state |= QStyle::State_Sunken;    panel.features = QStyleOptionFrameV2::None;    // Get the correct theme data for a text field    ControlPart appearance = applyTheme(panel, o);    if (appearance != TextFieldPart        && appearance != SearchFieldPart        && appearance != TextAreaPart        && appearance != ListboxPart)        return true;    // Now paint the text field.    p.drawPrimitive(QStyle::PE_PanelLineEdit, panel);    return false;}void RenderThemeQt::adjustTextAreaStyle(CSSStyleSelector* selector, RenderStyle* style, Element* element) const{    adjustTextFieldStyle(selector, style, element);}bool RenderThemeQt::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    return paintTextField(o, i, r);}void RenderThemeQt::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    style->resetBorder();    // Height is locked to auto.    style->setHeight(Length(Auto));    // White-space is locked to pre    style->setWhiteSpace(PRE);    computeSizeBasedOnStyle(style);    // Add in the padding that we'd like to use.    setPopupPadding(style);    style->setColor(QApplication::palette().text().color());}void RenderThemeQt::setPopupPadding(RenderStyle* style) const{    const int padding = 8;    style->setPaddingLeft(Length(padding, Fixed));    QStyleOptionComboBox opt;    int w = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0);    style->setPaddingRight(Length(padding + w, Fixed));    style->setPaddingTop(Length(2, Fixed));    style->setPaddingBottom(Length(0, Fixed));}bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    StylePainter p(i);    if (!p.isValid())        return true;    QStyleOptionComboBox opt;    if (p.widget)        opt.initFrom(p.widget);    ControlPart appearance = applyTheme(opt, o);    const QPoint topLeft = r.topLeft();    p.painter->translate(topLeft);    opt.rect.moveTo(QPoint(0,0));    opt.rect.setSize(r.size());    p.drawComplexControl(QStyle::CC_ComboBox, opt);    p.painter->translate(-topLeft);    return false;}void RenderThemeQt::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style,                                              Element* e) const{    // WORKAROUND because html4.css specifies -webkit-border-radius for <select> so we override it here    // see also http://bugs.webkit.org/show_bug.cgi?id=18399    style->resetBorderRadius();    // Height is locked to auto.    style->setHeight(Length(Auto));    // White-space is locked to pre    style->setWhiteSpace(PRE);    computeSizeBasedOnStyle(style);    // Add in the padding that we'd like to use.    setPopupPadding(style);    style->setColor(QApplication::palette().text().color());}bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i,                                        const IntRect& r){    StylePainter p(i);    if (!p.isValid())        return true;    QStyleOptionComboBox option;    if (p.widget)        option.initFrom(p.widget);    applyTheme(option, o);    option.rect = r;    // for drawing the combo box arrow, rely only on the fallback style    p.style = fallbackStyle();    option.subControls = QStyle::SC_ComboBoxArrow;    p.drawComplexControl(QStyle::CC_ComboBox, option);    return false;}bool RenderThemeQt::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& pi,                                     const IntRect& r){    notImplemented();    return RenderTheme::paintSliderTrack(o, pi, r);}bool RenderThemeQt::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& pi,                                     const IntRect& r){    notImplemented();    return RenderTheme::paintSliderThumb(o, pi, r);}bool RenderThemeQt::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& pi,                                     const IntRect& r){    paintTextField(o, pi, r);

⌨️ 快捷键说明

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