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 "fpdfsdk/include/fsdk_mgr.h" | 7 #include "fpdfsdk/include/fsdk_mgr.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { | 355 void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { |
356 auto it = m_pageMap.find(pUnderlyingPage); | 356 auto it = m_pageMap.find(pUnderlyingPage); |
357 if (it == m_pageMap.end()) | 357 if (it == m_pageMap.end()) |
358 return; | 358 return; |
359 | 359 |
360 CPDFSDK_PageView* pPageView = it->second; | 360 CPDFSDK_PageView* pPageView = it->second; |
361 if (pPageView->IsLocked()) | 361 if (pPageView->IsLocked()) |
362 return; | 362 return; |
363 | 363 |
| 364 // This must happen before we remove |pPageView| from the map because |
| 365 // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will |
| 366 // look for this page view in the map, if it doesn't find it a new one will |
| 367 // be created. We then have two page views pointing to the same page and |
| 368 // bad things happen. |
| 369 pPageView->KillFocusAnnotIfNeeded(); |
| 370 |
364 // Remove the page from the map to make sure we don't accidentally attempt | 371 // Remove the page from the map to make sure we don't accidentally attempt |
365 // to use the |pPageView| while we're cleaning it up. | 372 // to use the |pPageView| while we're cleaning it up. |
366 m_pageMap.erase(it); | 373 m_pageMap.erase(it); |
367 | 374 |
368 pPageView->KillFocusAnnotIfNeeded(); | |
369 delete pPageView; | 375 delete pPageView; |
370 } | 376 } |
371 | 377 |
372 UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { | 378 UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { |
373 return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); | 379 return UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); |
374 } | 380 } |
375 | 381 |
376 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { | 382 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { |
377 if (!m_pInterForm) | 383 if (!m_pInterForm) |
378 m_pInterForm.reset(new CPDFSDK_InterForm(this)); | 384 m_pInterForm.reset(new CPDFSDK_InterForm(this)); |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 return pAnnot; | 1034 return pAnnot; |
1029 } | 1035 } |
1030 return nullptr; | 1036 return nullptr; |
1031 } | 1037 } |
1032 | 1038 |
1033 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { | 1039 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
1034 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; | 1040 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; |
1035 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | 1041 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
1036 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; | 1042 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
1037 } | 1043 } |
OLD | NEW |