1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef __nsLookAndFeel
7 #define __nsLookAndFeel
8 
9 #include <windows.h>
10 
11 #include "nsXPLookAndFeel.h"
12 #include "gfxFont.h"
13 #include "mozilla/RangedArray.h"
14 #include "nsIWindowsRegKey.h"
15 
16 /*
17  * Gesture System Metrics
18  */
19 #ifndef SM_DIGITIZER
20 #define SM_DIGITIZER 94
21 #define TABLET_CONFIG_NONE 0x00000000
22 #define NID_INTEGRATED_TOUCH 0x00000001
23 #define NID_EXTERNAL_TOUCH 0x00000002
24 #define NID_INTEGRATED_PEN 0x00000004
25 #define NID_EXTERNAL_PEN 0x00000008
26 #define NID_MULTI_INPUT 0x00000040
27 #define NID_READY 0x00000080
28 #endif
29 
30 /*
31  * Tablet mode detection
32  */
33 #ifndef SM_SYSTEMDOCKED
34 #define SM_CONVERTIBLESLATEMODE 0x00002003
35 #define SM_SYSTEMDOCKED 0x00002004
36 #endif
37 
38 /*
39  * Color constant inclusive bounds for GetSysColor
40  */
41 #define SYS_COLOR_MIN 0
42 #define SYS_COLOR_MAX 30
43 #define SYS_COLOR_COUNT (SYS_COLOR_MAX - SYS_COLOR_MIN + 1)
44 
45 class nsLookAndFeel final : public nsXPLookAndFeel {
46   static OperatingSystemVersion GetOperatingSystemVersion();
47 
48  public:
49   nsLookAndFeel();
50   virtual ~nsLookAndFeel();
51 
52   void NativeInit() final;
53   void RefreshImpl() override;
54   nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
55   nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
56   nsresult GetFloatImpl(FloatID aID, float& aResult) override;
57   bool GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle,
58                    float aDevPixPerCSSPixel) override;
59   char16_t GetPasswordCharacterImpl() override;
60 
61   nsTArray<LookAndFeelInt> GetIntCacheImpl() override;
62   void SetIntCacheImpl(
63       const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) override;
64 
65  private:
66   /**
67    * Fetches the Windows accent color from the Windows settings if
68    * the accent color is set to apply to the title bar, otherwise
69    * returns an error code.
70    */
71   nsresult GetAccentColor(nscolor& aColor);
72 
73   /**
74    * If the Windows accent color from the Windows settings is set
75    * to apply to the title bar, this computes the color that should
76    * be used for text that is to be written over a background that has
77    * the accent color.  Otherwise, (if the accent color should not
78    * apply to the title bar) this returns an error code.
79    */
80   nsresult GetAccentColorText(nscolor& aColor);
81 
82   nscolor GetColorForSysColorIndex(int index);
83 
84   // Content process cached values that get shipped over from the browser
85   // process.
86   int32_t mUseAccessibilityTheme;
87   int32_t mUseDefaultTheme;  // is the current theme a known default?
88   int32_t mNativeThemeId;    // see LookAndFeel enum 'WindowsTheme'
89   int32_t mCaretBlinkTime;
90 
91   // Cached colors and flags indicating success in their retrieval.
92   nscolor mColorMenuHoverText;
93   bool mHasColorMenuHoverText;
94   nscolor mColorAccent;
95   bool mHasColorAccent;
96   nscolor mColorAccentText;
97   bool mHasColorAccentText;
98   nscolor mColorMediaText;
99   bool mHasColorMediaText;
100   nscolor mColorCommunicationsText;
101   bool mHasColorCommunicationsText;
102 
103   nscolor mSysColorTable[SYS_COLOR_COUNT];
104 
105   bool mInitialized;
106 
107   void EnsureInit();
108 
109   struct CachedSystemFont {
CachedSystemFontCachedSystemFont110     CachedSystemFont() : mCacheValid(false) {}
111 
112     bool mCacheValid;
113     bool mHaveFont;
114     nsString mFontName;
115     gfxFontStyle mFontStyle;
116   };
117 
118   mozilla::RangedArray<CachedSystemFont, FontID_MINIMUM,
119                        FontID_MAXIMUM + 1 - FontID_MINIMUM>
120       mSystemFontCache;
121 
122   nsCOMPtr<nsIWindowsRegKey> mDwmKey;
123 };
124 
125 #endif
126