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() : nsXPLookAndFeel(), 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(const ColorID aID, nscolor& aResult) {
49 case ColorID::WindowBackground:
50 aResult = NS_RGB(0xff, 0xff, 0xff);
52 case ColorID::WindowForeground:
53 aResult = NS_RGB(0x00, 0x00, 0x00);
55 case ColorID::WidgetBackground:
56 aResult = NS_RGB(0xdd, 0xdd, 0xdd);
58 case ColorID::WidgetForeground:
59 aResult = NS_RGB(0x00, 0x00, 0x00);
61 case ColorID::WidgetSelectBackground:
62 aResult = NS_RGB(0x80, 0x80, 0x80);
64 case ColorID::WidgetSelectForeground:
65 aResult = NS_RGB(0x00, 0x00, 0x80);
67 case ColorID::Widget3DHighlight:
68 aResult = NS_RGB(0xa0, 0xa0, 0xa0);
70 case ColorID::Widget3DShadow:
71 aResult = NS_RGB(0x40, 0x40, 0x40);
73 case ColorID::TextBackground:
74 aResult = NS_RGB(0xff, 0xff, 0xff);
76 case ColorID::TextForeground:
77 aResult = NS_RGB(0x00, 0x00, 0x00);
79 case ColorID::TextSelectBackground:
80 case ColorID::Highlight: // CSS2 color
81 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
83 case ColorID::MozMenuhover:
84 aResult = NS_RGB(0xee, 0xee, 0xee);
86 case ColorID::TextSelectForeground:
87 case ColorID::Highlighttext: // CSS2 color
88 case ColorID::MozMenuhovertext:
89 aResult = mColorTextSelectForeground;
91 case ColorID::IMESelectedRawTextBackground:
92 case ColorID::IMESelectedConvertedTextBackground:
93 case ColorID::IMERawInputBackground:
94 case ColorID::IMEConvertedTextBackground:
95 aResult = NS_TRANSPARENT;
97 case ColorID::IMESelectedRawTextForeground:
98 case ColorID::IMESelectedConvertedTextForeground:
99 case ColorID::IMERawInputForeground:
100 case ColorID::IMEConvertedTextForeground:
101 aResult = NS_SAME_AS_FOREGROUND_COLOR;
103 case ColorID::IMERawInputUnderline:
104 case ColorID::IMEConvertedTextUnderline:
105 aResult = NS_40PERCENT_FOREGROUND_COLOR;
107 case ColorID::IMESelectedRawTextUnderline:
108 case ColorID::IMESelectedConvertedTextUnderline:
109 aResult = NS_SAME_AS_FOREGROUND_COLOR;
111 case ColorID::SpellCheckerUnderline:
112 aResult = NS_RGB(0xff, 0, 0);
116 // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
118 case ColorID::Buttontext:
119 case ColorID::MozButtonhovertext:
120 case ColorID::Captiontext:
121 case ColorID::Menutext:
122 case ColorID::Infotext:
123 case ColorID::MozMenubartext:
124 case ColorID::Windowtext:
125 aResult = mColorDarkText;
127 case ColorID::Activecaption:
128 aResult = NS_RGB(0xff, 0xff, 0xff);
130 case ColorID::Activeborder:
131 aResult = NS_RGB(0x00, 0x00, 0x00);
133 case ColorID::Appworkspace:
134 aResult = NS_RGB(0xFF, 0xFF, 0xFF);
136 case ColorID::Background:
137 aResult = NS_RGB(0x63, 0x63, 0xCE);
139 case ColorID::Buttonface:
140 case ColorID::MozButtonhoverface:
141 aResult = NS_RGB(0xF0, 0xF0, 0xF0);
143 case ColorID::Buttonhighlight:
144 aResult = NS_RGB(0xFF, 0xFF, 0xFF);
146 case ColorID::Buttonshadow:
147 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
149 case ColorID::Graytext:
150 aResult = NS_RGB(0x44, 0x44, 0x44);
152 case ColorID::Inactiveborder:
153 aResult = NS_RGB(0xff, 0xff, 0xff);
155 case ColorID::Inactivecaption:
156 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
158 case ColorID::Inactivecaptiontext:
159 aResult = NS_RGB(0x45, 0x45, 0x45);
161 case ColorID::Scrollbar:
162 aResult = NS_RGB(0, 0, 0); // XXX
164 case ColorID::Threeddarkshadow:
165 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
167 case ColorID::Threedshadow:
168 aResult = NS_RGB(0xE0, 0xE0, 0xE0);
170 case ColorID::Threedface:
171 aResult = NS_RGB(0xF0, 0xF0, 0xF0);
173 case ColorID::Threedhighlight:
174 aResult = NS_RGB(0xff, 0xff, 0xff);
176 case ColorID::Threedlightshadow:
177 aResult = NS_RGB(0xDA, 0xDA, 0xDA);
180 aResult = NS_RGB(0xff, 0xff, 0xff);
182 case ColorID::Infobackground:
183 aResult = NS_RGB(0xFF, 0xFF, 0xC7);
185 case ColorID::Windowframe:
186 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
188 case ColorID::Window:
189 case ColorID::MozField:
190 case ColorID::MozCombobox:
191 aResult = NS_RGB(0xff, 0xff, 0xff);
193 case ColorID::MozFieldtext:
194 case ColorID::MozComboboxtext:
195 aResult = mColorDarkText;
197 case ColorID::MozDialog:
198 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
200 case ColorID::MozDialogtext:
201 case ColorID::MozCellhighlighttext:
202 case ColorID::MozHtmlCellhighlighttext:
203 case ColorID::MozColheadertext:
204 case ColorID::MozColheaderhovertext:
205 aResult = mColorDarkText;
207 case ColorID::MozDragtargetzone:
208 case ColorID::MozMacChromeActive:
209 case ColorID::MozMacChromeInactive:
210 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
212 case ColorID::MozMacFocusring:
213 aResult = NS_RGB(0x3F, 0x98, 0xDD);
215 case ColorID::MozMacMenushadow:
216 aResult = NS_RGB(0xA3, 0xA3, 0xA3);
218 case ColorID::MozMacMenutextdisable:
219 aResult = NS_RGB(0x88, 0x88, 0x88);
221 case ColorID::MozMacMenutextselect:
222 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
224 case ColorID::MozMacDisabledtoolbartext:
225 aResult = NS_RGB(0x3F, 0x3F, 0x3F);
227 case ColorID::MozMacMenuselect:
228 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
230 case ColorID::MozButtondefault:
231 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
233 case ColorID::MozCellhighlight:
234 case ColorID::MozHtmlCellhighlight:
235 case ColorID::MozMacSecondaryhighlight:
236 // For inactive list selection
237 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
239 case ColorID::MozEventreerow:
240 // Background color of even list rows.
241 aResult = NS_RGB(0xff, 0xff, 0xff);
243 case ColorID::MozOddtreerow:
244 // Background color of odd list rows.
245 aResult = NS_TRANSPARENT;
247 case ColorID::MozNativehyperlinktext:
248 // There appears to be no available system defined color. HARDCODING to the appropriate color.
249 aResult = NS_RGB(0x14, 0x4F, 0xAE);
252 NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
253 aResult = NS_RGB(0xff, 0xff, 0xff);
254 res = NS_ERROR_FAILURE;
262 nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
263 nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
264 if (NS_SUCCEEDED(res)) return res;
268 case IntID::CaretBlinkTime:
271 case IntID::CaretWidth:
274 case IntID::ShowCaretDuringSelection:
277 case IntID::SelectTextfieldsOnKeyFocus:
278 // Select textfield content when focused by kbd
279 // used by nsEventStateManager::sTextfieldSelectModel
282 case IntID::SubmenuDelay:
285 case IntID::MenusCanOverlapOSBar:
286 // xul popups are not allowed to overlap the menubar.
289 case IntID::SkipNavigatingDisabledMenuItem:
292 case IntID::DragThresholdX:
293 case IntID::DragThresholdY:
296 case IntID::ScrollArrowStyle:
297 aResult = eScrollArrow_None;
299 case IntID::ScrollSliderStyle:
300 aResult = eScrollThumbStyle_Proportional;
302 case IntID::TreeOpenDelay:
305 case IntID::TreeCloseDelay:
308 case IntID::TreeLazyScrollDelay:
311 case IntID::TreeScrollDelay:
314 case IntID::TreeScrollLinesMax:
317 case IntID::DWMCompositor:
318 case IntID::WindowsClassic:
319 case IntID::WindowsDefaultTheme:
320 case IntID::TouchEnabled:
322 res = NS_ERROR_NOT_IMPLEMENTED;
324 case IntID::MacGraphiteTheme:
327 case IntID::TabFocusModel:
328 aResult = 1; // default to just textboxes
330 case IntID::ScrollToClick:
333 case IntID::ChosenMenuItemsShouldBlink:
336 case IntID::IMERawInputUnderlineStyle:
337 case IntID::IMEConvertedTextUnderlineStyle:
338 case IntID::IMESelectedRawTextUnderlineStyle:
339 case IntID::IMESelectedConvertedTextUnderline:
340 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
342 case IntID::SpellCheckerUnderlineStyle:
343 aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
345 case IntID::ContextMenuOffsetVertical:
346 case IntID::ContextMenuOffsetHorizontal:
351 res = NS_ERROR_FAILURE;
357 nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
358 nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
359 if (NS_SUCCEEDED(res)) return res;
363 case FloatID::IMEUnderlineRelativeSize:
366 case FloatID::SpellCheckerUnderlineRelativeSize:
371 res = NS_ERROR_FAILURE;
377 bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) {
379 if (aID == FontID::Window || aID == FontID::Document) {
380 aFontStyle.style = FontSlantStyle::Normal();
381 aFontStyle.weight = FontWeight::Normal();
382 aFontStyle.stretch = FontStretch::Normal();
383 aFontStyle.size = 14;
384 aFontStyle.systemFont = true;
386 aFontName.AssignLiteral("sans-serif");
390 // TODO: implement more here?
394 void nsLookAndFeel::EnsureInit() {
401 GetColor(ColorID::TextSelectBackground, color);
402 if (color == 0x000000) {
403 mColorTextSelectForeground = NS_RGB(0xff, 0xff, 0xff);
405 mColorTextSelectForeground = NS_DONT_CHANGE_COLOR;
408 mColorDarkText = GetColorFromUIColor([UIColor darkTextColor]);