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

Side by Side Diff: xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp

Issue 2001743002: Use std::set to track uniqueness in xfa_script_layoutpseudomodel.cpp (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h" 7 #include "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h"
8 8
9 #include <set>
10
11 #include "third_party/base/stl_util.h"
9 #include "xfa/fxfa/app/xfa_ffnotify.h" 12 #include "xfa/fxfa/app/xfa_ffnotify.h"
10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" 13 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h"
11 #include "xfa/fxfa/parser/xfa_doclayout.h" 14 #include "xfa/fxfa/parser/xfa_doclayout.h"
12 #include "xfa/fxfa/parser/xfa_document.h" 15 #include "xfa/fxfa/parser/xfa_document.h"
13 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" 16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h"
14 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" 17 #include "xfa/fxfa/parser/xfa_layout_appadapter.h"
15 #include "xfa/fxfa/parser/xfa_localemgr.h" 18 #include "xfa/fxfa/parser/xfa_localemgr.h"
16 #include "xfa/fxfa/parser/xfa_object.h" 19 #include "xfa/fxfa/parser/xfa_object.h"
17 #include "xfa/fxfa/parser/xfa_parser.h" 20 #include "xfa/fxfa/parser/xfa_parser.h"
18 #include "xfa/fxfa/parser/xfa_parser_imp.h" 21 #include "xfa/fxfa/parser/xfa_parser_imp.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 228 }
226 if (wsType == FX_WSTRC(L"contentArea")) { 229 if (wsType == FX_WSTRC(L"contentArea")) {
227 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; 230 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem;
228 pItem = pItem->m_pNextSibling) { 231 pItem = pItem->m_pNextSibling) {
229 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { 232 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {
230 retArray.Add(pItem->m_pFormNode); 233 retArray.Add(pItem->m_pFormNode);
231 } 234 }
232 } 235 }
233 return; 236 return;
234 } 237 }
235 CFX_MapPtrToPtr formItems; 238 std::set<CXFA_Node*> formItems;
236 formItems.InitHashTable(256, TRUE);
237 if (wsType.IsEmpty()) { 239 if (wsType.IsEmpty()) {
238 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { 240 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) {
239 retArray.Add(pMasterPage); 241 retArray.Add(pMasterPage);
240 } 242 }
241 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; 243 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem;
242 pItem = pItem->m_pNextSibling) { 244 pItem = pItem->m_pNextSibling) {
243 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { 245 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {
244 retArray.Add(pItem->m_pFormNode); 246 retArray.Add(pItem->m_pFormNode);
245 if (!bOnPageArea) { 247 if (!bOnPageArea) {
246 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, 248 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
247 CXFA_TraverseStrategy_ContentLayoutItem> 249 CXFA_TraverseStrategy_ContentLayoutItem>
248 iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild); 250 iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild);
249 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); 251 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
250 pItemChild; pItemChild = iterator.MoveToNext()) { 252 pItemChild; pItemChild = iterator.MoveToNext()) {
251 if (!pItemChild->IsContentLayoutItem()) { 253 if (!pItemChild->IsContentLayoutItem()) {
252 continue; 254 continue;
253 } 255 }
254 XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID(); 256 XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID();
255 if (eElementType != XFA_ELEMENT_Field && 257 if (eElementType != XFA_ELEMENT_Field &&
256 eElementType != XFA_ELEMENT_Draw && 258 eElementType != XFA_ELEMENT_Draw &&
257 eElementType != XFA_ELEMENT_Subform && 259 eElementType != XFA_ELEMENT_Subform &&
258 eElementType != XFA_ELEMENT_Area) { 260 eElementType != XFA_ELEMENT_Area) {
259 continue; 261 continue;
260 } 262 }
261 if (formItems.GetValueAt(pItemChild->m_pFormNode)) { 263 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode))
262 continue; 264 continue;
263 } 265
264 formItems.SetAt(pItemChild->m_pFormNode, this); 266 formItems.insert(pItemChild->m_pFormNode);
265 retArray.Add(pItemChild->m_pFormNode); 267 retArray.Add(pItemChild->m_pFormNode);
266 } 268 }
267 } 269 }
268 } else { 270 } else {
269 if (bOnPageArea) { 271 if (bOnPageArea) {
270 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, 272 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
271 CXFA_TraverseStrategy_ContentLayoutItem> 273 CXFA_TraverseStrategy_ContentLayoutItem>
272 iterator((CXFA_ContentLayoutItem*)pItem); 274 iterator((CXFA_ContentLayoutItem*)pItem);
273 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); 275 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
274 pItemChild; pItemChild = iterator.MoveToNext()) { 276 pItemChild; pItemChild = iterator.MoveToNext()) {
275 if (!pItemChild->IsContentLayoutItem()) { 277 if (!pItemChild->IsContentLayoutItem()) {
276 continue; 278 continue;
277 } 279 }
278 XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID(); 280 XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID();
279 if (eElementType != XFA_ELEMENT_Field && 281 if (eElementType != XFA_ELEMENT_Field &&
280 eElementType != XFA_ELEMENT_Draw && 282 eElementType != XFA_ELEMENT_Draw &&
281 eElementType != XFA_ELEMENT_Subform && 283 eElementType != XFA_ELEMENT_Subform &&
282 eElementType != XFA_ELEMENT_Area) { 284 eElementType != XFA_ELEMENT_Area) {
283 continue; 285 continue;
284 } 286 }
285 if (formItems.GetValueAt(pItemChild->m_pFormNode)) { 287 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode))
286 continue; 288 continue;
287 } 289 formItems.insert(pItemChild->m_pFormNode);
288 formItems.SetAt(pItemChild->m_pFormNode, this);
289 retArray.Add(pItemChild->m_pFormNode); 290 retArray.Add(pItemChild->m_pFormNode);
290 } 291 }
291 } 292 }
292 } 293 }
293 } 294 }
294 return; 295 return;
295 } 296 }
296 XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN; 297 XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN;
297 if (wsType == FX_WSTRC(L"field")) { 298 if (wsType == FX_WSTRC(L"field")) {
298 eType = XFA_ELEMENT_Field; 299 eType = XFA_ELEMENT_Field;
299 } else if (wsType == FX_WSTRC(L"draw")) { 300 } else if (wsType == FX_WSTRC(L"draw")) {
300 eType = XFA_ELEMENT_Draw; 301 eType = XFA_ELEMENT_Draw;
301 } else if (wsType == FX_WSTRC(L"subform")) { 302 } else if (wsType == FX_WSTRC(L"subform")) {
302 eType = XFA_ELEMENT_Subform; 303 eType = XFA_ELEMENT_Subform;
303 } else if (wsType == FX_WSTRC(L"area")) { 304 } else if (wsType == FX_WSTRC(L"area")) {
304 eType = XFA_ELEMENT_Area; 305 eType = XFA_ELEMENT_Area;
305 } 306 }
306 if (eType != XFA_ELEMENT_UNKNOWN) { 307 if (eType != XFA_ELEMENT_UNKNOWN) {
307 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; 308 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem;
308 pItem = pItem->m_pNextSibling) { 309 pItem = pItem->m_pNextSibling) {
309 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { 310 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {
310 if (!bOnPageArea) { 311 if (!bOnPageArea) {
311 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, 312 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
312 CXFA_TraverseStrategy_ContentLayoutItem> 313 CXFA_TraverseStrategy_ContentLayoutItem>
313 iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild); 314 iterator((CXFA_ContentLayoutItem*)pItem->m_pFirstChild);
314 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); 315 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
315 pItemChild; pItemChild = iterator.MoveToNext()) { 316 pItemChild; pItemChild = iterator.MoveToNext()) {
316 if (!pItemChild->IsContentLayoutItem()) { 317 if (!pItemChild->IsContentLayoutItem())
317 continue; 318 continue;
318 } 319 if (pItemChild->m_pFormNode->GetClassID() != eType)
319 if (pItemChild->m_pFormNode->GetClassID() != eType) {
320 continue; 320 continue;
321 } 321 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode))
322 if (formItems.GetValueAt(pItemChild->m_pFormNode)) {
323 continue; 322 continue;
324 } 323 formItems.insert(pItemChild->m_pFormNode);
325 formItems.SetAt(pItemChild->m_pFormNode, this);
326 retArray.Add(pItemChild->m_pFormNode); 324 retArray.Add(pItemChild->m_pFormNode);
327 } 325 }
328 } 326 }
329 } else { 327 } else {
330 if (bOnPageArea) { 328 if (bOnPageArea) {
331 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, 329 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem,
332 CXFA_TraverseStrategy_ContentLayoutItem> 330 CXFA_TraverseStrategy_ContentLayoutItem>
333 iterator((CXFA_ContentLayoutItem*)pItem); 331 iterator((CXFA_ContentLayoutItem*)pItem);
334 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); 332 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent();
335 pItemChild; pItemChild = iterator.MoveToNext()) { 333 pItemChild; pItemChild = iterator.MoveToNext()) {
336 if (!pItemChild->IsContentLayoutItem()) { 334 if (!pItemChild->IsContentLayoutItem())
337 continue; 335 continue;
338 } 336 if (pItemChild->m_pFormNode->GetClassID() != eType)
339 if (pItemChild->m_pFormNode->GetClassID() != eType) {
340 continue; 337 continue;
341 } 338 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode))
342 if (formItems.GetValueAt(pItemChild->m_pFormNode)) {
343 continue; 339 continue;
344 } 340 formItems.insert(pItemChild->m_pFormNode);
345 formItems.SetAt(pItemChild->m_pFormNode, this);
346 retArray.Add(pItemChild->m_pFormNode); 341 retArray.Add(pItemChild->m_pFormNode);
347 } 342 }
348 } 343 }
349 } 344 }
350 } 345 }
351 return; 346 return;
352 } 347 }
353 } 348 }
354 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageContent( 349 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageContent(
355 CFXJSE_Arguments* pArguments) { 350 CFXJSE_Arguments* pArguments) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); 543 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
549 if (!pLayoutItem) { 544 if (!pLayoutItem) {
550 FXJSE_Value_SetInteger(hValue, -1); 545 FXJSE_Value_SetInteger(hValue, -1);
551 return; 546 return;
552 } 547 }
553 iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); 548 iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
554 if (hValue) { 549 if (hValue) {
555 FXJSE_Value_SetInteger(hValue, bAbsPage ? iPage : iPage + 1); 550 FXJSE_Value_SetInteger(hValue, bAbsPage ? iPage : iPage + 1);
556 } 551 }
557 } 552 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698