2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-03-31 02:32:18 +04:00
|
|
|
|
|
|
|
#ifndef __nsXPLookAndFeel
|
|
|
|
#define __nsXPLookAndFeel
|
|
|
|
|
2011-09-09 06:27:12 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2015-04-22 17:58:15 +03:00
|
|
|
#include "nsTArray.h"
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
class nsLookAndFeel;
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
struct nsLookAndFeelIntPref {
|
2001-11-07 09:24:10 +03:00
|
|
|
const char* name;
|
2011-09-09 06:27:13 +04:00
|
|
|
mozilla::LookAndFeel::IntID id;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isSet;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t intVar;
|
2000-03-31 02:32:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nsLookAndFeelFloatPref {
|
2001-11-07 09:24:10 +03:00
|
|
|
const char* name;
|
2011-09-09 06:27:13 +04:00
|
|
|
mozilla::LookAndFeel::FloatID id;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isSet;
|
2000-03-31 02:32:18 +04:00
|
|
|
float floatVar;
|
|
|
|
};
|
|
|
|
|
2001-11-06 05:41:04 +03:00
|
|
|
#define CACHE_BLOCK(x) ((x) >> 5)
|
|
|
|
#define CACHE_BIT(x) (1 << ((x)&31))
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
#define COLOR_CACHE_SIZE (CACHE_BLOCK(LookAndFeel::eColorID_LAST_COLOR) + 1)
|
2001-11-06 05:41:04 +03:00
|
|
|
#define IS_COLOR_CACHED(x) \
|
|
|
|
(CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)])
|
2008-09-05 13:57:52 +04:00
|
|
|
#define CLEAR_COLOR_CACHE(x) \
|
|
|
|
nsXPLookAndFeel::sCachedColors[(x)] = 0; \
|
|
|
|
nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] &= ~(CACHE_BIT(x));
|
2001-11-06 05:41:04 +03:00
|
|
|
#define CACHE_COLOR(x, y) \
|
|
|
|
nsXPLookAndFeel::sCachedColors[(x)] = y; \
|
|
|
|
nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
class nsXPLookAndFeel : public mozilla::LookAndFeel {
|
2000-03-31 02:32:18 +04:00
|
|
|
public:
|
|
|
|
virtual ~nsXPLookAndFeel();
|
|
|
|
|
2017-04-04 17:22:00 +03:00
|
|
|
static nsXPLookAndFeel* GetInstance();
|
2011-09-09 06:27:11 +04:00
|
|
|
static void Shutdown();
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
void Init();
|
|
|
|
|
|
|
|
//
|
|
|
|
// All these routines will return NS_OK if they have a value,
|
|
|
|
// in which case the nsLookAndFeel should use that value;
|
|
|
|
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
|
|
|
|
// platform-specific nsLookAndFeel should use its own values instead.
|
|
|
|
//
|
2015-09-25 01:59:00 +03:00
|
|
|
nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors,
|
|
|
|
nscolor& aResult);
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult);
|
2011-09-09 06:27:13 +04:00
|
|
|
virtual nsresult GetFloatImpl(FloatID aID, float& aResult);
|
|
|
|
|
2012-02-21 03:19:48 +04:00
|
|
|
// This one is different: there are no override prefs (fixme?), so
|
|
|
|
// there is no XP implementation, only per-system impls.
|
2019-02-08 16:22:11 +03:00
|
|
|
virtual bool GetFontImpl(FontID aID, nsString& aName,
|
|
|
|
gfxFontStyle& aStyle) = 0;
|
2012-02-21 03:19:48 +04:00
|
|
|
|
2011-09-09 06:27:13 +04:00
|
|
|
virtual void RefreshImpl();
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
virtual char16_t GetPasswordCharacterImpl() { return char16_t('*'); }
|
2011-09-09 06:27:13 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool GetEchoPasswordImpl() { return false; }
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual uint32_t GetPasswordMaskDelayImpl() { return 600; }
|
2012-07-13 06:26:20 +04:00
|
|
|
|
2015-04-22 17:58:15 +03:00
|
|
|
virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
|
|
|
|
virtual void SetIntCacheImpl(
|
|
|
|
const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}
|
2018-09-15 04:00:07 +03:00
|
|
|
void SetShouldRetainCacheImplForTest(bool aValue) {
|
|
|
|
mShouldRetainCacheForTest = aValue;
|
|
|
|
}
|
2015-04-22 17:58:15 +03:00
|
|
|
|
2017-08-03 23:16:31 +03:00
|
|
|
virtual void NativeInit() = 0;
|
|
|
|
|
2019-02-02 01:07:26 +03:00
|
|
|
void SetPrefersReducedMotionOverrideForTest(bool aValue) {
|
|
|
|
sIsInPrefersReducedMotionForTest = true;
|
|
|
|
sPrefersReducedMotionForTest = aValue;
|
|
|
|
}
|
|
|
|
void ResetPrefersReducedMotionOverrideForTest() {
|
|
|
|
sIsInPrefersReducedMotionForTest = false;
|
|
|
|
sPrefersReducedMotionForTest = false;
|
|
|
|
}
|
|
|
|
|
2000-03-31 02:32:18 +04:00
|
|
|
protected:
|
2011-09-09 06:27:13 +04:00
|
|
|
nsXPLookAndFeel();
|
|
|
|
|
2011-09-09 06:27:11 +04:00
|
|
|
static void IntPrefChanged(nsLookAndFeelIntPref* data);
|
|
|
|
static void FloatPrefChanged(nsLookAndFeelFloatPref* data);
|
|
|
|
static void ColorPrefChanged(unsigned int index, const char* prefName);
|
2011-05-23 18:54:03 +04:00
|
|
|
void InitFromPref(nsLookAndFeelIntPref* aPref);
|
|
|
|
void InitFromPref(nsLookAndFeelFloatPref* aPref);
|
2012-08-22 19:56:38 +04:00
|
|
|
void InitColorFromPref(int32_t aIndex);
|
2011-09-09 06:27:13 +04:00
|
|
|
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsSpecialColor(ColorID aID, nscolor& aColor);
|
2015-09-25 01:59:00 +03:00
|
|
|
bool ColorIsNotCSSAccessible(ColorID aID);
|
|
|
|
nscolor GetStandinForNativeColor(ColorID aID);
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
static void OnPrefChanged(const char* aPref, void* aClosure);
|
2011-09-09 06:27:11 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sInitialized;
|
2000-04-12 02:34:55 +04:00
|
|
|
static nsLookAndFeelIntPref sIntPrefs[];
|
|
|
|
static nsLookAndFeelFloatPref sFloatPrefs[];
|
2004-03-02 06:44:26 +03:00
|
|
|
/* this length must not be shorter than the length of the longest string in
|
|
|
|
* the array see nsXPLookAndFeel.cpp
|
|
|
|
*/
|
2017-09-13 14:48:07 +03:00
|
|
|
static const char sColorPrefs[][41];
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t sCachedColors[LookAndFeel::eColorID_LAST_COLOR];
|
|
|
|
static int32_t sCachedColorBits[COLOR_CACHE_SIZE];
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sUseNativeColors;
|
2016-06-09 14:30:44 +03:00
|
|
|
static bool sFindbarModalHighlight;
|
2000-03-31 02:32:18 +04:00
|
|
|
|
2017-04-04 17:22:00 +03:00
|
|
|
static nsXPLookAndFeel* sInstance;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sShutdown;
|
2018-09-15 04:00:07 +03:00
|
|
|
|
2019-02-02 01:07:26 +03:00
|
|
|
static bool sIsInPrefersReducedMotionForTest;
|
|
|
|
static bool sPrefersReducedMotionForTest;
|
|
|
|
|
2018-09-15 04:00:07 +03:00
|
|
|
// True if we shouldn't clear the cache value in RefreshImpl().
|
|
|
|
// NOTE: This should be used only for testing.
|
|
|
|
bool mShouldRetainCacheForTest;
|
2011-09-09 06:27:11 +04:00
|
|
|
};
|
2000-03-31 02:32:18 +04:00
|
|
|
|
|
|
|
#endif
|