| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fwl/core/cfwl_eventtarget.h" | 7 #include "xfa/fwl/core/cfwl_eventtarget.h" |
| 8 | 8 |
| 9 #include "xfa/fwl/core/ifwl_widget.h" | 9 #include "xfa/fwl/core/ifwl_widget.h" |
| 10 #include "xfa/fwl/core/ifwl_widgetdelegate.h" | 10 #include "xfa/fwl/core/ifwl_widgetdelegate.h" |
| 11 | 11 |
| 12 CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener) | 12 CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener) |
| 13 : m_pListener(pListener), m_bInvalid(false) {} | 13 : m_pListener(pListener), m_bInvalid(false) {} |
| 14 | 14 |
| 15 CFWL_EventTarget::~CFWL_EventTarget() { | 15 CFWL_EventTarget::~CFWL_EventTarget() {} |
| 16 m_eventSources.RemoveAll(); | |
| 17 } | |
| 18 | 16 |
| 19 int32_t CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource, | 17 void CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource) { |
| 20 uint32_t dwFilter) { | 18 if (pSource) |
| 21 if (pSource) { | 19 m_widgets.insert(pSource); |
| 22 m_eventSources.SetAt(pSource, dwFilter); | |
| 23 return m_eventSources.GetCount(); | |
| 24 } | |
| 25 return 1; | |
| 26 } | 20 } |
| 27 | 21 |
| 28 bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { | 22 bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { |
| 29 IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); | 23 IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); |
| 30 if (!pDelegate) | 24 if (!pDelegate) |
| 31 return false; | 25 return false; |
| 32 if (m_eventSources.GetCount() == 0) { | 26 if (!m_widgets.empty() && m_widgets.count(pEvent->m_pSrcTarget) == 0) |
| 33 pDelegate->OnProcessEvent(pEvent); | 27 return false; |
| 34 return true; | |
| 35 } | |
| 36 | 28 |
| 37 FX_POSITION pos = m_eventSources.GetStartPosition(); | 29 pDelegate->OnProcessEvent(pEvent); |
| 38 while (pos) { | 30 return true; |
| 39 IFWL_Widget* pSource = nullptr; | |
| 40 uint32_t dwFilter = 0; | |
| 41 m_eventSources.GetNextAssoc(pos, (void*&)pSource, dwFilter); | |
| 42 if (pSource == pEvent->m_pSrcTarget) { | |
| 43 if (IsFilterEvent(pEvent, dwFilter)) { | |
| 44 pDelegate->OnProcessEvent(pEvent); | |
| 45 return true; | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 return false; | |
| 50 } | 31 } |
| 51 | |
| 52 bool CFWL_EventTarget::IsFilterEvent(CFWL_Event* pEvent, | |
| 53 uint32_t dwFilter) const { | |
| 54 if (dwFilter == FWL_EVENT_ALL_MASK) | |
| 55 return true; | |
| 56 | |
| 57 switch (pEvent->GetClassID()) { | |
| 58 case CFWL_EventType::Mouse: | |
| 59 return !!(dwFilter & FWL_EVENT_MOUSE_MASK); | |
| 60 case CFWL_EventType::MouseWheel: | |
| 61 return !!(dwFilter & FWL_EVENT_MOUSEWHEEL_MASK); | |
| 62 case CFWL_EventType::Key: | |
| 63 return !!(dwFilter & FWL_EVENT_KEY_MASK); | |
| 64 case CFWL_EventType::SetFocus: | |
| 65 case CFWL_EventType::KillFocus: | |
| 66 return !!(dwFilter & FWL_EVENT_FOCUSCHANGED_MASK); | |
| 67 case CFWL_EventType::Close: | |
| 68 return !!(dwFilter & FWL_EVENT_CLOSE_MASK); | |
| 69 case CFWL_EventType::SizeChanged: | |
| 70 return !!(dwFilter & FWL_EVENT_SIZECHANGED_MASK); | |
| 71 default: | |
| 72 return !!(dwFilter & FWL_EVENT_CONTROL_MASK); | |
| 73 } | |
| 74 } | |
| OLD | NEW |