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

Side by Side Diff: fpdfsdk/cpdfsdk_document.cpp

Issue 2384323005: Cleanup some CPDFSDK_PageView annotation code. (Closed)
Patch Set: Review feedback 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.h ('k') | fpdfsdk/cpdfsdk_pageview.h » ('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/cpdfsdk_document.h" 7 #include "fpdfsdk/cpdfsdk_document.h"
8 8
9 #include "core/fpdfapi/parser/cpdf_array.h" 9 #include "core/fpdfapi/parser/cpdf_array.h"
10 #include "core/fpdfapi/parser/cpdf_dictionary.h" 10 #include "core/fpdfapi/parser/cpdf_dictionary.h"
(...skipping 21 matching lines...) Expand all
32 CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, 32 CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc,
33 CPDFSDK_Environment* pEnv) 33 CPDFSDK_Environment* pEnv)
34 : m_pDoc(pDoc), 34 : m_pDoc(pDoc),
35 m_pEnv(pEnv), 35 m_pEnv(pEnv),
36 m_bChangeMask(FALSE), 36 m_bChangeMask(FALSE),
37 m_bBeingDestroyed(FALSE) {} 37 m_bBeingDestroyed(FALSE) {}
38 38
39 CPDFSDK_Document::~CPDFSDK_Document() { 39 CPDFSDK_Document::~CPDFSDK_Document() {
40 m_bBeingDestroyed = TRUE; 40 m_bBeingDestroyed = TRUE;
41 41
42 for (auto& it : m_pageMap) 42 for (auto& it : m_pageMap) {
43 it.second->KillFocusAnnotIfNeeded(); 43 if (it.second->IsValidSDKAnnot(GetFocusAnnot()))
44 KillFocusAnnot(0);
45 }
44 46
45 for (auto& it : m_pageMap) 47 for (auto& it : m_pageMap)
46 delete it.second; 48 delete it.second;
47 m_pageMap.clear(); 49 m_pageMap.clear();
48 } 50 }
49 51
50 CPDFSDK_PageView* CPDFSDK_Document::GetPageView( 52 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(
51 UnderlyingPageType* pUnderlyingPage, 53 UnderlyingPageType* pUnderlyingPage,
52 bool ReNew) { 54 bool ReNew) {
53 auto it = m_pageMap.find(pUnderlyingPage); 55 auto it = m_pageMap.find(pUnderlyingPage);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 139
138 CPDFSDK_PageView* pPageView = it->second; 140 CPDFSDK_PageView* pPageView = it->second;
139 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) 141 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed())
140 return; 142 return;
141 143
142 // Mark the page view so we do not come into |RemovePageView| a second 144 // Mark the page view so we do not come into |RemovePageView| a second
143 // time while we're in the process of removing. 145 // time while we're in the process of removing.
144 pPageView->SetBeingDestroyed(); 146 pPageView->SetBeingDestroyed();
145 147
146 // This must happen before we remove |pPageView| from the map because 148 // This must happen before we remove |pPageView| from the map because
147 // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will 149 // |KillFocusAnnot| can call into the |GetPage| method which will
148 // look for this page view in the map, if it doesn't find it a new one will 150 // look for this page view in the map, if it doesn't find it a new one will
149 // be created. We then have two page views pointing to the same page and 151 // be created. We then have two page views pointing to the same page and
150 // bad things happen. 152 // bad things happen.
151 pPageView->KillFocusAnnotIfNeeded(); 153 if (pPageView->IsValidSDKAnnot(GetFocusAnnot()))
154 KillFocusAnnot(0);
152 155
153 // Remove the page from the map to make sure we don't accidentally attempt 156 // Remove the page from the map to make sure we don't accidentally attempt
154 // to use the |pPageView| while we're cleaning it up. 157 // to use the |pPageView| while we're cleaning it up.
155 m_pageMap.erase(it); 158 m_pageMap.erase(it);
156 159
157 delete pPageView; 160 delete pPageView;
158 } 161 }
159 162
160 UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { 163 UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) {
161 return UnderlyingFromFPDFPage(m_pEnv->GetPage(m_pDoc, nIndex)); 164 return UnderlyingFromFPDFPage(m_pEnv->GetPage(m_pDoc, nIndex));
162 } 165 }
163 166
164 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { 167 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() {
165 if (!m_pInterForm) 168 if (!m_pInterForm)
166 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this); 169 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this);
167 return m_pInterForm.get(); 170 return m_pInterForm.get();
168 } 171 }
169 172
170 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, 173 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender,
171 CPDFSDK_Annot* pAnnot) { 174 CPDFSDK_Annot* pAnnot) {
172 for (const auto& it : m_pageMap) { 175 for (const auto& it : m_pageMap) {
173 CPDFSDK_PageView* pPageView = it.second; 176 CPDFSDK_PageView* pPageView = it.second;
174 if (pPageView != pSender) { 177 if (pPageView != pSender)
175 pPageView->UpdateView(pAnnot); 178 pPageView->UpdateView(pAnnot);
176 }
177 } 179 }
178 } 180 }
179 181
180 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { 182 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot) {
181 return m_pFocusAnnot.Get();
182 }
183
184 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot,
185 uint32_t nFlag) {
186 if (m_bBeingDestroyed) 183 if (m_bBeingDestroyed)
187 return FALSE; 184 return FALSE;
188
189 if (m_pFocusAnnot == *pAnnot) 185 if (m_pFocusAnnot == *pAnnot)
190 return TRUE; 186 return TRUE;
191 187 if (m_pFocusAnnot && !KillFocusAnnot(0))
192 if (m_pFocusAnnot) { 188 return FALSE;
193 if (!KillFocusAnnot(nFlag))
194 return FALSE;
195 }
196
197 if (!*pAnnot) 189 if (!*pAnnot)
198 return FALSE; 190 return FALSE;
199 191
200 #ifdef PDF_ENABLE_XFA 192 #ifdef PDF_ENABLE_XFA
201 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); 193 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
202 #endif // PDF_ENABLE_XFA 194 #endif // PDF_ENABLE_XFA
203 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView(); 195 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView();
204 if (pPageView && pPageView->IsValid()) { 196 if (pPageView && pPageView->IsValid()) {
205 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); 197 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr();
206 if (!m_pFocusAnnot) { 198 if (!m_pFocusAnnot) {
207 #ifdef PDF_ENABLE_XFA 199 #ifdef PDF_ENABLE_XFA
208 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot)) 200 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
209 return FALSE; 201 return FALSE;
210 #endif // PDF_ENABLE_XFA 202 #endif // PDF_ENABLE_XFA
211 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) 203 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0))
212 return FALSE; 204 return FALSE;
213 if (!m_pFocusAnnot) { 205 if (!m_pFocusAnnot) {
214 m_pFocusAnnot.Reset(pAnnot->Get()); 206 m_pFocusAnnot.Reset(pAnnot->Get());
215 return TRUE; 207 return TRUE;
216 } 208 }
217 } 209 }
218 } 210 }
219 return FALSE; 211 return FALSE;
220 } 212 }
221 213
(...skipping 22 matching lines...) Expand all
244 if (!m_pFocusAnnot) 236 if (!m_pFocusAnnot)
245 return TRUE; 237 return TRUE;
246 } else { 238 } else {
247 m_pFocusAnnot.Reset(pFocusAnnot.Get()); 239 m_pFocusAnnot.Reset(pFocusAnnot.Get());
248 } 240 }
249 } 241 }
250 return FALSE; 242 return FALSE;
251 } 243 }
252 244
253 void CPDFSDK_Document::OnCloseDocument() { 245 void CPDFSDK_Document::OnCloseDocument() {
254 KillFocusAnnot(); 246 KillFocusAnnot(0);
255 } 247 }
256 248
257 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { 249 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) {
258 return GetPDFDocument()->GetUserPermissions() & nFlag; 250 return GetPDFDocument()->GetUserPermissions() & nFlag;
259 } 251 }
260 252
261 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { 253 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() {
262 return m_pEnv->GetJSRuntime(); 254 return m_pEnv->GetJSRuntime();
263 } 255 }
264 256
265 CFX_WideString CPDFSDK_Document::GetPath() { 257 CFX_WideString CPDFSDK_Document::GetPath() {
266 return m_pEnv->JS_docGetFilePath(); 258 return m_pEnv->JS_docGetFilePath();
267 } 259 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_document.h ('k') | fpdfsdk/cpdfsdk_pageview.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698