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 <Pt.h>
00040 #include "nsFont.h"
00041 
00042 #define PH_TO_NS_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff) 
00043 
00044 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
00045 {
00046 }
00047 
00048 nsLookAndFeel::~nsLookAndFeel()
00049 {
00050 }
00051 
00052 nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor)
00053 {
00054   nsresult res = NS_OK;
00055 
00056   /*
00057    * There used to be an entirely separate list of these colors in
00058    * nsDeviceContextPh::GetSystemAttribute.  The colors given there
00059    * were a bit different from these.  If these are inaccurate, it might
00060    * be worth looking at cvs history for the ones there to see if they
00061    * were better.
00062    */
00063 
00064   switch (aID) 
00065   {
00066          case eColor_WindowBackground:
00067               aColor = PH_TO_NS_RGB(Pg_LGREY);
00068               break;
00069          case eColor_WindowForeground:
00070               aColor = PH_TO_NS_RGB(Pg_DGREY);
00071               break;
00072          case eColor_WidgetBackground:
00073               aColor = PH_TO_NS_RGB(Pg_LGREY);
00074               break;
00075          case eColor_WidgetForeground:
00076               aColor = PH_TO_NS_RGB(Pg_DGREY);
00077               break;
00078          case eColor_WidgetSelectBackground:
00079               aColor = PH_TO_NS_RGB(Pg_DGREY);
00080               break;
00081          case eColor_WidgetSelectForeground:
00082               aColor = PH_TO_NS_RGB(Pg_DGREY);
00083               break;
00084          case eColor_Widget3DHighlight:
00085               aColor = PH_TO_NS_RGB(Pg_WHITE);
00086               break;
00087          case eColor_Widget3DShadow:
00088               aColor = PH_TO_NS_RGB(Pg_DGREY);
00089               break;
00090          case eColor_TextBackground:
00091               aColor = PH_TO_NS_RGB(Pg_WHITE);
00092               break;
00093          case eColor_TextForeground: 
00094               aColor = PH_TO_NS_RGB(Pg_BLACK);
00095               break;
00096          case eColor_TextSelectBackground:
00097               aColor = PH_TO_NS_RGB(Pg_BLACK);
00098               break;
00099          case eColor_TextSelectForeground:
00100               aColor = PH_TO_NS_RGB(Pg_WHITE);
00101               break;
00102 
00103               // css2  http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
00104          case eColor_activeborder:
00105               aColor = PH_TO_NS_RGB(Pg_BLACK);
00106               break;
00107          case eColor_activecaption:
00108               aColor = PH_TO_NS_RGB(Pg_YELLOW);
00109               break;
00110          case eColor_appworkspace:
00111               aColor = PH_TO_NS_RGB(Pg_LGREY);
00112               break;
00113          case eColor_background:
00114               aColor = PH_TO_NS_RGB(Pg_LGREY);
00115               break;
00116          case eColor_captiontext:
00117               aColor = PH_TO_NS_RGB(Pg_BLACK);
00118               break;
00119          case eColor_graytext:
00120               aColor = PH_TO_NS_RGB(Pg_DGREY);
00121               break;
00122          case eColor_highlight:
00123          case eColor__moz_menuhover:
00124               aColor = PH_TO_NS_RGB(0x9ba9c9); // bill blue
00125               break;
00126          case eColor_highlighttext:
00127          case eColor__moz_menuhovertext:
00128               aColor = PH_TO_NS_RGB(Pg_BLACK);
00129               break;
00130          case eColor_inactiveborder:
00131               aColor = PH_TO_NS_RGB(Pg_DGREY);
00132               break;
00133          case eColor_inactivecaption:
00134               aColor = PH_TO_NS_RGB(Pg_GREY);
00135               break;
00136          case eColor_inactivecaptiontext:
00137               aColor = PH_TO_NS_RGB(Pg_DGREY);
00138               break;
00139          case eColor_infobackground:
00140               aColor = PH_TO_NS_RGB(Pg_BALLOONCOLOR); // popup yellow
00141               break;
00142          case eColor_infotext:
00143               aColor = PH_TO_NS_RGB(Pg_BLACK);
00144               break;
00145          case eColor_menu:
00146               aColor = PH_TO_NS_RGB(Pg_LGREY);
00147               break;
00148          case eColor_menutext:
00149               aColor = PH_TO_NS_RGB(Pg_BLACK);
00150               break;
00151          case eColor_scrollbar:
00152               aColor = PH_TO_NS_RGB(Pg_LGREY);
00153               break;
00154          case eColor_threedface:
00155          case eColor_buttonface:
00156          case eColor__moz_buttonhoverface:
00157               aColor = PH_TO_NS_RGB(Pg_LGREY);
00158               break;
00159 
00160          case eColor_buttonhighlight:
00161          case eColor_threedhighlight:
00162               aColor = PH_TO_NS_RGB(Pg_WHITE);
00163               break;
00164 
00165          case eColor_buttontext:
00166          case eColor__moz_buttonhovertext:
00167               aColor = PH_TO_NS_RGB(Pg_BLACK);
00168               break;
00169 
00170          case eColor_buttonshadow:
00171          case eColor_threedshadow: // i think these should be the same
00172               aColor = PH_TO_NS_RGB(Pg_DGREY);
00173               break;
00174 
00175          case eColor_threeddarkshadow:
00176               aColor = PH_TO_NS_RGB(Pg_DGREY);
00177               break;
00178 
00179          case eColor_threedlightshadow:
00180               aColor = PH_TO_NS_RGB(Pg_LGREY);
00181               break;
00182 
00183          case eColor_window:
00184               aColor = PH_TO_NS_RGB(Pg_WHITE);
00185               break;
00186 
00187          case eColor_windowframe:
00188               aColor = PH_TO_NS_RGB(Pg_LGREY);
00189               break;
00190 
00191          case eColor_windowtext:
00192               aColor = PH_TO_NS_RGB(Pg_BLACK);
00193               break;
00194 
00195          // from the CSS3 working draft (not yet finalized)
00196          // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
00197 
00198          case eColor__moz_field:
00199               aColor = PH_TO_NS_RGB(Pg_WHITE);
00200               break;
00201 
00202        case eColor__moz_fieldtext:
00203          aColor = PH_TO_NS_RGB(Pg_BLACK);
00204          break;
00205 
00206        case eColor__moz_dialog:
00207        case eColor__moz_cellhighlight:
00208          aColor = PH_TO_NS_RGB(Pg_LGREY);
00209          break;
00210 
00211        case eColor__moz_dialogtext:
00212        case eColor__moz_cellhighlighttext:
00213          aColor = PH_TO_NS_RGB(Pg_BLACK);
00214          break;
00215 
00216        case eColor__moz_dragtargetzone:
00217          aColor = PH_TO_NS_RGB(Pg_LGREY);
00218          break;
00219 
00220        case eColor__moz_buttondefault:
00221          aColor = PH_TO_NS_RGB(Pg_DGREY);
00222          break;
00223 
00224        default:
00225     aColor = PH_TO_NS_RGB(Pg_WHITE);
00226     break;
00227   }
00228 
00229   return res;
00230 }
00231   
00232 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
00233 {
00234 
00235 
00236   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00237   if (NS_SUCCEEDED(res))
00238       return res;
00239 
00240   res = NS_OK;
00241 
00242   /*
00243    * There used to be an entirely separate list of these metrics in
00244    * nsDeviceContextPh::GetSystemAttribute.  The metrics given there
00245    * were a bit different from these.  If these are inaccurate, it might
00246    * be worth looking at cvs history for the ones there to see if they
00247    * were better.
00248    */
00249 
00250   switch (aID) 
00251   {
00252   case eMetric_WindowTitleHeight:
00253     aMetric = 0;
00254     break;
00255   case eMetric_WindowBorderWidth:
00256     aMetric = 1;
00257     break;
00258   case eMetric_WindowBorderHeight:
00259     aMetric = 1;
00260     break;
00261   case eMetric_Widget3DBorder:
00262     aMetric = 2;
00263     break;
00264   case eMetric_TextFieldHeight:
00265        aMetric = 20;
00266     break;
00267   case eMetric_TextFieldBorder:
00268     aMetric = 1;
00269     break;
00270   case eMetric_TextVerticalInsidePadding:
00271     aMetric = 0;
00272     break;
00273   case eMetric_TextShouldUseVerticalInsidePadding:
00274     aMetric = 0;
00275     break;
00276   case eMetric_TextHorizontalInsideMinimumPadding:
00277     aMetric = 0;
00278     break;
00279   case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
00280     aMetric = 0;
00281     break;
00282   case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
00283        aMetric = 10;
00284     break;
00285   case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
00286        aMetric = 8;
00287     break;
00288   case eMetric_CheckboxSize:
00289     aMetric = 10;
00290     break;
00291   case eMetric_RadioboxSize:
00292     aMetric = 10;
00293     break;
00294   case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
00295     aMetric = 0;
00296     break;
00297   case eMetric_ListHorizontalInsideMinimumPadding:
00298     aMetric = 0;
00299     break;
00300   case eMetric_ListShouldUseVerticalInsidePadding:
00301     aMetric = 0;
00302     break;
00303   case eMetric_ListVerticalInsidePadding:
00304     aMetric = 0;
00305     break;
00306   case eMetric_CaretBlinkTime:
00307     aMetric = 500;
00308     break;
00309   case eMetric_CaretWidth:
00310     aMetric = 1;
00311     break;
00312        case eMetric_ShowCaretDuringSelection:
00313               aMetric = 0;
00314               break;
00315        case eMetric_SelectTextfieldsOnKeyFocus:
00316               // Select textfield content when focused by kbd
00317               // used by nsEventStateManager::sTextfieldSelectModel
00318               aMetric = 1;
00319               break;
00320   case eMetric_SubmenuDelay:
00321     aMetric = 200;
00322     break;
00323        case eMetric_MenusCanOverlapOSBar:
00324               // we want XUL popups to be able to overlap the task bar.
00325               aMetric = 1;
00326               break;
00327        case eMetric_DragFullWindow:
00328               aMetric = 1;
00329               break;
00330   case eMetric_TreeOpenDelay:
00331     aMetric = 1000;
00332     break;
00333   case eMetric_TreeCloseDelay:
00334     aMetric = 1000;
00335     break;
00336   case eMetric_TreeLazyScrollDelay:
00337     aMetric = 150;
00338     break;
00339   case eMetric_TreeScrollDelay:
00340     aMetric = 100;
00341     break;
00342   case eMetric_TreeScrollLinesMax:
00343     aMetric = 3;
00344     break;
00345 
00346   default:
00347     aMetric = 0;
00348     res     = NS_ERROR_FAILURE;
00349   }
00350 
00351   return res;
00352 }
00353 
00354 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
00355 {
00356 
00357   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00358   if (NS_SUCCEEDED(res))
00359       return res;
00360 
00361   res = NS_OK;
00362 
00363   switch (aID) {
00364   case eMetricFloat_TextFieldVerticalInsidePadding:
00365     aMetric = 0.25f;
00366     break;
00367   case eMetricFloat_TextFieldHorizontalInsidePadding:
00368     aMetric = 0.95f; // large number on purpose so minimum padding is used
00369     break;
00370   case eMetricFloat_TextAreaVerticalInsidePadding:
00371     aMetric = 0.40f;    
00372     break;
00373   case eMetricFloat_TextAreaHorizontalInsidePadding:
00374     aMetric = 0.40f; // large number on purpose so minimum padding is used
00375     break;
00376   case eMetricFloat_ListVerticalInsidePadding:
00377     aMetric = 0.10f;
00378     break;
00379   case eMetricFloat_ListHorizontalInsidePadding:
00380     aMetric = 0.40f;
00381     break;
00382   case eMetricFloat_ButtonVerticalInsidePadding:
00383     aMetric = 0.25f;
00384     break;
00385   case eMetricFloat_ButtonHorizontalInsidePadding:
00386     aMetric = 0.25f;
00387     break;
00388   default:
00389     aMetric = -1.0;
00390     res = NS_ERROR_FAILURE;
00391   }
00392  
00393   return res;
00394 }