summaryrefslogtreecommitdiff
path: root/xfa/fwl/core/cfwl_eventtarget.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-11-21 17:05:58 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-21 17:05:59 -0800
commit37b6d1479b1674eb239cea8893eea31274d22ecd (patch)
tree07b5a2842c29c2b3324c6c60d369e9aea000e1b0 /xfa/fwl/core/cfwl_eventtarget.cpp
parent6a1c9bd09ef8fdd2fe2f9e39b9a05f6581be9d87 (diff)
downloadpdfium-37b6d1479b1674eb239cea8893eea31274d22ecd.tar.xz
Split fwl/core class pt II.
Split classes in FWL to be single class per file. In the case of data providers which added no new methods, removed and used the IFWL_Widget::DataProvider directly. Review-Url: https://codereview.chromium.org/2520063002
Diffstat (limited to 'xfa/fwl/core/cfwl_eventtarget.cpp')
-rw-r--r--xfa/fwl/core/cfwl_eventtarget.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/xfa/fwl/core/cfwl_eventtarget.cpp b/xfa/fwl/core/cfwl_eventtarget.cpp
new file mode 100644
index 0000000000..77fb9d8354
--- /dev/null
+++ b/xfa/fwl/core/cfwl_eventtarget.cpp
@@ -0,0 +1,74 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fwl/core/cfwl_eventtarget.h"
+
+#include "xfa/fwl/core/ifwl_widget.h"
+#include "xfa/fwl/core/ifwl_widgetdelegate.h"
+
+CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener)
+ : m_pListener(pListener), m_bInvalid(false) {}
+
+CFWL_EventTarget::~CFWL_EventTarget() {
+ m_eventSources.RemoveAll();
+}
+
+int32_t CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource,
+ uint32_t dwFilter) {
+ if (pSource) {
+ m_eventSources.SetAt(pSource, dwFilter);
+ return m_eventSources.GetCount();
+ }
+ return 1;
+}
+
+bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) {
+ IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate();
+ if (!pDelegate)
+ return false;
+ if (m_eventSources.GetCount() == 0) {
+ pDelegate->OnProcessEvent(pEvent);
+ return true;
+ }
+
+ FX_POSITION pos = m_eventSources.GetStartPosition();
+ while (pos) {
+ IFWL_Widget* pSource = nullptr;
+ uint32_t dwFilter = 0;
+ m_eventSources.GetNextAssoc(pos, (void*&)pSource, dwFilter);
+ if (pSource == pEvent->m_pSrcTarget) {
+ if (IsFilterEvent(pEvent, dwFilter)) {
+ pDelegate->OnProcessEvent(pEvent);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool CFWL_EventTarget::IsFilterEvent(CFWL_Event* pEvent,
+ uint32_t dwFilter) const {
+ if (dwFilter == FWL_EVENT_ALL_MASK)
+ return true;
+
+ switch (pEvent->GetClassID()) {
+ case CFWL_EventType::Mouse:
+ return !!(dwFilter & FWL_EVENT_MOUSE_MASK);
+ case CFWL_EventType::MouseWheel:
+ return !!(dwFilter & FWL_EVENT_MOUSEWHEEL_MASK);
+ case CFWL_EventType::Key:
+ return !!(dwFilter & FWL_EVENT_KEY_MASK);
+ case CFWL_EventType::SetFocus:
+ case CFWL_EventType::KillFocus:
+ return !!(dwFilter & FWL_EVENT_FOCUSCHANGED_MASK);
+ case CFWL_EventType::Close:
+ return !!(dwFilter & FWL_EVENT_CLOSE_MASK);
+ case CFWL_EventType::SizeChanged:
+ return !!(dwFilter & FWL_EVENT_SIZECHANGED_MASK);
+ default:
+ return !!(dwFilter & FWL_EVENT_CONTROL_MASK);
+ }
+}