Changeset 52664 in webkit


Ignore:
Timestamp:
Dec 30, 2009 9:42:05 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-30 Carol Szabo <carol.szabo@nokia.com>

Reviewed by Laszlo Gombos.

[Qt] RenderThemeQt::applyTheme is a misnomer and is suboptimally coded.

https://bugs.webkit.org/show_bug.cgi?id=33035

This patch:

  • renames RenderThemeQt::applyTheme to initializeCommonQStyleOptions,
  • extracts the palette initialization code to a separate function in order to provide for readable pointer checking and moves this code up in the function to allow for future changes to the palette brushes needed for bug 30173,
  • optimizes some of the code in the function for readability, speed and size.
  • fixes some minor style issues

No new tests because code behavior is not changed.

  • platform/qt/RenderThemeQt.cpp: (WebCore::RenderThemeQt::paintButton): (WebCore::RenderThemeQt::paintTextField): (WebCore::RenderThemeQt::paintMenuList): (WebCore::RenderThemeQt::paintMenuListButton): (WebCore::initPaletteFromPageClientIfExists): (WebCore::RenderThemeQt::initializeCommonQStyleOptions):
  • platform/qt/RenderThemeQt.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r52663 r52664  
     12009-12-30  Carol Szabo  <carol.szabo@nokia.com>
     2
     3        Reviewed by Laszlo Gombos.
     4
     5         [Qt] RenderThemeQt::applyTheme is a misnomer and is suboptimally coded.
     6        https://bugs.webkit.org/show_bug.cgi?id=33035
     7
     8        This patch:
     9        - renames RenderThemeQt::applyTheme to initializeCommonQStyleOptions,
     10        - extracts the palette initialization code to a separate function in order to
     11        provide for readable pointer checking and moves this code up in the function to
     12        allow for future changes to the palette brushes needed for bug 30173,
     13        - optimizes some of the code in the function for readability, speed and size.
     14        - fixes some minor style issues
     15
     16        No new tests because code behavior is not changed.
     17
     18        * platform/qt/RenderThemeQt.cpp:
     19        (WebCore::RenderThemeQt::paintButton):
     20        (WebCore::RenderThemeQt::paintTextField):
     21        (WebCore::RenderThemeQt::paintMenuList):
     22        (WebCore::RenderThemeQt::paintMenuListButton):
     23        (WebCore::initPaletteFromPageClientIfExists):
     24        (WebCore::RenderThemeQt::initializeCommonQStyleOptions):
     25        * platform/qt/RenderThemeQt.h:
     26
    1272009-12-30  Laszlo Gombos  <laszlo.1.gombos@nokia.com>
    228
  • trunk/WebCore/platform/qt/RenderThemeQt.cpp

    r52518 r52664  
    4444#include "NotImplemented.h"
    4545#include "Page.h"
     46#include "QWebPageClient.h"
    4647#include "RenderBox.h"
    4748#include "RenderTheme.h"
    4849#include "UserAgentStyleSheets.h"
    49 #include "QWebPageClient.h"
    5050#include "qwebpage.h"
    5151
     
    478478    option.state |= QStyle::State_Small;
    479479
    480     ControlPart appearance = applyTheme(option, o);
     480    ControlPart appearance = initializeCommonQStyleOptions(option, o);
    481481    if (appearance == PushButtonPart || appearance == ButtonPart) {
    482482        option.rect = inflateButtonRect(option.rect, qStyle());
     
    514514
    515515    // Get the correct theme data for a text field
    516     ControlPart appearance = applyTheme(panel, o);
     516    ControlPart appearance = initializeCommonQStyleOptions(panel, o);
    517517    if (appearance != TextFieldPart
    518518        && appearance != SearchFieldPart
     
    576576    if (p.widget)
    577577        opt.initFrom(p.widget);
    578     applyTheme(opt, o);
     578    initializeCommonQStyleOptions(opt, o);
    579579
    580580    const QPoint topLeft = r.topLeft();
     
    616616    if (p.widget)
    617617        option.initFrom(p.widget);
    618     applyTheme(option, o);
     618    initializeCommonQStyleOptions(option, o);
    619619    option.rect = r;
    620620
     
    713713}
    714714
    715 ControlPart RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const
     715static inline void setPaletteFromPageClientIfExists(QPalette &palette, const RenderObject *o)
     716{
     717    // If the webview has a custom palette, use it
     718    Page* page = o->document()->page();
     719    if (!page)
     720        return;
     721    Chrome* chrome = page->chrome();
     722    if (!chrome)
     723        return;
     724    ChromeClient* chromeClient = chrome->client();
     725    if (!chromeClient)
     726        return;
     727    QWebPageClient* pageClient = chromeClient->platformPageClient();
     728    if (!pageClient)
     729        return;
     730    palette = pageClient->palette();
     731}
     732
     733ControlPart RenderThemeQt::initializeCommonQStyleOptions(QStyleOption& option, RenderObject* o) const
    716734{
    717735    // Default bits: no focus, no mouse over
     
    725743        option.state |= QStyle::State_ReadOnly;
    726744
    727     if (supportsFocus(o->style()->appearance()) && isFocused(o)) {
     745    option.direction = Qt::LeftToRight;
     746
     747    if (isHovered(o))
     748        option.state |= QStyle::State_MouseOver;
     749
     750    setPaletteFromPageClientIfExists(option.palette, o);
     751    RenderStyle* style = o->style();
     752    if (!style)
     753        return NoControlPart;
     754
     755    ControlPart result = style->appearance();
     756    if (supportsFocus(result) && isFocused(o)) {
    728757        option.state |= QStyle::State_HasFocus;
    729758        option.state |= QStyle::State_KeyboardFocusChange;
    730759    }
    731760
    732     if (isHovered(o))
    733         option.state |= QStyle::State_MouseOver;
    734 
    735     option.direction = Qt::LeftToRight;
    736     if (o->style() && o->style()->direction() == WebCore::RTL)
     761    if (style->direction() == WebCore::RTL)
    737762        option.direction = Qt::RightToLeft;
    738 
    739     ControlPart result = o->style()->appearance();
    740763
    741764    switch (result) {
     
    754777        break;
    755778    }
    756     }
    757 
    758     if (result == RadioPart || result == CheckboxPart)
     779    case RadioPart:
     780    case CheckboxPart:
    759781        option.state |= (isChecked(o) ? QStyle::State_On : QStyle::State_Off);
    760 
    761     // If the owner widget has a custom palette, use it
    762     Page* page = o->document()->page();
    763     if (page) {
    764         ChromeClient* client = page->chrome()->client();
    765         QWebPageClient* pageClient = client->platformPageClient();
    766         if (pageClient)
    767             option.palette = pageClient->palette();
    768782    }
    769783
  • trunk/WebCore/platform/qt/RenderThemeQt.h

    r46170 r52664  
    2020 *
    2121 */
    22 #ifndef RenderThemeQt_H
    23 #define RenderThemeQt_H
     22#ifndef RenderThemeQt_h
     23#define RenderThemeQt_h
    2424
    2525#include "RenderTheme.h"
     
    133133    bool supportsFocus(ControlPart) const;
    134134
    135     ControlPart applyTheme(QStyleOption&, RenderObject*) const;
     135    ControlPart initializeCommonQStyleOptions(QStyleOption&, RenderObject*) const;
    136136
    137137    void setButtonPadding(RenderStyle*) const;
     
    181181}
    182182
    183 #endif
     183#endif // RenderThemeQt_h
Note: See TracChangeset for help on using the changeset viewer.