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/. */ 5 6#import <UIKit/UIColor.h> 7#import <UIKit/UIInterface.h> 8 9#include "nsLookAndFeel.h" 10 11#include "mozilla/FontPropertyTypes.h" 12#include "nsStyleConsts.h" 13#include "gfxFont.h" 14#include "gfxFontConstants.h" 15 16nsLookAndFeel::nsLookAndFeel() : mInitialized(false) {} 17 18nsLookAndFeel::~nsLookAndFeel() {} 19 20static 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)); 30 } 31 MOZ_ASSERT_UNREACHABLE("Unhandled color space!"); 32 return 0; 33} 34 35void nsLookAndFeel::NativeInit() { EnsureInit(); } 36 37void nsLookAndFeel::RefreshImpl() { 38 nsXPLookAndFeel::RefreshImpl(); 39 40 mInitialized = false; 41} 42 43nsresult nsLookAndFeel::NativeGetColor(ColorID, ColorScheme, nscolor& aResult) { 44 EnsureInit(); 45 46 nsresult res = NS_OK; 47 48 switch (aID) { 49 case ColorID::WindowBackground: 50 aResult = NS_RGB(0xff, 0xff, 0xff); 51 break; 52 case ColorID::WindowForeground: 53 aResult = NS_RGB(0x00, 0x00, 0x00); 54 break; 55 case ColorID::WidgetBackground: 56 aResult = NS_RGB(0xdd, 0xdd, 0xdd); 57 break; 58 case ColorID::WidgetForeground: 59 aResult = NS_RGB(0x00, 0x00, 0x00); 60 break; 61 case ColorID::WidgetSelectBackground: 62 aResult = NS_RGB(0x80, 0x80, 0x80); 63 break; 64 case ColorID::WidgetSelectForeground: 65 aResult = NS_RGB(0x00, 0x00, 0x80); 66 break; 67 case ColorID::Widget3DHighlight: 68 aResult = NS_RGB(0xa0, 0xa0, 0xa0); 69 break; 70 case ColorID::Widget3DShadow: 71 aResult = NS_RGB(0x40, 0x40, 0x40); 72 break; 73 case ColorID::TextBackground: 74 aResult = NS_RGB(0xff, 0xff, 0xff); 75 break; 76 case ColorID::TextForeground: 77 aResult = NS_RGB(0x00, 0x00, 0x00); 78 break; 79 case ColorID::TextSelectBackground: 80 case ColorID::Highlight: // CSS2 color 81 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 82 break; 83 case ColorID::MozMenuhover: 84 aResult = NS_RGB(0xee, 0xee, 0xee); 85 break; 86 case ColorID::TextSelectForeground: 87 case ColorID::Highlighttext: // CSS2 color 88 case ColorID::MozMenuhovertext: 89 aResult = mColorTextSelectForeground; 90 break; 91 case ColorID::IMESelectedRawTextBackground: 92 case ColorID::IMESelectedConvertedTextBackground: 93 case ColorID::IMERawInputBackground: 94 case ColorID::IMEConvertedTextBackground: 95 aResult = NS_TRANSPARENT; 96 break; 97 case ColorID::IMESelectedRawTextForeground: 98 case ColorID::IMESelectedConvertedTextForeground: 99 case ColorID::IMERawInputForeground: 100 case ColorID::IMEConvertedTextForeground: 101 aResult = NS_SAME_AS_FOREGROUND_COLOR; 102 break; 103 case ColorID::IMERawInputUnderline: 104 case ColorID::IMEConvertedTextUnderline: 105 aResult = NS_40PERCENT_FOREGROUND_COLOR; 106 break; 107 case ColorID::IMESelectedRawTextUnderline: 108 case ColorID::IMESelectedConvertedTextUnderline: 109 aResult = NS_SAME_AS_FOREGROUND_COLOR; 110 break; 111 case ColorID::SpellCheckerUnderline: 112 aResult = NS_RGB(0xff, 0, 0); 113 break; 114 115 // 116 // css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors 117 // 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; 126 break; 127 case ColorID::Activecaption: 128 aResult = NS_RGB(0xff, 0xff, 0xff); 129 break; 130 case ColorID::Activeborder: 131 aResult = NS_RGB(0x00, 0x00, 0x00); 132 break; 133 case ColorID::Appworkspace: 134 aResult = NS_RGB(0xFF, 0xFF, 0xFF); 135 break; 136 case ColorID::Background: 137 aResult = NS_RGB(0x63, 0x63, 0xCE); 138 break; 139 case ColorID::Buttonface: 140 case ColorID::MozButtonhoverface: 141 aResult = NS_RGB(0xF0, 0xF0, 0xF0); 142 break; 143 case ColorID::Buttonhighlight: 144 aResult = NS_RGB(0xFF, 0xFF, 0xFF); 145 break; 146 case ColorID::Buttonshadow: 147 aResult = NS_RGB(0xDC, 0xDC, 0xDC); 148 break; 149 case ColorID::Graytext: 150 aResult = NS_RGB(0x44, 0x44, 0x44); 151 break; 152 case ColorID::Inactiveborder: 153 aResult = NS_RGB(0xff, 0xff, 0xff); 154 break; 155 case ColorID::Inactivecaption: 156 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 157 break; 158 case ColorID::Inactivecaptiontext: 159 aResult = NS_RGB(0x45, 0x45, 0x45); 160 break; 161 case ColorID::Scrollbar: 162 aResult = NS_RGB(0, 0, 0); // XXX 163 break; 164 case ColorID::Threeddarkshadow: 165 aResult = NS_RGB(0xDC, 0xDC, 0xDC); 166 break; 167 case ColorID::Threedshadow: 168 aResult = NS_RGB(0xE0, 0xE0, 0xE0); 169 break; 170 case ColorID::Threedface: 171 aResult = NS_RGB(0xF0, 0xF0, 0xF0); 172 break; 173 case ColorID::Threedhighlight: 174 aResult = NS_RGB(0xff, 0xff, 0xff); 175 break; 176 case ColorID::Threedlightshadow: 177 aResult = NS_RGB(0xDA, 0xDA, 0xDA); 178 break; 179 case ColorID::Menu: 180 aResult = NS_RGB(0xff, 0xff, 0xff); 181 break; 182 case ColorID::Infobackground: 183 aResult = NS_RGB(0xFF, 0xFF, 0xC7); 184 break; 185 case ColorID::Windowframe: 186 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 187 break; 188 case ColorID::Window: 189 case ColorID::MozField: 190 case ColorID::MozCombobox: 191 aResult = NS_RGB(0xff, 0xff, 0xff); 192 break; 193 case ColorID::MozFieldtext: 194 case ColorID::MozComboboxtext: 195 aResult = mColorDarkText; 196 break; 197 case ColorID::MozDialog: 198 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 199 break; 200 case ColorID::MozDialogtext: 201 case ColorID::MozCellhighlighttext: 202 case ColorID::MozHtmlCellhighlighttext: 203 case ColorID::MozColheadertext: 204 case ColorID::MozColheaderhovertext: 205 aResult = mColorDarkText; 206 break; 207 case ColorID::MozDragtargetzone: 208 case ColorID::MozMacChromeActive: 209 case ColorID::MozMacChromeInactive: 210 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 211 break; 212 case ColorID::MozMacFocusring: 213 aResult = NS_RGB(0x3F, 0x98, 0xDD); 214 break; 215 case ColorID::MozMacMenushadow: 216 aResult = NS_RGB(0xA3, 0xA3, 0xA3); 217 break; 218 case ColorID::MozMacMenutextdisable: 219 aResult = NS_RGB(0x88, 0x88, 0x88); 220 break; 221 case ColorID::MozMacMenutextselect: 222 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 223 break; 224 case ColorID::MozMacDisabledtoolbartext: 225 aResult = NS_RGB(0x3F, 0x3F, 0x3F); 226 break; 227 case ColorID::MozMacMenuselect: 228 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 229 break; 230 case ColorID::MozButtondefault: 231 aResult = NS_RGB(0xDC, 0xDC, 0xDC); 232 break; 233 case ColorID::MozCellhighlight: 234 case ColorID::MozHtmlCellhighlight: 235 case ColorID::MozMacSecondaryhighlight: 236 // For inactive list selection 237 aResult = NS_RGB(0xaa, 0xaa, 0xaa); 238 break; 239 case ColorID::MozEventreerow: 240 // Background color of even list rows. 241 aResult = NS_RGB(0xff, 0xff, 0xff); 242 break; 243 case ColorID::MozOddtreerow: 244 // Background color of odd list rows. 245 aResult = NS_TRANSPARENT; 246 break; 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); 250 break; 251 default: 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; 255 break; 256 } 257 258 return res; 259} 260 261NS_IMETHODIMP 262nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { 263 nsresult res = NS_OK; 264 265 switch (aID) { 266 case IntID::ScrollButtonLeftMouseButtonAction: 267 aResult = 0; 268 break; 269 case IntID::ScrollButtonMiddleMouseButtonAction: 270 case IntID::ScrollButtonRightMouseButtonAction: 271 aResult = 3; 272 break; 273 case IntID::CaretBlinkTime: 274 aResult = 567; 275 break; 276 case IntID::CaretWidth: 277 aResult = 1; 278 break; 279 case IntID::ShowCaretDuringSelection: 280 aResult = 0; 281 break; 282 case IntID::SelectTextfieldsOnKeyFocus: 283 // Select textfield content when focused by kbd 284 // used by nsEventStateManager::sTextfieldSelectModel 285 aResult = 1; 286 break; 287 case IntID::SubmenuDelay: 288 aResult = 200; 289 break; 290 case IntID::MenusCanOverlapOSBar: 291 // xul popups are not allowed to overlap the menubar. 292 aResult = 0; 293 break; 294 case IntID::SkipNavigatingDisabledMenuItem: 295 aResult = 1; 296 break; 297 case IntID::DragThresholdX: 298 case IntID::DragThresholdY: 299 aResult = 4; 300 break; 301 case IntID::ScrollArrowStyle: 302 aResult = eScrollArrow_None; 303 break; 304 case IntID::ScrollSliderStyle: 305 aResult = eScrollThumbStyle_Proportional; 306 break; 307 case IntID::TreeOpenDelay: 308 aResult = 1000; 309 break; 310 case IntID::TreeCloseDelay: 311 aResult = 1000; 312 break; 313 case IntID::TreeLazyScrollDelay: 314 aResult = 150; 315 break; 316 case IntID::TreeScrollDelay: 317 aResult = 100; 318 break; 319 case IntID::TreeScrollLinesMax: 320 aResult = 3; 321 break; 322 case IntID::DWMCompositor: 323 case IntID::WindowsClassic: 324 case IntID::WindowsDefaultTheme: 325 aResult = 0; 326 res = NS_ERROR_NOT_IMPLEMENTED; 327 break; 328 case IntID::MacGraphiteTheme: 329 aResult = 0; 330 break; 331 case IntID::TabFocusModel: 332 aResult = 1; // default to just textboxes 333 break; 334 case IntID::ScrollToClick: 335 aResult = 0; 336 break; 337 case IntID::ChosenMenuItemsShouldBlink: 338 aResult = 1; 339 break; 340 case IntID::IMERawInputUnderlineStyle: 341 case IntID::IMEConvertedTextUnderlineStyle: 342 case IntID::IMESelectedRawTextUnderlineStyle: 343 case IntID::IMESelectedConvertedTextUnderline: 344 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID; 345 break; 346 case IntID::SpellCheckerUnderlineStyle: 347 aResult = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED; 348 break; 349 case IntID::ContextMenuOffsetVertical: 350 case IntID::ContextMenuOffsetHorizontal: 351 aResult = 2; 352 break; 353 default: 354 aResult = 0; 355 res = NS_ERROR_FAILURE; 356 } 357 return res; 358} 359 360NS_IMETHODIMP 361nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) { 362 nsresult res = NS_OK; 363 364 switch (aID) { 365 case FloatID::IMEUnderlineRelativeSize: 366 aResult = 2.0f; 367 break; 368 case FloatID::SpellCheckerUnderlineRelativeSize: 369 aResult = 2.0f; 370 break; 371 default: 372 aResult = -1.0; 373 res = NS_ERROR_FAILURE; 374 } 375 376 return res; 377} 378 379bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) { 380 // hack for now 381 if (aID == FontID::Window || aID == FontID::Document) { 382 aFontStyle.style = FontSlantStyle::Normal(); 383 aFontStyle.weight = FontWeight::Normal(); 384 aFontStyle.stretch = FontStretch::Normal(); 385 aFontStyle.size = 14; 386 aFontStyle.systemFont = true; 387 388 aFontName.AssignLiteral("sans-serif"); 389 return true; 390 } 391 392 // TODO: implement more here? 393 return false; 394} 395 396void nsLookAndFeel::EnsureInit() { 397 if (mInitialized) { 398 return; 399 } 400 mInitialized = true; 401 402 nscolor color; 403 GetColor(ColorID::TextSelectBackground, color); 404 if (color == 0x000000) { 405 mColorTextSelectForeground = NS_RGB(0xff, 0xff, 0xff); 406 } else { 407 mColorTextSelectForeground = NS_SAME_AS_FOREGROUND_COLOR; 408 } 409 410 mColorDarkText = GetColorFromUIColor([UIColor darkTextColor]); 411 412 RecordTelemetry(); 413} 414