7#include "xfa/fwl/cfwl_notedriver.h"
12#include "build/build_config.h"
13#include "core/fxcrt/fx_extension.h"
14#include "fxjs/gc/container_trace.h"
15#include "xfa/fwl/cfwl_app.h"
16#include "xfa/fwl/cfwl_event.h"
17#include "xfa/fwl/cfwl_messagekey.h"
18#include "xfa/fwl/cfwl_messagekillfocus.h"
19#include "xfa/fwl/cfwl_messagemouse.h"
20#include "xfa/fwl/cfwl_messagemousewheel.h"
21#include "xfa/fwl/cfwl_messagesetfocus.h"
22#include "xfa/fwl/cfwl_widgetmgr.h"
23#include "xfa/fwl/fwl_widgetdef.h"
29uint64_t g_next_listener_key = 1;
33CFWL_NoteDriver::CFWL_NoteDriver(CFWL_App* pApp) : m_pApp(pApp) {}
37void CFWL_NoteDriver::
Trace(cppgc::Visitor* visitor)
const {
38 visitor->Trace(m_pApp);
39 visitor->Trace(m_pHover);
40 visitor->Trace(m_pFocus);
41 visitor->Trace(m_pGrab);
42 ContainerTrace(visitor, m_eventTargets);
46 for (
const auto& pair : m_eventTargets) {
47 if (pair.second->IsValid())
48 pair.second->ProcessEvent(pNote);
56 key = g_next_listener_key++;
59 if (!m_eventTargets[key]) {
60 m_eventTargets[key] = cppgc::MakeGarbageCollected<Target>(
61 m_pApp->GetHeap()->GetAllocationHandle(), pListener);
63 m_eventTargets[key]->SetEventSource(pEventSource);
71 auto it = m_eventTargets.find(key);
72 if (it != m_eventTargets.end())
73 it->second->Invalidate();
77 if (m_pFocus == pNoteTarget)
79 if (m_pHover == pNoteTarget)
81 if (m_pGrab == pNoteTarget)
86 if (m_pFocus == pNoteTarget)
88 if (m_pHover == pNoteTarget)
90 if (m_pGrab == pNoteTarget)
101 if (!DispatchMessage(pMessage, pMessageForm))
105 MouseSecondary(pMessage);
108bool CFWL_NoteDriver::DispatchMessage(
CFWL_Message* pMessage,
112 if (!DoSetFocus(pMessage, pMessageForm))
117 if (!DoKillFocus(pMessage, pMessageForm))
122 if (!DoKey(pMessage, pMessageForm))
127 if (!DoMouse(pMessage, pMessageForm))
132 if (!DoWheel(pMessage, pMessageForm))
146 m_pFocus = pMessage->GetDstTarget();
150bool CFWL_NoteDriver::DoKillFocus(
CFWL_Message* pMessage,
152 if (m_pFocus == pMessage->GetDstTarget())
158 CFWL_MessageKey* pMsg =
static_cast<CFWL_MessageKey*>(pMessage);
159#if !BUILDFLAG(IS_APPLE)
160 if (pMsg->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown &&
161 pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Tab) {
167 pMsg->SetDstTarget(m_pFocus.Get());
185 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
192 pMsg->m_pos = pMsg
->GetDstTarget()->TransformTo(pMessageForm, pMsg->m_pos);
193 if (!DoMouseEx(pMsg, pMessageForm))
201 CFWL_MessageMouseWheel* pMsg =
static_cast<CFWL_MessageMouseWheel*>(pMessage);
216 pTarget = m_pGrab.Get();
218 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
223 if (pTarget && pMessageForm != pTarget)
230void CFWL_NoteDriver::MouseSecondary(
CFWL_Message* pMessage) {
232 if (pTarget == m_pHover)
235 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
237 CFWL_MessageMouse msLeave(
238 m_pHover.Get(), CFWL_MessageMouse::MouseCommand::kLeave,
239 Mask<XFA_FWL_KeyFlag>(),
240 pTarget->TransformTo(m_pHover.Get(), pMsg->m_pos));
241 DispatchMessage(&msLeave,
nullptr);
250 Mask<XFA_FWL_KeyFlag>(), pMsg->m_pos);
251 DispatchMessage(&msHover,
nullptr);
254CFWL_NoteDriver::Target::Target(
CFWL_Widget* pListener)
255 : m_pListener(pListener) {}
257CFWL_NoteDriver::Target::~Target() =
default;
259void CFWL_NoteDriver::Target::Trace(cppgc::Visitor* visitor)
const {
260 visitor->Trace(m_pListener);
261 for (
auto& widget : m_widgets)
262 visitor->Trace(widget);
265void CFWL_NoteDriver::Target::SetEventSource(
CFWL_Widget* pSource) {
267 m_widgets.insert(pSource);
270bool CFWL_NoteDriver::Target::ProcessEvent(
CFWL_Event* pEvent) {
274 if (!m_widgets.empty() && m_widgets.count(pEvent->GetSrcTarget()) == 0)
CFWL_WidgetMgr * GetWidgetMgr() const
const uint32_t m_dwKeyCodeOrChar
void set_pos(const CFX_PointF &pos)
const CFX_PointF & pos() const
const MouseCommand m_dwCmd
CFWL_Widget * GetDstTarget() const
void SetDstTarget(CFWL_Widget *pWidget)
void SendEvent(CFWL_Event *pNote)
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
void NotifyTargetDestroy(CFWL_Widget *pNoteTarget)
void UnregisterEventTarget(CFWL_Widget *pListener)
void Trace(cppgc::Visitor *visitor) const
void ProcessMessage(CFWL_Message *pMessage)
void NotifyTargetHide(CFWL_Widget *pNoteTarget)