| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Samsung Electronics | 2 * Copyright (C) 2012 Samsung Electronics |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #ifndef VibrationController_h | 20 #ifndef VibrationController_h |
| 21 #define VibrationController_h | 21 #define VibrationController_h |
| 22 | 22 |
| 23 #include "core/dom/ContextLifecycleObserver.h" | 23 #include "core/dom/ContextLifecycleObserver.h" |
| 24 #include "core/page/PageLifecycleObserver.h" | 24 #include "core/page/PageVisibilityObserver.h" |
| 25 #include "device/vibration/vibration_manager.mojom-blink.h" | 25 #include "device/vibration/vibration_manager.mojom-blink.h" |
| 26 #include "modules/ModulesExport.h" | 26 #include "modules/ModulesExport.h" |
| 27 #include "platform/Timer.h" | 27 #include "platform/Timer.h" |
| 28 #include "platform/heap/GarbageCollected.h" | 28 #include "platform/heap/GarbageCollected.h" |
| 29 #include "platform/heap/Handle.h" | 29 #include "platform/heap/Handle.h" |
| 30 #include "wtf/Noncopyable.h" | 30 #include "wtf/Noncopyable.h" |
| 31 #include "wtf/Vector.h" | 31 #include "wtf/Vector.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 class Document; | 35 class Document; |
| 36 class ExecutionContext; | 36 class ExecutionContext; |
| 37 class UnsignedLongOrUnsignedLongSequence; | 37 class UnsignedLongOrUnsignedLongSequence; |
| 38 | 38 |
| 39 class MODULES_EXPORT VibrationController final | 39 class MODULES_EXPORT VibrationController final |
| 40 : public GarbageCollectedFinalized<VibrationController> | 40 : public GarbageCollectedFinalized<VibrationController> |
| 41 , public ContextLifecycleObserver | 41 , public ContextLifecycleObserver |
| 42 , public PageLifecycleObserver { | 42 , public PageVisibilityObserver { |
| 43 USING_GARBAGE_COLLECTED_MIXIN(VibrationController); | 43 USING_GARBAGE_COLLECTED_MIXIN(VibrationController); |
| 44 WTF_MAKE_NONCOPYABLE(VibrationController); | 44 WTF_MAKE_NONCOPYABLE(VibrationController); |
| 45 public: | 45 public: |
| 46 using VibrationPattern = Vector<unsigned>; | 46 using VibrationPattern = Vector<unsigned>; |
| 47 | 47 |
| 48 explicit VibrationController(Document&); | 48 explicit VibrationController(Document&); |
| 49 virtual ~VibrationController(); | 49 virtual ~VibrationController(); |
| 50 | 50 |
| 51 static VibrationPattern sanitizeVibrationPattern(const UnsignedLongOrUnsigne
dLongSequence&); | 51 static VibrationPattern sanitizeVibrationPattern(const UnsignedLongOrUnsigne
dLongSequence&); |
| 52 | 52 |
| 53 bool vibrate(const VibrationPattern&); | 53 bool vibrate(const VibrationPattern&); |
| 54 void doVibrate(Timer<VibrationController>*); | 54 void doVibrate(Timer<VibrationController>*); |
| 55 void didVibrate(); | 55 void didVibrate(); |
| 56 | 56 |
| 57 // Cancels the ongoing vibration if there is one. | 57 // Cancels the ongoing vibration if there is one. |
| 58 void cancel(); | 58 void cancel(); |
| 59 void didCancel(); | 59 void didCancel(); |
| 60 | 60 |
| 61 // Whether a pattern is being processed. If this is true, the vibration | 61 // Whether a pattern is being processed. If this is true, the vibration |
| 62 // hardware may currently be active, but during a pause it may be inactive. | 62 // hardware may currently be active, but during a pause it may be inactive. |
| 63 bool isRunning() const { return m_isRunning; } | 63 bool isRunning() const { return m_isRunning; } |
| 64 | 64 |
| 65 VibrationPattern pattern() const { return m_pattern; } | 65 VibrationPattern pattern() const { return m_pattern; } |
| 66 | 66 |
| 67 DECLARE_VIRTUAL_TRACE(); | 67 DECLARE_VIRTUAL_TRACE(); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 // Inherited from ContextLifecycleObserver AND PageLifecycleObserver. | 70 // Inherited from ContextLifecycleObserver AND PageVisibilityObserver. |
| 71 void contextDestroyed() override; | 71 void contextDestroyed() override; |
| 72 | 72 |
| 73 // Inherited from PageLifecycleObserver. | 73 // Inherited from PageVisibilityObserver. |
| 74 void pageVisibilityChanged() override; | 74 void pageVisibilityChanged() override; |
| 75 | 75 |
| 76 // The VibrationManager mojo service. This is reset in |contextDestroyed| | 76 // The VibrationManager mojo service. This is reset in |contextDestroyed| |
| 77 // and must not be called or recreated after it is reset. | 77 // and must not be called or recreated after it is reset. |
| 78 device::blink::VibrationManagerPtr m_service; | 78 device::blink::VibrationManagerPtr m_service; |
| 79 | 79 |
| 80 // Timer for calling |doVibrate| after a delay. It is safe to call | 80 // Timer for calling |doVibrate| after a delay. It is safe to call |
| 81 // |startOneshot| when the timer is already running: it may affect the time | 81 // |startOneshot| when the timer is already running: it may affect the time |
| 82 // at which it fires, but |doVibrate| will still be called only once. | 82 // at which it fires, but |doVibrate| will still be called only once. |
| 83 Timer<VibrationController> m_timerDoVibrate; | 83 Timer<VibrationController> m_timerDoVibrate; |
| 84 | 84 |
| 85 // Whether a pattern is being processed. The vibration hardware may | 85 // Whether a pattern is being processed. The vibration hardware may |
| 86 // currently be active, or during a pause it may be inactive. | 86 // currently be active, or during a pause it may be inactive. |
| 87 bool m_isRunning; | 87 bool m_isRunning; |
| 88 | 88 |
| 89 // Whether an async mojo call to cancel is pending. | 89 // Whether an async mojo call to cancel is pending. |
| 90 bool m_isCallingCancel; | 90 bool m_isCallingCancel; |
| 91 | 91 |
| 92 // Whether an async mojo call to vibrate is pending. | 92 // Whether an async mojo call to vibrate is pending. |
| 93 bool m_isCallingVibrate; | 93 bool m_isCallingVibrate; |
| 94 | 94 |
| 95 VibrationPattern m_pattern; | 95 VibrationPattern m_pattern; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace blink | 98 } // namespace blink |
| 99 | 99 |
| 100 #endif // VibrationController_h | 100 #endif // VibrationController_h |
| OLD | NEW |