1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/nsLookAndFeel.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,453 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* Copyright 2012 Mozilla Foundation and Mozilla contributors 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#include "nsLookAndFeel.h" 1.21 +#include "nsStyleConsts.h" 1.22 +#include "gfxFont.h" 1.23 +#include "gfxFontConstants.h" 1.24 +#include "mozilla/gfx/2D.h" 1.25 +#include "cutils/properties.h" 1.26 + 1.27 +static const char16_t UNICODE_BULLET = 0x2022; 1.28 + 1.29 +nsLookAndFeel::nsLookAndFeel() 1.30 + : nsXPLookAndFeel() 1.31 +{ 1.32 +} 1.33 + 1.34 +nsLookAndFeel::~nsLookAndFeel() 1.35 +{ 1.36 +} 1.37 + 1.38 +nsresult 1.39 +nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor) 1.40 +{ 1.41 + nsresult rv = NS_OK; 1.42 + 1.43 +#define BASE_ACTIVE_COLOR NS_RGB(0xaa,0xaa,0xaa) 1.44 +#define BASE_NORMAL_COLOR NS_RGB(0xff,0xff,0xff) 1.45 +#define BASE_SELECTED_COLOR NS_RGB(0xaa,0xaa,0xaa) 1.46 +#define BG_ACTIVE_COLOR NS_RGB(0xff,0xff,0xff) 1.47 +#define BG_INSENSITIVE_COLOR NS_RGB(0xaa,0xaa,0xaa) 1.48 +#define BG_NORMAL_COLOR NS_RGB(0xff,0xff,0xff) 1.49 +#define BG_PRELIGHT_COLOR NS_RGB(0xee,0xee,0xee) 1.50 +#define BG_SELECTED_COLOR NS_RGB(0x99,0x99,0x99) 1.51 +#define DARK_NORMAL_COLOR NS_RGB(0x88,0x88,0x88) 1.52 +#define FG_INSENSITIVE_COLOR NS_RGB(0x44,0x44,0x44) 1.53 +#define FG_NORMAL_COLOR NS_RGB(0x00,0x00,0x00) 1.54 +#define FG_PRELIGHT_COLOR NS_RGB(0x77,0x77,0x77) 1.55 +#define FG_SELECTED_COLOR NS_RGB(0xaa,0xaa,0xaa) 1.56 +#define LIGHT_NORMAL_COLOR NS_RGB(0xaa,0xaa,0xaa) 1.57 +#define TEXT_ACTIVE_COLOR NS_RGB(0x99,0x99,0x99) 1.58 +#define TEXT_NORMAL_COLOR NS_RGB(0x00,0x00,0x00) 1.59 +#define TEXT_SELECTED_COLOR NS_RGB(0x00,0x00,0x00) 1.60 + 1.61 + switch (aID) { 1.62 + // These colors don't seem to be used for anything anymore in Mozilla 1.63 + // (except here at least TextSelectBackground and TextSelectForeground) 1.64 + // The CSS2 colors below are used. 1.65 + case eColorID_WindowBackground: 1.66 + aColor = BASE_NORMAL_COLOR; 1.67 + break; 1.68 + case eColorID_WindowForeground: 1.69 + aColor = TEXT_NORMAL_COLOR; 1.70 + break; 1.71 + case eColorID_WidgetBackground: 1.72 + aColor = BG_NORMAL_COLOR; 1.73 + break; 1.74 + case eColorID_WidgetForeground: 1.75 + aColor = FG_NORMAL_COLOR; 1.76 + break; 1.77 + case eColorID_WidgetSelectBackground: 1.78 + aColor = BG_SELECTED_COLOR; 1.79 + break; 1.80 + case eColorID_WidgetSelectForeground: 1.81 + aColor = FG_SELECTED_COLOR; 1.82 + break; 1.83 + case eColorID_Widget3DHighlight: 1.84 + aColor = NS_RGB(0xa0,0xa0,0xa0); 1.85 + break; 1.86 + case eColorID_Widget3DShadow: 1.87 + aColor = NS_RGB(0x40,0x40,0x40); 1.88 + break; 1.89 + case eColorID_TextBackground: 1.90 + // not used? 1.91 + aColor = BASE_NORMAL_COLOR; 1.92 + break; 1.93 + case eColorID_TextForeground: 1.94 + // not used? 1.95 + aColor = TEXT_NORMAL_COLOR; 1.96 + break; 1.97 + case eColorID_TextSelectBackground: 1.98 + case eColorID_IMESelectedRawTextBackground: 1.99 + case eColorID_IMESelectedConvertedTextBackground: 1.100 + // still used 1.101 + aColor = BASE_SELECTED_COLOR; 1.102 + break; 1.103 + case eColorID_TextSelectForeground: 1.104 + case eColorID_IMESelectedRawTextForeground: 1.105 + case eColorID_IMESelectedConvertedTextForeground: 1.106 + // still used 1.107 + aColor = TEXT_SELECTED_COLOR; 1.108 + break; 1.109 + case eColorID_IMERawInputBackground: 1.110 + case eColorID_IMEConvertedTextBackground: 1.111 + aColor = NS_TRANSPARENT; 1.112 + break; 1.113 + case eColorID_IMERawInputForeground: 1.114 + case eColorID_IMEConvertedTextForeground: 1.115 + aColor = NS_SAME_AS_FOREGROUND_COLOR; 1.116 + break; 1.117 + case eColorID_IMERawInputUnderline: 1.118 + case eColorID_IMEConvertedTextUnderline: 1.119 + aColor = NS_SAME_AS_FOREGROUND_COLOR; 1.120 + break; 1.121 + case eColorID_IMESelectedRawTextUnderline: 1.122 + case eColorID_IMESelectedConvertedTextUnderline: 1.123 + aColor = NS_TRANSPARENT; 1.124 + break; 1.125 + case eColorID_SpellCheckerUnderline: 1.126 + aColor = NS_RGB(0xff, 0, 0); 1.127 + break; 1.128 + 1.129 + // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors 1.130 + case eColorID_activeborder: 1.131 + // active window border 1.132 + aColor = BG_NORMAL_COLOR; 1.133 + break; 1.134 + case eColorID_activecaption: 1.135 + // active window caption background 1.136 + aColor = BG_NORMAL_COLOR; 1.137 + break; 1.138 + case eColorID_appworkspace: 1.139 + // MDI background color 1.140 + aColor = BG_NORMAL_COLOR; 1.141 + break; 1.142 + case eColorID_background: 1.143 + // desktop background 1.144 + aColor = BG_NORMAL_COLOR; 1.145 + break; 1.146 + case eColorID_captiontext: 1.147 + // text in active window caption, size box, and scrollbar arrow box (!) 1.148 + aColor = FG_NORMAL_COLOR; 1.149 + break; 1.150 + case eColorID_graytext: 1.151 + // disabled text in windows, menus, etc. 1.152 + aColor = FG_INSENSITIVE_COLOR; 1.153 + break; 1.154 + case eColorID_highlight: 1.155 + // background of selected item 1.156 + aColor = BASE_SELECTED_COLOR; 1.157 + break; 1.158 + case eColorID_highlighttext: 1.159 + // text of selected item 1.160 + aColor = TEXT_SELECTED_COLOR; 1.161 + break; 1.162 + case eColorID_inactiveborder: 1.163 + // inactive window border 1.164 + aColor = BG_NORMAL_COLOR; 1.165 + break; 1.166 + case eColorID_inactivecaption: 1.167 + // inactive window caption 1.168 + aColor = BG_INSENSITIVE_COLOR; 1.169 + break; 1.170 + case eColorID_inactivecaptiontext: 1.171 + // text in inactive window caption 1.172 + aColor = FG_INSENSITIVE_COLOR; 1.173 + break; 1.174 + case eColorID_infobackground: 1.175 + // tooltip background color 1.176 + aColor = BG_NORMAL_COLOR; 1.177 + break; 1.178 + case eColorID_infotext: 1.179 + // tooltip text color 1.180 + aColor = TEXT_NORMAL_COLOR; 1.181 + break; 1.182 + case eColorID_menu: 1.183 + // menu background 1.184 + aColor = BG_NORMAL_COLOR; 1.185 + break; 1.186 + case eColorID_menutext: 1.187 + // menu text 1.188 + aColor = TEXT_NORMAL_COLOR; 1.189 + break; 1.190 + case eColorID_scrollbar: 1.191 + // scrollbar gray area 1.192 + aColor = BG_ACTIVE_COLOR; 1.193 + break; 1.194 + 1.195 + case eColorID_threedface: 1.196 + case eColorID_buttonface: 1.197 + // 3-D face color 1.198 + aColor = BG_NORMAL_COLOR; 1.199 + break; 1.200 + 1.201 + case eColorID_buttontext: 1.202 + // text on push buttons 1.203 + aColor = TEXT_NORMAL_COLOR; 1.204 + break; 1.205 + 1.206 + case eColorID_buttonhighlight: 1.207 + // 3-D highlighted edge color 1.208 + case eColorID_threedhighlight: 1.209 + // 3-D highlighted outer edge color 1.210 + aColor = LIGHT_NORMAL_COLOR; 1.211 + break; 1.212 + 1.213 + case eColorID_threedlightshadow: 1.214 + // 3-D highlighted inner edge color 1.215 + aColor = BG_NORMAL_COLOR; 1.216 + break; 1.217 + 1.218 + case eColorID_buttonshadow: 1.219 + // 3-D shadow edge color 1.220 + case eColorID_threedshadow: 1.221 + // 3-D shadow inner edge color 1.222 + aColor = DARK_NORMAL_COLOR; 1.223 + break; 1.224 + 1.225 + case eColorID_threeddarkshadow: 1.226 + // 3-D shadow outer edge color 1.227 + aColor = NS_RGB(0,0,0); 1.228 + break; 1.229 + 1.230 + case eColorID_window: 1.231 + case eColorID_windowframe: 1.232 + aColor = BG_NORMAL_COLOR; 1.233 + break; 1.234 + 1.235 + case eColorID_windowtext: 1.236 + aColor = FG_NORMAL_COLOR; 1.237 + break; 1.238 + 1.239 + case eColorID__moz_eventreerow: 1.240 + case eColorID__moz_field: 1.241 + aColor = BASE_NORMAL_COLOR; 1.242 + break; 1.243 + case eColorID__moz_fieldtext: 1.244 + aColor = TEXT_NORMAL_COLOR; 1.245 + break; 1.246 + case eColorID__moz_dialog: 1.247 + aColor = BG_NORMAL_COLOR; 1.248 + break; 1.249 + case eColorID__moz_dialogtext: 1.250 + aColor = FG_NORMAL_COLOR; 1.251 + break; 1.252 + case eColorID__moz_dragtargetzone: 1.253 + aColor = BG_SELECTED_COLOR; 1.254 + break; 1.255 + case eColorID__moz_buttondefault: 1.256 + // default button border color 1.257 + aColor = NS_RGB(0,0,0); 1.258 + break; 1.259 + case eColorID__moz_buttonhoverface: 1.260 + aColor = BG_PRELIGHT_COLOR; 1.261 + break; 1.262 + case eColorID__moz_buttonhovertext: 1.263 + aColor = FG_PRELIGHT_COLOR; 1.264 + break; 1.265 + case eColorID__moz_cellhighlight: 1.266 + case eColorID__moz_html_cellhighlight: 1.267 + aColor = BASE_ACTIVE_COLOR; 1.268 + break; 1.269 + case eColorID__moz_cellhighlighttext: 1.270 + case eColorID__moz_html_cellhighlighttext: 1.271 + aColor = TEXT_ACTIVE_COLOR; 1.272 + break; 1.273 + case eColorID__moz_menuhover: 1.274 + aColor = BG_PRELIGHT_COLOR; 1.275 + break; 1.276 + case eColorID__moz_menuhovertext: 1.277 + aColor = FG_PRELIGHT_COLOR; 1.278 + break; 1.279 + case eColorID__moz_oddtreerow: 1.280 + aColor = NS_TRANSPARENT; 1.281 + break; 1.282 + case eColorID__moz_nativehyperlinktext: 1.283 + aColor = NS_SAME_AS_FOREGROUND_COLOR; 1.284 + break; 1.285 + case eColorID__moz_comboboxtext: 1.286 + aColor = TEXT_NORMAL_COLOR; 1.287 + break; 1.288 + case eColorID__moz_combobox: 1.289 + aColor = BG_NORMAL_COLOR; 1.290 + break; 1.291 + case eColorID__moz_menubartext: 1.292 + aColor = TEXT_NORMAL_COLOR; 1.293 + break; 1.294 + case eColorID__moz_menubarhovertext: 1.295 + aColor = FG_PRELIGHT_COLOR; 1.296 + break; 1.297 + default: 1.298 + /* default color is BLACK */ 1.299 + aColor = 0; 1.300 + rv = NS_ERROR_FAILURE; 1.301 + break; 1.302 + } 1.303 + 1.304 + return rv; 1.305 +} 1.306 + 1.307 +nsresult 1.308 +nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) 1.309 +{ 1.310 + nsresult rv = nsXPLookAndFeel::GetIntImpl(aID, aResult); 1.311 + if (NS_SUCCEEDED(rv)) 1.312 + return rv; 1.313 + 1.314 + rv = NS_OK; 1.315 + 1.316 + switch (aID) { 1.317 + case eIntID_CaretBlinkTime: 1.318 + aResult = 500; 1.319 + break; 1.320 + 1.321 + case eIntID_CaretWidth: 1.322 + aResult = 1; 1.323 + break; 1.324 + 1.325 + case eIntID_ShowCaretDuringSelection: 1.326 + aResult = 0; 1.327 + break; 1.328 + 1.329 + case eIntID_SelectTextfieldsOnKeyFocus: 1.330 + // Select textfield content when focused by kbd 1.331 + // used by EventStateManager::sTextfieldSelectModel 1.332 + aResult = 1; 1.333 + break; 1.334 + 1.335 + case eIntID_SubmenuDelay: 1.336 + aResult = 200; 1.337 + break; 1.338 + 1.339 + case eIntID_TooltipDelay: 1.340 + aResult = 500; 1.341 + break; 1.342 + 1.343 + case eIntID_MenusCanOverlapOSBar: 1.344 + // we want XUL popups to be able to overlap the task bar. 1.345 + aResult = 1; 1.346 + break; 1.347 + 1.348 + case eIntID_ScrollArrowStyle: 1.349 + aResult = eScrollArrowStyle_Single; 1.350 + break; 1.351 + 1.352 + case eIntID_ScrollSliderStyle: 1.353 + aResult = eScrollThumbStyle_Proportional; 1.354 + break; 1.355 + 1.356 + case eIntID_TouchEnabled: 1.357 + aResult = 1; 1.358 + break; 1.359 + 1.360 + case eIntID_WindowsDefaultTheme: 1.361 + case eIntID_WindowsThemeIdentifier: 1.362 + case eIntID_OperatingSystemVersionIdentifier: 1.363 + aResult = 0; 1.364 + rv = NS_ERROR_NOT_IMPLEMENTED; 1.365 + break; 1.366 + 1.367 + case eIntID_IMERawInputUnderlineStyle: 1.368 + case eIntID_IMEConvertedTextUnderlineStyle: 1.369 + aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID; 1.370 + break; 1.371 + 1.372 + case eIntID_IMESelectedRawTextUnderlineStyle: 1.373 + case eIntID_IMESelectedConvertedTextUnderline: 1.374 + aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE; 1.375 + break; 1.376 + 1.377 + case eIntID_SpellCheckerUnderlineStyle: 1.378 + aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY; 1.379 + break; 1.380 + 1.381 + case eIntID_ScrollbarButtonAutoRepeatBehavior: 1.382 + aResult = 0; 1.383 + break; 1.384 + 1.385 + case eIntID_PhysicalHomeButton: { 1.386 + char propValue[PROPERTY_VALUE_MAX]; 1.387 + property_get("ro.moz.has_home_button", propValue, "1"); 1.388 + aResult = atoi(propValue); 1.389 + break; 1.390 + } 1.391 + 1.392 + default: 1.393 + aResult = 0; 1.394 + rv = NS_ERROR_FAILURE; 1.395 + } 1.396 + 1.397 + return rv; 1.398 +} 1.399 + 1.400 +nsresult 1.401 +nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult) 1.402 +{ 1.403 + nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult); 1.404 + if (NS_SUCCEEDED(res)) 1.405 + return res; 1.406 + res = NS_OK; 1.407 + 1.408 + switch (aID) { 1.409 + case eFloatID_IMEUnderlineRelativeSize: 1.410 + aResult = 1.0f; 1.411 + break; 1.412 + case eFloatID_SpellCheckerUnderlineRelativeSize: 1.413 + aResult = 1.0f; 1.414 + break; 1.415 + default: 1.416 + aResult = -1.0; 1.417 + res = NS_ERROR_FAILURE; 1.418 + } 1.419 + return res; 1.420 +} 1.421 + 1.422 +/*virtual*/ 1.423 +bool 1.424 +nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, 1.425 + gfxFontStyle& aFontStyle, 1.426 + float aDevPixPerCSSPixel) 1.427 +{ 1.428 + aFontName.AssignLiteral("\"Fira Sans OT\""); 1.429 + aFontStyle.style = NS_FONT_STYLE_NORMAL; 1.430 + aFontStyle.weight = NS_FONT_WEIGHT_NORMAL; 1.431 + aFontStyle.stretch = NS_FONT_STRETCH_NORMAL; 1.432 + aFontStyle.size = 9.0 * 96.0f / 72.0f; 1.433 + aFontStyle.systemFont = true; 1.434 + return true; 1.435 +} 1.436 + 1.437 +/*virtual*/ 1.438 +bool 1.439 +nsLookAndFeel::GetEchoPasswordImpl() { 1.440 + return true; 1.441 +} 1.442 + 1.443 +/*virtual*/ 1.444 +uint32_t 1.445 +nsLookAndFeel::GetPasswordMaskDelayImpl() 1.446 +{ 1.447 + // Same value on Android framework 1.448 + return 1500; 1.449 +} 1.450 + 1.451 +/* virtual */ 1.452 +char16_t 1.453 +nsLookAndFeel::GetPasswordCharacterImpl() 1.454 +{ 1.455 + return UNICODE_BULLET; 1.456 +}