Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/VisualViewport.cpp
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
7
#include "VisualViewport.h"
8
#include "nsIScrollableFrame.h"
9
#include "nsIDocShell.h"
10
11
using namespace mozilla;
12
using namespace mozilla::dom;
13
14
VisualViewport::VisualViewport(nsPIDOMWindowInner* aWindow)
15
  : DOMEventTargetHelper(aWindow)
16
0
{
17
0
}
18
19
VisualViewport::~VisualViewport()
20
0
{
21
0
}
22
23
/* virtual */
24
JSObject*
25
VisualViewport::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
26
0
{
27
0
  return VisualViewport_Binding::Wrap(aCx, this, aGivenProto);
28
0
}
29
30
CSSSize
31
VisualViewport::VisualViewportSize() const
32
0
{
33
0
  CSSSize size = CSSSize(0,0);
34
0
35
0
  nsIPresShell* presShell = GetPresShell();
36
0
  if (presShell) {
37
0
    if (presShell->IsVisualViewportSizeSet()) {
38
0
      size = CSSRect::FromAppUnits(
39
0
        presShell->GetVisualViewportSize());
40
0
    } else {
41
0
      nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
42
0
      if (sf) {
43
0
        size = CSSRect::FromAppUnits(sf->GetScrollPortRect().Size());
44
0
      }
45
0
    }
46
0
  }
47
0
  return size;
48
0
}
49
50
double
51
VisualViewport::Width() const
52
0
{
53
0
  CSSSize size = VisualViewportSize();
54
0
  return size.width;
55
0
}
56
57
double
58
VisualViewport::Height() const
59
0
{
60
0
  CSSSize size = VisualViewportSize();
61
0
  return size.height;
62
0
}
63
64
double
65
VisualViewport::Scale() const
66
0
{
67
0
  double scale = 1;
68
0
  nsIPresShell* presShell = GetPresShell();
69
0
  if (presShell) {
70
0
    scale = presShell->GetResolution();
71
0
  }
72
0
  return scale;
73
0
}
74
75
CSSPoint
76
VisualViewport::VisualViewportOffset() const
77
0
{
78
0
  CSSPoint offset = CSSPoint(0,0);
79
0
80
0
  nsIPresShell* presShell = GetPresShell();
81
0
  if (presShell) {
82
0
      offset = CSSPoint::FromAppUnits(presShell->GetVisualViewportOffset());
83
0
  }
84
0
  return offset;
85
0
}
86
87
CSSPoint
88
VisualViewport::LayoutViewportOffset() const
89
0
{
90
0
  CSSPoint offset = CSSPoint(0,0);
91
0
92
0
  nsIPresShell* presShell = GetPresShell();
93
0
  if (presShell) {
94
0
    nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
95
0
    if (sf) {
96
0
      offset = CSSPoint::FromAppUnits(sf->GetScrollPosition());
97
0
    }
98
0
  }
99
0
  return offset;
100
0
}
101
102
double
103
VisualViewport::PageLeft() const
104
0
{
105
0
  return VisualViewportOffset().X();
106
0
}
107
108
double
109
VisualViewport::PageTop() const
110
0
{
111
0
  return VisualViewportOffset().Y();
112
0
}
113
114
double
115
VisualViewport::OffsetLeft() const
116
0
{
117
0
  return PageLeft() - LayoutViewportOffset().X();
118
0
}
119
120
double
121
VisualViewport::OffsetTop() const
122
0
{
123
0
  return PageTop() - LayoutViewportOffset().Y();
124
0
}
125
126
nsIPresShell*
127
VisualViewport::GetPresShell() const
128
0
{
129
0
  nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
130
0
  if (!window) {
131
0
    return nullptr;
132
0
  }
133
0
134
0
  nsIDocShell* docShell = window->GetDocShell();
135
0
  if (!docShell) {
136
0
    return nullptr;
137
0
  }
138
0
139
0
  return docShell->GetPresShell();
140
0
}