Back to index

lightning-sunbird  0.9+nobinonly
nsLookAndFeel.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsLookAndFeel.h"
00039 #include "nsWidget.h"
00040 
00041 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
00042 {
00043     PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::nsLookAndFeel()\n"));
00044 }
00045 
00046 nsLookAndFeel::~nsLookAndFeel()
00047 {
00048     PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::~nsLookAndFeel()\n"));
00049 }
00050 
00051 nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor)
00052 {
00053     PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::NativeGetColor()\n"));
00054     nsresult res = NS_OK;
00055 
00056     aColor = 0;
00057     switch (aID) {
00058     case eColor_WindowBackground:
00059         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00060         break;
00061     case eColor_WindowForeground:
00062         aColor = NS_RGB(0x00, 0x00, 0x00);
00063         break;
00064     case eColor_WidgetBackground:
00065         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00066         break;
00067     case eColor_WidgetForeground:
00068         aColor = NS_RGB(0x00, 0x00, 0x00);
00069         break;
00070     case eColor_WidgetSelectBackground:
00071         aColor = NS_RGB(0x00, 0x00, 0x9c);
00072         break;
00073     case eColor_WidgetSelectForeground:
00074         aColor = NS_RGB(0xff, 0xff, 0xff);
00075         break;
00076     case eColor_Widget3DHighlight:
00077         aColor = NS_RGB(0x99,0x99,0x99);
00078         break;
00079     case eColor_Widget3DShadow:
00080         aColor = NS_RGB(0x40,0x40,0x40);
00081         break;
00082     case eColor_TextBackground:
00083         aColor = NS_RGB(0xff, 0xff, 0xff);
00084         break;
00085     case eColor_TextForeground:
00086         aColor = NS_RGB(0x00, 0x00, 0x00);
00087         break;
00088     case eColor_TextSelectBackground:
00089         aColor = NS_RGB(0x00, 0x00, 0x9c);
00090         break;
00091     case eColor_TextSelectForeground:
00092         aColor = NS_RGB(0xff, 0xff, 0xff);
00093         break;
00094 
00095         // css2  http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
00096     case eColor_activeborder:
00097         aColor = NS_RGB(0x00, 0x00, 0x00);
00098         break;
00099     case eColor_activecaption:
00100         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00101         break;
00102     case eColor_appworkspace:
00103         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00104         break;
00105     case eColor_background:
00106         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00107         break;
00108 
00109     case eColor_captiontext:
00110         aColor = NS_RGB(0x00, 0x00, 0x00);
00111         break;
00112     case eColor_graytext:
00113         aColor = NS_RGB(0x80, 0x80, 0x80);
00114         break;
00115     case eColor_highlight:
00116     case eColor__moz_menuhover:
00117         aColor = NS_RGB(0x00, 0x00, 0x9c);
00118         break;
00119     case eColor_highlighttext:
00120     case eColor__moz_menuhovertext:
00121         aColor = NS_RGB(0xff, 0xff, 0xff);
00122         break;
00123     case eColor_inactiveborder:
00124         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00125         break;
00126     case eColor_inactivecaption:
00127         aColor = NS_RGB(0x80, 0x80, 0x80);
00128         break;
00129     case eColor_inactivecaptiontext:
00130         aColor = NS_RGB(0xff, 0xff, 0xff);
00131         break;
00132     case eColor_infobackground:
00133         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00134         break;
00135     case eColor_infotext:
00136         aColor = NS_RGB(0x00, 0x00, 0x00);
00137         break;
00138     case eColor_menu:
00139         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00140         break;
00141     case eColor_menutext:
00142         aColor = NS_RGB(0x00, 0x00, 0x00);
00143         break;
00144     case eColor_scrollbar:
00145         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00146         break;
00147 
00148     case eColor_threedface:
00149           // 3-D face color
00150     case eColor_buttonface:
00151     case eColor__moz_buttonhoverface:
00152           // 3-D face color
00153     case eColor_threedlightshadow:
00154           // 3-D inner highlight color
00155         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00156         break;
00157 
00158     case eColor_buttonhighlight:
00159           // 3-D highlight color
00160     case eColor_threedhighlight:
00161           // 3-D outer highlight color
00162         aColor = NS_RGB(0xff, 0xff, 0xff);
00163         break;
00164 
00165     case eColor_buttontext:
00166     case eColor__moz_buttonhovertext:
00167         aColor = NS_RGB(0x00, 0x00, 0x00);
00168         break;
00169 
00170     case eColor_buttonshadow:
00171           // 3-D shadow color
00172     case eColor_threedshadow:
00173           // 3-D inner shadow color
00174         aColor = NS_RGB(0x66, 0x66, 0x66);
00175         break;
00176 
00177     case eColor_threeddarkshadow:
00178           // 3-D outer shadow color
00179         aColor = NS_RGB(0x00, 0x00, 0x00);
00180         break;
00181 
00182     case eColor_window:
00183     case eColor_windowframe:
00184         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00185         break;
00186 
00187     case eColor_windowtext:
00188         aColor = NS_RGB(0x00, 0x00, 0x00);
00189         break;
00190 
00191     case eColor__moz_field:
00192         aColor = NS_RGB(0xff, 0xff, 0xff);
00193         break;
00194     case eColor__moz_fieldtext:
00195         aColor = NS_RGB(0x00, 0x00, 0x00);
00196         break;
00197     case eColor__moz_dialog:
00198     case eColor__moz_cellhighlight:
00199         aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00200         break;
00201     case eColor__moz_dialogtext:
00202     case eColor__moz_cellhighlighttext:
00203         aColor = NS_RGB(0x00, 0x00, 0x00);
00204         break;
00205 
00206     case eColor__moz_buttondefault:
00207           // default button border color
00208         aColor = NS_RGB(0x00, 0x00, 0x00);
00209         break;
00210 
00211     default:
00212         /* default color is BLACK */
00213         aColor = 0;
00214         res    = NS_ERROR_FAILURE;
00215         break;
00216     }
00217     return NS_OK;
00218 }
00219 
00220 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
00221 {
00222     PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric()\n"));
00223     // XXX These are not complete!
00224     nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00225     if (NS_SUCCEEDED(res))
00226         return res;
00227     res = NS_OK;
00228 
00229     switch (aID) { 
00230     case eMetric_WindowTitleHeight:
00231         aMetric = 20;
00232         break;
00233     case eMetric_WindowBorderWidth:
00234         aMetric = 1;
00235         break;
00236     case eMetric_WindowBorderHeight:
00237         aMetric = 1;
00238         break;
00239     case eMetric_Widget3DBorder:
00240         aMetric = 1;
00241         break;
00242     case eMetric_TextFieldHeight:
00243         aMetric = 24;
00244         break;
00245     case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
00246         aMetric = 10;
00247         break;
00248     case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
00249         aMetric = 8;
00250         break;
00251     case eMetric_CheckboxSize:
00252         aMetric = 15;
00253         break;
00254     case eMetric_RadioboxSize:
00255         aMetric = 15;
00256         break;
00257     case eMetric_TextHorizontalInsideMinimumPadding:
00258         aMetric = 3;
00259         break;
00260     case eMetric_TextVerticalInsidePadding:
00261         aMetric = 0;
00262         break;
00263     case eMetric_TextShouldUseVerticalInsidePadding:
00264         aMetric = 0;
00265         break;
00266     case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
00267         aMetric = 1;
00268         break;
00269     case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
00270         aMetric = 0;
00271         break;
00272     case eMetric_ListHorizontalInsideMinimumPadding:
00273         aMetric = 3;
00274         break;
00275     case eMetric_ListShouldUseVerticalInsidePadding:
00276         aMetric = 0;
00277         break;
00278     case eMetric_ListVerticalInsidePadding:
00279         aMetric = 0;
00280         break;
00281     case eMetric_CaretBlinkTime:
00282         aMetric = 500;
00283         break;
00284     case eMetric_CaretWidth:
00285         aMetric = 1;
00286         break;
00287     case eMetric_ShowCaretDuringSelection:
00288         aMetric = 0;
00289         break;
00290     case eMetric_SelectTextfieldsOnKeyFocus:
00291         // Select textfield content when focused by kbd
00292         // used by nsEventStateManager::sTextfieldSelectModel
00293         aMetric = 1;
00294         break;
00295     case eMetric_SubmenuDelay:
00296         aMetric = 200;
00297         break;
00298     case eMetric_TreeOpenDelay:
00299         aMetric = 1000;
00300         break;
00301     case eMetric_TreeCloseDelay:
00302         aMetric = 1000;
00303         break;
00304     case eMetric_TreeLazyScrollDelay:
00305         aMetric = 150;
00306         break;
00307     case eMetric_TreeScrollDelay:
00308         aMetric = 100;
00309         break;
00310     case eMetric_TreeScrollLinesMax:
00311         aMetric = 3;
00312         break;
00313     default:
00314         aMetric = 0;
00315         res = NS_ERROR_FAILURE;
00316     }
00317     return res;
00318 }
00319 
00320 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
00321 {
00322     PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric()\n"));
00323 
00324     // XXX this is not complete
00325     nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00326     if (NS_SUCCEEDED(res))
00327         return res;
00328     res = NS_OK;
00329 
00330     switch (aID) {
00331     case eMetricFloat_TextFieldVerticalInsidePadding:
00332         aMetric = 0.25f;
00333         break;
00334     case eMetricFloat_TextFieldHorizontalInsidePadding:
00335         aMetric = 0.95f;
00336         break;
00337     case eMetricFloat_TextAreaVerticalInsidePadding:
00338         aMetric = 0.40f;
00339         break;
00340     case eMetricFloat_TextAreaHorizontalInsidePadding:
00341         aMetric = 0.40f;
00342         break;
00343     case eMetricFloat_ListVerticalInsidePadding:
00344         aMetric = 0.10f;
00345         break;
00346     case eMetricFloat_ListHorizontalInsidePadding:
00347         aMetric = 0.40f;
00348         break;
00349     case eMetricFloat_ButtonVerticalInsidePadding:
00350         aMetric = 0.25f;
00351         break;
00352     case eMetricFloat_ButtonHorizontalInsidePadding:
00353         aMetric = 0.25f;
00354         break;
00355     default:
00356         aMetric = -1.0;
00357         res = NS_ERROR_FAILURE;
00358     }
00359     return res;
00360 }