LCOV - code coverage report
Current view: top level - dom/base - ScreenOrientation.h (source / functions) Hit Total Coverage
Test: output.info Lines: 1 3 33.3 %
Date: 2017-07-14 16:53:18 Functions: 1 20 5.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 file,
       5             :  * You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef mozilla_dom_ScreenOrientation_h
       8             : #define mozilla_dom_ScreenOrientation_h
       9             : 
      10             : #include "mozilla/DOMEventTargetHelper.h"
      11             : #include "mozilla/dom/BindingDeclarations.h"
      12             : #include "mozilla/dom/ScreenOrientationBinding.h"
      13             : #include "mozilla/HalScreenConfiguration.h"
      14             : 
      15             : class nsScreen;
      16             : 
      17             : namespace mozilla {
      18             : namespace dom {
      19             : 
      20             : class Promise;
      21             : // Make sure that any change to ScreenOrientationInternal values are
      22             : // also made in mobile/android/base/GeckoScreenOrientation.java
      23             : typedef uint32_t ScreenOrientationInternal;
      24             : 
      25             : static const ScreenOrientationInternal eScreenOrientation_None               = 0;
      26             : static const ScreenOrientationInternal eScreenOrientation_PortraitPrimary    = 1u << 0;
      27             : static const ScreenOrientationInternal eScreenOrientation_PortraitSecondary  = 1u << 1;
      28             : static const ScreenOrientationInternal eScreenOrientation_LandscapePrimary   = 1u << 2;
      29             : static const ScreenOrientationInternal eScreenOrientation_LandscapeSecondary = 1u << 3;
      30             : //eScreenOrientation_Default will use the natural orientation for the deivce,
      31             : //it could be PortraitPrimary or LandscapePrimary depends on display resolution
      32             : static const ScreenOrientationInternal eScreenOrientation_Default            = 1u << 4;
      33             : 
      34             : class ScreenOrientation final : public DOMEventTargetHelper,
      35             :                                 public mozilla::hal::ScreenConfigurationObserver
      36             : {
      37             :   // nsScreen has deprecated API that shares implementation.
      38             :   friend class ::nsScreen;
      39             : 
      40             : public:
      41             :   NS_DECL_ISUPPORTS_INHERITED
      42           1 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ScreenOrientation, mozilla::DOMEventTargetHelper)
      43           0 :   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper)
      44             : 
      45           0 :   IMPL_EVENT_HANDLER(change)
      46             : 
      47             :   ScreenOrientation(nsPIDOMWindowInner* aWindow, nsScreen* aScreen);
      48             : 
      49             :   already_AddRefed<Promise> Lock(OrientationLockType aOrientation,
      50             :                                  ErrorResult& aRv);
      51             : 
      52             :   void Unlock(ErrorResult& aRv);
      53             : 
      54             :   // DeviceType and DeviceAngle gets the current type and angle of the device.
      55             :   OrientationType DeviceType(CallerType aCallerType) const;
      56             :   uint16_t DeviceAngle(CallerType aCallerType) const;
      57             : 
      58             :   // GetType and GetAngle gets the type and angle of the responsible document
      59             :   // (as defined in specification).
      60             :   OrientationType GetType(CallerType aCallerType, ErrorResult& aRv) const;
      61             :   uint16_t GetAngle(CallerType aCallerType, ErrorResult& aRv) const;
      62             : 
      63             :   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
      64             : 
      65             :   void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration) override;
      66             : 
      67             :   static void UpdateActiveOrientationLock(ScreenOrientationInternal aOrientation);
      68             : 
      69             : private:
      70             :   virtual ~ScreenOrientation();
      71             : 
      72             :   // Listener to unlock orientation if we leave fullscreen.
      73             :   class FullScreenEventListener;
      74             : 
      75             :   // Listener to update document's orienation lock when document becomes
      76             :   // visible.
      77             :   class VisibleEventListener;
      78             : 
      79             :   // Task to run step to lock orientation as defined in specification.
      80             :   class LockOrientationTask;
      81             : 
      82             :   enum LockPermission {
      83             :     LOCK_DENIED,
      84             :     FULLSCREEN_LOCK_ALLOWED,
      85             :     LOCK_ALLOWED
      86             :   };
      87             : 
      88             :   // This method calls into the HAL to lock the device and sets
      89             :   // up listeners for full screen change.
      90             :   bool LockDeviceOrientation(ScreenOrientationInternal aOrientation,
      91             :                              bool aIsFullscreen, ErrorResult& aRv);
      92             : 
      93             :   // This method calls in to the HAL to unlock the device and removes
      94             :   // full screen change listener.
      95             :   void UnlockDeviceOrientation();
      96             : 
      97             :   // This method performs the same function as |Lock| except it takes
      98             :   // a ScreenOrientationInternal argument instead of an OrientationType.
      99             :   // This method exists in order to share implementation with nsScreen that
     100             :   // uses ScreenOrientationInternal.
     101             :   already_AddRefed<Promise> LockInternal(ScreenOrientationInternal aOrientation,
     102             :                                          ErrorResult& aRv);
     103             : 
     104             :   void DispatchChangeEvent();
     105             : 
     106             :   bool ShouldResistFingerprinting() const;
     107             : 
     108             :   LockPermission GetLockOrientationPermission(bool aCheckSandbox) const;
     109             : 
     110             :   // Gets the responsible document as defined in the spec.
     111             :   nsIDocument* GetResponsibleDocument() const;
     112             : 
     113             :   RefPtr<nsScreen> mScreen;
     114             :   RefPtr<FullScreenEventListener> mFullScreenListener;
     115             :   RefPtr<VisibleEventListener> mVisibleListener;
     116             :   OrientationType mType;
     117             :   uint16_t mAngle;
     118             : };
     119             : 
     120             : } // namespace dom
     121             : } // namespace mozilla
     122             : 
     123             : #endif // mozilla_dom_ScreenOrientation_h

Generated by: LCOV version 1.13