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

Side by Side Diff: fpdfsdk/cpdfsdk_pageview.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_pageview.h ('k') | fpdfsdk/javascript/Document.cpp » ('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_pageview.h" 7 #include "fpdfsdk/cpdfsdk_pageview.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 CPDFSDK_PageView::~CPDFSDK_PageView() { 60 CPDFSDK_PageView::~CPDFSDK_PageView() {
61 #ifndef PDF_ENABLE_XFA 61 #ifndef PDF_ENABLE_XFA
62 // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to 62 // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to
63 // be freed, which will cause issues if we try to cleanup the pageview pointer 63 // be freed, which will cause issues if we try to cleanup the pageview pointer
64 // in |m_page|. So, reset the pageview pointer before doing anything else. 64 // in |m_page|. So, reset the pageview pointer before doing anything else.
65 m_page->SetView(nullptr); 65 m_page->SetView(nullptr);
66 #endif // PDF_ENABLE_XFA 66 #endif // PDF_ENABLE_XFA
67 67
68 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 68 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
69 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 69 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
70 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) 70 for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray)
71 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); 71 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
72 72
73 m_fxAnnotArray.clear(); 73 m_SDKAnnotArray.clear();
74 m_pAnnotList.reset(); 74 m_pAnnotList.reset();
75 75
76 #ifndef PDF_ENABLE_XFA 76 #ifndef PDF_ENABLE_XFA
77 if (m_bOwnsPage) 77 if (m_bOwnsPage)
78 delete m_page; 78 delete m_page;
79 #endif // PDF_ENABLE_XFA 79 #endif // PDF_ENABLE_XFA
80 } 80 }
81 81
82 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, 82 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice,
83 CFX_Matrix* pUser2Device, 83 CFX_Matrix* pUser2Device,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 // for pdf/static xfa. 127 // for pdf/static xfa.
128 CPDFSDK_AnnotIterator annotIterator(this, true); 128 CPDFSDK_AnnotIterator annotIterator(this, true);
129 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { 129 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
130 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 130 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
131 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 131 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device,
132 pOptions->m_bDrawAnnots); 132 pOptions->m_bDrawAnnots);
133 } 133 }
134 } 134 }
135 135
136 const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX,
137 FX_FLOAT pageY) {
138 for (const auto& pAnnot : m_pAnnotList->All()) {
139 CFX_FloatRect annotRect = pAnnot->GetRect();
140 if (annotRect.Contains(pageX, pageY))
141 return pAnnot.get();
142 }
143 return nullptr;
144 }
145
146 const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX,
147 FX_FLOAT pageY) {
148 for (const auto& pAnnot : m_pAnnotList->All()) {
149 if (pAnnot->GetSubtype() == CPDF_Annot::Subtype::WIDGET) {
150 CFX_FloatRect annotRect = pAnnot->GetRect();
151 if (annotRect.Contains(pageX, pageY))
152 return pAnnot.get();
153 }
154 }
155 return nullptr;
156 }
157
158 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, 136 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX,
159 FX_FLOAT pageY) { 137 FX_FLOAT pageY) {
160 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 138 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
161 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); 139 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
162 CPDFSDK_AnnotIterator annotIterator(this, false); 140 CPDFSDK_AnnotIterator annotIterator(this, false);
163 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { 141 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
164 CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); 142 CFX_FloatRect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
165 if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) 143 if (pSDKAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP)
166 continue; 144 continue;
167 if (rc.Contains(pageX, pageY)) 145 if (rc.Contains(pageX, pageY))
(...skipping 18 matching lines...) Expand all
186 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); 164 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
187 CFX_FloatPoint point(pageX, pageY); 165 CFX_FloatPoint point(pageX, pageY);
188 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) 166 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
189 return pSDKAnnot; 167 return pSDKAnnot;
190 } 168 }
191 } 169 }
192 170
193 return nullptr; 171 return nullptr;
194 } 172 }
195 173
196 void CPDFSDK_PageView::KillFocusAnnotIfNeeded() {
197 // if there is a focused annot on the page, we should kill the focus first.
198 if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) {
199 if (pdfium::ContainsValue(m_fxAnnotArray, focusedAnnot))
200 KillFocusAnnot();
201 }
202 }
203
204 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) {
205 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
206 ASSERT(pEnv);
207 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
208 CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
209 if (!pSDKAnnot)
210 return nullptr;
211
212 m_fxAnnotArray.push_back(pSDKAnnot);
213 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
214 return pSDKAnnot;
215 }
216
217 #ifdef PDF_ENABLE_XFA 174 #ifdef PDF_ENABLE_XFA
218 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) { 175 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) {
219 if (!pPDFAnnot) 176 if (!pPDFAnnot)
220 return nullptr; 177 return nullptr;
221 178
222 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); 179 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
223 if (pSDKAnnot) 180 if (pSDKAnnot)
224 return pSDKAnnot; 181 return pSDKAnnot;
225 182
226 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 183 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
227 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); 184 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
228 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); 185 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
229 if (!pSDKAnnot) 186 if (!pSDKAnnot)
230 return nullptr; 187 return nullptr;
231 188
232 m_fxAnnotArray.push_back(pSDKAnnot); 189 m_SDKAnnotArray.push_back(pSDKAnnot);
233 return pSDKAnnot; 190 return pSDKAnnot;
234 } 191 }
235 #endif // PDF_ENABLE_XFA
236
237 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) {
238 return pDict ? AddAnnot(pDict->GetStringFor("Subtype").c_str(), pDict)
239 : nullptr;
240 }
241
242 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,
243 CPDF_Dictionary* pDict) {
244 return nullptr;
245 }
246 192
247 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { 193 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) {
248 #ifdef PDF_ENABLE_XFA
249 if (!pAnnot) 194 if (!pAnnot)
250 return FALSE; 195 return FALSE;
251 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); 196 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
252 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && 197 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA &&
253 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) 198 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA))
254 return FALSE; 199 return FALSE;
255 200
256 if (GetFocusAnnot() == pAnnot) 201 if (GetFocusAnnot() == pAnnot)
257 KillFocusAnnot(); 202 m_pSDKDoc->KillFocusAnnot(0);
258 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 203 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
259 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); 204 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
260 if (pAnnotHandler) 205 if (pAnnotHandler)
261 pAnnotHandler->ReleaseAnnot(pAnnot); 206 pAnnotHandler->ReleaseAnnot(pAnnot);
262 207
263 auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); 208 auto it = std::find(m_SDKAnnotArray.begin(), m_SDKAnnotArray.end(), pAnnot);
264 if (it != m_fxAnnotArray.end()) 209 if (it != m_SDKAnnotArray.end())
265 m_fxAnnotArray.erase(it); 210 m_SDKAnnotArray.erase(it);
266 if (m_pCaptureWidget.Get() == pAnnot) 211 if (m_pCaptureWidget.Get() == pAnnot)
267 m_pCaptureWidget.Reset(); 212 m_pCaptureWidget.Reset();
268 213
269 return TRUE; 214 return TRUE;
270 #else // PDF_ENABLE_XFA 215 }
271 return FALSE;
272 #endif // PDF_ENABLE_XFA 216 #endif // PDF_ENABLE_XFA
273 }
274 217
275 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { 218 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() {
276 if (m_page) { 219 if (m_page) {
277 #ifdef PDF_ENABLE_XFA 220 #ifdef PDF_ENABLE_XFA
278 return m_page->GetDocument()->GetPDFDoc(); 221 return m_page->GetDocument()->GetPDFDoc();
279 #else // PDF_ENABLE_XFA 222 #else // PDF_ENABLE_XFA
280 return m_page->m_pDocument; 223 return m_page->m_pDocument;
281 #endif // PDF_ENABLE_XFA 224 #endif // PDF_ENABLE_XFA
282 } 225 }
283 return nullptr; 226 return nullptr;
284 } 227 }
285 228
286 CPDF_Page* CPDFSDK_PageView::GetPDFPage() const { 229 CPDF_Page* CPDFSDK_PageView::GetPDFPage() const {
287 #ifdef PDF_ENABLE_XFA 230 #ifdef PDF_ENABLE_XFA
288 return m_page ? m_page->GetPDFPage() : nullptr; 231 return m_page ? m_page->GetPDFPage() : nullptr;
289 #else // PDF_ENABLE_XFA 232 #else // PDF_ENABLE_XFA
290 return m_page; 233 return m_page;
291 #endif // PDF_ENABLE_XFA 234 #endif // PDF_ENABLE_XFA
292 } 235 }
293 236
294 size_t CPDFSDK_PageView::CountAnnots() const {
295 return m_fxAnnotArray.size();
296 }
297
298 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) {
299 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr;
300 }
301
302 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { 237 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) {
303 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { 238 for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) {
304 if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) 239 if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict)
305 return pAnnot; 240 return pAnnot;
306 } 241 }
307 return nullptr; 242 return nullptr;
308 } 243 }
309 244
310 #ifdef PDF_ENABLE_XFA 245 #ifdef PDF_ENABLE_XFA
311 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) { 246 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* hWidget) {
312 if (!hWidget) 247 if (!hWidget)
313 return nullptr; 248 return nullptr;
314 249
315 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { 250 for (CPDFSDK_Annot* pAnnot : m_SDKAnnotArray) {
316 if (pAnnot->GetXFAWidget() == hWidget) 251 if (pAnnot->GetXFAWidget() == hWidget)
317 return pAnnot; 252 return pAnnot;
318 } 253 }
319 return nullptr; 254 return nullptr;
320 } 255 }
321 #endif // PDF_ENABLE_XFA 256 #endif // PDF_ENABLE_XFA
322 257
323 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point, 258 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CFX_FloatPoint& point,
324 uint32_t nFlag) { 259 uint32_t nFlag) {
325 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); 260 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y));
326 if (!pAnnot) { 261 if (!pAnnot) {
327 KillFocusAnnot(nFlag); 262 m_pSDKDoc->KillFocusAnnot(nFlag);
328 return FALSE; 263 return FALSE;
329 } 264 }
330 265
331 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 266 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
332 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 267 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
333 if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point)) 268 if (!pAnnotHandlerMgr->Annot_OnLButtonDown(this, &pAnnot, nFlag, point))
334 return FALSE; 269 return FALSE;
335 270
336 if (!pAnnot) 271 if (!pAnnot)
337 return FALSE; 272 return FALSE;
338 273
339 SetFocusAnnot(&pAnnot); 274 m_pSDKDoc->SetFocusAnnot(&pAnnot);
340 return TRUE; 275 return TRUE;
341 } 276 }
342 277
343 #ifdef PDF_ENABLE_XFA 278 #ifdef PDF_ENABLE_XFA
344 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point, 279 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CFX_FloatPoint& point,
345 uint32_t nFlag) { 280 uint32_t nFlag) {
346 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y)); 281 CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point.x, point.y));
347 if (!pAnnot) 282 if (!pAnnot)
348 return FALSE; 283 return FALSE;
349 284
350 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 285 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
351 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 286 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
352 FX_BOOL ok = 287 FX_BOOL ok =
353 pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point); 288 pAnnotHandlerMgr->Annot_OnRButtonDown(this, &pAnnot, nFlag, point);
354 if (!pAnnot) 289 if (!pAnnot)
355 return FALSE; 290 return FALSE;
356 291
357 if (ok) 292 if (ok)
358 SetFocusAnnot(&pAnnot); 293 m_pSDKDoc->SetFocusAnnot(&pAnnot);
359 294
360 return TRUE; 295 return TRUE;
361 } 296 }
362 297
363 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, 298 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point,
364 uint32_t nFlag) { 299 uint32_t nFlag) {
365 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 300 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
366 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 301 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
367 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y)); 302 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y));
368 if (!pFXAnnot) 303 if (!pFXAnnot)
369 return FALSE; 304 return FALSE;
370 305
371 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point)) 306 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point))
372 SetFocusAnnot(&pFXAnnot); 307 m_pSDKDoc->SetFocusAnnot(&pFXAnnot);
373 308
374 return TRUE; 309 return TRUE;
375 } 310 }
376 #endif // PDF_ENABLE_XFA 311 #endif // PDF_ENABLE_XFA
377 312
378 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, 313 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point,
379 uint32_t nFlag) { 314 uint32_t nFlag) {
380 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 315 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
381 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); 316 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
382 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y)); 317 CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point.x, point.y));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); 410 XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable));
476 if (!pWidgetHander) { 411 if (!pWidgetHander) {
477 SetLock(FALSE); 412 SetLock(FALSE);
478 return; 413 return;
479 } 414 }
480 415
481 while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) { 416 while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) {
482 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); 417 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
483 if (!pAnnot) 418 if (!pAnnot)
484 continue; 419 continue;
485 m_fxAnnotArray.push_back(pAnnot); 420 m_SDKAnnotArray.push_back(pAnnot);
486 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); 421 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
487 } 422 }
488 423
489 SetLock(FALSE); 424 SetLock(FALSE);
490 return; 425 return;
491 } 426 }
492 #endif // PDF_ENABLE_XFA 427 #endif // PDF_ENABLE_XFA
493 428
494 CPDF_Page* pPage = GetPDFPage(); 429 CPDF_Page* pPage = GetPDFPage();
495 ASSERT(pPage); 430 ASSERT(pPage);
496 bool bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); 431 bool bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled();
497 // Disable the default AP construction. 432 // Disable the default AP construction.
498 CPDF_InterForm::SetUpdateAP(false); 433 CPDF_InterForm::SetUpdateAP(false);
499 m_pAnnotList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); 434 m_pAnnotList = pdfium::MakeUnique<CPDF_AnnotList>(pPage);
500 CPDF_InterForm::SetUpdateAP(bUpdateAP); 435 CPDF_InterForm::SetUpdateAP(bUpdateAP);
501 436
502 const size_t nCount = m_pAnnotList->Count(); 437 const size_t nCount = m_pAnnotList->Count();
503 for (size_t i = 0; i < nCount; ++i) { 438 for (size_t i = 0; i < nCount; ++i) {
504 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); 439 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
505 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); 440 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot);
506 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); 441 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
507 if (!pAnnot) 442 if (!pAnnot)
508 continue; 443 continue;
509 m_fxAnnotArray.push_back(pAnnot); 444 m_SDKAnnotArray.push_back(pAnnot);
510 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); 445 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
511 } 446 }
512 447
513 SetLock(FALSE); 448 SetLock(FALSE);
514 } 449 }
515 450
516 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) { 451 void CPDFSDK_PageView::UpdateRects(const std::vector<CFX_FloatRect>& rects) {
517 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv(); 452 CPDFSDK_Environment* pEnv = m_pSDKDoc->GetEnv();
518 for (const auto& rc : rects) 453 for (const auto& rc : rects)
519 pEnv->Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); 454 pEnv->Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 return false; 488 return false;
554 489
555 const auto& annots = m_pAnnotList->All(); 490 const auto& annots = m_pAnnotList->All();
556 auto it = std::find_if(annots.begin(), annots.end(), 491 auto it = std::find_if(annots.begin(), annots.end(),
557 [p](const std::unique_ptr<CPDF_Annot>& annot) { 492 [p](const std::unique_ptr<CPDF_Annot>& annot) {
558 return annot.get() == p; 493 return annot.get() == p;
559 }); 494 });
560 return it != annots.end(); 495 return it != annots.end();
561 } 496 }
562 497
498 bool CPDFSDK_PageView::IsValidSDKAnnot(const CPDFSDK_Annot* p) const {
499 if (!p)
500 return false;
501 return pdfium::ContainsValue(m_SDKAnnotArray, p);
502 }
503
563 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { 504 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {
564 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); 505 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
565 if (!pFocusAnnot) 506 return IsValidSDKAnnot(pFocusAnnot) ? pFocusAnnot : nullptr;
566 return nullptr;
567
568 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) {
569 if (pAnnot == pFocusAnnot)
570 return pAnnot;
571 }
572 return nullptr;
573 } 507 }
574 508
575 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { 509 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const {
576 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; 510 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict;
577 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); 511 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument();
578 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; 512 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1;
579 } 513 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_pageview.h ('k') | fpdfsdk/javascript/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698