Tue, 06 Jan 2015 21:39:09 +0100
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++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef _NS_DEVICECONTEXT_H_ |
michael@0 | 7 | #define _NS_DEVICECONTEXT_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> // for uint32_t |
michael@0 | 10 | #include <sys/types.h> // for int32_t |
michael@0 | 11 | #include "gfxTypes.h" // for gfxFloat |
michael@0 | 12 | #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 |
michael@0 | 13 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 14 | #include "nsCOMPtr.h" // for nsCOMPtr |
michael@0 | 15 | #include "nsCoord.h" // for nscoord |
michael@0 | 16 | #include "nsError.h" // for nsresult |
michael@0 | 17 | #include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING |
michael@0 | 18 | #include "nsMathUtils.h" // for NS_round |
michael@0 | 19 | #include "nscore.h" // for char16_t, nsAString |
michael@0 | 20 | #include "mozilla/AppUnits.h" // for AppUnits |
michael@0 | 21 | |
michael@0 | 22 | class gfxASurface; |
michael@0 | 23 | class gfxTextPerfMetrics; |
michael@0 | 24 | class gfxUserFontSet; |
michael@0 | 25 | class nsFont; |
michael@0 | 26 | class nsFontCache; |
michael@0 | 27 | class nsFontMetrics; |
michael@0 | 28 | class nsIAtom; |
michael@0 | 29 | class nsIDeviceContextSpec; |
michael@0 | 30 | class nsIScreen; |
michael@0 | 31 | class nsIScreenManager; |
michael@0 | 32 | class nsIWidget; |
michael@0 | 33 | class nsRect; |
michael@0 | 34 | class nsRenderingContext; |
michael@0 | 35 | |
michael@0 | 36 | class nsDeviceContext MOZ_FINAL |
michael@0 | 37 | { |
michael@0 | 38 | public: |
michael@0 | 39 | nsDeviceContext(); |
michael@0 | 40 | |
michael@0 | 41 | NS_INLINE_DECL_REFCOUNTING(nsDeviceContext) |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Initialize the device context from a widget |
michael@0 | 45 | * @param aWidget a widget to initialize the device context from |
michael@0 | 46 | * @return error status |
michael@0 | 47 | */ |
michael@0 | 48 | nsresult Init(nsIWidget *aWidget); |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Initialize the device context from a device context spec |
michael@0 | 52 | * @param aDevSpec the specification of the printing device |
michael@0 | 53 | * @return error status |
michael@0 | 54 | */ |
michael@0 | 55 | nsresult InitForPrinting(nsIDeviceContextSpec *aDevSpec); |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * Create a rendering context and initialize it. Only call this |
michael@0 | 59 | * method on device contexts that were initialized for printing. |
michael@0 | 60 | * |
michael@0 | 61 | * @return the new rendering context (guaranteed to be non-null) |
michael@0 | 62 | */ |
michael@0 | 63 | already_AddRefed<nsRenderingContext> CreateRenderingContext(); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Gets the number of app units in one CSS pixel; this number is global, |
michael@0 | 67 | * not unique to each device context. |
michael@0 | 68 | */ |
michael@0 | 69 | static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); } |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Gets the number of app units in one device pixel; this number |
michael@0 | 73 | * is usually a factor of AppUnitsPerCSSPixel(), although that is |
michael@0 | 74 | * not guaranteed. |
michael@0 | 75 | */ |
michael@0 | 76 | int32_t AppUnitsPerDevPixel() const { return mAppUnitsPerDevPixel; } |
michael@0 | 77 | |
michael@0 | 78 | /** |
michael@0 | 79 | * Convert device pixels which is used for gfx/thebes to nearest |
michael@0 | 80 | * (rounded) app units |
michael@0 | 81 | */ |
michael@0 | 82 | nscoord GfxUnitsToAppUnits(gfxFloat aGfxUnits) const |
michael@0 | 83 | { return nscoord(NS_round(aGfxUnits * AppUnitsPerDevPixel())); } |
michael@0 | 84 | |
michael@0 | 85 | /** |
michael@0 | 86 | * Convert app units to device pixels which is used for gfx/thebes. |
michael@0 | 87 | */ |
michael@0 | 88 | gfxFloat AppUnitsToGfxUnits(nscoord aAppUnits) const |
michael@0 | 89 | { return gfxFloat(aAppUnits) / AppUnitsPerDevPixel(); } |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Gets the number of app units in one physical inch; this is the |
michael@0 | 93 | * device's DPI times AppUnitsPerDevPixel(). |
michael@0 | 94 | */ |
michael@0 | 95 | int32_t AppUnitsPerPhysicalInch() const |
michael@0 | 96 | { return mAppUnitsPerPhysicalInch; } |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Gets the number of app units in one CSS inch; this is |
michael@0 | 100 | * 96 times AppUnitsPerCSSPixel. |
michael@0 | 101 | */ |
michael@0 | 102 | static int32_t AppUnitsPerCSSInch() { return mozilla::AppUnitsPerCSSInch(); } |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Get the unscaled ratio of app units to dev pixels; useful if something |
michael@0 | 106 | * needs to be converted from to unscaled pixels |
michael@0 | 107 | */ |
michael@0 | 108 | int32_t UnscaledAppUnitsPerDevPixel() const |
michael@0 | 109 | { return mAppUnitsPerDevNotScaledPixel; } |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Get the nsFontMetrics that describe the properties of |
michael@0 | 113 | * an nsFont. |
michael@0 | 114 | * @param aFont font description to obtain metrics for |
michael@0 | 115 | * @param aLanguage the language of the document |
michael@0 | 116 | * @param aMetrics out parameter for font metrics |
michael@0 | 117 | * @param aUserFontSet user font set |
michael@0 | 118 | * @return error status |
michael@0 | 119 | */ |
michael@0 | 120 | nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage, |
michael@0 | 121 | gfxUserFontSet* aUserFontSet, |
michael@0 | 122 | gfxTextPerfMetrics* aTextPerf, |
michael@0 | 123 | nsFontMetrics*& aMetrics); |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Notification when a font metrics instance created for this device is |
michael@0 | 127 | * about to be deleted |
michael@0 | 128 | */ |
michael@0 | 129 | nsresult FontMetricsDeleted(const nsFontMetrics* aFontMetrics); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Attempt to free up resources by flushing out any fonts no longer |
michael@0 | 133 | * referenced by anything other than the font cache itself. |
michael@0 | 134 | * @return error status |
michael@0 | 135 | */ |
michael@0 | 136 | nsresult FlushFontCache(); |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Return the bit depth of the device. |
michael@0 | 140 | */ |
michael@0 | 141 | nsresult GetDepth(uint32_t& aDepth); |
michael@0 | 142 | |
michael@0 | 143 | /** |
michael@0 | 144 | * Get the size of the displayable area of the output device |
michael@0 | 145 | * in app units. |
michael@0 | 146 | * @param aWidth out parameter for width |
michael@0 | 147 | * @param aHeight out parameter for height |
michael@0 | 148 | * @return error status |
michael@0 | 149 | */ |
michael@0 | 150 | nsresult GetDeviceSurfaceDimensions(nscoord& aWidth, nscoord& aHeight); |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * Get the size of the content area of the output device in app |
michael@0 | 154 | * units. This corresponds on a screen device, for instance, to |
michael@0 | 155 | * the entire screen. |
michael@0 | 156 | * @param aRect out parameter for full rect. Position (x,y) will |
michael@0 | 157 | * be (0,0) or relative to the primary monitor if |
michael@0 | 158 | * this is not the primary. |
michael@0 | 159 | * @return error status |
michael@0 | 160 | */ |
michael@0 | 161 | nsresult GetRect(nsRect& aRect); |
michael@0 | 162 | |
michael@0 | 163 | /** |
michael@0 | 164 | * Get the size of the content area of the output device in app |
michael@0 | 165 | * units. This corresponds on a screen device, for instance, to |
michael@0 | 166 | * the area reported by GetDeviceSurfaceDimensions, minus the |
michael@0 | 167 | * taskbar (Windows) or menubar (Macintosh). |
michael@0 | 168 | * @param aRect out parameter for client rect. Position (x,y) will |
michael@0 | 169 | * be (0,0) adjusted for any upper/left non-client |
michael@0 | 170 | * space if present or relative to the primary |
michael@0 | 171 | * monitor if this is not the primary. |
michael@0 | 172 | * @return error status |
michael@0 | 173 | */ |
michael@0 | 174 | nsresult GetClientRect(nsRect& aRect); |
michael@0 | 175 | |
michael@0 | 176 | /** |
michael@0 | 177 | * Inform the output device that output of a document is beginning |
michael@0 | 178 | * Used for print related device contexts. Must be matched 1:1 with |
michael@0 | 179 | * EndDocument() or AbortDocument(). |
michael@0 | 180 | * |
michael@0 | 181 | * @param aTitle - title of Document |
michael@0 | 182 | * @param aPrintToFileName - name of file to print to, if nullptr |
michael@0 | 183 | * then don't print to file |
michael@0 | 184 | * @param aStartPage - starting page number (must be greater than zero) |
michael@0 | 185 | * @param aEndPage - ending page number (must be less than or |
michael@0 | 186 | * equal to number of pages) |
michael@0 | 187 | * |
michael@0 | 188 | * @return error status |
michael@0 | 189 | */ |
michael@0 | 190 | nsresult BeginDocument(const nsAString& aTitle, |
michael@0 | 191 | char16_t* aPrintToFileName, |
michael@0 | 192 | int32_t aStartPage, |
michael@0 | 193 | int32_t aEndPage); |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * Inform the output device that output of a document is ending. |
michael@0 | 197 | * Used for print related device contexts. Must be matched 1:1 with |
michael@0 | 198 | * BeginDocument() |
michael@0 | 199 | * @return error status |
michael@0 | 200 | */ |
michael@0 | 201 | nsresult EndDocument(); |
michael@0 | 202 | |
michael@0 | 203 | /** |
michael@0 | 204 | * Inform the output device that output of a document is being aborted. |
michael@0 | 205 | * Must be matched 1:1 with BeginDocument() |
michael@0 | 206 | * @return error status |
michael@0 | 207 | */ |
michael@0 | 208 | nsresult AbortDocument(); |
michael@0 | 209 | |
michael@0 | 210 | /** |
michael@0 | 211 | * Inform the output device that output of a page is beginning |
michael@0 | 212 | * Used for print related device contexts. Must be matched 1:1 with |
michael@0 | 213 | * EndPage() and within a BeginDocument()/EndDocument() pair. |
michael@0 | 214 | * @return error status |
michael@0 | 215 | */ |
michael@0 | 216 | nsresult BeginPage(); |
michael@0 | 217 | |
michael@0 | 218 | /** |
michael@0 | 219 | * Inform the output device that output of a page is ending |
michael@0 | 220 | * Used for print related device contexts. Must be matched 1:1 with |
michael@0 | 221 | * BeginPage() and within a BeginDocument()/EndDocument() pair. |
michael@0 | 222 | * @return error status |
michael@0 | 223 | */ |
michael@0 | 224 | nsresult EndPage(); |
michael@0 | 225 | |
michael@0 | 226 | /** |
michael@0 | 227 | * Check to see if the DPI has changed |
michael@0 | 228 | * @return whether there was actually a change in the DPI (whether |
michael@0 | 229 | * AppUnitsPerDevPixel() or AppUnitsPerPhysicalInch() |
michael@0 | 230 | * changed) |
michael@0 | 231 | */ |
michael@0 | 232 | bool CheckDPIChange(); |
michael@0 | 233 | |
michael@0 | 234 | /** |
michael@0 | 235 | * Set the pixel scaling factor: all lengths are multiplied by this factor |
michael@0 | 236 | * when we convert them to device pixels. Returns whether the ratio of |
michael@0 | 237 | * app units to dev pixels changed because of the scale factor. |
michael@0 | 238 | */ |
michael@0 | 239 | bool SetPixelScale(float aScale); |
michael@0 | 240 | |
michael@0 | 241 | /** |
michael@0 | 242 | * Returns the pixel scaling factor (page zoom factor) applied. |
michael@0 | 243 | */ |
michael@0 | 244 | float GetPixelScale() const { return mPixelScale; } |
michael@0 | 245 | |
michael@0 | 246 | /** |
michael@0 | 247 | * True if this device context was created for printing. |
michael@0 | 248 | */ |
michael@0 | 249 | bool IsPrinterSurface(); |
michael@0 | 250 | |
michael@0 | 251 | private: |
michael@0 | 252 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 253 | ~nsDeviceContext(); |
michael@0 | 254 | |
michael@0 | 255 | void SetDPI(); |
michael@0 | 256 | void ComputeClientRectUsingScreen(nsRect *outRect); |
michael@0 | 257 | void ComputeFullAreaUsingScreen(nsRect *outRect); |
michael@0 | 258 | void FindScreen(nsIScreen **outScreen); |
michael@0 | 259 | void CalcPrintingSize(); |
michael@0 | 260 | void UpdateScaledAppUnits(); |
michael@0 | 261 | |
michael@0 | 262 | nscoord mWidth; |
michael@0 | 263 | nscoord mHeight; |
michael@0 | 264 | uint32_t mDepth; |
michael@0 | 265 | int32_t mAppUnitsPerDevPixel; |
michael@0 | 266 | int32_t mAppUnitsPerDevNotScaledPixel; |
michael@0 | 267 | int32_t mAppUnitsPerPhysicalInch; |
michael@0 | 268 | float mPixelScale; |
michael@0 | 269 | float mPrintingScale; |
michael@0 | 270 | |
michael@0 | 271 | nsFontCache* mFontCache; |
michael@0 | 272 | nsCOMPtr<nsIWidget> mWidget; |
michael@0 | 273 | nsCOMPtr<nsIScreenManager> mScreenManager; |
michael@0 | 274 | nsCOMPtr<nsIDeviceContextSpec> mDeviceContextSpec; |
michael@0 | 275 | nsRefPtr<gfxASurface> mPrintingSurface; |
michael@0 | 276 | #ifdef XP_MACOSX |
michael@0 | 277 | nsRefPtr<gfxASurface> mCachedPrintingSurface; |
michael@0 | 278 | #endif |
michael@0 | 279 | }; |
michael@0 | 280 | |
michael@0 | 281 | #endif /* _NS_DEVICECONTEXT_H_ */ |