LCOV - code coverage report
Current view: top level - dom/base - WindowOrientationObserver.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 23 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 nsGlobalWindow 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           0 : WindowOrientationObserver::WindowOrientationObserver(
      21           0 :   nsGlobalWindow* aGlobalWindow)
      22           0 :   : mWindow(aGlobalWindow)
      23             : {
      24           0 :   MOZ_ASSERT(aGlobalWindow && aGlobalWindow->IsInnerWindow());
      25           0 :   hal::RegisterScreenConfigurationObserver(this);
      26             : 
      27           0 :   hal::ScreenConfiguration config;
      28           0 :   hal::GetCurrentScreenConfiguration(&config);
      29           0 :   mAngle = config.angle();
      30           0 : }
      31             : 
      32           0 : WindowOrientationObserver::~WindowOrientationObserver()
      33             : {
      34           0 :   hal::UnregisterScreenConfigurationObserver(this);
      35           0 : }
      36             : 
      37             : void
      38           0 : WindowOrientationObserver::Notify(
      39             :   const mozilla::hal::ScreenConfiguration& aConfiguration)
      40             : {
      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             :   }
      46           0 : }
      47             : 
      48             : /* static */ int16_t
      49           0 : WindowOrientationObserver::OrientationAngle()
      50             : {
      51           0 :   hal::ScreenConfiguration config;
      52           0 :   hal::GetCurrentScreenConfiguration(&config);
      53           0 :   int16_t angle = static_cast<int16_t>(config.angle());
      54             :   // config.angle() returns 0, 90, 180 or 270.
      55             :   // window.orientation returns -90, 0, 90 or 180.
      56           0 :   return angle <= 180 ? angle : angle - 360;
      57             : }

Generated by: LCOV version 1.13