Updates to nsNativeThemeQt - draws radio buttons
authorpekka.vanhoja
Sat, 19 Apr 2008 18:44:07 +0300
changeset 16850 d856e0b615d894876bb06da94d2a661ac220444c
parent 16849 42714c5f6dd2b4e2a4c47e65e08c0ae135cf534d
child 16851 3563acec1d3532ed2a805452ccca813c1a70ce58
push id1298
push userpavlov@mozilla.com
push dateSun, 17 Aug 2008 05:03:09 +0000
treeherderautoland@4a506fa751d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0a1pre
Updates to nsNativeThemeQt - draws radio buttons
widget/src/qt/nsNativeThemeQt.cpp
widget/src/qt/nsNativeThemeQt.h
widget/src/qt/nsWidgetFactory.cpp
--- a/widget/src/qt/nsNativeThemeQt.cpp
+++ b/widget/src/qt/nsNativeThemeQt.cpp
@@ -32,47 +32,50 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "nsIFrame.h"
+
 #include <QApplication>
 #include <QStyle>
 #include <QPalette>
 #include <QComboBox>
 #include <QRect>
 #include <QPainter>
 #include <QStyleOption>
 #include <QStyleOptionFrameV2>
 #include <QStyleOptionButton>
 #include <QFlags>
 
 #include "nsCoord.h"
 #include "nsNativeThemeQt.h"
 #include "nsIDeviceContext.h"
 
+
 #include "nsRect.h"
 #include "nsSize.h"
 #include "nsTransform2D.h"
 #include "nsThemeConstants.h"
 #include "nsILookAndFeel.h"
 #include "nsIServiceManager.h"
 #include "nsIEventStateManager.h"
 #include <malloc.h>
 
 
 #include "gfxASurface.h"
 #include "gfxContext.h"
 #include "gfxQPainterSurface.h"
 #include "nsIRenderingContext.h"
 
-nsNativeThemeQt::nsNativeThemeQt()
+nsNativeThemeQt::nsNativeThemeQt() : mP2A(0)
 {
     combo = new QComboBox((QWidget *)0);
     combo->resize(0, 0);
     ThemeChanged();
 }
 
 nsNativeThemeQt::~nsNativeThemeQt()
 {
@@ -110,28 +113,27 @@ nsNativeThemeQt::DrawWidgetBackground(ns
     gfxASurface* raw = surface;
     gfxQPainterSurface* qsurface = (gfxQPainterSurface*)raw;
     QPainter* qpainter = qsurface->GetQPainter();
 
 //     qDebug("aWidgetType = %d", aWidgetType);
     if (!qpainter)
         return NS_OK;
 
-    nsCOMPtr<nsIDeviceContext> dctx = nsnull;
-    aContext->GetDeviceContext(*getter_AddRefs(dctx));
-    PRInt32 p2a = dctx->AppUnitsPerDevPixel();
+    EnsuremP2A(aContext);
 
     QStyle* style = qApp->style();
 //    const QPalette::ColorGroup cg = qApp->palette().currentColorGroup();
 
     nsTransform2D* curTrans;
     aContext->GetCurrentTransform(curTrans);
 
-    QRect r = qRectInPixels(aRect, curTrans, p2a);
-    QRect cr = qRectInPixels(aClipRect, curTrans, p2a);
+    QRect r = qRectInPixels(aRect, curTrans, mP2A);
+    QRect cr = qRectInPixels(aClipRect, curTrans, mP2A);
+
 //    context->UpdateGC();
     qpainter->save();
     qpainter->translate(r.x(), r.y());
     r.translate(-r.x(), -r.y());
 
 //     qDebug("rect=%d %d %d %d\nr=%d %d %d %d",
 //         aRect.x, aRect.y, aRect.width, aRect.height,
 //         r.x(), r.y(), r.width(), r.height());
@@ -333,17 +335,52 @@ nsNativeThemeQt::GetMinimumWidgetSize(ns
 //    qDebug("%s", __PRETTY_FUNCTION__);
 
     (*aResult).width = (*aResult).height = 0;
     *aIsOverridable = PR_TRUE;
 
     QStyle *s = qApp->style();
 
     switch (aWidgetType) {
-    case NS_THEME_RADIO:
+    case NS_THEME_RADIO_SMALL:
+    case NS_THEME_RADIO: {
+        nsRect frameRect = aFrame->GetRect();
+
+        EnsuremP2A(aContext);
+
+        nsTransform2D* curTrans;
+        aContext->GetCurrentTransform(curTrans);
+
+        QRect qRect = qRectInPixels(frameRect, curTrans, mP2A);
+
+        QStyleOptionButton option;
+
+        ButtonStyle(aFrame, qRect, &option);
+/*
+        QStyle::State flags = IsDisabled(aFrame) ?
+                            QStyle::State_None :
+                            QStyle::State_Enabled;
+
+        flags |= IsChecked(aFrame) ? QStyle::State_On : QStyle::State_Off;
+
+        QStyleOptionButton option;
+        option.direction = QApplication::layoutDirection();
+        option.rect = qrect;
+        option.type = QStyleOption::SO_Button;
+        option.state = flags;
+        option.features = QStyleOptionButton::None;
+*/
+        QRect rect = s->subElementRect(
+            QStyle::SE_RadioButtonIndicator,
+            &option, NULL);
+
+        (*aResult).width = rect.width();
+        (*aResult).height = rect.height();
+        break;
+    }
     case NS_THEME_CHECKBOX: {
         QRect rect = s->subElementRect(aWidgetType == NS_THEME_CHECKBOX
                                ? QStyle::SE_CheckBoxIndicator
                                : QStyle::SE_RadioButtonIndicator,
                                0);
 
         (*aResult).width = rect.width();
         (*aResult).height = rect.height();
@@ -424,16 +461,17 @@ nsNativeThemeQt::ThemeSupportsWidget(nsP
     //case NS_THEME_SCROLLBAR_BUTTON_RIGHT:
     //case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL:
     //case NS_THEME_SCROLLBAR_THUMB_VERTICAL:
     //case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL:
     //case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL:
     //case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL:
     //case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
     case NS_THEME_RADIO:
+    case NS_THEME_RADIO_SMALL:
     case NS_THEME_CHECKBOX:
     case NS_THEME_BUTTON_BEVEL:
     case NS_THEME_BUTTON:
     //case NS_THEME_DROPDOWN:
     //case NS_THEME_DROPDOWN_BUTTON:
     //case NS_THEME_DROPDOWN_TEXT:
     //case NS_THEME_DROPDOWN_TEXTFIELD:
     case NS_THEME_TEXTFIELD:
@@ -481,8 +519,36 @@ nsNativeThemeQt::ThemeDrawsFocusForWidge
 }
 
 PRBool
 nsNativeThemeQt::ThemeNeedsComboboxDropmarker()
 {
 //    qDebug("%s", __PRETTY_FUNCTION__);
     return PR_FALSE;
 }
+
+void
+nsNativeThemeQt::EnsuremP2A(nsIRenderingContext* aContext)
+{
+    if (!mP2A) {
+        nsCOMPtr<nsIDeviceContext> dctx = nsnull;
+        aContext->GetDeviceContext(*getter_AddRefs(dctx));
+        mP2A = dctx->AppUnitsPerDevPixel();
+    }
+}
+
+void
+nsNativeThemeQt::ButtonStyle(nsIFrame* aFrame, QRect aRect, QStyleOptionButton* aOption)
+{
+    QStyle::State flags = IsDisabled(aFrame) ?
+        QStyle::State_None :
+        QStyle::State_Enabled;
+
+    flags |= IsChecked(aFrame) ?
+        QStyle::State_On :
+        QStyle::State_Off;
+
+    (*aOption).direction = QApplication::layoutDirection();
+    (*aOption).rect = aRect;
+    (*aOption).type = QStyleOption::SO_Button;
+    (*aOption).state = flags;
+    (*aOption).features = QStyleOptionButton::None;
+}
--- a/widget/src/qt/nsNativeThemeQt.h
+++ b/widget/src/qt/nsNativeThemeQt.h
@@ -40,16 +40,19 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsITheme.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
 #include "nsNativeTheme.h"
 
 class QComboBox;
+class QStyleOptionButton;
+class QRect;
+class nsIFrame;
 
 class nsNativeThemeQt : private nsNativeTheme,
                         public nsITheme
 {
 public:
   NS_DECL_ISUPPORTS
 
   // The nsITheme interface.
@@ -89,12 +92,22 @@ public:
                                                nsIFrame* aFrame, PRUint8 aWidgetType);
 
   PRBool ThemeNeedsComboboxDropmarker();
 
   nsNativeThemeQt();
   virtual ~nsNativeThemeQt();
 
 private:
+
+  void EnsuremP2A(nsIRenderingContext* aContext);
+
+  void ButtonStyle(nsIFrame* aFrame, QRect aRect, QStyleOptionButton* aOption);
+
+private:
+
   QComboBox *combo;
-  int frameWidth;
+
+  PRInt32 frameWidth;
+
+  PRInt32 mP2A;
 };
 
--- a/widget/src/qt/nsWidgetFactory.cpp
+++ b/widget/src/qt/nsWidgetFactory.cpp
@@ -160,22 +160,21 @@ static const nsModuleComponentInfo compo
       nsBidiKeyboardConstructor },
     { "Qt Idle Service",
        NS_IDLE_SERVICE_CID,
        "@mozilla.org/widget/idleservice;1",
        nsIdleServiceQtConstructor },
     { "Qt Sound",
       NS_SOUND_CID,
       "@mozilla.org/sound;1",
-      nsSoundConstructor }/*,
+      nsSoundConstructor },
     { "Native Theme Renderer",
       NS_THEMERENDERER_CID,
       "@mozilla.org/chrome/chrome-native-theme;1",
       nsNativeThemeQtConstructor }
-*/
 /*    
     { "Qt File Picker",
       NS_FILEPICKER_CID,
       "@mozilla.org/filepicker;1",
       nsFilePickerConstructor },
 */
 };