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 using namespace mozilla;
18 nsLookAndFeel::nsLookAndFeel() : mInitialized(false) {}
20 nsLookAndFeel::~nsLookAndFeel() {}
22 static nscolor GetColorFromUIColor(UIColor* aColor) {
23 CGColorRef cgColor = [aColor CGColor];
24 CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgColor));
25 const CGFloat* components = CGColorGetComponents(cgColor);
26 if (model == kCGColorSpaceModelRGB) {
27 return NS_RGB((unsigned int)(components[0] * 255.0),
28 (unsigned int)(components[1] * 255.0),
29 (unsigned int)(components[2] * 255.0));
30 } else if (model == kCGColorSpaceModelMonochrome) {
31 unsigned int val = (unsigned int)(components[0] * 255.0);
32 return NS_RGBA(val, val, val, (unsigned int)(components[1] * 255.0));
34 MOZ_ASSERT_UNREACHABLE("Unhandled color space!");
38 void nsLookAndFeel::NativeInit() { EnsureInit(); }
40 void nsLookAndFeel::RefreshImpl() {
41 nsXPLookAndFeel::RefreshImpl();
46 nsresult nsLookAndFeel::NativeGetColor(ColorID aID, ColorScheme aColorScheme,
53 case ColorID::Highlight:
54 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
56 case ColorID::MozMenuhover:
57 aResult = NS_RGB(0xee, 0xee, 0xee);
59 case ColorID::Highlighttext:
60 case ColorID::MozMenuhovertext:
61 aResult = NS_SAME_AS_FOREGROUND_COLOR;
63 case ColorID::IMESelectedRawTextBackground:
64 case ColorID::IMESelectedConvertedTextBackground:
65 case ColorID::IMERawInputBackground:
66 case ColorID::IMEConvertedTextBackground:
67 aResult = NS_TRANSPARENT;
69 case ColorID::IMESelectedRawTextForeground:
70 case ColorID::IMESelectedConvertedTextForeground:
71 case ColorID::IMERawInputForeground:
72 case ColorID::IMEConvertedTextForeground:
73 aResult = NS_SAME_AS_FOREGROUND_COLOR;
75 case ColorID::IMERawInputUnderline:
76 case ColorID::IMEConvertedTextUnderline:
77 aResult = NS_40PERCENT_FOREGROUND_COLOR;
79 case ColorID::IMESelectedRawTextUnderline:
80 case ColorID::IMESelectedConvertedTextUnderline:
81 aResult = NS_SAME_AS_FOREGROUND_COLOR;
83 case ColorID::SpellCheckerUnderline:
84 aResult = NS_RGB(0xff, 0, 0);
88 // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
90 case ColorID::Buttontext:
91 case ColorID::MozButtonhovertext:
92 case ColorID::Captiontext:
93 case ColorID::Menutext:
94 case ColorID::Infotext:
95 case ColorID::Windowtext:
96 aResult = mColorDarkText;
98 case ColorID::Activecaption:
99 aResult = NS_RGB(0xff, 0xff, 0xff);
101 case ColorID::Activeborder:
102 aResult = NS_RGB(0x00, 0x00, 0x00);
104 case ColorID::Appworkspace:
105 aResult = NS_RGB(0xFF, 0xFF, 0xFF);
107 case ColorID::Background:
108 aResult = NS_RGB(0x63, 0x63, 0xCE);
110 case ColorID::Buttonface:
111 case ColorID::MozButtonhoverface:
112 aResult = NS_RGB(0xF0, 0xF0, 0xF0);
114 case ColorID::Buttonhighlight:
115 aResult = NS_RGB(0xFF, 0xFF, 0xFF);
117 case ColorID::Buttonshadow:
118 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
120 case ColorID::Graytext:
121 aResult = NS_RGB(0x44, 0x44, 0x44);
123 case ColorID::Inactiveborder:
124 aResult = NS_RGB(0xff, 0xff, 0xff);
126 case ColorID::Inactivecaption:
127 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
129 case ColorID::Inactivecaptiontext:
130 aResult = NS_RGB(0x45, 0x45, 0x45);
132 case ColorID::Scrollbar:
133 aResult = NS_RGB(0, 0, 0); // XXX
135 case ColorID::Threeddarkshadow:
136 aResult = NS_RGB(0xDC, 0xDC, 0xDC);
138 case ColorID::Threedshadow:
139 aResult = NS_RGB(0xE0, 0xE0, 0xE0);
141 case ColorID::Threedface:
142 aResult = NS_RGB(0xF0, 0xF0, 0xF0);
144 case ColorID::Threedhighlight:
145 aResult = NS_RGB(0xff, 0xff, 0xff);
147 case ColorID::Threedlightshadow:
148 aResult = NS_RGB(0xDA, 0xDA, 0xDA);
151 aResult = NS_RGB(0xff, 0xff, 0xff);
153 case ColorID::Infobackground:
154 aResult = NS_RGB(0xFF, 0xFF, 0xC7);
156 case ColorID::Windowframe:
157 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
159 case ColorID::Window:
161 case ColorID::MozCombobox:
162 aResult = NS_RGB(0xff, 0xff, 0xff);
164 case ColorID::Fieldtext:
165 case ColorID::MozComboboxtext:
166 aResult = mColorDarkText;
168 case ColorID::MozDialog:
169 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
171 case ColorID::MozDialogtext:
172 case ColorID::MozCellhighlighttext:
173 case ColorID::Selecteditemtext:
174 case ColorID::MozColheadertext:
175 case ColorID::MozColheaderhovertext:
176 aResult = mColorDarkText;
178 case ColorID::MozMacFocusring:
179 aResult = NS_RGB(0x3F, 0x98, 0xDD);
181 case ColorID::MozMacDisabledtoolbartext:
182 aResult = NS_RGB(0x3F, 0x3F, 0x3F);
184 case ColorID::MozCellhighlight:
185 case ColorID::Selecteditem:
186 // For inactive list selection
187 aResult = NS_RGB(0xaa, 0xaa, 0xaa);
189 case ColorID::MozEventreerow:
190 // Background color of even list rows.
191 aResult = NS_RGB(0xff, 0xff, 0xff);
193 case ColorID::MozOddtreerow:
194 // Background color of odd list rows.
195 aResult = NS_TRANSPARENT;
197 case ColorID::MozNativehyperlinktext:
198 // There appears to be no available system defined color. HARDCODING to
199 // the appropriate color.
200 aResult = NS_RGB(0x14, 0x4F, 0xAE);
202 case ColorID::MozNativevisitedhyperlinktext:
203 // Safari defaults to the MacOS color implementation for visited links,
204 // which in turn uses systemPurpleColor, so we do the same here.
205 aResult = GetColorFromUIColor([UIColor systemPurpleColor]);
207 case ColorID::TargetTextBackground:
208 case ColorID::TargetTextForeground:
209 aResult = GetStandinForNativeColor(aID, aColorScheme);
212 NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
213 aResult = NS_RGB(0xff, 0xff, 0xff);
214 res = NS_ERROR_FAILURE;
222 nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
223 nsresult res = NS_OK;
226 case IntID::ScrollButtonLeftMouseButtonAction:
229 case IntID::ScrollButtonMiddleMouseButtonAction:
230 case IntID::ScrollButtonRightMouseButtonAction:
233 case IntID::CaretBlinkTime:
236 case IntID::CaretWidth:
239 case IntID::SelectTextfieldsOnKeyFocus:
240 // Select textfield content when focused by kbd
241 // used by nsEventStateManager::sTextfieldSelectModel
244 case IntID::SubmenuDelay:
247 case IntID::MenusCanOverlapOSBar:
248 // xul popups are not allowed to overlap the menubar.
251 case IntID::SkipNavigatingDisabledMenuItem:
254 case IntID::DragThresholdX:
255 case IntID::DragThresholdY:
258 case IntID::ScrollArrowStyle:
259 aResult = eScrollArrow_None;
261 case IntID::UseOverlayScrollbars:
262 case IntID::AllowOverlayScrollbarsOverlap:
265 case IntID::ScrollbarDisplayOnMouseMove:
268 case IntID::ScrollbarFadeBeginDelay:
271 case IntID::ScrollbarFadeDuration:
274 case IntID::TreeOpenDelay:
277 case IntID::TreeCloseDelay:
280 case IntID::TreeLazyScrollDelay:
283 case IntID::TreeScrollDelay:
286 case IntID::TreeScrollLinesMax:
289 case IntID::ScrollToClick:
292 case IntID::ChosenMenuItemsShouldBlink:
295 case IntID::IMERawInputUnderlineStyle:
296 case IntID::IMEConvertedTextUnderlineStyle:
297 case IntID::IMESelectedRawTextUnderlineStyle:
298 case IntID::IMESelectedConvertedTextUnderline:
299 aResult = static_cast<int32_t>(StyleTextDecorationStyle::Solid);
301 case IntID::SpellCheckerUnderlineStyle:
302 aResult = static_cast<int32_t>(StyleTextDecorationStyle::Dotted);
304 case IntID::ContextMenuOffsetVertical:
305 case IntID::ContextMenuOffsetHorizontal:
310 res = NS_ERROR_FAILURE;
316 nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
317 nsresult res = NS_OK;
320 case FloatID::IMEUnderlineRelativeSize:
323 case FloatID::SpellCheckerUnderlineRelativeSize:
328 res = NS_ERROR_FAILURE;
334 bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
335 gfxFontStyle& aFontStyle) {
337 if (aID == FontID::Caption || aID == FontID::Menu) {
338 aFontStyle.style = FontSlantStyle::NORMAL;
339 aFontStyle.weight = FontWeight::NORMAL;
340 aFontStyle.stretch = FontStretch::NORMAL;
341 aFontStyle.size = 14;
342 aFontStyle.systemFont = true;
344 aFontName.AssignLiteral("sans-serif");
348 // TODO: implement more here?
352 void nsLookAndFeel::EnsureInit() {
358 mColorDarkText = GetColorFromUIColor([UIColor darkTextColor]);