widget/qt/nsLookAndFeel.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial