| 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/fwl_noteimp.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fwl/basewidget/fwl_tooltipctrlimp.h" | 10 #include "xfa/fwl/basewidget/fwl_tooltipctrlimp.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 if (!pApp) | 59 if (!pApp) |
| 60 return; | 60 return; |
| 61 | 61 |
| 62 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | 62 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); |
| 63 if (!pDriver) | 63 if (!pDriver) |
| 64 return; | 64 return; |
| 65 | 65 |
| 66 pDriver->SendEvent(&ev); | 66 pDriver->SendEvent(&ev); |
| 67 } | 67 } |
| 68 CFWL_NoteDriver::CFWL_NoteDriver() | 68 CFWL_NoteDriver::CFWL_NoteDriver() |
| 69 : m_sendEventCalled(0), | 69 : m_pHover(nullptr), |
| 70 m_pHover(nullptr), | |
| 71 m_pFocus(nullptr), | 70 m_pFocus(nullptr), |
| 72 m_pGrab(nullptr) { | 71 m_pGrab(nullptr), |
| 73 m_pNoteLoop = new CFWL_NoteLoop; | 72 m_pNoteLoop(new CFWL_NoteLoop) { |
| 74 PushNoteLoop(m_pNoteLoop); | 73 PushNoteLoop(m_pNoteLoop); |
| 75 } | 74 } |
| 76 CFWL_NoteDriver::~CFWL_NoteDriver() { | 75 CFWL_NoteDriver::~CFWL_NoteDriver() { |
| 77 delete m_pNoteLoop; | 76 delete m_pNoteLoop; |
| 78 ClearInvalidEventTargets(TRUE); | 77 ClearInvalidEventTargets(TRUE); |
| 79 } | 78 } |
| 80 | 79 |
| 81 FX_BOOL CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { | 80 void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { |
| 82 int32_t iCount = m_eventTargets.GetCount(); | 81 if (m_eventTargets.empty()) |
| 83 if (iCount < 1) | 82 return; |
| 84 return TRUE; | |
| 85 if (CFWL_EventType::Mouse == pNote->GetClassID()) { | 83 if (CFWL_EventType::Mouse == pNote->GetClassID()) { |
| 86 CFWL_EvtMouse* pMouse = static_cast<CFWL_EvtMouse*>(pNote); | 84 CFWL_EvtMouse* pMouse = static_cast<CFWL_EvtMouse*>(pNote); |
| 87 if (FWL_MouseCommand::Hover == pMouse->m_dwCmd) { | 85 if (FWL_MouseCommand::Hover == pMouse->m_dwCmd) { |
| 88 if (m_pNoteLoop->GetForm() && | 86 if (m_pNoteLoop->GetForm() && |
| 89 CFWL_ToolTipContainer::getInstance()->ProcessEnter( | 87 CFWL_ToolTipContainer::getInstance()->ProcessEnter( |
| 90 pMouse, m_pNoteLoop->GetForm()->GetInterface())) { | 88 pMouse, m_pNoteLoop->GetForm()->GetInterface())) { |
| 91 } | 89 } |
| 92 } else if (FWL_MouseCommand::Leave == pMouse->m_dwCmd) { | 90 } else if (FWL_MouseCommand::Leave == pMouse->m_dwCmd) { |
| 93 CFWL_ToolTipContainer::getInstance()->ProcessLeave(pMouse); | 91 CFWL_ToolTipContainer::getInstance()->ProcessLeave(pMouse); |
| 94 } else if ((FWL_MouseCommand::LeftButtonDown <= pMouse->m_dwCmd) && | 92 } else if ((FWL_MouseCommand::LeftButtonDown <= pMouse->m_dwCmd) && |
| 95 (FWL_MouseCommand::MiddleButtonDblClk >= pMouse->m_dwCmd)) { | 93 (FWL_MouseCommand::MiddleButtonDblClk >= pMouse->m_dwCmd)) { |
| 96 CFWL_ToolTipContainer::getInstance()->ProcessLeave(pMouse); | 94 CFWL_ToolTipContainer::getInstance()->ProcessLeave(pMouse); |
| 97 } | 95 } |
| 98 } | 96 } |
| 99 m_sendEventCalled++; | 97 for (const auto& pair : m_eventTargets) { |
| 100 FX_POSITION pos = m_eventTargets.GetStartPosition(); | 98 CFWL_EventTarget* pEventTarget = pair.second; |
| 101 while (pos) { | |
| 102 void* key = nullptr; | |
| 103 void* value = nullptr; | |
| 104 m_eventTargets.GetNextAssoc(pos, key, value); | |
| 105 | |
| 106 CFWL_EventTarget* pEventTarget = static_cast<CFWL_EventTarget*>(value); | |
| 107 if (pEventTarget && !pEventTarget->IsInvalid()) | 99 if (pEventTarget && !pEventTarget->IsInvalid()) |
| 108 pEventTarget->ProcessEvent(pNote); | 100 pEventTarget->ProcessEvent(pNote); |
| 109 } | 101 } |
| 110 m_sendEventCalled--; | |
| 111 return TRUE; | |
| 112 } | 102 } |
| 113 | 103 |
| 114 #define FWL_NoteDriver_EventKey 1100 | 104 #define FWL_NoteDriver_EventKey 1100 |
| 115 FWL_Error CFWL_NoteDriver::RegisterEventTarget(IFWL_Widget* pListener, | 105 FWL_Error CFWL_NoteDriver::RegisterEventTarget(IFWL_Widget* pListener, |
| 116 IFWL_Widget* pEventSource, | 106 IFWL_Widget* pEventSource, |
| 117 uint32_t dwFilter) { | 107 uint32_t dwFilter) { |
| 118 uint32_t dwkey = (uint32_t)(uintptr_t)pListener->GetPrivateData( | 108 uint32_t key = (uint32_t)(uintptr_t)pListener->GetPrivateData( |
| 119 (void*)(uintptr_t)FWL_NoteDriver_EventKey); | 109 (void*)(uintptr_t)FWL_NoteDriver_EventKey); |
| 120 if (dwkey == 0) { | 110 if (key == 0) { |
| 121 void* random = FX_Random_MT_Start(0); | 111 void* random = FX_Random_MT_Start(0); |
| 122 dwkey = rand(); | 112 key = rand(); |
| 123 FX_Random_MT_Close(random); | 113 FX_Random_MT_Close(random); |
| 124 pListener->SetPrivateData((void*)(uintptr_t)FWL_NoteDriver_EventKey, | 114 pListener->SetPrivateData((void*)(uintptr_t)FWL_NoteDriver_EventKey, |
| 125 (void*)(uintptr_t)dwkey, NULL); | 115 (void*)(uintptr_t)key, NULL); |
| 126 } | 116 } |
| 127 CFWL_EventTarget* value = NULL; | 117 if (!m_eventTargets[key]) |
| 128 if (!m_eventTargets.Lookup((void*)(uintptr_t)dwkey, (void*&)value)) { | 118 m_eventTargets[key] = new CFWL_EventTarget(this, pListener); |
| 129 value = new CFWL_EventTarget(this, pListener); | 119 |
| 130 m_eventTargets.SetAt((void*)(uintptr_t)dwkey, value); | 120 m_eventTargets[key]->SetEventSource(pEventSource, dwFilter); |
| 131 } | |
| 132 value->SetEventSource(pEventSource, dwFilter); | |
| 133 return FWL_Error::Succeeded; | 121 return FWL_Error::Succeeded; |
| 134 } | 122 } |
| 123 |
| 135 FWL_Error CFWL_NoteDriver::UnregisterEventTarget(IFWL_Widget* pListener) { | 124 FWL_Error CFWL_NoteDriver::UnregisterEventTarget(IFWL_Widget* pListener) { |
| 136 uint32_t dwkey = (uint32_t)(uintptr_t)pListener->GetPrivateData( | 125 uint32_t key = (uint32_t)(uintptr_t)pListener->GetPrivateData( |
| 137 (void*)(uintptr_t)FWL_NoteDriver_EventKey); | 126 (void*)(uintptr_t)FWL_NoteDriver_EventKey); |
| 138 if (dwkey == 0) { | 127 if (key == 0) |
| 139 return FWL_Error::Indefinite; | 128 return FWL_Error::Indefinite; |
| 140 } | 129 |
| 141 CFWL_EventTarget* value = NULL; | 130 auto it = m_eventTargets.find(key); |
| 142 if (m_eventTargets.Lookup((void*)(uintptr_t)dwkey, (void*&)value)) { | 131 if (it != m_eventTargets.end()) |
| 143 value->FlagInvalid(); | 132 it->second->FlagInvalid(); |
| 144 } | 133 |
| 145 return FWL_Error::Succeeded; | 134 return FWL_Error::Succeeded; |
| 146 } | 135 } |
| 136 |
| 147 void CFWL_NoteDriver::ClearEventTargets(FX_BOOL bRemoveAll) { | 137 void CFWL_NoteDriver::ClearEventTargets(FX_BOOL bRemoveAll) { |
| 148 ClearInvalidEventTargets(bRemoveAll); | 138 ClearInvalidEventTargets(bRemoveAll); |
| 149 } | 139 } |
| 150 IFWL_App* CFWL_NoteDriver::GetOwnerApp() const { | 140 IFWL_App* CFWL_NoteDriver::GetOwnerApp() const { |
| 151 return FWL_GetApp(); | 141 return FWL_GetApp(); |
| 152 } | 142 } |
| 153 FWL_Error CFWL_NoteDriver::PushNoteLoop(CFWL_NoteLoop* pNoteLoop) { | 143 FWL_Error CFWL_NoteDriver::PushNoteLoop(CFWL_NoteLoop* pNoteLoop) { |
| 154 m_noteLoopQueue.Add(pNoteLoop); | 144 m_noteLoopQueue.Add(pNoteLoop); |
| 155 return FWL_Error::Succeeded; | 145 return FWL_Error::Succeeded; |
| 156 } | 146 } |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr()); | 659 static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr()); |
| 670 if (!pWidgetMgr) | 660 if (!pWidgetMgr) |
| 671 return nullptr; | 661 return nullptr; |
| 672 pMessageForm = | 662 pMessageForm = |
| 673 pWidgetMgr->GetWidget(pDstTarget, FWL_WGTRELATION_SystemForm); | 663 pWidgetMgr->GetWidget(pDstTarget, FWL_WGTRELATION_SystemForm); |
| 674 } | 664 } |
| 675 return pMessageForm; | 665 return pMessageForm; |
| 676 } | 666 } |
| 677 | 667 |
| 678 void CFWL_NoteDriver::ClearInvalidEventTargets(FX_BOOL bRemoveAll) { | 668 void CFWL_NoteDriver::ClearInvalidEventTargets(FX_BOOL bRemoveAll) { |
| 679 FX_POSITION pos = m_eventTargets.GetStartPosition(); | 669 auto it = m_eventTargets.begin(); |
| 680 while (pos) { | 670 while (it != m_eventTargets.end()) { |
| 681 void* key = NULL; | 671 auto old = it++; |
| 682 CFWL_EventTarget* pEventTarget = NULL; | 672 if (old->second && (bRemoveAll || old->second->IsInvalid())) { |
| 683 m_eventTargets.GetNextAssoc(pos, key, (void*&)pEventTarget); | 673 delete old->second; |
| 684 if (pEventTarget && (bRemoveAll || pEventTarget->IsInvalid())) { | 674 m_eventTargets.erase(old); |
| 685 m_eventTargets.RemoveKey(key); | |
| 686 delete pEventTarget; | |
| 687 } | 675 } |
| 688 } | 676 } |
| 689 } | 677 } |
| 678 |
| 690 class CFWL_CoreToolTipDP : public IFWL_ToolTipDP { | 679 class CFWL_CoreToolTipDP : public IFWL_ToolTipDP { |
| 691 public: | 680 public: |
| 692 FWL_Error GetCaption(IFWL_Widget* pWidget, CFX_WideString& wsCaption); | 681 FWL_Error GetCaption(IFWL_Widget* pWidget, CFX_WideString& wsCaption); |
| 693 int32_t GetInitialDelay(IFWL_Widget* pWidget); | 682 int32_t GetInitialDelay(IFWL_Widget* pWidget); |
| 694 int32_t GetAutoPopDelay(IFWL_Widget* pWidget); | 683 int32_t GetAutoPopDelay(IFWL_Widget* pWidget); |
| 695 CFX_DIBitmap* GetToolTipIcon(IFWL_Widget* pWidget); | 684 CFX_DIBitmap* GetToolTipIcon(IFWL_Widget* pWidget); |
| 696 CFX_SizeF GetToolTipIconSize(IFWL_Widget* pWidget); | 685 CFX_SizeF GetToolTipIconSize(IFWL_Widget* pWidget); |
| 697 CFX_RectF GetAnchor(); | 686 CFX_RectF GetAnchor(); |
| 698 CFWL_CoreToolTipDP(); | 687 CFWL_CoreToolTipDP(); |
| 699 | 688 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 if (HasToolTip(pEvt->m_pDstTarget) && NULL != m_pToolTipImp) { | 895 if (HasToolTip(pEvt->m_pDstTarget) && NULL != m_pToolTipImp) { |
| 907 m_pToolTipImp->Hide(); | 896 m_pToolTipImp->Hide(); |
| 908 pCurTarget = NULL; | 897 pCurTarget = NULL; |
| 909 return TRUE; | 898 return TRUE; |
| 910 } | 899 } |
| 911 return FALSE; | 900 return FALSE; |
| 912 } | 901 } |
| 913 IFWL_ToolTipTarget* CFWL_ToolTipContainer::GetCurrentToolTipTarget() { | 902 IFWL_ToolTipTarget* CFWL_ToolTipContainer::GetCurrentToolTipTarget() { |
| 914 return pCurTarget; | 903 return pCurTarget; |
| 915 } | 904 } |
| OLD | NEW |