widget/xpwidgets/nsBaseScreen.cpp

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #define MOZ_FATAL_ASSERTIONS_FOR_THREAD_SAFETY
michael@0 9
michael@0 10 #include "nsBaseScreen.h"
michael@0 11
michael@0 12 NS_IMPL_ISUPPORTS(nsBaseScreen, nsIScreen)
michael@0 13
michael@0 14 nsBaseScreen::nsBaseScreen()
michael@0 15 {
michael@0 16 for (uint32_t i = 0; i < nsIScreen::BRIGHTNESS_LEVELS; i++)
michael@0 17 mBrightnessLocks[i] = 0;
michael@0 18 }
michael@0 19
michael@0 20 nsBaseScreen::~nsBaseScreen() { }
michael@0 21
michael@0 22 NS_IMETHODIMP
michael@0 23 nsBaseScreen::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop,
michael@0 24 int32_t *outWidth, int32_t *outHeight)
michael@0 25 {
michael@0 26 return GetRect(outLeft, outTop, outWidth, outHeight);
michael@0 27 }
michael@0 28
michael@0 29 NS_IMETHODIMP
michael@0 30 nsBaseScreen::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop,
michael@0 31 int32_t *outWidth, int32_t *outHeight)
michael@0 32 {
michael@0 33 return GetAvailRect(outLeft, outTop, outWidth, outHeight);
michael@0 34 }
michael@0 35
michael@0 36 NS_IMETHODIMP
michael@0 37 nsBaseScreen::LockMinimumBrightness(uint32_t aBrightness)
michael@0 38 {
michael@0 39 NS_ABORT_IF_FALSE(
michael@0 40 aBrightness < nsIScreen::BRIGHTNESS_LEVELS,
michael@0 41 "Invalid brightness level to lock");
michael@0 42 mBrightnessLocks[aBrightness]++;
michael@0 43 NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0,
michael@0 44 "Overflow after locking brightness level");
michael@0 45
michael@0 46 CheckMinimumBrightness();
michael@0 47
michael@0 48 return NS_OK;
michael@0 49 }
michael@0 50
michael@0 51 NS_IMETHODIMP
michael@0 52 nsBaseScreen::UnlockMinimumBrightness(uint32_t aBrightness)
michael@0 53 {
michael@0 54 NS_ABORT_IF_FALSE(
michael@0 55 aBrightness < nsIScreen::BRIGHTNESS_LEVELS,
michael@0 56 "Invalid brightness level to lock");
michael@0 57 NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0,
michael@0 58 "Unlocking a brightness level with no corresponding lock");
michael@0 59 mBrightnessLocks[aBrightness]--;
michael@0 60
michael@0 61 CheckMinimumBrightness();
michael@0 62
michael@0 63 return NS_OK;
michael@0 64 }
michael@0 65
michael@0 66 void
michael@0 67 nsBaseScreen::CheckMinimumBrightness()
michael@0 68 {
michael@0 69 uint32_t brightness = nsIScreen::BRIGHTNESS_LEVELS;
michael@0 70 for (int32_t i = nsIScreen::BRIGHTNESS_LEVELS - 1; i >=0; i--) {
michael@0 71 if (mBrightnessLocks[i] > 0) {
michael@0 72 brightness = i;
michael@0 73 break;
michael@0 74 }
michael@0 75 }
michael@0 76
michael@0 77 ApplyMinimumBrightness(brightness);
michael@0 78 }
michael@0 79
michael@0 80 NS_IMETHODIMP
michael@0 81 nsBaseScreen::GetContentsScaleFactor(double* aContentsScaleFactor)
michael@0 82 {
michael@0 83 *aContentsScaleFactor = 1.0;
michael@0 84 return NS_OK;
michael@0 85 }

mercurial