Changeset 44759 in webkit
- Timestamp:
- Jun 17, 2009 7:52:43 AM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r44758 r44759 1 2009-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 1 26 2009-06-16 Kenneth Rohde Christiansen <kenneth.christiansen@openbossa.org> 2 27 -
trunk/WebCore/platform/qt/RenderThemeQt.cpp
r44758 r44759 121 121 } 122 122 123 RenderThemeQt::RenderThemeQt( )123 RenderThemeQt::RenderThemeQt(Page* page) 124 124 : RenderTheme() 125 , m_page(page) 126 , m_fallbackStyle(0) 125 127 { 126 128 QPushButton button; … … 132 134 m_buttonFontPixelSize = fontInfo.pixelSize(); 133 135 #endif 134 135 m_fallbackStyle = 0;136 137 // this will need to be regenerated when the style changes138 QLineEdit lineEdit;139 QStyleOptionFrameV2 opt;140 m_frameLineWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth,141 &opt, &lineEdit);142 136 } 143 137 … … 157 151 158 152 return m_fallbackStyle; 153 } 154 155 QStyle* 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(); 159 168 } 160 169 … … 198 207 } 199 208 200 static QRect inflateButtonRect(const QRect& originalRect) 209 static int findFrameLineWidth(QStyle* style) 210 { 211 QLineEdit lineEdit; 212 QStyleOptionFrameV2 opt; 213 return style->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, &lineEdit); 214 } 215 216 static QRect inflateButtonRect(const QRect& originalRect, QStyle* style) 201 217 { 202 218 QStyleOptionButton option; … … 204 220 option.rect = originalRect; 205 221 206 QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem, 207 &option, 0); 222 QRect layoutRect = style->subElementRect(QStyle::SE_PushButtonLayoutItem, &option, 0); 208 223 if (!layoutRect.isNull()) { 209 224 int paddingLeft = layoutRect.left() - originalRect.left(); … … 218 233 } 219 234 220 void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& r )235 void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& rect) 221 236 { 222 237 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; 229 242 case PushButtonPart: 230 243 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; 238 250 default: 239 251 break; … … 245 257 { 246 258 if (style->appearance() == TextFieldPart 247 248 259 || style->appearance() == TextAreaPart 260 || style->appearance() == ListboxPart) { 249 261 return style->border() != border; 250 262 } … … 296 308 QSize size(0, 0); 297 309 const QFontMetrics fm(renderStyle->font().font()); 298 QStyle* applicationStyle = QApplication::style();310 QStyle* style = qStyle(); 299 311 300 312 switch (renderStyle->appearance()) { … … 302 314 QStyleOption styleOption; 303 315 styleOption.state |= QStyle::State_Small; 304 int checkBoxWidth = applicationStyle->pixelMetric(QStyle::PM_IndicatorWidth, 305 &styleOption); 316 int checkBoxWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption); 306 317 size = QSize(checkBoxWidth, checkBoxWidth); 307 318 break; … … 310 321 QStyleOption styleOption; 311 322 styleOption.state |= QStyle::State_Small; 312 int radioWidth = applicationStyle->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, 313 &styleOption); 323 int radioWidth = style->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &styleOption); 314 324 size = QSize(radioWidth, radioWidth); 315 325 break; … … 320 330 styleOption.state |= QStyle::State_Small; 321 331 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); 326 334 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 accordinglyin 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. 332 340 if (!layoutRect.isNull()) { 333 341 size.setHeight(layoutRect.height()); … … 342 350 styleOption.state |= QStyle::State_Small; 343 351 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); 348 354 size.setHeight(menuListSize.height()); 349 355 break; … … 355 361 int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; 356 362 QStyleOptionFrameV2 opt; 357 opt.lineWidth = m_frameLineWidth;358 QSize sz = applicationStyle->sizeFromContents(QStyle::CT_LineEdit,359 360 361 363 opt.lineWidth = findFrameLineWidth(style); 364 QSize sz = style->sizeFromContents(QStyle::CT_LineEdit, 365 &opt, 366 QSize(w, h).expandedTo(QApplication::globalStrut()), 367 0); 362 368 size.setHeight(sz.height()); 363 369 … … 447 453 448 454 // 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); 451 456 int paddingLeft = buttonMargin; 452 457 int paddingRight = buttonMargin; … … 455 460 456 461 // Then check if the style uses layout margins 457 QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem,458 462 QRect layoutRect = qStyle()->subElementRect(QStyle::SE_PushButtonLayoutItem, 463 &styleOption, 0); 459 464 if (!layoutRect.isNull()) { 460 QRect contentsRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonContents,461 465 QRect contentsRect = qStyle()->subElementRect(QStyle::SE_PushButtonContents, 466 &styleOption, 0); 462 467 paddingLeft = contentsRect.left() - layoutRect.left(); 463 468 paddingRight = layoutRect.right() - contentsRect.right(); … … 489 494 ControlPart appearance = applyTheme(option, o); 490 495 if(appearance == PushButtonPart || appearance == ButtonPart) { 491 option.rect = inflateButtonRect(option.rect );496 option.rect = inflateButtonRect(option.rect, qStyle()); 492 497 p.drawControl(QStyle::CE_PushButton, option); 493 498 } else if(appearance == RadioPart) { … … 520 525 521 526 panel.rect = r; 522 panel.lineWidth = m_frameLineWidth;527 panel.lineWidth = findFrameLineWidth(qStyle()); 523 528 panel.state |= QStyle::State_Sunken; 524 529 panel.features = QStyleOptionFrameV2::None; … … 572 577 573 578 QStyleOptionComboBox opt; 574 int w = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0);579 int w = qStyle()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0); 575 580 style->setPaddingRight(Length(padding + w, Fixed)); 576 581 -
trunk/WebCore/platform/qt/RenderThemeQt.h
r44758 r44759 40 40 { 41 41 private: 42 RenderThemeQt( );42 RenderThemeQt(Page* page); 43 43 virtual ~RenderThemeQt(); 44 44 … … 142 142 void setPopupPadding(RenderStyle*) const; 143 143 144 QStyle* qStyle() const; 145 QStyle* fallbackStyle(); 146 147 Page* m_page; 148 144 149 #ifdef Q_WS_MAC 145 150 int m_buttonFontPixelSize; … … 148 153 149 154 QStyle* m_fallbackStyle; 150 QStyle* fallbackStyle();151 152 int m_frameLineWidth;153 155 }; 154 156
Note: See TracChangeset
for help on using the changeset viewer.