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

Side by Side Diff: xfa/fxfa/app/xfa_ffpageview.cpp

Issue 2648773003: Replace CXFA_StrokeArray and CXFA_WidgetArray with std::vector (Closed)
Patch Set: remove if Created 3 years, 11 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 | xfa/fxfa/app/xfa_ffwidget.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 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/xfa_ffpageview.h" 7 #include "xfa/fxfa/xfa_ffpageview.h"
8 8
9 #include <memory>
10 #include <vector>
11
12 #include "third_party/base/ptr_util.h"
13 #include "third_party/base/stl_util.h"
9 #include "xfa/fde/fde_render.h" 14 #include "xfa/fde/fde_render.h"
10 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" 15 #include "xfa/fxfa/app/xfa_ffcheckbutton.h"
11 #include "xfa/fxfa/app/xfa_ffchoicelist.h" 16 #include "xfa/fxfa/app/xfa_ffchoicelist.h"
12 #include "xfa/fxfa/app/xfa_fffield.h" 17 #include "xfa/fxfa/app/xfa_fffield.h"
13 #include "xfa/fxfa/app/xfa_ffimageedit.h" 18 #include "xfa/fxfa/app/xfa_ffimageedit.h"
14 #include "xfa/fxfa/app/xfa_ffpushbutton.h" 19 #include "xfa/fxfa/app/xfa_ffpushbutton.h"
15 #include "xfa/fxfa/app/xfa_fftextedit.h" 20 #include "xfa/fxfa/app/xfa_fftextedit.h"
16 #include "xfa/fxfa/app/xfa_fwladapter.h" 21 #include "xfa/fxfa/app/xfa_fwladapter.h"
17 #include "xfa/fxfa/xfa_ffdoc.h" 22 #include "xfa/fxfa/xfa_ffdoc.h"
18 #include "xfa/fxfa/xfa_ffdocview.h" 23 #include "xfa/fxfa/xfa_ffdocview.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 XFA_VERSION_205; 226 XFA_VERSION_205;
222 Reset(); 227 Reset();
223 } 228 }
224 229
225 CXFA_FFTabOrderPageWidgetIterator::~CXFA_FFTabOrderPageWidgetIterator() {} 230 CXFA_FFTabOrderPageWidgetIterator::~CXFA_FFTabOrderPageWidgetIterator() {}
226 231
227 void CXFA_FFTabOrderPageWidgetIterator::Reset() { 232 void CXFA_FFTabOrderPageWidgetIterator::Reset() {
228 CreateTabOrderWidgetArray(); 233 CreateTabOrderWidgetArray();
229 m_iCurWidget = -1; 234 m_iCurWidget = -1;
230 } 235 }
236
231 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() { 237 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() {
232 if (m_TabOrderWidgetArray.GetSize() > 0) { 238 for (int32_t i = 0;
233 for (int32_t i = 0; i < m_TabOrderWidgetArray.GetSize(); i++) { 239 i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
234 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, 240 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
235 m_bIgnorerelevant)) { 241 m_bIgnorerelevant)) {
236 m_iCurWidget = i; 242 m_iCurWidget = i;
237 return m_TabOrderWidgetArray[m_iCurWidget]; 243 return m_TabOrderWidgetArray[m_iCurWidget];
238 }
239 } 244 }
240 } 245 }
241 return nullptr; 246 return nullptr;
242 } 247 }
248
243 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() { 249 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() {
244 if (m_TabOrderWidgetArray.GetSize() > 0) { 250 for (int32_t i = pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) - 1;
245 for (int32_t i = m_TabOrderWidgetArray.GetSize() - 1; i >= 0; i--) { 251 i >= 0; i--) {
246 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, 252 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
247 m_bIgnorerelevant)) { 253 m_bIgnorerelevant)) {
248 m_iCurWidget = i; 254 m_iCurWidget = i;
249 return m_TabOrderWidgetArray[m_iCurWidget]; 255 return m_TabOrderWidgetArray[m_iCurWidget];
250 }
251 } 256 }
252 } 257 }
253 return nullptr; 258 return nullptr;
254 } 259 }
260
255 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() { 261 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() {
256 for (int32_t i = m_iCurWidget + 1; i < m_TabOrderWidgetArray.GetSize(); i++) { 262 for (int32_t i = m_iCurWidget + 1;
263 i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
257 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, 264 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
258 m_bIgnorerelevant)) { 265 m_bIgnorerelevant)) {
259 m_iCurWidget = i; 266 m_iCurWidget = i;
260 return m_TabOrderWidgetArray[m_iCurWidget]; 267 return m_TabOrderWidgetArray[m_iCurWidget];
261 } 268 }
262 } 269 }
263 m_iCurWidget = -1; 270 m_iCurWidget = -1;
264 return nullptr; 271 return nullptr;
265 } 272 }
273
266 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() { 274 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() {
267 for (int32_t i = m_iCurWidget - 1; i >= 0; i--) { 275 for (int32_t i = m_iCurWidget - 1; i >= 0; i--) {
268 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, 276 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
269 m_bIgnorerelevant)) { 277 m_bIgnorerelevant)) {
270 m_iCurWidget = i; 278 m_iCurWidget = i;
271 return m_TabOrderWidgetArray[m_iCurWidget]; 279 return m_TabOrderWidgetArray[m_iCurWidget];
272 } 280 }
273 } 281 }
274 m_iCurWidget = -1; 282 m_iCurWidget = -1;
275 return nullptr; 283 return nullptr;
276 } 284 }
285
277 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() { 286 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() {
278 if (m_iCurWidget >= 0) { 287 return m_iCurWidget >= 0 ? m_TabOrderWidgetArray[m_iCurWidget] : nullptr;
279 return m_TabOrderWidgetArray[m_iCurWidget];
280 }
281 return nullptr;
282 } 288 }
289
283 bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget( 290 bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget(
284 CXFA_FFWidget* hWidget) { 291 CXFA_FFWidget* hWidget) {
285 int32_t iWidgetIndex = m_TabOrderWidgetArray.Find(hWidget); 292 auto it = std::find(m_TabOrderWidgetArray.begin(),
286 if (iWidgetIndex >= 0) { 293 m_TabOrderWidgetArray.end(), hWidget);
287 m_iCurWidget = iWidgetIndex; 294 if (it == m_TabOrderWidgetArray.end())
288 return true; 295 return false;
289 } 296
290 return false; 297 m_iCurWidget = it - m_TabOrderWidgetArray.begin();
298 return true;
291 } 299 }
300
292 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget( 301 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget(
293 CXFA_FFWidget* pWidget) { 302 CXFA_FFWidget* pWidget) {
294 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); 303 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
295 CXFA_Node* pTraversal = pAcc->GetNode()->GetChild(0, XFA_Element::Traversal); 304 CXFA_Node* pTraversal = pAcc->GetNode()->GetChild(0, XFA_Element::Traversal);
296 if (pTraversal) { 305 if (pTraversal) {
297 CXFA_Node* pTraverse = pTraversal->GetChild(0, XFA_Element::Traverse); 306 CXFA_Node* pTraverse = pTraversal->GetChild(0, XFA_Element::Traverse);
298 if (pTraverse) { 307 if (pTraverse) {
299 CFX_WideString wsTraverseWidgetName; 308 CFX_WideString wsTraverseWidgetName;
300 if (pTraverse->GetAttribute(XFA_ATTRIBUTE_Ref, wsTraverseWidgetName)) { 309 if (pTraverse->GetAttribute(XFA_ATTRIBUTE_Ref, wsTraverseWidgetName)) {
301 return FindWidgetByName(wsTraverseWidgetName, pWidget); 310 return FindWidgetByName(wsTraverseWidgetName, pWidget);
302 } 311 }
303 } 312 }
304 } 313 }
305 return nullptr; 314 return nullptr;
306 } 315 }
307 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName( 316 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName(
308 const CFX_WideString& wsWidgetName, 317 const CFX_WideString& wsWidgetName,
309 CXFA_FFWidget* pRefWidget) { 318 CXFA_FFWidget* pRefWidget) {
310 return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget); 319 return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget);
311 } 320 }
321
312 void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { 322 void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() {
313 m_TabOrderWidgetArray.RemoveAll(); 323 m_TabOrderWidgetArray.clear();
314 CXFA_WidgetArray SpaceOrderWidgetArray; 324
315 CreateSpaceOrderWidgetArray(SpaceOrderWidgetArray); 325 std::vector<CXFA_FFWidget*> SpaceOrderWidgetArray;
316 int32_t nWidgetCount = SpaceOrderWidgetArray.GetSize(); 326 CreateSpaceOrderWidgetArray(&SpaceOrderWidgetArray);
317 if (nWidgetCount < 1) { 327 if (SpaceOrderWidgetArray.empty())
318 return; 328 return;
319 } 329
330 int32_t nWidgetCount = pdfium::CollectionSize<int32_t>(SpaceOrderWidgetArray);
320 CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0]; 331 CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0];
321 for (; m_TabOrderWidgetArray.GetSize() < nWidgetCount;) { 332 while (pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) <
322 if (m_TabOrderWidgetArray.Find(hWidget) < 0) { 333 nWidgetCount) {
323 m_TabOrderWidgetArray.Add(hWidget); 334 if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) {
335 m_TabOrderWidgetArray.push_back(hWidget);
324 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); 336 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
325 if (pWidgetAcc->GetUIType() == XFA_Element::ExclGroup) { 337 if (pWidgetAcc->GetUIType() == XFA_Element::ExclGroup) {
326 int32_t iWidgetIndex = SpaceOrderWidgetArray.Find(hWidget) + 1; 338 auto it = std::find(SpaceOrderWidgetArray.begin(),
339 SpaceOrderWidgetArray.end(), hWidget);
340 int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end()
341 ? it - SpaceOrderWidgetArray.begin() + 1
342 : 0;
327 while (true) { 343 while (true) {
328 CXFA_FFWidget* pRadio = 344 CXFA_FFWidget* pRadio =
329 SpaceOrderWidgetArray[(iWidgetIndex) % nWidgetCount]; 345 SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount];
330 if (pRadio->GetDataAcc()->GetExclGroup() != pWidgetAcc) { 346 if (pRadio->GetDataAcc()->GetExclGroup() != pWidgetAcc) {
331 break; 347 break;
332 } 348 }
333 if (m_TabOrderWidgetArray.Find(hWidget) < 0) { 349 if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) {
334 m_TabOrderWidgetArray.Add(pRadio); 350 m_TabOrderWidgetArray.push_back(pRadio);
335 } 351 }
336 iWidgetIndex++; 352 iWidgetIndex++;
337 } 353 }
338 } 354 }
339 if (CXFA_FFWidget* hTraverseWidget = GetTraverseWidget(hWidget)) { 355 if (CXFA_FFWidget* hTraverseWidget = GetTraverseWidget(hWidget)) {
340 hWidget = hTraverseWidget; 356 hWidget = hTraverseWidget;
341 continue; 357 continue;
342 } 358 }
343 } 359 }
344 int32_t iWidgetIndex = SpaceOrderWidgetArray.Find(hWidget); 360 auto it = std::find(SpaceOrderWidgetArray.begin(),
345 hWidget = SpaceOrderWidgetArray[(iWidgetIndex + 1) % nWidgetCount]; 361 SpaceOrderWidgetArray.end(), hWidget);
362 int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end()
363 ? it - SpaceOrderWidgetArray.begin() + 1
364 : 0;
365 hWidget = SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount];
346 } 366 }
347 } 367 }
368
348 static int32_t XFA_TabOrderWidgetComparator(const void* phWidget1, 369 static int32_t XFA_TabOrderWidgetComparator(const void* phWidget1,
349 const void* phWidget2) { 370 const void* phWidget2) {
350 CXFA_FFWidget* pWidget1 = (*(CXFA_TabParam**)phWidget1)->m_pWidget; 371 CXFA_FFWidget* pWidget1 = (*(CXFA_TabParam**)phWidget1)->m_pWidget;
351 CXFA_FFWidget* pWidget2 = (*(CXFA_TabParam**)phWidget2)->m_pWidget; 372 CXFA_FFWidget* pWidget2 = (*(CXFA_TabParam**)phWidget2)->m_pWidget;
352 CFX_RectF rt1, rt2; 373 CFX_RectF rt1, rt2;
353 pWidget1->GetWidgetRect(rt1); 374 pWidget1->GetWidgetRect(rt1);
354 pWidget2->GetWidgetRect(rt2); 375 pWidget2->GetWidgetRect(rt2);
355 FX_FLOAT x1 = rt1.left, y1 = rt1.top, x2 = rt2.left, y2 = rt2.top; 376 FX_FLOAT x1 = rt1.left, y1 = rt1.top, x2 = rt2.left, y2 = rt2.top;
356 if (y1 < y2 || (y1 - y2 < XFA_FLOAT_PERCISION && x1 < x2)) { 377 if (y1 < y2 || (y1 - y2 < XFA_FLOAT_PERCISION && x1 < x2)) {
357 return -1; 378 return -1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } else { 421 } else {
401 pSearchItem = sIterator->MoveToNext(); 422 pSearchItem = sIterator->MoveToNext();
402 } 423 }
403 } 424 }
404 int32_t iChildren = tabParams.GetSize(); 425 int32_t iChildren = tabParams.GetSize();
405 if (iChildren > 1) { 426 if (iChildren > 1) {
406 FXSYS_qsort(tabParams.GetData(), iChildren, sizeof(void*), 427 FXSYS_qsort(tabParams.GetData(), iChildren, sizeof(void*),
407 XFA_TabOrderWidgetComparator); 428 XFA_TabOrderWidgetComparator);
408 } 429 }
409 for (int32_t iStart = 0; iStart < iChildren; iStart++) { 430 for (int32_t iStart = 0; iStart < iChildren; iStart++) {
410 CXFA_TabParam* pParam = tabParams[iStart]; 431 std::unique_ptr<CXFA_TabParam> pParam(tabParams[iStart]);
411 pContainer->m_Children.Add(pParam->m_pWidget); 432 pContainer->m_Children.push_back(pParam->m_pWidget);
412 if (pParam->m_Children.GetSize() > 0) { 433 pContainer->m_Children.insert(pContainer->m_Children.end(),
413 pContainer->m_Children.Append(pParam->m_Children); 434 pParam->m_Children.begin(),
414 } 435 pParam->m_Children.end());
415 delete pParam;
416 } 436 }
417 tabParams.RemoveAll(); 437 tabParams.RemoveAll();
418 } 438 }
419 void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray( 439 void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray(
420 CXFA_WidgetArray& WidgetArray) { 440 std::vector<CXFA_FFWidget*>* WidgetArray) {
421 CXFA_LayoutItemIterator sIterator; 441 CXFA_LayoutItemIterator sIterator;
422 sIterator.Init(m_pPageView); 442 sIterator.Init(m_pPageView);
423 CXFA_TabParam* pParam = new CXFA_TabParam; 443 auto pParam = pdfium::MakeUnique<CXFA_TabParam>();
424 bool bCurrentItem = false; 444 bool bCurrentItem = false;
425 bool bContentArea = false; 445 bool bContentArea = false;
426 OrderContainer(&sIterator, nullptr, pParam, bCurrentItem, bContentArea); 446 OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea);
427 if (pParam->m_Children.GetSize() > 0) { 447 WidgetArray->insert(WidgetArray->end(), pParam->m_Children.begin(),
428 WidgetArray.Append(pParam->m_Children); 448 pParam->m_Children.end());
429 } 449
430 sIterator.Reset(); 450 sIterator.Reset();
431 bCurrentItem = false; 451 bCurrentItem = false;
432 bContentArea = false; 452 bContentArea = false;
433 pParam->m_Children.RemoveAll(); 453 pParam->m_Children.clear();
434 OrderContainer(&sIterator, nullptr, pParam, bCurrentItem, bContentArea, true); 454 OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea,
435 if (pParam->m_Children.GetSize() > 0) { 455 true);
436 WidgetArray.Append(pParam->m_Children); 456 WidgetArray->insert(WidgetArray->end(), pParam->m_Children.begin(),
437 } 457 pParam->m_Children.end());
438 delete pParam;
439 } 458 }
459
440 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( 460 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget(
441 CXFA_LayoutItem* pLayoutItem) { 461 CXFA_LayoutItem* pLayoutItem) {
442 if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) { 462 if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) {
443 if (!pWidget->IsLoaded() && 463 if (!pWidget->IsLoaded() &&
444 (pWidget->GetStatus() & XFA_WidgetStatus_Visible)) { 464 (pWidget->GetStatus() & XFA_WidgetStatus_Visible)) {
445 pWidget->LoadWidget(); 465 pWidget->LoadWidget();
446 } 466 }
447 return pWidget; 467 return pWidget;
448 } 468 }
449 return nullptr; 469 return nullptr;
450 } 470 }
451 471
452 CXFA_TabParam::CXFA_TabParam() : m_pWidget(nullptr) {} 472 CXFA_TabParam::CXFA_TabParam() : m_pWidget(nullptr) {}
453 473
454 CXFA_TabParam::~CXFA_TabParam() {} 474 CXFA_TabParam::~CXFA_TabParam() {}
OLDNEW
« no previous file with comments | « no previous file | xfa/fxfa/app/xfa_ffwidget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698