Changeset 102768 in webkit
- Timestamp:
- Dec 14, 2011 5:20:50 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r102767 r102768 1 2011-12-14 Pierre Rossi <pierre.rossi@gmail.com> 2 3 [Qt] Mobile theme could use a little refresh 4 https://bugs.webkit.org/show_bug.cgi?id=74293 5 6 The look and feel of the "mobile theme" we're 7 using in QtWebKit dates back to the maemo 5 days. 8 This is an attempt at making it look less out of 9 place, and also support progress and range. 10 11 Reviewed by Kenneth Rohde Christiansen. 12 13 No new tests, this is still not the default theme 14 for tests. 15 16 * DerivedSources.pri: 17 * css/mobileThemeQt.css: Added. 18 (input[type="submit"], select): 19 (input[type="submit"]:disabled, input[type="submit"]:disabled:active, select:disabled, input[type="text"]:disabled): 20 (input[type="submit"]:active): 21 * platform/qt/RenderThemeQt.cpp: 22 (WebCore::RenderThemeQt::extraDefaultStyleSheet): 23 (WebCore::StylePainter::StylePainter): 24 (WebCore::StylePainter::init): 25 (WebCore::StylePainter::~StylePainter): 26 * platform/qt/RenderThemeQt.h: 27 * platform/qt/RenderThemeQtMobile.cpp: 28 (WebCore::drawRectangularControlBackground): 29 (WebCore::shrinkRectToSquare): 30 (WebCore::StylePainterMobile::StylePainterMobile): 31 (WebCore::StylePainterMobile::~StylePainterMobile): 32 (WebCore::StylePainterMobile::drawCheckableBackground): 33 (WebCore::StylePainterMobile::sizeForPainterScale): 34 (WebCore::StylePainterMobile::drawChecker): 35 (WebCore::StylePainterMobile::findCheckBox): 36 (WebCore::StylePainterMobile::drawRadio): 37 (WebCore::StylePainterMobile::findRadio): 38 (WebCore::StylePainterMobile::drawMultipleComboButton): 39 (WebCore::StylePainterMobile::drawSimpleComboButton): 40 (WebCore::StylePainterMobile::getButtonImageSize): 41 (WebCore::StylePainterMobile::findComboButton): 42 (WebCore::StylePainterMobile::drawLineEdit): 43 (WebCore::StylePainterMobile::drawCheckBox): 44 (WebCore::StylePainterMobile::drawRadioButton): 45 (WebCore::StylePainterMobile::drawPushButton): 46 (WebCore::StylePainterMobile::drawComboBox): 47 (WebCore::StylePainterMobile::drawProgress): 48 (WebCore::StylePainterMobile::drawSliderThumb): 49 (WebCore::RenderThemeQtMobile::paintButton): 50 (WebCore::RenderThemeQtMobile::paintTextField): 51 (WebCore::RenderThemeQtMobile::setPopupPadding): 52 (WebCore::RenderThemeQtMobile::paintMenuList): 53 (WebCore::RenderThemeQtMobile::paintMenuListButton): 54 (WebCore::RenderThemeQtMobile::animationDurationForProgressBar): 55 (WebCore::RenderThemeQtMobile::paintProgressBar): 56 (WebCore::RenderThemeQtMobile::paintSliderTrack): 57 (WebCore::RenderThemeQtMobile::paintSliderThumb): 58 (WebCore::RenderThemeQtMobile::adjustSliderThumbSize): 59 * platform/qt/RenderThemeQtMobile.h: 60 1 61 2011-12-14 Rakesh KN <rakesh.kn@motorola.com> 2 62 -
trunk/Source/WebCore/DerivedSources.pri
r102430 r102768 87 87 $$PWD/css/mediaControlsQt.css \ 88 88 $$PWD/css/mediaControlsQtFullscreen.css \ 89 $$PWD/css/themeQtNoListboxes.css 89 $$PWD/css/themeQtNoListboxes.css \ 90 $$PWD/css/mobileThemeQt.css 90 91 91 92 IDL_BINDINGS += \ -
trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp
r102679 r102768 58 58 #include "TimeRanges.h" 59 59 #include "UserAgentStyleSheets.h" 60 #include <wtf/text/StringBuilder.h> 60 61 61 62 #include <QGuiApplication> … … 114 115 String RenderThemeQt::extraDefaultStyleSheet() 115 116 { 116 String result = RenderTheme::extraDefaultStyleSheet(); 117 if (useMobileTheme()) 118 result += String(themeQtNoListboxesUserAgentStyleSheet, sizeof(themeQtNoListboxesUserAgentStyleSheet)); 119 return result; 117 StringBuilder result; 118 result.append(RenderTheme::extraDefaultStyleSheet()); 119 if (useMobileTheme()) { 120 result.append(String(themeQtNoListboxesUserAgentStyleSheet, sizeof(themeQtNoListboxesUserAgentStyleSheet))); 121 result.append(String(mobileThemeQtUserAgentStyleSheet, sizeof(mobileThemeQtUserAgentStyleSheet))); 122 } 123 return result.toString(); 120 124 } 121 125 … … 868 872 { 869 873 Q_UNUSED(theme); 870 init(paintInfo.context ? paintInfo.context : 0); 874 ASSERT(paintInfo.context); 875 init(paintInfo.context); 871 876 } 872 877 … … 883 888 // the styles often assume being called with a pristine painter where no brush is set, 884 889 // so reset it manually 885 oldBrush = painter->brush();890 m_previousBrush = painter->brush(); 886 891 painter->setBrush(Qt::NoBrush); 887 892 888 893 // painting the widget with anti-aliasing will make it blurry 889 894 // disable it here and restore it later 890 oldAntialiasing = painter->testRenderHint(QPainter::Antialiasing);895 m_previousAntialiasing = painter->testRenderHint(QPainter::Antialiasing); 891 896 painter->setRenderHint(QPainter::Antialiasing, false); 892 897 } … … 896 901 { 897 902 if (painter) { 898 painter->setBrush( oldBrush);899 painter->setRenderHints(QPainter::Antialiasing, oldAntialiasing);903 painter->setBrush(m_previousBrush); 904 painter->setRenderHints(QPainter::Antialiasing, m_previousAntialiasing); 900 905 } 901 906 } -
trunk/Source/WebCore/platform/qt/RenderThemeQt.h
r100123 r102768 186 186 187 187 private: 188 QBrush oldBrush;189 bool oldAntialiasing;188 QBrush m_previousBrush; 189 bool m_previousAntialiasing; 190 190 191 191 }; -
trunk/Source/WebCore/platform/qt/RenderThemeQtMobile.cpp
r100270 r102768 56 56 using namespace HTMLNames; 57 57 58 // Constants extracted from QCommonStyle and QWindowsStyle59 static const int arrowBoxWidth = 16;58 // Constants used by the mobile theme 59 static const int arrowBoxWidth = 26; 60 60 static const int frameWidth = 2; 61 static const int checkBoxWidth = 13;62 static const int radioWidth = 12;61 static const int checkBoxWidth = 21; 62 static const int radioWidth = 21; 63 63 static const int buttonIconSize = 16; 64 static const int sliderWidth = 11; 65 static const int sliderHeight = 0; 66 67 // Other constants used by the mobile theme 68 static float buttonPaddingLeft = 18; 69 static float buttonPaddingRight = 18; 70 static float buttonPaddingTop = 2; 71 static float buttonPaddingBottom = 3; 72 static float menuListPadding = 9; 73 static float textFieldPadding = 5; 74 64 static const int sliderSize = 18; 65 66 static const float buttonPaddingLeft = 18; 67 static const float buttonPaddingRight = 18; 68 static const float buttonPaddingTop = 2; 69 static const float buttonPaddingBottom = 3; 70 static const float menuListPadding = 9; 71 static const float textFieldPadding = 5; 72 static const float radiusFactor = 0.36; 73 #if ENABLE(PROGRESS_TAG) 74 static const float progressBarChunkPercentage = 0.2; 75 static const int progressAnimationGranularity = 2; 76 #endif 77 static const float sliderGrooveBorderRatio = 0.2; 78 static const QColor darkColor(40, 40, 40); 79 static const QColor highlightColor(16, 128, 221); 80 static const QColor buttonGradientBottom(245, 245, 245); 81 static const QColor shadowColor(80, 80, 80, 160); 82 static const QPen borderPen(darkColor, 0.3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 75 83 76 84 static inline void drawRectangularControlBackground(QPainter* painter, const QPen& pen, const QRect& rect, const QBrush& brush) … … 82 90 painter->setBrush(brush); 83 91 84 int line = 1;85 painter->drawRoundedRect(rect.adjusted(line, line, -line, -line),86 /* xRadius */ 5.0, /* yRadious */ 5.0);92 const int line = 1; 93 const double radius = radiusFactor * rect.height(); 94 painter->drawRoundedRect(rect.adjusted(line, line, -line, -line), radius, radius); 87 95 painter->setPen(oldPen); 88 96 painter->setBrush(oldBrush); 89 97 } 90 98 99 static inline QRect shrinkRectToSquare(const QRect& rect) 100 { 101 const int side = qMin(rect.height(), rect.width()); 102 return QRect(rect.topLeft(), QSize(side, side)); 103 } 104 91 105 QSharedPointer<StylePainter> RenderThemeQtMobile::getStylePainter(const PaintInfo& pi) 92 106 { … … 97 111 : StylePainter(theme, paintInfo) 98 112 { 99 } 100 101 void StylePainterMobile::drawChecker(QPainter* painter, int size, QColor color) const 102 { 103 int border = qMin(qMax(1, int(0.2 * size)), 6); 104 int checkerSize = qMax(size - 2 * border, 3); 105 int width = checkerSize / 3; 106 int middle = qMax(3 * checkerSize / 7, 3); 107 int x = ((size - checkerSize) >> 1); 108 int y = ((size - checkerSize) >> 1) + (checkerSize - width - middle); 109 QVector<QLineF> lines(checkerSize + 1); 110 painter->setPen(color); 111 for (int i = 0; i < middle; ++i) { 112 lines[i] = QLineF(x, y, x, y + width); 113 ++x; 114 ++y; 115 } 116 for (int i = middle; i <= checkerSize; ++i) { 117 lines[i] = QLineF(x, y, x, y + width); 118 ++x; 119 --y; 120 } 121 painter->drawLines(lines.constData(), lines.size()); 122 } 123 124 QPixmap StylePainterMobile::findChecker(const QRect& rect, bool disabled) const 125 { 126 int size = qMin(rect.width(), rect.height()); 113 m_previousSmoothPixmapTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform); 114 if (!m_previousSmoothPixmapTransform) 115 painter->setRenderHint(QPainter::SmoothPixmapTransform); 116 } 117 118 StylePainterMobile::~StylePainterMobile() 119 { 120 painter->setRenderHints(QPainter::SmoothPixmapTransform, m_previousSmoothPixmapTransform); 121 } 122 123 void StylePainterMobile::drawCheckableBackground(QPainter* painter, const QRect& rect, bool checked, bool enabled) const 124 { 125 QBrush brush; 126 if (checked && enabled) { 127 QLinearGradient gradient; 128 gradient.setStart(rect.bottomLeft()); 129 gradient.setFinalStop(rect.topLeft()); 130 gradient.setColorAt(0.0, highlightColor); 131 gradient.setColorAt(1.0, highlightColor.lighter()); 132 brush = gradient; 133 } else 134 brush = Qt::lightGray; 135 drawRectangularControlBackground(painter, borderPen, rect, brush); 136 } 137 138 QSize StylePainterMobile::sizeForPainterScale(const QRect& rect) const 139 { 140 const QRect mappedRect = painter->transform().mapRect(rect); 141 return mappedRect.size(); 142 } 143 144 void StylePainterMobile::drawChecker(QPainter* painter, const QRect& rect, const QColor& color) const 145 { 146 painter->setRenderHint(QPainter::Antialiasing, true); 147 QPen pen(Qt::darkGray); 148 pen.setCosmetic(true); 149 painter->setPen(pen); 150 painter->scale(rect.width(), rect.height()); 151 QPainterPath path; 152 path.moveTo(0.18, 0.47); 153 path.lineTo(0.25, 0.4); 154 path.lineTo(0.4, 0.55); 155 path.quadTo(0.64, 0.29, 0.78, 0.2); 156 path.lineTo(0.8, 0.25); 157 path.quadTo(0.53, 0.55, 0.45, 0.75); 158 path.closeSubpath(); 159 painter->setBrush(color); 160 painter->drawPath(path); 161 } 162 163 QPixmap StylePainterMobile::findCheckBox(const QSize& size, bool checked, bool enabled) const 164 { 165 ASSERT(size.width() == size.height()); 127 166 QPixmap result; 128 static const QString prefix = QLatin1String("$qt-maemo5-mobile-theme-checker-"); 129 QString key = prefix + QString::number(size) + QLatin1String("-") + (disabled ? QLatin1String("disabled") : QLatin1String("enabled")); 130 if (!QPixmapCache::find(key, result)) { 131 result = QPixmap(size, size); 132 result.fill(Qt::transparent); 133 QPainter painter(&result); 134 drawChecker(&painter, size, disabled ? Qt::lightGray : Qt::darkGray); 135 QPixmapCache::insert(key, result); 136 } 137 return result; 138 } 139 140 void StylePainterMobile::drawRadio(QPainter* painter, const QSize& size, bool checked, QColor color) const 141 { 142 painter->setRenderHint(QPainter::Antialiasing, true); 143 144 // get minor size to do not paint a wide elipse 145 qreal squareSize = qMin(size.width(), size.height()); 146 // deflate one pixel 147 QRect rect = QRect(QPoint(1, 1), QSize(squareSize - 2, squareSize - 2)); 148 const QPoint centerGradient(rect.bottomRight() * 0.7); 149 150 QRadialGradient radialGradient(centerGradient, centerGradient.x() - 1); 151 radialGradient.setColorAt(0.0, Qt::white); 152 radialGradient.setColorAt(0.6, Qt::white); 153 radialGradient.setColorAt(1.0, color); 154 155 painter->setPen(color); 156 painter->setBrush(color); 157 painter->drawEllipse(rect); 158 painter->setBrush(radialGradient); 159 painter->drawEllipse(rect); 160 161 int border = 0.1 * (rect.width() + rect.height()); 162 border = qMin(qMax(2, border), 10); 163 rect.adjust(border, border, -border, -border); 164 if (checked) { 165 painter->setPen(Qt::NoPen); 166 painter->setBrush(color); 167 painter->drawEllipse(rect); 168 } 169 } 170 171 QPixmap StylePainterMobile::findRadio(const QSize& size, bool checked, bool disabled) const 172 { 173 QPixmap result; 174 static const QString prefix = QLatin1String("$qt-maemo5-mobile-theme-radio-"); 175 QString key = prefix + QString::number(size.width()) + QLatin1String("-") + QString::number(size.height()) + QLatin1String("-") 176 + (disabled ? QLatin1String("disabled") : QLatin1String("enabled")) + (checked ? QLatin1String("-checked") : QLatin1String("")); 167 static const QString prefix = QLatin1String("$qt-webkit-mobile-theme-checkbox-"); 168 QString key = prefix + QString::number(size.width()) + QLatin1String("-") + (enabled ? QLatin1String("on") : QLatin1String("off")) 169 + (checked ? QLatin1String("-checked") : QString()); 177 170 if (!QPixmapCache::find(key, result)) { 178 171 result = QPixmap(size); 179 172 result.fill(Qt::transparent); 180 173 QPainter painter(&result); 181 drawRadio(&painter, size, checked, disabled ? Qt::lightGray : Qt::darkGray); 174 QRect rect(QPoint(0, 0), size); 175 drawCheckableBackground(&painter, rect, checked, enabled); 176 if (checked || !enabled) 177 drawChecker(&painter, rect, enabled ? Qt::white : Qt::gray); 182 178 QPixmapCache::insert(key, result); 183 179 } … … 185 181 } 186 182 187 void StylePainterMobile::drawMultipleComboButton(QPainter* painter, const QSize& size, QColor color) const 188 { 189 int rectWidth = size.width() - 1; 190 int width = qMax(2, rectWidth >> 3); 191 int distance = (rectWidth - 3 * width) >> 1; 192 int top = (size.height() - width) >> 1; 183 void StylePainterMobile::drawRadio(QPainter* painter, const QSize& size, bool checked, bool enabled) const 184 { 185 ASSERT(size.width() == size.height()); 186 QRect rect(QPoint(0, 0), size); 187 188 drawCheckableBackground(painter, rect, checked, enabled); 189 const int border = size.width() / 4; 190 rect.adjust(border, border, -border, -border); 191 drawRectangularControlBackground(painter, borderPen, rect, enabled ? Qt::white : Qt::gray); 192 } 193 194 QPixmap StylePainterMobile::findRadio(const QSize& size, bool checked, bool enabled) const 195 { 196 QPixmap result; 197 static const QString prefix = QLatin1String("$qt-webkit-mobile-theme-radio-"); 198 QString key = prefix + QString::number(size.width()) + QLatin1String("-") + (enabled ? QLatin1String("on") : QLatin1String("off")) 199 + (checked ? QLatin1String("-checked") : QString()); 200 if (!QPixmapCache::find(key, result)) { 201 result = QPixmap(size); 202 result.fill(Qt::transparent); 203 QPainter painter(&result); 204 drawRadio(&painter, size, checked, enabled); 205 QPixmapCache::insert(key, result); 206 } 207 return result; 208 } 209 210 void StylePainterMobile::drawMultipleComboButton(QPainter* painter, const QSize& size, const QColor& color) const 211 { 212 const int dotSize = size.height() - 1; 193 213 194 214 painter->setPen(color); 195 215 painter->setBrush(color); 196 216 197 painter->drawRect(0, top, width, width); 198 painter->drawRect(width + distance, top, width, width); 199 painter->drawRect(2 * (width + distance), top, width, width); 200 } 201 202 void StylePainterMobile::drawSimpleComboButton(QPainter* painter, const QSize& size, QColor color) const 203 { 204 int width = size.width(); 205 int midle = width >> 1; 206 QVector<QLine> lines(width + 1); 207 208 for (int x = 0, y = 0; x < midle; x++, y++) { 209 lines[x] = QLine(x, y, x, y + 2); 210 lines[x + midle] = QLine(width - x - 1, y, width - x - 1, y + 2); 211 } 212 // Just to ensure the lines' intersection. 213 lines[width] = QLine(midle, midle, midle, midle + 2); 217 painter->drawEllipse(0, 0, dotSize, dotSize); 218 painter->drawEllipse(dotSize * 2, 0, dotSize, dotSize); 219 painter->drawEllipse(4 * dotSize, 0, dotSize, dotSize); 220 } 221 222 void StylePainterMobile::drawSimpleComboButton(QPainter* painter, const QSize& size, const QColor& color) const 223 { 224 const int width = size.width(); 225 const int height = size.height(); 226 const int horizontalCenter = width / 2; 227 const int verticalCenter = height / 2; 228 const int spacing = 1 + height / 15; 229 230 QVector<QLine> lines(2 * width); 231 int length = 0; 232 for (int x = 0; x < horizontalCenter ; x++) { 233 length++; 234 lines[x] = QLine(x, verticalCenter + spacing, x, verticalCenter + spacing + length); 235 lines[2 * width - x - 1] = QLine(x, verticalCenter - spacing, x, verticalCenter - spacing - length); 236 } 237 for (int x = horizontalCenter; x < width; x++) { 238 lines[x] = QLine(x, verticalCenter + spacing, x, verticalCenter + spacing + length); 239 lines[2 * width - x - 1] = QLine(x, verticalCenter - spacing, x, verticalCenter - spacing - length); 240 length--; 241 } 214 242 215 243 painter->setPen(color); … … 218 246 } 219 247 220 QSize StylePainterMobile::getButtonImageSize(const QSize& buttonSize) const 221 { 222 const int border = qMax(3, buttonSize.width() >> 3) << 1; 223 224 int width = buttonSize.width() - border; 225 int height = buttonSize.height() - border; 226 227 if (width < 0 || height < 0) 228 return QSize(); 229 230 if (height >= (width >> 1)) 231 width = width >> 1 << 1; 232 else 233 width = height << 1; 234 235 return QSize(width + 1, width); 236 } 237 238 QPixmap StylePainterMobile::findComboButton(const QSize& size, bool multiple, bool disabled) const 239 { 248 QSize StylePainterMobile::getButtonImageSize(const QSize& buttonSize, bool multiple) const 249 { 250 if (multiple) 251 return QSize(buttonSize.width(), buttonSize.width() / 5); 252 253 const int height = buttonSize.height() / 2 + frameWidth; 254 const int width = height - (2 * (1 + height / 15)) - 1; 255 return QSize(width , height); 256 } 257 258 QPixmap StylePainterMobile::findComboButton(const QSize& size, bool multiple, bool enabled) const 259 { 260 if (size.isNull()) 261 return QPixmap(); 262 static const QString prefix = QLatin1String("$qt-webkit-mobile-theme-combo-"); 240 263 QPixmap result; 241 QSize imageSize = getButtonImageSize(size);242 243 if (imageSize.isNull())244 return QPixmap();245 static const QString prefix = QLatin1String("$qt-maemo5-mobile-theme-combo-");246 264 QString key = prefix + (multiple ? QLatin1String("multiple-") : QLatin1String("simple-")) 247 + QString::number(imageSize.width()) + QLatin1String("-") + QString::number(imageSize.height()) 248 + QLatin1String("-") + (disabled ? QLatin1String("disabled") : QLatin1String("enabled")); 265 + QString::number(size.width()) + QLatin1String("-") + QString::number(size.height()) 266 + QLatin1String("-") + (enabled ? QLatin1String("on") : QLatin1String("off")); 267 249 268 if (!QPixmapCache::find(key, result)) { 269 result = QPixmap(size); 270 result.fill(Qt::transparent); 271 QPainter painter(&result); 272 if (multiple) 273 drawMultipleComboButton(&painter, size, enabled ? darkColor : Qt::lightGray); 274 else 275 drawSimpleComboButton(&painter, size, enabled ? darkColor : Qt::lightGray); 276 QPixmapCache::insert(key, result); 277 } 278 return result; 279 } 280 281 void StylePainterMobile::drawLineEdit(const QRect& rect, bool focused, bool enabled) 282 { 283 drawRectangularControlBackground(painter, borderPen, rect, Qt::white); 284 285 if (focused) { 286 QPen focusPen(highlightColor, float(rect.height() / 26.0), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 287 drawRectangularControlBackground(painter, focusPen, rect, Qt::NoBrush); 288 } 289 } 290 291 void StylePainterMobile::drawCheckBox(const QRect& rect, bool checked, bool enabled) 292 { 293 const QRect square = shrinkRectToSquare(rect); 294 QPixmap checkBox = findCheckBox(sizeForPainterScale(square), checked, enabled); 295 if (checkBox.isNull()) 296 return; 297 painter->drawPixmap(square, checkBox); 298 } 299 300 void StylePainterMobile::drawRadioButton(const QRect& rect, bool checked, bool enabled) 301 { 302 const QRect square = shrinkRectToSquare(rect); 303 QPixmap radio = findRadio(sizeForPainterScale(square), checked, enabled); 304 if (radio.isNull()) 305 return; 306 painter->drawPixmap(square, radio); 307 } 308 309 void StylePainterMobile::drawPushButton(const QRect& rect, bool sunken, bool enabled) 310 { 311 drawRectangularControlBackground(painter, Qt::NoPen, rect.adjusted(0, 1, 0, 1), shadowColor); 312 313 QBrush brush; 314 if (enabled && !sunken) { 315 QLinearGradient linearGradient; 316 linearGradient.setStart(rect.bottomLeft()); 317 linearGradient.setFinalStop(rect.topLeft()); 318 linearGradient.setColorAt(0.0, buttonGradientBottom); 319 linearGradient.setColorAt(1.0, Qt::white); 320 brush = linearGradient; 321 } else if (!enabled) 322 brush = QColor(241, 242, 243); 323 else { // sunken 324 QLinearGradient linearGradient; 325 linearGradient.setStart(rect.bottomLeft()); 326 linearGradient.setFinalStop(rect.topLeft()); 327 linearGradient.setColorAt(0.0, highlightColor); 328 linearGradient.setColorAt(1.0, highlightColor.lighter()); 329 brush = linearGradient; 330 } 331 332 drawRectangularControlBackground(painter, borderPen, rect, brush); 333 } 334 335 void StylePainterMobile::drawComboBox(const QRect& rect, bool multiple, bool enabled) 336 { 337 drawRectangularControlBackground(painter, Qt::NoPen, rect.adjusted(0, 1, 0, 2), shadowColor); 338 339 QLinearGradient linearGradient; 340 linearGradient.setStart(rect.bottomLeft()); 341 linearGradient.setFinalStop(rect.topLeft()); 342 linearGradient.setColorAt(0.0, buttonGradientBottom); 343 linearGradient.setColorAt(1.0, Qt::white); 344 345 346 drawRectangularControlBackground(painter, borderPen, rect, linearGradient); 347 348 const QRect buttonRect(rect.x() + rect.width() - frameWidth - arrowBoxWidth, rect.y() + frameWidth 349 , rect.height(), rect.height() - 2 * frameWidth); 350 QRect targetRect(QPoint(0, 0), getButtonImageSize(buttonRect.size(), multiple)); 351 targetRect.moveCenter(buttonRect.center()); 352 QPixmap pic = findComboButton(sizeForPainterScale(targetRect), multiple, enabled); 353 if (pic.isNull()) 354 return; 355 356 painter->drawPixmap(targetRect, pic); 357 } 358 359 void StylePainterMobile::drawProgress(const QRect& rect, double progress, bool leftToRight, bool animated) const 360 { 361 static const QString prefix = QLatin1String("$qt-webkit-mobile-theme-progress-"); 362 const int border = rect.height() / 4; 363 const QRect targetRect = rect.adjusted(0, border, 0, -border); 364 365 QPixmap result; 366 const QSize imageSize = sizeForPainterScale(targetRect); 367 QString key = prefix + QString::number(imageSize.width()) + QLatin1String("-") + QString::number(imageSize.height()) 368 + QLatin1String("-") + QString::number(progress, 'f', 3) + (animated? QLatin1String("-anim") : QString()) 369 + ((!animated && !leftToRight) ? QLatin1String("-rtl") : QString()); 370 if (!QPixmapCache::find(key, result)) { 371 if (imageSize.isNull()) 372 return; 250 373 result = QPixmap(imageSize); 251 374 result.fill(Qt::transparent); 252 375 QPainter painter(&result); 253 if (multiple) 254 drawMultipleComboButton(&painter, imageSize, disabled ? Qt::lightGray : Qt::darkGray); 255 else 256 drawSimpleComboButton(&painter, imageSize, disabled ? Qt::lightGray : Qt::darkGray); 376 QRect progressRect(QPoint(0, 0), imageSize); 377 drawRectangularControlBackground(&painter, borderPen, progressRect, Qt::white); 378 progressRect.adjust(1, 1, -1, -1); 379 if (animated) { 380 const int right = progressRect.right(); 381 const int startPos = right * (1 - progressBarChunkPercentage) * 2 * fabs(progress - 0.5); 382 progressRect.setWidth(progressBarChunkPercentage * right); 383 progressRect.moveLeft(startPos); 384 } else { 385 progressRect.setWidth(progress * progressRect.width()); 386 if (!leftToRight) 387 progressRect.moveRight(imageSize.width() - 2); 388 } 389 if (progressRect.width() > 0) { 390 QLinearGradient gradient; 391 gradient.setStart(progressRect.bottomLeft()); 392 gradient.setFinalStop(progressRect.topLeft()); 393 gradient.setColorAt(0.0, highlightColor); 394 gradient.setColorAt(1.0, highlightColor.lighter()); 395 drawRectangularControlBackground(&painter, Qt::NoPen, progressRect, gradient); 396 } 257 397 QPixmapCache::insert(key, result); 258 398 } 259 return result; 260 } 261 262 void StylePainterMobile::drawLineEdit(const QRect& rect, bool sunken, bool enabled) 263 { 264 QPen pen(Qt::darkGray, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 265 painter->setPen(pen); 266 267 if (sunken) { 268 drawRectangularControlBackground(painter, pen, rect, QBrush(Qt::darkGray)); 269 return; 270 } 271 272 QLinearGradient linearGradient; 273 if (!enabled) { 274 linearGradient.setStart(rect.topLeft()); 275 linearGradient.setFinalStop(rect.bottomLeft()); 276 linearGradient.setColorAt(0.0, Qt::lightGray); 277 linearGradient.setColorAt(1.0, Qt::white); 278 } else { 279 linearGradient.setStart(rect.topLeft()); 280 linearGradient.setFinalStop(QPoint(rect.topLeft().x(), 281 rect.topLeft().y() + /* offset limit for gradient */ 20)); 282 linearGradient.setColorAt(0.0, Qt::darkGray); 283 linearGradient.setColorAt(0.35, Qt::white); 284 } 285 286 drawRectangularControlBackground(painter, pen, rect, linearGradient); 287 } 288 289 void StylePainterMobile::drawCheckBox(const QRect& rect, bool checked, bool enabled) 290 { 291 QLinearGradient linearGradient(rect.topLeft(), rect.bottomLeft()); 292 if (!enabled) { 293 linearGradient.setColorAt(0.0, Qt::lightGray); 294 linearGradient.setColorAt(0.5, Qt::white); 295 } else { 296 linearGradient.setColorAt(0.0, Qt::darkGray); 297 linearGradient.setColorAt(0.5, Qt::white); 298 } 299 300 painter->setPen(QPen(enabled ? Qt::darkGray : Qt::lightGray)); 301 painter->setBrush(linearGradient); 302 painter->drawRect(rect); 303 const QRect r = rect.adjusted(1, 1, -1, -1); 304 305 if (!checked) 306 return; 307 308 QPixmap checker = findChecker(r, !enabled); 309 if (checker.isNull()) 310 return; 311 312 int x = (r.width() - checker.width()) >> 1; 313 int y = (r.height() - checker.height()) >> 1; 314 painter->drawPixmap(r.x() + x, r.y() + y, checker); 315 } 316 317 void StylePainterMobile::drawRadioButton(const QRect& rect, bool checked, bool enabled) 318 { 319 QPixmap radio = findRadio(rect.size(), checked, !enabled); 320 if (radio.isNull()) 321 return; 322 painter->drawPixmap(rect.x(), rect.y(), radio); 323 } 324 325 void StylePainterMobile::drawPushButton(const QRect& rect, bool sunken, bool enabled) 326 { 327 QPen pen(Qt::darkGray, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 328 painter->setPen(pen); 329 330 if (sunken) { 331 drawRectangularControlBackground(painter, pen, rect, QBrush(Qt::darkGray)); 332 return; 333 } 334 335 QLinearGradient linearGradient; 336 if (!enabled) { 337 linearGradient.setStart(rect.bottomLeft()); 338 linearGradient.setFinalStop(rect.topLeft()); 339 linearGradient.setColorAt(0.0, Qt::gray); 340 linearGradient.setColorAt(1.0, Qt::white); 341 } else { 342 linearGradient.setStart(rect.bottomLeft()); 343 linearGradient.setFinalStop(QPoint(rect.bottomLeft().x(), 344 rect.bottomLeft().y() - /* offset limit for gradient */ 20)); 345 linearGradient.setColorAt(0.0, Qt::gray); 346 linearGradient.setColorAt(0.4, Qt::white); 347 } 348 349 drawRectangularControlBackground(painter, pen, rect, linearGradient); 350 } 351 352 void StylePainterMobile::drawComboBox(const QRect& rect, bool multiple, bool enabled) 353 { 354 QPen pen(Qt::darkGray, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); 355 QLinearGradient linearGradient; 356 if (!enabled) { 357 linearGradient.setStart(rect.bottomLeft()); 358 linearGradient.setFinalStop(rect.topLeft()); 359 linearGradient.setColorAt(0.0, Qt::gray); 360 linearGradient.setColorAt(1.0, Qt::white); 361 } else { 362 linearGradient.setStart(rect.bottomLeft()); 363 linearGradient.setFinalStop(QPoint(rect.bottomLeft().x(), 364 rect.bottomLeft().y() - /* offset limit for gradient */ 20)); 365 linearGradient.setColorAt(0.0, Qt::gray); 366 linearGradient.setColorAt(0.4, Qt::white); 367 } 368 369 drawRectangularControlBackground(painter, pen, rect, linearGradient); 370 371 const QRect r(rect.x() + rect.width() - frameWidth - arrowBoxWidth, rect.y() + frameWidth 372 , arrowBoxWidth, rect.height() - 2 * frameWidth); 373 QPixmap pic = findComboButton(r.size(), multiple, !enabled); 374 375 if (pic.isNull()) 376 return; 377 378 int x = (r.width() - pic.width()) >> 1; 379 int y = (r.height() - pic.height()) >> 1; 380 painter->drawPixmap(r.x() + x, r.y() + y, pic); 381 382 painter->setPen(enabled ? Qt::darkGray : Qt::gray); 383 painter->drawLine(r.left() - 2, r.top() + 2, r.left() - 2, r.bottom() - 2); 399 painter->drawPixmap(targetRect, result); 400 } 401 402 void StylePainterMobile::drawSliderThumb(const QRect & rect, bool pressed) const 403 { 404 drawRectangularControlBackground(painter, borderPen, rect, pressed? Qt::lightGray : buttonGradientBottom); 384 405 } 385 406 … … 512 533 ControlPart appearance = o->style()->appearance(); 513 534 if (appearance == PushButtonPart || appearance == ButtonPart) { 514 p.drawPushButton(r, isPressed(o) );535 p.drawPushButton(r, isPressed(o), isEnabled(o)); 515 536 } else if (appearance == RadioPart) 516 p.drawRadioButton(r, isChecked(o) );537 p.drawRadioButton(r, isChecked(o), isEnabled(o)); 517 538 else if (appearance == CheckboxPart) 518 p.drawCheckBox(r, isChecked(o) );539 p.drawCheckBox(r, isChecked(o), isEnabled(o)); 519 540 520 541 return false; … … 550 571 551 572 // Now paint the text field. 552 p.drawLineEdit(r, /*sunken = */isPressed(o));573 p.drawLineEdit(r, isFocused(o), isEnabled(o)); 553 574 return false; 554 575 } … … 566 587 567 588 style->setPaddingLeft(Length(paddingLeft, Fixed)); 568 style->setPaddingRight(Length(paddingRight + buttonIconSize, Fixed));589 style->setPaddingRight(Length(paddingRight + arrowBoxWidth, Fixed)); 569 590 570 591 style->setPaddingTop(Length(2, Fixed)); … … 583 604 const QRect rect(QPoint(0, 0), r.size()); 584 605 585 p.drawComboBox(rect, checkMultiple(o) );606 p.drawComboBox(rect, checkMultiple(o), isEnabled(o)); 586 607 p.painter->translate(-topLeft); 587 608 return false; … … 595 616 return true; 596 617 597 p.drawComboBox(r, checkMultiple(o) );618 p.drawComboBox(r, checkMultiple(o), isEnabled(o)); 598 619 599 620 return false; … … 603 624 double RenderThemeQtMobile::animationDurationForProgressBar(RenderProgress* renderProgress) const 604 625 { 605 notImplemented(); 606 return 0.; 626 if (renderProgress->isDeterminate()) 627 return 0; 628 // Our animation goes back and forth so we need to make it last twice as long 629 // and we need the numerator to be an odd number to ensure we get a progress value of 0.5. 630 return (2 * progressAnimationGranularity +1) / progressBarChunkPercentage * animationRepeatIntervalForProgressBar(renderProgress); 607 631 } 608 632 609 633 bool RenderThemeQtMobile::paintProgressBar(RenderObject* o, const PaintInfo& pi, const IntRect& r) 610 634 { 611 notImplemented(); 612 return true; 635 if (!o->isProgress()) 636 return true; 637 638 StylePainterMobile p(this, pi); 639 if (!p.isValid()) 640 return true; 641 642 RenderProgress* renderProgress = toRenderProgress(o); 643 const bool isRTL = (renderProgress->style()->direction() == RTL); 644 645 if (renderProgress->isDeterminate()) 646 p.drawProgress(r, renderProgress->position(), !isRTL); 647 else 648 p.drawProgress(r, renderProgress->animationProgress(), !isRTL, true); 649 650 return false; 613 651 } 614 652 #endif … … 617 655 const IntRect& r) 618 656 { 619 notImplemented(); 620 return true; 657 StylePainterMobile p(this, pi); 658 if (!p.isValid()) 659 return true; 660 661 HTMLInputElement* slider = static_cast<HTMLInputElement*>(o->node()); 662 663 const double min = slider->minimum(); 664 const double max = slider->maximum(); 665 const double progress = (max - min > 0) ? (slider->valueAsNumber() - min) / (max - min) : 0; 666 667 // Render the spin buttons for LTR or RTL accordingly. 668 const int groovePadding = r.height() * sliderGrooveBorderRatio; 669 const QRect rect(r); 670 p.drawProgress(rect.adjusted(0, groovePadding, 0, -groovePadding), progress, o->style()->isLeftToRightDirection()); 671 672 return false; 621 673 } 622 674 … … 624 676 const IntRect& r) 625 677 { 626 // We've already painted it in paintSliderTrack(), no need to do anything here. 627 notImplemented(); 628 return true; 678 StylePainterMobile p(this, pi); 679 if (!p.isValid()) 680 return true; 681 682 p.drawSliderThumb(r, isPressed(o)); 683 684 return false; 629 685 } 630 686 … … 646 702 const ControlPart part = style->appearance(); 647 703 if (part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart) { 648 style->setWidth(Length(sliderWidth, Fixed)); 649 style->setHeight(Length(sliderHeight, Fixed)); 704 const int size = sliderSize * style->effectiveZoom(); 705 style->setWidth(Length(size, Fixed)); 706 style->setHeight(Length(size, Fixed)); 650 707 } else 651 708 RenderThemeQt::adjustSliderThumbSize(style); -
trunk/Source/WebCore/platform/qt/RenderThemeQtMobile.h
r102419 r102768 85 85 86 86 class StylePainterMobile : public StylePainter { 87 87 88 public: 88 89 explicit StylePainterMobile(RenderThemeQtMobile*, const PaintInfo&); 90 ~StylePainterMobile(); 89 91 90 void drawLineEdit(const QRect&, bool sunken, bool enabled = true);92 void drawLineEdit(const QRect&, bool focused, bool enabled = true); 91 93 void drawCheckBox(const QRect&, bool checked, bool enabled = true); 92 94 void drawRadioButton(const QRect&, bool checked, bool enabled = true); 93 95 void drawPushButton(const QRect&, bool sunken, bool enabled = true); 94 96 void drawComboBox(const QRect&, bool multiple, bool enabled = true); 97 void drawProgress(const QRect&, double progress, bool leftToRight = true, bool animated = false) const; 98 void drawSliderThumb(const QRect&, bool pressed) const; 95 99 96 100 private: 97 void drawChecker(QPainter*, int size, QColor) const; 98 QPixmap findChecker(const QRect&, bool disabled) const; 101 void drawCheckableBackground(QPainter*, const QRect&, bool checked, bool enabled) const; 102 void drawChecker(QPainter*, const QRect&, const QColor&) const; 103 QPixmap findCheckBox(const QSize&, bool checked, bool enabled) const; 99 104 100 void drawRadio(QPainter*, const QSize&, bool checked, QColor) const;101 QPixmap findRadio(const QSize&, bool checked, bool disabled) const;105 void drawRadio(QPainter*, const QSize&, bool checked, bool enabled) const; 106 QPixmap findRadio(const QSize&, bool checked, bool enabled) const; 102 107 103 QSize getButtonImageSize(const QSize&) const; 104 void drawSimpleComboButton(QPainter*, const QSize&, QColor) const; 105 void drawMultipleComboButton(QPainter*, const QSize&, QColor) const; 106 QPixmap findComboButton(const QSize&, bool multiple, bool disabled) const; 108 QSize getButtonImageSize(const QSize&, bool multiple) const; 109 void drawSimpleComboButton(QPainter*, const QSize&, const QColor&) const; 110 void drawMultipleComboButton(QPainter*, const QSize&, const QColor&) const; 111 QPixmap findComboButton(const QSize&, bool multiple, bool enabled) const; 112 113 QSize sizeForPainterScale(const QRect&) const; 114 115 bool m_previousSmoothPixmapTransform; 107 116 108 117 Q_DISABLE_COPY(StylePainterMobile); 109 118 }; 119 110 120 } 111 121 -
trunk/Tools/ChangeLog
r102766 r102768 1 2011-12-14 Pierre Rossi <pierre.rossi@gmail.com> 2 3 [Qt] Mobile theme could use a little refresh 4 https://bugs.webkit.org/show_bug.cgi?id=74293 5 6 Have MiniBrowser use the mobile theme when not 7 passed --desktop. 8 9 Reviewed by Kenneth Rohde Christiansen. 10 11 * MiniBrowser/qt/MiniBrowserApplication.cpp: 12 (MiniBrowserApplication::handleUserOptions): 13 1 14 2011-12-14 João Paulo Rechi Vita <jprvita@openbossa.org> 2 15 -
trunk/Tools/MiniBrowser/qt/MiniBrowserApplication.cpp
r102568 r102768 200 200 } 201 201 202 m_windowOptions.setUseTraditionalDesktopBehavior(takeOptionFlag(&args, "--desktop")); 202 const bool useDesktopBehavior = takeOptionFlag(&args, "--desktop"); 203 if (!useDesktopBehavior) 204 qputenv("QT_WEBKIT_USE_MOBILE_THEME", QByteArray("1")); 205 m_windowOptions.setUseTraditionalDesktopBehavior(useDesktopBehavior); 203 206 m_windowOptions.setPrintLoadedUrls(takeOptionFlag(&args, "-v")); 204 207 m_windowOptions.setStartMaximized(takeOptionFlag(&args, "--maximize"));
Note: See TracChangeset
for help on using the changeset viewer.