widget/android/nsLookAndFeel.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/dom/ContentChild.h"
michael@0 7 #include "nsStyleConsts.h"
michael@0 8 #include "nsXULAppAPI.h"
michael@0 9 #include "nsLookAndFeel.h"
michael@0 10 #include "gfxFont.h"
michael@0 11 #include "gfxFontConstants.h"
michael@0 12 #include "mozilla/gfx/2D.h"
michael@0 13
michael@0 14 using namespace mozilla;
michael@0 15 using mozilla::dom::ContentChild;
michael@0 16
michael@0 17 bool nsLookAndFeel::mInitializedSystemColors = false;
michael@0 18 AndroidSystemColors nsLookAndFeel::mSystemColors;
michael@0 19
michael@0 20 bool nsLookAndFeel::mInitializedShowPassword = false;
michael@0 21 bool nsLookAndFeel::mShowPassword = true;
michael@0 22
michael@0 23 static const char16_t UNICODE_BULLET = 0x2022;
michael@0 24
michael@0 25 nsLookAndFeel::nsLookAndFeel()
michael@0 26 : nsXPLookAndFeel()
michael@0 27 {
michael@0 28 }
michael@0 29
michael@0 30 nsLookAndFeel::~nsLookAndFeel()
michael@0 31 {
michael@0 32 }
michael@0 33
michael@0 34 #define BG_PRELIGHT_COLOR NS_RGB(0xee,0xee,0xee)
michael@0 35 #define FG_PRELIGHT_COLOR NS_RGB(0x77,0x77,0x77)
michael@0 36 #define BLACK_COLOR NS_RGB(0x00,0x00,0x00)
michael@0 37 #define DARK_GRAY_COLOR NS_RGB(0x40,0x40,0x40)
michael@0 38 #define GRAY_COLOR NS_RGB(0x80,0x80,0x80)
michael@0 39 #define LIGHT_GRAY_COLOR NS_RGB(0xa0,0xa0,0xa0)
michael@0 40 #define RED_COLOR NS_RGB(0xff,0x00,0x00)
michael@0 41
michael@0 42 nsresult
michael@0 43 nsLookAndFeel::GetSystemColors()
michael@0 44 {
michael@0 45 if (mInitializedSystemColors)
michael@0 46 return NS_OK;
michael@0 47
michael@0 48 if (!AndroidBridge::Bridge())
michael@0 49 return NS_ERROR_FAILURE;
michael@0 50
michael@0 51 AndroidBridge::Bridge()->GetSystemColors(&mSystemColors);
michael@0 52
michael@0 53 mInitializedSystemColors = true;
michael@0 54
michael@0 55 return NS_OK;
michael@0 56 }
michael@0 57
michael@0 58 nsresult
michael@0 59 nsLookAndFeel::CallRemoteGetSystemColors()
michael@0 60 {
michael@0 61 // An array has to be used to get data from remote process
michael@0 62 InfallibleTArray<uint32_t> colors;
michael@0 63 uint32_t colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor);
michael@0 64
michael@0 65 if (!ContentChild::GetSingleton()->SendGetSystemColors(colorsCount, &colors))
michael@0 66 return NS_ERROR_FAILURE;
michael@0 67
michael@0 68 NS_ASSERTION(colors.Length() == colorsCount, "System colors array is incomplete");
michael@0 69 if (colors.Length() == 0)
michael@0 70 return NS_ERROR_FAILURE;
michael@0 71
michael@0 72 if (colors.Length() < colorsCount)
michael@0 73 colorsCount = colors.Length();
michael@0 74
michael@0 75 // Array elements correspond to the members of mSystemColors structure,
michael@0 76 // so just copy the memory block
michael@0 77 memcpy(&mSystemColors, colors.Elements(), sizeof(nscolor) * colorsCount);
michael@0 78
michael@0 79 mInitializedSystemColors = true;
michael@0 80
michael@0 81 return NS_OK;
michael@0 82 }
michael@0 83
michael@0 84 nsresult
michael@0 85 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
michael@0 86 {
michael@0 87 nsresult rv = NS_OK;
michael@0 88
michael@0 89 if (!mInitializedSystemColors) {
michael@0 90 if (XRE_GetProcessType() == GeckoProcessType_Default)
michael@0 91 rv = GetSystemColors();
michael@0 92 else
michael@0 93 rv = CallRemoteGetSystemColors();
michael@0 94 NS_ENSURE_SUCCESS(rv, rv);
michael@0 95 }
michael@0 96
michael@0 97 // XXX we'll want to use context.obtainStyledAttributes on the java side to
michael@0 98 // get all of these; see TextView.java for a good exmaple.
michael@0 99
michael@0 100 switch (aID) {
michael@0 101 // These colors don't seem to be used for anything anymore in Mozilla
michael@0 102 // (except here at least TextSelectBackground and TextSelectForeground)
michael@0 103 // The CSS2 colors below are used.
michael@0 104 case eColorID_WindowBackground:
michael@0 105 aColor = NS_RGB(0xFF, 0xFF, 0xFF);
michael@0 106 break;
michael@0 107 case eColorID_WindowForeground:
michael@0 108 aColor = mSystemColors.textColorPrimary;
michael@0 109 break;
michael@0 110 case eColorID_WidgetBackground:
michael@0 111 aColor = mSystemColors.colorBackground;
michael@0 112 break;
michael@0 113 case eColorID_WidgetForeground:
michael@0 114 aColor = mSystemColors.colorForeground;
michael@0 115 break;
michael@0 116 case eColorID_WidgetSelectBackground:
michael@0 117 aColor = mSystemColors.textColorHighlight;
michael@0 118 break;
michael@0 119 case eColorID_WidgetSelectForeground:
michael@0 120 aColor = mSystemColors.textColorPrimaryInverse;
michael@0 121 break;
michael@0 122 case eColorID_Widget3DHighlight:
michael@0 123 aColor = LIGHT_GRAY_COLOR;
michael@0 124 break;
michael@0 125 case eColorID_Widget3DShadow:
michael@0 126 aColor = DARK_GRAY_COLOR;
michael@0 127 break;
michael@0 128 case eColorID_TextBackground:
michael@0 129 // not used?
michael@0 130 aColor = mSystemColors.colorBackground;
michael@0 131 break;
michael@0 132 case eColorID_TextForeground:
michael@0 133 // not used?
michael@0 134 aColor = mSystemColors.textColorPrimary;
michael@0 135 break;
michael@0 136 case eColorID_TextSelectBackground:
michael@0 137 case eColorID_IMESelectedRawTextBackground:
michael@0 138 case eColorID_IMESelectedConvertedTextBackground:
michael@0 139 // still used
michael@0 140 aColor = mSystemColors.textColorHighlight;
michael@0 141 break;
michael@0 142 case eColorID_TextSelectForeground:
michael@0 143 case eColorID_IMESelectedRawTextForeground:
michael@0 144 case eColorID_IMESelectedConvertedTextForeground:
michael@0 145 // still used
michael@0 146 aColor = mSystemColors.textColorPrimaryInverse;
michael@0 147 break;
michael@0 148 case eColorID_IMERawInputBackground:
michael@0 149 case eColorID_IMEConvertedTextBackground:
michael@0 150 aColor = NS_TRANSPARENT;
michael@0 151 break;
michael@0 152 case eColorID_IMERawInputForeground:
michael@0 153 case eColorID_IMEConvertedTextForeground:
michael@0 154 aColor = NS_SAME_AS_FOREGROUND_COLOR;
michael@0 155 break;
michael@0 156 case eColorID_IMERawInputUnderline:
michael@0 157 case eColorID_IMEConvertedTextUnderline:
michael@0 158 aColor = NS_SAME_AS_FOREGROUND_COLOR;
michael@0 159 break;
michael@0 160 case eColorID_IMESelectedRawTextUnderline:
michael@0 161 case eColorID_IMESelectedConvertedTextUnderline:
michael@0 162 aColor = NS_TRANSPARENT;
michael@0 163 break;
michael@0 164 case eColorID_SpellCheckerUnderline:
michael@0 165 aColor = RED_COLOR;
michael@0 166 break;
michael@0 167
michael@0 168 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
michael@0 169 case eColorID_activeborder:
michael@0 170 // active window border
michael@0 171 aColor = mSystemColors.colorBackground;
michael@0 172 break;
michael@0 173 case eColorID_activecaption:
michael@0 174 // active window caption background
michael@0 175 aColor = mSystemColors.colorBackground;
michael@0 176 break;
michael@0 177 case eColorID_appworkspace:
michael@0 178 // MDI background color
michael@0 179 aColor = mSystemColors.colorBackground;
michael@0 180 break;
michael@0 181 case eColorID_background:
michael@0 182 // desktop background
michael@0 183 aColor = mSystemColors.colorBackground;
michael@0 184 break;
michael@0 185 case eColorID_captiontext:
michael@0 186 // text in active window caption, size box, and scrollbar arrow box (!)
michael@0 187 aColor = mSystemColors.colorForeground;
michael@0 188 break;
michael@0 189 case eColorID_graytext:
michael@0 190 // disabled text in windows, menus, etc.
michael@0 191 aColor = mSystemColors.textColorTertiary;
michael@0 192 break;
michael@0 193 case eColorID_highlight:
michael@0 194 // background of selected item
michael@0 195 aColor = mSystemColors.textColorHighlight;
michael@0 196 break;
michael@0 197 case eColorID_highlighttext:
michael@0 198 // text of selected item
michael@0 199 aColor = mSystemColors.textColorPrimaryInverse;
michael@0 200 break;
michael@0 201 case eColorID_inactiveborder:
michael@0 202 // inactive window border
michael@0 203 aColor = mSystemColors.colorBackground;
michael@0 204 break;
michael@0 205 case eColorID_inactivecaption:
michael@0 206 // inactive window caption
michael@0 207 aColor = mSystemColors.colorBackground;
michael@0 208 break;
michael@0 209 case eColorID_inactivecaptiontext:
michael@0 210 // text in inactive window caption
michael@0 211 aColor = mSystemColors.textColorTertiary;
michael@0 212 break;
michael@0 213 case eColorID_infobackground:
michael@0 214 // tooltip background color
michael@0 215 aColor = mSystemColors.colorBackground;
michael@0 216 break;
michael@0 217 case eColorID_infotext:
michael@0 218 // tooltip text color
michael@0 219 aColor = mSystemColors.colorForeground;
michael@0 220 break;
michael@0 221 case eColorID_menu:
michael@0 222 // menu background
michael@0 223 aColor = mSystemColors.colorBackground;
michael@0 224 break;
michael@0 225 case eColorID_menutext:
michael@0 226 // menu text
michael@0 227 aColor = mSystemColors.colorForeground;
michael@0 228 break;
michael@0 229 case eColorID_scrollbar:
michael@0 230 // scrollbar gray area
michael@0 231 aColor = mSystemColors.colorBackground;
michael@0 232 break;
michael@0 233
michael@0 234 case eColorID_threedface:
michael@0 235 case eColorID_buttonface:
michael@0 236 // 3-D face color
michael@0 237 aColor = mSystemColors.colorBackground;
michael@0 238 break;
michael@0 239
michael@0 240 case eColorID_buttontext:
michael@0 241 // text on push buttons
michael@0 242 aColor = mSystemColors.colorForeground;
michael@0 243 break;
michael@0 244
michael@0 245 case eColorID_buttonhighlight:
michael@0 246 // 3-D highlighted edge color
michael@0 247 case eColorID_threedhighlight:
michael@0 248 // 3-D highlighted outer edge color
michael@0 249 aColor = LIGHT_GRAY_COLOR;
michael@0 250 break;
michael@0 251
michael@0 252 case eColorID_threedlightshadow:
michael@0 253 // 3-D highlighted inner edge color
michael@0 254 aColor = mSystemColors.colorBackground;
michael@0 255 break;
michael@0 256
michael@0 257 case eColorID_buttonshadow:
michael@0 258 // 3-D shadow edge color
michael@0 259 case eColorID_threedshadow:
michael@0 260 // 3-D shadow inner edge color
michael@0 261 aColor = GRAY_COLOR;
michael@0 262 break;
michael@0 263
michael@0 264 case eColorID_threeddarkshadow:
michael@0 265 // 3-D shadow outer edge color
michael@0 266 aColor = BLACK_COLOR;
michael@0 267 break;
michael@0 268
michael@0 269 case eColorID_window:
michael@0 270 case eColorID_windowframe:
michael@0 271 aColor = mSystemColors.colorBackground;
michael@0 272 break;
michael@0 273
michael@0 274 case eColorID_windowtext:
michael@0 275 aColor = mSystemColors.textColorPrimary;
michael@0 276 break;
michael@0 277
michael@0 278 case eColorID__moz_eventreerow:
michael@0 279 case eColorID__moz_field:
michael@0 280 aColor = mSystemColors.colorBackground;
michael@0 281 break;
michael@0 282 case eColorID__moz_fieldtext:
michael@0 283 aColor = mSystemColors.textColorPrimary;
michael@0 284 break;
michael@0 285 case eColorID__moz_dialog:
michael@0 286 aColor = mSystemColors.colorBackground;
michael@0 287 break;
michael@0 288 case eColorID__moz_dialogtext:
michael@0 289 aColor = mSystemColors.colorForeground;
michael@0 290 break;
michael@0 291 case eColorID__moz_dragtargetzone:
michael@0 292 aColor = mSystemColors.textColorHighlight;
michael@0 293 break;
michael@0 294 case eColorID__moz_buttondefault:
michael@0 295 // default button border color
michael@0 296 aColor = BLACK_COLOR;
michael@0 297 break;
michael@0 298 case eColorID__moz_buttonhoverface:
michael@0 299 aColor = BG_PRELIGHT_COLOR;
michael@0 300 break;
michael@0 301 case eColorID__moz_buttonhovertext:
michael@0 302 aColor = FG_PRELIGHT_COLOR;
michael@0 303 break;
michael@0 304 case eColorID__moz_cellhighlight:
michael@0 305 case eColorID__moz_html_cellhighlight:
michael@0 306 aColor = mSystemColors.textColorHighlight;
michael@0 307 break;
michael@0 308 case eColorID__moz_cellhighlighttext:
michael@0 309 case eColorID__moz_html_cellhighlighttext:
michael@0 310 aColor = mSystemColors.textColorPrimaryInverse;
michael@0 311 break;
michael@0 312 case eColorID__moz_menuhover:
michael@0 313 aColor = BG_PRELIGHT_COLOR;
michael@0 314 break;
michael@0 315 case eColorID__moz_menuhovertext:
michael@0 316 aColor = FG_PRELIGHT_COLOR;
michael@0 317 break;
michael@0 318 case eColorID__moz_oddtreerow:
michael@0 319 aColor = NS_TRANSPARENT;
michael@0 320 break;
michael@0 321 case eColorID__moz_nativehyperlinktext:
michael@0 322 aColor = NS_SAME_AS_FOREGROUND_COLOR;
michael@0 323 break;
michael@0 324 case eColorID__moz_comboboxtext:
michael@0 325 aColor = mSystemColors.colorForeground;
michael@0 326 break;
michael@0 327 case eColorID__moz_combobox:
michael@0 328 aColor = mSystemColors.colorBackground;
michael@0 329 break;
michael@0 330 case eColorID__moz_menubartext:
michael@0 331 aColor = mSystemColors.colorForeground;
michael@0 332 break;
michael@0 333 case eColorID__moz_menubarhovertext:
michael@0 334 aColor = FG_PRELIGHT_COLOR;
michael@0 335 break;
michael@0 336 default:
michael@0 337 /* default color is BLACK */
michael@0 338 aColor = 0;
michael@0 339 rv = NS_ERROR_FAILURE;
michael@0 340 break;
michael@0 341 }
michael@0 342
michael@0 343 return rv;
michael@0 344 }
michael@0 345
michael@0 346
michael@0 347 nsresult
michael@0 348 nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
michael@0 349 {
michael@0 350 nsresult rv = nsXPLookAndFeel::GetIntImpl(aID, aResult);
michael@0 351 if (NS_SUCCEEDED(rv))
michael@0 352 return rv;
michael@0 353
michael@0 354 rv = NS_OK;
michael@0 355
michael@0 356 switch (aID) {
michael@0 357 case eIntID_CaretBlinkTime:
michael@0 358 aResult = 500;
michael@0 359 break;
michael@0 360
michael@0 361 case eIntID_CaretWidth:
michael@0 362 aResult = 1;
michael@0 363 break;
michael@0 364
michael@0 365 case eIntID_ShowCaretDuringSelection:
michael@0 366 aResult = 0;
michael@0 367 break;
michael@0 368
michael@0 369 case eIntID_SelectTextfieldsOnKeyFocus:
michael@0 370 // Select textfield content when focused by kbd
michael@0 371 // used by EventStateManager::sTextfieldSelectModel
michael@0 372 aResult = 1;
michael@0 373 break;
michael@0 374
michael@0 375 case eIntID_SubmenuDelay:
michael@0 376 aResult = 200;
michael@0 377 break;
michael@0 378
michael@0 379 case eIntID_TooltipDelay:
michael@0 380 aResult = 500;
michael@0 381 break;
michael@0 382
michael@0 383 case eIntID_MenusCanOverlapOSBar:
michael@0 384 // we want XUL popups to be able to overlap the task bar.
michael@0 385 aResult = 1;
michael@0 386 break;
michael@0 387
michael@0 388 case eIntID_ScrollArrowStyle:
michael@0 389 aResult = eScrollArrowStyle_Single;
michael@0 390 break;
michael@0 391
michael@0 392 case eIntID_ScrollSliderStyle:
michael@0 393 aResult = eScrollThumbStyle_Proportional;
michael@0 394 break;
michael@0 395
michael@0 396 case eIntID_TouchEnabled:
michael@0 397 aResult = 1;
michael@0 398 break;
michael@0 399
michael@0 400 case eIntID_ColorPickerAvailable:
michael@0 401 aResult = 1;
michael@0 402 break;
michael@0 403
michael@0 404 case eIntID_WindowsDefaultTheme:
michael@0 405 case eIntID_WindowsThemeIdentifier:
michael@0 406 case eIntID_OperatingSystemVersionIdentifier:
michael@0 407 aResult = 0;
michael@0 408 rv = NS_ERROR_NOT_IMPLEMENTED;
michael@0 409 break;
michael@0 410
michael@0 411 case eIntID_SpellCheckerUnderlineStyle:
michael@0 412 aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
michael@0 413 break;
michael@0 414
michael@0 415 case eIntID_ScrollbarButtonAutoRepeatBehavior:
michael@0 416 aResult = 0;
michael@0 417 break;
michael@0 418
michael@0 419 default:
michael@0 420 aResult = 0;
michael@0 421 rv = NS_ERROR_FAILURE;
michael@0 422 }
michael@0 423
michael@0 424 return rv;
michael@0 425 }
michael@0 426
michael@0 427 nsresult
michael@0 428 nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
michael@0 429 {
michael@0 430 nsresult rv = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
michael@0 431 if (NS_SUCCEEDED(rv))
michael@0 432 return rv;
michael@0 433 rv = NS_OK;
michael@0 434
michael@0 435 switch (aID) {
michael@0 436 case eFloatID_IMEUnderlineRelativeSize:
michael@0 437 aResult = 1.0f;
michael@0 438 break;
michael@0 439
michael@0 440 case eFloatID_SpellCheckerUnderlineRelativeSize:
michael@0 441 aResult = 1.0f;
michael@0 442 break;
michael@0 443
michael@0 444 default:
michael@0 445 aResult = -1.0;
michael@0 446 rv = NS_ERROR_FAILURE;
michael@0 447 break;
michael@0 448 }
michael@0 449 return rv;
michael@0 450 }
michael@0 451
michael@0 452 /*virtual*/
michael@0 453 bool
michael@0 454 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
michael@0 455 gfxFontStyle& aFontStyle,
michael@0 456 float aDevPixPerCSSPixel)
michael@0 457 {
michael@0 458 aFontName.AssignLiteral("\"Droid Sans\"");
michael@0 459 aFontStyle.style = NS_FONT_STYLE_NORMAL;
michael@0 460 aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
michael@0 461 aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
michael@0 462 aFontStyle.size = 9.0 * 96.0f / 72.0f * aDevPixPerCSSPixel;
michael@0 463 aFontStyle.systemFont = true;
michael@0 464 return true;
michael@0 465 }
michael@0 466
michael@0 467 /*virtual*/
michael@0 468 bool
michael@0 469 nsLookAndFeel::GetEchoPasswordImpl()
michael@0 470 {
michael@0 471 if (!mInitializedShowPassword) {
michael@0 472 if (XRE_GetProcessType() == GeckoProcessType_Default) {
michael@0 473 mShowPassword = mozilla::widget::android::GeckoAppShell::GetShowPasswordSetting();
michael@0 474 } else {
michael@0 475 ContentChild::GetSingleton()->SendGetShowPasswordSetting(&mShowPassword);
michael@0 476 }
michael@0 477 mInitializedShowPassword = true;
michael@0 478 }
michael@0 479 return mShowPassword;
michael@0 480 }
michael@0 481
michael@0 482 uint32_t
michael@0 483 nsLookAndFeel::GetPasswordMaskDelayImpl()
michael@0 484 {
michael@0 485 // This value is hard-coded in Android OS's PasswordTransformationMethod.java
michael@0 486 return 1500;
michael@0 487 }
michael@0 488
michael@0 489 /* virtual */
michael@0 490 char16_t
michael@0 491 nsLookAndFeel::GetPasswordCharacterImpl()
michael@0 492 {
michael@0 493 // This value is hard-coded in Android OS's PasswordTransformationMethod.java
michael@0 494 return UNICODE_BULLET;
michael@0 495 }

mercurial