widget/gonk/OrientationObserver.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/OrientationObserver.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et ft=cpp : */
     1.6 +/* Copyright 2012 Mozilla Foundation and Mozilla contributors
     1.7 + *
     1.8 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.9 + * you may not use this file except in compliance with the License.
    1.10 + * You may obtain a copy of the License at
    1.11 + *
    1.12 + *     http://www.apache.org/licenses/LICENSE-2.0
    1.13 + *
    1.14 + * Unless required by applicable law or agreed to in writing, software
    1.15 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.16 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.17 + * See the License for the specific language governing permissions and
    1.18 + * limitations under the License.
    1.19 + */
    1.20 +
    1.21 +#ifndef OrientationObserver_h
    1.22 +#define OrientationObserver_h
    1.23 +
    1.24 +#include "mozilla/Observer.h"
    1.25 +#include "mozilla/dom/ScreenOrientation.h"
    1.26 +#include "mozilla/Scoped.h"
    1.27 +
    1.28 +namespace mozilla {
    1.29 +class ProcessOrientation;
    1.30 +namespace hal {
    1.31 +class SensorData;
    1.32 +typedef mozilla::Observer<SensorData> ISensorObserver;
    1.33 +} // namespace hal
    1.34 +} // namespace mozilla
    1.35 +
    1.36 +using mozilla::hal::ISensorObserver;
    1.37 +using mozilla::hal::SensorData;
    1.38 +using mozilla::dom::ScreenOrientation;
    1.39 +
    1.40 +class OrientationObserver : public ISensorObserver {
    1.41 +public:
    1.42 +  OrientationObserver();
    1.43 +  ~OrientationObserver();
    1.44 +
    1.45 +  // Call DisableAutoOrientation on the existing OrientatiOnobserver singleton,
    1.46 +  // if it exists.  If no OrientationObserver exists, do nothing.
    1.47 +  static void ShutDown();
    1.48 +
    1.49 +  // Notification from sensor.
    1.50 +  void Notify(const SensorData& aSensorData);
    1.51 +
    1.52 +  // Methods to enable/disable automatic orientation.
    1.53 +  void EnableAutoOrientation();
    1.54 +  void DisableAutoOrientation();
    1.55 +
    1.56 +  // Methods called by methods in hal_impl namespace.
    1.57 +  bool LockScreenOrientation(ScreenOrientation aOrientation);
    1.58 +  void UnlockScreenOrientation();
    1.59 +
    1.60 +  static OrientationObserver* GetInstance();
    1.61 +
    1.62 +private:
    1.63 +  bool mAutoOrientationEnabled;
    1.64 +  uint32_t mAllowedOrientations;
    1.65 +  mozilla::ScopedDeletePtr<mozilla::ProcessOrientation> mOrientation;
    1.66 +
    1.67 +  static const uint32_t sDefaultOrientations =
    1.68 +      mozilla::dom::eScreenOrientation_PortraitPrimary |
    1.69 +      mozilla::dom::eScreenOrientation_PortraitSecondary |
    1.70 +      mozilla::dom::eScreenOrientation_LandscapePrimary |
    1.71 +      mozilla::dom::eScreenOrientation_LandscapeSecondary;
    1.72 +};
    1.73 +
    1.74 +#endif

mercurial