OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/fwl_noteimp.h" | 7 #include "xfa/fwl/core/cfwl_notedriver.h" |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "core/fxcrt/fx_ext.h" | 11 #include "core/fxcrt/fx_ext.h" |
12 #include "third_party/base/ptr_util.h" | 12 #include "third_party/base/ptr_util.h" |
13 #include "third_party/base/stl_util.h" | 13 #include "third_party/base/stl_util.h" |
| 14 #include "xfa/fwl/core/cfwl_eventtarget.h" |
14 #include "xfa/fwl/core/cfwl_msgkey.h" | 15 #include "xfa/fwl/core/cfwl_msgkey.h" |
15 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | 16 #include "xfa/fwl/core/cfwl_msgkillfocus.h" |
16 #include "xfa/fwl/core/cfwl_msgmouse.h" | 17 #include "xfa/fwl/core/cfwl_msgmouse.h" |
17 #include "xfa/fwl/core/cfwl_msgmousewheel.h" | 18 #include "xfa/fwl/core/cfwl_msgmousewheel.h" |
18 #include "xfa/fwl/core/cfwl_msgsetfocus.h" | 19 #include "xfa/fwl/core/cfwl_msgsetfocus.h" |
| 20 #include "xfa/fwl/core/cfwl_noteloop.h" |
19 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 21 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
20 #include "xfa/fwl/core/ifwl_app.h" | 22 #include "xfa/fwl/core/ifwl_app.h" |
21 #include "xfa/fwl/core/ifwl_tooltip.h" | 23 #include "xfa/fwl/core/ifwl_tooltip.h" |
22 | 24 |
23 CFWL_NoteLoop::CFWL_NoteLoop() : m_bContinueModal(true) {} | |
24 | |
25 CFWL_NoteDriver::CFWL_NoteDriver() | 25 CFWL_NoteDriver::CFWL_NoteDriver() |
26 : m_pHover(nullptr), | 26 : m_pHover(nullptr), |
27 m_pFocus(nullptr), | 27 m_pFocus(nullptr), |
28 m_pGrab(nullptr), | 28 m_pGrab(nullptr), |
29 m_pNoteLoop(pdfium::MakeUnique<CFWL_NoteLoop>()) { | 29 m_pNoteLoop(pdfium::MakeUnique<CFWL_NoteLoop>()) { |
30 PushNoteLoop(m_pNoteLoop.get()); | 30 PushNoteLoop(m_pNoteLoop.get()); |
31 } | 31 } |
32 | 32 |
33 CFWL_NoteDriver::~CFWL_NoteDriver() { | 33 CFWL_NoteDriver::~CFWL_NoteDriver() { |
34 ClearEventTargets(true); | 34 ClearEventTargets(true); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { | 480 void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { |
481 auto it = m_eventTargets.begin(); | 481 auto it = m_eventTargets.begin(); |
482 while (it != m_eventTargets.end()) { | 482 while (it != m_eventTargets.end()) { |
483 auto old = it++; | 483 auto old = it++; |
484 if (old->second && (bRemoveAll || old->second->IsInvalid())) { | 484 if (old->second && (bRemoveAll || old->second->IsInvalid())) { |
485 delete old->second; | 485 delete old->second; |
486 m_eventTargets.erase(old); | 486 m_eventTargets.erase(old); |
487 } | 487 } |
488 } | 488 } |
489 } | 489 } |
490 | |
491 CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener) | |
492 : m_pListener(pListener), m_bInvalid(false) {} | |
493 | |
494 CFWL_EventTarget::~CFWL_EventTarget() { | |
495 m_eventSources.RemoveAll(); | |
496 } | |
497 | |
498 int32_t CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource, | |
499 uint32_t dwFilter) { | |
500 if (pSource) { | |
501 m_eventSources.SetAt(pSource, dwFilter); | |
502 return m_eventSources.GetCount(); | |
503 } | |
504 return 1; | |
505 } | |
506 | |
507 bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { | |
508 IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); | |
509 if (!pDelegate) | |
510 return false; | |
511 if (m_eventSources.GetCount() == 0) { | |
512 pDelegate->OnProcessEvent(pEvent); | |
513 return true; | |
514 } | |
515 | |
516 FX_POSITION pos = m_eventSources.GetStartPosition(); | |
517 while (pos) { | |
518 IFWL_Widget* pSource = nullptr; | |
519 uint32_t dwFilter = 0; | |
520 m_eventSources.GetNextAssoc(pos, (void*&)pSource, dwFilter); | |
521 if (pSource == pEvent->m_pSrcTarget) { | |
522 if (IsFilterEvent(pEvent, dwFilter)) { | |
523 pDelegate->OnProcessEvent(pEvent); | |
524 return true; | |
525 } | |
526 } | |
527 } | |
528 return false; | |
529 } | |
530 | |
531 bool CFWL_EventTarget::IsFilterEvent(CFWL_Event* pEvent, | |
532 uint32_t dwFilter) const { | |
533 if (dwFilter == FWL_EVENT_ALL_MASK) | |
534 return true; | |
535 | |
536 switch (pEvent->GetClassID()) { | |
537 case CFWL_EventType::Mouse: | |
538 return !!(dwFilter & FWL_EVENT_MOUSE_MASK); | |
539 case CFWL_EventType::MouseWheel: | |
540 return !!(dwFilter & FWL_EVENT_MOUSEWHEEL_MASK); | |
541 case CFWL_EventType::Key: | |
542 return !!(dwFilter & FWL_EVENT_KEY_MASK); | |
543 case CFWL_EventType::SetFocus: | |
544 case CFWL_EventType::KillFocus: | |
545 return !!(dwFilter & FWL_EVENT_FOCUSCHANGED_MASK); | |
546 case CFWL_EventType::Close: | |
547 return !!(dwFilter & FWL_EVENT_CLOSE_MASK); | |
548 case CFWL_EventType::SizeChanged: | |
549 return !!(dwFilter & FWL_EVENT_SIZECHANGED_MASK); | |
550 default: | |
551 return !!(dwFilter & FWL_EVENT_CONTROL_MASK); | |
552 } | |
553 } | |
OLD | NEW |