Changeset 122647 in webkit


Ignore:
Timestamp:
Jul 13, 2012 5:15:43 PM (12 years ago)
Author:
pierre.rossi@gmail.com
Message:

[Qt] Improve the mobile theme slightly
https://bugs.webkit.org/show_bug.cgi?id=90806

Reviewed by Kenneth Rohde Christiansen.

Improve drawing of the mobile theme's controls' background.

Ensure the focus ring never appears with the mobile theme, since it
looks bad in combination with the highlights.

No new tests. The painting code from the mobile theme is still
not covered specifically (it will when we revive pixel tests).

  • platform/qt/RenderThemeQtMobile.cpp:

(WebCore):
(WebCore::addPointToOctants): Added. This is simply a helper to avoid

doing too much duplicate work in drawControlBackground.

(WebCore::drawControlBackground): Rely on the octant logic added above

and take the opportunity to increase the granularity.

(WebCore::borderPen):
(WebCore::StylePainterMobile::findLineEdit):
(WebCore::RenderThemeQtMobile::adjustTextFieldStyle):

  • platform/qt/RenderThemeQtMobile.h:

(RenderThemeQtMobile):
(WebCore::RenderThemeQtMobile::supportsFocusRing):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122642 r122647  
     12012-07-13  Pierre Rossi  <pierre.rossi@gmail.com>
     2
     3        [Qt] Improve the mobile theme slightly
     4        https://bugs.webkit.org/show_bug.cgi?id=90806
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Improve drawing of the mobile theme's controls' background.
     9
     10        Ensure the focus ring never appears with the mobile theme, since it
     11        looks bad in combination with the highlights.
     12
     13        No new tests. The painting code from the mobile theme is still
     14        not covered specifically (it will when we revive pixel tests).
     15
     16        * platform/qt/RenderThemeQtMobile.cpp:
     17        (WebCore):
     18        (WebCore::addPointToOctants): Added. This is simply a helper to avoid
     19            doing too much duplicate work in drawControlBackground.
     20        (WebCore::drawControlBackground): Rely on the octant logic added above
     21            and take the opportunity to increase the granularity.
     22        (WebCore::borderPen):
     23        (WebCore::StylePainterMobile::findLineEdit):
     24        (WebCore::RenderThemeQtMobile::adjustTextFieldStyle):
     25        * platform/qt/RenderThemeQtMobile.h:
     26        (RenderThemeQtMobile):
     27        (WebCore::RenderThemeQtMobile::supportsFocusRing):
     28
    1292012-07-13  Julien Chaffraix  <jchaffraix@webkit.org>
    230
  • trunk/Source/WebCore/platform/qt/RenderThemeQtMobile.cpp

    r119547 r122647  
    6767static const float buttonPaddingBottom = 3;
    6868static const float menuListPadding = 9;
    69 static const float textFieldPadding = 5;
     69static const float textFieldPadding = 10;
    7070static const float radiusFactor = 0.36;
    7171static const float progressBarChunkPercentage = 0.2;
     
    109109}
    110110
     111/*
     112 * The octants' indices are identified below, for each point (x,y)
     113 * in the first octant, we can populate the 7 others with the corresponding
     114 * point.
     115 *
     116 *                                       index |   xpos   |   ypos
     117 *                xd                    ---------------------------
     118 *      4      |<--->| 3                    0  |  xd + x  |    y
     119 *     __________________                   1  |  xd + y  |    x
     120 *    /                  \                  2  |  xd + y  |   -x
     121 * 5 |         .(c)       |  2              3  |  xd + x  |   -y
     122 * 6 |                    |  1              4  | -xd - x  |   -y
     123 *    \__________________/                  5  | -xd - y  |   -x
     124 *                                          6  | -xd - y  |    x
     125 *      7              0                    7  | -xd - x  |    y
     126 *
     127 **/
     128
     129static void addPointToOctants(QVector<QPainterPath>& octants, const QPointF& center, qreal x, qreal y , int xDelta = 0)
     130{
     131    ASSERT(octants.count() == 8);
     132
     133    for (short i = 0; i < 8; ++i) {
     134        QPainterPath& octant = octants[i];
     135        QPointF pos(center);
     136        // The Gray code corresponding to the octant's index helps doing the math in a more generic way.
     137        const short gray = (i >> 1) ^ i;
     138        const qreal xOffset = xDelta + ((gray & 1) ? y : x);
     139        pos.ry() += ((gray & 2)? -1 : 1) * ((gray & 1) ? x : y);
     140        pos.rx() += (i < 4) ? xOffset : -xOffset;
     141
     142        if (octant.elementCount())
     143            octant.lineTo(pos);
     144        else // The path is empty. Initialize the start point.
     145            octant.moveTo(pos);
     146    }
     147}
     148
    111149static void drawControlBackground(QPainter* painter, const QPen& pen, const QRect& rect, const QBrush& brush)
    112150{
     
    117155    painter->setBrush(brush);
    118156
    119     const int line = 1;
    120     const QRect paddedRect = rect.adjusted(line, line, -line, -line);
    121 
    122     const int n = 3;
     157    static const qreal line = 1.5;
     158    const QRectF paddedRect = rect.adjusted(line, line, -line, -line);
     159
     160    static const int n = 3;
    123161    const qreal invPow = 1 / double(n);
    124162    ASSERT(paddedRect.width() >= paddedRect.height());
    125163    const int radius = paddedRect.height() / 2;
    126164    const int xDelta = paddedRect.width() / 2 - radius;
    127     const QPoint center = paddedRect.topLeft() + QPoint(xDelta + radius, radius);
    128     qreal x, y;
    129     QPainterPath path;
    130     path.moveTo(-xDelta, -radius);
    131     for (y = -radius ; y <= radius; ++y) {
    132         x = -xDelta - radius * pow(1 - pow(qAbs(y) / radius , n), invPow);
    133         path.lineTo(x, y);
    134     }
    135     for (y = radius ; y >= -radius; --y) {
    136         x =  xDelta + radius * pow(1 - pow(qAbs(y) / radius , n), invPow);
    137         path.lineTo(x, y);
     165    const QPointF center = paddedRect.center();
     166    qreal x = 0;
     167    qreal y;
     168    QVector<QPainterPath> octants(8);
     169    // Stay within reasonable distance from edge values, which can cause artifacts at certain zoom levels.
     170    static const float epsilon = 0.02;
     171    for (y = radius - epsilon; y - epsilon > x; y -= 0.5) {
     172        x = radius * pow(1 - pow(qAbs(y) / radius , n), invPow);
     173        addPointToOctants(octants, center, x, y, xDelta);
     174    }
     175
     176    QPainterPath path = octants.first();
     177    for (int i = 1; i < 8; ++i) {
     178        // Due to the orientation of the arcs, we need to reverse the paths with odd indices.
     179        QPainterPath subPath = (i % 2) ?  octants.at(i).toReversed() : octants.at(i);
     180        path.connectPath(subPath);
    138181    }
    139182    path.closeSubpath();
    140     path.translate(center);
    141183
    142184    painter->drawPath(path);
     
    153195static inline QPen borderPen(QPainter* painter = 0)
    154196{
    155     return QPen(darkColor, 0.4 * painterScale(painter), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
     197    return QPen(darkColor, qMin(1.0, 0.4 * painterScale(painter)));
    156198}
    157199
     
    384426    if (!findCachedControl(id, &result)) {
    385427        const int focusFrame = painterScale(painter);
    386         result = QPixmap(size + QSize(2 * focusFrame, 2 * focusFrame));
     428        result = QPixmap(size);
    387429        result.fill(Qt::transparent);
    388430        const QRect rect = result.rect().adjusted(focusFrame, focusFrame, -focusFrame, -focusFrame);
     
    391433
    392434        if (focused) {
    393             QPen focusPen(highlightColor, focusFrame, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
     435            QPen focusPen(highlightColor, 1.2 * painterScale(painter), Qt::SolidLine);
    394436            drawControlBackground(&cachePainter, focusPen, rect, Qt::NoBrush);
    395437        }
     
    698740    style->setBackgroundColor(Color::transparent);
    699741    style->resetBorder();
     742    style->setBorderTopWidth(frameWidth);
     743    style->setBorderRightWidth(frameWidth);
     744    style->setBorderBottomWidth(frameWidth);
     745    style->setBorderLeftWidth(frameWidth);
    700746    style->resetPadding();
    701747    computeSizeBasedOnStyle(style);
  • trunk/Source/WebCore/platform/qt/RenderThemeQtMobile.h

    r119547 r122647  
    5454    virtual bool delegatesMenuListRendering() const { return true; }
    5555
    56     // drawFocusRing() will return early if the color is invalid.
    57     virtual Color platformFocusRingColor() const { return Color(); }
     56    // We don't want the focus ring to be drawn by the graphics context so we
     57    // always claim to support it in the theme.
     58    // FIXME: This could be a usability problem in the case of contenteditable divs.
     59    virtual bool supportsFocusRing(const RenderStyle*) const { return true; }
    5860
    5961protected:
Note: See TracChangeset for help on using the changeset viewer.