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"
27uint64_t g_next_listener_key = 1;
31CFWL_NoteDriver::CFWL_NoteDriver(CFWL_App* pApp) : m_pApp(pApp) {}
35void CFWL_NoteDriver::
Trace(cppgc::Visitor* visitor)
const {
36 visitor->Trace(m_pApp);
37 visitor->Trace(m_pHover);
38 visitor->Trace(m_pFocus);
39 visitor->Trace(m_pGrab);
40 ContainerTrace(visitor, m_eventTargets);
44 for (
const auto& pair : m_eventTargets) {
45 if (pair.second->IsValid())
46 pair.second->ProcessEvent(pNote);
54 key = g_next_listener_key++;
57 if (!m_eventTargets[key]) {
58 m_eventTargets[key] = cppgc::MakeGarbageCollected<Target>(
59 m_pApp->GetHeap()->GetAllocationHandle(), pListener);
61 m_eventTargets[key]->SetEventSource(pEventSource);
69 auto it = m_eventTargets.find(key);
70 if (it != m_eventTargets.end())
71 it->second->Invalidate();
75 if (m_pFocus == pNoteTarget)
77 if (m_pHover == pNoteTarget)
79 if (m_pGrab == pNoteTarget)
84 if (m_pFocus == pNoteTarget)
86 if (m_pHover == pNoteTarget)
88 if (m_pGrab == pNoteTarget)
99 if (!DispatchMessage(pMessage, pMessageForm))
103 MouseSecondary(pMessage);
106bool CFWL_NoteDriver::DispatchMessage(
CFWL_Message* pMessage,
110 if (!DoSetFocus(pMessage, pMessageForm))
115 if (!DoKillFocus(pMessage, pMessageForm))
120 if (!DoKey(pMessage, pMessageForm))
125 if (!DoMouse(pMessage, pMessageForm))
130 if (!DoWheel(pMessage, pMessageForm))
144 m_pFocus = pMessage->GetDstTarget();
148bool CFWL_NoteDriver::DoKillFocus(
CFWL_Message* pMessage,
150 if (m_pFocus == pMessage->GetDstTarget())
156 CFWL_MessageKey* pMsg =
static_cast<CFWL_MessageKey*>(pMessage);
157#if !BUILDFLAG(IS_APPLE)
158 if (pMsg->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown &&
159 pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Tab) {
165 pMsg->SetDstTarget(m_pFocus.Get());
183 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
190 pMsg->m_pos = pMsg
->GetDstTarget()->TransformTo(pMessageForm, pMsg->m_pos);
191 if (!DoMouseEx(pMsg, pMessageForm))
199 CFWL_MessageMouseWheel* pMsg =
static_cast<CFWL_MessageMouseWheel*>(pMessage);
214 pTarget = m_pGrab.Get();
216 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
221 if (pTarget && pMessageForm != pTarget)
228void CFWL_NoteDriver::MouseSecondary(
CFWL_Message* pMessage) {
230 if (pTarget == m_pHover)
233 CFWL_MessageMouse* pMsg =
static_cast<CFWL_MessageMouse*>(pMessage);
235 CFWL_MessageMouse msLeave(
236 m_pHover.Get(), CFWL_MessageMouse::MouseCommand::kLeave,
237 Mask<XFA_FWL_KeyFlag>(),
238 pTarget->TransformTo(m_pHover.Get(), pMsg->m_pos));
239 DispatchMessage(&msLeave,
nullptr);
248 Mask<XFA_FWL_KeyFlag>(), pMsg->m_pos);
249 DispatchMessage(&msHover,
nullptr);
252CFWL_NoteDriver::Target::Target(
CFWL_Widget* pListener)
253 : m_pListener(pListener) {}
255CFWL_NoteDriver::Target::~Target() =
default;
257void CFWL_NoteDriver::Target::Trace(cppgc::Visitor* visitor)
const {
258 visitor->Trace(m_pListener);
259 for (
auto& widget : m_widgets)
260 visitor->Trace(widget);
263void CFWL_NoteDriver::Target::SetEventSource(
CFWL_Widget* pSource) {
265 m_widgets.insert(pSource);
268bool CFWL_NoteDriver::Target::ProcessEvent(
CFWL_Event* pEvent) {
272 if (!m_widgets.empty() && m_widgets.count(pEvent->GetSrcTarget()) == 0)
CFWL_WidgetMgr * GetWidgetMgr() const
const uint32_t m_dwKeyCodeOrChar
const CFX_PointF & pos() const
void set_pos(const CFX_PointF &pos)
const MouseCommand m_dwCmd
CFWL_Widget * GetDstTarget() const
void SetDstTarget(CFWL_Widget *pWidget)
void NotifyTargetHide(CFWL_Widget *pNoteTarget)
void SendEvent(CFWL_Event *pNote)
void ProcessMessage(CFWL_Message *pMessage)
void UnregisterEventTarget(CFWL_Widget *pListener)
void NotifyTargetDestroy(CFWL_Widget *pNoteTarget)
void Trace(cppgc::Visitor *visitor) const
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)