1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef __LookAndFeel
39 : #define __LookAndFeel
40 :
41 : #ifndef MOZILLA_INTERNAL_API
42 : #error "This header is only usable from within libxul (MOZILLA_INTERNAL_API)."
43 : #endif
44 :
45 : #include "nsDebug.h"
46 : #include "nsColor.h"
47 :
48 : struct gfxFontStyle;
49 :
50 : namespace mozilla {
51 :
52 : class LookAndFeel
53 : {
54 : public:
55 : // When modifying this list, also modify nsXPLookAndFeel::sColorPrefs
56 : // in widget/xpwidgts/nsXPLookAndFeel.cpp.
57 : enum ColorID {
58 :
59 : // WARNING : NO NEGATIVE VALUE IN THIS ENUMERATION
60 : // see patch in bug 57757 for more information
61 :
62 : eColorID_WindowBackground,
63 : eColorID_WindowForeground,
64 : eColorID_WidgetBackground,
65 : eColorID_WidgetForeground,
66 : eColorID_WidgetSelectBackground,
67 : eColorID_WidgetSelectForeground,
68 : eColorID_Widget3DHighlight,
69 : eColorID_Widget3DShadow,
70 : eColorID_TextBackground,
71 : eColorID_TextForeground,
72 : eColorID_TextSelectBackground,
73 : eColorID_TextSelectForeground,
74 : eColorID_TextSelectBackgroundDisabled,
75 : eColorID_TextSelectBackgroundAttention,
76 : eColorID_TextHighlightBackground,
77 : eColorID_TextHighlightForeground,
78 :
79 : eColorID_IMERawInputBackground,
80 : eColorID_IMERawInputForeground,
81 : eColorID_IMERawInputUnderline,
82 : eColorID_IMESelectedRawTextBackground,
83 : eColorID_IMESelectedRawTextForeground,
84 : eColorID_IMESelectedRawTextUnderline,
85 : eColorID_IMEConvertedTextBackground,
86 : eColorID_IMEConvertedTextForeground,
87 : eColorID_IMEConvertedTextUnderline,
88 : eColorID_IMESelectedConvertedTextBackground,
89 : eColorID_IMESelectedConvertedTextForeground,
90 : eColorID_IMESelectedConvertedTextUnderline,
91 :
92 : eColorID_SpellCheckerUnderline,
93 :
94 : // New CSS 2 color definitions
95 : eColorID_activeborder,
96 : eColorID_activecaption,
97 : eColorID_appworkspace,
98 : eColorID_background,
99 : eColorID_buttonface,
100 : eColorID_buttonhighlight,
101 : eColorID_buttonshadow,
102 : eColorID_buttontext,
103 : eColorID_captiontext,
104 : eColorID_graytext,
105 : eColorID_highlight,
106 : eColorID_highlighttext,
107 : eColorID_inactiveborder,
108 : eColorID_inactivecaption,
109 : eColorID_inactivecaptiontext,
110 : eColorID_infobackground,
111 : eColorID_infotext,
112 : eColorID_menu,
113 : eColorID_menutext,
114 : eColorID_scrollbar,
115 : eColorID_threeddarkshadow,
116 : eColorID_threedface,
117 : eColorID_threedhighlight,
118 : eColorID_threedlightshadow,
119 : eColorID_threedshadow,
120 : eColorID_window,
121 : eColorID_windowframe,
122 : eColorID_windowtext,
123 :
124 : eColorID__moz_buttondefault,
125 : // Colors which will hopefully become CSS3
126 : eColorID__moz_field,
127 : eColorID__moz_fieldtext,
128 : eColorID__moz_dialog,
129 : eColorID__moz_dialogtext,
130 : // used to highlight valid regions to drop something onto
131 : eColorID__moz_dragtargetzone,
132 :
133 : // used to cell text background, selected but not focus
134 : eColorID__moz_cellhighlight,
135 : // used to cell text, selected but not focus
136 : eColorID__moz_cellhighlighttext,
137 : // used to html select cell text background, selected but not focus
138 : eColorID__moz_html_cellhighlight,
139 : // used to html select cell text, selected but not focus
140 : eColorID__moz_html_cellhighlighttext,
141 : // used to button text background, when mouse is over
142 : eColorID__moz_buttonhoverface,
143 : // used to button text, when mouse is over
144 : eColorID__moz_buttonhovertext,
145 : // used to menu item background, when mouse is over
146 : eColorID__moz_menuhover,
147 : // used to menu item text, when mouse is over
148 : eColorID__moz_menuhovertext,
149 : // used to menu bar item text
150 : eColorID__moz_menubartext,
151 : // used to menu bar item text, when mouse is over
152 : eColorID__moz_menubarhovertext,
153 : // On platforms where these colors are the same as
154 : // -moz-field, use -moz-fieldtext as foreground color
155 : eColorID__moz_eventreerow,
156 : eColorID__moz_oddtreerow,
157 :
158 : // colors needed by the Mac OS X theme
159 :
160 : // background color of chrome toolbars in active windows
161 : eColorID__moz_mac_chrome_active,
162 : // background color of chrome toolbars in inactive windows
163 : eColorID__moz_mac_chrome_inactive,
164 : //ring around text fields and lists
165 : eColorID__moz_mac_focusring,
166 : //colour used when mouse is over a menu item
167 : eColorID__moz_mac_menuselect,
168 : //colour used to do shadows on menu items
169 : eColorID__moz_mac_menushadow,
170 : // color used to display text for disabled menu items
171 : eColorID__moz_mac_menutextdisable,
172 : //colour used to display text while mouse is over a menu item
173 : eColorID__moz_mac_menutextselect,
174 : // text color of disabled text on toolbars
175 : eColorID__moz_mac_disabledtoolbartext,
176 :
177 : //new in 10.2
178 :
179 : //active list highlight
180 : eColorID__moz_mac_alternateprimaryhighlight,
181 : //inactive light hightlight
182 : eColorID__moz_mac_secondaryhighlight,
183 :
184 : // vista rebars
185 :
186 : // media rebar text
187 : eColorID__moz_win_mediatext,
188 : // communications rebar text
189 : eColorID__moz_win_communicationstext,
190 :
191 : // Hyperlink color extracted from the system, not affected by the
192 : // browser.anchor_color user pref.
193 : // There is no OS-specified safe background color for this text,
194 : // but it is used regularly within Windows and the Gnome DE on Dialog and
195 : // Window colors.
196 : eColorID__moz_nativehyperlinktext,
197 :
198 : // Combo box widgets
199 : eColorID__moz_comboboxtext,
200 : eColorID__moz_combobox,
201 :
202 : // keep this one last, please
203 : eColorID_LAST_COLOR
204 : };
205 :
206 : // When modifying this list, also modify nsXPLookAndFeel::sIntPrefs
207 : // in widget/xpwidgts/nsXPLookAndFeel.cpp.
208 : enum IntID {
209 : // default, may be overriden by OS
210 : eIntID_CaretBlinkTime,
211 : // pixel width of caret
212 : eIntID_CaretWidth,
213 : // show the caret when text is selected?
214 : eIntID_ShowCaretDuringSelection,
215 : // select textfields when focused via tab/accesskey?
216 : eIntID_SelectTextfieldsOnKeyFocus,
217 : // delay before submenus open
218 : eIntID_SubmenuDelay,
219 : // can popups overlap menu/task bar?
220 : eIntID_MenusCanOverlapOSBar,
221 : // skip navigating to disabled menu item?
222 : eIntID_SkipNavigatingDisabledMenuItem,
223 : // begin a drag if the mouse is moved further than the threshold while the
224 : // button is down
225 : eIntID_DragThresholdX,
226 : eIntID_DragThresholdY,
227 : // Accessibility theme being used?
228 : eIntID_UseAccessibilityTheme,
229 :
230 : // position of scroll arrows in a scrollbar
231 : eIntID_ScrollArrowStyle,
232 : // is scroll thumb proportional or fixed?
233 : eIntID_ScrollSliderStyle,
234 :
235 : // each button can take one of four values:
236 : eIntID_ScrollButtonLeftMouseButtonAction,
237 : // 0 - scrolls one line, 1 - scrolls one page
238 : eIntID_ScrollButtonMiddleMouseButtonAction,
239 : // 2 - scrolls to end, 3 - button ignored
240 : eIntID_ScrollButtonRightMouseButtonAction,
241 :
242 : // delay for opening spring loaded folders
243 : eIntID_TreeOpenDelay,
244 : // delay for closing spring loaded folders
245 : eIntID_TreeCloseDelay,
246 : // delay for triggering the tree scrolling
247 : eIntID_TreeLazyScrollDelay,
248 : // delay for scrolling the tree
249 : eIntID_TreeScrollDelay,
250 : // the maximum number of lines to be scrolled at ones
251 : eIntID_TreeScrollLinesMax,
252 : // What type of tab-order to use
253 : eIntID_TabFocusModel,
254 : // Should menu items blink when they're chosen?
255 : eIntID_ChosenMenuItemsShouldBlink,
256 :
257 : /*
258 : * A Boolean value to determine whether the Windows default theme is
259 : * being used.
260 : *
261 : * The value of this metric is not used on other platforms. These platforms
262 : * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
263 : */
264 : eIntID_WindowsDefaultTheme,
265 :
266 : /*
267 : * A Boolean value to determine whether the DWM compositor is being used
268 : *
269 : * This metric is not used on non-Windows platforms. These platforms
270 : * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
271 : */
272 : eIntID_DWMCompositor,
273 :
274 : /*
275 : * A Boolean value to determine whether Windows is themed (Classic vs.
276 : * uxtheme)
277 : *
278 : * This is Windows-specific and is not implemented on other platforms
279 : * (will return the default of NS_ERROR_FAILURE).
280 : */
281 : eIntID_WindowsClassic,
282 :
283 : /*
284 : * A Boolean value to determine whether the device is a touch enabled
285 : * device. Currently this is only supported by the Windows 7 Touch API.
286 : *
287 : * Platforms that do not support this metric should return
288 : * NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
289 : */
290 : eIntID_TouchEnabled,
291 :
292 : /*
293 : * A Boolean value to determine whether the Mac graphite theme is
294 : * being used.
295 : *
296 : * The value of this metric is not used on other platforms. These platforms
297 : * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
298 : */
299 : eIntID_MacGraphiteTheme,
300 :
301 : /*
302 : * A Boolean value to determine whether the Mac OS X Lion-specific theming
303 : * should be used.
304 : *
305 : * The value of this metric is not used on non-Mac platforms. These
306 : * platforms should return NS_ERROR_NOT_IMPLEMENTED when queried for this
307 : * metric.
308 : */
309 : eIntID_MacLionTheme,
310 :
311 : /*
312 : * A Boolean value to determine whether Mameo is using the new Fremantle
313 : * theme.
314 : *
315 : * The value of this metric is not used on other platforms. These platforms
316 : * should return NS_ERROR_NOT_IMPLEMENTED when queried for this metric.
317 : */
318 : eIntID_MaemoClassic,
319 :
320 : /*
321 : * eIntID_AlertNotificationOrigin indicates from which corner of the
322 : * screen alerts slide in, and from which direction (horizontal/vertical).
323 : * 0, the default, represents bottom right, sliding vertically.
324 : * Use any bitwise combination of the following constants:
325 : * NS_ALERT_HORIZONTAL (1), NS_ALERT_LEFT (2), NS_ALERT_TOP (4).
326 : *
327 : * 6 4
328 : * +-----------+
329 : * 7| |5
330 : * | |
331 : * 3| |1
332 : * +-----------+
333 : * 2 0
334 : */
335 : eIntID_AlertNotificationOrigin,
336 :
337 : /**
338 : * If true, clicking on a scrollbar (not as in dragging the thumb) defaults
339 : * to scrolling the view corresponding to the clicked point. Otherwise, we
340 : * only do so if the scrollbar is clicked using the middle mouse button or
341 : * if shift is pressed when the scrollbar is clicked.
342 : */
343 : eIntID_ScrollToClick,
344 :
345 : /**
346 : * IME and spell checker underline styles, the values should be
347 : * NS_DECORATION_LINE_STYLE_*. They are defined below.
348 : */
349 : eIntID_IMERawInputUnderlineStyle,
350 : eIntID_IMESelectedRawTextUnderlineStyle,
351 : eIntID_IMEConvertedTextUnderlineStyle,
352 : eIntID_IMESelectedConvertedTextUnderline,
353 : eIntID_SpellCheckerUnderlineStyle,
354 :
355 : /**
356 : * If this metric != 0, show icons in menus.
357 : */
358 : eIntID_ImagesInMenus,
359 : /**
360 : * If this metric != 0, show icons in buttons.
361 : */
362 : eIntID_ImagesInButtons,
363 : /**
364 : * If this metric != 0, support window dragging on the menubar.
365 : */
366 : eIntID_MenuBarDrag,
367 : /**
368 : * Return the appropriate WindowsThemeIdentifier for the current theme.
369 : */
370 : eIntID_WindowsThemeIdentifier,
371 : /**
372 : * 0: scrollbar button repeats to scroll only when cursor is on the button.
373 : * 1: scrollbar button repeats to scroll even if cursor is outside of it.
374 : */
375 : eIntID_ScrollbarButtonAutoRepeatBehavior,
376 : /**
377 : * Dealy before showing a tooltip.
378 : */
379 : eIntID_TooltipDelay
380 : };
381 :
382 : /**
383 : * Windows themes we currently detect.
384 : */
385 : enum WindowsTheme {
386 : eWindowsTheme_Generic = 0, // unrecognized theme
387 : eWindowsTheme_Classic,
388 : eWindowsTheme_Aero,
389 : eWindowsTheme_LunaBlue,
390 : eWindowsTheme_LunaOlive,
391 : eWindowsTheme_LunaSilver,
392 : eWindowsTheme_Royale,
393 : eWindowsTheme_Zune
394 : };
395 :
396 : enum {
397 : eScrollArrow_None = 0,
398 : eScrollArrow_StartBackward = 0x1000,
399 : eScrollArrow_StartForward = 0x0100,
400 : eScrollArrow_EndBackward = 0x0010,
401 : eScrollArrow_EndForward = 0x0001
402 : };
403 :
404 : enum {
405 : // single arrow at each end
406 : eScrollArrowStyle_Single =
407 : eScrollArrow_StartBackward | eScrollArrow_EndForward,
408 : // both arrows at bottom/right, none at top/left
409 : eScrollArrowStyle_BothAtBottom =
410 : eScrollArrow_EndBackward | eScrollArrow_EndForward,
411 : // both arrows at both ends
412 : eScrollArrowStyle_BothAtEachEnd =
413 : eScrollArrow_EndBackward | eScrollArrow_EndForward |
414 : eScrollArrow_StartBackward | eScrollArrow_StartForward,
415 : // both arrows at top/left, none at bottom/right
416 : eScrollArrowStyle_BothAtTop =
417 : eScrollArrow_StartBackward | eScrollArrow_StartForward
418 : };
419 :
420 : enum {
421 : eScrollThumbStyle_Normal,
422 : eScrollThumbStyle_Proportional
423 : };
424 :
425 : // When modifying this list, also modify nsXPLookAndFeel::sFloatPrefs
426 : // in widget/xpwidgts/nsXPLookAndFeel.cpp.
427 : enum FloatID {
428 : eFloatID_IMEUnderlineRelativeSize,
429 : eFloatID_SpellCheckerUnderlineRelativeSize,
430 :
431 : // The width/height ratio of the cursor. If used, the CaretWidth int metric
432 : // should be added to the calculated caret width.
433 : eFloatID_CaretAspectRatio
434 : };
435 :
436 : // These constants must be kept in 1:1 correspondence with the
437 : // NS_STYLE_FONT_* system font constants.
438 : enum FontID {
439 : eFont_Caption = 1, // css2
440 : eFont_Icon,
441 : eFont_Menu,
442 : eFont_MessageBox,
443 : eFont_SmallCaption,
444 : eFont_StatusBar,
445 :
446 : eFont_Window, // css3
447 : eFont_Document,
448 : eFont_Workspace,
449 : eFont_Desktop,
450 : eFont_Info,
451 : eFont_Dialog,
452 : eFont_Button,
453 : eFont_PullDownMenu,
454 : eFont_List,
455 : eFont_Field,
456 :
457 : eFont_Tooltips, // moz
458 : eFont_Widget
459 : };
460 :
461 : /**
462 : * GetColor() return a native color value (might be overwritten by prefs) for
463 : * aID. Some platforms don't return an error even if the index doesn't
464 : * match any system colors. And also some platforms may initialize the
465 : * return value even when it returns an error. Therefore, if you want to
466 : * use a color for the default value, you should use the other GetColor()
467 : * which returns nscolor directly.
468 : *
469 : * NOTE:
470 : * eColorID_TextSelectForeground might return NS_DONT_CHANGE_COLOR.
471 : * eColorID_IME* might return NS_TRANSPARENT, NS_SAME_AS_FOREGROUND_COLOR or
472 : * NS_40PERCENT_FOREGROUND_COLOR.
473 : * These values have particular meaning. Then, they are not an actual
474 : * color value.
475 : */
476 : static nsresult GetColor(ColorID aID, nscolor* aResult);
477 :
478 : /**
479 : * GetInt() and GetFloat() return a int or float value for aID. The result
480 : * might be distance, time, some flags or a int value which has particular
481 : * meaning. See each document at definition of each ID for the detail.
482 : * The result is always 0 when they return error. Therefore, if you want to
483 : * use a value for the default value, you should use the other method which
484 : * returns int or float directly.
485 : */
486 : static nsresult GetInt(IntID aID, PRInt32* aResult);
487 : static nsresult GetFloat(FloatID aID, float* aResult);
488 :
489 0 : static nscolor GetColor(ColorID aID, nscolor aDefault = NS_RGB(0, 0, 0))
490 : {
491 0 : nscolor result = NS_RGB(0, 0, 0);
492 0 : if (NS_FAILED(GetColor(aID, &result))) {
493 0 : return aDefault;
494 : }
495 0 : return result;
496 : }
497 :
498 0 : static PRInt32 GetInt(IntID aID, PRInt32 aDefault = 0)
499 : {
500 : PRInt32 result;
501 0 : if (NS_FAILED(GetInt(aID, &result))) {
502 0 : return aDefault;
503 : }
504 0 : return result;
505 : }
506 :
507 0 : static float GetFloat(FloatID aID, float aDefault = 0.0f)
508 : {
509 : float result;
510 0 : if (NS_FAILED(GetFloat(aID, &result))) {
511 0 : return aDefault;
512 : }
513 0 : return result;
514 : }
515 :
516 : /**
517 : * Retrieve the name and style of a system-theme font. Returns true
518 : * if the system theme specifies this font, false if a default should
519 : * be used. In the latter case neither aName nor aStyle is modified.
520 : *
521 : * @param aID Which system-theme font is wanted.
522 : * @param aName The name of the font to use.
523 : * @param aStyle Styling to apply to the font.
524 : */
525 : static bool GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle);
526 :
527 : /**
528 : * GetPasswordCharacter() returns a unicode character which should be used
529 : * for a masked character in password editor. E.g., '*'.
530 : */
531 : static PRUnichar GetPasswordCharacter();
532 :
533 : /**
534 : * If the latest character in password field shouldn't be hidden by the
535 : * result of GetPasswordCharacter(), GetEchoPassword() returns TRUE.
536 : * Otherwise, FALSE.
537 : */
538 : static bool GetEchoPassword();
539 :
540 : /**
541 : * When system look and feel is changed, Refresh() must be called. Then,
542 : * cached data would be released.
543 : */
544 : static void Refresh();
545 : };
546 :
547 : } // namespace mozilla
548 :
549 : // On the Mac, GetColor(eColorID_TextSelectForeground, color) returns this
550 : // constant to specify that the foreground color should not be changed
551 : // (ie. a colored text keeps its colors when selected).
552 : // Of course if other plaforms work like the Mac, they can use it too.
553 : #define NS_DONT_CHANGE_COLOR NS_RGB(0x01, 0x01, 0x01)
554 :
555 : // ---------------------------------------------------------------------
556 : // Special colors for eColorID_IME* and eColorID_SpellCheckerUnderline
557 : // ---------------------------------------------------------------------
558 :
559 : // For background color only.
560 : #define NS_TRANSPARENT NS_RGBA(0x01, 0x00, 0x00, 0x00)
561 : // For foreground color only.
562 : #define NS_SAME_AS_FOREGROUND_COLOR NS_RGBA(0x02, 0x00, 0x00, 0x00)
563 : #define NS_40PERCENT_FOREGROUND_COLOR NS_RGBA(0x03, 0x00, 0x00, 0x00)
564 :
565 : #define NS_IS_SELECTION_SPECIAL_COLOR(c) ((c) == NS_TRANSPARENT || \
566 : (c) == NS_SAME_AS_FOREGROUND_COLOR || \
567 : (c) == NS_40PERCENT_FOREGROUND_COLOR)
568 :
569 : // ------------------------------------------
570 : // Bits for eIntID_AlertNotificationOrigin
571 : // ------------------------------------------
572 :
573 : #define NS_ALERT_HORIZONTAL 1
574 : #define NS_ALERT_LEFT 2
575 : #define NS_ALERT_TOP 4
576 :
577 : #endif /* __LookAndFeel */
|