| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 void EventSender<T>::dispatchEventSoon(T* sender) { | 78 void EventSender<T>::dispatchEventSoon(T* sender) { |
| 79 m_dispatchSoonList.append(sender); | 79 m_dispatchSoonList.append(sender); |
| 80 if (!m_timer.isActive()) | 80 if (!m_timer.isActive()) |
| 81 m_timer.startOneShot(0, BLINK_FROM_HERE); | 81 m_timer.startOneShot(0, BLINK_FROM_HERE); |
| 82 } | 82 } |
| 83 | 83 |
| 84 template <typename T> | 84 template <typename T> |
| 85 void EventSender<T>::cancelEvent(T* sender) { | 85 void EventSender<T>::cancelEvent(T* sender) { |
| 86 // Remove instances of this sender from both lists. | 86 // Remove instances of this sender from both lists. |
| 87 // Use loops because we allow multiple instances to get into the lists. | 87 // Use loops because we allow multiple instances to get into the lists. |
| 88 size_t size = m_dispatchSoonList.size(); | 88 for (auto& senderInList : m_dispatchSoonList) { |
| 89 for (size_t i = 0; i < size; ++i) { | 89 if (senderInList == sender) |
| 90 if (m_dispatchSoonList[i] == sender) | 90 senderInList = nullptr; |
| 91 m_dispatchSoonList[i] = nullptr; | |
| 92 } | 91 } |
| 93 size = m_dispatchingList.size(); | 92 for (auto& senderInList : m_dispatchingList) { |
| 94 for (size_t i = 0; i < size; ++i) { | 93 if (senderInList == sender) |
| 95 if (m_dispatchingList[i] == sender) | 94 senderInList = nullptr; |
| 96 m_dispatchingList[i] = nullptr; | |
| 97 } | 95 } |
| 98 } | 96 } |
| 99 | 97 |
| 100 template <typename T> | 98 template <typename T> |
| 101 void EventSender<T>::dispatchPendingEvents() { | 99 void EventSender<T>::dispatchPendingEvents() { |
| 102 // Need to avoid re-entering this function; if new dispatches are | 100 // Need to avoid re-entering this function; if new dispatches are |
| 103 // scheduled before the parent finishes processing the list, they | 101 // scheduled before the parent finishes processing the list, they |
| 104 // will set a timer and eventually be processed. | 102 // will set a timer and eventually be processed. |
| 105 if (!m_dispatchingList.isEmpty()) | 103 if (!m_dispatchingList.isEmpty()) |
| 106 return; | 104 return; |
| 107 | 105 |
| 108 m_timer.stop(); | 106 m_timer.stop(); |
| 109 | 107 |
| 110 m_dispatchingList.swap(m_dispatchSoonList); | 108 m_dispatchingList.swap(m_dispatchSoonList); |
| 111 size_t size = m_dispatchingList.size(); | 109 for (auto& senderInList : m_dispatchingList) { |
| 112 for (size_t i = 0; i < size; ++i) { | 110 if (T* sender = senderInList) { |
| 113 if (T* sender = m_dispatchingList[i]) { | 111 senderInList = nullptr; |
| 114 m_dispatchingList[i] = nullptr; | |
| 115 sender->dispatchPendingEvent(this); | 112 sender->dispatchPendingEvent(this); |
| 116 } | 113 } |
| 117 } | 114 } |
| 118 m_dispatchingList.clear(); | 115 m_dispatchingList.clear(); |
| 119 } | 116 } |
| 120 | 117 |
| 121 } // namespace blink | 118 } // namespace blink |
| 122 | 119 |
| 123 #endif // EventSender_h | 120 #endif // EventSender_h |
| OLD | NEW |