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

Side by Side Diff: fpdfsdk/cpdfsdk_pageview.cpp

Issue 2368403002: Watch destruction of widgets around OnAAction() method (Closed)
Patch Set: blown merge Created 4 years, 2 months 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 | « fpdfsdk/cpdfsdk_document.cpp ('k') | fpdfsdk/cpdfsdk_widgethandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "fpdfsdk/include/cpdfsdk_pageview.h" 7 #include "fpdfsdk/include/cpdfsdk_pageview.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
10 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" 10 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
(...skipping 11 matching lines...) Expand all
22 #include "xfa/fxfa/include/xfa_ffpageview.h" 22 #include "xfa/fxfa/include/xfa_ffpageview.h"
23 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" 23 #include "xfa/fxfa/include/xfa_ffwidgethandler.h"
24 #include "xfa/fxfa/include/xfa_rendercontext.h" 24 #include "xfa/fxfa/include/xfa_rendercontext.h"
25 #include "xfa/fxgraphics/include/cfx_graphics.h" 25 #include "xfa/fxgraphics/include/cfx_graphics.h"
26 #endif // PDF_ENABLE_XFA 26 #endif // PDF_ENABLE_XFA
27 27
28 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, 28 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,
29 UnderlyingPageType* page) 29 UnderlyingPageType* page)
30 : m_page(page), 30 : m_page(page),
31 m_pSDKDoc(pSDKDoc), 31 m_pSDKDoc(pSDKDoc),
32 m_CaptureWidget(nullptr),
33 #ifndef PDF_ENABLE_XFA 32 #ifndef PDF_ENABLE_XFA
34 m_bOwnsPage(false), 33 m_bOwnsPage(false),
35 #endif // PDF_ENABLE_XFA 34 #endif // PDF_ENABLE_XFA
36 m_bEnterWidget(FALSE), 35 m_bEnterWidget(FALSE),
37 m_bExitWidget(FALSE), 36 m_bExitWidget(FALSE),
38 m_bOnWidget(FALSE), 37 m_bOnWidget(FALSE),
39 m_bValid(FALSE), 38 m_bValid(FALSE),
40 m_bLocked(FALSE) { 39 m_bLocked(FALSE) {
41 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); 40 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
42 if (pInterForm) { 41 if (pInterForm) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (GetFocusAnnot() == pAnnot) 251 if (GetFocusAnnot() == pAnnot)
253 KillFocusAnnot(); 252 KillFocusAnnot();
254 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 253 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
255 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); 254 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
256 if (pAnnotHandler) 255 if (pAnnotHandler)
257 pAnnotHandler->ReleaseAnnot(pAnnot); 256 pAnnotHandler->ReleaseAnnot(pAnnot);
258 257
259 auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); 258 auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot);
260 if (it != m_fxAnnotArray.end()) 259 if (it != m_fxAnnotArray.end())
261 m_fxAnnotArray.erase(it); 260 m_fxAnnotArray.erase(it);
262 if (m_CaptureWidget == pAnnot) 261 if (m_pCaptureWidget.Get() == pAnnot)
263 m_CaptureWidget = nullptr; 262 m_pCaptureWidget.Reset();
264 263
265 return TRUE; 264 return TRUE;
266 #else // PDF_ENABLE_XFA 265 #else // PDF_ENABLE_XFA
267 return FALSE; 266 return FALSE;
268 #endif // PDF_ENABLE_XFA 267 #endif // PDF_ENABLE_XFA
269 } 268 }
270 269
271 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { 270 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() {
272 if (m_page) { 271 if (m_page) {
273 #ifdef PDF_ENABLE_XFA 272 #ifdef PDF_ENABLE_XFA
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { 310 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
312 if (pAnnot->GetXFAWidget() == hWidget) 311 if (pAnnot->GetXFAWidget() == hWidget)
313 return pAnnot; 312 return pAnnot;
314 } 313 }
315 return nullptr; 314 return nullptr;
316 } 315 }
317 #endif // PDF_ENABLE_XFA 316 #endif // PDF_ENABLE_XFA
318 317
319 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, 318 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point,
320 uint32_t nFlag) { 319 uint32_t nFlag) {
321 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 320 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y));
322 ASSERT(pEnv); 321 if (!pAnnot) {
323 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
324 if (!pFXAnnot) {
325 KillFocusAnnot(nFlag); 322 KillFocusAnnot(nFlag);
326 return FALSE; 323 return FALSE;
327 } 324 }
328 325
326 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
329 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 327 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
330 FX_BOOL bRet = 328 if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point))
331 pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); 329 return FALSE;
332 if (bRet) 330
333 SetFocusAnnot(pFXAnnot); 331 if (!pAnnot)
334 return bRet; 332 return FALSE;
333
334 SetFocusAnnot(&pAnnot);
335 return TRUE;
335 } 336 }
336 337
337 #ifdef PDF_ENABLE_XFA 338 #ifdef PDF_ENABLE_XFA
338 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, 339 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point,
339 uint32_t nFlag) { 340 uint32_t nFlag) {
340 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 341 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y));
341 ASSERT(pEnv); 342 if (!pAnnot)
342 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
343 ASSERT(pAnnotHandlerMgr);
344
345 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
346
347 if (!pFXAnnot)
348 return FALSE; 343 return FALSE;
349 344
350 if (pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point)) 345 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
351 SetFocusAnnot(pFXAnnot); 346 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
347 FX_BOOL ok =
348 pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point);
349 if (!pAnnot)
350 return FALSE;
351
352 if (ok)
353 SetFocusAnnot(&pAnnot);
352 354
353 return TRUE; 355 return TRUE;
354 } 356 }
355 357
356 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, 358 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point,
357 uint32_t nFlag) { 359 uint32_t nFlag) {
358 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 360 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
359 ASSERT(pEnv);
360 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 361 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
361 362 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y));
362 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
363
364 if (!pFXAnnot) 363 if (!pFXAnnot)
365 return FALSE; 364 return FALSE;
366 365
367 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point)) 366 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point))
368 SetFocusAnnot(pFXAnnot); 367 SetFocusAnnot(&pFXAnnot);
369 368
370 return TRUE; 369 return TRUE;
371 } 370 }
372 #endif // PDF_ENABLE_XFA 371 #endif // PDF_ENABLE_XFA
373 372
374 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, 373 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point,
375 uint32_t nFlag) { 374 uint32_t nFlag) {
376 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 375 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
377 ASSERT(pEnv);
378 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 376 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
379 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); 377 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y));
380 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); 378 CPDFSDK_Annot::ObservedPtr pFocusAnnot(GetFocusAnnot());
381 FX_BOOL bRet = FALSE;
382 if (pFocusAnnot && pFocusAnnot != pFXAnnot) { 379 if (pFocusAnnot && pFocusAnnot != pFXAnnot) {
383 // Last focus Annot gets a chance to handle the event. 380 // Last focus Annot gets a chance to handle the event.
384 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); 381 if (pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFocusAnnot, nFlag, point))
382 return TRUE;
385 } 383 }
386 if (pFXAnnot && !bRet) 384 return pFXAnnot &&
387 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); 385 pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFXAnnot, nFlag, point);
388 return bRet;
389 } 386 }
390 387
391 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) { 388 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) {
392 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 389 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
393 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 390 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
394 if (CPDFSDK_Annot* pFXAnnot = GetFXAnnotAtPoint(point.x, point.y)) { 391 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXAnnotAtPoint(point.x, point.y));
395 if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { 392 if (pFXAnnot) {
393 if (m_pCaptureWidget && m_pCaptureWidget != pFXAnnot) {
396 m_bExitWidget = TRUE; 394 m_bExitWidget = TRUE;
397 m_bEnterWidget = FALSE; 395 m_bEnterWidget = FALSE;
398 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); 396 pAnnotHandlerMgr->Annot_OnMouseExit(this, &m_pCaptureWidget, nFlag);
399 } 397 }
400 m_CaptureWidget = pFXAnnot; 398 m_pCaptureWidget.Reset(pFXAnnot.Get());
401 m_bOnWidget = TRUE; 399 m_bOnWidget = TRUE;
402 if (!m_bEnterWidget) { 400 if (!m_bEnterWidget) {
403 m_bEnterWidget = TRUE; 401 m_bEnterWidget = TRUE;
404 m_bExitWidget = FALSE; 402 m_bExitWidget = FALSE;
405 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); 403 pAnnotHandlerMgr->Annot_OnMouseEnter(this, &pFXAnnot, nFlag);
406 } 404 }
407 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); 405 pAnnotHandlerMgr->Annot_OnMouseMove(this, &pFXAnnot, nFlag, point);
408 return TRUE; 406 return TRUE;
409 } 407 }
410 if (m_bOnWidget) { 408 if (m_bOnWidget) {
411 m_bOnWidget = FALSE; 409 m_bOnWidget = FALSE;
412 m_bExitWidget = TRUE; 410 m_bExitWidget = TRUE;
413 m_bEnterWidget = FALSE; 411 m_bEnterWidget = FALSE;
414 if (m_CaptureWidget) { 412 if (m_pCaptureWidget) {
415 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); 413 pAnnotHandlerMgr->Annot_OnMouseExit(this, &m_pCaptureWidget, nFlag);
416 m_CaptureWidget = nullptr; 414 m_pCaptureWidget.Reset();
417 } 415 }
418 } 416 }
419 return FALSE; 417 return FALSE;
420 } 418 }
421 419
422 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, 420 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX,
423 double deltaY, 421 double deltaY,
424 const CFX_FloatPoint& point, 422 const CFX_FloatPoint& point,
425 int nFlag) { 423 int nFlag) {
426 if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { 424 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y));
427 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 425 if (!pAnnot)
428 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 426 return FALSE;
429 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, 427
430 (int)deltaY, point); 428 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
431 } 429 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
432 return FALSE; 430 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, (int)deltaY,
431 point);
433 } 432 }
434 433
435 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) { 434 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) {
436 if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { 435 if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) {
437 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 436 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
438 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 437 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
439 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); 438 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
440 } 439 }
441 440
442 return FALSE; 441 return FALSE;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 continue; 503 continue;
505 m_fxAnnotArray.push_back(pAnnot); 504 m_fxAnnotArray.push_back(pAnnot);
506 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); 505 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
507 } 506 }
508 507
509 SetLock(FALSE); 508 SetLock(FALSE);
510 } 509 }
511 510
512 void CPDFSDK_PageView::ClearFXAnnots() { 511 void CPDFSDK_PageView::ClearFXAnnots() {
513 SetLock(TRUE); 512 SetLock(TRUE);
514 if (m_pSDKDoc && GetFocusAnnot()) 513 if (m_pSDKDoc && GetFocusAnnot()) {
515 m_pSDKDoc->SetFocusAnnot(nullptr); 514 CPDFSDK_Annot::ObservedPtr pNull;
516 m_CaptureWidget = nullptr; 515 m_pSDKDoc->SetFocusAnnot(&pNull);
516 }
517 m_pCaptureWidget.Reset();
517 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) 518 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray)
518 m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); 519 m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot);
519 m_fxAnnotArray.clear(); 520 m_fxAnnotArray.clear();
520 m_pAnnotList.reset(); 521 m_pAnnotList.reset();
521 SetLock(FALSE); 522 SetLock(FALSE);
522 } 523 }
523 524
524 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { 525 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) {
525 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 526 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
526 for (const auto& rc : rects) 527 for (const auto& rc : rects)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return pAnnot; 579 return pAnnot;
579 } 580 }
580 return nullptr; 581 return nullptr;
581 } 582 }
582 583
583 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { 584 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const {
584 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; 585 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict;
585 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); 586 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument();
586 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; 587 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1;
587 } 588 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_document.cpp ('k') | fpdfsdk/cpdfsdk_widgethandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698