| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h" | 7 #include "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "fxjse/include/cfxjse_arguments.h" | 11 #include "fxjse/include/cfxjse_arguments.h" |
| 12 #include "third_party/base/stl_util.h" | 12 #include "third_party/base/stl_util.h" |
| 13 #include "xfa/fxfa/app/xfa_ffnotify.h" | 13 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 14 #include "xfa/fxfa/parser/xfa_doclayout.h" | 14 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 15 #include "xfa/fxfa/parser/xfa_document.h" | 15 #include "xfa/fxfa/parser/xfa_document.h" |
| 16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" | 16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" |
| 17 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" | 17 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" |
| 18 #include "xfa/fxfa/parser/xfa_localemgr.h" | 18 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 19 #include "xfa/fxfa/parser/xfa_object.h" | 19 #include "xfa/fxfa/parser/xfa_object.h" |
| 20 #include "xfa/fxfa/parser/xfa_parser.h" | 20 #include "xfa/fxfa/parser/xfa_parser.h" |
| 21 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 21 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
| 22 #include "xfa/fxfa/parser/xfa_script.h" | 22 #include "xfa/fxfa/parser/xfa_script.h" |
| 23 #include "xfa/fxfa/parser/xfa_script_imp.h" | 23 #include "xfa/fxfa/parser/xfa_script_imp.h" |
| 24 #include "xfa/fxfa/parser/xfa_utils.h" | 24 #include "xfa/fxfa/parser/xfa_utils.h" |
| 25 | 25 |
| 26 CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) | 26 CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) |
| 27 : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_LayoutPseudoModel) { | 27 : CXFA_OrdinaryObject(pDocument, XFA_Element::LayoutPseudoModel) { |
| 28 m_uScriptHash = XFA_HASHCODE_Layout; | 28 m_uScriptHash = XFA_HASHCODE_Layout; |
| 29 } | 29 } |
| 30 CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel() {} | 30 CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel() {} |
| 31 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Ready( | 31 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Ready( |
| 32 CFXJSE_Value* pValue, | 32 CFXJSE_Value* pValue, |
| 33 FX_BOOL bSetting, | 33 FX_BOOL bSetting, |
| 34 XFA_ATTRIBUTE eAttribute) { | 34 XFA_ATTRIBUTE eAttribute) { |
| 35 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 35 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
| 36 if (!pNotify) { | 36 if (!pNotify) { |
| 37 return; | 37 return; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 if (wsType == FX_WSTRC(L"pageArea")) { | 218 if (wsType == FX_WSTRC(L"pageArea")) { |
| 219 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { | 219 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { |
| 220 retArray.Add(pMasterPage); | 220 retArray.Add(pMasterPage); |
| 221 } | 221 } |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 if (wsType == FX_WSTRC(L"contentArea")) { | 224 if (wsType == FX_WSTRC(L"contentArea")) { |
| 225 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; | 225 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; |
| 226 pItem = pItem->m_pNextSibling) { | 226 pItem = pItem->m_pNextSibling) { |
| 227 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { | 227 if (pItem->m_pFormNode->GetClassID() == XFA_Element::ContentArea) { |
| 228 retArray.Add(pItem->m_pFormNode); | 228 retArray.Add(pItem->m_pFormNode); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 return; | 231 return; |
| 232 } | 232 } |
| 233 std::set<CXFA_Node*> formItems; | 233 std::set<CXFA_Node*> formItems; |
| 234 if (wsType.IsEmpty()) { | 234 if (wsType.IsEmpty()) { |
| 235 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { | 235 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { |
| 236 retArray.Add(pMasterPage); | 236 retArray.Add(pMasterPage); |
| 237 } | 237 } |
| 238 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; | 238 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; |
| 239 pItem = pItem->m_pNextSibling) { | 239 pItem = pItem->m_pNextSibling) { |
| 240 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { | 240 if (pItem->m_pFormNode->GetClassID() == XFA_Element::ContentArea) { |
| 241 retArray.Add(pItem->m_pFormNode); | 241 retArray.Add(pItem->m_pFormNode); |
| 242 if (!bOnPageArea) { | 242 if (!bOnPageArea) { |
| 243 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | 243 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, |
| 244 CXFA_TraverseStrategy_ContentLayoutItem> | 244 CXFA_TraverseStrategy_ContentLayoutItem> |
| 245 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); | 245 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); |
| 246 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | 246 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); |
| 247 pItemChild; pItemChild = iterator.MoveToNext()) { | 247 pItemChild; pItemChild = iterator.MoveToNext()) { |
| 248 if (!pItemChild->IsContentLayoutItem()) { | 248 if (!pItemChild->IsContentLayoutItem()) { |
| 249 continue; | 249 continue; |
| 250 } | 250 } |
| 251 XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID(); | 251 XFA_Element eElementType = pItemChild->m_pFormNode->GetClassID(); |
| 252 if (eElementType != XFA_ELEMENT_Field && | 252 if (eElementType != XFA_Element::Field && |
| 253 eElementType != XFA_ELEMENT_Draw && | 253 eElementType != XFA_Element::Draw && |
| 254 eElementType != XFA_ELEMENT_Subform && | 254 eElementType != XFA_Element::Subform && |
| 255 eElementType != XFA_ELEMENT_Area) { | 255 eElementType != XFA_Element::Area) { |
| 256 continue; | 256 continue; |
| 257 } | 257 } |
| 258 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) | 258 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) |
| 259 continue; | 259 continue; |
| 260 | 260 |
| 261 formItems.insert(pItemChild->m_pFormNode); | 261 formItems.insert(pItemChild->m_pFormNode); |
| 262 retArray.Add(pItemChild->m_pFormNode); | 262 retArray.Add(pItemChild->m_pFormNode); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } else { | 265 } else { |
| 266 if (bOnPageArea) { | 266 if (bOnPageArea) { |
| 267 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | 267 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, |
| 268 CXFA_TraverseStrategy_ContentLayoutItem> | 268 CXFA_TraverseStrategy_ContentLayoutItem> |
| 269 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); | 269 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); |
| 270 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | 270 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); |
| 271 pItemChild; pItemChild = iterator.MoveToNext()) { | 271 pItemChild; pItemChild = iterator.MoveToNext()) { |
| 272 if (!pItemChild->IsContentLayoutItem()) { | 272 if (!pItemChild->IsContentLayoutItem()) { |
| 273 continue; | 273 continue; |
| 274 } | 274 } |
| 275 XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID(); | 275 XFA_Element eElementType = pItemChild->m_pFormNode->GetClassID(); |
| 276 if (eElementType != XFA_ELEMENT_Field && | 276 if (eElementType != XFA_Element::Field && |
| 277 eElementType != XFA_ELEMENT_Draw && | 277 eElementType != XFA_Element::Draw && |
| 278 eElementType != XFA_ELEMENT_Subform && | 278 eElementType != XFA_Element::Subform && |
| 279 eElementType != XFA_ELEMENT_Area) { | 279 eElementType != XFA_Element::Area) { |
| 280 continue; | 280 continue; |
| 281 } | 281 } |
| 282 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) | 282 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) |
| 283 continue; | 283 continue; |
| 284 formItems.insert(pItemChild->m_pFormNode); | 284 formItems.insert(pItemChild->m_pFormNode); |
| 285 retArray.Add(pItemChild->m_pFormNode); | 285 retArray.Add(pItemChild->m_pFormNode); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN; | 292 XFA_Element eType = XFA_Element::Unknown; |
| 293 if (wsType == FX_WSTRC(L"field")) { | 293 if (wsType == FX_WSTRC(L"field")) { |
| 294 eType = XFA_ELEMENT_Field; | 294 eType = XFA_Element::Field; |
| 295 } else if (wsType == FX_WSTRC(L"draw")) { | 295 } else if (wsType == FX_WSTRC(L"draw")) { |
| 296 eType = XFA_ELEMENT_Draw; | 296 eType = XFA_Element::Draw; |
| 297 } else if (wsType == FX_WSTRC(L"subform")) { | 297 } else if (wsType == FX_WSTRC(L"subform")) { |
| 298 eType = XFA_ELEMENT_Subform; | 298 eType = XFA_Element::Subform; |
| 299 } else if (wsType == FX_WSTRC(L"area")) { | 299 } else if (wsType == FX_WSTRC(L"area")) { |
| 300 eType = XFA_ELEMENT_Area; | 300 eType = XFA_Element::Area; |
| 301 } | 301 } |
| 302 if (eType != XFA_ELEMENT_UNKNOWN) { | 302 if (eType != XFA_Element::Unknown) { |
| 303 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; | 303 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; |
| 304 pItem = pItem->m_pNextSibling) { | 304 pItem = pItem->m_pNextSibling) { |
| 305 if (pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) { | 305 if (pItem->m_pFormNode->GetClassID() == XFA_Element::ContentArea) { |
| 306 if (!bOnPageArea) { | 306 if (!bOnPageArea) { |
| 307 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | 307 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, |
| 308 CXFA_TraverseStrategy_ContentLayoutItem> | 308 CXFA_TraverseStrategy_ContentLayoutItem> |
| 309 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); | 309 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); |
| 310 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | 310 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); |
| 311 pItemChild; pItemChild = iterator.MoveToNext()) { | 311 pItemChild; pItemChild = iterator.MoveToNext()) { |
| 312 if (!pItemChild->IsContentLayoutItem()) | 312 if (!pItemChild->IsContentLayoutItem()) |
| 313 continue; | 313 continue; |
| 314 if (pItemChild->m_pFormNode->GetClassID() != eType) | 314 if (pItemChild->m_pFormNode->GetClassID() != eType) |
| 315 continue; | 315 continue; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 401 } |
| 402 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 402 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
| 403 int32_t iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc); | 403 int32_t iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc); |
| 404 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | 404 CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 405 if (pValue) | 405 if (pValue) |
| 406 pValue->SetInteger(iPageCount); | 406 pValue->SetInteger(iPageCount); |
| 407 } | 407 } |
| 408 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Relayout( | 408 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Relayout( |
| 409 CFXJSE_Arguments* pArguments) { | 409 CFXJSE_Arguments* pArguments) { |
| 410 CXFA_Node* pRootNode = m_pDocument->GetRoot(); | 410 CXFA_Node* pRootNode = m_pDocument->GetRoot(); |
| 411 CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_ELEMENT_Form); | 411 CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); |
| 412 ASSERT(pFormRoot); | 412 ASSERT(pFormRoot); |
| 413 CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); | 413 CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 414 CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); | 414 CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); |
| 415 if (pContentRootNode) { | 415 if (pContentRootNode) { |
| 416 pLayoutProcessor->AddChangedContainer(pContentRootNode); | 416 pLayoutProcessor->AddChangedContainer(pContentRootNode); |
| 417 } | 417 } |
| 418 pLayoutProcessor->SetForceReLayout(TRUE); | 418 pLayoutProcessor->SetForceReLayout(TRUE); |
| 419 } | 419 } |
| 420 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageSpan( | 420 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageSpan( |
| 421 CFXJSE_Arguments* pArguments) { | 421 CFXJSE_Arguments* pArguments) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 530 } |
| 531 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); | 531 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); |
| 532 if (!pLayoutItem) { | 532 if (!pLayoutItem) { |
| 533 pValue->SetInteger(-1); | 533 pValue->SetInteger(-1); |
| 534 return; | 534 return; |
| 535 } | 535 } |
| 536 iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); | 536 iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); |
| 537 if (pValue) | 537 if (pValue) |
| 538 pValue->SetInteger(bAbsPage ? iPage : iPage + 1); | 538 pValue->SetInteger(bAbsPage ? iPage : iPage + 1); |
| 539 } | 539 } |
| OLD | NEW |