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),
26 (unsigned int)(components[1] * 255.0),
27 (unsigned int)(components[2] * 255.0));
28 } else if (model == kCGColorSpaceModelMonochrome) {
29 unsigned int val = (unsigned int)(components[0] * 255.0);
30 return NS_RGBA(val, val, val, (unsigned int)(components[1] * 255.0));
32 MOZ_ASSERT_UNREACHABLE("Unhandled color space!");
36 void nsLookAndFeel::NativeInit() { EnsureInit(); }
38 void nsLookAndFeel::RefreshImpl() {
39 nsXPLookAndFeel::RefreshImpl();
44 nsresult nsLookAndFeel::NativeGetColor(ColorID, ColorScheme, nscolor& aResult) {
50 case ColorID::Highlight:
51 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
53 case ColorID::MozMenuhover:
54 aResult = NS_RGB(0xee, 0xee, 0xee);
56 case ColorID::Highlighttext:
57 case ColorID::MozMenuhovertext:
58 aResult = mColorTextSelectForeground;
60 case ColorID::IMESelectedRawTextBackground:
61 case ColorID::IMESelectedConvertedTextBackground:
62 case ColorID::IMERawInputBackground:
63 case ColorID::IMEConvertedTextBackground:
64 aResult = NS_TRANSPARENT;
66 case ColorID::IMESelectedRawTextForeground:
67 case ColorID::IMESelectedConvertedTextForeground:
68 case ColorID::IMERawInputForeground:
69 case ColorID::IMEConvertedTextForeground:
70 aResult = NS_SAME_AS_FOREGROUND_COLOR;
72 case ColorID::IMERawInputUnderline:
73 case ColorID::IMEConvertedTextUnderline:
74 aResult = NS_40PERCENT_FOREGROUND_COLOR;
76 case ColorID::IMESelectedRawTextUnderline:
77 case ColorID::IMESelectedConvertedTextUnderline:
78 aResult = NS_SAME_AS_FOREGROUND_COLOR;
80 case ColorID::SpellCheckerUnderline:
81 aResult = NS_RGB(0xff, 0, 0);
85 // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
87 case ColorID::Buttontext:
88 case ColorID::MozButtonhovertext:
89 case ColorID::Captiontext:
90 case ColorID::Menutext:
91 case ColorID::Infotext:
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::MozMacFocusring:
176 aResult = NS_RGB(0x3F, 0x98, 0xDD);
178 case ColorID::MozMacMenutextdisable:
179 aResult = NS_RGB(0x88, 0x88, 0x88);
181 case ColorID::MozMacMenutextselect:
182 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
184 case ColorID::MozMacDisabledtoolbartext:
185 aResult = NS_RGB(0x3F, 0x3F, 0x3F);
187 case ColorID::MozCellhighlight:
188 case ColorID::Selecteditem:
189 // For inactive list selection
190 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
192 case ColorID::MozEventreerow:
193 // Background color of even list rows.
194 aResult = NS_RGB(0xff, 0xff, 0xff);
196 case ColorID::MozOddtreerow:
197 // Background color of odd list rows.
198 aResult = NS_TRANSPARENT;
200 case ColorID::MozNativehyperlinktext:
201 // There appears to be no available system defined color. HARDCODING to
202 // the appropriate color.
203 aResult = NS_RGB(0x14, 0x4F, 0xAE);
205 case ColorID::MozNativevisitedhyperlinktext:
206 // Safari defaults to the MacOS color implementation for visited links,
207 // which in turn uses systemPurpleColor, so we do the same here.
208 aResult = GetColorFromUIColor([UIColor systemPurpleColor]);
211 NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
212 aResult = NS_RGB(0xff, 0xff, 0xff);
213 res = NS_ERROR_FAILURE;
221 nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
222 nsresult res = NS_OK;
225 case IntID::ScrollButtonLeftMouseButtonAction:
228 case IntID::ScrollButtonMiddleMouseButtonAction:
229 case IntID::ScrollButtonRightMouseButtonAction:
232 case IntID::CaretBlinkTime:
235 case IntID::CaretWidth:
238 case IntID::ShowCaretDuringSelection:
241 case IntID::SelectTextfieldsOnKeyFocus:
242 // Select textfield content when focused by kbd
243 // used by nsEventStateManager::sTextfieldSelectModel
246 case IntID::SubmenuDelay:
249 case IntID::MenusCanOverlapOSBar:
250 // xul popups are not allowed to overlap the menubar.
253 case IntID::SkipNavigatingDisabledMenuItem:
256 case IntID::DragThresholdX:
257 case IntID::DragThresholdY:
260 case IntID::ScrollArrowStyle:
261 aResult = eScrollArrow_None;
263 case IntID::TreeOpenDelay:
266 case IntID::TreeCloseDelay:
269 case IntID::TreeLazyScrollDelay:
272 case IntID::TreeScrollDelay:
275 case IntID::TreeScrollLinesMax:
278 case IntID::TabFocusModel:
279 aResult = 1; // default to just textboxes
281 case IntID::ScrollToClick:
284 case IntID::ChosenMenuItemsShouldBlink:
287 case IntID::IMERawInputUnderlineStyle:
288 case IntID::IMEConvertedTextUnderlineStyle:
289 case IntID::IMESelectedRawTextUnderlineStyle:
290 case IntID::IMESelectedConvertedTextUnderline:
291 aResult = static_cast<int32_t>(StyleTextDecorationStyle::Solid);
293 case IntID::SpellCheckerUnderlineStyle:
294 aResult = static_cast<int32_t>(StyleTextDecorationStyle::Dotted);
296 case IntID::ContextMenuOffsetVertical:
297 case IntID::ContextMenuOffsetHorizontal:
302 res = NS_ERROR_FAILURE;
308 nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
309 nsresult res = NS_OK;
312 case FloatID::IMEUnderlineRelativeSize:
315 case FloatID::SpellCheckerUnderlineRelativeSize:
320 res = NS_ERROR_FAILURE;
326 bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
327 gfxFontStyle& aFontStyle) {
329 if (aID == FontID::Window || aID == FontID::Document) {
330 aFontStyle.style = FontSlantStyle::Normal();
331 aFontStyle.weight = FontWeight::Normal();
332 aFontStyle.stretch = FontStretch::Normal();
333 aFontStyle.size = 14;
334 aFontStyle.systemFont = true;
336 aFontName.AssignLiteral("sans-serif");
340 // TODO: implement more here?
344 void nsLookAndFeel::EnsureInit() {
351 GetColor(ColorID::TextSelectBackground, color);
352 if (color == 0x000000) {
353 mColorTextSelectForeground = NS_RGB(0xff, 0xff, 0xff);
355 mColorTextSelectForeground = NS_SAME_AS_FOREGROUND_COLOR;
358 mColorDarkText = GetColorFromUIColor([UIColor darkTextColor]);