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 #ifndef XFA_FXFA_CXFA_FFPAGEVIEW_H_
8 #define XFA_FXFA_CXFA_FFPAGEVIEW_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/observed_ptr.h"
14 #include "xfa/fxfa/layout/cxfa_contentlayoutitem.h"
15 #include "xfa/fxfa/layout/cxfa_traversestrategy_layoutitem.h"
16 #include "xfa/fxfa/layout/cxfa_viewlayoutitem.h"
17 
18 class CXFA_FFWidget;
19 class CXFA_FFDocView;
20 
21 class CXFA_FFPageView : public Observable {
22  public:
23   CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea);
24   ~CXFA_FFPageView();
25 
GetLayoutItem()26   CXFA_ViewLayoutItem* GetLayoutItem() const { return m_pLayoutItem.Get(); }
SetLayoutItem(CXFA_ViewLayoutItem * pItem)27   void SetLayoutItem(CXFA_ViewLayoutItem* pItem) { m_pLayoutItem = pItem; }
28 
29   CXFA_FFDocView* GetDocView() const;
30   CFX_RectF GetPageViewRect() const;
31   CFX_Matrix GetDisplayMatrix(const FX_RECT& rtDisp, int32_t iRotate) const;
32 
33   // These always return a non-null iterator.
34   std::unique_ptr<IXFA_WidgetIterator> CreateFormWidgetIterator(
35       uint32_t dwWidgetFilter);
36   std::unique_ptr<IXFA_WidgetIterator> CreateTraverseWidgetIterator(
37       uint32_t dwWidgetFilter);
38 
39  private:
40   UnownedPtr<CXFA_Node> const m_pPageArea;
41   UnownedPtr<CXFA_FFDocView> const m_pDocView;
42   UnownedPtr<CXFA_ViewLayoutItem> m_pLayoutItem;
43 };
44 
45 class CXFA_FFPageWidgetIterator final : public IXFA_WidgetIterator {
46  public:
47   CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView, uint32_t dwFilter);
48   ~CXFA_FFPageWidgetIterator() override;
49 
50   void Reset() override;
51   CXFA_FFWidget* MoveToFirst() override;
52   CXFA_FFWidget* MoveToLast() override;
53   CXFA_FFWidget* MoveToNext() override;
54   CXFA_FFWidget* MoveToPrevious() override;
55   CXFA_FFWidget* GetCurrentWidget() override;
56   bool SetCurrentWidget(CXFA_FFWidget* hWidget) override;
57 
58  private:
59   CXFA_FFWidget* GetWidget(CXFA_LayoutItem* pLayoutItem);
60 
61   UnownedPtr<CXFA_FFPageView> m_pPageView;
62   UnownedPtr<CXFA_FFWidget> m_hCurWidget;
63   uint32_t m_dwFilter;
64   bool m_bIgnoreRelevant;
65   CXFA_LayoutItemIterator m_sIterator;
66 };
67 
68 class CXFA_TabParam {
69  public:
70   explicit CXFA_TabParam(CXFA_FFWidget* pWidget);
71   ~CXFA_TabParam();
72 
73   void AppendTabParam(CXFA_TabParam* pParam);
74   void ClearChildren();
GetWidget()75   CXFA_FFWidget* GetWidget() const { return m_pWidget.Get(); }
GetChildren()76   const std::vector<CXFA_FFWidget*>& GetChildren() const { return m_Children; }
77 
78  private:
79   UnownedPtr<CXFA_FFWidget> const m_pWidget;
80   std::vector<CXFA_FFWidget*> m_Children;
81 };
82 
83 class CXFA_FFTabOrderPageWidgetIterator final : public IXFA_WidgetIterator {
84  public:
85   CXFA_FFTabOrderPageWidgetIterator(CXFA_FFPageView* pPageView,
86                                     uint32_t dwFilter);
87   ~CXFA_FFTabOrderPageWidgetIterator() override;
88 
89   void Reset() override;
90   CXFA_FFWidget* MoveToFirst() override;
91   CXFA_FFWidget* MoveToLast() override;
92   CXFA_FFWidget* MoveToNext() override;
93   CXFA_FFWidget* MoveToPrevious() override;
94   CXFA_FFWidget* GetCurrentWidget() override;
95   bool SetCurrentWidget(CXFA_FFWidget* hWidget) override;
96 
97  private:
98   CXFA_FFWidget* GetTraverseWidget(CXFA_FFWidget* pWidget);
99   CXFA_FFWidget* FindWidgetByName(const WideString& wsWidgetName,
100                                   CXFA_FFWidget* pRefWidget);
101   void CreateTabOrderWidgetArray();
102   void CreateSpaceOrderWidgetArray(std::vector<CXFA_FFWidget*>* WidgetArray);
103   CXFA_FFWidget* GetWidget(CXFA_LayoutItem* pLayoutItem);
104   void OrderContainer(CXFA_LayoutItemIterator* sIterator,
105                       CXFA_LayoutItem* pViewItem,
106                       CXFA_TabParam* pContainer,
107                       bool* bCurrentItem,
108                       bool* bContentArea,
109                       bool bMasterPage);
110 
111   std::vector<UnownedPtr<CXFA_FFWidget>> m_TabOrderWidgetArray;
112   UnownedPtr<CXFA_FFPageView> m_pPageView;
113   uint32_t m_dwFilter;
114   int32_t m_iCurWidget;
115   bool m_bIgnoreRelevant;
116 };
117 
118 #endif  // XFA_FXFA_CXFA_FFPAGEVIEW_H_
119