Bug 455836 - Native theme for menulist widget (ff toolbar). r=vladimir.
[mozilla-central.git] / widget / src / qt / nsNativeThemeQt.cpp
blobec196daed007954daa227bec616ba72671666426
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * David Hyatt (hyatt@netscape.com).
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Lars Knoll <knoll@kde.org>
23 * Zack Rusin <zack@kde.org>
24 * Tim Hill (tim@prismelite.com)
25 * Vladimir Vukicevic <vladimir@pobox.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsIFrame.h"
43 #include <QApplication>
44 #include <QStyle>
45 #include <QPalette>
46 #include <QRect>
47 #include <QPainter>
48 #include <QStyleOption>
49 #include <QStyleOptionFrameV2>
50 #include <QStyleOptionButton>
51 #include <QFlags>
52 #include <QStyleOptionComboBox>
54 #include "nsCoord.h"
55 #include "nsNativeThemeQt.h"
56 #include "nsIDeviceContext.h"
57 #include "nsPresContext.h"
59 #include "nsRect.h"
60 #include "nsSize.h"
61 #include "nsTransform2D.h"
62 #include "nsThemeConstants.h"
63 #include "nsILookAndFeel.h"
64 #include "nsIServiceManager.h"
65 #include "nsIEventStateManager.h"
66 #include "nsIDOMHTMLInputElement.h"
67 #include <malloc.h>
70 #include "gfxASurface.h"
71 #include "gfxContext.h"
72 #include "gfxQPainterSurface.h"
73 #include "nsIRenderingContext.h"
75 nsNativeThemeQt::nsNativeThemeQt()
77 mNoBackgroundPalette.setColor(QPalette::Window, Qt::transparent);
78 ThemeChanged();
81 nsNativeThemeQt::~nsNativeThemeQt()
85 NS_IMPL_ISUPPORTS1(nsNativeThemeQt, nsITheme)
87 static inline QRect qRectInPixels(const nsRect &aRect,
88 const PRInt32 p2a)
90 return QRect(NSAppUnitsToIntPixels(aRect.x, p2a),
91 NSAppUnitsToIntPixels(aRect.y, p2a),
92 NSAppUnitsToIntPixels(aRect.width, p2a),
93 NSAppUnitsToIntPixels(aRect.height, p2a));
96 NS_IMETHODIMP
97 nsNativeThemeQt::DrawWidgetBackground(nsIRenderingContext* aContext,
98 nsIFrame* aFrame,
99 PRUint8 aWidgetType,
100 const nsRect& aRect,
101 const nsRect& aClipRect)
103 gfxContext* context = aContext->ThebesContext();
104 nsRefPtr<gfxASurface> surface = context->CurrentSurface();
106 context->UpdateSurfaceClip();
108 if (surface->GetType() != gfxASurface::SurfaceTypeQPainter)
109 return NS_ERROR_NOT_IMPLEMENTED;
111 gfxQPainterSurface* qSurface = (gfxQPainterSurface*) (surface.get());
112 QPainter* qPainter = qSurface->GetQPainter();
114 NS_ASSERTION(qPainter, "Where'd my QPainter go?");
116 if (qPainter == nsnull)
117 return NS_OK;
119 QStyle* style = qApp->style();
121 qPainter->save();
123 gfxPoint offs = surface->GetDeviceOffset();
124 qPainter->translate(offs.x, offs.y);
126 gfxMatrix ctm = context->CurrentMatrix();
127 if (!ctm.HasNonTranslation()) {
128 ctm.x0 = NSToCoordRound(ctm.x0);
129 ctm.y0 = NSToCoordRound(ctm.y0);
132 QMatrix qctm(ctm.xx, ctm.xy, ctm.yx, ctm.yy, ctm.x0, ctm.y0);
133 qPainter->setWorldMatrix(qctm, true);
135 PRInt32 p2a = GetAppUnitsPerDevPixel(aContext);
137 QRect r = qRectInPixels(aRect, p2a);
138 QRect cr = qRectInPixels(aClipRect, p2a);
140 QStyle::State extraFlags = QStyle::State_None;
142 switch (aWidgetType) {
143 case NS_THEME_RADIO:
144 case NS_THEME_RADIO_SMALL:
145 case NS_THEME_CHECKBOX:
146 case NS_THEME_CHECKBOX_SMALL: {
147 QStyleOptionButton opt;
148 InitButtonStyle (aWidgetType, aFrame, r, opt);
150 if (aWidgetType == NS_THEME_CHECKBOX ||
151 aWidgetType == NS_THEME_CHECKBOX_SMALL)
153 style->drawPrimitive (QStyle::PE_IndicatorCheckBox, &opt, qPainter);
154 } else {
155 style->drawPrimitive (QStyle::PE_IndicatorRadioButton, &opt, qPainter);
157 break;
159 case NS_THEME_BUTTON:
160 case NS_THEME_BUTTON_BEVEL: {
161 QStyleOptionButton opt;
162 InitButtonStyle (aWidgetType, aFrame, r, opt);
164 if (aWidgetType == NS_THEME_BUTTON) {
165 style->drawPrimitive(QStyle::PE_PanelButtonCommand, &opt, qPainter);
166 if (IsDefaultButton(aFrame))
167 style->drawPrimitive(QStyle::PE_FrameDefaultButton, &opt, qPainter);
168 } else {
169 style->drawPrimitive(QStyle::PE_PanelButtonBevel, &opt, qPainter);
170 style->drawPrimitive(QStyle::PE_FrameButtonBevel, &opt, qPainter);
172 break;
174 case NS_THEME_SCROLLBAR: {
175 qPainter->fillRect(r, qApp->palette().brush(QPalette::Normal, QPalette::Window));
176 break;
178 case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: {
179 qPainter->fillRect(r, qApp->palette().brush(QPalette::Active, QPalette::Window));
180 break;
182 case NS_THEME_SCROLLBAR_TRACK_VERTICAL: {
183 qPainter->fillRect(r, qApp->palette().brush(QPalette::Active, QPalette::Window));
184 break;
186 case NS_THEME_SCROLLBAR_BUTTON_LEFT: {
187 QStyleOptionSlider opt;
188 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt, QStyle::State_Horizontal);
189 opt.orientation = Qt::Horizontal;
190 style->drawControl(QStyle::CE_ScrollBarSubLine, &opt, qPainter, NULL);
191 break;
193 case NS_THEME_SCROLLBAR_BUTTON_RIGHT: {
194 QStyleOptionSlider opt;
195 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt, QStyle::State_Horizontal);
196 opt.orientation = Qt::Horizontal;
197 style->drawControl(QStyle::CE_ScrollBarAddLine, &opt, qPainter, NULL);
198 break;
200 case NS_THEME_SCROLLBAR_BUTTON_UP: {
201 QStyleOptionSlider opt;
202 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt);
203 opt.orientation = Qt::Vertical;
204 style->drawControl(QStyle::CE_ScrollBarSubLine, &opt, qPainter, NULL);
205 break;
207 case NS_THEME_SCROLLBAR_BUTTON_DOWN: {
208 QStyleOptionSlider opt;
209 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)opt);
210 opt.orientation = Qt::Vertical;
211 style->drawControl(QStyle::CE_ScrollBarAddLine, &opt, qPainter, NULL);
212 break;
214 case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: {
215 extraFlags |= QStyle::State_Horizontal;
216 QStyleOptionSlider option;
217 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)option, extraFlags);
218 option.orientation = Qt::Horizontal;
219 style->drawControl(QStyle::CE_ScrollBarSlider, &option, qPainter, NULL);
220 break;
222 case NS_THEME_SCROLLBAR_THUMB_VERTICAL: {
223 QStyleOptionSlider option;
224 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)option, extraFlags);
225 option.orientation = Qt::Vertical;
226 style->drawControl(QStyle::CE_ScrollBarSlider, &option, qPainter, NULL);
227 break;
229 case NS_THEME_DROPDOWN: {
230 QStyleOptionComboBox comboOpt;
232 InitComboStyle(aWidgetType, aFrame, r, comboOpt);
234 style->drawComplexControl(QStyle::CC_ComboBox, &comboOpt, qPainter);
235 break;
237 case NS_THEME_DROPDOWN_BUTTON: {
238 QStyleOptionComboBox option;
240 InitComboStyle(aWidgetType, aFrame, r, option);
242 style->drawPrimitive(QStyle::PE_FrameDefaultButton, &option, qPainter);
243 style->drawPrimitive(QStyle::PE_IndicatorSpinDown, &option, qPainter);
244 break;
246 case NS_THEME_DROPDOWN_TEXT:
247 case NS_THEME_DROPDOWN_TEXTFIELD:
248 case NS_THEME_TEXTFIELD:
249 case NS_THEME_TEXTFIELD_MULTILINE:
250 case NS_THEME_LISTBOX: {
251 QStyleOptionFrameV2 frameOpt;
253 if (!IsDisabled(aFrame))
254 frameOpt.state |= QStyle::State_Enabled;
256 frameOpt.rect = r;
257 frameOpt.features = QStyleOptionFrameV2::Flat;
259 if (aWidgetType == NS_THEME_TEXTFIELD || aWidgetType == NS_THEME_TEXTFIELD_MULTILINE) {
260 QRect contentRect = style->subElementRect(QStyle::SE_LineEditContents, &frameOpt);
261 contentRect.adjust(mFrameWidth, mFrameWidth, -mFrameWidth, -mFrameWidth);
262 qPainter->fillRect(contentRect, QBrush(Qt::white));
265 frameOpt.palette = mNoBackgroundPalette;
266 style->drawPrimitive(QStyle::PE_FrameLineEdit, &frameOpt, qPainter, NULL);
267 break;
269 case NS_THEME_MENUPOPUP: {
270 QStyleOptionMenuItem option;
271 InitPlainStyle(aWidgetType, aFrame, r, (QStyleOption&)option, extraFlags);
272 style->drawPrimitive(QStyle::PE_FrameMenu, &option, qPainter, NULL);
273 break;
275 default:
276 break;
279 qPainter->restore();
280 return NS_OK;
283 NS_IMETHODIMP
284 nsNativeThemeQt::GetWidgetBorder(nsIDeviceContext* aContext,
285 nsIFrame* aFrame,
286 PRUint8 aWidgetType,
287 nsMargin* aResult)
289 (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = 0;
291 QStyle* style = qApp->style();
292 switch(aWidgetType) {
293 // case NS_THEME_TEXTFIELD:
294 // case NS_THEME_LISTBOX:
295 case NS_THEME_MENUPOPUP: {
296 (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = style->pixelMetric(QStyle::PM_MenuPanelWidth);
297 break;
299 default:
300 break;
303 return NS_OK;
306 PRBool
307 nsNativeThemeQt::GetWidgetPadding(nsIDeviceContext* ,
308 nsIFrame*, PRUint8 aWidgetType,
309 nsMargin* aResult)
311 // XXX: Where to get padding values, framewidth?
312 if (aWidgetType == NS_THEME_TEXTFIELD ||
313 aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
314 aWidgetType == NS_THEME_DROPDOWN) {
315 aResult->SizeTo(2, 2, 2, 2);
316 return PR_TRUE;
319 return PR_FALSE;
322 NS_IMETHODIMP
323 nsNativeThemeQt::GetMinimumWidgetSize(nsIRenderingContext* aContext, nsIFrame* aFrame,
324 PRUint8 aWidgetType,
325 nsSize* aResult, PRBool* aIsOverridable)
327 (*aResult).width = (*aResult).height = 0;
328 *aIsOverridable = PR_TRUE;
330 QStyle *s = qApp->style();
332 PRInt32 p2a = GetAppUnitsPerDevPixel(aContext);
334 switch (aWidgetType) {
335 case NS_THEME_RADIO_SMALL:
336 case NS_THEME_RADIO:
337 case NS_THEME_CHECKBOX_SMALL:
338 case NS_THEME_CHECKBOX: {
339 nsRect frameRect = aFrame->GetRect();
341 QRect qRect = qRectInPixels(frameRect, p2a);
343 QStyleOptionButton option;
345 InitButtonStyle(aWidgetType, aFrame, qRect, option);
347 QRect rect = s->subElementRect(
348 (aWidgetType == NS_THEME_CHECKBOX || aWidgetType == NS_THEME_CHECKBOX_SMALL ) ?
349 QStyle::SE_CheckBoxIndicator :
350 QStyle::SE_RadioButtonIndicator,
351 &option,
352 NULL);
354 (*aResult).width = rect.width();
355 (*aResult).height = rect.height();
356 break;
358 case NS_THEME_BUTTON: {
359 nsRect frameRect = aFrame->GetRect();
361 QRect qRect = qRectInPixels(frameRect, p2a);
363 QStyleOptionButton option;
365 InitButtonStyle(aWidgetType, aFrame, qRect, option);
367 QRect rect = s->subElementRect(
368 QStyle::SE_PushButtonFocusRect,
369 &option,
370 NULL);
372 (*aResult).width = rect.width();
373 (*aResult).height = rect.height();
374 break;
376 case NS_THEME_SCROLLBAR_BUTTON_UP:
377 case NS_THEME_SCROLLBAR_BUTTON_DOWN: {
378 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarExtent);
379 (*aResult).height = (*aResult).width;
380 //*aIsOverridable = PR_FALSE;
381 break;
383 case NS_THEME_SCROLLBAR_BUTTON_LEFT:
384 case NS_THEME_SCROLLBAR_BUTTON_RIGHT: {
385 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarExtent);
386 (*aResult).width = (*aResult).height;
387 //*aIsOverridable = PR_FALSE;
388 break;
390 case NS_THEME_SCROLLBAR_THUMB_VERTICAL: {
391 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarExtent);
392 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarSliderMin);
393 //*aIsOverridable = PR_FALSE;
394 break;
396 case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: {
397 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarSliderMin);
398 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarExtent);
399 //*aIsOverridable = PR_FALSE;
400 break;
402 case NS_THEME_SCROLLBAR_TRACK_VERTICAL: {
403 (*aResult).width = s->pixelMetric(QStyle::PM_ScrollBarExtent);
404 (*aResult).height = s->pixelMetric(QStyle::PM_SliderLength);
405 break;
407 case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: {
408 (*aResult).width = s->pixelMetric(QStyle::PM_SliderLength);
409 (*aResult).height = s->pixelMetric(QStyle::PM_ScrollBarExtent);
410 break;
412 case NS_THEME_DROPDOWN_BUTTON: {
413 QStyleOptionComboBox comboOpt;
415 nsRect frameRect = aFrame->GetRect();
416 QRect qRect = qRectInPixels(frameRect, p2a);
417 comboOpt.rect = qRect;
419 InitComboStyle(aWidgetType, aFrame, qRect, comboOpt);
421 QRect subRect = s->subControlRect(QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxArrow, NULL);
423 (*aResult).width = subRect.width();
424 (*aResult).height = subRect.height();
425 //*aIsOverridable = PR_FALSE;
426 break;
428 case NS_THEME_DROPDOWN: {
429 QStyleOptionComboBox comboOpt;
431 nsRect frameRect = aFrame->GetRect();
432 QRect qRect = qRectInPixels(frameRect, p2a);
433 comboOpt.rect = qRect;
435 InitComboStyle(aWidgetType, aFrame, qRect, comboOpt);
437 QRect subRect = s->subControlRect(QStyle::CC_ComboBox,
438 &comboOpt,
439 QStyle::SC_ComboBoxFrame,
440 NULL);
442 (*aResult).width = subRect.width();
443 (*aResult).height = subRect.height();
444 //*aIsOverridable = PR_FALSE;
445 break;
447 case NS_THEME_DROPDOWN_TEXT: {
448 QStyleOptionComboBox comboOpt;
450 nsRect frameRect = aFrame->GetRect();
452 QRect qRect = qRectInPixels(frameRect, p2a);
454 comboOpt.rect = qRect;
456 QRect subRect = s->subControlRect(QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxEditField, NULL);
458 (*aResult).width = subRect.width();
459 (*aResult).height = subRect.height();
460 //*aIsOverridable = PR_FALSE;
461 break;
463 case NS_THEME_DROPDOWN_TEXTFIELD: {
464 QStyleOptionComboBox comboOpt;
466 nsRect frameRect = aFrame->GetRect();
468 QRect qRect = qRectInPixels(frameRect, p2a);
470 comboOpt.rect = qRect;
472 QRect subRect = s->subControlRect(QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxArrow, NULL);
473 QRect subRect2 = s->subControlRect(QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxFrame, NULL);
475 (*aResult).width = subRect.width() + subRect2.width();
476 (*aResult).height = std::max(subRect.height(), subRect2.height());
477 //*aIsOverridable = PR_FALSE;
478 break;
480 case NS_THEME_TEXTFIELD:
481 case NS_THEME_TEXTFIELD_MULTILINE:
482 break;
484 return NS_OK;
487 NS_IMETHODIMP
488 nsNativeThemeQt::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
489 nsIAtom* aAttribute, PRBool* aShouldRepaint)
491 *aShouldRepaint = TRUE;
492 return NS_OK;
496 NS_IMETHODIMP
497 nsNativeThemeQt::ThemeChanged()
499 QStyle *s = qApp->style();
500 if (s)
501 mFrameWidth = s->pixelMetric(QStyle::PM_DefaultFrameWidth);
502 return NS_OK;
505 PRBool
506 nsNativeThemeQt::ThemeSupportsWidget(nsPresContext* aPresContext,
507 nsIFrame* aFrame,
508 PRUint8 aWidgetType)
510 switch (aWidgetType) {
511 case NS_THEME_SCROLLBAR:
512 case NS_THEME_SCROLLBAR_BUTTON_UP:
513 case NS_THEME_SCROLLBAR_BUTTON_DOWN:
514 case NS_THEME_SCROLLBAR_BUTTON_LEFT:
515 case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
516 case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
517 case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
518 //case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL:
519 //case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL:
520 case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
521 case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
522 case NS_THEME_RADIO:
523 case NS_THEME_RADIO_SMALL:
524 case NS_THEME_CHECKBOX:
525 case NS_THEME_CHECKBOX_SMALL:
526 case NS_THEME_BUTTON_BEVEL:
527 case NS_THEME_BUTTON:
528 case NS_THEME_DROPDOWN:
529 case NS_THEME_DROPDOWN_BUTTON:
530 case NS_THEME_DROPDOWN_TEXT:
531 case NS_THEME_DROPDOWN_TEXTFIELD:
532 case NS_THEME_TEXTFIELD:
533 case NS_THEME_TEXTFIELD_MULTILINE:
534 case NS_THEME_LISTBOX:
535 case NS_THEME_MENUPOPUP:
536 return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
537 default:
538 break;
540 return PR_FALSE;
543 PRBool
544 nsNativeThemeQt::WidgetIsContainer(PRUint8 aWidgetType)
546 // if (aWidgetType == NS_THEME_DROPDOWN_BUTTON ||
547 // aWidgetType == NS_THEME_RADIO ||
548 // aWidgetType == NS_THEME_CHECKBOX) {
549 // return PR_FALSE;
550 // }
552 return PR_TRUE;
555 PRBool
556 nsNativeThemeQt::ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType)
558 if (aWidgetType == NS_THEME_DROPDOWN ||
559 aWidgetType == NS_THEME_BUTTON ||
560 aWidgetType == NS_THEME_TREEVIEW_HEADER_CELL) {
561 return PR_TRUE;
564 return PR_FALSE;
567 PRBool
568 nsNativeThemeQt::ThemeNeedsComboboxDropmarker()
570 return PR_TRUE;
573 void
574 nsNativeThemeQt::InitButtonStyle(PRUint8 aWidgetType,
575 nsIFrame* aFrame,
576 QRect rect,
577 QStyleOptionButton &opt)
579 PRInt32 eventState = GetContentState(aFrame, aWidgetType);
581 opt.rect = rect;
582 opt.palette = mNoBackgroundPalette;
584 PRBool disabled = IsDisabled(aFrame);
586 if (!disabled)
587 opt.state |= QStyle::State_Enabled;
588 if (eventState & NS_EVENT_STATE_HOVER)
589 opt.state |= QStyle::State_MouseOver;
590 if (eventState & NS_EVENT_STATE_FOCUS)
591 opt.state |= QStyle::State_HasFocus;
592 if (!disabled && eventState & NS_EVENT_STATE_ACTIVE)
593 // Don't allow sunken when disabled
594 opt.state |= QStyle::State_Sunken;
596 switch (aWidgetType) {
597 case NS_THEME_RADIO:
598 case NS_THEME_RADIO_SMALL:
599 case NS_THEME_CHECKBOX:
600 case NS_THEME_CHECKBOX_SMALL:
601 if (IsChecked(aFrame))
602 opt.state |= QStyle::State_On;
603 else
604 opt.state |= QStyle::State_Off;
606 break;
607 default:
608 if (!(eventState & NS_EVENT_STATE_ACTIVE))
609 opt.state |= QStyle::State_Raised;
610 break;
614 void
615 nsNativeThemeQt::InitPlainStyle(PRUint8 aWidgetType,
616 nsIFrame* aFrame,
617 QRect rect,
618 QStyleOption &opt,
619 QStyle::State extraFlags)
621 PRInt32 eventState = GetContentState(aFrame, aWidgetType);
623 opt.rect = rect;
625 if (!IsDisabled(aFrame))
626 opt.state |= QStyle::State_Enabled;
627 if (eventState & NS_EVENT_STATE_HOVER)
628 opt.state |= QStyle::State_MouseOver;
629 if (eventState & NS_EVENT_STATE_FOCUS)
630 opt.state |= QStyle::State_HasFocus;
632 opt.state |= extraFlags;
635 void
636 nsNativeThemeQt::InitComboStyle(PRUint8 aWidgetType,
637 nsIFrame* aFrame,
638 QRect rect,
639 QStyleOptionComboBox &opt)
641 PRInt32 eventState = GetContentState(aFrame, aWidgetType);
643 PRBool disabled = IsDisabled(aFrame);
645 if (!disabled)
646 opt.state |= QStyle::State_Enabled;
647 if (eventState & NS_EVENT_STATE_HOVER)
648 opt.state |= QStyle::State_MouseOver;
649 if (eventState & NS_EVENT_STATE_FOCUS)
650 opt.state |= QStyle::State_HasFocus;
651 if (!(eventState & NS_EVENT_STATE_ACTIVE))
652 opt.state |= QStyle::State_Raised;
653 if (!disabled && eventState & NS_EVENT_STATE_ACTIVE)
654 // Don't allow sunken when disabled
655 opt.state |= QStyle::State_Sunken;
657 opt.rect = rect;
658 opt.palette = mNoBackgroundPalette;