jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "fpdfsdk/include/cpdfsdk_annot.h" |
| 8 | |
| 9 | #include <algorithm> |
| 10 | |
| 11 | #include "fpdfsdk/include/fsdk_mgr.h" |
dsinclair | ce04a45 | 2016-09-07 05:46:55 -0700 | [diff] [blame^] | 12 | #include "third_party/base/stl_util.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 13 | |
| 14 | #ifdef PDF_ENABLE_XFA |
| 15 | #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| 16 | #endif // PDF_ENABLE_XFA |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | const float kMinWidth = 1.0f; |
| 21 | const float kMinHeight = 1.0f; |
| 22 | |
| 23 | } // namespace |
| 24 | |
dsinclair | ce04a45 | 2016-09-07 05:46:55 -0700 | [diff] [blame^] | 25 | CPDFSDK_Annot::Observer::Observer(CPDFSDK_Annot** pWatchedPtr) |
| 26 | : m_pWatchedPtr(pWatchedPtr) { |
| 27 | (*m_pWatchedPtr)->AddObserver(this); |
| 28 | } |
| 29 | |
| 30 | CPDFSDK_Annot::Observer::~Observer() { |
| 31 | if (m_pWatchedPtr) |
| 32 | (*m_pWatchedPtr)->RemoveObserver(this); |
| 33 | } |
| 34 | |
| 35 | void CPDFSDK_Annot::Observer::OnAnnotDestroyed() { |
| 36 | ASSERT(m_pWatchedPtr); |
| 37 | *m_pWatchedPtr = nullptr; |
| 38 | m_pWatchedPtr = nullptr; |
| 39 | } |
| 40 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 41 | CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) |
jaepark | d99a833 | 2016-08-25 13:02:39 -0700 | [diff] [blame] | 42 | : m_pPageView(pPageView), m_bSelected(FALSE) {} |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 43 | |
dsinclair | ce04a45 | 2016-09-07 05:46:55 -0700 | [diff] [blame^] | 44 | CPDFSDK_Annot::~CPDFSDK_Annot() { |
| 45 | for (auto* pObserver : m_Observers) |
| 46 | pObserver->OnAnnotDestroyed(); |
| 47 | } |
| 48 | |
| 49 | void CPDFSDK_Annot::AddObserver(Observer* pObserver) { |
| 50 | ASSERT(!pdfium::ContainsKey(m_Observers, pObserver)); |
| 51 | m_Observers.insert(pObserver); |
| 52 | } |
| 53 | |
| 54 | void CPDFSDK_Annot::RemoveObserver(Observer* pObserver) { |
| 55 | ASSERT(pdfium::ContainsKey(m_Observers, pObserver)); |
| 56 | m_Observers.erase(pObserver); |
| 57 | } |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 58 | |
| 59 | #ifdef PDF_ENABLE_XFA |
| 60 | |
| 61 | FX_BOOL CPDFSDK_Annot::IsXFAField() { |
| 62 | return FALSE; |
| 63 | } |
| 64 | |
| 65 | CXFA_FFWidget* CPDFSDK_Annot::GetXFAWidget() const { |
| 66 | return nullptr; |
| 67 | } |
| 68 | |
| 69 | CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() { |
| 70 | return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr; |
| 71 | } |
| 72 | |
| 73 | #endif // PDF_ENABLE_XFA |
| 74 | |
| 75 | FX_FLOAT CPDFSDK_Annot::GetMinWidth() const { |
| 76 | return kMinWidth; |
| 77 | } |
| 78 | |
| 79 | FX_FLOAT CPDFSDK_Annot::GetMinHeight() const { |
| 80 | return kMinHeight; |
| 81 | } |
| 82 | |
| 83 | int CPDFSDK_Annot::GetLayoutOrder() const { |
| 84 | return 5; |
| 85 | } |
| 86 | |
| 87 | CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot() const { |
| 88 | return nullptr; |
| 89 | } |
| 90 | |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 91 | CPDF_Annot::Subtype CPDFSDK_Annot::GetAnnotSubtype() const { |
| 92 | return CPDF_Annot::Subtype::UNKNOWN; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 93 | } |
| 94 | |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 95 | bool CPDFSDK_Annot::IsSignatureWidget() const { |
| 96 | return false; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | void CPDFSDK_Annot::SetRect(const CFX_FloatRect& rect) {} |
| 100 | |
| 101 | CFX_FloatRect CPDFSDK_Annot::GetRect() const { |
| 102 | return CFX_FloatRect(); |
| 103 | } |
| 104 | |
| 105 | void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, |
| 106 | CFX_Matrix* pUser2Device, |
| 107 | CPDF_RenderOptions* pOptions) {} |
| 108 | |
| 109 | FX_BOOL CPDFSDK_Annot::IsSelected() { |
| 110 | return m_bSelected; |
| 111 | } |
| 112 | |
| 113 | void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) { |
| 114 | m_bSelected = bSelected; |
| 115 | } |
| 116 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 117 | UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() { |
| 118 | #ifdef PDF_ENABLE_XFA |
| 119 | return GetPDFXFAPage(); |
| 120 | #else // PDF_ENABLE_XFA |
| 121 | return GetPDFPage(); |
| 122 | #endif // PDF_ENABLE_XFA |
| 123 | } |
| 124 | |
| 125 | CPDF_Page* CPDFSDK_Annot::GetPDFPage() { |
| 126 | return m_pPageView ? m_pPageView->GetPDFPage() : nullptr; |
| 127 | } |