Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/WindowOrientationObserver.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 "WindowOrientationObserver.h"
8
9
#include "nsGlobalWindow.h"
10
#include "mozilla/Hal.h"
11
12
using namespace mozilla::dom;
13
14
/**
15
 * This class is used by nsGlobalWindowInner to implement window.orientation
16
 * and window.onorientationchange. This class is defined in its own file
17
 * because Hal.h pulls in windows.h and can't be included from
18
 * nsGlobalWindow.cpp
19
 */
20
WindowOrientationObserver::WindowOrientationObserver(
21
  nsGlobalWindowInner* aGlobalWindow)
22
  : mWindow(aGlobalWindow)
23
0
{
24
0
  MOZ_ASSERT(aGlobalWindow);
25
0
  hal::RegisterScreenConfigurationObserver(this);
26
0
27
0
  hal::ScreenConfiguration config;
28
0
  hal::GetCurrentScreenConfiguration(&config);
29
0
  mAngle = config.angle();
30
0
}
31
32
WindowOrientationObserver::~WindowOrientationObserver()
33
0
{
34
0
  hal::UnregisterScreenConfigurationObserver(this);
35
0
}
36
37
void
38
WindowOrientationObserver::Notify(
39
  const mozilla::hal::ScreenConfiguration& aConfiguration)
40
0
{
41
0
  uint16_t currentAngle = aConfiguration.angle();
42
0
  if (mAngle != currentAngle && mWindow->AsInner()->IsCurrentInnerWindow()) {
43
0
    mAngle = currentAngle;
44
0
    mWindow->GetOuterWindow()->DispatchCustomEvent(NS_LITERAL_STRING("orientationchange"));
45
0
  }
46
0
}
47
48
/* static */ int16_t
49
WindowOrientationObserver::OrientationAngle()
50
0
{
51
0
  hal::ScreenConfiguration config;
52
0
  hal::GetCurrentScreenConfiguration(&config);
53
0
  int16_t angle = static_cast<int16_t>(config.angle());
54
0
  // config.angle() returns 0, 90, 180 or 270.
55
0
  // window.orientation returns -90, 0, 90 or 180.
56
0
  return angle <= 180 ? angle : angle - 360;
57
0
}