Bug 1793629 - Implement attention indicator for the unified extensions button, r...
[gecko.git] / widget / nsIDeviceContextSpec.cpp
blob09517ff7affd1aed977c76758758f95108bec59b
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/. */
6 #include "nsIDeviceContextSpec.h"
8 #include "gfxPoint.h"
9 #include "nsIPrintSettings.h"
11 // We have some platform specific code here rather than in the appropriate
12 // nsIDeviceContextSpec subclass. We structure the code this way so that
13 // nsIDeviceContextSpecProxy gets the correct behavior without us having to
14 // instantiate a platform specific nsIDeviceContextSpec subclass in content
15 // processes. That is necessary for sandboxing.
17 float nsIDeviceContextSpec::GetPrintingScale() {
18 #ifdef XP_WIN
19 if (mPrintSettings->GetOutputFormat() != nsIPrintSettings::kOutputFormatPDF
20 # ifdef MOZ_ENABLE_SKIA_PDF
21 && !mPrintViaSkPDF
22 # endif
23 ) {
24 // The print settings will have the resolution stored from the real device.
25 int32_t resolution;
26 mPrintSettings->GetResolution(&resolution);
27 return float(resolution) / GetDPI();
29 #endif
31 return 72.0f / GetDPI();
34 gfxPoint nsIDeviceContextSpec::GetPrintingTranslate() {
35 #ifdef XP_WIN
36 // The underlying surface on windows is the size of the printable region. When
37 // the region is smaller than the actual paper size the (0, 0) coordinate
38 // refers top-left of that unwritable region. To instead have (0, 0) become
39 // the top-left of the actual paper, translate it's coordinate system by the
40 // unprintable region's width.
41 double marginTop, marginLeft;
42 mPrintSettings->GetUnwriteableMarginTop(&marginTop);
43 mPrintSettings->GetUnwriteableMarginLeft(&marginLeft);
44 int32_t resolution;
45 mPrintSettings->GetResolution(&resolution);
46 return gfxPoint(-marginLeft * resolution, -marginTop * resolution);
47 #else
48 return gfxPoint(0, 0);
49 #endif