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 "nsCarbonHelpers.h"
00040 #include "nsIInternetConfigService.h"
00041 #include "nsIServiceManager.h"
00042 #include "nsSize.h"
00043 
00044 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
00045 // This theme brush is available in 10.2 and later, but was not
00046 // formally documented in the SDK until 10.3.
00047 #define kThemeBrushAlternatePrimaryHighlightColor -5
00048 #endif
00049  
00050 //-------------------------------------------------------------------------
00051 //
00052 // Query interface implementation
00053 //
00054 //-------------------------------------------------------------------------
00055 
00056 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
00057 {
00058 }
00059 
00060 nsLookAndFeel::~nsLookAndFeel()
00061 {
00062 }
00063 
00064 nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor)
00065 {
00066     nsresult res = NS_OK;
00067 
00068     switch (aID) {
00069     case eColor_WindowBackground:
00070         {
00071           nsCOMPtr<nsIInternetConfigService> icService_wb (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
00072           if (icService_wb)
00073           {
00074             res = icService_wb->GetColor(nsIInternetConfigService::eICColor_WebBackgroundColour, &aColor);
00075             if (NS_SUCCEEDED(res))
00076               return res;
00077           }
00078 
00079           aColor = NS_RGB(0xff,0xff,0xff); // default to white if we didn't find it in internet config
00080           res = NS_OK;
00081         }
00082         break;
00083     case eColor_WindowForeground:
00084         aColor = NS_RGB(0x00,0x00,0x00);        
00085         break;
00086     case eColor_WidgetBackground:
00087         aColor = NS_RGB(0xdd,0xdd,0xdd);
00088         break;
00089     case eColor_WidgetForeground:
00090         aColor = NS_RGB(0x00,0x00,0x00);        
00091         break;
00092     case eColor_WidgetSelectBackground:
00093         aColor = NS_RGB(0x80,0x80,0x80);
00094         break;
00095     case eColor_WidgetSelectForeground:
00096         aColor = NS_RGB(0x00,0x00,0x80);
00097         break;
00098     case eColor_Widget3DHighlight:
00099         aColor = NS_RGB(0xa0,0xa0,0xa0);
00100         break;
00101     case eColor_Widget3DShadow:
00102         aColor = NS_RGB(0x40,0x40,0x40);
00103         break;
00104     case eColor_TextBackground:
00105         aColor = NS_RGB(0xff,0xff,0xff);
00106         break;
00107     case eColor_TextForeground: 
00108         {
00109           nsCOMPtr<nsIInternetConfigService> icService_tf (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
00110           if (icService_tf)
00111           {
00112             res = icService_tf->GetColor(nsIInternetConfigService::eICColor_WebTextColor, &aColor);
00113             if (NS_SUCCEEDED(res))
00114               return res;
00115           }
00116           aColor = NS_RGB(0x00,0x00,0x00);
00117           res = NS_OK;
00118         }
00119         break;
00120     case eColor_highlight: // CSS2 color
00121     case eColor_TextSelectBackground:
00122     case eColor__moz_menuhover:
00123         // XXX can probably just always use GetMacBrushColor here
00124 #ifdef MOZ_WIDGET_COCOA
00125         res = GetMacBrushColor(kThemeBrushPrimaryHighlightColor, aColor, NS_RGB(0x00,0x00,0x00));
00126 #else
00127         RGBColor macColor;
00128         CGrafPtr thePort;
00129         ::GetPort((GrafPtr*)&thePort);
00130               if (thePort)
00131               {
00132           ::GetPortHiliteColor(thePort,&macColor);
00133           aColor = NS_RGB(macColor.red>>8, macColor.green>>8, macColor.blue>>8);
00134               }
00135               else
00136               aColor = NS_RGB(0x00,0x00,0x00);
00137 #endif
00138         break;
00139     case eColor_highlighttext:  // CSS2 color
00140     case eColor_TextSelectForeground:
00141     case eColor__moz_menuhovertext:
00142               GetColor(eColor_TextSelectBackground, aColor);
00143               if (aColor == 0x000000)
00144                                    aColor = NS_RGB(0xff,0xff,0xff);
00145               else
00146                      aColor = NS_DONT_CHANGE_COLOR;
00147         break;
00148 
00149     //
00150     // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
00151     //
00152     // It's really hard to effectively map these to the Appearance Manager properly,
00153     // since they are modeled word for word after the win32 system colors and don't have any 
00154     // real counterparts in the Mac world. I'm sure we'll be tweaking these for 
00155     // years to come. 
00156     //
00157     // Thanks to mpt26@student.canterbury.ac.nz for the hardcoded values that form the defaults
00158     // if querying the Appearance Manager fails ;)
00159     //
00160     
00161     case eColor_buttontext:
00162     case eColor__moz_buttonhovertext:
00163        res = GetMacTextColor(kThemeTextColorPushButtonActive, aColor, NS_RGB(0x00,0x00,0x00));
00164            break;
00165     case eColor_captiontext:
00166        res = GetMacTextColor(kThemeTextColorWindowHeaderActive, aColor, NS_RGB(0x00,0x00,0x00));
00167            break;
00168     case eColor_menutext:
00169        res = GetMacTextColor(kThemeTextColorMenuItemActive, aColor, NS_RGB(0x00,0x00,0x00));
00170            break;
00171     case eColor_infotext:
00172               //this will only work on MacOS 9. Mac OS < 9 will use hardcoded value
00173        res = GetMacTextColor(kThemeTextColorNotification, aColor, NS_RGB(0x00,0x00,0x00));
00174            break;    
00175     case eColor_windowtext:
00176               //DialogActive is closest match to "windowtext"
00177        res = GetMacTextColor(kThemeTextColorDialogActive, aColor, NS_RGB(0x00,0x00,0x00));
00178            break;
00179     case eColor_activecaption:
00180        //no way to fetch this colour. HARDCODING to Platinum
00181               //res = GetMacBrushColor(??, aColor, NS_RGB(0xCC,0xCC,0xCC));
00182               //active titlebar etc is #CCCCCC
00183        aColor = NS_RGB(0xCC,0xCC,0xCC);
00184        res = NS_OK;
00185            break;
00186     case eColor_activeborder:
00187               //If it means anything at all on Mac OS, then its black in every theme I've tried,
00188               //but Aqua *has* no border!
00189        res = GetMacBrushColor(kThemeBrushBlack, aColor, NS_RGB(0x00,0x00,0x00));
00190            break;
00191        case eColor_appworkspace:
00192         // NOTE: this is an MDI color and does not exist on macOS.
00193               //used the closest match, which will likely be white.
00194        res = GetMacBrushColor(kThemeBrushDocumentWindowBackground, aColor, NS_RGB(0x63,0x63,0xCE));
00195            break;   
00196     case eColor_background:
00197         // NOTE: chances are good this is a pattern, not a pure color. What do we do?
00198         // Seconded. This is almost never going to be a flat colour...
00199         //incidentally, this is supposed to be the colour of the desktop, though how anyone
00200         //is supposed to guess that from the name?
00201         aColor = NS_RGB(0x63,0x63,0xCE);
00202         res = NS_OK;
00203         break;
00204     case eColor_buttonface:
00205     case eColor__moz_buttonhoverface:
00206        res = GetMacBrushColor(kThemeBrushButtonFaceActive, aColor, NS_RGB(0xDD,0xDD,0xDD));
00207            break;
00208     case eColor_buttonhighlight:
00209               //lighter of 2 possible highlight colours available
00210        res = GetMacBrushColor(kThemeBrushButtonActiveLightHighlight, aColor, NS_RGB(0xFF,0xFF,0xFF));
00211            break;
00212     case eColor_buttonshadow:
00213               //darker of 2 possible shadow colours available
00214        res = GetMacBrushColor(kThemeBrushButtonActiveDarkShadow, aColor, NS_RGB(0x77,0x77,0x77));
00215            break;
00216     case eColor_graytext:
00217        res = GetMacTextColor(kThemeTextColorDialogInactive, aColor, NS_RGB(0x77,0x77,0x77));
00218            break;
00219     case eColor_inactiveborder:
00220               //ScrollBar DelimiterInactive looks like an odd constant to use, but gives the right colour in most themes, 
00221               //also if you look at where this colour is *actually* used, it is pretty much what we want
00222        res = GetMacBrushColor(kThemeBrushScrollBarDelimiterInactive, aColor, NS_RGB(0x55,0x55,0x55));
00223            break;
00224     case eColor_inactivecaption:
00225               //best guess. Usually right in most themes I think
00226        res = GetMacBrushColor(kThemeBrushDialogBackgroundInactive, aColor, NS_RGB(0xDD,0xDD,0xDD));
00227            break;
00228     case eColor_inactivecaptiontext:
00229        res = GetMacTextColor(kThemeTextColorWindowHeaderInactive, aColor, NS_RGB(0x77,0x77,0x77));
00230               break;
00231     case eColor_scrollbar:
00232         //this is the scrollbar trough. HARDCODING no way to get this colour
00233               //res = GetMacBrushColor(??, aColor, NS_RGB(0xAA,0xAA,0xAA));
00234        aColor = NS_RGB(0xAA,0xAA,0xAA);
00235        res = NS_OK;
00236            break;
00237     case eColor_threeddarkshadow:
00238               res = GetMacBrushColor(kThemeBrushButtonActiveDarkShadow, aColor, NS_RGB(0x77,0x77,0x77));
00239            break;
00240     case eColor_threedshadow:
00241               res = GetMacBrushColor(kThemeBrushButtonActiveLightShadow, aColor, NS_RGB(0x99,0x99,0x99));
00242            break;
00243     case eColor_threedface:
00244               res = GetMacBrushColor(kThemeBrushButtonFaceActive, aColor, NS_RGB(0xDD,0xDD,0xDD));
00245            break;
00246     case eColor_threedhighlight:
00247               res = GetMacBrushColor(kThemeBrushButtonActiveLightHighlight, aColor, NS_RGB(0xFF,0xFF,0xFF));
00248            break;
00249     case eColor_threedlightshadow:
00250               //the description in the CSS2 spec says this is on the side facing the lightsource,
00251               //so its not a shadow in Mac OS terms, its the darker of the highlights 
00252               res = GetMacBrushColor(kThemeBrushButtonActiveDarkHighlight, aColor, NS_RGB(0xDD,0xDD,0xDD));
00253            break;
00254     case eColor_menu:
00255               //best guess. Menus have similar background to dialogs in most themes
00256               res = GetMacBrushColor(kThemeBrushDialogBackgroundActive, aColor, NS_RGB(0xDD,0xDD,0xDD));
00257            break;
00258     case eColor_infobackground:
00259               //Brush exists on on MacOS 9. Earlier Mac OS will use default Platinum colour
00260               res = GetMacBrushColor(kThemeBrushNotificationWindowBackground, aColor, NS_RGB(0xFF,0xFF,0xC6));
00261            break;
00262     case eColor_windowframe:
00263        //no way to fetch this colour. HARDCODING to Platinum
00264               //res = GetMacBrushColor(??, aColor, NS_RGB(0xCC,0xCC,0xCC));
00265        aColor = NS_RGB(0xCC,0xCC,0xCC);
00266        res = NS_OK;
00267            break;
00268     case eColor_window:
00269               res = GetMacBrushColor(kThemeBrushDocumentWindowBackground, aColor, NS_RGB(0xFF,0xFF,0xFF));        
00270               break;
00271     case eColor__moz_field:
00272               aColor = NS_RGB(0xff,0xff,0xff);
00273         break;
00274     case eColor__moz_fieldtext:
00275         // XXX There may be a better color for this, but I'm making it
00276         // the same as WindowText since that's what's currently used where
00277         // I will use -moz-FieldText.
00278         res = GetMacTextColor(kThemeTextColorDialogActive, aColor, NS_RGB(0x00,0x00,0x00));
00279         break;
00280     case eColor__moz_dialog:
00281     case eColor__moz_cellhighlight:
00282         // XXX There may be a better color for this, but I'm making it
00283         // the same as ThreeDFace since that's what's currently used where
00284         // I will use -moz-Dialog:
00285         res = GetMacBrushColor(kThemeBrushButtonFaceActive, aColor, NS_RGB(0xDD,0xDD,0xDD));
00286         break;
00287     case eColor__moz_dialogtext:
00288     case eColor__moz_cellhighlighttext:
00289         // XXX There may be a better color for this, but I'm making it
00290         // the same as WindowText since that's what's currently used where
00291         // I will use -moz-DialogText.
00292         res = GetMacTextColor(kThemeTextColorDialogActive, aColor, NS_RGB(0x00,0x00,0x00));
00293         break;
00294     case eColor__moz_dragtargetzone:
00295               //default to lavender if not available
00296               res = GetMacBrushColor(kThemeBrushDragHilite, aColor, NS_RGB(0x63,0x63,0xCE));
00297            break;
00298        case eColor__moz_mac_focusring:
00299               //default to lavender if not available
00300               res = GetMacBrushColor(kThemeBrushFocusHighlight, aColor, NS_RGB(0x63,0x63,0xCE));
00301            break;
00302        case eColor__moz_mac_menushadow:
00303               res = GetMacBrushColor(kThemeBrushBevelActiveDark, aColor, NS_RGB(0x88,0x88,0x88));
00304            break;            
00305        case eColor__moz_mac_menutextdisable:
00306               res = GetMacTextColor(kThemeTextColorMenuItemDisabled, aColor, NS_RGB(0x99,0x99,0x99));
00307            break;        
00308        case eColor__moz_mac_menutextselect:
00309               //default to white, which is what Platinum uses, if not available            
00310               res = GetMacTextColor(kThemeTextColorMenuItemSelected, aColor, NS_RGB(0xFF,0xFF,0xFF));
00311            break;        
00312        case eColor__moz_mac_accentlightesthighlight:
00313               //get this colour by querying variation table, ows. default to Platinum/Lavendar
00314               res = GetMacAccentColor(eColorOffset_mac_accentlightesthighlight, aColor, NS_RGB(0xEE,0xEE,0xEE));
00315            break;    
00316     case eColor__moz_mac_accentregularhighlight:
00317               //get this colour by querying variation table, ows. default to Platinum/Lavendar
00318               res = GetMacAccentColor(eColorOffset_mac_accentregularhighlight, aColor, NS_RGB(0xCC,0xCC,0xFF));
00319            break;        
00320     case eColor__moz_mac_accentface:
00321               //get this colour by querying variation table, ows. default to Platinum/Lavendar
00322               res = GetMacAccentColor(eColorOffset_mac_accentface, aColor, NS_RGB(0x99,0x99,0xFF));
00323            break;            
00324     case eColor__moz_mac_accentlightshadow:
00325               //get this colour by querying variation table, ows. default to Platinum/Lavendar
00326               res = GetMacAccentColor(eColorOffset_mac_accentlightshadow, aColor, NS_RGB(0x66,0x66,0xCC));
00327            break; 
00328        case eColor__moz_mac_menuselect:
00329        case eColor__moz_mac_accentregularshadow:
00330               //get this colour by querying variation table, ows. default to Platinum/Lavendar
00331               res = GetMacAccentColor(eColorOffset_mac_accentregularshadow, aColor, NS_RGB(0x63,0x63,0xCE));
00332            break;
00333     case eColor__moz_mac_accentdarkshadow:
00334        //get this colour by querying variation table, ows. default to Platinum/Lavendar
00335               res = GetMacAccentColor(eColorOffset_mac_accentdarkshadow, aColor, NS_RGB(0x00,0x00,0x88));
00336            break;
00337     case eColor__moz_mac_accentdarkestshadow:
00338        //get this colour by querying variation table, ows. default to Platinum/Lavendar
00339               res = GetMacAccentColor(eColorOffset_mac_accentdarkestshadow, aColor, NS_RGB(0x00,0x00,0x55));
00340            break;
00341     case eColor__moz_buttondefault:
00342         res = GetMacBrushColor(kThemeBrushButtonActiveDarkShadow, aColor, NS_RGB(0x77,0x77,0x77));
00343         break;
00344     case eColor__moz_mac_alternateprimaryhighlight:
00345         // For proper styling of lists when active, on 10.2+
00346         // On older OSs may have to fall back to primary highlight color
00347         nscolor fallbackColor;
00348         GetMacBrushColor(kThemeBrushPrimaryHighlightColor, fallbackColor, NS_RGB(0x00,0x00,0x00));
00349         res = GetMacBrushColor(kThemeBrushAlternatePrimaryHighlightColor, aColor, fallbackColor);
00350         break;
00351     case eColor__moz_mac_secondaryhighlight:
00352        // For inactive list selection
00353         res = GetMacBrushColor(kThemeBrushSecondaryHighlightColor, aColor, NS_RGB(0x00,0x00,0x00));
00354         break;
00355     default:
00356         NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
00357         aColor = NS_RGB(0xff,0xff,0xff);
00358         res = NS_ERROR_FAILURE;
00359         break;
00360     }
00361 
00362     return res;
00363 }
00364 
00365 NS_IMETHODIMP nsLookAndFeel::GetMacBrushColor(   const PRInt32 aBrushType, nscolor & aColor,
00366                                                                                     const nscolor & aDefaultColor)
00367 {
00368        OSStatus err = noErr;
00369        RGBColor macColor;
00370        
00371        err = ::GetThemeBrushAsColor(aBrushType, 32, true, &macColor);
00372        if (err == noErr) 
00373               aColor =  NS_RGB(macColor.red>>8, macColor.green>>8, macColor.blue>>8);
00374        else
00375               aColor = aDefaultColor;
00376        return NS_OK;
00377        
00378 }
00379 
00380 NS_IMETHODIMP nsLookAndFeel::GetMacTextColor(const PRInt32 aTextType, nscolor & aColor,
00381                                                                               const nscolor & aDefaultColor)
00382 {
00383        OSStatus err = noErr;
00384        RGBColor macColor;
00385        
00386        err = ::GetThemeTextColor(aTextType, 32, true, &macColor);
00387        if (err == noErr) 
00388               aColor =  NS_RGB(macColor.red>>8, macColor.green>>8, macColor.blue>>8);
00389        else
00390               aColor = aDefaultColor;
00391        return NS_OK;
00392        
00393 }
00394 
00395 NS_IMETHODIMP nsLookAndFeel::GetMacAccentColor(  const nsMacAccentColorOffset aAccent, 
00396                                                                                     nscolor & aColor,
00397                                                                                     const nscolor & aDefaultColor)
00398 {
00399        nsresult res = NS_OK;
00400        OSStatus err = noErr;
00401        ColorTable colourTable;
00402        CTabPtr ctPointer = &colourTable;
00403        CTabHandle ctHandle = &ctPointer;
00404        CTabHandle *colors = &ctHandle;
00405        RGBColor *macColor;         
00406 
00407        err = ::GetThemeAccentColors(colors);
00408        if (err == themeHasNoAccentsErr) {
00409               //fine, theme doesn't support accents, use default
00410               res = NS_OK;
00411               aColor = aDefaultColor;
00412        } else if (err != noErr || ! colors) {
00413               res = NS_ERROR_FAILURE;
00414               aColor = aDefaultColor;
00415        } else {
00416               if ((**colors)->ctSize == 
00417                             (eColorOffset_mac_accentdarkestshadow - eColorOffset_mac_accentlightesthighlight +1)) {
00418                      //if the size is 7 then its likely to be a standard Platinum variation, so lets use it
00419                      macColor = &((**colors)->ctTable[aAccent].rgb);
00420                      aColor = NS_RGB(macColor->red>>8, macColor->green>>8, macColor->blue>>8);
00421                      res = NS_OK;         
00422               } else if ((**colors)->ctSize == -1) {
00423                      //this is probably the high contrast Black & White Platinum variation
00424                      //so lets be high contrast
00425                      res = NS_OK;
00426                      if (aAccent <= eColorOffset_mac_accentface) {
00427                             aColor = NS_RGB(0xFF,0xFF,0xFF);
00428                      } else {
00429                             aColor = NS_RGB(0x00,0x00,0x00);
00430                      }
00431               //else if ( ?? )  // add aqua support here?
00432               } else {
00433                      //some other size we've never heard of, no idea what to do with it
00434                      res = NS_ERROR_FAILURE;
00435                      aColor = aDefaultColor;
00436               }
00437        }
00438        return res;
00439 }
00440 
00441 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
00442 {
00443     nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00444     if (NS_SUCCEEDED(res))
00445         return res;
00446     res = NS_OK;
00447 
00448     switch (aID) {
00449     case eMetric_WindowTitleHeight:
00450         aMetric = 0;
00451         break;
00452     case eMetric_WindowBorderWidth:
00453         aMetric = 4;
00454         break;
00455     case eMetric_WindowBorderHeight:
00456         aMetric = 4;
00457         break;
00458     case eMetric_Widget3DBorder:
00459         aMetric = 4;
00460         break;
00461     case eMetric_TextFieldHeight:
00462         aMetric = 16;
00463         break;
00464     case eMetric_TextFieldBorder:
00465         aMetric = 2;
00466         break;
00467     case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
00468         aMetric = 20;
00469         break;
00470     case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
00471         aMetric = 0;
00472         break;
00473     case eMetric_CheckboxSize:
00474         aMetric = 14;
00475         break;
00476     case eMetric_RadioboxSize:
00477         aMetric = 14;
00478         break;
00479     case eMetric_TextHorizontalInsideMinimumPadding:
00480         aMetric = 4;
00481         break;
00482     case eMetric_TextVerticalInsidePadding:
00483         aMetric = 4;
00484         break;
00485     case eMetric_TextShouldUseVerticalInsidePadding:
00486         aMetric = 1;
00487         break;
00488     case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
00489         aMetric = 1;
00490         break;
00491     case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
00492         aMetric = 0;
00493         break;
00494     case eMetric_ListHorizontalInsideMinimumPadding:
00495         aMetric = 4;
00496         break;
00497     case eMetric_ListShouldUseVerticalInsidePadding:
00498         aMetric = 1;
00499         break;
00500     case eMetric_ListVerticalInsidePadding:
00501         aMetric = 3;
00502         break;
00503     case eMetric_CaretBlinkTime:
00504         aMetric = ::GetCaretTime() * 1000 / 60;
00505         break;
00506     case eMetric_CaretWidth:
00507         aMetric = 1;
00508         break;
00509     case eMetric_ShowCaretDuringSelection:
00510         aMetric = 0;
00511         break;
00512     case eMetric_SelectTextfieldsOnKeyFocus:
00513         // Select textfield content when focused by kbd
00514         // used by nsEventStateManager::sTextfieldSelectModel
00515         aMetric = 1;
00516         break;
00517     case eMetric_SubmenuDelay:
00518         aMetric = 200;
00519         break;
00520     case eMetric_MenusCanOverlapOSBar:
00521         // xul popups are not allowed to overlap the menubar.
00522         aMetric = 0;
00523         break;
00524     case eMetric_SkipNavigatingDisabledMenuItem:
00525         aMetric = 1;
00526         break;
00527     case eMetric_DragFullWindow:
00528         aMetric = 1;
00529         break;        
00530     case eMetric_DragThresholdX:
00531     case eMetric_DragThresholdY:
00532         aMetric = 4;
00533         break;
00534     case eMetric_ScrollArrowStyle:
00535         ThemeScrollBarArrowStyle arrowStyle;
00536         ::GetThemeScrollBarArrowStyle ( &arrowStyle );
00537         aMetric = arrowStyle;
00538         break;
00539     case eMetric_ScrollSliderStyle:
00540         ThemeScrollBarThumbStyle thumbStyle;
00541         ::GetThemeScrollBarThumbStyle ( &thumbStyle );
00542         aMetric = thumbStyle;
00543         break;
00544     case eMetric_TreeOpenDelay:
00545         aMetric = 1000;
00546         break;
00547     case eMetric_TreeCloseDelay:
00548         aMetric = 1000;
00549         break;
00550     case eMetric_TreeLazyScrollDelay:
00551         aMetric = 150;
00552         break;
00553     case eMetric_TreeScrollDelay:
00554         aMetric = 100;
00555         break;
00556     case eMetric_TreeScrollLinesMax:
00557         aMetric = 3;
00558         break;
00559     case eMetric_TabFocusModel:
00560         {
00561           // we should probably cache this
00562           CFPropertyListRef fullKeyboardAccessProperty;
00563           fullKeyboardAccessProperty = ::CFPreferencesCopyValue(CFSTR("AppleKeyboardUIMode"),
00564                                                                  kCFPreferencesAnyApplication,
00565                                                                  kCFPreferencesCurrentUser,
00566                                                                  kCFPreferencesAnyHost);
00567           aMetric = 1;    // default to just textboxes
00568           if (fullKeyboardAccessProperty)
00569           {
00570             PRInt32 fullKeyboardAccessPrefVal;
00571             if (::CFNumberGetValue((CFNumberRef) fullKeyboardAccessProperty, kCFNumberIntType, &fullKeyboardAccessPrefVal))
00572             {
00573               // the second bit means  "Full keyboard access" is on
00574               if (fullKeyboardAccessPrefVal & (1 << 1))
00575                 aMetric = 7; // everything that can be focused
00576             }
00577             ::CFRelease(fullKeyboardAccessProperty);
00578           }
00579         }
00580         break;
00581     default:
00582         aMetric = 0;
00583         res = NS_ERROR_FAILURE;
00584     }
00585     return res;
00586 }
00587 
00588 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
00589 {
00590   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00591   if (NS_SUCCEEDED(res))
00592       return res;
00593   res = NS_OK;
00594 
00595   switch (aID) {
00596     case eMetricFloat_TextFieldVerticalInsidePadding:
00597         aMetric = 0.25f;
00598         break;
00599     case eMetricFloat_TextFieldHorizontalInsidePadding:
00600         aMetric = 0.95f;
00601         break;
00602     case eMetricFloat_TextAreaVerticalInsidePadding:
00603         aMetric = 0.40f;
00604         break;
00605     case eMetricFloat_TextAreaHorizontalInsidePadding:
00606         aMetric = 0.40f;
00607         break;
00608     case eMetricFloat_ListVerticalInsidePadding:
00609         aMetric = 0.08f;
00610         break;
00611     case eMetricFloat_ListHorizontalInsidePadding:
00612         aMetric = 0.40f;
00613         break;
00614     case eMetricFloat_ButtonVerticalInsidePadding:
00615         aMetric = 0.5f;
00616         break;
00617     case eMetricFloat_ButtonHorizontalInsidePadding:
00618         aMetric = 0.5f;
00619         break;
00620     default:
00621         aMetric = -1.0;
00622         res = NS_ERROR_FAILURE;
00623     }
00624   return res;
00625 }