| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Apple Inc. All rights reserved. | 2 * Copyright 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above copyright | 10 * * Redistributions in binary form must reproduce the above copyright |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "modules/device_orientation/DeviceSensorEventController.h" | 28 #include "modules/device_orientation/DeviceSensorEventController.h" |
| 29 | 29 |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/page/DOMWindow.h" | 31 #include "core/page/DOMWindow.h" |
| 32 | 32 |
| 33 namespace WebCore { | 33 namespace WebCore { |
| 34 | 34 |
| 35 DeviceSensorEventController::DeviceSensorEventController(Document* document) | 35 DeviceSensorEventController::DeviceSensorEventController(Document* document) |
| 36 : m_document(document) | 36 : m_document(document) |
| 37 , m_isActive(false) | 37 , m_isActive(false) |
| 38 , m_needsCheckingNullEvents(true) |
| 38 , m_timer(this, &DeviceSensorEventController::fireDeviceEvent) | 39 , m_timer(this, &DeviceSensorEventController::fireDeviceEvent) |
| 39 { | 40 { |
| 40 } | 41 } |
| 41 | 42 |
| 42 DeviceSensorEventController::~DeviceSensorEventController() | 43 DeviceSensorEventController::~DeviceSensorEventController() |
| 43 { | 44 { |
| 44 stopUpdating(); | 45 stopUpdating(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void DeviceSensorEventController::fireDeviceEvent(Timer<DeviceSensorEventControl
ler>* timer) | 48 void DeviceSensorEventController::fireDeviceEvent(Timer<DeviceSensorEventControl
ler>* timer) |
| 48 { | 49 { |
| 49 ASSERT_UNUSED(timer, timer == &m_timer); | 50 ASSERT_UNUSED(timer, timer == &m_timer); |
| 50 ASSERT(hasLastData()); | 51 ASSERT(hasLastData()); |
| 51 | 52 |
| 52 m_timer.stop(); | 53 m_timer.stop(); |
| 53 dispatchDeviceEvent(getLastEvent()); | 54 dispatchDeviceEvent(getLastEvent()); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void DeviceSensorEventController::dispatchDeviceEvent(PassRefPtr<Event> prpEvent
) | 57 void DeviceSensorEventController::dispatchDeviceEvent(PassRefPtr<Event> prpEvent
) |
| 57 { | 58 { |
| 58 RefPtr<Event> event = prpEvent; | 59 RefPtr<Event> event = prpEvent; |
| 59 if (m_document && m_document->domWindow() | 60 if (m_document && m_document->domWindow() |
| 60 && !m_document->activeDOMObjectsAreSuspended() | 61 && !m_document->activeDOMObjectsAreSuspended() |
| 61 && !m_document->activeDOMObjectsAreStopped()) | 62 && !m_document->activeDOMObjectsAreStopped()) |
| 62 m_document->domWindow()->dispatchEvent(event); | 63 m_document->domWindow()->dispatchEvent(event); |
| 64 |
| 65 if (m_needsCheckingNullEvents) { |
| 66 if (isNullEvent(event.get())) |
| 67 stopUpdating(); |
| 68 else |
| 69 m_needsCheckingNullEvents = false; |
| 70 } |
| 63 } | 71 } |
| 64 | 72 |
| 65 void DeviceSensorEventController::startUpdating() | 73 void DeviceSensorEventController::startUpdating() |
| 66 { | 74 { |
| 67 if (m_isActive) | 75 if (m_isActive) |
| 68 return; | 76 return; |
| 69 | 77 |
| 70 registerWithDispatcher(); | |
| 71 m_isActive = true; | |
| 72 | |
| 73 if (hasLastData() && !m_timer.isActive()) { | 78 if (hasLastData() && !m_timer.isActive()) { |
| 74 // Make sure to fire the device motion data as soon as possible. | 79 // Make sure to fire the device motion data as soon as possible. |
| 75 m_timer.startOneShot(0); | 80 m_timer.startOneShot(0); |
| 76 } | 81 } |
| 82 |
| 83 registerWithDispatcher(); |
| 84 m_isActive = true; |
| 77 } | 85 } |
| 78 | 86 |
| 79 void DeviceSensorEventController::stopUpdating() | 87 void DeviceSensorEventController::stopUpdating() |
| 80 { | 88 { |
| 81 if (!m_isActive) | 89 if (!m_isActive) |
| 82 return; | 90 return; |
| 83 | 91 |
| 92 if (m_timer.isActive()) |
| 93 m_timer.stop(); |
| 94 |
| 84 unregisterWithDispatcher(); | 95 unregisterWithDispatcher(); |
| 85 m_isActive = false; | 96 m_isActive = false; |
| 86 } | 97 } |
| 87 | 98 |
| 88 } // namespace WebCore | 99 } // namespace WebCore |
| OLD | NEW |