Changeset 44759 in webkit


Ignore:
Timestamp:
Jun 17, 2009 7:52:43 AM (15 years ago)
Author:
Adam Roben
Message:

2009-06-16 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org>

Reviewed by Simon Hausmann.

Follow up to bug https://bugs.webkit.org/show_bug.cgi?id=26278
Patch that make WebCore have a RenderTheme per page

Make the Qt implementation of RenderTheme create a theme per page,
and use the QStyle associated with the view of each page, in order
to make the QWidget setStyle() method work as advertised.

  • platform/qt/RenderThemeQt.cpp: (WebCore::RenderThemeQt::RenderThemeQt): (WebCore::RenderThemeQt::qStyle): (WebCore::findFrameLineWidth): (WebCore::inflateButtonRect): (WebCore::RenderThemeQt::adjustRepaintRect): (WebCore::RenderThemeQt::isControlStyled): (WebCore::RenderThemeQt::computeSizeBasedOnStyle): (WebCore::RenderThemeQt::setButtonPadding): (WebCore::RenderThemeQt::paintButton): (WebCore::RenderThemeQt::paintTextField): (WebCore::RenderThemeQt::setPopupPadding):
  • platform/qt/RenderThemeQt.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r44758 r44759  
     12009-06-16  Kenneth Rohde Christiansen  <kenneth.christiansen@openbossa.org>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Follow up to bug https://bugs.webkit.org/show_bug.cgi?id=26278
     6        Patch that make WebCore have a RenderTheme per page
     7
     8        Make the Qt implementation of RenderTheme create a theme per page,
     9        and use the QStyle associated with the view of each page, in order
     10        to make the QWidget setStyle() method work as advertised.
     11
     12        * platform/qt/RenderThemeQt.cpp:
     13        (WebCore::RenderThemeQt::RenderThemeQt):
     14        (WebCore::RenderThemeQt::qStyle):
     15        (WebCore::findFrameLineWidth):
     16        (WebCore::inflateButtonRect):
     17        (WebCore::RenderThemeQt::adjustRepaintRect):
     18        (WebCore::RenderThemeQt::isControlStyled):
     19        (WebCore::RenderThemeQt::computeSizeBasedOnStyle):
     20        (WebCore::RenderThemeQt::setButtonPadding):
     21        (WebCore::RenderThemeQt::paintButton):
     22        (WebCore::RenderThemeQt::paintTextField):
     23        (WebCore::RenderThemeQt::setPopupPadding):
     24        * platform/qt/RenderThemeQt.h:
     25
    1262009-06-16  Kenneth Rohde Christiansen  <kenneth.christiansen@openbossa.org>
    227
  • trunk/WebCore/platform/qt/RenderThemeQt.cpp

    r44758 r44759  
    121121}
    122122
    123 RenderThemeQt::RenderThemeQt()
     123RenderThemeQt::RenderThemeQt(Page* page)
    124124    : RenderTheme()
     125    , m_page(page)
     126    , m_fallbackStyle(0)
    125127{
    126128    QPushButton button;
     
    132134    m_buttonFontPixelSize = fontInfo.pixelSize();
    133135#endif
    134 
    135     m_fallbackStyle = 0;
    136 
    137     // this will need to be regenerated when the style changes
    138     QLineEdit lineEdit;
    139     QStyleOptionFrameV2 opt;
    140     m_frameLineWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth,
    141                                                           &opt, &lineEdit);
    142136}
    143137
     
    157151
    158152    return m_fallbackStyle;
     153}
     154
     155QStyle* RenderThemeQt::qStyle() const
     156{
     157    if (m_page) {
     158        ChromeClientQt* client = static_cast<ChromeClientQt*>(m_page->chrome()->client());
     159
     160        if (!client->m_webPage)
     161            return QApplication::style();
     162
     163        if (QWidget* view = client->m_webPage->view())
     164            return view->style();
     165    }
     166
     167    return QApplication::style();
    159168}
    160169
     
    198207}
    199208
    200 static QRect inflateButtonRect(const QRect& originalRect)
     209static int findFrameLineWidth(QStyle* style)
     210{
     211    QLineEdit lineEdit;
     212    QStyleOptionFrameV2 opt;
     213    return style->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, &lineEdit);
     214}
     215
     216static QRect inflateButtonRect(const QRect& originalRect, QStyle* style)
    201217{
    202218    QStyleOptionButton option;
     
    204220    option.rect = originalRect;
    205221
    206     QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem,
    207                                                                   &option, 0);
     222    QRect layoutRect = style->subElementRect(QStyle::SE_PushButtonLayoutItem, &option, 0);
    208223    if (!layoutRect.isNull()) {
    209224        int paddingLeft = layoutRect.left() - originalRect.left();
     
    218233}
    219234
    220 void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& r)
     235void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& rect)
    221236{
    222237    switch (o->style()->appearance()) {
    223     case CheckboxPart: {
    224         break;
    225     }
    226     case RadioPart: {
    227         break;
    228     }
     238    case CheckboxPart:
     239        break;
     240    case RadioPart:
     241        break;
    229242    case PushButtonPart:
    230243    case ButtonPart: {
    231         QRect inflatedRect = inflateButtonRect(r);
    232         r = IntRect(inflatedRect.x(), inflatedRect.y(), inflatedRect.width(), inflatedRect.height());
    233         break;
    234     }
    235     case MenulistPart: {
    236         break;
    237     }
     244        QRect inflatedRect = inflateButtonRect(rect, qStyle());
     245        rect = IntRect(inflatedRect.x(), inflatedRect.y(), inflatedRect.width(), inflatedRect.height());
     246        break;
     247    }
     248    case MenulistPart:
     249        break;
    238250    default:
    239251        break;
     
    245257{
    246258    if (style->appearance() == TextFieldPart
    247             || style->appearance() == TextAreaPart
    248             || style->appearance() == ListboxPart) {
     259        || style->appearance() == TextAreaPart
     260        || style->appearance() == ListboxPart) {
    249261        return style->border() != border;
    250262    }
     
    296308    QSize size(0, 0);
    297309    const QFontMetrics fm(renderStyle->font().font());
    298     QStyle* applicationStyle = QApplication::style();
     310    QStyle* style = qStyle();
    299311
    300312    switch (renderStyle->appearance()) {
     
    302314        QStyleOption styleOption;
    303315        styleOption.state |= QStyle::State_Small;
    304         int checkBoxWidth = applicationStyle->pixelMetric(QStyle::PM_IndicatorWidth,
    305                                                           &styleOption);
     316        int checkBoxWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption);
    306317        size = QSize(checkBoxWidth, checkBoxWidth);
    307318        break;
     
    310321        QStyleOption styleOption;
    311322        styleOption.state |= QStyle::State_Small;
    312         int radioWidth = applicationStyle->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth,
    313                                                        &styleOption);
     323        int radioWidth = style->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &styleOption);
    314324        size = QSize(radioWidth, radioWidth);
    315325        break;
     
    320330        styleOption.state |= QStyle::State_Small;
    321331        QSize contentSize = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X"));
    322         QSize pushButtonSize = applicationStyle->sizeFromContents(QStyle::CT_PushButton,
    323                                                                   &styleOption,
    324                                                                   contentSize,
    325                                                                   0);
     332        QSize pushButtonSize = style->sizeFromContents(QStyle::CT_PushButton,
     333                                                       &styleOption, contentSize, 0);
    326334        styleOption.rect = QRect(0, 0, pushButtonSize.width(), pushButtonSize.height());
    327         QRect layoutRect = applicationStyle->subElementRect(QStyle::SE_PushButtonLayoutItem,
    328                                                                   &styleOption,
    329                                                                   0);
    330         // If the style supports layout rects we use that, and
    331         // compensate accordingly in paintButton() below.
     335        QRect layoutRect = style->subElementRect(QStyle::SE_PushButtonLayoutItem,
     336                                                 &styleOption, 0);
     337
     338        // If the style supports layout rects we use that, and  compensate accordingly
     339        // in paintButton() below.
    332340        if (!layoutRect.isNull()) {
    333341            size.setHeight(layoutRect.height());
     
    342350        styleOption.state |= QStyle::State_Small;
    343351        int contentHeight = qMax(fm.lineSpacing(), 14) + 2;
    344         QSize menuListSize = applicationStyle->sizeFromContents(QStyle::CT_ComboBox,
    345                                                         &styleOption,
    346                                                         QSize(0, contentHeight),
    347                                                         0);
     352        QSize menuListSize = style->sizeFromContents(QStyle::CT_ComboBox,
     353                                                     &styleOption, QSize(0, contentHeight), 0);
    348354        size.setHeight(menuListSize.height());
    349355        break;
     
    355361        int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin;
    356362        QStyleOptionFrameV2 opt;
    357         opt.lineWidth = m_frameLineWidth;
    358         QSize sz = applicationStyle->sizeFromContents(QStyle::CT_LineEdit,
    359                                                       &opt,
    360                                                       QSize(w, h).expandedTo(QApplication::globalStrut()),
    361                                                       0);
     363        opt.lineWidth = findFrameLineWidth(style);
     364        QSize sz = style->sizeFromContents(QStyle::CT_LineEdit,
     365                                           &opt,
     366                                           QSize(w, h).expandedTo(QApplication::globalStrut()),
     367                                           0);
    362368        size.setHeight(sz.height());
    363369
     
    447453
    448454    // Default padding is based on the button margin pixel metric
    449     int buttonMargin = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin,
    450                                                           &styleOption, 0);
     455    int buttonMargin = qStyle()->pixelMetric(QStyle::PM_ButtonMargin, &styleOption, 0);
    451456    int paddingLeft = buttonMargin;
    452457    int paddingRight = buttonMargin;
     
    455460
    456461    // Then check if the style uses layout margins
    457     QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem,
    458                                                                   &styleOption, 0);
     462    QRect layoutRect = qStyle()->subElementRect(QStyle::SE_PushButtonLayoutItem,
     463                                                &styleOption, 0);
    459464    if (!layoutRect.isNull()) {
    460         QRect contentsRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonContents,
    461                                                                   &styleOption, 0);
     465        QRect contentsRect = qStyle()->subElementRect(QStyle::SE_PushButtonContents,
     466                                                      &styleOption, 0);
    462467        paddingLeft = contentsRect.left() - layoutRect.left();
    463468        paddingRight = layoutRect.right() - contentsRect.right();
     
    489494    ControlPart appearance = applyTheme(option, o);
    490495    if(appearance == PushButtonPart || appearance == ButtonPart) {
    491         option.rect = inflateButtonRect(option.rect);
     496        option.rect = inflateButtonRect(option.rect, qStyle());
    492497        p.drawControl(QStyle::CE_PushButton, option);
    493498    } else if(appearance == RadioPart) {
     
    520525
    521526    panel.rect = r;
    522     panel.lineWidth = m_frameLineWidth;
     527    panel.lineWidth = findFrameLineWidth(qStyle());
    523528    panel.state |= QStyle::State_Sunken;
    524529    panel.features = QStyleOptionFrameV2::None;
     
    572577
    573578    QStyleOptionComboBox opt;
    574     int w = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0);
     579    int w = qStyle()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0);
    575580    style->setPaddingRight(Length(padding + w, Fixed));
    576581
  • trunk/WebCore/platform/qt/RenderThemeQt.h

    r44758 r44759  
    4040{
    4141private:
    42     RenderThemeQt();
     42    RenderThemeQt(Page* page);
    4343    virtual ~RenderThemeQt();
    4444
     
    142142    void setPopupPadding(RenderStyle*) const;
    143143
     144    QStyle* qStyle() const;
     145    QStyle* fallbackStyle();
     146
     147    Page* m_page;
     148
    144149#ifdef Q_WS_MAC
    145150    int m_buttonFontPixelSize;
     
    148153
    149154    QStyle* m_fallbackStyle;
    150     QStyle* fallbackStyle();
    151 
    152     int m_frameLineWidth;
    153155};
    154156
Note: See TracChangeset for help on using the changeset viewer.