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