Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/nsScreen.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
#ifndef nsScreen_h___
7
#define nsScreen_h___
8
9
#include "mozilla/Attributes.h"
10
#include "mozilla/dom/ScreenBinding.h"
11
#include "mozilla/dom/ScreenLuminance.h"
12
#include "mozilla/dom/ScreenOrientation.h"
13
#include "mozilla/DOMEventTargetHelper.h"
14
#include "mozilla/ErrorResult.h"
15
#include "mozilla/StaticPrefs.h"
16
#include "nsCOMPtr.h"
17
#include "nsRect.h"
18
19
class nsDeviceContext;
20
21
// Script "screen" object
22
class nsScreen : public mozilla::DOMEventTargetHelper
23
{
24
  typedef mozilla::ErrorResult ErrorResult;
25
public:
26
  static already_AddRefed<nsScreen> Create(nsPIDOMWindowInner* aWindow);
27
28
  NS_DECL_ISUPPORTS_INHERITED
29
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen, mozilla::DOMEventTargetHelper)
30
31
  nsPIDOMWindowInner* GetParentObject() const
32
0
  {
33
0
    return GetOwner();
34
0
  }
35
36
  nsPIDOMWindowOuter* GetOuter() const;
37
38
  int32_t GetTop(ErrorResult& aRv)
39
0
  {
40
0
    nsRect rect;
41
0
    aRv = GetRect(rect);
42
0
    return rect.y;
43
0
  }
44
45
  int32_t GetLeft(ErrorResult& aRv)
46
0
  {
47
0
    nsRect rect;
48
0
    aRv = GetRect(rect);
49
0
    return rect.x;
50
0
  }
51
52
  int32_t GetWidth(ErrorResult& aRv)
53
0
  {
54
0
    nsRect rect;
55
0
    if (IsDeviceSizePageSize()) {
56
0
      if (nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner()) {
57
0
        int32_t innerWidth = 0;
58
0
        aRv = owner->GetInnerWidth(&innerWidth);
59
0
        return innerWidth;
60
0
      }
61
0
    }
62
0
63
0
    aRv = GetRect(rect);
64
0
    return rect.Width();
65
0
  }
66
67
  int32_t GetHeight(ErrorResult& aRv)
68
0
  {
69
0
    nsRect rect;
70
0
    if (IsDeviceSizePageSize()) {
71
0
      if (nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner()) {
72
0
        int32_t innerHeight = 0;
73
0
        aRv = owner->GetInnerHeight(&innerHeight);
74
0
        return innerHeight;
75
0
      }
76
0
    }
77
0
78
0
    aRv = GetRect(rect);
79
0
    return rect.Height();
80
0
  }
81
82
  int32_t GetPixelDepth(ErrorResult& aRv);
83
  int32_t GetColorDepth(ErrorResult& aRv)
84
0
  {
85
0
    return GetPixelDepth(aRv);
86
0
  }
87
88
  int32_t GetAvailTop(ErrorResult& aRv)
89
0
  {
90
0
    nsRect rect;
91
0
    aRv = GetAvailRect(rect);
92
0
    return rect.y;
93
0
  }
94
95
  int32_t GetAvailLeft(ErrorResult& aRv)
96
0
  {
97
0
    nsRect rect;
98
0
    aRv = GetAvailRect(rect);
99
0
    return rect.x;
100
0
  }
101
102
  int32_t GetAvailWidth(ErrorResult& aRv)
103
0
  {
104
0
    nsRect rect;
105
0
    aRv = GetAvailRect(rect);
106
0
    return rect.Width();
107
0
  }
108
109
  int32_t GetAvailHeight(ErrorResult& aRv)
110
0
  {
111
0
    nsRect rect;
112
0
    aRv = GetAvailRect(rect);
113
0
    return rect.Height();
114
0
  }
115
116
  // Media Capabilities extension
117
  mozilla::dom::ScreenColorGamut ColorGamut() const
118
0
  {
119
0
    return mozilla::dom::ScreenColorGamut::Srgb;
120
0
  }
121
122
  already_AddRefed<mozilla::dom::ScreenLuminance> GetLuminance() const
123
0
  {
124
0
    return nullptr;
125
0
  }
126
127
  static bool MediaCapabilitiesEnabled(JSContext* aCx, JSObject* aGlobal)
128
0
  {
129
0
    return mozilla::StaticPrefs::MediaCapabilitiesScreenEnabled();
130
0
  }
131
132
  IMPL_EVENT_HANDLER(change);
133
134
  // Deprecated
135
  void GetMozOrientation(nsString& aOrientation,
136
                         mozilla::dom::CallerType aCallerType) const;
137
138
  IMPL_EVENT_HANDLER(mozorientationchange)
139
140
  bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv);
141
  bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations, ErrorResult& aRv);
142
  void MozUnlockOrientation();
143
144
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
145
146
  mozilla::dom::ScreenOrientation* Orientation() const;
147
148
protected:
149
  nsDeviceContext* GetDeviceContext();
150
  nsresult GetRect(nsRect& aRect);
151
  nsresult GetAvailRect(nsRect& aRect);
152
  nsresult GetWindowInnerRect(nsRect& aRect);
153
154
private:
155
  explicit nsScreen(nsPIDOMWindowInner* aWindow);
156
  virtual ~nsScreen();
157
158
  bool IsDeviceSizePageSize();
159
160
  bool ShouldResistFingerprinting() const;
161
162
  RefPtr<mozilla::dom::ScreenOrientation> mScreenOrientation;
163
};
164
165
#endif /* nsScreen_h___ */