OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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) |
Lei Zhang
2016/09/27 20:45:03
Is this missing an '!' ?
Tom Sepez
2016/09/27 20:49:32
yikes. done.
| |
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 if (pFXAnnot) { |
387 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); | 385 if (pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFXAnnot, nFlag, point)) |
Lei Zhang
2016/09/27 20:45:03
Combine the 2 if statements?
Tom Sepez
2016/09/27 20:49:31
Done.
| |
388 return bRet; | 386 return TRUE; |
387 } | |
388 return FALSE; | |
389 } | 389 } |
390 | 390 |
391 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) { | 391 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CFX_FloatPoint& point, int nFlag) { |
392 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); | 392 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); |
393 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 393 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
394 if (CPDFSDK_Annot* pFXAnnot = GetFXAnnotAtPoint(point.x, point.y)) { | 394 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXAnnotAtPoint(point.x, point.y)); |
395 if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { | 395 if (pFXAnnot) { |
396 if (m_pCaptureWidget && m_pCaptureWidget != pFXAnnot) { | |
396 m_bExitWidget = TRUE; | 397 m_bExitWidget = TRUE; |
397 m_bEnterWidget = FALSE; | 398 m_bEnterWidget = FALSE; |
398 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); | 399 pAnnotHandlerMgr->Annot_OnMouseExit(this, &m_pCaptureWidget, nFlag); |
399 } | 400 } |
400 m_CaptureWidget = pFXAnnot; | 401 m_pCaptureWidget.Reset(pFXAnnot.Get()); |
401 m_bOnWidget = TRUE; | 402 m_bOnWidget = TRUE; |
402 if (!m_bEnterWidget) { | 403 if (!m_bEnterWidget) { |
403 m_bEnterWidget = TRUE; | 404 m_bEnterWidget = TRUE; |
404 m_bExitWidget = FALSE; | 405 m_bExitWidget = FALSE; |
405 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); | 406 pAnnotHandlerMgr->Annot_OnMouseEnter(this, &pFXAnnot, nFlag); |
406 } | 407 } |
407 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); | 408 pAnnotHandlerMgr->Annot_OnMouseMove(this, &pFXAnnot, nFlag, point); |
408 return TRUE; | 409 return TRUE; |
409 } | 410 } |
410 if (m_bOnWidget) { | 411 if (m_bOnWidget) { |
411 m_bOnWidget = FALSE; | 412 m_bOnWidget = FALSE; |
412 m_bExitWidget = TRUE; | 413 m_bExitWidget = TRUE; |
413 m_bEnterWidget = FALSE; | 414 m_bEnterWidget = FALSE; |
414 if (m_CaptureWidget) { | 415 if (m_pCaptureWidget) { |
415 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); | 416 pAnnotHandlerMgr->Annot_OnMouseExit(this, &m_pCaptureWidget, nFlag); |
416 m_CaptureWidget = nullptr; | 417 m_pCaptureWidget.Reset(); |
417 } | 418 } |
418 } | 419 } |
419 return FALSE; | 420 return FALSE; |
420 } | 421 } |
421 | 422 |
422 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, | 423 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, |
423 double deltaY, | 424 double deltaY, |
424 const CFX_FloatPoint& point, | 425 const CFX_FloatPoint& point, |
425 int nFlag) { | 426 int nFlag) { |
426 if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { | 427 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); |
427 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); | 428 if (!pAnnot) |
428 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 429 return FALSE; |
429 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, | 430 |
430 (int)deltaY, point); | 431 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); |
431 } | 432 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
432 return FALSE; | 433 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, (int)deltaY, |
434 point); | |
433 } | 435 } |
434 | 436 |
435 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) { | 437 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) { |
436 if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { | 438 if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
437 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); | 439 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); |
438 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 440 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
439 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); | 441 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
440 } | 442 } |
441 | 443 |
442 return FALSE; | 444 return FALSE; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 continue; | 506 continue; |
505 m_fxAnnotArray.push_back(pAnnot); | 507 m_fxAnnotArray.push_back(pAnnot); |
506 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | 508 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
507 } | 509 } |
508 | 510 |
509 SetLock(FALSE); | 511 SetLock(FALSE); |
510 } | 512 } |
511 | 513 |
512 void CPDFSDK_PageView::ClearFXAnnots() { | 514 void CPDFSDK_PageView::ClearFXAnnots() { |
513 SetLock(TRUE); | 515 SetLock(TRUE); |
514 if (m_pSDKDoc && GetFocusAnnot()) | 516 if (m_pSDKDoc && GetFocusAnnot()) { |
515 m_pSDKDoc->SetFocusAnnot(nullptr); | 517 CPDFSDK_Annot::ObservedPtr pNull; |
516 m_CaptureWidget = nullptr; | 518 m_pSDKDoc->SetFocusAnnot(&pNull); |
519 } | |
520 m_pCaptureWidget.Reset(); | |
517 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) | 521 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
518 m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); | 522 m_pSDKDoc->GetEnv()->GetAnnotHandlerMgr()->ReleaseAnnot(pAnnot); |
519 m_fxAnnotArray.clear(); | 523 m_fxAnnotArray.clear(); |
520 m_pAnnotList.reset(); | 524 m_pAnnotList.reset(); |
521 SetLock(FALSE); | 525 SetLock(FALSE); |
522 } | 526 } |
523 | 527 |
524 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { | 528 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { |
525 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); | 529 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); |
526 for (const auto& rc : rects) | 530 for (const auto& rc : rects) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 return pAnnot; | 582 return pAnnot; |
579 } | 583 } |
580 return nullptr; | 584 return nullptr; |
581 } | 585 } |
582 | 586 |
583 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { | 587 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
584 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; | 588 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; |
585 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | 589 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
586 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; | 590 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
587 } | 591 } |
OLD | NEW |