Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: xfa/fwl/core/fwl_noteimp.cpp

Issue 2506493003: Continue nit cleanup in fwl/core (Closed)
Patch Set: review feedback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/core/fwl_noteimp.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fx_ext.h" 9 #include "core/fxcrt/fx_ext.h"
10 #include "third_party/base/ptr_util.h" 10 #include "third_party/base/ptr_util.h"
11 #include "third_party/base/stl_util.h" 11 #include "third_party/base/stl_util.h"
12 #include "xfa/fwl/core/cfwl_message.h" 12 #include "xfa/fwl/core/cfwl_message.h"
13 #include "xfa/fwl/core/cfwl_widgetmgr.h" 13 #include "xfa/fwl/core/cfwl_widgetmgr.h"
14 #include "xfa/fwl/core/ifwl_app.h" 14 #include "xfa/fwl/core/ifwl_app.h"
15 #include "xfa/fwl/core/ifwl_tooltip.h" 15 #include "xfa/fwl/core/ifwl_tooltip.h"
16 16
17 CFWL_NoteLoop::CFWL_NoteLoop() : m_bContinueModal(true) {} 17 CFWL_NoteLoop::CFWL_NoteLoop() : m_bContinueModal(true) {}
18 18
19 CFWL_NoteDriver::CFWL_NoteDriver() 19 CFWL_NoteDriver::CFWL_NoteDriver()
20 : m_pHover(nullptr), 20 : m_pHover(nullptr),
21 m_pFocus(nullptr), 21 m_pFocus(nullptr),
22 m_pGrab(nullptr), 22 m_pGrab(nullptr),
23 m_pNoteLoop(pdfium::MakeUnique<CFWL_NoteLoop>()) { 23 m_pNoteLoop(pdfium::MakeUnique<CFWL_NoteLoop>()) {
24 PushNoteLoop(m_pNoteLoop.get()); 24 PushNoteLoop(m_pNoteLoop.get());
25 } 25 }
26
26 CFWL_NoteDriver::~CFWL_NoteDriver() { 27 CFWL_NoteDriver::~CFWL_NoteDriver() {
27 ClearEventTargets(true); 28 ClearEventTargets(true);
28 } 29 }
29 30
30 void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) { 31 void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) {
31 if (m_eventTargets.empty()) 32 if (m_eventTargets.empty())
32 return; 33 return;
33 34
34 for (const auto& pair : m_eventTargets) { 35 for (const auto& pair : m_eventTargets) {
35 CFWL_EventTarget* pEventTarget = pair.second; 36 CFWL_EventTarget* pEventTarget = pair.second;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 71
71 CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() { 72 CFWL_NoteLoop* CFWL_NoteDriver::PopNoteLoop() {
72 int32_t pos = m_noteLoopQueue.GetSize(); 73 int32_t pos = m_noteLoopQueue.GetSize();
73 if (pos <= 0) 74 if (pos <= 0)
74 return nullptr; 75 return nullptr;
75 76
76 CFWL_NoteLoop* p = m_noteLoopQueue.GetAt(pos - 1); 77 CFWL_NoteLoop* p = m_noteLoopQueue.GetAt(pos - 1);
77 m_noteLoopQueue.RemoveAt(pos - 1); 78 m_noteLoopQueue.RemoveAt(pos - 1);
78 return p; 79 return p;
79 } 80 }
81
80 bool CFWL_NoteDriver::SetFocus(IFWL_Widget* pFocus, bool bNotify) { 82 bool CFWL_NoteDriver::SetFocus(IFWL_Widget* pFocus, bool bNotify) {
81 if (m_pFocus == pFocus) { 83 if (m_pFocus == pFocus)
82 return true; 84 return true;
83 } 85
84 IFWL_Widget* pPrev = m_pFocus; 86 IFWL_Widget* pPrev = m_pFocus;
85 m_pFocus = pFocus; 87 m_pFocus = pFocus;
86 if (pPrev) { 88 if (pPrev) {
87 CFWL_MsgKillFocus ms; 89 CFWL_MsgKillFocus ms;
88 ms.m_pDstTarget = pPrev; 90 ms.m_pDstTarget = pPrev;
89 ms.m_pSrcTarget = pPrev; 91 ms.m_pSrcTarget = pPrev;
90 if (bNotify) { 92 if (bNotify)
91 ms.m_dwExtend = 1; 93 ms.m_dwExtend = 1;
92 } 94
93 if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) 95 if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate())
94 pDelegate->OnProcessMessage(&ms); 96 pDelegate->OnProcessMessage(&ms);
95 } 97 }
96 if (pFocus) { 98 if (pFocus) {
97 IFWL_Widget* pWidget = 99 IFWL_Widget* pWidget =
98 pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus); 100 pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus);
99 IFWL_Form* pForm = static_cast<IFWL_Form*>(pWidget); 101 IFWL_Form* pForm = static_cast<IFWL_Form*>(pWidget);
100 if (pForm) 102 if (pForm)
101 pForm->SetSubFocus(pFocus); 103 pForm->SetSubFocus(pFocus);
102 104
103 CFWL_MsgSetFocus ms; 105 CFWL_MsgSetFocus ms;
104 ms.m_pDstTarget = pFocus; 106 ms.m_pDstTarget = pFocus;
105 if (bNotify) { 107 if (bNotify)
106 ms.m_dwExtend = 1; 108 ms.m_dwExtend = 1;
107 }
108
109 if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) 109 if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate())
110 pDelegate->OnProcessMessage(&ms); 110 pDelegate->OnProcessMessage(&ms);
111 } 111 }
112 return true; 112 return true;
113 } 113 }
114 114
115 void CFWL_NoteDriver::Run() { 115 void CFWL_NoteDriver::Run() {
116 #if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \ 116 #if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \
117 _FX_OS_ == _FX_WIN64_) 117 _FX_OS_ == _FX_WIN64_)
118 CFWL_NoteLoop* pTopLoop = nullptr;
119 for (;;) { 118 for (;;) {
120 pTopLoop = GetTopLoop(); 119 CFWL_NoteLoop* pTopLoop = GetTopLoop();
121 if (!pTopLoop || !pTopLoop->ContinueModal()) 120 if (!pTopLoop || !pTopLoop->ContinueModal())
122 break; 121 break;
123 if (UnqueueMessage(pTopLoop)) 122 UnqueueMessage(pTopLoop);
124 continue;
125 } 123 }
126 #endif 124 #endif
127 } 125 }
128 126
129 void CFWL_NoteDriver::NotifyTargetHide(IFWL_Widget* pNoteTarget) { 127 void CFWL_NoteDriver::NotifyTargetHide(IFWL_Widget* pNoteTarget) {
130 if (m_pFocus == pNoteTarget) { 128 if (m_pFocus == pNoteTarget)
131 m_pFocus = nullptr; 129 m_pFocus = nullptr;
132 } 130 if (m_pHover == pNoteTarget)
133 if (m_pHover == pNoteTarget) {
134 m_pHover = nullptr; 131 m_pHover = nullptr;
135 } 132 if (m_pGrab == pNoteTarget)
136 if (m_pGrab == pNoteTarget) {
137 m_pGrab = nullptr; 133 m_pGrab = nullptr;
138 }
139 } 134 }
135
140 void CFWL_NoteDriver::NotifyTargetDestroy(IFWL_Widget* pNoteTarget) { 136 void CFWL_NoteDriver::NotifyTargetDestroy(IFWL_Widget* pNoteTarget) {
141 if (m_pFocus == pNoteTarget) { 137 if (m_pFocus == pNoteTarget)
142 m_pFocus = nullptr; 138 m_pFocus = nullptr;
143 } 139 if (m_pHover == pNoteTarget)
144 if (m_pHover == pNoteTarget) {
145 m_pHover = nullptr; 140 m_pHover = nullptr;
146 } 141 if (m_pGrab == pNoteTarget)
147 if (m_pGrab == pNoteTarget) {
148 m_pGrab = nullptr; 142 m_pGrab = nullptr;
149 } 143
150 UnregisterEventTarget(pNoteTarget); 144 UnregisterEventTarget(pNoteTarget);
151 int32_t count = m_forms.GetSize(); 145
152 for (int32_t nIndex = 0; nIndex < count; nIndex++) { 146 for (int32_t nIndex = 0; nIndex < m_forms.GetSize(); nIndex++) {
153 IFWL_Form* pForm = static_cast<IFWL_Form*>(m_forms[nIndex]); 147 IFWL_Form* pForm = static_cast<IFWL_Form*>(m_forms[nIndex]);
154 if (!pForm) { 148 if (!pForm)
155 continue; 149 continue;
156 } 150
157 IFWL_Widget* pSubFocus = pForm->GetSubFocus(); 151 IFWL_Widget* pSubFocus = pForm->GetSubFocus();
158 if (!pSubFocus) 152 if (!pSubFocus)
159 return; 153 return;
160 if (pSubFocus == pNoteTarget) { 154 if (pSubFocus == pNoteTarget)
161 pForm->SetSubFocus(nullptr); 155 pForm->SetSubFocus(nullptr);
162 }
163 } 156 }
164 } 157 }
165 158
166 void CFWL_NoteDriver::RegisterForm(IFWL_Widget* pForm) { 159 void CFWL_NoteDriver::RegisterForm(IFWL_Widget* pForm) {
167 if (!pForm || m_forms.Find(pForm) >= 0) 160 if (!pForm || m_forms.Find(pForm) >= 0)
168 return; 161 return;
169 162
170 m_forms.Add(pForm); 163 m_forms.Add(pForm);
171 if (m_forms.GetSize() == 1) { 164 if (m_forms.GetSize() != 1)
172 CFWL_NoteLoop* pLoop = 165 return;
173 static_cast<CFWL_NoteLoop*>(m_noteLoopQueue.GetAt(0)); 166
174 if (!pLoop) 167 CFWL_NoteLoop* pLoop = m_noteLoopQueue.GetAt(0);
175 return; 168 if (!pLoop)
176 pLoop->SetMainForm(pForm); 169 return;
177 } 170
171 pLoop->SetMainForm(pForm);
178 } 172 }
179 173
180 void CFWL_NoteDriver::UnRegisterForm(IFWL_Widget* pForm) { 174 void CFWL_NoteDriver::UnRegisterForm(IFWL_Widget* pForm) {
181 if (!pForm) 175 if (!pForm)
182 return; 176 return;
177
183 int32_t nIndex = m_forms.Find(pForm); 178 int32_t nIndex = m_forms.Find(pForm);
184 if (nIndex < 0) 179 if (nIndex < 0)
185 return; 180 return;
181
186 m_forms.RemoveAt(nIndex); 182 m_forms.RemoveAt(nIndex);
187 } 183 }
188 bool CFWL_NoteDriver::QueueMessage(CFWL_Message* pMessage) { 184
185 void CFWL_NoteDriver::QueueMessage(CFWL_Message* pMessage) {
189 pMessage->Retain(); 186 pMessage->Retain();
190 m_noteQueue.Add(pMessage); 187 m_noteQueue.Add(pMessage);
191 return true;
192 } 188 }
193 bool CFWL_NoteDriver::UnqueueMessage(CFWL_NoteLoop* pNoteLoop) { 189
194 if (m_noteQueue.GetSize() < 1) { 190 void CFWL_NoteDriver::UnqueueMessage(CFWL_NoteLoop* pNoteLoop) {
195 return false; 191 if (m_noteQueue.GetSize() < 1)
196 } 192 return;
193
197 CFWL_Message* pMessage = m_noteQueue[0]; 194 CFWL_Message* pMessage = m_noteQueue[0];
198 m_noteQueue.RemoveAt(0); 195 m_noteQueue.RemoveAt(0);
199 if (!IsValidMessage(pMessage)) { 196 if (!IsValidMessage(pMessage)) {
200 pMessage->Release(); 197 pMessage->Release();
201 return true; 198 return;
202 } 199 }
203 ProcessMessage(pMessage); 200 ProcessMessage(pMessage);
201 pMessage->Release();
202 }
204 203
205 pMessage->Release();
206 return true;
207 }
208 CFWL_NoteLoop* CFWL_NoteDriver::GetTopLoop() const { 204 CFWL_NoteLoop* CFWL_NoteDriver::GetTopLoop() const {
209 int32_t size = m_noteLoopQueue.GetSize(); 205 int32_t size = m_noteLoopQueue.GetSize();
210 if (size <= 0) 206 if (size <= 0)
211 return nullptr; 207 return nullptr;
212 return static_cast<CFWL_NoteLoop*>(m_noteLoopQueue[size - 1]); 208 return m_noteLoopQueue[size - 1];
213 } 209 }
214 210
215 bool CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) { 211 void CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) {
216 CFWL_WidgetMgr* pWidgetMgr = 212 CFWL_WidgetMgr* pWidgetMgr =
217 pMessage->m_pDstTarget->GetOwnerApp()->GetWidgetMgr(); 213 pMessage->m_pDstTarget->GetOwnerApp()->GetWidgetMgr();
218 IFWL_Widget* pMessageForm = pWidgetMgr->IsFormDisabled() 214 IFWL_Widget* pMessageForm = pWidgetMgr->IsFormDisabled()
219 ? pMessage->m_pDstTarget 215 ? pMessage->m_pDstTarget
220 : GetMessageForm(pMessage->m_pDstTarget); 216 : GetMessageForm(pMessage->m_pDstTarget);
221 if (!pMessageForm) 217 if (!pMessageForm)
218 return;
219 if (!DispatchMessage(pMessage, pMessageForm))
220 return;
221
222 if (pMessage->GetClassID() == CFWL_MessageType::Mouse)
223 MouseSecondary(pMessage);
224 }
225
226 bool CFWL_NoteDriver::DispatchMessage(CFWL_Message* pMessage,
227 IFWL_Widget* pMessageForm) {
228 switch (pMessage->GetClassID()) {
229 case CFWL_MessageType::SetFocus: {
230 if (!DoSetFocus(pMessage, pMessageForm))
231 return false;
232 break;
233 }
234 case CFWL_MessageType::KillFocus: {
235 if (!DoKillFocus(pMessage, pMessageForm))
236 return false;
237 break;
238 }
239 case CFWL_MessageType::Key: {
240 if (!DoKey(pMessage, pMessageForm))
241 return false;
242 break;
243 }
244 case CFWL_MessageType::Mouse: {
245 if (!DoMouse(pMessage, pMessageForm))
246 return false;
247 break;
248 }
249 case CFWL_MessageType::MouseWheel: {
250 if (!DoWheel(pMessage, pMessageForm))
251 return false;
252 break;
253 }
254 default:
255 break;
256 }
257 if (IFWL_WidgetDelegate* pDelegate = pMessage->m_pDstTarget->GetDelegate())
258 pDelegate->OnProcessMessage(pMessage);
259
260 return true;
261 }
262
263 bool CFWL_NoteDriver::DoSetFocus(CFWL_Message* pMessage,
264 IFWL_Widget* pMessageForm) {
265 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
266 if (pWidgetMgr->IsFormDisabled()) {
267 m_pFocus = pMessage->m_pDstTarget;
268 return true;
269 }
270
271 IFWL_Widget* pWidget = pMessage->m_pDstTarget;
272 if (!pWidget)
222 return false; 273 return false;
223 if (DispatchMessage(pMessage, pMessageForm)) { 274
224 if (pMessage->GetClassID() == CFWL_MessageType::Mouse) 275 IFWL_Form* pForm = static_cast<IFWL_Form*>(pWidget);
225 MouseSecondary(static_cast<CFWL_MsgMouse*>(pMessage)); 276 IFWL_Widget* pSubFocus = pForm->GetSubFocus();
226 return true; 277 if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) {
278 pMessage->m_pDstTarget = pSubFocus;
279 if (m_pFocus != pMessage->m_pDstTarget) {
280 m_pFocus = pMessage->m_pDstTarget;
281 return true;
282 }
227 } 283 }
228 return false; 284 return false;
229 } 285 }
230 286
231 bool CFWL_NoteDriver::DispatchMessage(CFWL_Message* pMessage, 287 bool CFWL_NoteDriver::DoKillFocus(CFWL_Message* pMessage,
232 IFWL_Widget* pMessageForm) { 288 IFWL_Widget* pMessageForm) {
233 bool bRet = false;
234 switch (pMessage->GetClassID()) {
235 case CFWL_MessageType::SetFocus: {
236 bRet = DoSetFocus(static_cast<CFWL_MsgSetFocus*>(pMessage), pMessageForm);
237 break;
238 }
239 case CFWL_MessageType::KillFocus: {
240 bRet =
241 DoKillFocus(static_cast<CFWL_MsgKillFocus*>(pMessage), pMessageForm);
242 break;
243 }
244 case CFWL_MessageType::Key: {
245 bRet = DoKey(static_cast<CFWL_MsgKey*>(pMessage), pMessageForm);
246 break;
247 }
248 case CFWL_MessageType::Mouse: {
249 bRet = DoMouse(static_cast<CFWL_MsgMouse*>(pMessage), pMessageForm);
250 break;
251 }
252 case CFWL_MessageType::MouseWheel: {
253 bRet = DoWheel(static_cast<CFWL_MsgMouseWheel*>(pMessage), pMessageForm);
254 break;
255 }
256 default: {
257 bRet = true;
258 break;
259 }
260 }
261 if (bRet) {
262 if (IFWL_WidgetDelegate* pDelegate =
263 pMessage->m_pDstTarget->GetDelegate()) {
264 pDelegate->OnProcessMessage(pMessage);
265 }
266 }
267 return bRet;
268 }
269
270 bool CFWL_NoteDriver::DoSetFocus(CFWL_MsgSetFocus* pMsg,
271 IFWL_Widget* pMessageForm) {
272 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); 289 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
273 if (pWidgetMgr->IsFormDisabled()) { 290 if (pWidgetMgr->IsFormDisabled()) {
274 m_pFocus = pMsg->m_pDstTarget; 291 if (m_pFocus == pMessage->m_pDstTarget)
292 m_pFocus = nullptr;
275 return true; 293 return true;
276 } 294 }
277 IFWL_Widget* pWidget = pMsg->m_pDstTarget; 295
278 if (pWidget) { 296 IFWL_Form* pForm = static_cast<IFWL_Form*>(pMessage->m_pDstTarget);
279 IFWL_Form* pForm = static_cast<IFWL_Form*>(pWidget); 297 if (!pForm)
280 IFWL_Widget* pSubFocus = pForm->GetSubFocus(); 298 return false;
281 if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) { 299
282 pMsg->m_pDstTarget = pSubFocus; 300 IFWL_Widget* pSubFocus = pForm->GetSubFocus();
283 if (m_pFocus != pMsg->m_pDstTarget) { 301 if (pSubFocus && (pSubFocus->GetStates() & FWL_WGTSTATE_Focused)) {
284 m_pFocus = pMsg->m_pDstTarget; 302 pMessage->m_pDstTarget = pSubFocus;
285 return true; 303 if (m_pFocus == pMessage->m_pDstTarget) {
286 } 304 m_pFocus = nullptr;
305 return true;
287 } 306 }
288 } 307 }
289 return false; 308 return false;
290 } 309 }
291 bool CFWL_NoteDriver::DoKillFocus(CFWL_MsgKillFocus* pMsg, 310
292 IFWL_Widget* pMessageForm) { 311 bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, IFWL_Widget* pMessageForm) {
293 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); 312 CFWL_MsgKey* pMsg = static_cast<CFWL_MsgKey*>(pMessage);
294 if (pWidgetMgr->IsFormDisabled()) {
295 if (m_pFocus == pMsg->m_pDstTarget) {
296 m_pFocus = nullptr;
297 }
298 return true;
299 }
300 IFWL_Form* pForm = static_cast<IFWL_Form*>(pMsg->m_pDstTarget);
301 if (pForm) {
302 IFWL_Widget* pSubFocus = pForm->GetSubFocus();
303 if (pSubFocus && (pSubFocus->GetStates() & FWL_WGTSTATE_Focused)) {
304 pMsg->m_pDstTarget = pSubFocus;
305 if (m_pFocus == pMsg->m_pDstTarget) {
306 m_pFocus = nullptr;
307 return true;
308 }
309 }
310 }
311 return false;
312 }
313 bool CFWL_NoteDriver::DoKey(CFWL_MsgKey* pMsg, IFWL_Widget* pMessageForm) {
314 #if (_FX_OS_ != _FX_MACOSX_) 313 #if (_FX_OS_ != _FX_MACOSX_)
315 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && 314 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown &&
316 pMsg->m_dwKeyCode == FWL_VKEY_Tab) { 315 pMsg->m_dwKeyCode == FWL_VKEY_Tab) {
317 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); 316 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
318 IFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget); 317 IFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget);
319 IFWL_Widget* pFocus = m_pFocus; 318 IFWL_Widget* pFocus = m_pFocus;
320 if (m_pFocus) { 319 if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm)
321 if (pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) 320 pFocus = nullptr;
322 pFocus = nullptr; 321
323 }
324 bool bFind = false; 322 bool bFind = false;
325 IFWL_Widget* pNextTabStop = pWidgetMgr->NextTab(pForm, pFocus, bFind); 323 IFWL_Widget* pNextTabStop = pWidgetMgr->NextTab(pForm, pFocus, bFind);
326 if (!pNextTabStop) { 324 if (!pNextTabStop) {
327 bFind = false; 325 bFind = false;
328 pNextTabStop = pWidgetMgr->NextTab(pForm, nullptr, bFind); 326 pNextTabStop = pWidgetMgr->NextTab(pForm, nullptr, bFind);
329 } 327 }
330 if (pNextTabStop == pFocus) { 328 if (pNextTabStop == pFocus)
331 return true; 329 return true;
332 } 330 if (pNextTabStop)
333 if (pNextTabStop) {
334 SetFocus(pNextTabStop); 331 SetFocus(pNextTabStop);
335 }
336 return true; 332 return true;
337 } 333 }
338 #endif 334 #endif
335
339 if (!m_pFocus) { 336 if (!m_pFocus) {
340 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && 337 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown &&
341 pMsg->m_dwKeyCode == FWL_VKEY_Return) { 338 pMsg->m_dwKeyCode == FWL_VKEY_Return) {
342 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); 339 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
343 IFWL_Widget* defButton = pWidgetMgr->GetDefaultButton(pMessageForm); 340 IFWL_Widget* defButton = pWidgetMgr->GetDefaultButton(pMessageForm);
344 if (defButton) { 341 if (defButton) {
345 pMsg->m_pDstTarget = defButton; 342 pMsg->m_pDstTarget = defButton;
346 return true; 343 return true;
347 } 344 }
348 } 345 }
349 return false; 346 return false;
350 } 347 }
351 pMsg->m_pDstTarget = m_pFocus; 348 pMsg->m_pDstTarget = m_pFocus;
352 return true; 349 return true;
353 } 350 }
354 bool CFWL_NoteDriver::DoMouse(CFWL_MsgMouse* pMsg, IFWL_Widget* pMessageForm) { 351
352 bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage,
353 IFWL_Widget* pMessageForm) {
354 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
355 if (pMsg->m_dwCmd == FWL_MouseCommand::Leave || 355 if (pMsg->m_dwCmd == FWL_MouseCommand::Leave ||
356 pMsg->m_dwCmd == FWL_MouseCommand::Hover || 356 pMsg->m_dwCmd == FWL_MouseCommand::Hover ||
357 pMsg->m_dwCmd == FWL_MouseCommand::Enter) { 357 pMsg->m_dwCmd == FWL_MouseCommand::Enter) {
358 return !!pMsg->m_pDstTarget; 358 return !!pMsg->m_pDstTarget;
359 } 359 }
360 if (pMsg->m_pDstTarget != pMessageForm) { 360 if (pMsg->m_pDstTarget != pMessageForm)
361 pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy); 361 pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy);
362 } 362 if (!DoMouseEx(pMsg, pMessageForm))
363 if (!DoMouseEx(pMsg, pMessageForm)) {
364 pMsg->m_pDstTarget = pMessageForm; 363 pMsg->m_pDstTarget = pMessageForm;
365 }
366 return true; 364 return true;
367 } 365 }
368 bool CFWL_NoteDriver::DoWheel(CFWL_MsgMouseWheel* pMsg, 366
367 bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage,
369 IFWL_Widget* pMessageForm) { 368 IFWL_Widget* pMessageForm) {
370 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); 369 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
371 if (!pWidgetMgr) 370 if (!pWidgetMgr)
372 return false; 371 return false;
373 372
373 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage);
374 IFWL_Widget* pDst = 374 IFWL_Widget* pDst =
375 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); 375 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy);
376 if (!pDst) 376 if (!pDst)
377 return false; 377 return false;
378 378
379 pMessageForm->TransformTo(pDst, pMsg->m_fx, pMsg->m_fy); 379 pMessageForm->TransformTo(pDst, pMsg->m_fx, pMsg->m_fy);
380 pMsg->m_pDstTarget = pDst; 380 pMsg->m_pDstTarget = pDst;
381 return true; 381 return true;
382 } 382 }
383 383
384 bool CFWL_NoteDriver::DoMouseEx(CFWL_MsgMouse* pMsg, 384 bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage,
385 IFWL_Widget* pMessageForm) { 385 IFWL_Widget* pMessageForm) {
386 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); 386 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
387 if (!pWidgetMgr) 387 if (!pWidgetMgr)
388 return false; 388 return false;
389 IFWL_Widget* pTarget = nullptr; 389 IFWL_Widget* pTarget = nullptr;
390 if (m_pGrab) 390 if (m_pGrab)
391 pTarget = m_pGrab; 391 pTarget = m_pGrab;
392
393 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
392 if (!pTarget) { 394 if (!pTarget) {
393 pTarget = 395 pTarget =
394 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); 396 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy);
395 } 397 }
396 if (pTarget) { 398 if (pTarget) {
397 if (pMessageForm != pTarget) { 399 if (pMessageForm != pTarget)
398 pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy); 400 pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy);
399 }
400 } 401 }
401 if (!pTarget) 402 if (!pTarget)
402 return false; 403 return false;
404
403 pMsg->m_pDstTarget = pTarget; 405 pMsg->m_pDstTarget = pTarget;
404 return true; 406 return true;
405 } 407 }
406 void CFWL_NoteDriver::MouseSecondary(CFWL_MsgMouse* pMsg) { 408
407 IFWL_Widget* pTarget = pMsg->m_pDstTarget; 409 void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) {
408 if (pTarget == m_pHover) { 410 IFWL_Widget* pTarget = pMessage->m_pDstTarget;
411 if (pTarget == m_pHover)
409 return; 412 return;
410 } 413
414 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
411 if (m_pHover) { 415 if (m_pHover) {
412 CFWL_MsgMouse msLeave; 416 CFWL_MsgMouse msLeave;
413 msLeave.m_pDstTarget = m_pHover; 417 msLeave.m_pDstTarget = m_pHover;
414 msLeave.m_fx = pMsg->m_fx; 418 msLeave.m_fx = pMsg->m_fx;
415 msLeave.m_fy = pMsg->m_fy; 419 msLeave.m_fy = pMsg->m_fy;
416 pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy); 420 pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy);
421
417 msLeave.m_dwFlags = 0; 422 msLeave.m_dwFlags = 0;
418 msLeave.m_dwCmd = FWL_MouseCommand::Leave; 423 msLeave.m_dwCmd = FWL_MouseCommand::Leave;
419 DispatchMessage(&msLeave, nullptr); 424 DispatchMessage(&msLeave, nullptr);
420 } 425 }
421 if (pTarget->GetClassID() == FWL_Type::Form) { 426 if (pTarget->GetClassID() == FWL_Type::Form) {
422 m_pHover = nullptr; 427 m_pHover = nullptr;
423 return; 428 return;
424 } 429 }
425 m_pHover = pTarget; 430 m_pHover = pTarget;
431
426 CFWL_MsgMouse msHover; 432 CFWL_MsgMouse msHover;
427 msHover.m_pDstTarget = pTarget; 433 msHover.m_pDstTarget = pTarget;
428 msHover.m_fx = pMsg->m_fx; 434 msHover.m_fx = pMsg->m_fx;
429 msHover.m_fy = pMsg->m_fy; 435 msHover.m_fy = pMsg->m_fy;
430 msHover.m_dwFlags = 0; 436 msHover.m_dwFlags = 0;
431 msHover.m_dwCmd = FWL_MouseCommand::Hover; 437 msHover.m_dwCmd = FWL_MouseCommand::Hover;
432 DispatchMessage(&msHover, nullptr); 438 DispatchMessage(&msHover, nullptr);
433 } 439 }
440
434 bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { 441 bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) {
435 int32_t iCount = m_noteLoopQueue.GetSize(); 442 for (int32_t i = 0; i < m_noteLoopQueue.GetSize(); i++) {
436 for (int32_t i = 0; i < iCount; i++) { 443 CFWL_NoteLoop* pNoteLoop = m_noteLoopQueue[i];
437 CFWL_NoteLoop* pNoteLoop = static_cast<CFWL_NoteLoop*>(m_noteLoopQueue[i]);
438 IFWL_Widget* pForm = pNoteLoop->GetForm(); 444 IFWL_Widget* pForm = pNoteLoop->GetForm();
439 if (pForm && (pForm == pMessage->m_pDstTarget)) 445 if (pForm && (pForm == pMessage->m_pDstTarget))
440 return true; 446 return true;
441 } 447 }
442 iCount = m_forms.GetSize(); 448
443 for (int32_t j = 0; j < iCount; j++) { 449 for (int32_t j = 0; j < m_forms.GetSize(); j++) {
444 IFWL_Form* pForm = static_cast<IFWL_Form*>(m_forms[j]); 450 IFWL_Form* pForm = static_cast<IFWL_Form*>(m_forms[j]);
445 if (pForm == pMessage->m_pDstTarget) 451 if (pForm == pMessage->m_pDstTarget)
446 return true; 452 return true;
447 } 453 }
448 return false; 454 return false;
449 } 455 }
450 456
451 IFWL_Widget* CFWL_NoteDriver::GetMessageForm(IFWL_Widget* pDstTarget) { 457 IFWL_Widget* CFWL_NoteDriver::GetMessageForm(IFWL_Widget* pDstTarget) {
452 int32_t iTrackLoop = m_noteLoopQueue.GetSize(); 458 int32_t iTrackLoop = m_noteLoopQueue.GetSize();
453 if (iTrackLoop <= 0) 459 if (iTrackLoop <= 0)
454 return nullptr; 460 return nullptr;
461
455 IFWL_Widget* pMessageForm = nullptr; 462 IFWL_Widget* pMessageForm = nullptr;
456 if (iTrackLoop > 1) { 463 if (iTrackLoop > 1)
457 CFWL_NoteLoop* pNootLoop = 464 pMessageForm = m_noteLoopQueue[iTrackLoop - 1]->GetForm();
458 static_cast<CFWL_NoteLoop*>(m_noteLoopQueue[iTrackLoop - 1]); 465 else if (m_forms.Find(pDstTarget) < 0)
459 pMessageForm = pNootLoop->GetForm();
460 } else if (m_forms.Find(pDstTarget) < 0) {
461 pMessageForm = pDstTarget; 466 pMessageForm = pDstTarget;
462 }
463 if (!pMessageForm && pDstTarget) { 467 if (!pMessageForm && pDstTarget) {
464 CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr(); 468 CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr();
465 if (!pWidgetMgr) 469 if (!pWidgetMgr)
466 return nullptr; 470 return nullptr;
467 pMessageForm = pWidgetMgr->GetSystemFormWidget(pDstTarget); 471 pMessageForm = pWidgetMgr->GetSystemFormWidget(pDstTarget);
468 } 472 }
469 return pMessageForm; 473 return pMessageForm;
470 } 474 }
471 475
472 void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { 476 void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) {
473 auto it = m_eventTargets.begin(); 477 auto it = m_eventTargets.begin();
474 while (it != m_eventTargets.end()) { 478 while (it != m_eventTargets.end()) {
475 auto old = it++; 479 auto old = it++;
476 if (old->second && (bRemoveAll || old->second->IsInvalid())) { 480 if (old->second && (bRemoveAll || old->second->IsInvalid())) {
477 delete old->second; 481 delete old->second;
478 m_eventTargets.erase(old); 482 m_eventTargets.erase(old);
479 } 483 }
480 } 484 }
481 } 485 }
482 486
483 CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener) 487 CFWL_EventTarget::CFWL_EventTarget(IFWL_Widget* pListener)
484 : m_pListener(pListener), m_bInvalid(false) {} 488 : m_pListener(pListener), m_bInvalid(false) {}
489
485 CFWL_EventTarget::~CFWL_EventTarget() { 490 CFWL_EventTarget::~CFWL_EventTarget() {
486 m_eventSources.RemoveAll(); 491 m_eventSources.RemoveAll();
487 } 492 }
488 493
489 int32_t CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource, 494 int32_t CFWL_EventTarget::SetEventSource(IFWL_Widget* pSource,
490 uint32_t dwFilter) { 495 uint32_t dwFilter) {
491 if (pSource) { 496 if (pSource) {
492 m_eventSources.SetAt(pSource, dwFilter); 497 m_eventSources.SetAt(pSource, dwFilter);
493 return m_eventSources.GetCount(); 498 return m_eventSources.GetCount();
494 } 499 }
495 return 1; 500 return 1;
496 } 501 }
497 502
498 bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) { 503 bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) {
499 IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate(); 504 IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate();
500 if (!pDelegate) 505 if (!pDelegate)
501 return false; 506 return false;
502 if (m_eventSources.GetCount() == 0) { 507 if (m_eventSources.GetCount() == 0) {
503 pDelegate->OnProcessEvent(pEvent); 508 pDelegate->OnProcessEvent(pEvent);
504 return true; 509 return true;
505 } 510 }
511
506 FX_POSITION pos = m_eventSources.GetStartPosition(); 512 FX_POSITION pos = m_eventSources.GetStartPosition();
507 while (pos) { 513 while (pos) {
508 IFWL_Widget* pSource = nullptr; 514 IFWL_Widget* pSource = nullptr;
509 uint32_t dwFilter = 0; 515 uint32_t dwFilter = 0;
510 m_eventSources.GetNextAssoc(pos, (void*&)pSource, dwFilter); 516 m_eventSources.GetNextAssoc(pos, (void*&)pSource, dwFilter);
511 if (pSource == pEvent->m_pSrcTarget) { 517 if (pSource == pEvent->m_pSrcTarget) {
512 if (IsFilterEvent(pEvent, dwFilter)) { 518 if (IsFilterEvent(pEvent, dwFilter)) {
513 pDelegate->OnProcessEvent(pEvent); 519 pDelegate->OnProcessEvent(pEvent);
514 return true; 520 return true;
515 } 521 }
(...skipping 18 matching lines...) Expand all
534 case CFWL_EventType::KillFocus: 540 case CFWL_EventType::KillFocus:
535 return !!(dwFilter & FWL_EVENT_FOCUSCHANGED_MASK); 541 return !!(dwFilter & FWL_EVENT_FOCUSCHANGED_MASK);
536 case CFWL_EventType::Close: 542 case CFWL_EventType::Close:
537 return !!(dwFilter & FWL_EVENT_CLOSE_MASK); 543 return !!(dwFilter & FWL_EVENT_CLOSE_MASK);
538 case CFWL_EventType::SizeChanged: 544 case CFWL_EventType::SizeChanged:
539 return !!(dwFilter & FWL_EVENT_SIZECHANGED_MASK); 545 return !!(dwFilter & FWL_EVENT_SIZECHANGED_MASK);
540 default: 546 default:
541 return !!(dwFilter & FWL_EVENT_CONTROL_MASK); 547 return !!(dwFilter & FWL_EVENT_CONTROL_MASK);
542 } 548 }
543 } 549 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/fwl_noteimp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698