OLD | NEW |
| (Empty) |
1 // 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 | |
7 #include "xfa/src/fxfa/app/xfa_ffpageview.h" | |
8 | |
9 #include "xfa/src/fde/fde_render.h" | |
10 #include "xfa/src/fxfa/app/xfa_ffcheckbutton.h" | |
11 #include "xfa/src/fxfa/app/xfa_ffchoicelist.h" | |
12 #include "xfa/src/fxfa/app/xfa_ffdoc.h" | |
13 #include "xfa/src/fxfa/app/xfa_ffdocview.h" | |
14 #include "xfa/src/fxfa/app/xfa_fffield.h" | |
15 #include "xfa/src/fxfa/app/xfa_ffimageedit.h" | |
16 #include "xfa/src/fxfa/app/xfa_ffpushbutton.h" | |
17 #include "xfa/src/fxfa/app/xfa_fftextedit.h" | |
18 #include "xfa/src/fxfa/app/xfa_ffwidget.h" | |
19 #include "xfa/src/fxfa/app/xfa_fwladapter.h" | |
20 | |
21 CXFA_FFPageView::CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea) | |
22 : CXFA_ContainerLayoutItem(pPageArea), | |
23 m_pDocView(pDocView), | |
24 m_bLoaded(FALSE) {} | |
25 CXFA_FFPageView::~CXFA_FFPageView() {} | |
26 IXFA_DocView* CXFA_FFPageView::GetDocView() { | |
27 return m_pDocView; | |
28 } | |
29 int32_t CXFA_FFPageView::GetPageViewIndex() { | |
30 return GetPageIndex(); | |
31 } | |
32 void CXFA_FFPageView::GetPageViewRect(CFX_RectF& rtPage) { | |
33 CFX_SizeF sz; | |
34 GetPageSize(sz); | |
35 rtPage.Set(0, 0, sz); | |
36 } | |
37 void CXFA_FFPageView::GetDisplayMatrix(CFX_Matrix& mt, | |
38 const CFX_Rect& rtDisp, | |
39 int32_t iRotate) { | |
40 CFX_SizeF sz; | |
41 GetPageSize(sz); | |
42 CFX_RectF fdePage; | |
43 fdePage.Set(0, 0, sz.x, sz.y); | |
44 FDE_GetPageMatrix(mt, fdePage, rtDisp, iRotate, 0); | |
45 } | |
46 int32_t CXFA_FFPageView::LoadPageView(IFX_Pause* pPause) { | |
47 if (m_bLoaded) { | |
48 return 100; | |
49 } | |
50 m_bLoaded = TRUE; | |
51 return 100; | |
52 } | |
53 void CXFA_FFPageView::UnloadPageView() { | |
54 if (!m_bLoaded) { | |
55 return; | |
56 } | |
57 } | |
58 FX_BOOL CXFA_FFPageView::IsPageViewLoaded() { | |
59 return m_bLoaded; | |
60 } | |
61 IXFA_Widget* CXFA_FFPageView::GetWidgetByPos(FX_FLOAT fx, FX_FLOAT fy) { | |
62 if (!m_bLoaded) { | |
63 return nullptr; | |
64 } | |
65 IXFA_WidgetIterator* pIterator = CreateWidgetIterator(); | |
66 CXFA_FFWidget* pWidget = nullptr; | |
67 while ((pWidget = static_cast<CXFA_FFWidget*>(pIterator->MoveToNext()))) { | |
68 if (!(pWidget->GetStatus() & XFA_WIDGETSTATUS_Visible)) { | |
69 continue; | |
70 } | |
71 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); | |
72 int32_t type = pAcc->GetClassID(); | |
73 if (type != XFA_ELEMENT_Field && type != XFA_ELEMENT_Draw) { | |
74 continue; | |
75 } | |
76 FX_FLOAT fWidgetx = fx; | |
77 FX_FLOAT fWidgety = fy; | |
78 pWidget->Rotate2Normal(fWidgetx, fWidgety); | |
79 FX_DWORD dwFlag = pWidget->OnHitTest(fWidgetx, fWidgety); | |
80 if ((FWL_WGTHITTEST_Client == dwFlag || | |
81 FWL_WGTHITTEST_HyperLink == dwFlag)) { | |
82 break; | |
83 } | |
84 } | |
85 pIterator->Release(); | |
86 return pWidget; | |
87 } | |
88 IXFA_WidgetIterator* CXFA_FFPageView::CreateWidgetIterator( | |
89 FX_DWORD dwTraverseWay, | |
90 FX_DWORD dwWidgetFilter) { | |
91 switch (dwTraverseWay) { | |
92 case XFA_TRAVERSEWAY_Tranvalse: | |
93 return new CXFA_FFTabOrderPageWidgetIterator(this, dwWidgetFilter); | |
94 case XFA_TRAVERSEWAY_Form: | |
95 return new CXFA_FFPageWidgetIterator(this, dwWidgetFilter); | |
96 } | |
97 return NULL; | |
98 } | |
99 static FX_BOOL XFA_PageWidgetFilter(CXFA_FFWidget* pWidget, | |
100 FX_DWORD dwFilter, | |
101 FX_BOOL bTraversal, | |
102 FX_BOOL bIgnorerelevant) { | |
103 CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); | |
104 FX_DWORD dwType = dwFilter & XFA_WIDGETFILTER_AllType; | |
105 if ((dwType == XFA_WIDGETFILTER_Field) && | |
106 (pWidgetAcc->GetClassID() != XFA_ELEMENT_Field)) { | |
107 return FALSE; | |
108 } | |
109 FX_DWORD dwStatus = pWidget->GetStatus(); | |
110 if (bTraversal && (dwStatus & XFA_WIDGETSTATUS_Disabled)) { | |
111 return FALSE; | |
112 } | |
113 if (bIgnorerelevant) { | |
114 return (dwStatus & XFA_WIDGETFILTER_Visible) != 0; | |
115 } | |
116 dwFilter &= (XFA_WIDGETFILTER_Visible | XFA_WIDGETFILTER_Viewable | | |
117 XFA_WIDGETFILTER_Printable); | |
118 return (dwFilter & dwStatus) == dwFilter; | |
119 } | |
120 CXFA_FFPageWidgetIterator::CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView, | |
121 FX_DWORD dwFilter) { | |
122 m_pPageView = pPageView; | |
123 m_dwFilter = dwFilter; | |
124 m_sIterator.Init(pPageView); | |
125 m_bIgnorerelevant = ((CXFA_FFDoc*)m_pPageView->GetDocView()->GetDoc()) | |
126 ->GetXFADoc() | |
127 ->GetCurVersionMode() < XFA_VERSION_205; | |
128 } | |
129 CXFA_FFPageWidgetIterator::~CXFA_FFPageWidgetIterator() {} | |
130 void CXFA_FFPageWidgetIterator::Reset() { | |
131 m_sIterator.Reset(); | |
132 } | |
133 IXFA_Widget* CXFA_FFPageWidgetIterator::MoveToFirst() { | |
134 m_sIterator.Reset(); | |
135 for (CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); pLayoutItem; | |
136 pLayoutItem = m_sIterator.MoveToNext()) { | |
137 if (IXFA_Widget* hWidget = GetWidget(pLayoutItem)) { | |
138 return hWidget; | |
139 } | |
140 } | |
141 return NULL; | |
142 } | |
143 IXFA_Widget* CXFA_FFPageWidgetIterator::MoveToLast() { | |
144 m_sIterator.SetCurrent(NULL); | |
145 return MoveToPrevious(); | |
146 } | |
147 IXFA_Widget* CXFA_FFPageWidgetIterator::MoveToNext() { | |
148 for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToNext(); pLayoutItem; | |
149 pLayoutItem = m_sIterator.MoveToNext()) { | |
150 if (IXFA_Widget* hWidget = GetWidget(pLayoutItem)) { | |
151 return hWidget; | |
152 } | |
153 } | |
154 return NULL; | |
155 } | |
156 IXFA_Widget* CXFA_FFPageWidgetIterator::MoveToPrevious() { | |
157 for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToPrev(); pLayoutItem; | |
158 pLayoutItem = m_sIterator.MoveToPrev()) { | |
159 if (IXFA_Widget* hWidget = GetWidget(pLayoutItem)) { | |
160 return hWidget; | |
161 } | |
162 } | |
163 return NULL; | |
164 } | |
165 IXFA_Widget* CXFA_FFPageWidgetIterator::GetCurrentWidget() { | |
166 CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); | |
167 return pLayoutItem ? XFA_GetWidgetFromLayoutItem(pLayoutItem) : NULL; | |
168 } | |
169 FX_BOOL CXFA_FFPageWidgetIterator::SetCurrentWidget(IXFA_Widget* hWidget) { | |
170 CXFA_FFWidget* pWidget = static_cast<CXFA_FFWidget*>(hWidget); | |
171 return pWidget && m_sIterator.SetCurrent(pWidget); | |
172 } | |
173 IXFA_Widget* CXFA_FFPageWidgetIterator::GetWidget( | |
174 CXFA_LayoutItem* pLayoutItem) { | |
175 if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) { | |
176 if (!XFA_PageWidgetFilter(pWidget, m_dwFilter, FALSE, m_bIgnorerelevant)) { | |
177 return NULL; | |
178 } | |
179 if (!pWidget->IsLoaded() && | |
180 (pWidget->GetStatus() & XFA_WIDGETSTATUS_Visible) != 0) { | |
181 pWidget->LoadWidget(); | |
182 } | |
183 return pWidget; | |
184 } | |
185 return NULL; | |
186 } | |
187 CXFA_FFTabOrderPageWidgetIterator::CXFA_FFTabOrderPageWidgetIterator( | |
188 CXFA_FFPageView* pPageView, | |
189 FX_DWORD dwFilter) | |
190 : m_pPageView(pPageView), m_dwFilter(dwFilter), m_iCurWidget(-1) { | |
191 m_bIgnorerelevant = ((CXFA_FFDoc*)m_pPageView->GetDocView()->GetDoc()) | |
192 ->GetXFADoc() | |
193 ->GetCurVersionMode() < XFA_VERSION_205; | |
194 Reset(); | |
195 } | |
196 CXFA_FFTabOrderPageWidgetIterator::~CXFA_FFTabOrderPageWidgetIterator() {} | |
197 void CXFA_FFTabOrderPageWidgetIterator::Release() { | |
198 delete this; | |
199 } | |
200 void CXFA_FFTabOrderPageWidgetIterator::Reset() { | |
201 CreateTabOrderWidgetArray(); | |
202 m_iCurWidget = -1; | |
203 } | |
204 IXFA_Widget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() { | |
205 if (m_TabOrderWidgetArray.GetSize() > 0) { | |
206 for (int32_t i = 0; i < m_TabOrderWidgetArray.GetSize(); i++) { | |
207 if (XFA_PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, TRUE, | |
208 m_bIgnorerelevant)) { | |
209 m_iCurWidget = i; | |
210 return m_TabOrderWidgetArray[m_iCurWidget]; | |
211 } | |
212 } | |
213 } | |
214 return NULL; | |
215 } | |
216 IXFA_Widget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() { | |
217 if (m_TabOrderWidgetArray.GetSize() > 0) { | |
218 for (int32_t i = m_TabOrderWidgetArray.GetSize() - 1; i >= 0; i--) { | |
219 if (XFA_PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, TRUE, | |
220 m_bIgnorerelevant)) { | |
221 m_iCurWidget = i; | |
222 return m_TabOrderWidgetArray[m_iCurWidget]; | |
223 } | |
224 } | |
225 } | |
226 return NULL; | |
227 } | |
228 IXFA_Widget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() { | |
229 for (int32_t i = m_iCurWidget + 1; i < m_TabOrderWidgetArray.GetSize(); i++) { | |
230 if (XFA_PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, TRUE, | |
231 m_bIgnorerelevant)) { | |
232 m_iCurWidget = i; | |
233 return m_TabOrderWidgetArray[m_iCurWidget]; | |
234 } | |
235 } | |
236 m_iCurWidget = -1; | |
237 return NULL; | |
238 } | |
239 IXFA_Widget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() { | |
240 for (int32_t i = m_iCurWidget - 1; i >= 0; i--) { | |
241 if (XFA_PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, TRUE, | |
242 m_bIgnorerelevant)) { | |
243 m_iCurWidget = i; | |
244 return m_TabOrderWidgetArray[m_iCurWidget]; | |
245 } | |
246 } | |
247 m_iCurWidget = -1; | |
248 return NULL; | |
249 } | |
250 IXFA_Widget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() { | |
251 if (m_iCurWidget >= 0) { | |
252 return m_TabOrderWidgetArray[m_iCurWidget]; | |
253 } | |
254 return NULL; | |
255 } | |
256 FX_BOOL CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget( | |
257 IXFA_Widget* hWidget) { | |
258 int32_t iWidgetIndex = | |
259 m_TabOrderWidgetArray.Find(static_cast<CXFA_FFWidget*>(hWidget)); | |
260 if (iWidgetIndex >= 0) { | |
261 m_iCurWidget = iWidgetIndex; | |
262 return TRUE; | |
263 } | |
264 return FALSE; | |
265 } | |
266 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget( | |
267 CXFA_FFWidget* pWidget) { | |
268 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); | |
269 CXFA_Node* pTraversal = pAcc->GetNode()->GetChild(0, XFA_ELEMENT_Traversal); | |
270 if (pTraversal) { | |
271 CXFA_Node* pTraverse = pTraversal->GetChild(0, XFA_ELEMENT_Traverse); | |
272 if (pTraverse) { | |
273 CFX_WideString wsTraverseWidgetName; | |
274 if (pTraverse->GetAttribute(XFA_ATTRIBUTE_Ref, wsTraverseWidgetName)) { | |
275 return FindWidgetByName(wsTraverseWidgetName, pWidget); | |
276 } | |
277 } | |
278 } | |
279 return NULL; | |
280 } | |
281 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName( | |
282 const CFX_WideStringC& wsWidgetName, | |
283 CXFA_FFWidget* pRefWidget) { | |
284 return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget); | |
285 } | |
286 void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { | |
287 m_TabOrderWidgetArray.RemoveAll(); | |
288 CXFA_WidgetArray SpaceOrderWidgetArray; | |
289 CreateSpaceOrderWidgetArray(SpaceOrderWidgetArray); | |
290 int32_t nWidgetCount = SpaceOrderWidgetArray.GetSize(); | |
291 if (nWidgetCount < 1) { | |
292 return; | |
293 } | |
294 CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0]; | |
295 for (; m_TabOrderWidgetArray.GetSize() < nWidgetCount;) { | |
296 if (m_TabOrderWidgetArray.Find(hWidget) < 0) { | |
297 m_TabOrderWidgetArray.Add(hWidget); | |
298 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); | |
299 if (pWidgetAcc->GetUIType() == XFA_ELEMENT_ExclGroup) { | |
300 int32_t iWidgetIndex = SpaceOrderWidgetArray.Find(hWidget) + 1; | |
301 while (TRUE) { | |
302 CXFA_FFWidget* pRadio = | |
303 SpaceOrderWidgetArray[(iWidgetIndex) % nWidgetCount]; | |
304 if (pRadio->GetDataAcc()->GetExclGroup() != pWidgetAcc) { | |
305 break; | |
306 } | |
307 if (m_TabOrderWidgetArray.Find(hWidget) < 0) { | |
308 m_TabOrderWidgetArray.Add(pRadio); | |
309 } | |
310 iWidgetIndex++; | |
311 } | |
312 } | |
313 if (CXFA_FFWidget* hTraverseWidget = GetTraverseWidget(hWidget)) { | |
314 hWidget = hTraverseWidget; | |
315 continue; | |
316 } | |
317 } | |
318 int32_t iWidgetIndex = SpaceOrderWidgetArray.Find(hWidget); | |
319 hWidget = SpaceOrderWidgetArray[(iWidgetIndex + 1) % nWidgetCount]; | |
320 } | |
321 } | |
322 static int32_t XFA_TabOrderWidgetComparator(const void* phWidget1, | |
323 const void* phWidget2) { | |
324 CXFA_FFWidget* pWidget1 = (*(CXFA_TabParam**)phWidget1)->m_pWidget; | |
325 CXFA_FFWidget* pWidget2 = (*(CXFA_TabParam**)phWidget2)->m_pWidget; | |
326 CFX_RectF rt1, rt2; | |
327 pWidget1->GetWidgetRect(rt1); | |
328 pWidget2->GetWidgetRect(rt2); | |
329 FX_FLOAT x1 = rt1.left, y1 = rt1.top, x2 = rt2.left, y2 = rt2.top; | |
330 if (y1 < y2 || (y1 - y2 < XFA_FLOAT_PERCISION && x1 < x2)) { | |
331 return -1; | |
332 } | |
333 return 1; | |
334 } | |
335 void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( | |
336 CXFA_LayoutItemIterator* sIterator, | |
337 CXFA_LayoutItem* pContainerItem, | |
338 CXFA_TabParam* pContainer, | |
339 FX_BOOL& bCurrentItem, | |
340 FX_BOOL& bContentArea, | |
341 FX_BOOL bMarsterPage) { | |
342 CFX_PtrArray tabParams; | |
343 CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext(); | |
344 while (pSearchItem) { | |
345 if (!pSearchItem->IsContentLayoutItem()) { | |
346 bContentArea = TRUE; | |
347 pSearchItem = sIterator->MoveToNext(); | |
348 continue; | |
349 } | |
350 if (bMarsterPage && bContentArea) { | |
351 break; | |
352 } | |
353 if (bMarsterPage || bContentArea) { | |
354 CXFA_FFWidget* hWidget = GetWidget(pSearchItem); | |
355 if (!hWidget) { | |
356 pSearchItem = sIterator->MoveToNext(); | |
357 continue; | |
358 } | |
359 if (pContainerItem && (pSearchItem->GetParent() != pContainerItem)) { | |
360 bCurrentItem = TRUE; | |
361 break; | |
362 } | |
363 CXFA_TabParam* pParam = new CXFA_TabParam; | |
364 pParam->m_pWidget = hWidget; | |
365 tabParams.Add(pParam); | |
366 if (XFA_IsLayoutElement(pSearchItem->GetFormNode()->GetClassID(), TRUE)) { | |
367 OrderContainer(sIterator, pSearchItem, pParam, bCurrentItem, | |
368 bContentArea, bMarsterPage); | |
369 } | |
370 } | |
371 if (bCurrentItem) { | |
372 pSearchItem = sIterator->GetCurrent(); | |
373 bCurrentItem = FALSE; | |
374 } else { | |
375 pSearchItem = sIterator->MoveToNext(); | |
376 } | |
377 } | |
378 int32_t iChildren = tabParams.GetSize(); | |
379 if (iChildren > 1) { | |
380 FXSYS_qsort(tabParams.GetData(), iChildren, sizeof(void*), | |
381 XFA_TabOrderWidgetComparator); | |
382 } | |
383 for (int32_t iStart = 0; iStart < iChildren; iStart++) { | |
384 CXFA_TabParam* pParam = (CXFA_TabParam*)tabParams[iStart]; | |
385 pContainer->m_Children.Add(pParam->m_pWidget); | |
386 if (pParam->m_Children.GetSize() > 0) { | |
387 pContainer->m_Children.Append(pParam->m_Children); | |
388 } | |
389 delete pParam; | |
390 } | |
391 tabParams.RemoveAll(); | |
392 } | |
393 void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray( | |
394 CXFA_WidgetArray& WidgetArray) { | |
395 CXFA_LayoutItemIterator sIterator; | |
396 sIterator.Init(m_pPageView); | |
397 CXFA_TabParam* pParam = new CXFA_TabParam; | |
398 FX_BOOL bCurrentItem = FALSE; | |
399 FX_BOOL bContentArea = FALSE; | |
400 OrderContainer(&sIterator, NULL, pParam, bCurrentItem, bContentArea); | |
401 if (pParam->m_Children.GetSize() > 0) { | |
402 WidgetArray.Append(pParam->m_Children); | |
403 } | |
404 sIterator.Reset(); | |
405 bCurrentItem = FALSE; | |
406 bContentArea = FALSE; | |
407 pParam->m_Children.RemoveAll(); | |
408 OrderContainer(&sIterator, NULL, pParam, bCurrentItem, bContentArea, TRUE); | |
409 if (pParam->m_Children.GetSize() > 0) { | |
410 WidgetArray.Append(pParam->m_Children); | |
411 } | |
412 delete pParam; | |
413 } | |
414 CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( | |
415 CXFA_LayoutItem* pLayoutItem) { | |
416 if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) { | |
417 if (!pWidget->IsLoaded() && | |
418 (pWidget->GetStatus() & XFA_WIDGETSTATUS_Visible)) { | |
419 pWidget->LoadWidget(); | |
420 } | |
421 return pWidget; | |
422 } | |
423 return NULL; | |
424 } | |
OLD | NEW |