widget/gonk/nsLookAndFeel.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* Copyright 2012 Mozilla Foundation and Mozilla contributors
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #include "nsLookAndFeel.h"
michael@0 18 #include "nsStyleConsts.h"
michael@0 19 #include "gfxFont.h"
michael@0 20 #include "gfxFontConstants.h"
michael@0 21 #include "mozilla/gfx/2D.h"
michael@0 22 #include "cutils/properties.h"
michael@0 23
michael@0 24 static const char16_t UNICODE_BULLET = 0x2022;
michael@0 25
michael@0 26 nsLookAndFeel::nsLookAndFeel()
michael@0 27 : nsXPLookAndFeel()
michael@0 28 {
michael@0 29 }
michael@0 30
michael@0 31 nsLookAndFeel::~nsLookAndFeel()
michael@0 32 {
michael@0 33 }
michael@0 34
michael@0 35 nsresult
michael@0 36 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
michael@0 37 {
michael@0 38 nsresult rv = NS_OK;
michael@0 39
michael@0 40 #define BASE_ACTIVE_COLOR NS_RGB(0xaa,0xaa,0xaa)
michael@0 41 #define BASE_NORMAL_COLOR NS_RGB(0xff,0xff,0xff)
michael@0 42 #define BASE_SELECTED_COLOR NS_RGB(0xaa,0xaa,0xaa)
michael@0 43 #define BG_ACTIVE_COLOR NS_RGB(0xff,0xff,0xff)
michael@0 44 #define BG_INSENSITIVE_COLOR NS_RGB(0xaa,0xaa,0xaa)
michael@0 45 #define BG_NORMAL_COLOR NS_RGB(0xff,0xff,0xff)
michael@0 46 #define BG_PRELIGHT_COLOR NS_RGB(0xee,0xee,0xee)
michael@0 47 #define BG_SELECTED_COLOR NS_RGB(0x99,0x99,0x99)
michael@0 48 #define DARK_NORMAL_COLOR NS_RGB(0x88,0x88,0x88)
michael@0 49 #define FG_INSENSITIVE_COLOR NS_RGB(0x44,0x44,0x44)
michael@0 50 #define FG_NORMAL_COLOR NS_RGB(0x00,0x00,0x00)
michael@0 51 #define FG_PRELIGHT_COLOR NS_RGB(0x77,0x77,0x77)
michael@0 52 #define FG_SELECTED_COLOR NS_RGB(0xaa,0xaa,0xaa)
michael@0 53 #define LIGHT_NORMAL_COLOR NS_RGB(0xaa,0xaa,0xaa)
michael@0 54 #define TEXT_ACTIVE_COLOR NS_RGB(0x99,0x99,0x99)
michael@0 55 #define TEXT_NORMAL_COLOR NS_RGB(0x00,0x00,0x00)
michael@0 56 #define TEXT_SELECTED_COLOR NS_RGB(0x00,0x00,0x00)
michael@0 57
michael@0 58 switch (aID) {
michael@0 59 // These colors don't seem to be used for anything anymore in Mozilla
michael@0 60 // (except here at least TextSelectBackground and TextSelectForeground)
michael@0 61 // The CSS2 colors below are used.
michael@0 62 case eColorID_WindowBackground:
michael@0 63 aColor = BASE_NORMAL_COLOR;
michael@0 64 break;
michael@0 65 case eColorID_WindowForeground:
michael@0 66 aColor = TEXT_NORMAL_COLOR;
michael@0 67 break;
michael@0 68 case eColorID_WidgetBackground:
michael@0 69 aColor = BG_NORMAL_COLOR;
michael@0 70 break;
michael@0 71 case eColorID_WidgetForeground:
michael@0 72 aColor = FG_NORMAL_COLOR;
michael@0 73 break;
michael@0 74 case eColorID_WidgetSelectBackground:
michael@0 75 aColor = BG_SELECTED_COLOR;
michael@0 76 break;
michael@0 77 case eColorID_WidgetSelectForeground:
michael@0 78 aColor = FG_SELECTED_COLOR;
michael@0 79 break;
michael@0 80 case eColorID_Widget3DHighlight:
michael@0 81 aColor = NS_RGB(0xa0,0xa0,0xa0);
michael@0 82 break;
michael@0 83 case eColorID_Widget3DShadow:
michael@0 84 aColor = NS_RGB(0x40,0x40,0x40);
michael@0 85 break;
michael@0 86 case eColorID_TextBackground:
michael@0 87 // not used?
michael@0 88 aColor = BASE_NORMAL_COLOR;
michael@0 89 break;
michael@0 90 case eColorID_TextForeground:
michael@0 91 // not used?
michael@0 92 aColor = TEXT_NORMAL_COLOR;
michael@0 93 break;
michael@0 94 case eColorID_TextSelectBackground:
michael@0 95 case eColorID_IMESelectedRawTextBackground:
michael@0 96 case eColorID_IMESelectedConvertedTextBackground:
michael@0 97 // still used
michael@0 98 aColor = BASE_SELECTED_COLOR;
michael@0 99 break;
michael@0 100 case eColorID_TextSelectForeground:
michael@0 101 case eColorID_IMESelectedRawTextForeground:
michael@0 102 case eColorID_IMESelectedConvertedTextForeground:
michael@0 103 // still used
michael@0 104 aColor = TEXT_SELECTED_COLOR;
michael@0 105 break;
michael@0 106 case eColorID_IMERawInputBackground:
michael@0 107 case eColorID_IMEConvertedTextBackground:
michael@0 108 aColor = NS_TRANSPARENT;
michael@0 109 break;
michael@0 110 case eColorID_IMERawInputForeground:
michael@0 111 case eColorID_IMEConvertedTextForeground:
michael@0 112 aColor = NS_SAME_AS_FOREGROUND_COLOR;
michael@0 113 break;
michael@0 114 case eColorID_IMERawInputUnderline:
michael@0 115 case eColorID_IMEConvertedTextUnderline:
michael@0 116 aColor = NS_SAME_AS_FOREGROUND_COLOR;
michael@0 117 break;
michael@0 118 case eColorID_IMESelectedRawTextUnderline:
michael@0 119 case eColorID_IMESelectedConvertedTextUnderline:
michael@0 120 aColor = NS_TRANSPARENT;
michael@0 121 break;
michael@0 122 case eColorID_SpellCheckerUnderline:
michael@0 123 aColor = NS_RGB(0xff, 0, 0);
michael@0 124 break;
michael@0 125
michael@0 126 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
michael@0 127 case eColorID_activeborder:
michael@0 128 // active window border
michael@0 129 aColor = BG_NORMAL_COLOR;
michael@0 130 break;
michael@0 131 case eColorID_activecaption:
michael@0 132 // active window caption background
michael@0 133 aColor = BG_NORMAL_COLOR;
michael@0 134 break;
michael@0 135 case eColorID_appworkspace:
michael@0 136 // MDI background color
michael@0 137 aColor = BG_NORMAL_COLOR;
michael@0 138 break;
michael@0 139 case eColorID_background:
michael@0 140 // desktop background
michael@0 141 aColor = BG_NORMAL_COLOR;
michael@0 142 break;
michael@0 143 case eColorID_captiontext:
michael@0 144 // text in active window caption, size box, and scrollbar arrow box (!)
michael@0 145 aColor = FG_NORMAL_COLOR;
michael@0 146 break;
michael@0 147 case eColorID_graytext:
michael@0 148 // disabled text in windows, menus, etc.
michael@0 149 aColor = FG_INSENSITIVE_COLOR;
michael@0 150 break;
michael@0 151 case eColorID_highlight:
michael@0 152 // background of selected item
michael@0 153 aColor = BASE_SELECTED_COLOR;
michael@0 154 break;
michael@0 155 case eColorID_highlighttext:
michael@0 156 // text of selected item
michael@0 157 aColor = TEXT_SELECTED_COLOR;
michael@0 158 break;
michael@0 159 case eColorID_inactiveborder:
michael@0 160 // inactive window border
michael@0 161 aColor = BG_NORMAL_COLOR;
michael@0 162 break;
michael@0 163 case eColorID_inactivecaption:
michael@0 164 // inactive window caption
michael@0 165 aColor = BG_INSENSITIVE_COLOR;
michael@0 166 break;
michael@0 167 case eColorID_inactivecaptiontext:
michael@0 168 // text in inactive window caption
michael@0 169 aColor = FG_INSENSITIVE_COLOR;
michael@0 170 break;
michael@0 171 case eColorID_infobackground:
michael@0 172 // tooltip background color
michael@0 173 aColor = BG_NORMAL_COLOR;
michael@0 174 break;
michael@0 175 case eColorID_infotext:
michael@0 176 // tooltip text color
michael@0 177 aColor = TEXT_NORMAL_COLOR;
michael@0 178 break;
michael@0 179 case eColorID_menu:
michael@0 180 // menu background
michael@0 181 aColor = BG_NORMAL_COLOR;
michael@0 182 break;
michael@0 183 case eColorID_menutext:
michael@0 184 // menu text
michael@0 185 aColor = TEXT_NORMAL_COLOR;
michael@0 186 break;
michael@0 187 case eColorID_scrollbar:
michael@0 188 // scrollbar gray area
michael@0 189 aColor = BG_ACTIVE_COLOR;
michael@0 190 break;
michael@0 191
michael@0 192 case eColorID_threedface:
michael@0 193 case eColorID_buttonface:
michael@0 194 // 3-D face color
michael@0 195 aColor = BG_NORMAL_COLOR;
michael@0 196 break;
michael@0 197
michael@0 198 case eColorID_buttontext:
michael@0 199 // text on push buttons
michael@0 200 aColor = TEXT_NORMAL_COLOR;
michael@0 201 break;
michael@0 202
michael@0 203 case eColorID_buttonhighlight:
michael@0 204 // 3-D highlighted edge color
michael@0 205 case eColorID_threedhighlight:
michael@0 206 // 3-D highlighted outer edge color
michael@0 207 aColor = LIGHT_NORMAL_COLOR;
michael@0 208 break;
michael@0 209
michael@0 210 case eColorID_threedlightshadow:
michael@0 211 // 3-D highlighted inner edge color
michael@0 212 aColor = BG_NORMAL_COLOR;
michael@0 213 break;
michael@0 214
michael@0 215 case eColorID_buttonshadow:
michael@0 216 // 3-D shadow edge color
michael@0 217 case eColorID_threedshadow:
michael@0 218 // 3-D shadow inner edge color
michael@0 219 aColor = DARK_NORMAL_COLOR;
michael@0 220 break;
michael@0 221
michael@0 222 case eColorID_threeddarkshadow:
michael@0 223 // 3-D shadow outer edge color
michael@0 224 aColor = NS_RGB(0,0,0);
michael@0 225 break;
michael@0 226
michael@0 227 case eColorID_window:
michael@0 228 case eColorID_windowframe:
michael@0 229 aColor = BG_NORMAL_COLOR;
michael@0 230 break;
michael@0 231
michael@0 232 case eColorID_windowtext:
michael@0 233 aColor = FG_NORMAL_COLOR;
michael@0 234 break;
michael@0 235
michael@0 236 case eColorID__moz_eventreerow:
michael@0 237 case eColorID__moz_field:
michael@0 238 aColor = BASE_NORMAL_COLOR;
michael@0 239 break;
michael@0 240 case eColorID__moz_fieldtext:
michael@0 241 aColor = TEXT_NORMAL_COLOR;
michael@0 242 break;
michael@0 243 case eColorID__moz_dialog:
michael@0 244 aColor = BG_NORMAL_COLOR;
michael@0 245 break;
michael@0 246 case eColorID__moz_dialogtext:
michael@0 247 aColor = FG_NORMAL_COLOR;
michael@0 248 break;
michael@0 249 case eColorID__moz_dragtargetzone:
michael@0 250 aColor = BG_SELECTED_COLOR;
michael@0 251 break;
michael@0 252 case eColorID__moz_buttondefault:
michael@0 253 // default button border color
michael@0 254 aColor = NS_RGB(0,0,0);
michael@0 255 break;
michael@0 256 case eColorID__moz_buttonhoverface:
michael@0 257 aColor = BG_PRELIGHT_COLOR;
michael@0 258 break;
michael@0 259 case eColorID__moz_buttonhovertext:
michael@0 260 aColor = FG_PRELIGHT_COLOR;
michael@0 261 break;
michael@0 262 case eColorID__moz_cellhighlight:
michael@0 263 case eColorID__moz_html_cellhighlight:
michael@0 264 aColor = BASE_ACTIVE_COLOR;
michael@0 265 break;
michael@0 266 case eColorID__moz_cellhighlighttext:
michael@0 267 case eColorID__moz_html_cellhighlighttext:
michael@0 268 aColor = TEXT_ACTIVE_COLOR;
michael@0 269 break;
michael@0 270 case eColorID__moz_menuhover:
michael@0 271 aColor = BG_PRELIGHT_COLOR;
michael@0 272 break;
michael@0 273 case eColorID__moz_menuhovertext:
michael@0 274 aColor = FG_PRELIGHT_COLOR;
michael@0 275 break;
michael@0 276 case eColorID__moz_oddtreerow:
michael@0 277 aColor = NS_TRANSPARENT;
michael@0 278 break;
michael@0 279 case eColorID__moz_nativehyperlinktext:
michael@0 280 aColor = NS_SAME_AS_FOREGROUND_COLOR;
michael@0 281 break;
michael@0 282 case eColorID__moz_comboboxtext:
michael@0 283 aColor = TEXT_NORMAL_COLOR;
michael@0 284 break;
michael@0 285 case eColorID__moz_combobox:
michael@0 286 aColor = BG_NORMAL_COLOR;
michael@0 287 break;
michael@0 288 case eColorID__moz_menubartext:
michael@0 289 aColor = TEXT_NORMAL_COLOR;
michael@0 290 break;
michael@0 291 case eColorID__moz_menubarhovertext:
michael@0 292 aColor = FG_PRELIGHT_COLOR;
michael@0 293 break;
michael@0 294 default:
michael@0 295 /* default color is BLACK */
michael@0 296 aColor = 0;
michael@0 297 rv = NS_ERROR_FAILURE;
michael@0 298 break;
michael@0 299 }
michael@0 300
michael@0 301 return rv;
michael@0 302 }
michael@0 303
michael@0 304 nsresult
michael@0 305 nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
michael@0 306 {
michael@0 307 nsresult rv = nsXPLookAndFeel::GetIntImpl(aID, aResult);
michael@0 308 if (NS_SUCCEEDED(rv))
michael@0 309 return rv;
michael@0 310
michael@0 311 rv = NS_OK;
michael@0 312
michael@0 313 switch (aID) {
michael@0 314 case eIntID_CaretBlinkTime:
michael@0 315 aResult = 500;
michael@0 316 break;
michael@0 317
michael@0 318 case eIntID_CaretWidth:
michael@0 319 aResult = 1;
michael@0 320 break;
michael@0 321
michael@0 322 case eIntID_ShowCaretDuringSelection:
michael@0 323 aResult = 0;
michael@0 324 break;
michael@0 325
michael@0 326 case eIntID_SelectTextfieldsOnKeyFocus:
michael@0 327 // Select textfield content when focused by kbd
michael@0 328 // used by EventStateManager::sTextfieldSelectModel
michael@0 329 aResult = 1;
michael@0 330 break;
michael@0 331
michael@0 332 case eIntID_SubmenuDelay:
michael@0 333 aResult = 200;
michael@0 334 break;
michael@0 335
michael@0 336 case eIntID_TooltipDelay:
michael@0 337 aResult = 500;
michael@0 338 break;
michael@0 339
michael@0 340 case eIntID_MenusCanOverlapOSBar:
michael@0 341 // we want XUL popups to be able to overlap the task bar.
michael@0 342 aResult = 1;
michael@0 343 break;
michael@0 344
michael@0 345 case eIntID_ScrollArrowStyle:
michael@0 346 aResult = eScrollArrowStyle_Single;
michael@0 347 break;
michael@0 348
michael@0 349 case eIntID_ScrollSliderStyle:
michael@0 350 aResult = eScrollThumbStyle_Proportional;
michael@0 351 break;
michael@0 352
michael@0 353 case eIntID_TouchEnabled:
michael@0 354 aResult = 1;
michael@0 355 break;
michael@0 356
michael@0 357 case eIntID_WindowsDefaultTheme:
michael@0 358 case eIntID_WindowsThemeIdentifier:
michael@0 359 case eIntID_OperatingSystemVersionIdentifier:
michael@0 360 aResult = 0;
michael@0 361 rv = NS_ERROR_NOT_IMPLEMENTED;
michael@0 362 break;
michael@0 363
michael@0 364 case eIntID_IMERawInputUnderlineStyle:
michael@0 365 case eIntID_IMEConvertedTextUnderlineStyle:
michael@0 366 aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
michael@0 367 break;
michael@0 368
michael@0 369 case eIntID_IMESelectedRawTextUnderlineStyle:
michael@0 370 case eIntID_IMESelectedConvertedTextUnderline:
michael@0 371 aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
michael@0 372 break;
michael@0 373
michael@0 374 case eIntID_SpellCheckerUnderlineStyle:
michael@0 375 aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
michael@0 376 break;
michael@0 377
michael@0 378 case eIntID_ScrollbarButtonAutoRepeatBehavior:
michael@0 379 aResult = 0;
michael@0 380 break;
michael@0 381
michael@0 382 case eIntID_PhysicalHomeButton: {
michael@0 383 char propValue[PROPERTY_VALUE_MAX];
michael@0 384 property_get("ro.moz.has_home_button", propValue, "1");
michael@0 385 aResult = atoi(propValue);
michael@0 386 break;
michael@0 387 }
michael@0 388
michael@0 389 default:
michael@0 390 aResult = 0;
michael@0 391 rv = NS_ERROR_FAILURE;
michael@0 392 }
michael@0 393
michael@0 394 return rv;
michael@0 395 }
michael@0 396
michael@0 397 nsresult
michael@0 398 nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
michael@0 399 {
michael@0 400 nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
michael@0 401 if (NS_SUCCEEDED(res))
michael@0 402 return res;
michael@0 403 res = NS_OK;
michael@0 404
michael@0 405 switch (aID) {
michael@0 406 case eFloatID_IMEUnderlineRelativeSize:
michael@0 407 aResult = 1.0f;
michael@0 408 break;
michael@0 409 case eFloatID_SpellCheckerUnderlineRelativeSize:
michael@0 410 aResult = 1.0f;
michael@0 411 break;
michael@0 412 default:
michael@0 413 aResult = -1.0;
michael@0 414 res = NS_ERROR_FAILURE;
michael@0 415 }
michael@0 416 return res;
michael@0 417 }
michael@0 418
michael@0 419 /*virtual*/
michael@0 420 bool
michael@0 421 nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
michael@0 422 gfxFontStyle& aFontStyle,
michael@0 423 float aDevPixPerCSSPixel)
michael@0 424 {
michael@0 425 aFontName.AssignLiteral("\"Fira Sans OT\"");
michael@0 426 aFontStyle.style = NS_FONT_STYLE_NORMAL;
michael@0 427 aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
michael@0 428 aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
michael@0 429 aFontStyle.size = 9.0 * 96.0f / 72.0f;
michael@0 430 aFontStyle.systemFont = true;
michael@0 431 return true;
michael@0 432 }
michael@0 433
michael@0 434 /*virtual*/
michael@0 435 bool
michael@0 436 nsLookAndFeel::GetEchoPasswordImpl() {
michael@0 437 return true;
michael@0 438 }
michael@0 439
michael@0 440 /*virtual*/
michael@0 441 uint32_t
michael@0 442 nsLookAndFeel::GetPasswordMaskDelayImpl()
michael@0 443 {
michael@0 444 // Same value on Android framework
michael@0 445 return 1500;
michael@0 446 }
michael@0 447
michael@0 448 /* virtual */
michael@0 449 char16_t
michael@0 450 nsLookAndFeel::GetPasswordCharacterImpl()
michael@0 451 {
michael@0 452 return UNICODE_BULLET;
michael@0 453 }

mercurial