Add copy of .ttf font with .eot extension for testing
[wine-gecko.git] / widget / src / photon / nsLookAndFeel.cpp
blob6d22a0a461d5708f39629d47614e33278fdddaad
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
13 * License.
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.
22 * Contributor(s):
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"
39 #include <Pt.h>
40 #include "nsFont.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)
54 nsresult res = NS_OK;
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
61 * were better.
64 switch (aID)
66 case eColor_WindowBackground:
67 aColor = PH_TO_NS_RGB(Pg_LGREY);
68 break;
69 case eColor_WindowForeground:
70 aColor = PH_TO_NS_RGB(Pg_DGREY);
71 break;
72 case eColor_WidgetBackground:
73 aColor = PH_TO_NS_RGB(Pg_LGREY);
74 break;
75 case eColor_WidgetForeground:
76 aColor = PH_TO_NS_RGB(Pg_DGREY);
77 break;
78 case eColor_WidgetSelectBackground:
79 aColor = PH_TO_NS_RGB(Pg_DGREY);
80 break;
81 case eColor_WidgetSelectForeground:
82 aColor = PH_TO_NS_RGB(Pg_DGREY);
83 break;
84 case eColor_Widget3DHighlight:
85 aColor = PH_TO_NS_RGB(Pg_WHITE);
86 break;
87 case eColor_Widget3DShadow:
88 aColor = PH_TO_NS_RGB(Pg_DGREY);
89 break;
90 case eColor_TextBackground:
91 aColor = PH_TO_NS_RGB(Pg_WHITE);
92 break;
93 case eColor_TextForeground:
94 aColor = PH_TO_NS_RGB(Pg_BLACK);
95 break;
96 case eColor_TextSelectBackground:
97 case eColor_IMESelectedRawTextBackground:
98 case eColor_IMESelectedConvertedTextBackground:
99 aColor = PH_TO_NS_RGB(Pg_BLACK);
100 break;
101 case eColor_TextSelectForeground:
102 case eColor_IMESelectedRawTextForeground:
103 case eColor_IMESelectedConvertedTextForeground:
104 aColor = PH_TO_NS_RGB(Pg_WHITE);
105 break;
106 case eColor_IMERawInputBackground:
107 case eColor_IMEConvertedTextBackground:
108 aColor = NS_TRANSPARENT;
109 break;
110 case eColor_IMERawInputForeground:
111 case eColor_IMEConvertedTextForeground:
112 aColor = NS_SAME_AS_FOREGROUND_COLOR;
113 break;
114 case eColor_IMERawInputUnderline:
115 case eColor_IMEConvertedTextUnderline:
116 aColor = NS_SAME_AS_FOREGROUND_COLOR;
117 break;
118 case eColor_IMESelectedRawTextUnderline:
119 case eColor_IMESelectedConvertedTextUnderline:
120 aColor = NS_TRANSPARENT;
121 break;
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);
126 break;
127 case eColor_activecaption:
128 aColor = PH_TO_NS_RGB(Pg_YELLOW);
129 break;
130 case eColor_appworkspace:
131 aColor = PH_TO_NS_RGB(Pg_LGREY);
132 break;
133 case eColor_background:
134 aColor = PH_TO_NS_RGB(Pg_LGREY);
135 break;
136 case eColor_captiontext:
137 aColor = PH_TO_NS_RGB(Pg_BLACK);
138 break;
139 case eColor_graytext:
140 aColor = PH_TO_NS_RGB(Pg_DGREY);
141 break;
142 case eColor_highlight:
143 case eColor__moz_html_cellhighlight:
144 case eColor__moz_menuhover:
145 aColor = PH_TO_NS_RGB(0x9ba9c9); // bill blue
146 break;
147 case eColor_highlighttext:
148 case eColor__moz_html_cellhighlighttext:
149 case eColor__moz_menuhovertext:
150 aColor = PH_TO_NS_RGB(Pg_BLACK);
151 break;
152 case eColor_inactiveborder:
153 aColor = PH_TO_NS_RGB(Pg_DGREY);
154 break;
155 case eColor_inactivecaption:
156 aColor = PH_TO_NS_RGB(Pg_GREY);
157 break;
158 case eColor_inactivecaptiontext:
159 aColor = PH_TO_NS_RGB(Pg_DGREY);
160 break;
161 case eColor_infobackground:
162 aColor = PH_TO_NS_RGB(Pg_BALLOONCOLOR); // popup yellow
163 break;
164 case eColor_infotext:
165 aColor = PH_TO_NS_RGB(Pg_BLACK);
166 break;
167 case eColor_menu:
168 aColor = PH_TO_NS_RGB(Pg_LGREY);
169 break;
170 case eColor_menutext:
171 aColor = PH_TO_NS_RGB(Pg_BLACK);
172 break;
173 case eColor_scrollbar:
174 aColor = PH_TO_NS_RGB(Pg_LGREY);
175 break;
176 case eColor_threedface:
177 case eColor_buttonface:
178 case eColor__moz_buttonhoverface:
179 aColor = PH_TO_NS_RGB(Pg_LGREY);
180 break;
182 case eColor_buttonhighlight:
183 case eColor_threedhighlight:
184 aColor = PH_TO_NS_RGB(Pg_WHITE);
185 break;
187 case eColor_buttontext:
188 case eColor__moz_buttonhovertext:
189 aColor = PH_TO_NS_RGB(Pg_BLACK);
190 break;
192 case eColor_buttonshadow:
193 case eColor_threedshadow: // i think these should be the same
194 aColor = PH_TO_NS_RGB(Pg_DGREY);
195 break;
197 case eColor_threeddarkshadow:
198 aColor = PH_TO_NS_RGB(Pg_DGREY);
199 break;
201 case eColor_threedlightshadow:
202 aColor = PH_TO_NS_RGB(Pg_LGREY);
203 break;
205 case eColor_window:
206 aColor = PH_TO_NS_RGB(Pg_WHITE);
207 break;
209 case eColor_windowframe:
210 aColor = PH_TO_NS_RGB(Pg_LGREY);
211 break;
213 case eColor_windowtext:
214 aColor = PH_TO_NS_RGB(Pg_BLACK);
215 break;
217 case eColor__moz_eventreerow:
218 case eColor__moz_oddtreerow:
219 case eColor__moz_field:
220 aColor = PH_TO_NS_RGB(Pg_WHITE);
221 break;
223 case eColor__moz_fieldtext:
224 aColor = PH_TO_NS_RGB(Pg_BLACK);
225 break;
227 case eColor__moz_dialog:
228 case eColor__moz_cellhighlight:
229 aColor = PH_TO_NS_RGB(Pg_LGREY);
230 break;
232 case eColor__moz_dialogtext:
233 case eColor__moz_cellhighlighttext:
234 aColor = PH_TO_NS_RGB(Pg_BLACK);
235 break;
237 case eColor__moz_dragtargetzone:
238 aColor = PH_TO_NS_RGB(Pg_LGREY);
239 break;
241 case eColor__moz_buttondefault:
242 aColor = PH_TO_NS_RGB(Pg_DGREY);
243 break;
245 default:
246 aColor = PH_TO_NS_RGB(Pg_WHITE);
247 break;
250 return res;
253 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
257 nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
258 if (NS_SUCCEEDED(res))
259 return res;
261 res = NS_OK;
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
268 * were better.
271 switch (aID)
273 case eMetric_WindowTitleHeight:
274 aMetric = 0;
275 break;
276 case eMetric_WindowBorderWidth:
277 aMetric = 1;
278 break;
279 case eMetric_WindowBorderHeight:
280 aMetric = 1;
281 break;
282 case eMetric_Widget3DBorder:
283 aMetric = 2;
284 break;
285 case eMetric_TextFieldHeight:
286 aMetric = 20;
287 break;
288 case eMetric_TextFieldBorder:
289 aMetric = 1;
290 break;
291 case eMetric_TextVerticalInsidePadding:
292 aMetric = 0;
293 break;
294 case eMetric_TextShouldUseVerticalInsidePadding:
295 aMetric = 0;
296 break;
297 case eMetric_TextHorizontalInsideMinimumPadding:
298 aMetric = 0;
299 break;
300 case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
301 aMetric = 0;
302 break;
303 case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
304 aMetric = 10;
305 break;
306 case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
307 aMetric = 8;
308 break;
309 case eMetric_CheckboxSize:
310 aMetric = 10;
311 break;
312 case eMetric_RadioboxSize:
313 aMetric = 10;
314 break;
315 case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
316 aMetric = 0;
317 break;
318 case eMetric_ListHorizontalInsideMinimumPadding:
319 aMetric = 0;
320 break;
321 case eMetric_ListShouldUseVerticalInsidePadding:
322 aMetric = 0;
323 break;
324 case eMetric_ListVerticalInsidePadding:
325 aMetric = 0;
326 break;
327 case eMetric_CaretBlinkTime:
328 aMetric = 500;
329 break;
330 case eMetric_CaretWidth:
331 aMetric = 1;
332 break;
333 case eMetric_ShowCaretDuringSelection:
334 aMetric = 0;
335 break;
336 case eMetric_SelectTextfieldsOnKeyFocus:
337 // Select textfield content when focused by kbd
338 // used by nsEventStateManager::sTextfieldSelectModel
339 aMetric = 1;
340 break;
341 case eMetric_SubmenuDelay:
342 aMetric = 200;
343 break;
344 case eMetric_MenusCanOverlapOSBar:
345 // we want XUL popups to be able to overlap the task bar.
346 aMetric = 1;
347 break;
348 case eMetric_DragFullWindow:
349 aMetric = 1;
350 break;
351 case eMetric_TreeOpenDelay:
352 aMetric = 1000;
353 break;
354 case eMetric_TreeCloseDelay:
355 aMetric = 1000;
356 break;
357 case eMetric_TreeLazyScrollDelay:
358 aMetric = 150;
359 break;
360 case eMetric_TreeScrollDelay:
361 aMetric = 100;
362 break;
363 case eMetric_TreeScrollLinesMax:
364 aMetric = 3;
365 break;
366 case eMetric_DWMCompositor:
367 case eMetric_WindowsClassic:
368 case eMetric_WindowsDefaultTheme:
369 aMetric = 0;
370 res = NS_ERROR_NOT_IMPLEMENTED;
371 break;
372 case eMetric_MacGraphiteTheme:
373 aMetric = 0;
374 res = NS_ERROR_NOT_IMPLEMENTED;
375 break;
376 case eMetric_IMERawInputUnderlineStyle:
377 case eMetric_IMEConvertedTextUnderlineStyle:
378 aMetric = NS_UNDERLINE_STYLE_SOLID;
379 break;
380 case eMetric_IMESelectedRawTextUnderlineStyle:
381 case eMetric_IMESelectedConvertedTextUnderline:
382 aMetric = NS_UNDERLINE_STYLE_NONE;
383 break;
385 default:
386 aMetric = 0;
387 res = NS_ERROR_FAILURE;
390 return res;
393 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
396 nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
397 if (NS_SUCCEEDED(res))
398 return res;
400 res = NS_OK;
402 switch (aID) {
403 case eMetricFloat_TextFieldVerticalInsidePadding:
404 aMetric = 0.25f;
405 break;
406 case eMetricFloat_TextFieldHorizontalInsidePadding:
407 aMetric = 0.95f; // large number on purpose so minimum padding is used
408 break;
409 case eMetricFloat_TextAreaVerticalInsidePadding:
410 aMetric = 0.40f;
411 break;
412 case eMetricFloat_TextAreaHorizontalInsidePadding:
413 aMetric = 0.40f; // large number on purpose so minimum padding is used
414 break;
415 case eMetricFloat_ListVerticalInsidePadding:
416 aMetric = 0.10f;
417 break;
418 case eMetricFloat_ListHorizontalInsidePadding:
419 aMetric = 0.40f;
420 break;
421 case eMetricFloat_ButtonVerticalInsidePadding:
422 aMetric = 0.25f;
423 break;
424 case eMetricFloat_ButtonHorizontalInsidePadding:
425 aMetric = 0.25f;
426 break;
427 case eMetricFloat_IMEUnderlineRelativeSize:
428 aMetric = 1.0f;
429 break;
430 default:
431 aMetric = -1.0;
432 res = NS_ERROR_FAILURE;
435 return res;