Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 7 | #include "xfa/fxfa/cxfa_ffpageview.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 9 | #include <algorithm> |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 10 | #include <memory> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "third_party/base/ptr_util.h" |
| 14 | #include "third_party/base/stl_util.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 15 | #include "xfa/fde/fde_render.h" |
| 16 | #include "xfa/fxfa/app/xfa_ffcheckbutton.h" |
| 17 | #include "xfa/fxfa/app/xfa_ffchoicelist.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 18 | #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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 22 | #include "xfa/fxfa/app/xfa_fwladapter.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 23 | #include "xfa/fxfa/cxfa_ffdoc.h" |
| 24 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 25 | #include "xfa/fxfa/cxfa_ffwidget.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 26 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 27 | namespace { |
| 28 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 29 | CFX_Matrix GetPageMatrix(const CFX_RectF& docPageRect, |
| 30 | const CFX_Rect& devicePageRect, |
| 31 | int32_t iRotate, |
| 32 | uint32_t dwCoordinatesType) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 33 | ASSERT(iRotate >= 0 && iRotate <= 3); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 34 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 35 | bool bFlipX = (dwCoordinatesType & 0x01) != 0; |
| 36 | bool bFlipY = (dwCoordinatesType & 0x02) != 0; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 37 | CFX_Matrix m((bFlipX ? -1.0f : 1.0f), 0, 0, (bFlipY ? -1.0f : 1.0f), 0, 0); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 38 | if (iRotate == 0 || iRotate == 2) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 39 | m.a *= (float)devicePageRect.width / docPageRect.width; |
| 40 | m.d *= (float)devicePageRect.height / docPageRect.height; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 41 | } else { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 42 | m.a *= (float)devicePageRect.height / docPageRect.width; |
| 43 | m.d *= (float)devicePageRect.width / docPageRect.height; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 44 | } |
| 45 | m.Rotate(iRotate * 1.57079632675f); |
| 46 | switch (iRotate) { |
| 47 | case 0: |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 48 | m.e = bFlipX ? (float)devicePageRect.right() : (float)devicePageRect.left; |
| 49 | m.f = bFlipY ? (float)devicePageRect.bottom() : (float)devicePageRect.top; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 50 | break; |
| 51 | case 1: |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 52 | m.e = bFlipY ? (float)devicePageRect.left : (float)devicePageRect.right(); |
| 53 | m.f = bFlipX ? (float)devicePageRect.bottom() : (float)devicePageRect.top; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 54 | break; |
| 55 | case 2: |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 56 | m.e = bFlipX ? (float)devicePageRect.left : (float)devicePageRect.right(); |
| 57 | m.f = bFlipY ? (float)devicePageRect.top : (float)devicePageRect.bottom(); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 58 | break; |
| 59 | case 3: |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 60 | m.e = bFlipY ? (float)devicePageRect.right() : (float)devicePageRect.left; |
| 61 | m.f = bFlipX ? (float)devicePageRect.top : (float)devicePageRect.bottom(); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 62 | break; |
| 63 | default: |
| 64 | break; |
| 65 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 66 | return m; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 67 | } |
| 68 | |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 69 | bool PageWidgetFilter(CXFA_FFWidget* pWidget, |
| 70 | uint32_t dwFilter, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 71 | bool bTraversal, |
| 72 | bool bIgnorerelevant) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 73 | CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); |
| 74 | |
| 75 | if (!!(dwFilter & XFA_WidgetStatus_Focused) && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 76 | pWidgetAcc->GetElementType() != XFA_Element::Field) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 77 | 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 | |
dsinclair | d1cf239 | 2016-07-11 06:46:59 -0700 | [diff] [blame] | 91 | bool 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 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 109 | } // namespace |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 110 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 111 | CXFA_FFPageView::CXFA_FFPageView(CXFA_FFDocView* pDocView, CXFA_Node* pPageArea) |
thestig | 9f3dbbc | 2016-04-13 13:18:21 -0700 | [diff] [blame] | 112 | : CXFA_ContainerLayoutItem(pPageArea), m_pDocView(pDocView) {} |
| 113 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 114 | CXFA_FFPageView::~CXFA_FFPageView() {} |
thestig | 9f3dbbc | 2016-04-13 13:18:21 -0700 | [diff] [blame] | 115 | |
| 116 | CXFA_FFDocView* CXFA_FFPageView::GetDocView() const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 117 | return m_pDocView; |
| 118 | } |
thestig | 9f3dbbc | 2016-04-13 13:18:21 -0700 | [diff] [blame] | 119 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 120 | CFX_RectF CXFA_FFPageView::GetPageViewRect() const { |
| 121 | return CFX_RectF(0, 0, GetPageSize()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 122 | } |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 123 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 124 | CFX_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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 127 | } |
thestig | 9f3dbbc | 2016-04-13 13:18:21 -0700 | [diff] [blame] | 128 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 129 | IXFA_WidgetIterator* CXFA_FFPageView::CreateWidgetIterator( |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 130 | uint32_t dwTraverseWay, |
| 131 | uint32_t dwWidgetFilter) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 132 | 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 | } |
thestig | 9f3dbbc | 2016-04-13 13:18:21 -0700 | [diff] [blame] | 138 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 139 | } |
thestig | 9f3dbbc | 2016-04-13 13:18:21 -0700 | [diff] [blame] | 140 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 141 | CXFA_FFPageWidgetIterator::CXFA_FFPageWidgetIterator(CXFA_FFPageView* pPageView, |
Tom Sepez | 312ce17 | 2017-03-06 14:00:07 -0800 | [diff] [blame] | 142 | uint32_t dwFilter) |
| 143 | : m_pPageView(pPageView), m_dwFilter(dwFilter), m_sIterator(pPageView) { |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 144 | m_bIgnorerelevant = |
| 145 | m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() < |
| 146 | XFA_VERSION_205; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 147 | } |
Tom Sepez | 312ce17 | 2017-03-06 14:00:07 -0800 | [diff] [blame] | 148 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 149 | CXFA_FFPageWidgetIterator::~CXFA_FFPageWidgetIterator() {} |
Tom Sepez | 312ce17 | 2017-03-06 14:00:07 -0800 | [diff] [blame] | 150 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 151 | void CXFA_FFPageWidgetIterator::Reset() { |
| 152 | m_sIterator.Reset(); |
| 153 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 154 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 155 | CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToFirst() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | m_sIterator.Reset(); |
| 157 | for (CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); pLayoutItem; |
| 158 | pLayoutItem = m_sIterator.MoveToNext()) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 159 | if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 160 | return hWidget; |
| 161 | } |
| 162 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 163 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 164 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 165 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 166 | CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToLast() { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 167 | m_sIterator.SetCurrent(nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | return MoveToPrevious(); |
| 169 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 170 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 171 | CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToNext() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToNext(); pLayoutItem; |
| 173 | pLayoutItem = m_sIterator.MoveToNext()) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 174 | if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 175 | return hWidget; |
| 176 | } |
| 177 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 178 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 179 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 180 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 181 | CXFA_FFWidget* CXFA_FFPageWidgetIterator::MoveToPrevious() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 182 | for (CXFA_LayoutItem* pLayoutItem = m_sIterator.MoveToPrev(); pLayoutItem; |
| 183 | pLayoutItem = m_sIterator.MoveToPrev()) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 184 | if (CXFA_FFWidget* hWidget = GetWidget(pLayoutItem)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 185 | return hWidget; |
| 186 | } |
| 187 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 188 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 189 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 190 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 191 | CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetCurrentWidget() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 192 | CXFA_LayoutItem* pLayoutItem = m_sIterator.GetCurrent(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 193 | return pLayoutItem ? XFA_GetWidgetFromLayoutItem(pLayoutItem) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 194 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 195 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 196 | bool CXFA_FFPageWidgetIterator::SetCurrentWidget(CXFA_FFWidget* hWidget) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 197 | return hWidget && m_sIterator.SetCurrent(hWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 198 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 199 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 200 | CXFA_FFWidget* CXFA_FFPageWidgetIterator::GetWidget( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 201 | CXFA_LayoutItem* pLayoutItem) { |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 202 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 212 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 213 | return pWidget; |
| 214 | } |
| 215 | |
| 216 | void 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 | |
| 222 | void CXFA_TabParam::ClearChildren() { |
| 223 | m_Children.clear(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 224 | } |
tsepez | cc4d6d8 | 2016-05-16 13:21:03 -0700 | [diff] [blame] | 225 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 226 | CXFA_FFTabOrderPageWidgetIterator::CXFA_FFTabOrderPageWidgetIterator( |
| 227 | CXFA_FFPageView* pPageView, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 228 | uint32_t dwFilter) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 229 | : m_pPageView(pPageView), m_dwFilter(dwFilter), m_iCurWidget(-1) { |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 230 | m_bIgnorerelevant = |
| 231 | m_pPageView->GetDocView()->GetDoc()->GetXFADoc()->GetCurVersionMode() < |
| 232 | XFA_VERSION_205; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 233 | Reset(); |
| 234 | } |
tsepez | cc4d6d8 | 2016-05-16 13:21:03 -0700 | [diff] [blame] | 235 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 236 | CXFA_FFTabOrderPageWidgetIterator::~CXFA_FFTabOrderPageWidgetIterator() {} |
tsepez | cc4d6d8 | 2016-05-16 13:21:03 -0700 | [diff] [blame] | 237 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 238 | void CXFA_FFTabOrderPageWidgetIterator::Reset() { |
| 239 | CreateTabOrderWidgetArray(); |
| 240 | m_iCurWidget = -1; |
| 241 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 242 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 243 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 244 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 250 | } |
| 251 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 252 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 253 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 254 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 255 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 256 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 262 | } |
| 263 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 264 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 265 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 266 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 267 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 268 | for (int32_t i = m_iCurWidget + 1; |
| 269 | i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 270 | if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 271 | m_bIgnorerelevant)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 272 | m_iCurWidget = i; |
| 273 | return m_TabOrderWidgetArray[m_iCurWidget]; |
| 274 | } |
| 275 | } |
| 276 | m_iCurWidget = -1; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 277 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 278 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 279 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 280 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 281 | for (int32_t i = m_iCurWidget - 1; i >= 0; i--) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 282 | if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 283 | m_bIgnorerelevant)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 284 | m_iCurWidget = i; |
| 285 | return m_TabOrderWidgetArray[m_iCurWidget]; |
| 286 | } |
| 287 | } |
| 288 | m_iCurWidget = -1; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 289 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 290 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 291 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 292 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 293 | return m_iCurWidget >= 0 ? m_TabOrderWidgetArray[m_iCurWidget] : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 294 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 295 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 296 | bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget( |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 297 | CXFA_FFWidget* hWidget) { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 298 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 305 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 306 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 307 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget( |
| 308 | CXFA_FFWidget* pWidget) { |
| 309 | CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 310 | CXFA_Node* pTraversal = pAcc->GetNode()->GetChild(0, XFA_Element::Traversal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 311 | if (pTraversal) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 312 | CXFA_Node* pTraverse = pTraversal->GetChild(0, XFA_Element::Traverse); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 313 | if (pTraverse) { |
| 314 | CFX_WideString wsTraverseWidgetName; |
| 315 | if (pTraverse->GetAttribute(XFA_ATTRIBUTE_Ref, wsTraverseWidgetName)) { |
tsepez | 70c5520 | 2016-04-14 15:32:35 -0700 | [diff] [blame] | 316 | return FindWidgetByName(wsTraverseWidgetName, pWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 320 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 321 | } |
| 322 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName( |
tsepez | 70c5520 | 2016-04-14 15:32:35 -0700 | [diff] [blame] | 323 | const CFX_WideString& wsWidgetName, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 324 | CXFA_FFWidget* pRefWidget) { |
| 325 | return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget); |
| 326 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 327 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 328 | void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 329 | m_TabOrderWidgetArray.clear(); |
| 330 | |
| 331 | std::vector<CXFA_FFWidget*> SpaceOrderWidgetArray; |
| 332 | CreateSpaceOrderWidgetArray(&SpaceOrderWidgetArray); |
| 333 | if (SpaceOrderWidgetArray.empty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 334 | return; |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 335 | |
| 336 | int32_t nWidgetCount = pdfium::CollectionSize<int32_t>(SpaceOrderWidgetArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 337 | CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0]; |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 338 | while (pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) < |
| 339 | nWidgetCount) { |
| 340 | if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) { |
| 341 | m_TabOrderWidgetArray.push_back(hWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 342 | CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 343 | if (pWidgetAcc->GetUIType() == XFA_Element::ExclGroup) { |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 344 | auto it = std::find(SpaceOrderWidgetArray.begin(), |
| 345 | SpaceOrderWidgetArray.end(), hWidget); |
| 346 | int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end() |
| 347 | ? it - SpaceOrderWidgetArray.begin() + 1 |
| 348 | : 0; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 349 | while (true) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 350 | CXFA_FFWidget* pRadio = |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 351 | SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 352 | if (pRadio->GetDataAcc()->GetExclGroup() != pWidgetAcc) { |
| 353 | break; |
| 354 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 355 | if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) { |
| 356 | m_TabOrderWidgetArray.push_back(pRadio); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 357 | } |
| 358 | iWidgetIndex++; |
| 359 | } |
| 360 | } |
| 361 | if (CXFA_FFWidget* hTraverseWidget = GetTraverseWidget(hWidget)) { |
| 362 | hWidget = hTraverseWidget; |
| 363 | continue; |
| 364 | } |
| 365 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 366 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 372 | } |
| 373 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 374 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 375 | void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( |
| 376 | CXFA_LayoutItemIterator* sIterator, |
| 377 | CXFA_LayoutItem* pContainerItem, |
| 378 | CXFA_TabParam* pContainer, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 379 | bool& bCurrentItem, |
| 380 | bool& bContentArea, |
| 381 | bool bMarsterPage) { |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 382 | std::vector<std::unique_ptr<CXFA_TabParam>> tabParams; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 383 | CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext(); |
| 384 | while (pSearchItem) { |
| 385 | if (!pSearchItem->IsContentLayoutItem()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 386 | bContentArea = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 387 | 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)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 400 | bCurrentItem = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 401 | break; |
| 402 | } |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 403 | tabParams.push_back(pdfium::MakeUnique<CXFA_TabParam>(hWidget)); |
dsinclair | d1cf239 | 2016-07-11 06:46:59 -0700 | [diff] [blame] | 404 | if (IsLayoutElement(pSearchItem->GetFormNode()->GetElementType(), true)) { |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 405 | OrderContainer(sIterator, pSearchItem, tabParams.back().get(), |
| 406 | bCurrentItem, bContentArea, bMarsterPage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | if (bCurrentItem) { |
| 410 | pSearchItem = sIterator->GetCurrent(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 411 | bCurrentItem = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 412 | } else { |
| 413 | pSearchItem = sIterator->MoveToNext(); |
| 414 | } |
| 415 | } |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 416 | std::sort(tabParams.begin(), tabParams.end(), |
| 417 | [](const std::unique_ptr<CXFA_TabParam>& arg1, |
| 418 | const std::unique_ptr<CXFA_TabParam>& arg2) { |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 419 | const CFX_RectF& rt1 = arg1->GetWidget()->GetWidgetRect(); |
| 420 | const CFX_RectF& rt2 = arg2->GetWidget()->GetWidgetRect(); |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 421 | if (rt1.top - rt2.top >= XFA_FLOAT_PERCISION) |
| 422 | return rt1.top < rt2.top; |
| 423 | return rt1.left < rt2.left; |
| 424 | }); |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 425 | for (const auto& pParam : tabParams) |
| 426 | pContainer->AppendTabParam(pParam.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 427 | } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 428 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 429 | void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray( |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 430 | std::vector<CXFA_FFWidget*>* WidgetArray) { |
Tom Sepez | 312ce17 | 2017-03-06 14:00:07 -0800 | [diff] [blame] | 431 | CXFA_LayoutItemIterator sIterator(m_pPageView); |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 432 | auto pParam = pdfium::MakeUnique<CXFA_TabParam>(nullptr); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 433 | bool bCurrentItem = false; |
| 434 | bool bContentArea = false; |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 435 | OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea); |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 436 | WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(), |
| 437 | pParam->GetChildren().end()); |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 438 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 439 | sIterator.Reset(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 440 | bCurrentItem = false; |
| 441 | bContentArea = false; |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 442 | pParam->ClearChildren(); |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 443 | OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea, |
| 444 | true); |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 445 | WidgetArray->insert(WidgetArray->end(), pParam->GetChildren().begin(), |
| 446 | pParam->GetChildren().end()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 447 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 448 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 449 | CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( |
| 450 | CXFA_LayoutItem* pLayoutItem) { |
| 451 | if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) { |
| 452 | if (!pWidget->IsLoaded() && |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 453 | (pWidget->GetStatus() & XFA_WidgetStatus_Visible)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 454 | pWidget->LoadWidget(); |
| 455 | } |
| 456 | return pWidget; |
| 457 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 458 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 459 | } |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 460 | |
Tom Sepez | b822782 | 2017-03-24 13:10:14 -0700 | [diff] [blame] | 461 | CXFA_TabParam::CXFA_TabParam(CXFA_FFWidget* pWidget) : m_pWidget(pWidget) {} |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 462 | |
| 463 | CXFA_TabParam::~CXFA_TabParam() {} |