| 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/cfwl_notedriver.h" | 7 #include "xfa/fwl/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_app.h" | 14 #include "xfa/fwl/cfwl_app.h" |
| 15 #include "xfa/fwl/core/cfwl_eventtarget.h" | 15 #include "xfa/fwl/cfwl_eventtarget.h" |
| 16 #include "xfa/fwl/core/cfwl_form.h" | 16 #include "xfa/fwl/cfwl_form.h" |
| 17 #include "xfa/fwl/core/cfwl_msgkey.h" | 17 #include "xfa/fwl/cfwl_messagekey.h" |
| 18 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | 18 #include "xfa/fwl/cfwl_messagekillfocus.h" |
| 19 #include "xfa/fwl/core/cfwl_msgmouse.h" | 19 #include "xfa/fwl/cfwl_messagemouse.h" |
| 20 #include "xfa/fwl/core/cfwl_msgmousewheel.h" | 20 #include "xfa/fwl/cfwl_messagemousewheel.h" |
| 21 #include "xfa/fwl/core/cfwl_msgsetfocus.h" | 21 #include "xfa/fwl/cfwl_messagesetfocus.h" |
| 22 #include "xfa/fwl/core/cfwl_noteloop.h" | 22 #include "xfa/fwl/cfwl_noteloop.h" |
| 23 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 23 #include "xfa/fwl/cfwl_widgetmgr.h" |
| 24 | 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() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) { | 87 bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) { |
| 88 if (m_pFocus == pFocus) | 88 if (m_pFocus == pFocus) |
| 89 return true; | 89 return true; |
| 90 | 90 |
| 91 CFWL_Widget* pPrev = m_pFocus; | 91 CFWL_Widget* pPrev = m_pFocus; |
| 92 m_pFocus = pFocus; | 92 m_pFocus = pFocus; |
| 93 if (pPrev) { | 93 if (pPrev) { |
| 94 if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) { | 94 if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) { |
| 95 CFWL_MsgKillFocus ms(pPrev, pPrev); | 95 CFWL_MessageKillFocus ms(pPrev, pPrev); |
| 96 pDelegate->OnProcessMessage(&ms); | 96 pDelegate->OnProcessMessage(&ms); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 if (pFocus) { | 99 if (pFocus) { |
| 100 CFWL_Widget* pWidget = | 100 CFWL_Widget* pWidget = |
| 101 pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus); | 101 pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus); |
| 102 CFWL_Form* pForm = static_cast<CFWL_Form*>(pWidget); | 102 CFWL_Form* pForm = static_cast<CFWL_Form*>(pWidget); |
| 103 if (pForm) | 103 if (pForm) |
| 104 pForm->SetSubFocus(pFocus); | 104 pForm->SetSubFocus(pFocus); |
| 105 | 105 |
| 106 if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) { | 106 if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) { |
| 107 CFWL_MsgSetFocus ms(nullptr, pFocus); | 107 CFWL_MessageSetFocus ms(nullptr, pFocus); |
| 108 pDelegate->OnProcessMessage(&ms); | 108 pDelegate->OnProcessMessage(&ms); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 return true; | 111 return true; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void CFWL_NoteDriver::Run() { | 114 void CFWL_NoteDriver::Run() { |
| 115 #if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \ | 115 #if (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_WIN32_DESKTOP_ || \ |
| 116 _FX_OS_ == _FX_WIN64_) | 116 _FX_OS_ == _FX_WIN64_) |
| 117 for (;;) { | 117 for (;;) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 pMessage->m_pDstTarget = pSubFocus; | 299 pMessage->m_pDstTarget = pSubFocus; |
| 300 if (m_pFocus == pMessage->m_pDstTarget) { | 300 if (m_pFocus == pMessage->m_pDstTarget) { |
| 301 m_pFocus = nullptr; | 301 m_pFocus = nullptr; |
| 302 return true; | 302 return true; |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 return false; | 305 return false; |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) { | 308 bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) { |
| 309 CFWL_MsgKey* pMsg = static_cast<CFWL_MsgKey*>(pMessage); | 309 CFWL_MessageKey* pMsg = static_cast<CFWL_MessageKey*>(pMessage); |
| 310 #if (_FX_OS_ != _FX_MACOSX_) | 310 #if (_FX_OS_ != _FX_MACOSX_) |
| 311 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && | 311 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown && |
| 312 pMsg->m_dwKeyCode == FWL_VKEY_Tab) { | 312 pMsg->m_dwKeyCode == FWL_VKEY_Tab) { |
| 313 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); | 313 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); |
| 314 CFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget); | 314 CFWL_Widget* pForm = GetMessageForm(pMsg->m_pDstTarget); |
| 315 CFWL_Widget* pFocus = m_pFocus; | 315 CFWL_Widget* pFocus = m_pFocus; |
| 316 if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) | 316 if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus) != pForm) |
| 317 pFocus = nullptr; | 317 pFocus = nullptr; |
| 318 | 318 |
| 319 bool bFind = false; | 319 bool bFind = false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 return false; | 343 return false; |
| 344 } | 344 } |
| 345 pMsg->m_pDstTarget = m_pFocus; | 345 pMsg->m_pDstTarget = m_pFocus; |
| 346 return true; | 346 return true; |
| 347 } | 347 } |
| 348 | 348 |
| 349 bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage, | 349 bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage, |
| 350 CFWL_Widget* pMessageForm) { | 350 CFWL_Widget* pMessageForm) { |
| 351 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 351 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
| 352 if (pMsg->m_dwCmd == FWL_MouseCommand::Leave || | 352 if (pMsg->m_dwCmd == FWL_MouseCommand::Leave || |
| 353 pMsg->m_dwCmd == FWL_MouseCommand::Hover || | 353 pMsg->m_dwCmd == FWL_MouseCommand::Hover || |
| 354 pMsg->m_dwCmd == FWL_MouseCommand::Enter) { | 354 pMsg->m_dwCmd == FWL_MouseCommand::Enter) { |
| 355 return !!pMsg->m_pDstTarget; | 355 return !!pMsg->m_pDstTarget; |
| 356 } | 356 } |
| 357 if (pMsg->m_pDstTarget != pMessageForm) | 357 if (pMsg->m_pDstTarget != pMessageForm) |
| 358 pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy); | 358 pMsg->m_pDstTarget->TransformTo(pMessageForm, pMsg->m_fx, pMsg->m_fy); |
| 359 if (!DoMouseEx(pMsg, pMessageForm)) | 359 if (!DoMouseEx(pMsg, pMessageForm)) |
| 360 pMsg->m_pDstTarget = pMessageForm; | 360 pMsg->m_pDstTarget = pMessageForm; |
| 361 return true; | 361 return true; |
| 362 } | 362 } |
| 363 | 363 |
| 364 bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage, | 364 bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage, |
| 365 CFWL_Widget* pMessageForm) { | 365 CFWL_Widget* pMessageForm) { |
| 366 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); | 366 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); |
| 367 if (!pWidgetMgr) | 367 if (!pWidgetMgr) |
| 368 return false; | 368 return false; |
| 369 | 369 |
| 370 CFWL_MsgMouseWheel* pMsg = static_cast<CFWL_MsgMouseWheel*>(pMessage); | 370 CFWL_MessageMouseWheel* pMsg = static_cast<CFWL_MessageMouseWheel*>(pMessage); |
| 371 CFWL_Widget* pDst = | 371 CFWL_Widget* pDst = |
| 372 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); | 372 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); |
| 373 if (!pDst) | 373 if (!pDst) |
| 374 return false; | 374 return false; |
| 375 | 375 |
| 376 pMessageForm->TransformTo(pDst, pMsg->m_fx, pMsg->m_fy); | 376 pMessageForm->TransformTo(pDst, pMsg->m_fx, pMsg->m_fy); |
| 377 pMsg->m_pDstTarget = pDst; | 377 pMsg->m_pDstTarget = pDst; |
| 378 return true; | 378 return true; |
| 379 } | 379 } |
| 380 | 380 |
| 381 bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage, | 381 bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage, |
| 382 CFWL_Widget* pMessageForm) { | 382 CFWL_Widget* pMessageForm) { |
| 383 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); | 383 CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr(); |
| 384 if (!pWidgetMgr) | 384 if (!pWidgetMgr) |
| 385 return false; | 385 return false; |
| 386 CFWL_Widget* pTarget = nullptr; | 386 CFWL_Widget* pTarget = nullptr; |
| 387 if (m_pGrab) | 387 if (m_pGrab) |
| 388 pTarget = m_pGrab; | 388 pTarget = m_pGrab; |
| 389 | 389 |
| 390 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 390 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
| 391 if (!pTarget) { | 391 if (!pTarget) { |
| 392 pTarget = | 392 pTarget = |
| 393 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); | 393 pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_fx, pMsg->m_fy); |
| 394 } | 394 } |
| 395 if (pTarget) { | 395 if (pTarget) { |
| 396 if (pMessageForm != pTarget) | 396 if (pMessageForm != pTarget) |
| 397 pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy); | 397 pMessageForm->TransformTo(pTarget, pMsg->m_fx, pMsg->m_fy); |
| 398 } | 398 } |
| 399 if (!pTarget) | 399 if (!pTarget) |
| 400 return false; | 400 return false; |
| 401 | 401 |
| 402 pMsg->m_pDstTarget = pTarget; | 402 pMsg->m_pDstTarget = pTarget; |
| 403 return true; | 403 return true; |
| 404 } | 404 } |
| 405 | 405 |
| 406 void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { | 406 void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) { |
| 407 CFWL_Widget* pTarget = pMessage->m_pDstTarget; | 407 CFWL_Widget* pTarget = pMessage->m_pDstTarget; |
| 408 if (pTarget == m_pHover) | 408 if (pTarget == m_pHover) |
| 409 return; | 409 return; |
| 410 | 410 |
| 411 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 411 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
| 412 if (m_pHover) { | 412 if (m_pHover) { |
| 413 CFWL_MsgMouse msLeave(nullptr, m_pHover); | 413 CFWL_MessageMouse msLeave(nullptr, m_pHover); |
| 414 msLeave.m_fx = pMsg->m_fx; | 414 msLeave.m_fx = pMsg->m_fx; |
| 415 msLeave.m_fy = pMsg->m_fy; | 415 msLeave.m_fy = pMsg->m_fy; |
| 416 pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy); | 416 pTarget->TransformTo(m_pHover, msLeave.m_fx, msLeave.m_fy); |
| 417 | 417 |
| 418 msLeave.m_dwFlags = 0; | 418 msLeave.m_dwFlags = 0; |
| 419 msLeave.m_dwCmd = FWL_MouseCommand::Leave; | 419 msLeave.m_dwCmd = FWL_MouseCommand::Leave; |
| 420 DispatchMessage(&msLeave, nullptr); | 420 DispatchMessage(&msLeave, nullptr); |
| 421 } | 421 } |
| 422 if (pTarget->GetClassID() == FWL_Type::Form) { | 422 if (pTarget->GetClassID() == FWL_Type::Form) { |
| 423 m_pHover = nullptr; | 423 m_pHover = nullptr; |
| 424 return; | 424 return; |
| 425 } | 425 } |
| 426 m_pHover = pTarget; | 426 m_pHover = pTarget; |
| 427 | 427 |
| 428 CFWL_MsgMouse msHover(nullptr, pTarget); | 428 CFWL_MessageMouse msHover(nullptr, pTarget); |
| 429 msHover.m_fx = pMsg->m_fx; | 429 msHover.m_fx = pMsg->m_fx; |
| 430 msHover.m_fy = pMsg->m_fy; | 430 msHover.m_fy = pMsg->m_fy; |
| 431 msHover.m_dwFlags = 0; | 431 msHover.m_dwFlags = 0; |
| 432 msHover.m_dwCmd = FWL_MouseCommand::Hover; | 432 msHover.m_dwCmd = FWL_MouseCommand::Hover; |
| 433 DispatchMessage(&msHover, nullptr); | 433 DispatchMessage(&msHover, nullptr); |
| 434 } | 434 } |
| 435 | 435 |
| 436 bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { | 436 bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { |
| 437 for (int32_t i = 0; i < m_noteLoopQueue.GetSize(); i++) { | 437 for (int32_t i = 0; i < m_noteLoopQueue.GetSize(); i++) { |
| 438 CFWL_NoteLoop* pNoteLoop = m_noteLoopQueue[i]; | 438 CFWL_NoteLoop* pNoteLoop = m_noteLoopQueue[i]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { | 471 void CFWL_NoteDriver::ClearEventTargets(bool bRemoveAll) { |
| 472 auto it = m_eventTargets.begin(); | 472 auto it = m_eventTargets.begin(); |
| 473 while (it != m_eventTargets.end()) { | 473 while (it != m_eventTargets.end()) { |
| 474 auto old = it++; | 474 auto old = it++; |
| 475 if (old->second && (bRemoveAll || old->second->IsInvalid())) { | 475 if (old->second && (bRemoveAll || old->second->IsInvalid())) { |
| 476 delete old->second; | 476 delete old->second; |
| 477 m_eventTargets.erase(old); | 477 m_eventTargets.erase(old); |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 } | 480 } |
| OLD | NEW |