7#include "xfa/fxfa/cxfa_ffpageview.h"
12#include "core/fxcrt/stl_util.h"
13#include "fxjs/gc/container_trace.h"
14#include "fxjs/xfa/cjx_object.h"
15#include "third_party/base/check.h"
16#include "third_party/base/containers/contains.h"
17#include "xfa/fxfa/cxfa_ffcheckbutton.h"
18#include "xfa/fxfa/cxfa_ffdoc.h"
19#include "xfa/fxfa/cxfa_ffdocview.h"
20#include "xfa/fxfa/cxfa_fffield.h"
21#include "xfa/fxfa/cxfa_ffimageedit.h"
22#include "xfa/fxfa/cxfa_ffpushbutton.h"
23#include "xfa/fxfa/cxfa_ffwidget.h"
24#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h"
25#include "xfa/fxfa/parser/cxfa_node.h"
26#include "xfa/fxfa/parser/cxfa_traversal.h"
27#include "xfa/fxfa/parser/cxfa_traverse.h"
38 if (iRotate == 0 || iRotate == 2) {
72 bool bIgnoreRelevant) {
106CXFA_Document* GetDocForPageView(
const CXFA_FFPageView* view) {
110bool IsDocVersionBelow205(
const CXFA_Document* doc) {
128 EnsureWidgetLoadedIfVisible(pWidget);
135 bool bIgnoreRelevant) {
140 if (!PageWidgetFilter(pWidget, dwFilter,
false, bIgnoreRelevant))
143 if (!EnsureWidgetLoadedIfVisible(pWidget))
151 CXFA_TabParam() =
default;
153 : m_pItem(pWidget->GetLayoutItem()) {}
154 CXFA_TabParam(
const CXFA_TabParam&) =
delete;
155 CXFA_TabParam(CXFA_TabParam&&)
noexcept =
default;
156 ~CXFA_TabParam() =
default;
158 CXFA_TabParam& operator=(
const CXFA_TabParam&) =
delete;
159 CXFA_TabParam& operator=(CXFA_TabParam&&)
noexcept =
default;
161 CXFA_FFWidget* GetWidget()
const {
return m_pItem->GetFFWidget(); }
162 const std::vector<cppgc::Persistent<CXFA_ContentLayoutItem>>& GetChildren()
166 void ClearChildren() { m_Children.clear(); }
167 void AppendTabParam(
const CXFA_TabParam* pParam) {
168 m_Children.push_back(pParam->m_pItem);
169 m_Children.insert(m_Children.end(), pParam->m_Children.begin(),
170 pParam->m_Children.end());
174 cppgc::Persistent<CXFA_ContentLayoutItem> m_pItem;
175 std::vector<cppgc::Persistent<CXFA_ContentLayoutItem>> m_Children;
178void OrderContainer(CXFA_LayoutItemIterator* sIterator,
180 CXFA_TabParam* pContainer,
184 std::vector<CXFA_TabParam> tabParams;
186 while (pSearchItem) {
188 *bContentArea =
true;
189 pSearchItem = sIterator->MoveToNext();
192 if (bMasterPage && *bContentArea) {
195 if (bMasterPage || *bContentArea) {
196 CXFA_FFWidget* hWidget = LoadedWidgetFromLayoutItem(pSearchItem);
198 pSearchItem = sIterator->MoveToNext();
201 if (pViewItem && (pSearchItem->GetParent() != pViewItem)) {
202 *bCurrentItem =
true;
205 tabParams.emplace_back(hWidget);
207 OrderContainer(sIterator, pSearchItem, &tabParams.back(), bCurrentItem,
208 bContentArea, bMasterPage);
212 pSearchItem = sIterator->GetCurrent();
213 *bCurrentItem =
false;
215 pSearchItem = sIterator->MoveToNext();
218 std::sort(tabParams.begin(), tabParams.end(),
219 [](
const CXFA_TabParam& arg1,
const CXFA_TabParam& arg2) {
226 for (
const auto& param : tabParams)
227 pContainer->AppendTabParam(¶m);
233 : m_pPageArea(pPageArea), m_pDocView(pDocView) {}
237void CXFA_FFPageView::Trace(
cppgc::Visitor* visitor)
const {
238 visitor->Trace(m_pPageArea);
239 visitor->Trace(m_pDocView);
240 visitor->Trace(m_pLayoutItem);
256 int32_t iRotate)
const {
266 return cppgc::MakeGarbageCollected<CXFA_FFTabOrderPageWidgetIterator>(
267 GetDocView()->GetDoc()->GetHeap()->GetAllocationHandle(),
this,
272 CXFA_FFPageView* pPageView,
276 m_bIgnoreRelevant(IsDocVersionBelow205(GetDocForPageView(pPageView))) {}
282 for (
CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); pLayoutItem;
283 pLayoutItem = m_sIterator.MoveToNext()) {
285 pLayoutItem, m_dwFilter, m_bIgnoreRelevant);
293 m_sIterator.SetCurrent(
nullptr);
298 for (
CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToNext(); pLayoutItem;
299 pLayoutItem = m_sIterator.MoveToNext()) {
301 pLayoutItem, m_dwFilter, m_bIgnoreRelevant);
309 for (
CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToPrev(); pLayoutItem;
310 pLayoutItem = m_sIterator.MoveToPrev()) {
312 pLayoutItem, m_dwFilter, m_bIgnoreRelevant);
325 return pWidget && m_sIterator.SetCurrent(pWidget->GetLayoutItem());
328CXFA_FFTabOrderPageWidgetIterator::CXFA_FFTabOrderPageWidgetIterator(
329 CXFA_FFPageView* pPageView,
331 : m_pPageViewLayout(pPageView->GetLayoutItem()),
332 m_dwFilter(dwFilter),
333 m_bIgnoreRelevant(IsDocVersionBelow205(GetDocForPageView(pPageView))) {
334 CreateTabOrderWidgetArray();
340void CXFA_FFTabOrderPageWidgetIterator::Trace(
cppgc::Visitor* visitor)
const {
341 visitor->Trace(m_pPageViewLayout);
342 ContainerTrace(visitor, m_TabOrderWidgetArray);
346 for (int32_t i = 0; i < fxcrt::CollectionSize<int32_t>(m_TabOrderWidgetArray);
348 if (PageWidgetFilter(m_TabOrderWidgetArray[i]->GetFFWidget(), m_dwFilter,
349 true, m_bIgnoreRelevant)) {
351 return m_TabOrderWidgetArray[m_iCurWidget]->GetFFWidget();
358 for (int32_t i = fxcrt::CollectionSize<int32_t>(m_TabOrderWidgetArray) - 1;
360 if (PageWidgetFilter(m_TabOrderWidgetArray[i]->GetFFWidget(), m_dwFilter,
361 true, m_bIgnoreRelevant)) {
363 return m_TabOrderWidgetArray[m_iCurWidget]->GetFFWidget();
370 for (int32_t i = m_iCurWidget + 1;
371 i < fxcrt::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) {
372 if (PageWidgetFilter(m_TabOrderWidgetArray[i]->GetFFWidget(), m_dwFilter,
373 true, m_bIgnoreRelevant)) {
375 return m_TabOrderWidgetArray[m_iCurWidget]->GetFFWidget();
383 for (int32_t i = m_iCurWidget - 1; i >= 0; i--) {
384 if (PageWidgetFilter(m_TabOrderWidgetArray[i]->GetFFWidget(), m_dwFilter,
385 true, m_bIgnoreRelevant)) {
387 return m_TabOrderWidgetArray[m_iCurWidget]->GetFFWidget();
395 return m_iCurWidget >= 0 ? m_TabOrderWidgetArray[m_iCurWidget]->GetFFWidget()
401 auto it = std::find(m_TabOrderWidgetArray.begin(),
402 m_TabOrderWidgetArray.end(), hWidget->GetLayoutItem());
403 if (it == m_TabOrderWidgetArray.end())
407 pdfium::base::checked_cast<int32_t>(it - m_TabOrderWidgetArray.begin());
411CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget(
413 CXFA_Traversal* pTraversal = pWidget
->GetNode()->GetChild<CXFA_Traversal>(
416 CXFA_Traverse* pTraverse =
417 pTraversal->GetChild<CXFA_Traverse>(0,
XFA_Element::Traverse,
false);
419 absl::optional<WideString> traverseWidgetName =
420 pTraverse->JSObject()->TryAttribute(XFA_Attribute::Ref,
true);
421 if (traverseWidgetName.has_value())
422 return FindWidgetByName(traverseWidgetName.value(), pWidget);
427CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName(
428 const WideString& wsWidgetName,
433void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() {
434 m_TabOrderWidgetArray.clear();
436 const std::vector<CXFA_ContentLayoutItem*> items =
437 CreateSpaceOrderLayoutItems();
441 CXFA_ContentLayoutItem* item = items[0];
442 while (m_TabOrderWidgetArray.size() < items.size()) {
443 if (!pdfium::Contains(m_TabOrderWidgetArray, item)) {
444 m_TabOrderWidgetArray.emplace_back(item);
447 auto it =
std::find(items.begin(), items.end(), item);
448 size_t index = it != items.end() ? it - items.begin() + 1 : 0;
450 CXFA_FFWidget* radio = items[index % items.size()]->GetFFWidget();
453 if (!pdfium::Contains(m_TabOrderWidgetArray, item))
454 m_TabOrderWidgetArray.emplace_back(radio->GetLayoutItem());
464 auto it =
std::find(items.begin(), items.end(), item);
465 size_t index = it != items.end() ? it - items.begin() + 1 : 0;
466 item = items[index % items.size()];
470std::vector<CXFA_ContentLayoutItem*>
471CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderLayoutItems() {
472 std::vector<CXFA_ContentLayoutItem*> items;
473 CXFA_LayoutItemIterator sIterator(m_pPageViewLayout.Get());
474 CXFA_TabParam tabparam;
475 bool bCurrentItem =
false;
476 bool bContentArea =
false;
477 OrderContainer(&sIterator,
nullptr, &tabparam, &bCurrentItem, &bContentArea,
479 items.reserve(tabparam.GetChildren().size());
480 for (
const auto& layout_item : tabparam.GetChildren())
481 items.push_back(layout_item);
484 bCurrentItem =
false;
485 bContentArea =
false;
486 tabparam.ClearChildren();
487 OrderContainer(&sIterator,
nullptr, &tabparam, &bCurrentItem, &bContentArea,
489 for (
const auto& layout_item : tabparam.GetChildren())
490 items.push_back(layout_item);
void Rotate(float fRadian)
constexpr CFX_RectF()=default
CFX_RectF(float dst_left, float dst_top, const SizeType &dst_size)
bool TestStatusBits(Mask< XFA_WidgetStatus > val) const
CXFA_FFWidget * GetFFWidget()
XFA_VERSION GetCurVersionMode() const
CXFA_FFDoc * GetDoc() const
CXFA_FFWidget * GetWidgetByName(const WideString &wsName, CXFA_FFWidget *pRefWidget)
CXFA_Document * GetXFADoc() const
CXFA_ViewLayoutItem * GetLayoutItem() const
CXFA_FFDocView * GetDocView() const
CFX_Matrix GetDisplayMatrix(const FX_RECT &rtDisp, int32_t iRotate) const
CXFA_FFWidget::IteratorIface * CreateGCedTraverseWidgetIterator(Mask< XFA_WidgetStatus > dwWidgetFilter)
CFX_RectF GetPageViewRect() const
~CXFA_FFPageWidgetIterator() override
CXFA_FFPageWidgetIterator(CXFA_FFPageView *pPageView, Mask< XFA_WidgetStatus > dwFilter)
CXFA_FFWidget * MoveToLast() override
CXFA_FFWidget * MoveToNext() override
CXFA_FFWidget * MoveToFirst() override
bool SetCurrentWidget(CXFA_FFWidget *hWidget) override
CXFA_FFWidget * GetCurrentWidget() override
CXFA_FFWidget * MoveToPrevious() override
~CXFA_FFTabOrderPageWidgetIterator() override
CXFA_FFWidget * MoveToFirst() override
CXFA_FFWidget * MoveToLast() override
CXFA_FFWidget * MoveToNext() override
CXFA_FFWidget * GetCurrentWidget() override
CXFA_FFWidget * MoveToPrevious() override
bool SetCurrentWidget(CXFA_FFWidget *hWidget) override
bool IsContentLayoutItem() const
CXFA_Node * GetFormNode() const
CXFA_Node * GetExclGroupIfExists()
XFA_FFWidgetType GetFFWidgetType()
XFA_Element GetElementType() const
CFX_SizeF GetPageSize() const