michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* Copyright 2012 Mozilla Foundation and Mozilla contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef OrientationObserver_h michael@0: #define OrientationObserver_h michael@0: michael@0: #include "mozilla/Observer.h" michael@0: #include "mozilla/dom/ScreenOrientation.h" michael@0: #include "mozilla/Scoped.h" michael@0: michael@0: namespace mozilla { michael@0: class ProcessOrientation; michael@0: namespace hal { michael@0: class SensorData; michael@0: typedef mozilla::Observer ISensorObserver; michael@0: } // namespace hal michael@0: } // namespace mozilla michael@0: michael@0: using mozilla::hal::ISensorObserver; michael@0: using mozilla::hal::SensorData; michael@0: using mozilla::dom::ScreenOrientation; michael@0: michael@0: class OrientationObserver : public ISensorObserver { michael@0: public: michael@0: OrientationObserver(); michael@0: ~OrientationObserver(); michael@0: michael@0: // Call DisableAutoOrientation on the existing OrientatiOnobserver singleton, michael@0: // if it exists. If no OrientationObserver exists, do nothing. michael@0: static void ShutDown(); michael@0: michael@0: // Notification from sensor. michael@0: void Notify(const SensorData& aSensorData); michael@0: michael@0: // Methods to enable/disable automatic orientation. michael@0: void EnableAutoOrientation(); michael@0: void DisableAutoOrientation(); michael@0: michael@0: // Methods called by methods in hal_impl namespace. michael@0: bool LockScreenOrientation(ScreenOrientation aOrientation); michael@0: void UnlockScreenOrientation(); michael@0: michael@0: static OrientationObserver* GetInstance(); michael@0: michael@0: private: michael@0: bool mAutoOrientationEnabled; michael@0: uint32_t mAllowedOrientations; michael@0: mozilla::ScopedDeletePtr mOrientation; michael@0: michael@0: static const uint32_t sDefaultOrientations = michael@0: mozilla::dom::eScreenOrientation_PortraitPrimary | michael@0: mozilla::dom::eScreenOrientation_PortraitSecondary | michael@0: mozilla::dom::eScreenOrientation_LandscapePrimary | michael@0: mozilla::dom::eScreenOrientation_LandscapeSecondary; michael@0: }; michael@0: michael@0: #endif