Back to index

lightning-sunbird  0.9+nobinonly
nsNativeTheme.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Brian Ryner <bryner@brianryner.com>  (Original Author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 // This defines a common base class for nsITheme implementations, to reduce
00040 // code duplication.
00041 
00042 #include "prtypes.h"
00043 #include "nsIAtom.h"
00044 #include "nsCOMPtr.h"
00045 #include "nsString.h"
00046 #include "nsMargin.h"
00047 #include "nsILookAndFeel.h"
00048 
00049 class nsIFrame;
00050 class nsIPresShell;
00051 class nsPresContext;
00052 
00053 class nsNativeTheme
00054 {
00055  protected:
00056 
00057   enum TreeSortDirection {
00058     eTreeSortDirection_Descending,
00059     eTreeSortDirection_Natural,
00060     eTreeSortDirection_Ascending
00061   };
00062 
00063   nsNativeTheme();
00064 
00065   // Returns the content state (hover, focus, etc), see nsIEventStateManager.h
00066   PRInt32 GetContentState(nsIFrame* aFrame, PRUint8 aWidgetType);
00067 
00068   // Returns whether the widget is already styled by content
00069   // Normally called from ThemeSupportsWidget to turn off native theming
00070   // for elements that are already styled.
00071   PRBool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
00072                         PRUint8 aWidgetType);                                              
00073 
00074   // Accessors to widget-specific state information
00075 
00076   // all widgets:
00077   PRBool IsDisabled(nsIFrame* aFrame) {
00078     return CheckBooleanAttr(aFrame, mDisabledAtom);
00079   }
00080 
00081   // button:
00082   PRBool IsDefaultButton(nsIFrame* aFrame) {
00083     return CheckBooleanAttr(aFrame, mDefaultAtom);
00084   }
00085 
00086   // checkbox:
00087   PRBool IsChecked(nsIFrame* aFrame) {
00088     return GetCheckedOrSelected(aFrame, PR_FALSE);
00089   }
00090 
00091   // radiobutton:
00092   PRBool IsSelected(nsIFrame* aFrame) {
00093     return GetCheckedOrSelected(aFrame, PR_TRUE);
00094   }
00095   
00096   PRBool IsFocused(nsIFrame* aFrame) {
00097     return CheckBooleanAttr(aFrame, mFocusedAtom);
00098   }
00099 
00100   // tab:
00101   PRBool IsSelectedTab(nsIFrame* aFrame) {
00102     return CheckBooleanAttr(aFrame, mSelectedAtom);
00103   }
00104 
00105   // toolbarbutton:
00106   PRBool IsCheckedButton(nsIFrame* aFrame) {
00107     return CheckBooleanAttr(aFrame, mCheckedAtom);
00108   }
00109   
00110   // treeheadercell:
00111   TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame) {
00112     nsAutoString sortdir;
00113     if (GetAttr(aFrame, mSortDirectionAtom, sortdir)) {
00114       if (sortdir.EqualsLiteral("descending"))
00115         return eTreeSortDirection_Descending;
00116       else if (sortdir.EqualsLiteral("ascending"))
00117         return eTreeSortDirection_Ascending;
00118     }
00119 
00120     return eTreeSortDirection_Natural;
00121   }
00122 
00123   // tab:
00124   PRBool IsBottomTab(nsIFrame* aFrame) {
00125     nsAutoString classStr;
00126     if (GetAttr(aFrame, mClassAtom, classStr))
00127       return classStr.Find("tab-bottom") != kNotFound;
00128     return PR_FALSE;
00129   }
00130 
00131   // progressbar:
00132   PRBool IsIndeterminateProgress(nsIFrame* aFrame) {
00133     nsAutoString mode;
00134     if (GetAttr(aFrame, mModeAtom, mode))
00135       return mode.EqualsLiteral("undetermined");
00136     return PR_FALSE;
00137   }
00138 
00139   PRInt32 GetProgressValue(nsIFrame* aFrame) {
00140     return CheckIntAttr(aFrame, mValueAtom);
00141   }
00142 
00143   // textfield:
00144   PRBool IsReadOnly(nsIFrame* aFrame) {
00145       return CheckBooleanAttr(aFrame, mReadOnlyAtom);
00146   }
00147 
00148   // These are used by nsNativeThemeGtk
00149   nsIPresShell *GetPresShell(nsIFrame* aFrame);
00150   PRInt32 CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom);
00151   PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
00152 
00153 private:
00154   PRBool GetAttr(nsIFrame* aFrame, nsIAtom* aAtom, nsAString& attrValue);
00155   PRBool GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected);
00156 
00157 protected:
00158   // these are available to subclasses because they are useful in
00159   // implementing WidgetStateChanged()
00160   nsCOMPtr<nsIAtom> mDisabledAtom;
00161   nsCOMPtr<nsIAtom> mCheckedAtom;
00162   nsCOMPtr<nsIAtom> mSelectedAtom;
00163   nsCOMPtr<nsIAtom> mReadOnlyAtom;
00164   nsCOMPtr<nsIAtom> mFirstTabAtom;
00165   nsCOMPtr<nsIAtom> mFocusedAtom;
00166   nsCOMPtr<nsIAtom> mSortDirectionAtom;
00167 
00168   // these should be set to appropriate platform values by the subclass, to
00169   // match the values in forms.css.  These defaults match forms.css
00170   static nsMargin                  sButtonBorderSize;
00171   static nsMargin                  sButtonDisabledBorderSize;
00172   static PRUint8                   sButtonActiveBorderStyle;
00173   static PRUint8                   sButtonInactiveBorderStyle;
00174   static nsILookAndFeel::nsColorID sButtonBorderColorID;
00175   static nsILookAndFeel::nsColorID sButtonDisabledBorderColorID;
00176   static nsILookAndFeel::nsColorID sButtonBGColorID;
00177   static nsILookAndFeel::nsColorID sButtonDisabledBGColorID;
00178   static nsMargin                  sTextfieldBorderSize;
00179   static PRUint8                   sTextfieldBorderStyle;
00180   static nsILookAndFeel::nsColorID sTextfieldBorderColorID;
00181   static PRBool                    sTextfieldBGTransparent;
00182   static nsILookAndFeel::nsColorID sTextfieldBGColorID;
00183   static nsILookAndFeel::nsColorID sTextfieldDisabledBGColorID;
00184   static nsMargin                  sListboxBorderSize;
00185   static PRUint8                   sListboxBorderStyle;
00186   static nsILookAndFeel::nsColorID sListboxBorderColorID;
00187   static PRBool                    sListboxBGTransparent;
00188   static nsILookAndFeel::nsColorID sListboxBGColorID;
00189   static nsILookAndFeel::nsColorID sListboxDisabledBGColorID;
00190 
00191 private:
00192   nsCOMPtr<nsIAtom> mDefaultAtom;
00193   nsCOMPtr<nsIAtom> mValueAtom;
00194   nsCOMPtr<nsIAtom> mModeAtom;
00195   nsCOMPtr<nsIAtom> mClassAtom;
00196 };