зеркало из https://github.com/mozilla/gecko-dev.git
Bug 714416: Get rid of nsIScreen_MOZILLA_2_0_BRANCH and create nsBaseScreen for shared code. sr=roc
This commit is contained in:
Родитель
bdde79044d
Коммит
625b29ce54
|
@ -1176,8 +1176,7 @@ var FullScreenVideo = {
|
|||
try {
|
||||
this.screen = null;
|
||||
let screenManager = Cc["@mozilla.org/gfx/screenmanager;1"].getService(Ci.nsIScreenManager);
|
||||
let screen = screenManager.primaryScreen.QueryInterface(Ci.nsIScreen_MOZILLA_2_0_BRANCH);
|
||||
this.screen = screen;
|
||||
this.screen = screenManager.primaryScreen;
|
||||
}
|
||||
catch (e) {} // The screen does not support brightness locks
|
||||
},
|
||||
|
|
|
@ -42,8 +42,6 @@
|
|||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsScreenAndroid, nsIScreen, nsIScreen_MOZILLA_2_0_BRANCH)
|
||||
|
||||
nsScreenAndroid::nsScreenAndroid(void *nativeScreen)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -41,23 +41,23 @@
|
|||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsBaseScreen.h"
|
||||
#include "nsIScreenManager.h"
|
||||
#include "nsIScreen.h"
|
||||
#include "WidgetUtils.h"
|
||||
|
||||
class nsScreenAndroid
|
||||
: public nsIScreen
|
||||
, public mozilla::widget::BrightnessLockingWidget
|
||||
class nsScreenAndroid : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenAndroid(void *nativeScreen);
|
||||
~nsScreenAndroid();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
|
||||
protected:
|
||||
void ApplyMinimumBrightness(PRUint32 aBrightness);
|
||||
virtual void ApplyMinimumBrightness(PRUint32 aBrightness) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
class nsScreenManagerAndroid :
|
||||
|
|
|
@ -41,17 +41,18 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "nsIScreen.h"
|
||||
#include "nsBaseScreen.h"
|
||||
|
||||
class nsScreenCocoa : public nsIScreen
|
||||
class nsScreenCocoa : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenCocoa (NSScreen *screen);
|
||||
~nsScreenCocoa ();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
|
||||
NSScreen *CocoaScreen() { return mScreen; }
|
||||
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
#include "nsObjCExceptions.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScreenCocoa, nsIScreen)
|
||||
|
||||
nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
||||
|
|
|
@ -41,8 +41,6 @@
|
|||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsScreenGonk, nsIScreen, nsIScreen)
|
||||
|
||||
nsScreenGonk::nsScreenGonk(void *nativeScreen)
|
||||
{
|
||||
}
|
||||
|
@ -64,16 +62,14 @@ nsScreenGonk::GetRect(PRInt32 *outLeft, PRInt32 *outTop,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenGonk::GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop,
|
||||
PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
return GetRect(outLeft, outTop, outWidth, outHeight);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenGonk::GetPixelDepth(PRInt32 *aPixelDepth)
|
||||
{
|
||||
|
@ -83,7 +79,6 @@ nsScreenGonk::GetPixelDepth(PRInt32 *aPixelDepth)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenGonk::GetColorDepth(PRInt32 *aColorDepth)
|
||||
{
|
||||
|
|
|
@ -41,18 +41,19 @@
|
|||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsBaseScreen.h"
|
||||
#include "nsIScreenManager.h"
|
||||
#include "nsIScreen.h"
|
||||
#include "WidgetUtils.h"
|
||||
|
||||
class nsScreenGonk : public nsIScreen
|
||||
class nsScreenGonk : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenGonk(void *nativeScreen);
|
||||
nsScreenGonk(void* nativeScreen);
|
||||
~nsScreenGonk();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
};
|
||||
|
||||
class nsScreenManagerGonk : public nsIScreenManager
|
||||
|
|
|
@ -58,10 +58,6 @@ nsScreenGtk :: ~nsScreenGtk()
|
|||
}
|
||||
|
||||
|
||||
// addref, release, QI
|
||||
NS_IMPL_ISUPPORTS1(nsScreenGtk, nsIScreen)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenGtk :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#ifndef nsScreenGtk_h___
|
||||
#define nsScreenGtk_h___
|
||||
|
||||
#include "nsIScreen.h"
|
||||
#include "nsBaseScreen.h"
|
||||
#include "nsRect.h"
|
||||
#include "gdk/gdk.h"
|
||||
#ifdef MOZ_X11
|
||||
|
@ -56,14 +56,16 @@ typedef struct {
|
|||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class nsScreenGtk : public nsIScreen
|
||||
class nsScreenGtk : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenGtk();
|
||||
~nsScreenGtk();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
|
||||
void Init(GdkWindow *aRootWindow);
|
||||
#ifdef MOZ_X11
|
||||
|
|
|
@ -38,24 +38,9 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
|
||||
[scriptable, uuid(f728830e-1dd1-11b2-9598-fb9f414f2465)]
|
||||
[scriptable, uuid(498dcd6c-94a2-4c32-8c77-531b583dff37)]
|
||||
interface nsIScreen : nsISupports
|
||||
{
|
||||
void GetRect ( out long left, out long top, out long width, out long height );
|
||||
void GetAvailRect ( out long left, out long top, out long width, out long height );
|
||||
|
||||
readonly attribute long pixelDepth;
|
||||
readonly attribute long colorDepth;
|
||||
};
|
||||
|
||||
|
||||
%{ C++
|
||||
|
||||
%}
|
||||
|
||||
[scriptable, uuid(f7c93d20-c4e4-4628-b343-cb5530b04f15)]
|
||||
interface nsIScreen_MOZILLA_2_0_BRANCH : nsISupports {
|
||||
/**
|
||||
* Levels of brightness for the screen, from off to full brightness.
|
||||
*/
|
||||
|
@ -65,6 +50,9 @@ interface nsIScreen_MOZILLA_2_0_BRANCH : nsISupports {
|
|||
/* The number of different brightness levels */
|
||||
const unsigned long BRIGHTNESS_LEVELS = 2;
|
||||
|
||||
void getRect(out long left, out long top, out long width, out long height);
|
||||
void getAvailRect(out long left, out long top, out long width, out long height);
|
||||
|
||||
/**
|
||||
* Locks the minimum brightness of the screen, forcing it to be at
|
||||
* least as bright as a certain brightness level. Each call to this
|
||||
|
@ -82,5 +70,7 @@ interface nsIScreen_MOZILLA_2_0_BRANCH : nsISupports {
|
|||
* @param brightness A brightness level, one of the above constants.
|
||||
*/
|
||||
void unlockMinimumBrightness(in unsigned long brightness);
|
||||
|
||||
readonly attribute long pixelDepth;
|
||||
readonly attribute long colorDepth;
|
||||
};
|
||||
|
||||
|
|
|
@ -51,10 +51,6 @@ nsScreenOS2 :: ~nsScreenOS2()
|
|||
}
|
||||
|
||||
|
||||
// addref, release, QI
|
||||
NS_IMPL_ISUPPORTS1(nsScreenOS2, nsIScreen)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenOS2 :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#ifndef nsScreenOS2_h___
|
||||
#define nsScreenOS2_h___
|
||||
|
||||
#include "nsIScreen.h"
|
||||
#include "nsBaseScreen.h"
|
||||
|
||||
#define INCL_WIN
|
||||
#define INCL_DOS
|
||||
|
@ -46,14 +46,16 @@
|
|||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class nsScreenOS2 : public nsIScreen
|
||||
class nsScreenOS2 : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenOS2 ( );
|
||||
virtual ~nsScreenOS2();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -79,13 +79,6 @@ nsScreenQt::~nsScreenQt()
|
|||
#endif
|
||||
}
|
||||
|
||||
// addref, release, QI
|
||||
#ifdef MOZ_ENABLE_QMSYSTEM2
|
||||
NS_IMPL_ISUPPORTS2(nsScreenQt, nsIScreen, nsIScreen_MOZILLA_2_0_BRANCH)
|
||||
#else
|
||||
NS_IMPL_ISUPPORTS1(nsScreenQt, nsIScreen)
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenQt::GetRect(PRInt32 *outLeft,PRInt32 *outTop,
|
||||
PRInt32 *outWidth,PRInt32 *outHeight)
|
||||
|
|
|
@ -41,10 +41,9 @@
|
|||
#ifndef nsScreenQt_h___
|
||||
#define nsScreenQt_h___
|
||||
|
||||
#include "nsIScreen.h"
|
||||
#include "nsBaseScreen.h"
|
||||
|
||||
#ifdef MOZ_ENABLE_QMSYSTEM2
|
||||
#include "WidgetUtils.h"
|
||||
namespace MeeGo
|
||||
{
|
||||
class QmDisplayState;
|
||||
|
@ -54,20 +53,20 @@ namespace MeeGo
|
|||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class nsScreenQt : public nsIScreen
|
||||
#ifdef MOZ_ENABLE_QMSYSTEM2
|
||||
, public mozilla::widget::BrightnessLockingWidget
|
||||
#endif
|
||||
class nsScreenQt : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenQt (int aScreen);
|
||||
virtual ~nsScreenQt();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
|
||||
#ifdef MOZ_ENABLE_QMSYSTEM2
|
||||
void ApplyMinimumBrightness(PRUint32 aType);
|
||||
protected:
|
||||
virtual void ApplyMinimumBrightness(PRUint32 aType) MOZ_OVERRIDE;
|
||||
private:
|
||||
MeeGo::QmDisplayState* mDisplayState;
|
||||
#endif
|
||||
|
|
|
@ -80,54 +80,5 @@ WidgetUtils::DOMWindowToWidget(nsIDOMWindow *aDOMWindow)
|
|||
return widget.forget();
|
||||
}
|
||||
|
||||
// class BrightnessLockingWidget
|
||||
|
||||
BrightnessLockingWidget::BrightnessLockingWidget()
|
||||
{
|
||||
for (PRUint32 i = 0; i < nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS; i++)
|
||||
mBrightnessLocks[i] = 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BrightnessLockingWidget::LockMinimumBrightness(PRUint32 aBrightness)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(
|
||||
aBrightness < nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS,
|
||||
"Invalid brightness level to lock");
|
||||
mBrightnessLocks[aBrightness]++;
|
||||
NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0,
|
||||
"Overflow after locking brightness level");
|
||||
|
||||
CheckMinimumBrightness();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BrightnessLockingWidget::UnlockMinimumBrightness(PRUint32 aBrightness)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(
|
||||
aBrightness < nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS,
|
||||
"Invalid brightness level to lock");
|
||||
NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0,
|
||||
"Unlocking a brightness level with no corresponding lock");
|
||||
mBrightnessLocks[aBrightness]--;
|
||||
|
||||
CheckMinimumBrightness();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BrightnessLockingWidget::CheckMinimumBrightness()
|
||||
{
|
||||
PRUint32 brightness = nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS;
|
||||
for (PRUint32 i = 0; i < nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS; i++)
|
||||
if (mBrightnessLocks[i] > 0)
|
||||
brightness = i;
|
||||
|
||||
ApplyMinimumBrightness(brightness);
|
||||
}
|
||||
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include "nsIWidget.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScreen.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace widget {
|
||||
|
@ -61,46 +60,6 @@ public:
|
|||
static already_AddRefed<nsIWidget> DOMWindowToWidget(nsIDOMWindow *aDOMWindow);
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple management of screen brightness locks. This abstract base class
|
||||
* allows all widget implementations to share brightness locking code.
|
||||
*/
|
||||
class BrightnessLockingWidget : public nsIScreen_MOZILLA_2_0_BRANCH
|
||||
{
|
||||
public:
|
||||
BrightnessLockingWidget();
|
||||
|
||||
NS_IMETHOD LockMinimumBrightness(PRUint32 aBrightness);
|
||||
NS_IMETHOD UnlockMinimumBrightness(PRUint32 aBrightness);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Manually set the current level of brightness locking. This is called after
|
||||
* we determine, based on the current active locks, what the strongest
|
||||
* lock is. You should normally not call this function - it will be
|
||||
* called automatically by this class.
|
||||
*
|
||||
* Each widget implementation should implement this in a way that
|
||||
* makes sense there. This is normally the only function that
|
||||
* contains widget-specific code.
|
||||
*
|
||||
* @param aBrightness The current brightness level to set. If this is
|
||||
* nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS
|
||||
* (an impossible value for a brightness level to be),
|
||||
* then that signifies that there is no current
|
||||
* minimum brightness level, and the screen can shut off.
|
||||
*/
|
||||
virtual void ApplyMinimumBrightness(PRUint32 aBrightness) = 0;
|
||||
|
||||
/**
|
||||
* Checks what the minimum brightness value is, and calls
|
||||
* ApplyMinimumBrightness.
|
||||
*/
|
||||
void CheckMinimumBrightness();
|
||||
|
||||
PRUint32 mBrightnessLocks[nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS];
|
||||
};
|
||||
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -70,10 +70,6 @@ nsScreenWin :: ~nsScreenWin()
|
|||
}
|
||||
|
||||
|
||||
// addref, release, QI
|
||||
NS_IMPL_ISUPPORTS1(nsScreenWin, nsIScreen)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenWin :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
|
|
|
@ -39,18 +39,20 @@
|
|||
#define nsScreenWin_h___
|
||||
|
||||
#include <windows.h>
|
||||
#include "nsIScreen.h"
|
||||
#include "nsBaseScreen.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class nsScreenWin : public nsIScreen
|
||||
class nsScreenWin : public nsBaseScreen
|
||||
{
|
||||
public:
|
||||
nsScreenWin ( void* inScreen );
|
||||
~nsScreenWin();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREEN
|
||||
NS_IMETHOD GetRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetAvailRect(PRInt32* aLeft, PRInt32* aTop, PRInt32* aWidth, PRInt32* aHeight);
|
||||
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);
|
||||
NS_IMETHOD GetColorDepth(PRInt32* aColorDepth);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ DEFINES += \
|
|||
|
||||
CPPSRCS = \
|
||||
nsBaseAppShell.cpp \
|
||||
nsBaseScreen.cpp \
|
||||
nsBaseWidget.cpp \
|
||||
nsTransferable.cpp \
|
||||
nsHTMLFormatConverter.cpp \
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Jones <jones.chris.g@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsBaseScreen.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsBaseScreen, nsIScreen)
|
||||
|
||||
nsBaseScreen::nsBaseScreen()
|
||||
{
|
||||
for (PRUint32 i = 0; i < nsIScreen::BRIGHTNESS_LEVELS; i++)
|
||||
mBrightnessLocks[i] = 0;
|
||||
}
|
||||
|
||||
nsBaseScreen::~nsBaseScreen() { }
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBaseScreen::LockMinimumBrightness(PRUint32 aBrightness)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(
|
||||
aBrightness < nsIScreen::BRIGHTNESS_LEVELS,
|
||||
"Invalid brightness level to lock");
|
||||
mBrightnessLocks[aBrightness]++;
|
||||
NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0,
|
||||
"Overflow after locking brightness level");
|
||||
|
||||
CheckMinimumBrightness();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBaseScreen::UnlockMinimumBrightness(PRUint32 aBrightness)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(
|
||||
aBrightness < nsIScreen::BRIGHTNESS_LEVELS,
|
||||
"Invalid brightness level to lock");
|
||||
NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0,
|
||||
"Unlocking a brightness level with no corresponding lock");
|
||||
mBrightnessLocks[aBrightness]--;
|
||||
|
||||
CheckMinimumBrightness();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsBaseScreen::CheckMinimumBrightness()
|
||||
{
|
||||
PRUint32 brightness = nsIScreen::BRIGHTNESS_LEVELS;
|
||||
for (PRUint32 i = 0; i < nsIScreen::BRIGHTNESS_LEVELS; i++)
|
||||
if (mBrightnessLocks[i] > 0)
|
||||
brightness = i;
|
||||
|
||||
ApplyMinimumBrightness(brightness);
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=8 et :
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Chris Jones <jones.chris.g@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsBaseScreen_h
|
||||
#define nsBaseScreen_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsIScreen.h"
|
||||
|
||||
class nsBaseScreen : public nsIScreen
|
||||
{
|
||||
public:
|
||||
nsBaseScreen();
|
||||
virtual ~nsBaseScreen();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIScreen interface
|
||||
|
||||
/**
|
||||
* Simple management of screen brightness locks. This abstract base class
|
||||
* allows all widget implementations to share brightness locking code.
|
||||
*/
|
||||
NS_IMETHOD LockMinimumBrightness(PRUint32 aBrightness);
|
||||
NS_IMETHOD UnlockMinimumBrightness(PRUint32 aBrightness);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Manually set the current level of brightness locking. This is called after
|
||||
* we determine, based on the current active locks, what the strongest
|
||||
* lock is. You should normally not call this function - it will be
|
||||
* called automatically by this class.
|
||||
*
|
||||
* Each widget implementation should implement this in a way that
|
||||
* makes sense there. This is normally the only function that
|
||||
* contains widget-specific code.
|
||||
*
|
||||
* The default implementation does nothing.
|
||||
*
|
||||
* @param aBrightness The current brightness level to set. If this is
|
||||
* nsIScreen_MOZILLA_2_0_BRANCH::BRIGHTNESS_LEVELS
|
||||
* (an impossible value for a brightness level to be),
|
||||
* then that signifies that there is no current
|
||||
* minimum brightness level, and the screen can shut off.
|
||||
*/
|
||||
virtual void ApplyMinimumBrightness(PRUint32 aBrightness) { }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Checks what the minimum brightness value is, and calls
|
||||
* ApplyMinimumBrightness.
|
||||
*/
|
||||
void CheckMinimumBrightness();
|
||||
|
||||
PRUint32 mBrightnessLocks[nsIScreen::BRIGHTNESS_LEVELS];
|
||||
};
|
||||
|
||||
#endif // nsBaseScreen_h
|
Загрузка…
Ссылка в новой задаче