OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #include "xfa/fwl/core/cfwl_eventtarget.h" |
| 8 |
| 9 #include "xfa/fwl/core/ifwl_widget.h" |
| 10 #include "xfa/fwl/core/ifwl_widgetdelegate.h" |
| 11 |
| 12 CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener) |
| 13 : m_pListener(pListener), m_bInvalid(false) {} |
| 14 |
| 15 CFWL_EventTarget::~CFWL_EventTarget() { |
| 16 m_eventSources.RemoveAll(); |
| 17 } |
| 18 |
| 19 int32_t CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource, |
| 20 uint32_t dwFilter) { |
| 21 if (pSource) { |
| 22 m_eventSources.SetAt(pSource, dwFilter); |
| 23 return m_eventSources.GetCount(); |
| 24 } |
| 25 return 1; |
| 26 } |
| 27 |
| 28 bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { |
| 29 IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); |
| 30 if (!pDelegate) |
| 31 return false; |
| 32 if (m_eventSources.GetCount() == 0) { |
| 33 pDelegate->OnProcessEvent(pEvent); |
| 34 return true; |
| 35 } |
| 36 |
| 37 FX_POSITION pos = m_eventSources.GetStartPosition(); |
| 38 while (pos) { |
| 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 } |
| 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 |