author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* This file is part of the WebKit project. |
|
3 |
* |
|
4 |
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
|
5 |
* |
|
6 |
* Copyright (C) 2006 Zack Rusin <zack@kde.org> |
|
7 |
* 2006 Dirk Mueller <mueller@kde.org> |
|
8 |
* 2006 Nikolas Zimmermann <zimmermann@kde.org> |
|
9 |
* Copyright (C) 2008 Holger Hans Peter Freyther |
|
10 |
* |
|
11 |
* All rights reserved. |
|
12 |
* |
|
13 |
* This library is free software; you can redistribute it and/or |
|
14 |
* modify it under the terms of the GNU Library General Public |
|
15 |
* License as published by the Free Software Foundation; either |
|
16 |
* version 2 of the License, or (at your option) any later version. |
|
17 |
* |
|
18 |
* This library is distributed in the hope that it will be useful, |
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
21 |
* Library General Public License for more details. |
|
22 |
* |
|
23 |
* You should have received a copy of the GNU Library General Public License |
|
24 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
25 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
26 |
* Boston, MA 02110-1301, USA. |
|
27 |
* |
|
28 |
*/ |
|
29 |
||
30 |
#include "config.h" |
|
31 |
#include "RenderThemeQt.h" |
|
32 |
||
33 |
#include "CSSStyleSelector.h" |
|
34 |
#include "CSSStyleSheet.h" |
|
35 |
#include "ChromeClientQt.h" |
|
36 |
#include "Color.h" |
|
37 |
#include "Document.h" |
|
38 |
#include "Font.h" |
|
39 |
#include "FontSelector.h" |
|
40 |
#include "GraphicsContext.h" |
|
41 |
#include "HTMLMediaElement.h" |
|
42 |
#include "HTMLNames.h" |
|
43 |
#include "NotImplemented.h" |
|
44 |
#include "Page.h" |
|
45 |
#include "RenderBox.h" |
|
46 |
#include "RenderTheme.h" |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
47 |
#include "ScrollbarThemeQt.h" |
0 | 48 |
#include "UserAgentStyleSheets.h" |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
#include "QWebPageClient.h" |
0 | 50 |
#include "qwebpage.h" |
51 |
||
52 |
#include <QApplication> |
|
53 |
#include <QColor> |
|
54 |
#include <QDebug> |
|
55 |
#include <QFile> |
|
56 |
#include <QLineEdit> |
|
57 |
#include <QPainter> |
|
58 |
#include <QPushButton> |
|
59 |
#include <QStyleFactory> |
|
60 |
#include <QStyleOptionButton> |
|
61 |
#include <QStyleOptionFrameV2> |
|
62 |
#include <QWidget> |
|
63 |
||
64 |
||
65 |
namespace WebCore { |
|
66 |
||
67 |
using namespace HTMLNames; |
|
68 |
||
69 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
70 |
StylePainter::StylePainter(RenderThemeQt* theme, const RenderObject::PaintInfo& paintInfo) |
0 | 71 |
{ |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
72 |
init(paintInfo.context ? paintInfo.context : 0, theme->qStyle()); |
0 | 73 |
} |
74 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
75 |
StylePainter::StylePainter(ScrollbarThemeQt* theme, GraphicsContext* context) |
0 | 76 |
{ |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
77 |
init(context, theme->style()); |
0 | 78 |
} |
79 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
80 |
void StylePainter::init(GraphicsContext* context, QStyle* themeStyle) |
0 | 81 |
{ |
82 |
painter = static_cast<QPainter*>(context->platformContext()); |
|
83 |
widget = 0; |
|
84 |
QPaintDevice* dev = 0; |
|
85 |
if (painter) |
|
86 |
dev = painter->device(); |
|
87 |
if (dev && dev->devType() == QInternal::Widget) |
|
88 |
widget = static_cast<QWidget*>(dev); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
89 |
style = themeStyle; |
0 | 90 |
|
91 |
if (painter) { |
|
92 |
// the styles often assume being called with a pristine painter where no brush is set, |
|
93 |
// so reset it manually |
|
94 |
oldBrush = painter->brush(); |
|
95 |
painter->setBrush(Qt::NoBrush); |
|
96 |
||
97 |
// painting the widget with anti-aliasing will make it blurry |
|
98 |
// disable it here and restore it later |
|
99 |
oldAntialiasing = painter->testRenderHint(QPainter::Antialiasing); |
|
100 |
painter->setRenderHint(QPainter::Antialiasing, false); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
StylePainter::~StylePainter() |
|
105 |
{ |
|
106 |
if (painter) { |
|
107 |
painter->setBrush(oldBrush); |
|
108 |
painter->setRenderHints(QPainter::Antialiasing, oldAntialiasing); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
PassRefPtr<RenderTheme> RenderThemeQt::create(Page* page) |
|
113 |
{ |
|
114 |
return adoptRef(new RenderThemeQt(page)); |
|
115 |
} |
|
116 |
||
117 |
PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page* page) |
|
118 |
{ |
|
119 |
if (page) |
|
120 |
return RenderThemeQt::create(page); |
|
121 |
||
122 |
static RenderTheme* fallback = RenderThemeQt::create(0).releaseRef(); |
|
123 |
return fallback; |
|
124 |
} |
|
125 |
||
126 |
RenderThemeQt::RenderThemeQt(Page* page) |
|
127 |
: RenderTheme() |
|
128 |
, m_page(page) |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
129 |
, m_lineEdit(0) |
0 | 130 |
{ |
131 |
QPushButton button; |
|
132 |
button.setAttribute(Qt::WA_MacSmallSize); |
|
133 |
QFont defaultButtonFont = QApplication::font(&button); |
|
134 |
QFontInfo fontInfo(defaultButtonFont); |
|
135 |
m_buttonFontFamily = defaultButtonFont.family(); |
|
136 |
#ifdef Q_WS_MAC |
|
137 |
m_buttonFontPixelSize = fontInfo.pixelSize(); |
|
138 |
#endif |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
139 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
140 |
m_fallbackStyle = QStyleFactory::create(QLatin1String("windows")); |
0 | 141 |
} |
142 |
||
143 |
RenderThemeQt::~RenderThemeQt() |
|
144 |
{ |
|
145 |
delete m_fallbackStyle; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
146 |
delete m_lineEdit; |
0 | 147 |
} |
148 |
||
149 |
// for some widget painting, we need to fallback to Windows style |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
150 |
QStyle* RenderThemeQt::fallbackStyle() const |
0 | 151 |
{ |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
152 |
return (m_fallbackStyle) ? m_fallbackStyle : QApplication::style(); |
0 | 153 |
} |
154 |
||
155 |
QStyle* RenderThemeQt::qStyle() const |
|
156 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
157 |
#ifdef Q_WS_MAEMO_5 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
158 |
return fallbackStyle(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
159 |
#endif |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
160 |
|
0 | 161 |
if (m_page) { |
162 |
ChromeClientQt* client = static_cast<ChromeClientQt*>(m_page->chrome()->client()); |
|
163 |
||
164 |
if (!client->m_webPage) |
|
165 |
return QApplication::style(); |
|
166 |
||
167 |
if (QWidget* view = client->m_webPage->view()) |
|
168 |
return view->style(); |
|
169 |
} |
|
170 |
||
171 |
return QApplication::style(); |
|
172 |
} |
|
173 |
||
174 |
bool RenderThemeQt::supportsHover(const RenderStyle*) const |
|
175 |
{ |
|
176 |
return true; |
|
177 |
} |
|
178 |
||
179 |
bool RenderThemeQt::supportsFocusRing(const RenderStyle*) const |
|
180 |
{ |
|
181 |
return true; // Qt provides this through the style |
|
182 |
} |
|
183 |
||
184 |
int RenderThemeQt::baselinePosition(const RenderObject* o) const |
|
185 |
{ |
|
186 |
if (!o->isBox()) |
|
187 |
return 0; |
|
188 |
||
189 |
if (o->style()->appearance() == CheckboxPart || o->style()->appearance() == RadioPart) |
|
190 |
return toRenderBox(o)->marginTop() + toRenderBox(o)->height() - 2; // Same as in old khtml |
|
191 |
return RenderTheme::baselinePosition(o); |
|
192 |
} |
|
193 |
||
194 |
bool RenderThemeQt::controlSupportsTints(const RenderObject* o) const |
|
195 |
{ |
|
196 |
if (!isEnabled(o)) |
|
197 |
return false; |
|
198 |
||
199 |
// Checkboxes only have tint when checked. |
|
200 |
if (o->style()->appearance() == CheckboxPart) |
|
201 |
return isChecked(o); |
|
202 |
||
203 |
// For now assume other controls have tint if enabled. |
|
204 |
return true; |
|
205 |
} |
|
206 |
||
207 |
bool RenderThemeQt::supportsControlTints() const |
|
208 |
{ |
|
209 |
return true; |
|
210 |
} |
|
211 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
212 |
int RenderThemeQt::findFrameLineWidth(QStyle* style) const |
0 | 213 |
{ |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
214 |
if (!m_lineEdit) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
215 |
m_lineEdit = new QLineEdit(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
216 |
|
0 | 217 |
QStyleOptionFrameV2 opt; |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
218 |
return style->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, m_lineEdit); |
0 | 219 |
} |
220 |
||
221 |
static QRect inflateButtonRect(const QRect& originalRect, QStyle* style) |
|
222 |
{ |
|
223 |
QStyleOptionButton option; |
|
224 |
option.state |= QStyle::State_Small; |
|
225 |
option.rect = originalRect; |
|
226 |
||
227 |
QRect layoutRect = style->subElementRect(QStyle::SE_PushButtonLayoutItem, &option, 0); |
|
228 |
if (!layoutRect.isNull()) { |
|
229 |
int paddingLeft = layoutRect.left() - originalRect.left(); |
|
230 |
int paddingRight = originalRect.right() - layoutRect.right(); |
|
231 |
int paddingTop = layoutRect.top() - originalRect.top(); |
|
232 |
int paddingBottom = originalRect.bottom() - layoutRect.bottom(); |
|
233 |
||
234 |
return originalRect.adjusted(-paddingLeft, -paddingTop, paddingRight, paddingBottom); |
|
235 |
} |
|
236 |
return originalRect; |
|
237 |
} |
|
238 |
||
239 |
void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& rect) |
|
240 |
{ |
|
241 |
switch (o->style()->appearance()) { |
|
242 |
case CheckboxPart: |
|
243 |
break; |
|
244 |
case RadioPart: |
|
245 |
break; |
|
246 |
case PushButtonPart: |
|
247 |
case ButtonPart: { |
|
248 |
QRect inflatedRect = inflateButtonRect(rect, qStyle()); |
|
249 |
rect = IntRect(inflatedRect.x(), inflatedRect.y(), inflatedRect.width(), inflatedRect.height()); |
|
250 |
break; |
|
251 |
} |
|
252 |
case MenulistPart: |
|
253 |
break; |
|
254 |
default: |
|
255 |
break; |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
Color RenderThemeQt::platformActiveSelectionBackgroundColor() const |
|
260 |
{ |
|
261 |
QPalette pal = QApplication::palette(); |
|
262 |
return pal.brush(QPalette::Active, QPalette::Highlight).color(); |
|
263 |
} |
|
264 |
||
265 |
Color RenderThemeQt::platformInactiveSelectionBackgroundColor() const |
|
266 |
{ |
|
267 |
QPalette pal = QApplication::palette(); |
|
268 |
return pal.brush(QPalette::Inactive, QPalette::Highlight).color(); |
|
269 |
} |
|
270 |
||
271 |
Color RenderThemeQt::platformActiveSelectionForegroundColor() const |
|
272 |
{ |
|
273 |
QPalette pal = QApplication::palette(); |
|
274 |
return pal.brush(QPalette::Active, QPalette::HighlightedText).color(); |
|
275 |
} |
|
276 |
||
277 |
Color RenderThemeQt::platformInactiveSelectionForegroundColor() const |
|
278 |
{ |
|
279 |
QPalette pal = QApplication::palette(); |
|
280 |
return pal.brush(QPalette::Inactive, QPalette::HighlightedText).color(); |
|
281 |
} |
|
282 |
||
283 |
void RenderThemeQt::systemFont(int, FontDescription&) const |
|
284 |
{ |
|
285 |
// no-op |
|
286 |
} |
|
287 |
||
288 |
int RenderThemeQt::minimumMenuListSize(RenderStyle*) const |
|
289 |
{ |
|
290 |
const QFontMetrics &fm = QApplication::fontMetrics(); |
|
291 |
return 7 * fm.width(QLatin1Char('x')); |
|
292 |
} |
|
293 |
||
294 |
void RenderThemeQt::computeSizeBasedOnStyle(RenderStyle* renderStyle) const |
|
295 |
{ |
|
296 |
// If the width and height are both specified, then we have nothing to do. |
|
297 |
if (!renderStyle->width().isIntrinsicOrAuto() && !renderStyle->height().isAuto()) |
|
298 |
return; |
|
299 |
||
300 |
QSize size(0, 0); |
|
301 |
const QFontMetrics fm(renderStyle->font().font()); |
|
302 |
QStyle* style = qStyle(); |
|
303 |
||
304 |
switch (renderStyle->appearance()) { |
|
305 |
case CheckboxPart: { |
|
306 |
QStyleOption styleOption; |
|
307 |
styleOption.state |= QStyle::State_Small; |
|
308 |
int checkBoxWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption); |
|
309 |
size = QSize(checkBoxWidth, checkBoxWidth); |
|
310 |
break; |
|
311 |
} |
|
312 |
case RadioPart: { |
|
313 |
QStyleOption styleOption; |
|
314 |
styleOption.state |= QStyle::State_Small; |
|
315 |
int radioWidth = style->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &styleOption); |
|
316 |
size = QSize(radioWidth, radioWidth); |
|
317 |
break; |
|
318 |
} |
|
319 |
case PushButtonPart: |
|
320 |
case ButtonPart: { |
|
321 |
QStyleOptionButton styleOption; |
|
322 |
styleOption.state |= QStyle::State_Small; |
|
323 |
QSize contentSize = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); |
|
324 |
QSize pushButtonSize = style->sizeFromContents(QStyle::CT_PushButton, |
|
325 |
&styleOption, contentSize, 0); |
|
326 |
styleOption.rect = QRect(0, 0, pushButtonSize.width(), pushButtonSize.height()); |
|
327 |
QRect layoutRect = style->subElementRect(QStyle::SE_PushButtonLayoutItem, |
|
328 |
&styleOption, 0); |
|
329 |
||
330 |
// If the style supports layout rects we use that, and compensate accordingly |
|
331 |
// in paintButton() below. |
|
332 |
if (!layoutRect.isNull()) |
|
333 |
size.setHeight(layoutRect.height()); |
|
334 |
else |
|
335 |
size.setHeight(pushButtonSize.height()); |
|
336 |
||
337 |
break; |
|
338 |
} |
|
339 |
case MenulistPart: { |
|
340 |
QStyleOptionComboBox styleOption; |
|
341 |
styleOption.state |= QStyle::State_Small; |
|
342 |
int contentHeight = qMax(fm.lineSpacing(), 14) + 2; |
|
343 |
QSize menuListSize = style->sizeFromContents(QStyle::CT_ComboBox, |
|
344 |
&styleOption, QSize(0, contentHeight), 0); |
|
345 |
size.setHeight(menuListSize.height()); |
|
346 |
break; |
|
347 |
} |
|
348 |
case TextFieldPart: { |
|
349 |
const int verticalMargin = 1; |
|
350 |
const int horizontalMargin = 2; |
|
351 |
int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin; |
|
352 |
int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; |
|
353 |
QStyleOptionFrameV2 opt; |
|
354 |
opt.lineWidth = findFrameLineWidth(style); |
|
355 |
QSize sz = style->sizeFromContents(QStyle::CT_LineEdit, |
|
356 |
&opt, |
|
357 |
QSize(w, h).expandedTo(QApplication::globalStrut()), |
|
358 |
0); |
|
359 |
size.setHeight(sz.height()); |
|
360 |
||
361 |
renderStyle->setPaddingLeft(Length(opt.lineWidth, Fixed)); |
|
362 |
renderStyle->setPaddingRight(Length(opt.lineWidth, Fixed)); |
|
363 |
break; |
|
364 |
} |
|
365 |
default: |
|
366 |
break; |
|
367 |
} |
|
368 |
||
369 |
// FIXME: Check is flawed, since it doesn't take min-width/max-width into account. |
|
370 |
if (renderStyle->width().isIntrinsicOrAuto() && size.width() > 0) |
|
371 |
renderStyle->setWidth(Length(size.width(), Fixed)); |
|
372 |
if (renderStyle->height().isAuto() && size.height() > 0) |
|
373 |
renderStyle->setHeight(Length(size.height(), Fixed)); |
|
374 |
} |
|
375 |
||
376 |
void RenderThemeQt::setCheckboxSize(RenderStyle* style) const |
|
377 |
{ |
|
378 |
computeSizeBasedOnStyle(style); |
|
379 |
} |
|
380 |
||
381 |
bool RenderThemeQt::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
382 |
{ |
|
383 |
return paintButton(o, i, r); |
|
384 |
} |
|
385 |
||
386 |
void RenderThemeQt::setRadioSize(RenderStyle* style) const |
|
387 |
{ |
|
388 |
computeSizeBasedOnStyle(style); |
|
389 |
} |
|
390 |
||
391 |
bool RenderThemeQt::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
392 |
{ |
|
393 |
return paintButton(o, i, r); |
|
394 |
} |
|
395 |
||
396 |
void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element*) const |
|
397 |
{ |
|
398 |
// Ditch the border. |
|
399 |
style->resetBorder(); |
|
400 |
||
401 |
// Height is locked to auto. |
|
402 |
style->setHeight(Length(Auto)); |
|
403 |
||
404 |
// White-space is locked to pre |
|
405 |
style->setWhiteSpace(PRE); |
|
406 |
||
407 |
FontDescription fontDescription = style->fontDescription(); |
|
408 |
fontDescription.setIsAbsoluteSize(true); |
|
409 |
||
410 |
#ifdef Q_WS_MAC // Use fixed font size and family on Mac (like Safari does) |
|
411 |
fontDescription.setSpecifiedSize(m_buttonFontPixelSize); |
|
412 |
fontDescription.setComputedSize(m_buttonFontPixelSize); |
|
413 |
#else |
|
414 |
fontDescription.setSpecifiedSize(style->fontSize()); |
|
415 |
fontDescription.setComputedSize(style->fontSize()); |
|
416 |
#endif |
|
417 |
||
418 |
FontFamily fontFamily; |
|
419 |
fontFamily.setFamily(m_buttonFontFamily); |
|
420 |
fontDescription.setFamily(fontFamily); |
|
421 |
style->setFontDescription(fontDescription); |
|
422 |
style->font().update(selector->fontSelector()); |
|
423 |
style->setLineHeight(RenderStyle::initialLineHeight()); |
|
424 |
||
425 |
setButtonSize(style); |
|
426 |
setButtonPadding(style); |
|
427 |
} |
|
428 |
||
429 |
void RenderThemeQt::setButtonSize(RenderStyle* style) const |
|
430 |
{ |
|
431 |
computeSizeBasedOnStyle(style); |
|
432 |
} |
|
433 |
||
434 |
void RenderThemeQt::setButtonPadding(RenderStyle* style) const |
|
435 |
{ |
|
436 |
QStyleOptionButton styleOption; |
|
437 |
styleOption.state |= QStyle::State_Small; |
|
438 |
||
439 |
// Fake a button rect here, since we're just computing deltas |
|
440 |
QRect originalRect = QRect(0, 0, 100, 30); |
|
441 |
styleOption.rect = originalRect; |
|
442 |
||
443 |
// Default padding is based on the button margin pixel metric |
|
444 |
int buttonMargin = qStyle()->pixelMetric(QStyle::PM_ButtonMargin, &styleOption, 0); |
|
445 |
int paddingLeft = buttonMargin; |
|
446 |
int paddingRight = buttonMargin; |
|
447 |
int paddingTop = 1; |
|
448 |
int paddingBottom = 0; |
|
449 |
||
450 |
// Then check if the style uses layout margins |
|
451 |
QRect layoutRect = qStyle()->subElementRect(QStyle::SE_PushButtonLayoutItem, |
|
452 |
&styleOption, 0); |
|
453 |
if (!layoutRect.isNull()) { |
|
454 |
QRect contentsRect = qStyle()->subElementRect(QStyle::SE_PushButtonContents, |
|
455 |
&styleOption, 0); |
|
456 |
paddingLeft = contentsRect.left() - layoutRect.left(); |
|
457 |
paddingRight = layoutRect.right() - contentsRect.right(); |
|
458 |
paddingTop = contentsRect.top() - layoutRect.top(); |
|
459 |
||
460 |
// Can't use this right now because we don't have the baseline to compensate |
|
461 |
// paddingBottom = layoutRect.bottom() - contentsRect.bottom(); |
|
462 |
} |
|
463 |
||
464 |
style->setPaddingLeft(Length(paddingLeft, Fixed)); |
|
465 |
style->setPaddingRight(Length(paddingRight, Fixed)); |
|
466 |
style->setPaddingTop(Length(paddingTop, Fixed)); |
|
467 |
style->setPaddingBottom(Length(paddingBottom, Fixed)); |
|
468 |
} |
|
469 |
||
470 |
bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
471 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
472 |
StylePainter p(this, i); |
0 | 473 |
if (!p.isValid()) |
474 |
return true; |
|
475 |
||
476 |
QStyleOptionButton option; |
|
477 |
if (p.widget) |
|
478 |
option.initFrom(p.widget); |
|
479 |
||
480 |
option.rect = r; |
|
481 |
option.state |= QStyle::State_Small; |
|
482 |
||
483 |
ControlPart appearance = applyTheme(option, o); |
|
484 |
if (appearance == PushButtonPart || appearance == ButtonPart) { |
|
485 |
option.rect = inflateButtonRect(option.rect, qStyle()); |
|
486 |
p.drawControl(QStyle::CE_PushButton, option); |
|
487 |
} else if (appearance == RadioPart) |
|
488 |
p.drawControl(QStyle::CE_RadioButton, option); |
|
489 |
else if (appearance == CheckboxPart) |
|
490 |
p.drawControl(QStyle::CE_CheckBox, option); |
|
491 |
||
492 |
return false; |
|
493 |
} |
|
494 |
||
495 |
void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const |
|
496 |
{ |
|
497 |
style->setBackgroundColor(Color::transparent); |
|
498 |
style->resetBorder(); |
|
499 |
style->resetPadding(); |
|
500 |
computeSizeBasedOnStyle(style); |
|
501 |
} |
|
502 |
||
503 |
bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
504 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
505 |
StylePainter p(this, i); |
0 | 506 |
if (!p.isValid()) |
507 |
return true; |
|
508 |
||
509 |
QStyleOptionFrameV2 panel; |
|
510 |
if (p.widget) |
|
511 |
panel.initFrom(p.widget); |
|
512 |
||
513 |
panel.rect = r; |
|
514 |
panel.lineWidth = findFrameLineWidth(qStyle()); |
|
515 |
panel.state |= QStyle::State_Sunken; |
|
516 |
panel.features = QStyleOptionFrameV2::None; |
|
517 |
||
518 |
// Get the correct theme data for a text field |
|
519 |
ControlPart appearance = applyTheme(panel, o); |
|
520 |
if (appearance != TextFieldPart |
|
521 |
&& appearance != SearchFieldPart |
|
522 |
&& appearance != TextAreaPart |
|
523 |
&& appearance != ListboxPart) |
|
524 |
return true; |
|
525 |
||
526 |
// Now paint the text field. |
|
527 |
p.drawPrimitive(QStyle::PE_PanelLineEdit, panel); |
|
528 |
||
529 |
return false; |
|
530 |
} |
|
531 |
||
532 |
void RenderThemeQt::adjustTextAreaStyle(CSSStyleSelector* selector, RenderStyle* style, Element* element) const |
|
533 |
{ |
|
534 |
adjustTextFieldStyle(selector, style, element); |
|
535 |
} |
|
536 |
||
537 |
bool RenderThemeQt::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
538 |
{ |
|
539 |
return paintTextField(o, i, r); |
|
540 |
} |
|
541 |
||
542 |
void RenderThemeQt::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element*) const |
|
543 |
{ |
|
544 |
style->resetBorder(); |
|
545 |
||
546 |
// Height is locked to auto. |
|
547 |
style->setHeight(Length(Auto)); |
|
548 |
||
549 |
// White-space is locked to pre |
|
550 |
style->setWhiteSpace(PRE); |
|
551 |
||
552 |
computeSizeBasedOnStyle(style); |
|
553 |
||
554 |
// Add in the padding that we'd like to use. |
|
555 |
setPopupPadding(style); |
|
556 |
} |
|
557 |
||
558 |
void RenderThemeQt::setPopupPadding(RenderStyle* style) const |
|
559 |
{ |
|
560 |
const int padding = 8; |
|
561 |
style->setPaddingLeft(Length(padding, Fixed)); |
|
562 |
||
563 |
QStyleOptionComboBox opt; |
|
564 |
int w = qStyle()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0); |
|
565 |
style->setPaddingRight(Length(padding + w, Fixed)); |
|
566 |
||
567 |
style->setPaddingTop(Length(2, Fixed)); |
|
568 |
style->setPaddingBottom(Length(0, Fixed)); |
|
569 |
} |
|
570 |
||
571 |
||
572 |
bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
573 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
574 |
StylePainter p(this, i); |
0 | 575 |
if (!p.isValid()) |
576 |
return true; |
|
577 |
||
578 |
QStyleOptionComboBox opt; |
|
579 |
if (p.widget) |
|
580 |
opt.initFrom(p.widget); |
|
581 |
applyTheme(opt, o); |
|
582 |
||
583 |
const QPoint topLeft = r.topLeft(); |
|
584 |
p.painter->translate(topLeft); |
|
585 |
opt.rect.moveTo(QPoint(0, 0)); |
|
586 |
opt.rect.setSize(r.size()); |
|
587 |
||
588 |
p.drawComplexControl(QStyle::CC_ComboBox, opt); |
|
589 |
p.painter->translate(-topLeft); |
|
590 |
return false; |
|
591 |
} |
|
592 |
||
593 |
void RenderThemeQt::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const |
|
594 |
{ |
|
595 |
// WORKAROUND because html.css specifies -webkit-border-radius for <select> so we override it here |
|
596 |
// see also http://bugs.webkit.org/show_bug.cgi?id=18399 |
|
597 |
style->resetBorderRadius(); |
|
598 |
||
599 |
// Height is locked to auto. |
|
600 |
style->setHeight(Length(Auto)); |
|
601 |
||
602 |
// White-space is locked to pre |
|
603 |
style->setWhiteSpace(PRE); |
|
604 |
||
605 |
computeSizeBasedOnStyle(style); |
|
606 |
||
607 |
// Add in the padding that we'd like to use. |
|
608 |
setPopupPadding(style); |
|
609 |
} |
|
610 |
||
611 |
bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, |
|
612 |
const IntRect& r) |
|
613 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
614 |
StylePainter p(this, i); |
0 | 615 |
if (!p.isValid()) |
616 |
return true; |
|
617 |
||
618 |
QStyleOptionComboBox option; |
|
619 |
if (p.widget) |
|
620 |
option.initFrom(p.widget); |
|
621 |
applyTheme(option, o); |
|
622 |
option.rect = r; |
|
623 |
||
624 |
// for drawing the combo box arrow, rely only on the fallback style |
|
625 |
p.style = fallbackStyle(); |
|
626 |
option.subControls = QStyle::SC_ComboBoxArrow; |
|
627 |
p.drawComplexControl(QStyle::CC_ComboBox, option); |
|
628 |
||
629 |
return false; |
|
630 |
} |
|
631 |
||
632 |
bool RenderThemeQt::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& pi, |
|
633 |
const IntRect& r) |
|
634 |
{ |
|
635 |
notImplemented(); |
|
636 |
return RenderTheme::paintSliderTrack(o, pi, r); |
|
637 |
} |
|
638 |
||
639 |
bool RenderThemeQt::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& pi, |
|
640 |
const IntRect& r) |
|
641 |
{ |
|
642 |
notImplemented(); |
|
643 |
return RenderTheme::paintSliderThumb(o, pi, r); |
|
644 |
} |
|
645 |
||
646 |
bool RenderThemeQt::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& pi, |
|
647 |
const IntRect& r) |
|
648 |
{ |
|
649 |
paintTextField(o, pi, r); |
|
650 |
return false; |
|
651 |
} |
|
652 |
||
653 |
void RenderThemeQt::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style, |
|
654 |
Element* e) const |
|
655 |
{ |
|
656 |
notImplemented(); |
|
657 |
RenderTheme::adjustSearchFieldStyle(selector, style, e); |
|
658 |
} |
|
659 |
||
660 |
void RenderThemeQt::adjustSearchFieldCancelButtonStyle(CSSStyleSelector* selector, RenderStyle* style, |
|
661 |
Element* e) const |
|
662 |
{ |
|
663 |
notImplemented(); |
|
664 |
RenderTheme::adjustSearchFieldCancelButtonStyle(selector, style, e); |
|
665 |
} |
|
666 |
||
667 |
bool RenderThemeQt::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& pi, |
|
668 |
const IntRect& r) |
|
669 |
{ |
|
670 |
notImplemented(); |
|
671 |
return RenderTheme::paintSearchFieldCancelButton(o, pi, r); |
|
672 |
} |
|
673 |
||
674 |
void RenderThemeQt::adjustSearchFieldDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, |
|
675 |
Element* e) const |
|
676 |
{ |
|
677 |
notImplemented(); |
|
678 |
RenderTheme::adjustSearchFieldDecorationStyle(selector, style, e); |
|
679 |
} |
|
680 |
||
681 |
bool RenderThemeQt::paintSearchFieldDecoration(RenderObject* o, const RenderObject::PaintInfo& pi, |
|
682 |
const IntRect& r) |
|
683 |
{ |
|
684 |
notImplemented(); |
|
685 |
return RenderTheme::paintSearchFieldDecoration(o, pi, r); |
|
686 |
} |
|
687 |
||
688 |
void RenderThemeQt::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, |
|
689 |
Element* e) const |
|
690 |
{ |
|
691 |
notImplemented(); |
|
692 |
RenderTheme::adjustSearchFieldResultsDecorationStyle(selector, style, e); |
|
693 |
} |
|
694 |
||
695 |
bool RenderThemeQt::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& pi, |
|
696 |
const IntRect& r) |
|
697 |
{ |
|
698 |
notImplemented(); |
|
699 |
return RenderTheme::paintSearchFieldResultsDecoration(o, pi, r); |
|
700 |
} |
|
701 |
||
702 |
bool RenderThemeQt::supportsFocus(ControlPart appearance) const |
|
703 |
{ |
|
704 |
switch (appearance) { |
|
705 |
case PushButtonPart: |
|
706 |
case ButtonPart: |
|
707 |
case TextFieldPart: |
|
708 |
case TextAreaPart: |
|
709 |
case ListboxPart: |
|
710 |
case MenulistPart: |
|
711 |
case RadioPart: |
|
712 |
case CheckboxPart: |
|
713 |
return true; |
|
714 |
default: // No for all others... |
|
715 |
return false; |
|
716 |
} |
|
717 |
} |
|
718 |
||
719 |
ControlPart RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const |
|
720 |
{ |
|
721 |
// Default bits: no focus, no mouse over |
|
722 |
option.state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver); |
|
723 |
||
724 |
if (!isEnabled(o)) |
|
725 |
option.state &= ~QStyle::State_Enabled; |
|
726 |
||
727 |
if (isReadOnlyControl(o)) |
|
728 |
// Readonly is supported on textfields. |
|
729 |
option.state |= QStyle::State_ReadOnly; |
|
730 |
||
731 |
if (supportsFocus(o->style()->appearance()) && isFocused(o)) { |
|
732 |
option.state |= QStyle::State_HasFocus; |
|
733 |
option.state |= QStyle::State_KeyboardFocusChange; |
|
734 |
} |
|
735 |
||
736 |
if (isHovered(o)) |
|
737 |
option.state |= QStyle::State_MouseOver; |
|
738 |
||
739 |
option.direction = Qt::LeftToRight; |
|
740 |
if (o->style() && o->style()->direction() == WebCore::RTL) |
|
741 |
option.direction = Qt::RightToLeft; |
|
742 |
||
743 |
ControlPart result = o->style()->appearance(); |
|
744 |
||
745 |
switch (result) { |
|
746 |
case PushButtonPart: |
|
747 |
case SquareButtonPart: |
|
748 |
case ButtonPart: |
|
749 |
case ButtonBevelPart: |
|
750 |
case ListItemPart: |
|
751 |
case MenulistButtonPart: |
|
752 |
case SearchFieldResultsButtonPart: |
|
753 |
case SearchFieldCancelButtonPart: { |
|
754 |
if (isPressed(o)) |
|
755 |
option.state |= QStyle::State_Sunken; |
|
756 |
else if (result == PushButtonPart) |
|
757 |
option.state |= QStyle::State_Raised; |
|
758 |
break; |
|
759 |
} |
|
760 |
} |
|
761 |
||
762 |
if (result == RadioPart || result == CheckboxPart) |
|
763 |
option.state |= (isChecked(o) ? QStyle::State_On : QStyle::State_Off); |
|
764 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
765 |
#ifdef Q_WS_MAEMO_5 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
766 |
static QPalette lightGrayPalette(Qt::lightGray); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
767 |
option.palette = lightGrayPalette; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
768 |
#else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
// If the owner widget has a custom palette, use it |
0 | 770 |
Page* page = o->document()->page(); |
771 |
if (page) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
ChromeClient* client = page->chrome()->client(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
QWebPageClient* pageClient = client->platformPageClient(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
if (pageClient) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
option.palette = pageClient->palette(); |
0 | 776 |
} |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
777 |
#endif |
0 | 778 |
|
779 |
return result; |
|
780 |
} |
|
781 |
||
782 |
#if ENABLE(VIDEO) |
|
783 |
||
784 |
String RenderThemeQt::extraMediaControlsStyleSheet() |
|
785 |
{ |
|
786 |
return String(mediaControlsQtUserAgentStyleSheet, sizeof(mediaControlsQtUserAgentStyleSheet)); |
|
787 |
} |
|
788 |
||
789 |
// Helper class to transform the painter's world matrix to the object's content area, scaled to 0,0,100,100 |
|
790 |
class WorldMatrixTransformer { |
|
791 |
public: |
|
792 |
WorldMatrixTransformer(QPainter* painter, RenderObject* renderObject, const IntRect& r) : m_painter(painter) |
|
793 |
{ |
|
794 |
RenderStyle* style = renderObject->style(); |
|
795 |
m_originalTransform = m_painter->transform(); |
|
796 |
m_painter->translate(r.x() + style->paddingLeft().value(), r.y() + style->paddingTop().value()); |
|
797 |
m_painter->scale((r.width() - style->paddingLeft().value() - style->paddingRight().value()) / 100.0, |
|
798 |
(r.height() - style->paddingTop().value() - style->paddingBottom().value()) / 100.0); |
|
799 |
} |
|
800 |
||
801 |
~WorldMatrixTransformer() { m_painter->setTransform(m_originalTransform); } |
|
802 |
||
803 |
private: |
|
804 |
QPainter* m_painter; |
|
805 |
QTransform m_originalTransform; |
|
806 |
}; |
|
807 |
||
808 |
HTMLMediaElement* RenderThemeQt::getMediaElementFromRenderObject(RenderObject* o) const |
|
809 |
{ |
|
810 |
Node* node = o->node(); |
|
811 |
Node* mediaNode = node ? node->shadowAncestorNode() : 0; |
|
812 |
if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag))) |
|
813 |
return 0; |
|
814 |
||
815 |
return static_cast<HTMLMediaElement*>(mediaNode); |
|
816 |
} |
|
817 |
||
818 |
void RenderThemeQt::paintMediaBackground(QPainter* painter, const IntRect& r) const |
|
819 |
{ |
|
820 |
painter->setPen(Qt::NoPen); |
|
821 |
static QColor transparentBlack(0, 0, 0, 100); |
|
822 |
painter->setBrush(transparentBlack); |
|
823 |
painter->drawRoundedRect(r.x(), r.y(), r.width(), r.height(), 5.0, 5.0); |
|
824 |
} |
|
825 |
||
826 |
QColor RenderThemeQt::getMediaControlForegroundColor(RenderObject* o) const |
|
827 |
{ |
|
828 |
QColor fgColor = platformActiveSelectionBackgroundColor(); |
|
829 |
if (o && o->node()->active()) |
|
830 |
fgColor = fgColor.lighter(); |
|
831 |
return fgColor; |
|
832 |
} |
|
833 |
||
834 |
bool RenderThemeQt::paintMediaFullscreenButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) |
|
835 |
{ |
|
836 |
return RenderTheme::paintMediaFullscreenButton(o, paintInfo, r); |
|
837 |
} |
|
838 |
||
839 |
bool RenderThemeQt::paintMediaMuteButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) |
|
840 |
{ |
|
841 |
HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o); |
|
842 |
if (!mediaElement) |
|
843 |
return false; |
|
844 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
845 |
StylePainter p(this, paintInfo); |
0 | 846 |
if (!p.isValid()) |
847 |
return true; |
|
848 |
||
849 |
p.painter->setRenderHint(QPainter::Antialiasing, true); |
|
850 |
||
851 |
paintMediaBackground(p.painter, r); |
|
852 |
||
853 |
WorldMatrixTransformer transformer(p.painter, o, r); |
|
854 |
const QPointF speakerPolygon[6] = { QPointF(20, 30), QPointF(50, 30), QPointF(80, 0), |
|
855 |
QPointF(80, 100), QPointF(50, 70), QPointF(20, 70)}; |
|
856 |
||
857 |
p.painter->setBrush(getMediaControlForegroundColor(o)); |
|
858 |
p.painter->drawPolygon(speakerPolygon, 6); |
|
859 |
||
860 |
if (mediaElement->muted()) { |
|
861 |
p.painter->setPen(Qt::red); |
|
862 |
p.painter->drawLine(0, 100, 100, 0); |
|
863 |
} |
|
864 |
||
865 |
return false; |
|
866 |
} |
|
867 |
||
868 |
bool RenderThemeQt::paintMediaPlayButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) |
|
869 |
{ |
|
870 |
HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o); |
|
871 |
if (!mediaElement) |
|
872 |
return false; |
|
873 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
874 |
StylePainter p(this, paintInfo); |
0 | 875 |
if (!p.isValid()) |
876 |
return true; |
|
877 |
||
878 |
p.painter->setRenderHint(QPainter::Antialiasing, true); |
|
879 |
||
880 |
paintMediaBackground(p.painter, r); |
|
881 |
||
882 |
WorldMatrixTransformer transformer(p.painter, o, r); |
|
883 |
p.painter->setBrush(getMediaControlForegroundColor(o)); |
|
884 |
if (mediaElement->canPlay()) { |
|
885 |
const QPointF playPolygon[3] = { QPointF(0, 0), QPointF(100, 50), QPointF(0, 100)}; |
|
886 |
p.painter->drawPolygon(playPolygon, 3); |
|
887 |
} else { |
|
888 |
p.painter->drawRect(0, 0, 30, 100); |
|
889 |
p.painter->drawRect(70, 0, 30, 100); |
|
890 |
} |
|
891 |
||
892 |
return false; |
|
893 |
} |
|
894 |
||
895 |
bool RenderThemeQt::paintMediaSeekBackButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) |
|
896 |
{ |
|
897 |
// We don't want to paint this at the moment. |
|
898 |
return false; |
|
899 |
} |
|
900 |
||
901 |
bool RenderThemeQt::paintMediaSeekForwardButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) |
|
902 |
{ |
|
903 |
// We don't want to paint this at the moment. |
|
904 |
return false; |
|
905 |
} |
|
906 |
||
907 |
bool RenderThemeQt::paintMediaSliderTrack(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) |
|
908 |
{ |
|
909 |
HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o); |
|
910 |
if (!mediaElement) |
|
911 |
return false; |
|
912 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
913 |
StylePainter p(this, paintInfo); |
0 | 914 |
if (!p.isValid()) |
915 |
return true; |
|
916 |
||
917 |
p.painter->setRenderHint(QPainter::Antialiasing, true); |
|
918 |
||
919 |
paintMediaBackground(p.painter, r); |
|
920 |
||
921 |
if (MediaPlayer* player = mediaElement->player()) { |
|
922 |
if (player->totalBytesKnown()) { |
|
923 |
float percentLoaded = static_cast<float>(player->bytesLoaded()) / player->totalBytes(); |
|
924 |
||
925 |
WorldMatrixTransformer transformer(p.painter, o, r); |
|
926 |
p.painter->setBrush(getMediaControlForegroundColor()); |
|
927 |
p.painter->drawRect(0, 37, 100 * percentLoaded, 26); |
|
928 |
} |
|
929 |
} |
|
930 |
||
931 |
return false; |
|
932 |
} |
|
933 |
||
934 |
bool RenderThemeQt::paintMediaSliderThumb(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) |
|
935 |
{ |
|
936 |
HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o->parent()); |
|
937 |
if (!mediaElement) |
|
938 |
return false; |
|
939 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
940 |
StylePainter p(this, paintInfo); |
0 | 941 |
if (!p.isValid()) |
942 |
return true; |
|
943 |
||
944 |
p.painter->setRenderHint(QPainter::Antialiasing, true); |
|
945 |
||
946 |
p.painter->setPen(Qt::NoPen); |
|
947 |
p.painter->setBrush(getMediaControlForegroundColor(o)); |
|
948 |
p.painter->drawRect(r.x(), r.y(), r.width(), r.height()); |
|
949 |
||
950 |
return false; |
|
951 |
} |
|
952 |
#endif |
|
953 |
||
954 |
void RenderThemeQt::adjustSliderThumbSize(RenderObject* o) const |
|
955 |
{ |
|
956 |
if (o->style()->appearance() == MediaSliderThumbPart) { |
|
957 |
RenderStyle* parentStyle = o->parent()->style(); |
|
958 |
Q_ASSERT(parentStyle); |
|
959 |
||
960 |
int parentHeight = parentStyle->height().value(); |
|
961 |
o->style()->setWidth(Length(parentHeight / 3, Fixed)); |
|
962 |
o->style()->setHeight(Length(parentHeight, Fixed)); |
|
963 |
} |
|
964 |
} |
|
965 |
||
966 |
double RenderThemeQt::caretBlinkInterval() const |
|
967 |
{ |
|
968 |
return QApplication::cursorFlashTime() / 1000.0 / 2.0; |
|
969 |
} |
|
970 |
||
971 |
} |
|
972 |
||
973 |
// vim: ts=4 sw=4 et |