|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set sw=2 ts=8 et ft=cpp : */ |
|
3 /* Copyright 2012 Mozilla Foundation and Mozilla contributors |
|
4 * |
|
5 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 * you may not use this file except in compliance with the License. |
|
7 * You may obtain a copy of the License at |
|
8 * |
|
9 * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 * |
|
11 * Unless required by applicable law or agreed to in writing, software |
|
12 * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 * See the License for the specific language governing permissions and |
|
15 * limitations under the License. |
|
16 */ |
|
17 |
|
18 #ifndef OrientationObserver_h |
|
19 #define OrientationObserver_h |
|
20 |
|
21 #include "mozilla/Observer.h" |
|
22 #include "mozilla/dom/ScreenOrientation.h" |
|
23 #include "mozilla/Scoped.h" |
|
24 |
|
25 namespace mozilla { |
|
26 class ProcessOrientation; |
|
27 namespace hal { |
|
28 class SensorData; |
|
29 typedef mozilla::Observer<SensorData> ISensorObserver; |
|
30 } // namespace hal |
|
31 } // namespace mozilla |
|
32 |
|
33 using mozilla::hal::ISensorObserver; |
|
34 using mozilla::hal::SensorData; |
|
35 using mozilla::dom::ScreenOrientation; |
|
36 |
|
37 class OrientationObserver : public ISensorObserver { |
|
38 public: |
|
39 OrientationObserver(); |
|
40 ~OrientationObserver(); |
|
41 |
|
42 // Call DisableAutoOrientation on the existing OrientatiOnobserver singleton, |
|
43 // if it exists. If no OrientationObserver exists, do nothing. |
|
44 static void ShutDown(); |
|
45 |
|
46 // Notification from sensor. |
|
47 void Notify(const SensorData& aSensorData); |
|
48 |
|
49 // Methods to enable/disable automatic orientation. |
|
50 void EnableAutoOrientation(); |
|
51 void DisableAutoOrientation(); |
|
52 |
|
53 // Methods called by methods in hal_impl namespace. |
|
54 bool LockScreenOrientation(ScreenOrientation aOrientation); |
|
55 void UnlockScreenOrientation(); |
|
56 |
|
57 static OrientationObserver* GetInstance(); |
|
58 |
|
59 private: |
|
60 bool mAutoOrientationEnabled; |
|
61 uint32_t mAllowedOrientations; |
|
62 mozilla::ScopedDeletePtr<mozilla::ProcessOrientation> mOrientation; |
|
63 |
|
64 static const uint32_t sDefaultOrientations = |
|
65 mozilla::dom::eScreenOrientation_PortraitPrimary | |
|
66 mozilla::dom::eScreenOrientation_PortraitSecondary | |
|
67 mozilla::dom::eScreenOrientation_LandscapePrimary | |
|
68 mozilla::dom::eScreenOrientation_LandscapeSecondary; |
|
69 }; |
|
70 |
|
71 #endif |