1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #import <UIKit/UIColor.h>
7 #import <UIKit/UIInterface.h>
9 #include "nsLookAndFeel.h"
11 #include "mozilla/FontPropertyTypes.h"
12 #include "nsStyleConsts.h"
14 #include "gfxFontConstants.h"
16 nsLookAndFeel::nsLookAndFeel() : mInitialized(false) {}
18 nsLookAndFeel::~nsLookAndFeel() {}
20 static nscolor GetColorFromUIColor(UIColor* aColor) {
21 CGColorRef cgColor = [aColor CGColor];
22 CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgColor));
23 const CGFloat* components = CGColorGetComponents(cgColor);
24 if (model == kCGColorSpaceModelRGB) {
25 return NS_RGB((unsigned int)(components[0] * 255.0), (unsigned int)(components[1] * 255.0),
26 (unsigned int)(components[2] * 255.0));
27 } else if (model == kCGColorSpaceModelMonochrome) {
28 unsigned int val = (unsigned int)(components[0] * 255.0);
29 return NS_RGBA(val, val, val, (unsigned int)(components[1] * 255.0));
31 MOZ_ASSERT_UNREACHABLE("Unhandled color space!");
35 void nsLookAndFeel::NativeInit() { EnsureInit(); }
37 void nsLookAndFeel::RefreshImpl() {
38 nsXPLookAndFeel::RefreshImpl();
43 nsresult nsLookAndFeel::NativeGetColor(ColorID, ColorScheme, nscolor& aResult) {
49 case ColorID::Highlight:
50 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
52 case ColorID::MozMenuhover:
53 aResult = NS_RGB(0xee, 0xee, 0xee);
55 case ColorID::Highlighttext:
56 case ColorID::MozMenuhovertext:
57 aResult = mColorTextSelectForeground;
59 case ColorID::IMESelectedRawTextBackground:
60 case ColorID::IMESelectedConvertedTextBackground:
61 case ColorID::IMERawInputBackground:
62 case ColorID::IMEConvertedTextBackground:
63 aResult = NS_TRANSPARENT;
65 case ColorID::IMESelectedRawTextForeground:
66 case ColorID::IMESelectedConvertedTextForeground:
67 case ColorID::IMERawInputForeground:
68 case ColorID::IMEConvertedTextForeground:
69 aResult = NS_SAME_AS_FOREGROUND_COLOR;
71 case ColorID::IMERawInputUnderline:
72 case ColorID::IMEConvertedTextUnderline:
73 aResult = NS_40PERCENT_FOREGROUND_COLOR;
75 case ColorID::IMESelectedRawTextUnderline:
76 case ColorID::IMESelectedConvertedTextUnderline:
77 aResult = NS_SAME_AS_FOREGROUND_COLOR;
79 case ColorID::SpellCheckerUnderline:
80 aResult = NS_RGB(0xff, 0, 0);
84 // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
86 case ColorID::Buttontext:
87 case ColorID::MozButtonhovertext:
88 case ColorID::Captiontext:
89 case ColorID::Menutext:
90 case ColorID::Infotext:
91 case ColorID::MozMenubartext:
92 case ColorID::Windowtext:
93 aResult = mColorDarkText;
95 case ColorID::Activecaption:
96 aResult = NS_RGB(0xff, 0xff, 0xff);
98 case ColorID::Activeborder:
99 aResult = NS_RGB(0x00, 0x00, 0x00);
101 case ColorID::Appworkspace:
102 aResult = NS_RGB(0xFF, 0xFF, 0xFF);
104 case ColorID::Background:
105 aResult = NS_RGB(0x63, 0x63, 0xCE);
107 case ColorID::Buttonface:
108 case ColorID::MozButtonhoverface:
109 aResult = NS_RGB(0xF0, 0xF0, 0xF0);
111 case ColorID::Buttonhighlight:
112 aResult = NS_RGB(0xFF, 0xFF, 0xFF);
114 case ColorID::Buttonshadow:
115 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
117 case ColorID::Graytext:
118 aResult = NS_RGB(0x44, 0x44, 0x44);
120 case ColorID::Inactiveborder:
121 aResult = NS_RGB(0xff, 0xff, 0xff);
123 case ColorID::Inactivecaption:
124 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
126 case ColorID::Inactivecaptiontext:
127 aResult = NS_RGB(0x45, 0x45, 0x45);
129 case ColorID::Scrollbar:
130 aResult = NS_RGB(0, 0, 0); // XXX
132 case ColorID::Threeddarkshadow:
133 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
135 case ColorID::Threedshadow:
136 aResult = NS_RGB(0xE0, 0xE0, 0xE0);
138 case ColorID::Threedface:
139 aResult = NS_RGB(0xF0, 0xF0, 0xF0);
141 case ColorID::Threedhighlight:
142 aResult = NS_RGB(0xff, 0xff, 0xff);
144 case ColorID::Threedlightshadow:
145 aResult = NS_RGB(0xDA, 0xDA, 0xDA);
148 aResult = NS_RGB(0xff, 0xff, 0xff);
150 case ColorID::Infobackground:
151 aResult = NS_RGB(0xFF, 0xFF, 0xC7);
153 case ColorID::Windowframe:
154 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
156 case ColorID::Window:
157 case ColorID::MozField:
158 case ColorID::MozCombobox:
159 aResult = NS_RGB(0xff, 0xff, 0xff);
161 case ColorID::MozFieldtext:
162 case ColorID::MozComboboxtext:
163 aResult = mColorDarkText;
165 case ColorID::MozDialog:
166 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
168 case ColorID::MozDialogtext:
169 case ColorID::MozCellhighlighttext:
170 case ColorID::Selecteditemtext:
171 case ColorID::MozColheadertext:
172 case ColorID::MozColheaderhovertext:
173 aResult = mColorDarkText;
175 case ColorID::MozDragtargetzone:
176 case ColorID::MozMacChromeActive:
177 case ColorID::MozMacChromeInactive:
178 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
180 case ColorID::MozMacFocusring:
181 aResult = NS_RGB(0x3F, 0x98, 0xDD);
183 case ColorID::MozMacMenushadow:
184 aResult = NS_RGB(0xA3, 0xA3, 0xA3);
186 case ColorID::MozMacMenutextdisable:
187 aResult = NS_RGB(0x88, 0x88, 0x88);
189 case ColorID::MozMacMenutextselect:
190 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
192 case ColorID::MozMacDisabledtoolbartext:
193 aResult = NS_RGB(0x3F, 0x3F, 0x3F);
195 case ColorID::MozMacMenuselect:
196 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
198 case ColorID::MozButtondefault:
199 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
201 case ColorID::MozCellhighlight:
202 case ColorID::Selecteditem:
203 case ColorID::MozMacSecondaryhighlight:
204 // For inactive list selection
205 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
207 case ColorID::MozEventreerow:
208 // Background color of even list rows.
209 aResult = NS_RGB(0xff, 0xff, 0xff);
211 case ColorID::MozOddtreerow:
212 // Background color of odd list rows.
213 aResult = NS_TRANSPARENT;
215 case ColorID::MozNativehyperlinktext:
216 // There appears to be no available system defined color. HARDCODING to the appropriate color.
217 aResult = NS_RGB(0x14, 0x4F, 0xAE);
219 case ColorID::MozNativevisitedhyperlinktext:
220 // Safari defaults to the MacOS color implementation for visited links, which in turn uses
221 // systemPurpleColor, so we do the same here.
222 aResult = GetColorFromUIColor([UIColor systemPurpleColor]);
225 NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
226 aResult = NS_RGB(0xff, 0xff, 0xff);
227 res = NS_ERROR_FAILURE;
235 nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
236 nsresult res = NS_OK;
239 case IntID::ScrollButtonLeftMouseButtonAction:
242 case IntID::ScrollButtonMiddleMouseButtonAction:
243 case IntID::ScrollButtonRightMouseButtonAction:
246 case IntID::CaretBlinkTime:
249 case IntID::CaretWidth:
252 case IntID::ShowCaretDuringSelection:
255 case IntID::SelectTextfieldsOnKeyFocus:
256 // Select textfield content when focused by kbd
257 // used by nsEventStateManager::sTextfieldSelectModel
260 case IntID::SubmenuDelay:
263 case IntID::MenusCanOverlapOSBar:
264 // xul popups are not allowed to overlap the menubar.
267 case IntID::SkipNavigatingDisabledMenuItem:
270 case IntID::DragThresholdX:
271 case IntID::DragThresholdY:
274 case IntID::ScrollArrowStyle:
275 aResult = eScrollArrow_None;
277 case IntID::TreeOpenDelay:
280 case IntID::TreeCloseDelay:
283 case IntID::TreeLazyScrollDelay:
286 case IntID::TreeScrollDelay:
289 case IntID::TreeScrollLinesMax:
292 case IntID::DWMCompositor:
293 case IntID::WindowsClassic:
294 case IntID::WindowsDefaultTheme:
296 res = NS_ERROR_NOT_IMPLEMENTED;
298 case IntID::MacGraphiteTheme:
301 case IntID::TabFocusModel:
302 aResult = 1; // default to just textboxes
304 case IntID::ScrollToClick:
307 case IntID::ChosenMenuItemsShouldBlink:
310 case IntID::IMERawInputUnderlineStyle:
311 case IntID::IMEConvertedTextUnderlineStyle:
312 case IntID::IMESelectedRawTextUnderlineStyle:
313 case IntID::IMESelectedConvertedTextUnderline:
314 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
316 case IntID::SpellCheckerUnderlineStyle:
317 aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
319 case IntID::ContextMenuOffsetVertical:
320 case IntID::ContextMenuOffsetHorizontal:
325 res = NS_ERROR_FAILURE;
331 nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
332 nsresult res = NS_OK;
335 case FloatID::IMEUnderlineRelativeSize:
338 case FloatID::SpellCheckerUnderlineRelativeSize:
343 res = NS_ERROR_FAILURE;
349 bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) {
351 if (aID == FontID::Window || aID == FontID::Document) {
352 aFontStyle.style = FontSlantStyle::Normal();
353 aFontStyle.weight = FontWeight::Normal();
354 aFontStyle.stretch = FontStretch::Normal();
355 aFontStyle.size = 14;
356 aFontStyle.systemFont = true;
358 aFontName.AssignLiteral("sans-serif");
362 // TODO: implement more here?
366 void nsLookAndFeel::EnsureInit() {
373 GetColor(ColorID::TextSelectBackground, color);
374 if (color == 0x000000) {
375 mColorTextSelectForeground = NS_RGB(0xff, 0xff, 0xff);
377 mColorTextSelectForeground = NS_SAME_AS_FOREGROUND_COLOR;
380 mColorDarkText = GetColorFromUIColor([UIColor darkTextColor]);