1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsLookAndFeel.h"
42 #define PH_TO_NS_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
44 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
48 nsLookAndFeel::~nsLookAndFeel()
52 nsresult
nsLookAndFeel::NativeGetColor(const nsColorID aID
, nscolor
&aColor
)
57 * There used to be an entirely separate list of these colors in
58 * nsDeviceContextPh::GetSystemAttribute. The colors given there
59 * were a bit different from these. If these are inaccurate, it might
60 * be worth looking at cvs history for the ones there to see if they
66 case eColor_WindowBackground
:
67 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
69 case eColor_WindowForeground
:
70 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
72 case eColor_WidgetBackground
:
73 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
75 case eColor_WidgetForeground
:
76 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
78 case eColor_WidgetSelectBackground
:
79 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
81 case eColor_WidgetSelectForeground
:
82 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
84 case eColor_Widget3DHighlight
:
85 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
87 case eColor_Widget3DShadow
:
88 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
90 case eColor_TextBackground
:
91 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
93 case eColor_TextForeground
:
94 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
96 case eColor_TextSelectBackground
:
97 case eColor_IMESelectedRawTextBackground
:
98 case eColor_IMESelectedConvertedTextBackground
:
99 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
101 case eColor_TextSelectForeground
:
102 case eColor_IMESelectedRawTextForeground
:
103 case eColor_IMESelectedConvertedTextForeground
:
104 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
106 case eColor_IMERawInputBackground
:
107 case eColor_IMEConvertedTextBackground
:
108 aColor
= NS_TRANSPARENT
;
110 case eColor_IMERawInputForeground
:
111 case eColor_IMEConvertedTextForeground
:
112 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
114 case eColor_IMERawInputUnderline
:
115 case eColor_IMEConvertedTextUnderline
:
116 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
118 case eColor_IMESelectedRawTextUnderline
:
119 case eColor_IMESelectedConvertedTextUnderline
:
120 aColor
= NS_TRANSPARENT
;
123 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
124 case eColor_activeborder
:
125 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
127 case eColor_activecaption
:
128 aColor
= PH_TO_NS_RGB(Pg_YELLOW
);
130 case eColor_appworkspace
:
131 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
133 case eColor_background
:
134 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
136 case eColor_captiontext
:
137 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
139 case eColor_graytext
:
140 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
142 case eColor_highlight
:
143 case eColor__moz_html_cellhighlight
:
144 case eColor__moz_menuhover
:
145 aColor
= PH_TO_NS_RGB(0x9ba9c9); // bill blue
147 case eColor_highlighttext
:
148 case eColor__moz_html_cellhighlighttext
:
149 case eColor__moz_menuhovertext
:
150 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
152 case eColor_inactiveborder
:
153 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
155 case eColor_inactivecaption
:
156 aColor
= PH_TO_NS_RGB(Pg_GREY
);
158 case eColor_inactivecaptiontext
:
159 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
161 case eColor_infobackground
:
162 aColor
= PH_TO_NS_RGB(Pg_BALLOONCOLOR
); // popup yellow
164 case eColor_infotext
:
165 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
168 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
170 case eColor_menutext
:
171 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
173 case eColor_scrollbar
:
174 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
176 case eColor_threedface
:
177 case eColor_buttonface
:
178 case eColor__moz_buttonhoverface
:
179 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
182 case eColor_buttonhighlight
:
183 case eColor_threedhighlight
:
184 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
187 case eColor_buttontext
:
188 case eColor__moz_buttonhovertext
:
189 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
192 case eColor_buttonshadow
:
193 case eColor_threedshadow
: // i think these should be the same
194 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
197 case eColor_threeddarkshadow
:
198 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
201 case eColor_threedlightshadow
:
202 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
206 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
209 case eColor_windowframe
:
210 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
213 case eColor_windowtext
:
214 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
217 case eColor__moz_eventreerow
:
218 case eColor__moz_oddtreerow
:
219 case eColor__moz_field
:
220 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
223 case eColor__moz_fieldtext
:
224 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
227 case eColor__moz_dialog
:
228 case eColor__moz_cellhighlight
:
229 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
232 case eColor__moz_dialogtext
:
233 case eColor__moz_cellhighlighttext
:
234 aColor
= PH_TO_NS_RGB(Pg_BLACK
);
237 case eColor__moz_dragtargetzone
:
238 aColor
= PH_TO_NS_RGB(Pg_LGREY
);
241 case eColor__moz_buttondefault
:
242 aColor
= PH_TO_NS_RGB(Pg_DGREY
);
246 aColor
= PH_TO_NS_RGB(Pg_WHITE
);
253 NS_IMETHODIMP
nsLookAndFeel::GetMetric(const nsMetricID aID
, PRInt32
& aMetric
)
257 nsresult res
= nsXPLookAndFeel::GetMetric(aID
, aMetric
);
258 if (NS_SUCCEEDED(res
))
264 * There used to be an entirely separate list of these metrics in
265 * nsDeviceContextPh::GetSystemAttribute. The metrics given there
266 * were a bit different from these. If these are inaccurate, it might
267 * be worth looking at cvs history for the ones there to see if they
273 case eMetric_WindowTitleHeight
:
276 case eMetric_WindowBorderWidth
:
279 case eMetric_WindowBorderHeight
:
282 case eMetric_Widget3DBorder
:
285 case eMetric_TextFieldHeight
:
288 case eMetric_TextFieldBorder
:
291 case eMetric_TextVerticalInsidePadding
:
294 case eMetric_TextShouldUseVerticalInsidePadding
:
297 case eMetric_TextHorizontalInsideMinimumPadding
:
300 case eMetric_TextShouldUseHorizontalInsideMinimumPadding
:
303 case eMetric_ButtonHorizontalInsidePaddingNavQuirks
:
306 case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks
:
309 case eMetric_CheckboxSize
:
312 case eMetric_RadioboxSize
:
315 case eMetric_ListShouldUseHorizontalInsideMinimumPadding
:
318 case eMetric_ListHorizontalInsideMinimumPadding
:
321 case eMetric_ListShouldUseVerticalInsidePadding
:
324 case eMetric_ListVerticalInsidePadding
:
327 case eMetric_CaretBlinkTime
:
330 case eMetric_CaretWidth
:
333 case eMetric_ShowCaretDuringSelection
:
336 case eMetric_SelectTextfieldsOnKeyFocus
:
337 // Select textfield content when focused by kbd
338 // used by nsEventStateManager::sTextfieldSelectModel
341 case eMetric_SubmenuDelay
:
344 case eMetric_MenusCanOverlapOSBar
:
345 // we want XUL popups to be able to overlap the task bar.
348 case eMetric_DragFullWindow
:
351 case eMetric_TreeOpenDelay
:
354 case eMetric_TreeCloseDelay
:
357 case eMetric_TreeLazyScrollDelay
:
360 case eMetric_TreeScrollDelay
:
363 case eMetric_TreeScrollLinesMax
:
366 case eMetric_DWMCompositor
:
367 case eMetric_WindowsClassic
:
368 case eMetric_WindowsDefaultTheme
:
370 res
= NS_ERROR_NOT_IMPLEMENTED
;
372 case eMetric_MacGraphiteTheme
:
374 res
= NS_ERROR_NOT_IMPLEMENTED
;
376 case eMetric_IMERawInputUnderlineStyle
:
377 case eMetric_IMEConvertedTextUnderlineStyle
:
378 aMetric
= NS_UNDERLINE_STYLE_SOLID
;
380 case eMetric_IMESelectedRawTextUnderlineStyle
:
381 case eMetric_IMESelectedConvertedTextUnderline
:
382 aMetric
= NS_UNDERLINE_STYLE_NONE
;
387 res
= NS_ERROR_FAILURE
;
393 NS_IMETHODIMP
nsLookAndFeel::GetMetric(const nsMetricFloatID aID
, float & aMetric
)
396 nsresult res
= nsXPLookAndFeel::GetMetric(aID
, aMetric
);
397 if (NS_SUCCEEDED(res
))
403 case eMetricFloat_TextFieldVerticalInsidePadding
:
406 case eMetricFloat_TextFieldHorizontalInsidePadding
:
407 aMetric
= 0.95f
; // large number on purpose so minimum padding is used
409 case eMetricFloat_TextAreaVerticalInsidePadding
:
412 case eMetricFloat_TextAreaHorizontalInsidePadding
:
413 aMetric
= 0.40f
; // large number on purpose so minimum padding is used
415 case eMetricFloat_ListVerticalInsidePadding
:
418 case eMetricFloat_ListHorizontalInsidePadding
:
421 case eMetricFloat_ButtonVerticalInsidePadding
:
424 case eMetricFloat_ButtonHorizontalInsidePadding
:
427 case eMetricFloat_IMEUnderlineRelativeSize
:
432 res
= NS_ERROR_FAILURE
;