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

Side by Side Diff: fpdfsdk/cpdfsdk_document.cpp

Issue 2368403002: Watch destruction of widgets around OnAAction() method (Closed)
Patch Set: blown merge 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_baannothandler.cpp ('k') | fpdfsdk/cpdfsdk_pageview.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/include/cpdfsdk_document.h" 7 #include "fpdfsdk/include/cpdfsdk_document.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
(...skipping 13 matching lines...) Expand all
24 // static 24 // static
25 CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( 25 CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle(
26 FPDF_FORMHANDLE hHandle) { 26 FPDF_FORMHANDLE hHandle) {
27 CPDFSDK_Environment* pEnv = static_cast<CPDFSDK_Environment*>(hHandle); 27 CPDFSDK_Environment* pEnv = static_cast<CPDFSDK_Environment*>(hHandle);
28 return pEnv ? pEnv->GetSDKDocument() : nullptr; 28 return pEnv ? pEnv->GetSDKDocument() : nullptr;
29 } 29 }
30 30
31 CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc, 31 CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc,
32 CPDFSDK_Environment* pEnv) 32 CPDFSDK_Environment* pEnv)
33 : m_pDoc(pDoc), 33 : m_pDoc(pDoc),
34 m_pFocusAnnot(nullptr),
35 m_pEnv(pEnv), 34 m_pEnv(pEnv),
36 m_bChangeMask(FALSE), 35 m_bChangeMask(FALSE),
37 m_bBeingDestroyed(FALSE) {} 36 m_bBeingDestroyed(FALSE) {}
38 37
39 CPDFSDK_Document::~CPDFSDK_Document() { 38 CPDFSDK_Document::~CPDFSDK_Document() {
40 m_bBeingDestroyed = TRUE; 39 m_bBeingDestroyed = TRUE;
41 40
42 for (auto& it : m_pageMap) 41 for (auto& it : m_pageMap)
43 it.second->KillFocusAnnotIfNeeded(); 42 it.second->KillFocusAnnotIfNeeded();
44 43
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 CPDFSDK_Annot* pAnnot) { 166 CPDFSDK_Annot* pAnnot) {
168 for (const auto& it : m_pageMap) { 167 for (const auto& it : m_pageMap) {
169 CPDFSDK_PageView* pPageView = it.second; 168 CPDFSDK_PageView* pPageView = it.second;
170 if (pPageView != pSender) { 169 if (pPageView != pSender) {
171 pPageView->UpdateView(pAnnot); 170 pPageView->UpdateView(pAnnot);
172 } 171 }
173 } 172 }
174 } 173 }
175 174
176 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { 175 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() {
177 return m_pFocusAnnot; 176 return m_pFocusAnnot.Get();
178 } 177 }
179 178
180 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { 179 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot::ObservedPtr* pAnnot,
180 uint32_t nFlag) {
181 if (m_bBeingDestroyed) 181 if (m_bBeingDestroyed)
182 return FALSE; 182 return FALSE;
183 183
184 if (m_pFocusAnnot == pAnnot) 184 if (m_pFocusAnnot == *pAnnot)
185 return TRUE; 185 return TRUE;
186 186
187 if (m_pFocusAnnot) { 187 if (m_pFocusAnnot) {
188 if (!KillFocusAnnot(nFlag)) 188 if (!KillFocusAnnot(nFlag))
189 return FALSE; 189 return FALSE;
190 } 190 }
191 191
192 if (!pAnnot) 192 if (!*pAnnot)
193 return FALSE; 193 return FALSE;
194 194
195 #ifdef PDF_ENABLE_XFA 195 #ifdef PDF_ENABLE_XFA
196 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; 196 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
197 #endif // PDF_ENABLE_XFA 197 #endif // PDF_ENABLE_XFA
198 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); 198 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView();
199 if (pPageView && pPageView->IsValid()) { 199 if (pPageView && pPageView->IsValid()) {
200 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); 200 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr();
201 if (!m_pFocusAnnot) { 201 if (!m_pFocusAnnot) {
202 #ifdef PDF_ENABLE_XFA 202 #ifdef PDF_ENABLE_XFA
203 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) 203 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
204 return FALSE; 204 return FALSE;
205 #endif // PDF_ENABLE_XFA 205 #endif // PDF_ENABLE_XFA
206 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) 206 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag))
207 return FALSE; 207 return FALSE;
208 if (!m_pFocusAnnot) { 208 if (!m_pFocusAnnot) {
209 m_pFocusAnnot = pAnnot; 209 m_pFocusAnnot.Reset(pAnnot->Get());
210 return TRUE; 210 return TRUE;
211 } 211 }
212 } 212 }
213 } 213 }
214 return FALSE; 214 return FALSE;
215 } 215 }
216 216
217 FX_BOOL CPDFSDK_Document::KillFocusAnnot(uint32_t nFlag) { 217 FX_BOOL CPDFSDK_Document::KillFocusAnnot(uint32_t nFlag) {
218 if (m_pFocusAnnot) { 218 if (m_pFocusAnnot) {
219 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); 219 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr();
220 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; 220 CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get());
221 m_pFocusAnnot = nullptr; 221 m_pFocusAnnot.Reset();
222 222
223 #ifdef PDF_ENABLE_XFA 223 #ifdef PDF_ENABLE_XFA
224 if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) 224 CPDFSDK_Annot::ObservedPtr pNull;
225 if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot))
225 return FALSE; 226 return FALSE;
226 #endif // PDF_ENABLE_XFA 227 #endif // PDF_ENABLE_XFA
227 228
228 if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { 229 if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) {
229 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { 230 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) {
230 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; 231 CPDFSDK_Widget* pWidget =
232 static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get());
231 int nFieldType = pWidget->GetFieldType(); 233 int nFieldType = pWidget->GetFieldType();
232 if (FIELDTYPE_TEXTFIELD == nFieldType || 234 if (FIELDTYPE_TEXTFIELD == nFieldType ||
233 FIELDTYPE_COMBOBOX == nFieldType) { 235 FIELDTYPE_COMBOBOX == nFieldType) {
234 m_pEnv->OnSetFieldInputFocus(nullptr, 0, FALSE); 236 m_pEnv->OnSetFieldInputFocus(nullptr, 0, FALSE);
235 } 237 }
236 } 238 }
237
238 if (!m_pFocusAnnot) 239 if (!m_pFocusAnnot)
239 return TRUE; 240 return TRUE;
240 } else { 241 } else {
241 m_pFocusAnnot = pFocusAnnot; 242 m_pFocusAnnot.Reset(pFocusAnnot.Get());
242 } 243 }
243 } 244 }
244 return FALSE; 245 return FALSE;
245 } 246 }
246 247
247 void CPDFSDK_Document::OnCloseDocument() { 248 void CPDFSDK_Document::OnCloseDocument() {
248 KillFocusAnnot(); 249 KillFocusAnnot();
249 } 250 }
250 251
251 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { 252 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) {
252 return GetPDFDocument()->GetUserPermissions() & nFlag; 253 return GetPDFDocument()->GetUserPermissions() & nFlag;
253 } 254 }
254 255
255 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { 256 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() {
256 return m_pEnv->GetJSRuntime(); 257 return m_pEnv->GetJSRuntime();
257 } 258 }
258 259
259 CFX_WideString CPDFSDK_Document::GetPath() { 260 CFX_WideString CPDFSDK_Document::GetPath() {
260 return m_pEnv->JS_docGetFilePath(); 261 return m_pEnv->JS_docGetFilePath();
261 } 262 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_baannothandler.cpp ('k') | fpdfsdk/cpdfsdk_pageview.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698