blob: 4c0b3cf63817c1c30623ad6a0b9ba83381334020 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclair80c48782017-03-23 12:11:20 -04007#include "xfa/fxfa/cxfa_ffpageview.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
Tom Sepezb8227822017-03-24 13:10:14 -07009#include <algorithm>
tsepeza0b2d232017-01-23 11:32:36 -080010#include <memory>
11#include <vector>
12
13#include "third_party/base/ptr_util.h"
14#include "third_party/base/stl_util.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040015#include "xfa/fde/fde_render.h"
16#include "xfa/fxfa/app/xfa_ffcheckbutton.h"
17#include "xfa/fxfa/app/xfa_ffchoicelist.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040018#include "xfa/fxfa/app/xfa_fffield.h"
19#include "xfa/fxfa/app/xfa_ffimageedit.h"
20#include "xfa/fxfa/app/xfa_ffpushbutton.h"
21#include "xfa/fxfa/app/xfa_fftextedit.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040022#include "xfa/fxfa/app/xfa_fwladapter.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040023#include "xfa/fxfa/cxfa_ffdoc.h"
24#include "xfa/fxfa/cxfa_ffdocview.h"
25#include "xfa/fxfa/cxfa_ffwidget.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040026
dsinclairacd0d592016-04-21 11:06:27 -070027namespace {
28
Dan Sinclair1b08df12017-02-09 09:17:20 -050029CFX_Matrix GetPageMatrix(const CFX_RectF& docPageRect,
30 const CFX_Rect& devicePageRect,
31 int32_t iRotate,
32 uint32_t dwCoordinatesType) {
dsinclair43854a52016-04-27 12:26:00 -070033 ASSERT(iRotate >= 0 && iRotate <= 3);
Dan Sinclair1b08df12017-02-09 09:17:20 -050034
tsepezd19e9122016-11-02 15:43:18 -070035 bool bFlipX = (dwCoordinatesType & 0x01) != 0;
36 bool bFlipY = (dwCoordinatesType & 0x02) != 0;
Dan Sinclairbba2a7c2017-02-07 16:36:39 -050037 CFX_Matrix m((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0);
dsinclairacd0d592016-04-21 11:06:27 -070038 if (iRotate == 0 || iRotate == 2) {
Dan Sinclair05df0752017-03-14 14:43:42 -040039 m.a *= (float)devicePageRect.width / docPageRect.width;
40 m.d *= (float)devicePageRect.height / docPageRect.height;
dsinclairacd0d592016-04-21 11:06:27 -070041 } else {
Dan Sinclair05df0752017-03-14 14:43:42 -040042 m.a *= (float)devicePageRect.height / docPageRect.width;
43 m.d *= (float)devicePageRect.width / docPageRect.height;
dsinclairacd0d592016-04-21 11:06:27 -070044 }
45 m.Rotate(iRotate * 1.57079632675f);
46 switch (iRotate) {
47 case 0:
Dan Sinclair05df0752017-03-14 14:43:42 -040048 m.e = bFlipX ? (float)devicePageRect.right() : (float)devicePageRect.left;
49 m.f = bFlipY ? (float)devicePageRect.bottom() : (float)devicePageRect.top;
dsinclairacd0d592016-04-21 11:06:27 -070050 break;
51 case 1:
Dan Sinclair05df0752017-03-14 14:43:42 -040052 m.e = bFlipY ? (float)devicePageRect.left : (float)devicePageRect.right();
53 m.f = bFlipX ? (float)devicePageRect.bottom() : (float)devicePageRect.top;
dsinclairacd0d592016-04-21 11:06:27 -070054 break;
55 case 2:
Dan Sinclair05df0752017-03-14 14:43:42 -040056 m.e = bFlipX ? (float)devicePageRect.left : (float)devicePageRect.right();
57 m.f = bFlipY ? (float)devicePageRect.top : (float)devicePageRect.bottom();
dsinclairacd0d592016-04-21 11:06:27 -070058 break;
59 case 3:
Dan Sinclair05df0752017-03-14 14:43:42 -040060 m.e = bFlipY ? (float)devicePageRect.right() : (float)devicePageRect.left;
61 m.f = bFlipX ? (float)devicePageRect.top : (float)devicePageRect.bottom();
dsinclairacd0d592016-04-21 11:06:27 -070062 break;
63 default:
64 break;
65 }
Dan Sinclair1b08df12017-02-09 09:17:20 -050066 return m;
dsinclairacd0d592016-04-21 11:06:27 -070067}
68
dsinclair935d8d52016-05-17 10:32:18 -070069bool PageWidgetFilter(CXFA_FFWidget* pWidget,
70 uint32_t dwFilter,
tsepezd19e9122016-11-02 15:43:18 -070071 bool bTraversal,
72 bool bIgnorerelevant) {
dsinclair935d8d52016-05-17 10:32:18 -070073 CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc();
74
75 if (!!(dwFilter & XFA_WidgetStatus_Focused) &&
dsinclair070fcdf2016-06-22 22:04:54 -070076 pWidgetAcc->GetElementType() != XFA_Element::Field) {
dsinclair935d8d52016-05-17 10:32:18 -070077 return false;
78 }
79
80 uint32_t dwStatus = pWidget->GetStatus();
81 if (bTraversal && (dwStatus & XFA_WidgetStatus_Disabled))
82 return false;
83 if (bIgnorerelevant)
84 return !!(dwStatus & XFA_WidgetStatus_Visible);
85
86 dwFilter &= (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable |
87 XFA_WidgetStatus_Printable);
88 return (dwFilter & dwStatus) == dwFilter;
89}
90
dsinclaird1cf2392016-07-11 06:46:59 -070091bool IsLayoutElement(XFA_Element eElement, bool bLayoutContainer) {
92 switch (eElement) {
93 case XFA_Element::Draw:
94 case XFA_Element::Field:
95 case XFA_Element::InstanceManager:
96 return !bLayoutContainer;
97 case XFA_Element::Area:
98 case XFA_Element::Subform:
99 case XFA_Element::ExclGroup:
100 case XFA_Element::SubformSet:
101 case XFA_Element::PageArea:
102 case XFA_Element::Form:
103 return true;
104 default:
105 return false;
106 }
107}
108
dsinclairacd0d592016-04-21 11:06:27 -0700109} // namespace
dsinclair935d8d52016-05-17 10:32:18 -0700110
Dan Sinclair1770c022016-03-14 14:14:16 -0400111CXFA_FFPageView::CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea)
thestig9f3dbbc2016-04-13 13:18:21 -0700112 : CXFA_ContainerLayoutItem(pPageArea), m_pDocView(pDocView) {}
113
Dan Sinclair1770c022016-03-14 14:14:16 -0400114CXFA_FFPageView::~CXFA_FFPageView() {}
thestig9f3dbbc2016-04-13 13:18:21 -0700115
116CXFA_FFDocView* CXFA_FFPageView::GetDocView() const {
Dan Sinclair1770c022016-03-14 14:14:16 -0400117 return m_pDocView;
118}
thestig9f3dbbc2016-04-13 13:18:21 -0700119
Dan Sinclair1b08df12017-02-09 09:17:20 -0500120CFX_RectF CXFA_FFPageView::GetPageViewRect() const {
121 return CFX_RectF(0, 0, GetPageSize());
Dan Sinclair1770c022016-03-14 14:14:16 -0400122}
dsinclair0b851ff2016-07-21 12:03:01 -0700123
Dan Sinclair1b08df12017-02-09 09:17:20 -0500124CFX_Matrix CXFA_FFPageView::GetDisplayMatrix(const CFX_Rect& rtDisp,
125 int32_t iRotate) const {
126 return GetPageMatrix(CFX_RectF(0, 0, GetPageSize()), rtDisp, iRotate, 0);
Dan Sinclair1770c022016-03-14 14:14:16 -0400127}
thestig9f3dbbc2016-04-13 13:18:21 -0700128
Dan Sinclair1770c022016-03-14 14:14:16 -0400129IXFA_WidgetIterator* CXFA_FFPageView::CreateWidgetIterator(
tsepez736f28a2016-03-25 14:19:51 -0700130 uint32_t dwTraverseWay,
131 uint32_t dwWidgetFilter) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400132 switch (dwTraverseWay) {
133 case XFA_TRAVERSEWAY_Tranvalse:
134 return new CXFA_FFTabOrderPageWidgetIterator(this, dwWidgetFilter);
135 case XFA_TRAVERSEWAY_Form:
136 return new CXFA_FFPageWidgetIterator(this, dwWidgetFilter);
137 }
thestig9f3dbbc2016-04-13 13:18:21 -0700138 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400139}
thestig9f3dbbc2016-04-13 13:18:21 -0700140
Dan Sinclair1770c022016-03-14 14:14:16 -0400141CXFA_FFPageWidgetIterator::CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView,
Tom Sepez312ce172017-03-06 14:00:07 -0800142 uint32_t dwFilter)
143 : m_pPageView(pPageView), m_dwFilter(dwFilter), m_sIterator(pPageView) {
tsepez20d6b762016-06-09 11:46:16 -0700144 m_bIgnorerelevant =
145 m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() <
146 XFA_VERSION_205;
Dan Sinclair1770c022016-03-14 14:14:16 -0400147}
Tom Sepez312ce172017-03-06 14:00:07 -0800148
Dan Sinclair1770c022016-03-14 14:14:16 -0400149CXFA_FFPageWidgetIterator::~CXFA_FFPageWidgetIterator() {}
Tom Sepez312ce172017-03-06 14:00:07 -0800150
Dan Sinclair1770c022016-03-14 14:14:16 -0400151void CXFA_FFPageWidgetIterator::Reset() {
152 m_sIterator.Reset();
153}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700154
dsinclairdf4bc592016-03-31 20:34:43 -0700155CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToFirst() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400156 m_sIterator.Reset();
157 for (CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); pLayoutItem;
158 pLayoutItem = m_sIterator.MoveToNext()) {
dsinclairdf4bc592016-03-31 20:34:43 -0700159 if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400160 return hWidget;
161 }
162 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700163 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400164}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700165
dsinclairdf4bc592016-03-31 20:34:43 -0700166CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToLast() {
dsinclair85d1f2c2016-06-23 12:40:16 -0700167 m_sIterator.SetCurrent(nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400168 return MoveToPrevious();
169}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700170
dsinclairdf4bc592016-03-31 20:34:43 -0700171CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToNext() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400172 for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToNext(); pLayoutItem;
173 pLayoutItem = m_sIterator.MoveToNext()) {
dsinclairdf4bc592016-03-31 20:34:43 -0700174 if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400175 return hWidget;
176 }
177 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700178 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400179}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700180
dsinclairdf4bc592016-03-31 20:34:43 -0700181CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToPrevious() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400182 for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToPrev(); pLayoutItem;
183 pLayoutItem = m_sIterator.MoveToPrev()) {
dsinclairdf4bc592016-03-31 20:34:43 -0700184 if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400185 return hWidget;
186 }
187 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700188 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400189}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700190
dsinclairdf4bc592016-03-31 20:34:43 -0700191CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetCurrentWidget() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400192 CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent();
dsinclair85d1f2c2016-06-23 12:40:16 -0700193 return pLayoutItem ? XFA_GetWidgetFromLayoutItem(pLayoutItem) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400194}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700195
tsepezd19e9122016-11-02 15:43:18 -0700196bool CXFA_FFPageWidgetIterator::SetCurrentWidget(CXFA_FFWidget* hWidget) {
dsinclairdf4bc592016-03-31 20:34:43 -0700197 return hWidget && m_sIterator.SetCurrent(hWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -0400198}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700199
dsinclairdf4bc592016-03-31 20:34:43 -0700200CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetWidget(
Dan Sinclair1770c022016-03-14 14:14:16 -0400201 CXFA_LayoutItem* pLayoutItem) {
Lei Zhangafc8eb32017-03-28 14:32:13 -0700202 CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem);
203 if (!pWidget)
204 return nullptr;
205
206 if (!PageWidgetFilter(pWidget, m_dwFilter, false, m_bIgnorerelevant))
207 return nullptr;
208
209 if (!pWidget->IsLoaded() &&
210 !!(pWidget->GetStatus() & XFA_WidgetStatus_Visible)) {
211 pWidget->LoadWidget();
Dan Sinclair1770c022016-03-14 14:14:16 -0400212 }
Lei Zhangafc8eb32017-03-28 14:32:13 -0700213 return pWidget;
214}
215
216void CXFA_TabParam::AppendTabParam(CXFA_TabParam* pParam) {
217 m_Children.push_back(pParam->GetWidget());
218 m_Children.insert(m_Children.end(), pParam->GetChildren().begin(),
219 pParam->GetChildren().end());
220}
221
222void CXFA_TabParam::ClearChildren() {
223 m_Children.clear();
Dan Sinclair1770c022016-03-14 14:14:16 -0400224}
tsepezcc4d6d82016-05-16 13:21:03 -0700225
Dan Sinclair1770c022016-03-14 14:14:16 -0400226CXFA_FFTabOrderPageWidgetIterator::CXFA_FFTabOrderPageWidgetIterator(
227 CXFA_FFPageView* pPageView,
tsepez736f28a2016-03-25 14:19:51 -0700228 uint32_t dwFilter)
Dan Sinclair1770c022016-03-14 14:14:16 -0400229 : m_pPageView(pPageView), m_dwFilter(dwFilter), m_iCurWidget(-1) {
tsepez20d6b762016-06-09 11:46:16 -0700230 m_bIgnorerelevant =
231 m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() <
232 XFA_VERSION_205;
Dan Sinclair1770c022016-03-14 14:14:16 -0400233 Reset();
234}
tsepezcc4d6d82016-05-16 13:21:03 -0700235
Dan Sinclair1770c022016-03-14 14:14:16 -0400236CXFA_FFTabOrderPageWidgetIterator::~CXFA_FFTabOrderPageWidgetIterator() {}
tsepezcc4d6d82016-05-16 13:21:03 -0700237
Dan Sinclair1770c022016-03-14 14:14:16 -0400238void CXFA_FFTabOrderPageWidgetIterator::Reset() {
239 CreateTabOrderWidgetArray();
240 m_iCurWidget = -1;
241}
tsepeza0b2d232017-01-23 11:32:36 -0800242
dsinclairdf4bc592016-03-31 20:34:43 -0700243CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() {
tsepeza0b2d232017-01-23 11:32:36 -0800244 for (int32_t i = 0;
245 i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
246 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
247 m_bIgnorerelevant)) {
248 m_iCurWidget = i;
249 return m_TabOrderWidgetArray[m_iCurWidget];
Dan Sinclair1770c022016-03-14 14:14:16 -0400250 }
251 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700252 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400253}
tsepeza0b2d232017-01-23 11:32:36 -0800254
dsinclairdf4bc592016-03-31 20:34:43 -0700255CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() {
tsepeza0b2d232017-01-23 11:32:36 -0800256 for (int32_t i = pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) - 1;
257 i >= 0; i--) {
258 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
259 m_bIgnorerelevant)) {
260 m_iCurWidget = i;
261 return m_TabOrderWidgetArray[m_iCurWidget];
Dan Sinclair1770c022016-03-14 14:14:16 -0400262 }
263 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700264 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400265}
tsepeza0b2d232017-01-23 11:32:36 -0800266
dsinclairdf4bc592016-03-31 20:34:43 -0700267CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() {
tsepeza0b2d232017-01-23 11:32:36 -0800268 for (int32_t i = m_iCurWidget + 1;
269 i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
tsepezd19e9122016-11-02 15:43:18 -0700270 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
dsinclair935d8d52016-05-17 10:32:18 -0700271 m_bIgnorerelevant)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400272 m_iCurWidget = i;
273 return m_TabOrderWidgetArray[m_iCurWidget];
274 }
275 }
276 m_iCurWidget = -1;
dsinclair85d1f2c2016-06-23 12:40:16 -0700277 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400278}
tsepeza0b2d232017-01-23 11:32:36 -0800279
dsinclairdf4bc592016-03-31 20:34:43 -0700280CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400281 for (int32_t i = m_iCurWidget - 1; i >= 0; i--) {
tsepezd19e9122016-11-02 15:43:18 -0700282 if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true,
dsinclair935d8d52016-05-17 10:32:18 -0700283 m_bIgnorerelevant)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400284 m_iCurWidget = i;
285 return m_TabOrderWidgetArray[m_iCurWidget];
286 }
287 }
288 m_iCurWidget = -1;
dsinclair85d1f2c2016-06-23 12:40:16 -0700289 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400290}
tsepeza0b2d232017-01-23 11:32:36 -0800291
dsinclairdf4bc592016-03-31 20:34:43 -0700292CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() {
tsepeza0b2d232017-01-23 11:32:36 -0800293 return m_iCurWidget >= 0 ? m_TabOrderWidgetArray[m_iCurWidget] : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400294}
tsepeza0b2d232017-01-23 11:32:36 -0800295
tsepezd19e9122016-11-02 15:43:18 -0700296bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget(
dsinclairdf4bc592016-03-31 20:34:43 -0700297 CXFA_FFWidget* hWidget) {
tsepeza0b2d232017-01-23 11:32:36 -0800298 auto it = std::find(m_TabOrderWidgetArray.begin(),
299 m_TabOrderWidgetArray.end(), hWidget);
300 if (it == m_TabOrderWidgetArray.end())
301 return false;
302
303 m_iCurWidget = it - m_TabOrderWidgetArray.begin();
304 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400305}
tsepeza0b2d232017-01-23 11:32:36 -0800306
Dan Sinclair1770c022016-03-14 14:14:16 -0400307CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget(
308 CXFA_FFWidget* pWidget) {
309 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
dsinclair56a8b192016-06-21 14:15:25 -0700310 CXFA_Node* pTraversal = pAcc->GetNode()->GetChild(0, XFA_Element::Traversal);
Dan Sinclair1770c022016-03-14 14:14:16 -0400311 if (pTraversal) {
dsinclair56a8b192016-06-21 14:15:25 -0700312 CXFA_Node* pTraverse = pTraversal->GetChild(0, XFA_Element::Traverse);
Dan Sinclair1770c022016-03-14 14:14:16 -0400313 if (pTraverse) {
314 CFX_WideString wsTraverseWidgetName;
315 if (pTraverse->GetAttribute(XFA_ATTRIBUTE_Ref, wsTraverseWidgetName)) {
tsepez70c55202016-04-14 15:32:35 -0700316 return FindWidgetByName(wsTraverseWidgetName, pWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -0400317 }
318 }
319 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700320 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400321}
322CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName(
tsepez70c55202016-04-14 15:32:35 -0700323 const CFX_WideString& wsWidgetName,
Dan Sinclair1770c022016-03-14 14:14:16 -0400324 CXFA_FFWidget* pRefWidget) {
325 return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget);
326}
tsepeza0b2d232017-01-23 11:32:36 -0800327
Dan Sinclair1770c022016-03-14 14:14:16 -0400328void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() {
tsepeza0b2d232017-01-23 11:32:36 -0800329 m_TabOrderWidgetArray.clear();
330
331 std::vector<CXFA_FFWidget*> SpaceOrderWidgetArray;
332 CreateSpaceOrderWidgetArray(&SpaceOrderWidgetArray);
333 if (SpaceOrderWidgetArray.empty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400334 return;
tsepeza0b2d232017-01-23 11:32:36 -0800335
336 int32_t nWidgetCount = pdfium::CollectionSize<int32_t>(SpaceOrderWidgetArray);
Dan Sinclair1770c022016-03-14 14:14:16 -0400337 CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0];
tsepeza0b2d232017-01-23 11:32:36 -0800338 while (pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) <
339 nWidgetCount) {
340 if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) {
341 m_TabOrderWidgetArray.push_back(hWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -0400342 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
dsinclair56a8b192016-06-21 14:15:25 -0700343 if (pWidgetAcc->GetUIType() == XFA_Element::ExclGroup) {
tsepeza0b2d232017-01-23 11:32:36 -0800344 auto it = std::find(SpaceOrderWidgetArray.begin(),
345 SpaceOrderWidgetArray.end(), hWidget);
346 int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end()
347 ? it - SpaceOrderWidgetArray.begin() + 1
348 : 0;
tsepezd19e9122016-11-02 15:43:18 -0700349 while (true) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400350 CXFA_FFWidget* pRadio =
tsepeza0b2d232017-01-23 11:32:36 -0800351 SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount];
Dan Sinclair1770c022016-03-14 14:14:16 -0400352 if (pRadio->GetDataAcc()->GetExclGroup() != pWidgetAcc) {
353 break;
354 }
tsepeza0b2d232017-01-23 11:32:36 -0800355 if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) {
356 m_TabOrderWidgetArray.push_back(pRadio);
Dan Sinclair1770c022016-03-14 14:14:16 -0400357 }
358 iWidgetIndex++;
359 }
360 }
361 if (CXFA_FFWidget* hTraverseWidget = GetTraverseWidget(hWidget)) {
362 hWidget = hTraverseWidget;
363 continue;
364 }
365 }
tsepeza0b2d232017-01-23 11:32:36 -0800366 auto it = std::find(SpaceOrderWidgetArray.begin(),
367 SpaceOrderWidgetArray.end(), hWidget);
368 int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end()
369 ? it - SpaceOrderWidgetArray.begin() + 1
370 : 0;
371 hWidget = SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount];
Dan Sinclair1770c022016-03-14 14:14:16 -0400372 }
373}
tsepeza0b2d232017-01-23 11:32:36 -0800374
Dan Sinclair1770c022016-03-14 14:14:16 -0400375void CXFA_FFTabOrderPageWidgetIterator::OrderContainer(
376 CXFA_LayoutItemIterator* sIterator,
377 CXFA_LayoutItem* pContainerItem,
378 CXFA_TabParam* pContainer,
tsepezd19e9122016-11-02 15:43:18 -0700379 bool& bCurrentItem,
380 bool& bContentArea,
381 bool bMarsterPage) {
Tom Sepezb8227822017-03-24 13:10:14 -0700382 std::vector<std::unique_ptr<CXFA_TabParam>> tabParams;
Dan Sinclair1770c022016-03-14 14:14:16 -0400383 CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext();
384 while (pSearchItem) {
385 if (!pSearchItem->IsContentLayoutItem()) {
tsepezd19e9122016-11-02 15:43:18 -0700386 bContentArea = true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400387 pSearchItem = sIterator->MoveToNext();
388 continue;
389 }
390 if (bMarsterPage && bContentArea) {
391 break;
392 }
393 if (bMarsterPage || bContentArea) {
394 CXFA_FFWidget* hWidget = GetWidget(pSearchItem);
395 if (!hWidget) {
396 pSearchItem = sIterator->MoveToNext();
397 continue;
398 }
399 if (pContainerItem && (pSearchItem->GetParent() != pContainerItem)) {
tsepezd19e9122016-11-02 15:43:18 -0700400 bCurrentItem = true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400401 break;
402 }
Tom Sepezb8227822017-03-24 13:10:14 -0700403 tabParams.push_back(pdfium::MakeUnique<CXFA_TabParam>(hWidget));
dsinclaird1cf2392016-07-11 06:46:59 -0700404 if (IsLayoutElement(pSearchItem->GetFormNode()->GetElementType(), true)) {
Tom Sepezb8227822017-03-24 13:10:14 -0700405 OrderContainer(sIterator, pSearchItem, tabParams.back().get(),
406 bCurrentItem, bContentArea, bMarsterPage);
Dan Sinclair1770c022016-03-14 14:14:16 -0400407 }
408 }
409 if (bCurrentItem) {
410 pSearchItem = sIterator->GetCurrent();
tsepezd19e9122016-11-02 15:43:18 -0700411 bCurrentItem = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400412 } else {
413 pSearchItem = sIterator->MoveToNext();
414 }
415 }
Tom Sepezb8227822017-03-24 13:10:14 -0700416 std::sort(tabParams.begin(), tabParams.end(),
417 [](const std::unique_ptr<CXFA_TabParam>& arg1,
418 const std::unique_ptr<CXFA_TabParam>& arg2) {
Lei Zhangafc8eb32017-03-28 14:32:13 -0700419 const CFX_RectF& rt1 = arg1->GetWidget()->GetWidgetRect();
420 const CFX_RectF& rt2 = arg2->GetWidget()->GetWidgetRect();
Tom Sepezb8227822017-03-24 13:10:14 -0700421 if (rt1.top - rt2.top >= XFA_FLOAT_PERCISION)
422 return rt1.top < rt2.top;
423 return rt1.left < rt2.left;
424 });
Lei Zhangafc8eb32017-03-28 14:32:13 -0700425 for (const auto& pParam : tabParams)
426 pContainer->AppendTabParam(pParam.get());
Dan Sinclair1770c022016-03-14 14:14:16 -0400427}
Lei Zhangafc8eb32017-03-28 14:32:13 -0700428
Dan Sinclair1770c022016-03-14 14:14:16 -0400429void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray(
tsepeza0b2d232017-01-23 11:32:36 -0800430 std::vector<CXFA_FFWidget*>* WidgetArray) {
Tom Sepez312ce172017-03-06 14:00:07 -0800431 CXFA_LayoutItemIterator sIterator(m_pPageView);
Tom Sepezb8227822017-03-24 13:10:14 -0700432 auto pParam = pdfium::MakeUnique<CXFA_TabParam>(nullptr);
tsepezd19e9122016-11-02 15:43:18 -0700433 bool bCurrentItem = false;
434 bool bContentArea = false;
tsepeza0b2d232017-01-23 11:32:36 -0800435 OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea);
Lei Zhangafc8eb32017-03-28 14:32:13 -0700436 WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(),
437 pParam->GetChildren().end());
tsepeza0b2d232017-01-23 11:32:36 -0800438
Dan Sinclair1770c022016-03-14 14:14:16 -0400439 sIterator.Reset();
tsepezd19e9122016-11-02 15:43:18 -0700440 bCurrentItem = false;
441 bContentArea = false;
Lei Zhangafc8eb32017-03-28 14:32:13 -0700442 pParam->ClearChildren();
tsepeza0b2d232017-01-23 11:32:36 -0800443 OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea,
444 true);
Lei Zhangafc8eb32017-03-28 14:32:13 -0700445 WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(),
446 pParam->GetChildren().end());
Dan Sinclair1770c022016-03-14 14:14:16 -0400447}
tsepeza0b2d232017-01-23 11:32:36 -0800448
Dan Sinclair1770c022016-03-14 14:14:16 -0400449CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget(
450 CXFA_LayoutItem* pLayoutItem) {
451 if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) {
452 if (!pWidget->IsLoaded() &&
dsinclair935d8d52016-05-17 10:32:18 -0700453 (pWidget->GetStatus() & XFA_WidgetStatus_Visible)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400454 pWidget->LoadWidget();
455 }
456 return pWidget;
457 }
dsinclair85d1f2c2016-06-23 12:40:16 -0700458 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400459}
weili47bcd4c2016-06-16 08:00:06 -0700460
Tom Sepezb8227822017-03-24 13:10:14 -0700461CXFA_TabParam::CXFA_TabParam(CXFA_FFWidget* pWidget) : m_pWidget(pWidget) {}
weili47bcd4c2016-06-16 08:00:06 -0700462
463CXFA_TabParam::~CXFA_TabParam() {}