Bug 944300 - Disable browser_tabview_privatebrowsing_perwindowpb.js on Linux for...
[gecko.git] / widget / qt / nsNativeThemeQt.cpp
blob1df3cd6bc8ec153485c61f5ddc6f911d74ff2afc
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include <QApplication>
6 #include <QStyle>
7 #include <QPalette>
8 #include <QRect>
9 #include <QPainter>
10 #include <QStyleOption>
11 #include <QStyleOptionFrameV2>
12 #include <QStyleOptionButton>
13 #include <QFlags>
14 #include <QStyleOptionComboBox>
16 #include "nsIFrame.h"
18 #include "nsCoord.h"
19 #include "nsNativeThemeQt.h"
20 #include "nsPresContext.h"
22 #include "nsRect.h"
23 #include "nsSize.h"
24 #include "nsTransform2D.h"
25 #include "nsThemeConstants.h"
26 #include "nsIServiceManager.h"
27 #include "nsIDOMHTMLInputElement.h"
30 #include "gfxASurface.h"
31 #include "gfxContext.h"
32 #include "gfxQtPlatform.h"
33 #include "gfxQPainterSurface.h"
34 #ifdef MOZ_X11
35 #include "gfxXlibSurface.h"
36 #endif
37 #include "nsRenderingContext.h"
39 nsNativeThemeQt::nsNativeThemeQt()
41 mNoBackgroundPalette.setColor(QPalette::Window, Qt::transparent);
42 ThemeChanged();
45 nsNativeThemeQt::~nsNativeThemeQt()
49 NS_IMPL_ISUPPORTS_INHERITED1(nsNativeThemeQt, nsNativeTheme, nsITheme)
51 static inline QRect qRectInPixels(const nsRect &aRect,
52 const int32_t p2a)
54 return QRect(NSAppUnitsToIntPixels(aRect.x, p2a),
55 NSAppUnitsToIntPixels(aRect.y, p2a),
56 NSAppUnitsToIntPixels(aRect.width, p2a),
57 NSAppUnitsToIntPixels(aRect.height, p2a));
60 static inline QImage::Format
61 _qimage_from_gfximage_format (gfxImageFormat aFormat)
63 switch (aFormat) {
64 case gfxImageFormatARGB32:
65 return QImage::Format_ARGB32_Premultiplied;
66 case gfxImageFormatRGB24:
67 return QImage::Format_RGB32;
68 case gfxImageFormatRGB16_565:
69 return QImage::Format_RGB16;
70 case gfxImageFormatA8:
71 return QImage::Format_Indexed8;
72 case gfxImageFormatA1:
73 #ifdef WORDS_BIGENDIAN
74 return QImage::Format_Mono;
75 #else
76 return QImage::Format_MonoLSB;
77 #endif
78 default:
79 return QImage::Format_Invalid;
82 return QImage::Format_Mono;
85 NS_IMETHODIMP
86 nsNativeThemeQt::DrawWidgetBackground(nsRenderingContext* aContext,
87 nsIFrame* aFrame,
88 uint8_t aWidgetType,
89 const nsRect& aRect,
90 const nsRect& aClipRect)
92 gfxContext* context = aContext->ThebesContext();
93 nsRefPtr<gfxASurface> surface = context->CurrentSurface();
95 #ifdef CAIRO_HAS_QT_SURFACE
96 if (surface->GetType() == gfxSurfaceTypeQPainter) {
97 gfxQPainterSurface* qSurface = (gfxQPainterSurface*) (surface.get());
98 QPainter *painter = qSurface->GetQPainter();
99 NS_ASSERTION(painter, "Where'd my QPainter go?");
100 if (!painter)
101 return NS_ERROR_FAILURE;
102 return DrawWidgetBackground(painter, aContext,
103 aFrame, aWidgetType,
104 aRect, aClipRect);
105 } else
106 #endif
107 if (surface->GetType() == gfxSurfaceTypeImage) {
108 gfxImageSurface* qSurface = (gfxImageSurface*) (surface.get());
109 QImage tempQImage(qSurface->Data(),
110 qSurface->Width(),
111 qSurface->Height(),
112 qSurface->Stride(),
113 _qimage_from_gfximage_format(qSurface->Format()));
114 QPainter painter(&tempQImage);
115 return DrawWidgetBackground(&painter, aContext,
116 aFrame, aWidgetType,
117 aRect, aClipRect);
119 #if defined(MOZ_X11) && defined(Q_WS_X11)
120 else if (surface->GetType() == gfxSurfaceTypeXlib) {
121 gfxXlibSurface* qSurface = (gfxXlibSurface*) (surface.get());
122 QPixmap pixmap(QPixmap::fromX11Pixmap(qSurface->XDrawable()));
123 QPainter painter(&pixmap);
124 return DrawWidgetBackground(&painter, aContext,
125 aFrame, aWidgetType,
126 aRect, aClipRect);
128 #endif
130 return NS_ERROR_NOT_IMPLEMENTED;
133 nsresult
134 nsNativeThemeQt::DrawWidgetBackground(QPainter *qPainter,
135 nsRenderingContext* aContext,
136 nsIFrame* aFrame,
137 uint8_t aWidgetType,
138 const nsRect& aRect,
139 const nsRect& aClipRect)
142 gfxContext* context = aContext->ThebesContext();
143 nsRefPtr<gfxASurface> surface = context->CurrentSurface();
145 context->UpdateSurfaceClip();
147 QStyle* style = qApp->style();
149 qPainter->save();
151 gfxPoint offs = surface->GetDeviceOffset();
152 qPainter->translate(offs.x, offs.y);
154 gfxMatrix ctm = context->CurrentMatrix();
155 if (!ctm.HasNonTranslation()) {
156 ctm.x0 = NSToCoordRound(ctm.x0);
157 ctm.y0 = NSToCoordRound(ctm.y0);
160 QMatrix qctm(ctm.xx, ctm.yx, ctm.xy, ctm.yy, ctm.x0, ctm.y0);
161 qPainter->setWorldMatrix(qctm, true);
163 int32_t p2a = aContext->AppUnitsPerDevPixel();
165 QRect r = qRectInPixels(aRect, p2a);
166 QRect cr = qRectInPixels(aClipRect, p2a);
168 QStyle::State extraFlags = QStyle::State_None;
170 switch (aWidgetType) {
171 case NS_THEME_RADIO:
172 case NS_THEME_CHECKBOX: {
173 QStyleOptionButton opt;
174 InitButtonStyle (aWidgetType, aFrame, r, opt);
176 if (aWidgetType == NS_THEME_CHECKBOX)
178 style->drawPrimitive (QStyle::PE_IndicatorCheckBox, &opt, qPainter);
179 } else {
180 style->drawPrimitive (QStyle::PE_IndicatorRadioButton, &opt, qPainter);
182 break;
184 case NS_THEME_BUTTON:
185 case NS_THEME_BUTTON_BEVEL: {
186 QStyleOptionButton opt;
187 InitButtonStyle (aWidgetType, aFrame, r, opt);
189 if (aWidgetType == NS_THEME_BUTTON) {
190 style->drawPrimitive(QStyle::PE_PanelButtonCommand, &opt, qPainter);
191 if (IsDefaultButton(aFrame))
192 style->drawPrimitive(QStyle::PE_FrameDefaultButton, &opt, qPainter);
193 } else {
194 style->drawPrimitive(QStyle::PE_PanelButtonBevel, &opt, qPainter);
195 style->drawPrimitive(QStyle::PE_FrameButtonBevel, &opt, qPainter);
197 break;
199 case NS_THEME_SCROLLBAR: {
200 qPainter->fillRect(r, qApp->palette().brush(QPalette::Normal, QPalette::Window));
201 break;
203 case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: {
204 qPainter->fillRect(r, qApp->palette().brush(QPalette::Active, QPalette::Window));
205 break;
207 case NS_THEME_SCROLLBAR_TRACK_VERTICAL: {
208 qPainter->fillRect(r, qApp->palette().brush(QPalette::Active, QPalette::Window));
209 break;
211 case NS_THEME_SCROLLBAR_BUTTON_LEFT: {
212 QStyleOptionSlider opt;
213 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt, QStyle::State_Horizontal);
214 opt.orientation = Qt::Horizontal;
215 style->drawControl(QStyle::CE_ScrollBarSubLine, &opt, qPainter, nullptr);
216 break;
218 case NS_THEME_SCROLLBAR_BUTTON_RIGHT: {
219 QStyleOptionSlider opt;
220 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt, QStyle::State_Horizontal);
221 opt.orientation = Qt::Horizontal;
222 style->drawControl(QStyle::CE_ScrollBarAddLine, &opt, qPainter, nullptr);
223 break;
225 case NS_THEME_SCROLLBAR_BUTTON_UP: {
226 QStyleOptionSlider opt;
227 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt);
228 opt.orientation = Qt::Vertical;
229 style->drawControl(QStyle::CE_ScrollBarSubLine, &opt, qPainter, nullptr);
230 break;
232 case NS_THEME_SCROLLBAR_BUTTON_DOWN: {
233 QStyleOptionSlider opt;
234 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt);
235 opt.orientation = Qt::Vertical;
236 style->drawControl(QStyle::CE_ScrollBarAddLine, &opt, qPainter, nullptr);
237 break;
239 case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: {
240 extraFlags |= QStyle::State_Horizontal;
241 QStyleOptionSlider option;
242 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)option, extraFlags);
243 option.orientation = Qt::Horizontal;
244 style->drawControl(QStyle::CE_ScrollBarSlider, &option, qPainter, nullptr);
245 break;
247 case NS_THEME_SCROLLBAR_THUMB_VERTICAL: {
248 QStyleOptionSlider option;
249 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)option, extraFlags);
250 option.orientation = Qt::Vertical;
251 style->drawControl(QStyle::CE_ScrollBarSlider, &option, qPainter, nullptr);
252 break;
254 case NS_THEME_DROPDOWN: {
255 QStyleOptionComboBox comboOpt;
257 InitComboStyle(aWidgetType, aFrame, r, comboOpt);
259 style->drawComplexControl(QStyle::CC_ComboBox, &comboOpt, qPainter);
260 break;
262 case NS_THEME_DROPDOWN_BUTTON: {
263 QStyleOptionComboBox option;
265 InitComboStyle(aWidgetType, aFrame, r, option);
267 style->drawPrimitive(QStyle::PE_FrameDefaultButton, &option, qPainter);
268 style->drawPrimitive(QStyle::PE_IndicatorSpinDown, &option, qPainter);
269 break;
271 case NS_THEME_DROPDOWN_TEXT:
272 case NS_THEME_DROPDOWN_TEXTFIELD:
273 case NS_THEME_NUMBER_INPUT:
274 case NS_THEME_TEXTFIELD:
275 case NS_THEME_TEXTFIELD_MULTILINE:
276 case NS_THEME_LISTBOX: {
277 QStyleOptionFrameV2 frameOpt;
278 nsEventStates eventState = GetContentState(aFrame, aWidgetType);
280 if (!IsDisabled(aFrame, eventState))
281 frameOpt.state |= QStyle::State_Enabled;
283 frameOpt.rect = r;
284 frameOpt.features = QStyleOptionFrameV2::Flat;
286 if (aWidgetType == NS_THEME_NUMBER_INPUT ||
287 aWidgetType == NS_THEME_TEXTFIELD ||
288 aWidgetType == NS_THEME_TEXTFIELD_MULTILINE) {
289 QRect contentRect = style->subElementRect(QStyle::SE_LineEditContents, &frameOpt);
290 contentRect.adjust(mFrameWidth, mFrameWidth, -mFrameWidth, -mFrameWidth);
291 qPainter->fillRect(contentRect, QBrush(Qt::white));
294 frameOpt.palette = mNoBackgroundPalette;
295 style->drawPrimitive(QStyle::PE_FrameLineEdit, &frameOpt, qPainter, nullptr);
296 break;
298 case NS_THEME_MENUPOPUP: {
299 QStyleOptionMenuItem option;
300 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)option, extraFlags);
301 style->drawPrimitive(QStyle::PE_FrameMenu, &option, qPainter, nullptr);
302 break;
304 default:
305 break;
308 qPainter->restore();
309 return NS_OK;
312 NS_IMETHODIMP
313 nsNativeThemeQt::GetWidgetBorder(nsDeviceContext* ,
314 nsIFrame* aFrame,
315 uint8_t aWidgetType,
316 nsIntMargin* aResult)
318 (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = 0;
320 QStyle* style = qApp->style();
321 switch(aWidgetType) {
322 // case NS_THEME_TEXTFIELD:
323 // case NS_THEME_LISTBOX:
324 case NS_THEME_MENUPOPUP: {
325 (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = style->pixelMetric(QStyle::PM_MenuPanelWidth);
326 break;
328 default:
329 break;
332 return NS_OK;
335 bool
336 nsNativeThemeQt::GetWidgetPadding(nsDeviceContext* ,
337 nsIFrame*, uint8_t aWidgetType,
338 nsIntMargin* aResult)
340 // XXX: Where to get padding values, framewidth?
341 if (aWidgetType == NS_THEME_NUMBER_INPUT ||
342 aWidgetType == NS_THEME_TEXTFIELD ||
343 aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
344 aWidgetType == NS_THEME_DROPDOWN) {
345 aResult->SizeTo(2, 2, 2, 2);
346 return true;
349 return false;
352 NS_IMETHODIMP
353 nsNativeThemeQt::GetMinimumWidgetSize(nsRenderingContext* aContext, nsIFrame* aFrame,
354 uint8_t aWidgetType,
355 nsIntSize* aResult, bool* aIsOverridable)
357 (*aResult).width = (*aResult).height = 0;
358 *aIsOverridable = true;
360 QStyle *s = qApp->style();
362 int32_t p2a = aContext->AppUnitsPerDevPixel();
364 switch (aWidgetType) {
365 case NS_THEME_RADIO:
366 case NS_THEME_CHECKBOX: {
367 nsRect frameRect = aFrame->GetRect();
369 QRect qRect = qRectInPixels(frameRect, p2a);
371 QStyleOptionButton option;
373 InitButtonStyle(aWidgetType, aFrame, qRect, option);
375 QRect rect = s->subElementRect(
376 (aWidgetType == NS_THEME_CHECKBOX) ?
377 QStyle::SE_CheckBoxIndicator :
378 QStyle::SE_RadioButtonIndicator,
379 &option,
380 nullptr);
382 (*aResult).width = rect.width();
383 (*aResult).height = rect.height();
384 break;
386 case NS_THEME_BUTTON: {
387 nsRect frameRect = aFrame->GetRect();
389 QRect qRect = qRectInPixels(frameRect, p2a);
391 QStyleOptionButton option;
393 InitButtonStyle(aWidgetType, aFrame, qRect, option);
395 QRect rect = s->subElementRect(
396 QStyle::SE_PushButtonFocusRect,
397 &option,
398 nullptr);
400 (*aResult).width = rect.width();
401 (*aResult).height = rect.height();
402 break;
404 case NS_THEME_SCROLLBAR_BUTTON_UP:
405 case NS_THEME_SCROLLBAR_BUTTON_DOWN: {
406 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarExtent);
407 (*aResult).height = (*aResult).width;
408 //*aIsOverridable = false;
409 break;
411 case NS_THEME_SCROLLBAR_BUTTON_LEFT:
412 case NS_THEME_SCROLLBAR_BUTTON_RIGHT: {
413 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarExtent);
414 (*aResult).width = (*aResult).height;
415 //*aIsOverridable = false;
416 break;
418 case NS_THEME_SCROLLBAR_THUMB_VERTICAL: {
419 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarExtent);
420 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarSliderMin);
421 //*aIsOverridable = false;
422 break;
424 case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: {
425 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarSliderMin);
426 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarExtent);
427 //*aIsOverridable = false;
428 break;
430 case NS_THEME_SCROLLBAR_TRACK_VERTICAL: {
431 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarExtent);
432 (*aResult).height = s->pixelMetric(QStyle::PM_SliderLength);
433 break;
435 case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: {
436 (*aResult).width = s->pixelMetric(QStyle::PM_SliderLength);
437 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarExtent);
438 break;
440 case NS_THEME_DROPDOWN_BUTTON: {
441 QStyleOptionComboBox comboOpt;
443 nsRect frameRect = aFrame->GetRect();
444 QRect qRect = qRectInPixels(frameRect, p2a);
445 comboOpt.rect = qRect;
447 InitComboStyle(aWidgetType, aFrame, qRect, comboOpt);
449 QRect subRect = s->subControlRect(QStyle::CC_ComboBox, &comboOpt,
450 QStyle::SC_ComboBoxArrow, nullptr);
452 (*aResult).width = subRect.width();
453 (*aResult).height = subRect.height();
454 //*aIsOverridable = false;
455 break;
457 case NS_THEME_DROPDOWN: {
458 QStyleOptionComboBox comboOpt;
460 nsRect frameRect = aFrame->GetRect();
461 QRect qRect = qRectInPixels(frameRect, p2a);
462 comboOpt.rect = qRect;
464 InitComboStyle(aWidgetType, aFrame, qRect, comboOpt);
466 QRect subRect = s->subControlRect(QStyle::CC_ComboBox,
467 &comboOpt,
468 QStyle::SC_ComboBoxFrame,
469 nullptr);
471 (*aResult).width = subRect.width();
472 (*aResult).height = subRect.height();
473 //*aIsOverridable = false;
474 break;
476 case NS_THEME_DROPDOWN_TEXT: {
477 QStyleOptionComboBox comboOpt;
479 nsRect frameRect = aFrame->GetRect();
481 QRect qRect = qRectInPixels(frameRect, p2a);
483 comboOpt.rect = qRect;
485 QRect subRect = s->subControlRect(QStyle::CC_ComboBox, &comboOpt,
486 QStyle::SC_ComboBoxEditField, nullptr);
488 (*aResult).width = subRect.width();
489 (*aResult).height = subRect.height();
490 //*aIsOverridable = false;
491 break;
493 case NS_THEME_DROPDOWN_TEXTFIELD: {
494 QStyleOptionComboBox comboOpt;
496 nsRect frameRect = aFrame->GetRect();
498 QRect qRect = qRectInPixels(frameRect, p2a);
500 comboOpt.rect = qRect;
502 QRect subRect = s->subControlRect(QStyle::CC_ComboBox, &comboOpt,
503 QStyle::SC_ComboBoxArrow, nullptr);
504 QRect subRect2 = s->subControlRect(QStyle::CC_ComboBox, &comboOpt,
505 QStyle::SC_ComboBoxFrame, nullptr);
507 (*aResult).width = subRect.width() + subRect2.width();
508 (*aResult).height = std::max(subRect.height(), subRect2.height());
509 //*aIsOverridable = false;
510 break;
512 case NS_THEME_NUMBER_INPUT:
513 case NS_THEME_TEXTFIELD:
514 case NS_THEME_TEXTFIELD_MULTILINE:
515 break;
517 return NS_OK;
520 NS_IMETHODIMP
521 nsNativeThemeQt::WidgetStateChanged(nsIFrame* aFrame, uint8_t aWidgetType,
522 nsIAtom* aAttribute, bool* aShouldRepaint)
524 *aShouldRepaint = true;
525 return NS_OK;
529 NS_IMETHODIMP
530 nsNativeThemeQt::ThemeChanged()
532 QStyle *s = qApp->style();
533 if (s)
534 mFrameWidth = s->pixelMetric(QStyle::PM_DefaultFrameWidth);
535 return NS_OK;
538 bool
539 nsNativeThemeQt::ThemeSupportsWidget(nsPresContext* aPresContext,
540 nsIFrame* aFrame,
541 uint8_t aWidgetType)
543 switch (aWidgetType) {
544 case NS_THEME_SCROLLBAR:
545 case NS_THEME_SCROLLBAR_BUTTON_UP:
546 case NS_THEME_SCROLLBAR_BUTTON_DOWN:
547 case NS_THEME_SCROLLBAR_BUTTON_LEFT:
548 case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
549 case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
550 case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
551 //case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL:
552 //case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL:
553 case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
554 case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
555 case NS_THEME_RADIO:
556 case NS_THEME_CHECKBOX:
557 case NS_THEME_BUTTON_BEVEL:
558 case NS_THEME_BUTTON:
559 case NS_THEME_DROPDOWN:
560 case NS_THEME_DROPDOWN_BUTTON:
561 case NS_THEME_DROPDOWN_TEXT:
562 case NS_THEME_DROPDOWN_TEXTFIELD:
563 case NS_THEME_NUMBER_INPUT:
564 case NS_THEME_TEXTFIELD:
565 case NS_THEME_TEXTFIELD_MULTILINE:
566 case NS_THEME_LISTBOX:
567 case NS_THEME_MENUPOPUP:
568 return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
569 default:
570 break;
572 return false;
575 bool
576 nsNativeThemeQt::WidgetIsContainer(uint8_t aWidgetType)
578 // if (aWidgetType == NS_THEME_DROPDOWN_BUTTON ||
579 // aWidgetType == NS_THEME_RADIO ||
580 // aWidgetType == NS_THEME_CHECKBOX) {
581 // return false;
582 // }
584 return true;
587 bool
588 nsNativeThemeQt::ThemeDrawsFocusForWidget(uint8_t aWidgetType)
590 if (aWidgetType == NS_THEME_DROPDOWN ||
591 aWidgetType == NS_THEME_BUTTON ||
592 aWidgetType == NS_THEME_TREEVIEW_HEADER_CELL) {
593 return true;
596 return false;
599 bool
600 nsNativeThemeQt::ThemeNeedsComboboxDropmarker()
602 return true;
605 void
606 nsNativeThemeQt::InitButtonStyle(uint8_t aWidgetType,
607 nsIFrame* aFrame,
608 QRect rect,
609 QStyleOptionButton &opt)
611 nsEventStates eventState = GetContentState(aFrame, aWidgetType);
613 opt.rect = rect;
614 opt.palette = mNoBackgroundPalette;
616 bool isDisabled = IsDisabled(aFrame, eventState);
618 if (!isDisabled)
619 opt.state |= QStyle::State_Enabled;
620 if (eventState.HasState(NS_EVENT_STATE_HOVER))
621 opt.state |= QStyle::State_MouseOver;
622 if (eventState.HasState(NS_EVENT_STATE_FOCUS))
623 opt.state |= QStyle::State_HasFocus;
624 if (!isDisabled && eventState.HasState(NS_EVENT_STATE_ACTIVE))
625 // Don't allow sunken when disabled
626 opt.state |= QStyle::State_Sunken;
628 switch (aWidgetType) {
629 case NS_THEME_RADIO:
630 case NS_THEME_CHECKBOX:
631 if (IsChecked(aFrame))
632 opt.state |= QStyle::State_On;
633 else
634 opt.state |= QStyle::State_Off;
636 break;
637 default:
638 if (!eventState.HasState(NS_EVENT_STATE_ACTIVE))
639 opt.state |= QStyle::State_Raised;
640 break;
644 void
645 nsNativeThemeQt::InitPlainStyle(uint8_t aWidgetType,
646 nsIFrame* aFrame,
647 QRect rect,
648 QStyleOption &opt,
649 QStyle::State extraFlags)
651 nsEventStates eventState = GetContentState(aFrame, aWidgetType);
653 opt.rect = rect;
655 if (!IsDisabled(aFrame, eventState))
656 opt.state |= QStyle::State_Enabled;
657 if (eventState.HasState(NS_EVENT_STATE_HOVER))
658 opt.state |= QStyle::State_MouseOver;
659 if (eventState.HasState(NS_EVENT_STATE_FOCUS))
660 opt.state |= QStyle::State_HasFocus;
662 opt.state |= extraFlags;
665 void
666 nsNativeThemeQt::InitComboStyle(uint8_t aWidgetType,
667 nsIFrame* aFrame,
668 QRect rect,
669 QStyleOptionComboBox &opt)
671 nsEventStates eventState = GetContentState(aFrame, aWidgetType);
672 bool isDisabled = IsDisabled(aFrame, eventState);
674 if (!isDisabled)
675 opt.state |= QStyle::State_Enabled;
676 if (eventState.HasState(NS_EVENT_STATE_HOVER))
677 opt.state |= QStyle::State_MouseOver;
678 if (eventState.HasState(NS_EVENT_STATE_FOCUS))
679 opt.state |= QStyle::State_HasFocus;
680 if (!eventState.HasState(NS_EVENT_STATE_ACTIVE))
681 opt.state |= QStyle::State_Raised;
682 if (!isDisabled && eventState.HasState(NS_EVENT_STATE_ACTIVE))
683 // Don't allow sunken when disabled
684 opt.state |= QStyle::State_Sunken;
686 opt.rect = rect;
687 opt.palette = mNoBackgroundPalette;