Back to index

lightning-sunbird  0.9+nobinonly
nsLookAndFeel.cpp
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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Sergei Dolgov <sergei_d@fi.tartu.ee>
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 #include "nsLookAndFeel.h"
00040 #include "nsFont.h"
00041 #include "nsSize.h"
00042 
00043 #include <InterfaceDefs.h>
00044 #include <Menu.h>
00045 
00046 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
00047 {
00048 }
00049 
00050 nsLookAndFeel::~nsLookAndFeel()
00051 {
00052 }
00053 
00054 nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor)
00055 {
00056   nsresult res = NS_OK;
00057   rgb_color color;
00058   /*
00059    * There used to be an entirely separate list of these colors in
00060    * nsDeviceContextBeOS::GetSystemAttribute.  The colors given there
00061    * were a bit different from these.  If these are inaccurate, it might
00062    * be worth looking at cvs history for the ones there to see if they
00063    * were better.
00064    */
00065 
00066   switch (aID) {
00067     case eColor_WindowBackground:
00068       aColor = NS_RGB(0xff, 0xff, 0xff); 
00069       break;
00070     case eColor_WindowForeground:
00071       aColor = NS_RGB(0x00, 0x00, 0x00);        
00072       break;
00073     case eColor_WidgetBackground:
00074       aColor = NS_RGB(0xdd, 0xdd, 0xdd);
00075       break;
00076     case eColor_WidgetForeground:
00077       aColor = NS_RGB(0x00, 0x00, 0x00);        
00078       break;
00079     case eColor_WidgetSelectBackground:
00080       {
00081         color = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR);
00082         aColor = NS_RGB(color.red, color.green, color.blue);
00083       }
00084       break;
00085     case eColor_WidgetSelectForeground:
00086       aColor = NS_RGB(0x00, 0x00, 0x80);
00087       break;
00088     case eColor_Widget3DHighlight:
00089       aColor = NS_RGB(0xa0, 0xa0, 0xa0);
00090       break;
00091     case eColor_Widget3DShadow:
00092       aColor = NS_RGB(0x40, 0x40, 0x40);
00093       break;
00094     case eColor_TextBackground:
00095       aColor = NS_RGB(0xff, 0xff, 0xff);
00096       break;
00097     case eColor_TextForeground: 
00098       aColor = NS_RGB(0x00, 0x00, 0x00);
00099       break;
00100     case eColor_TextSelectBackground:
00101       {
00102         // looks good in Mozilla, though, never noticed this color in BeOS menu
00103         color = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR);
00104         aColor = NS_RGB(color.red, color.green, color.blue);
00105       }
00106       break;
00107     case eColor_TextSelectForeground:
00108       {
00109         color = ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR);
00110         aColor = NS_RGB(color.red, color.green, color.blue);
00111       }
00112       break;
00113        // two following colors get initialisation in XPLookAndFeel.
00114        //eColor_TextSelectBackgroundDisabled,
00115     //eColor_TextSelectBackgroundAttention,
00116     
00117     //  CSS 2 Colors
00118     case eColor_activeborder:
00119       aColor = NS_RGB(0x88, 0x88, 0x88);
00120       break;
00121     // active titletab
00122     case eColor_activecaption:
00123       {
00124         color = ui_color(B_WINDOW_TAB_COLOR);
00125         aColor = NS_RGB(color.red, color.green, color.blue);
00126       }    
00127       break;
00128     //MDI color
00129     case eColor_appworkspace:
00130       aColor = NS_RGB(0xd8, 0xd8, 0xd8);
00131       break;
00132     //incidentally, this is supposed to be the colour of the desktop, though how anyone
00133     //is supposed to guess that from the name?
00134     case eColor_background:
00135       {
00136         color = ui_color(B_DESKTOP_COLOR);
00137         aColor = NS_RGB(color.red, color.green, color.blue);
00138       }
00139       break;
00140     case eColor_buttonface:
00141     case eColor__moz_buttonhoverface:
00142       aColor = NS_RGB(0xdd, 0xdd, 0xdd);
00143       break;
00144     //should be lighter of 2 possible highlight colours available
00145     case eColor_buttonhighlight:
00146       aColor = NS_RGB(0xff, 0xff, 0xff);
00147       break;
00148     //darker of 2 possible shadow colours available
00149     case eColor_buttonshadow:
00150       aColor = NS_RGB(0x77, 0x77, 0x77);
00151       break;
00152     case eColor_buttontext:
00153     case eColor__moz_buttonhovertext:
00154       aColor = NS_RGB(0x00, 0x00, 0x00);
00155       break;
00156     case eColor_captiontext:
00157       aColor = NS_RGB(0x00, 0x00, 0x00);
00158       break;
00159     case eColor_graytext:
00160       aColor = NS_RGB(0x77, 0x77, 0x77);
00161       break;
00162     case eColor_highlight:
00163     case eColor__moz_menuhover:
00164       {
00165         // B_MENU_SELECTION_BACKGROUND_COLOR  is used for text selection
00166         // this blue colors seems more suitable
00167         color = ui_color(B_KEYBOARD_NAVIGATION_COLOR);
00168         aColor = NS_RGB(color.red, color.green, color.blue);
00169       }
00170       break;
00171     case eColor_highlighttext:
00172     case eColor__moz_menuhovertext:
00173       {
00174         color = ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR);
00175         aColor = NS_RGB(color.red, color.green, color.blue);
00176       }
00177       break;
00178     case eColor_inactiveborder:
00179       aColor = NS_RGB(0x55, 0x55, 0x55);
00180       break;
00181     case eColor_inactivecaption:
00182       aColor = NS_RGB(0xdd, 0xdd, 0xdd);
00183       break;
00184     case eColor_inactivecaptiontext:
00185       aColor = NS_RGB(0x77, 0x77, 0x77);
00186       break;
00187     case eColor_infobackground:
00188       // tooltips
00189       aColor = NS_RGB(0xff, 0xff, 0xd0);
00190       break;
00191     case eColor_infotext:
00192       aColor = NS_RGB(0x00, 0x00, 0x00);
00193       break;
00194     case eColor_menu:
00195       {
00196         color = ui_color(B_MENU_BACKGROUND_COLOR);
00197         aColor = NS_RGB(color.red, color.green, color.blue);
00198       }
00199       break;
00200     case eColor_menutext:
00201       {
00202         color = ui_color(B_MENU_ITEM_TEXT_COLOR);
00203         aColor = NS_RGB(color.red, color.green, color.blue);
00204       }
00205       break;
00206     case eColor_scrollbar:
00207       aColor = NS_RGB(0xaa, 0xaa, 0xaa);
00208       break;
00209     case eColor_threeddarkshadow:
00210       aColor = NS_RGB(0x77, 0x77, 0x77);
00211       break;
00212     case eColor_threedface:
00213       aColor = NS_RGB(0xdd, 0xdd, 0xdd);
00214       break;
00215     case eColor_threedhighlight:
00216       aColor = NS_RGB(0xff, 0xff, 0xff);
00217       break;
00218     case eColor_threedlightshadow:
00219       aColor = NS_RGB(0xdd, 0xdd, 0xdd);
00220       break;
00221     case eColor_threedshadow:
00222       aColor = NS_RGB(0x99, 0x99, 0x99);
00223       break;
00224     case eColor_window:
00225       aColor = NS_RGB(0xff, 0xff, 0xff);
00226       break;
00227     case eColor_windowframe:
00228       aColor = NS_RGB(0xcc, 0xcc, 0xcc);
00229       break;
00230     case eColor_windowtext:
00231       aColor = NS_RGB(0x00, 0x00, 0x00);
00232       break;
00233     // CSS3 candidates
00234     case eColor__moz_field: 
00235       // normal widget background
00236       aColor = NS_RGB(0xff, 0xff, 0xff);
00237       break;  
00238     case eColor__moz_fieldtext:
00239       aColor = NS_RGB(0x00, 0x00, 0x00);
00240       break;  
00241     case eColor__moz_dialog:
00242     case eColor__moz_cellhighlight:
00243       //all bars  including MenuBar
00244       aColor = NS_RGB(0xdd, 0xdd, 0xdd);
00245       break;  
00246     case eColor__moz_dialogtext:
00247     case eColor__moz_cellhighlighttext:
00248       aColor = NS_RGB(0x00, 0x00, 0x00);
00249       break;  
00250     case eColor__moz_dragtargetzone:
00251       aColor = NS_RGB(0x63, 0x63, 0xCE);
00252       break;
00253     case eColor__moz_buttondefault:
00254       aColor = NS_RGB(0x77, 0x77, 0x77);
00255       break;
00256     case eColor_LAST_COLOR:
00257     default:
00258       aColor = NS_RGB(0xff, 0xff, 0xff);
00259       res    = NS_ERROR_FAILURE;
00260       break;
00261   }
00262 
00263   return res;
00264 }
00265   
00266 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
00267 {
00268   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00269   if (NS_SUCCEEDED(res))
00270     return res;
00271   res = NS_OK;
00272 
00273   /*
00274    * There used to be an entirely separate list of these metrics in
00275    * nsDeviceContextBeOS::GetSystemAttribute.  The metrics given there
00276    * were a bit different from these.  If these are inaccurate, it might
00277    * be worth looking at cvs history for the ones there to see if they
00278    * were better.
00279    */
00280 
00281   switch (aID) 
00282   {
00283     case eMetric_WindowTitleHeight:
00284       // 2*horizontal scrollbar height
00285       aMetric = 28;
00286       break;
00287     case eMetric_WindowBorderWidth:
00288       aMetric = 2;
00289       break;
00290     case eMetric_WindowBorderHeight:
00291       aMetric = 2;
00292       break;
00293     case eMetric_Widget3DBorder:
00294       aMetric = 5;
00295       break;
00296     case eMetric_TextFieldBorder:
00297       aMetric = 3;
00298       break;
00299     case eMetric_TextFieldHeight:
00300       aMetric = 24;
00301       break;
00302     case eMetric_TextVerticalInsidePadding:
00303       aMetric = 0;
00304       break;    
00305     case eMetric_TextShouldUseVerticalInsidePadding:
00306       aMetric = 0;
00307       break;
00308     case eMetric_TextHorizontalInsideMinimumPadding:
00309       aMetric = 3;
00310       break;
00311     case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
00312       aMetric = 1;
00313       break;    
00314     case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
00315       aMetric = 10;
00316       break;
00317     case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
00318       aMetric = 8;
00319       break;
00320     case eMetric_CheckboxSize:
00321       aMetric = 12;
00322       break;
00323     case eMetric_RadioboxSize:
00324       aMetric = 12;
00325       break;
00326 
00327     case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
00328       aMetric = 0;
00329       break;
00330     case eMetric_ListHorizontalInsideMinimumPadding:
00331       aMetric = 3;
00332       break;
00333       
00334     case eMetric_ListShouldUseVerticalInsidePadding:
00335       aMetric = 0;
00336       break;
00337     case eMetric_ListVerticalInsidePadding:
00338       aMetric = 0;
00339       break;
00340       
00341     case eMetric_CaretBlinkTime:
00342       aMetric = 500;
00343       break;
00344     case eMetric_CaretWidth:
00345       aMetric = 1;
00346       break;
00347     case eMetric_ShowCaretDuringSelection:
00348       aMetric = 1;
00349       break;
00350     case eMetric_SelectTextfieldsOnKeyFocus:
00351       // Do not select textfield content when focused by kbd
00352       // used by nsEventStateManager::sTextfieldSelectModel
00353       aMetric = 0;
00354       break;
00355     case eMetric_SubmenuDelay:
00356       aMetric = 500;
00357       break;
00358     case eMetric_MenusCanOverlapOSBar: // can popups overlap menu/task bar?
00359       aMetric = 0;
00360       break;
00361     case eMetric_DragFullWindow:
00362       aMetric = 0;
00363       break;
00364     case eMetric_ScrollArrowStyle:
00365       {
00366         aMetric = eMetric_ScrollArrowStyleBothAtEachEnd; // BeOS default
00367 
00368         scroll_bar_info info;
00369         if(B_OK == get_scroll_bar_info(&info) && !info.double_arrows)
00370         {
00371           aMetric = eMetric_ScrollArrowStyleSingle;
00372         }
00373       }
00374       break;
00375     case eMetric_ScrollSliderStyle:
00376       {
00377         aMetric = eMetric_ScrollThumbStyleProportional; // BeOS default
00378 
00379         scroll_bar_info info;
00380         if(B_OK == get_scroll_bar_info(&info) && !info.proportional)
00381         {
00382           aMetric = eMetric_ScrollThumbStyleNormal;
00383         }
00384       }
00385       break;
00386     case eMetric_TreeOpenDelay:
00387       aMetric = 1000;
00388       break;
00389     case eMetric_TreeCloseDelay:
00390       aMetric = 1000;
00391       break;
00392     case eMetric_TreeLazyScrollDelay:
00393       aMetric = 150;
00394       break;
00395     case eMetric_TreeScrollDelay:
00396       aMetric = 100;
00397       break;
00398     case eMetric_TreeScrollLinesMax:
00399       aMetric = 3;
00400       break;
00401     default:
00402         aMetric = 0;
00403         res = NS_ERROR_FAILURE;
00404     }
00405   return res;
00406 }
00407 
00408 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
00409 {
00410   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00411   if (NS_SUCCEEDED(res))
00412     return res;
00413   res = NS_OK;
00414 
00415   switch (aID) {
00416     case eMetricFloat_TextFieldVerticalInsidePadding:
00417         aMetric = 0.25f;
00418         break;
00419     case eMetricFloat_TextFieldHorizontalInsidePadding:
00420         aMetric = 0.95f;
00421         break;
00422     case eMetricFloat_TextAreaVerticalInsidePadding:
00423         aMetric = 0.40f;
00424         break;
00425     case eMetricFloat_TextAreaHorizontalInsidePadding:
00426         aMetric = 0.40f;
00427         break;
00428     case eMetricFloat_ListVerticalInsidePadding:
00429         aMetric = 0.10f;
00430         break;
00431     case eMetricFloat_ListHorizontalInsidePadding:
00432         aMetric = 0.40f;
00433         break;
00434     case eMetricFloat_ButtonVerticalInsidePadding:
00435         aMetric = 0.25f;
00436         break;
00437     case eMetricFloat_ButtonHorizontalInsidePadding:
00438         aMetric = 0.25f;
00439         break;
00440     default:
00441         aMetric = -1.0;
00442         res = NS_ERROR_FAILURE;
00443     }
00444   return res;
00445 }