blob: 353edaaaf97cc85bf1b08d5587013aa0a2af6527 [file] [log] [blame]
jaepark27362762016-08-11 13:10:39 -07001// 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"
dsinclairce04a452016-09-07 05:46:55 -070012#include "third_party/base/stl_util.h"
jaepark27362762016-08-11 13:10:39 -070013
14#ifdef PDF_ENABLE_XFA
15#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
16#endif // PDF_ENABLE_XFA
17
18namespace {
19
20const float kMinWidth = 1.0f;
21const float kMinHeight = 1.0f;
22
23} // namespace
24
dsinclairce04a452016-09-07 05:46:55 -070025CPDFSDK_Annot::Observer::Observer(CPDFSDK_Annot** pWatchedPtr)
26 : m_pWatchedPtr(pWatchedPtr) {
27 (*m_pWatchedPtr)->AddObserver(this);
28}
29
30CPDFSDK_Annot::Observer::~Observer() {
31 if (m_pWatchedPtr)
32 (*m_pWatchedPtr)->RemoveObserver(this);
33}
34
35void CPDFSDK_Annot::Observer::OnAnnotDestroyed() {
36 ASSERT(m_pWatchedPtr);
37 *m_pWatchedPtr = nullptr;
38 m_pWatchedPtr = nullptr;
39}
40
jaepark27362762016-08-11 13:10:39 -070041CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
jaeparkd99a8332016-08-25 13:02:39 -070042 : m_pPageView(pPageView), m_bSelected(FALSE) {}
jaepark27362762016-08-11 13:10:39 -070043
dsinclairce04a452016-09-07 05:46:55 -070044CPDFSDK_Annot::~CPDFSDK_Annot() {
45 for (auto* pObserver : m_Observers)
46 pObserver->OnAnnotDestroyed();
47}
48
49void CPDFSDK_Annot::AddObserver(Observer* pObserver) {
50 ASSERT(!pdfium::ContainsKey(m_Observers, pObserver));
51 m_Observers.insert(pObserver);
52}
53
54void CPDFSDK_Annot::RemoveObserver(Observer* pObserver) {
55 ASSERT(pdfium::ContainsKey(m_Observers, pObserver));
56 m_Observers.erase(pObserver);
57}
jaepark27362762016-08-11 13:10:39 -070058
59#ifdef PDF_ENABLE_XFA
60
61FX_BOOL CPDFSDK_Annot::IsXFAField() {
62 return FALSE;
63}
64
65CXFA_FFWidget* CPDFSDK_Annot::GetXFAWidget() const {
66 return nullptr;
67}
68
69CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
70 return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr;
71}
72
73#endif // PDF_ENABLE_XFA
74
75FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
76 return kMinWidth;
77}
78
79FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
80 return kMinHeight;
81}
82
83int CPDFSDK_Annot::GetLayoutOrder() const {
84 return 5;
85}
86
87CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot() const {
88 return nullptr;
89}
90
jaepark956553e2016-08-31 06:49:27 -070091CPDF_Annot::Subtype CPDFSDK_Annot::GetAnnotSubtype() const {
92 return CPDF_Annot::Subtype::UNKNOWN;
jaepark27362762016-08-11 13:10:39 -070093}
94
jaepark9ed91372016-08-26 16:16:10 -070095bool CPDFSDK_Annot::IsSignatureWidget() const {
96 return false;
jaepark27362762016-08-11 13:10:39 -070097}
98
99void CPDFSDK_Annot::SetRect(const CFX_FloatRect& rect) {}
100
101CFX_FloatRect CPDFSDK_Annot::GetRect() const {
102 return CFX_FloatRect();
103}
104
105void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice,
106 CFX_Matrix* pUser2Device,
107 CPDF_RenderOptions* pOptions) {}
108
109FX_BOOL CPDFSDK_Annot::IsSelected() {
110 return m_bSelected;
111}
112
113void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) {
114 m_bSelected = bSelected;
115}
116
jaepark27362762016-08-11 13:10:39 -0700117UnderlyingPageType* 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
125CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
126 return m_pPageView ? m_pPageView->GetPDFPage() : nullptr;
127}