dom/base/nsScreen.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/nsScreen.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,165 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef nsScreen_h___
     1.9 +#define nsScreen_h___
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "mozilla/dom/ScreenOrientation.h"
    1.13 +#include "mozilla/DOMEventTargetHelper.h"
    1.14 +#include "mozilla/ErrorResult.h"
    1.15 +#include "mozilla/HalScreenConfiguration.h"
    1.16 +#include "nsIDOMScreen.h"
    1.17 +#include "nsCOMPtr.h"
    1.18 +#include "nsRect.h"
    1.19 +
    1.20 +class nsDeviceContext;
    1.21 +
    1.22 +// Script "screen" object
    1.23 +class nsScreen : public mozilla::DOMEventTargetHelper
    1.24 +               , public nsIDOMScreen
    1.25 +               , public mozilla::hal::ScreenConfigurationObserver
    1.26 +{
    1.27 +  typedef mozilla::ErrorResult ErrorResult;
    1.28 +public:
    1.29 +  static already_AddRefed<nsScreen> Create(nsPIDOMWindow* aWindow);
    1.30 +
    1.31 +  NS_DECL_ISUPPORTS_INHERITED
    1.32 +  NS_DECL_NSIDOMSCREEN
    1.33 +  NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper)
    1.34 +
    1.35 +  nsPIDOMWindow* GetParentObject() const
    1.36 +  {
    1.37 +    return GetOwner();
    1.38 +  }
    1.39 +
    1.40 +  int32_t GetTop(ErrorResult& aRv)
    1.41 +  {
    1.42 +    nsRect rect;
    1.43 +    aRv = GetRect(rect);
    1.44 +    return rect.y;
    1.45 +  }
    1.46 +
    1.47 +  int32_t GetLeft(ErrorResult& aRv)
    1.48 +  {
    1.49 +    nsRect rect;
    1.50 +    aRv = GetRect(rect);
    1.51 +    return rect.x;
    1.52 +  }
    1.53 +
    1.54 +  int32_t GetWidth(ErrorResult& aRv)
    1.55 +  {
    1.56 +    nsRect rect;
    1.57 +    if (IsDeviceSizePageSize()) {
    1.58 +      nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
    1.59 +      if (owner) {
    1.60 +        int32_t innerWidth = 0;
    1.61 +        aRv = owner->GetInnerWidth(&innerWidth);
    1.62 +        return innerWidth;
    1.63 +      }
    1.64 +    }
    1.65 +
    1.66 +    aRv = GetRect(rect);
    1.67 +    return rect.width;
    1.68 +  }
    1.69 +
    1.70 +  int32_t GetHeight(ErrorResult& aRv)
    1.71 +  {
    1.72 +    nsRect rect;
    1.73 +    if (IsDeviceSizePageSize()) {
    1.74 +      nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
    1.75 +      if (owner) {
    1.76 +        int32_t innerHeight = 0;
    1.77 +        aRv = owner->GetInnerHeight(&innerHeight);
    1.78 +        return innerHeight;
    1.79 +      }
    1.80 +    }
    1.81 +
    1.82 +    aRv = GetRect(rect);
    1.83 +    return rect.height;
    1.84 +  }
    1.85 +
    1.86 +  int32_t GetPixelDepth(ErrorResult& aRv);
    1.87 +  int32_t GetColorDepth(ErrorResult& aRv)
    1.88 +  {
    1.89 +    return GetPixelDepth(aRv);
    1.90 +  }
    1.91 +
    1.92 +  int32_t GetAvailTop(ErrorResult& aRv)
    1.93 +  {
    1.94 +    nsRect rect;
    1.95 +    aRv = GetAvailRect(rect);
    1.96 +    return rect.y;
    1.97 +  }
    1.98 +
    1.99 +  int32_t GetAvailLeft(ErrorResult& aRv)
   1.100 +  {
   1.101 +    nsRect rect;
   1.102 +    aRv = GetAvailRect(rect);
   1.103 +    return rect.x;
   1.104 +  }
   1.105 +
   1.106 +  int32_t GetAvailWidth(ErrorResult& aRv)
   1.107 +  {
   1.108 +    nsRect rect;
   1.109 +    aRv = GetAvailRect(rect);
   1.110 +    return rect.width;
   1.111 +  }
   1.112 +
   1.113 +  int32_t GetAvailHeight(ErrorResult& aRv)
   1.114 +  {
   1.115 +    nsRect rect;
   1.116 +    aRv = GetAvailRect(rect);
   1.117 +    return rect.height;
   1.118 +  }
   1.119 +
   1.120 +  void GetMozOrientation(nsString& aOrientation);
   1.121 +
   1.122 +  IMPL_EVENT_HANDLER(mozorientationchange)
   1.123 +
   1.124 +  bool MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv);
   1.125 +  bool MozLockOrientation(const mozilla::dom::Sequence<nsString>& aOrientations, ErrorResult& aRv);
   1.126 +  void MozUnlockOrientation();
   1.127 +
   1.128 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   1.129 +
   1.130 +  void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration);
   1.131 +
   1.132 +protected:
   1.133 +  nsDeviceContext* GetDeviceContext();
   1.134 +  nsresult GetRect(nsRect& aRect);
   1.135 +  nsresult GetAvailRect(nsRect& aRect);
   1.136 +  bool IsChrome();
   1.137 +  nsresult GetDOMWindow(nsIDOMWindow **aResult);
   1.138 +  nsresult GetWindowInnerRect(nsRect& aRect);
   1.139 +
   1.140 +  mozilla::dom::ScreenOrientation mOrientation;
   1.141 +
   1.142 +private:
   1.143 +  class FullScreenEventListener MOZ_FINAL : public nsIDOMEventListener
   1.144 +  {
   1.145 +  public:
   1.146 +    FullScreenEventListener() {};
   1.147 +
   1.148 +    NS_DECL_ISUPPORTS
   1.149 +    NS_DECL_NSIDOMEVENTLISTENER
   1.150 +  };
   1.151 +
   1.152 +  nsScreen(nsPIDOMWindow* aWindow);
   1.153 +  virtual ~nsScreen();
   1.154 +
   1.155 +  enum LockPermission {
   1.156 +    LOCK_DENIED,
   1.157 +    FULLSCREEN_LOCK_ALLOWED,
   1.158 +    LOCK_ALLOWED
   1.159 +  };
   1.160 +
   1.161 +  LockPermission GetLockOrientationPermission() const;
   1.162 +
   1.163 +  bool IsDeviceSizePageSize();
   1.164 +
   1.165 +  nsRefPtr<FullScreenEventListener> mEventListener;
   1.166 +};
   1.167 +
   1.168 +#endif /* nsScreen_h___ */

mercurial