7#include "fxjs/xfa/cjx_layoutpseudomodel.h"
12#include "core/fxcrt/fx_coordinates.h"
14#include "fxjs/js_resources.h"
15#include "fxjs/xfa/cfxjse_class.h"
16#include "fxjs/xfa/cfxjse_engine.h"
17#include "third_party/base/containers/contains.h"
18#include "v8/include/cppgc/allocation.h"
19#include "v8/include/v8-object.h"
20#include "xfa/fxfa/cxfa_ffnotify.h"
21#include "xfa/fxfa/layout/cxfa_contentlayoutitem.h"
22#include "xfa/fxfa/layout/cxfa_layoutitem.h"
23#include "xfa/fxfa/layout/cxfa_layoutprocessor.h"
24#include "xfa/fxfa/layout/cxfa_traversestrategy_layoutitem.h"
25#include "xfa/fxfa/layout/cxfa_viewlayoutitem.h"
26#include "xfa/fxfa/parser/cscript_layoutpseudomodel.h"
27#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
28#include "xfa/fxfa/parser/cxfa_document.h"
29#include "xfa/fxfa/parser/cxfa_form.h"
30#include "xfa/fxfa/parser/cxfa_measurement.h"
31#include "xfa/fxfa/parser/cxfa_node.h"
32#include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h"
35 {
"absPage", absPage_static},
36 {
"absPageCount", absPageCount_static},
37 {
"absPageCountInBatch", absPageCountInBatch_static},
38 {
"absPageInBatch", absPageInBatch_static},
39 {
"absPageSpan", absPageSpan_static},
41 {
"page", page_static},
42 {
"pageContent", pageContent_static},
43 {
"pageCount", pageCount_static},
44 {
"pageSpan", pageSpan_static},
45 {
"relayout", relayout_static},
46 {
"relayoutPageArea", relayoutPageArea_static},
47 {
"sheet", sheet_static},
48 {
"sheetCount", sheetCount_static},
49 {
"sheetCountInBatch", sheetCountInBatch_static},
50 {
"sheetInBatch", sheetInBatch_static},
55CJX_LayoutPseudoModel::CJX_LayoutPseudoModel(CScript_LayoutPseudoModel* model)
66void CJX_LayoutPseudoModel::ready(
v8::Isolate* pIsolate,
67 v8::Local<v8::Value>* pValue,
82 *pValue = fxv8::NewBooleanHelper(pIsolate, bReady);
85CJS_Result CJX_LayoutPseudoModel::DoHWXYInternal(
87 pdfium::span<v8::Local<v8::Value>> params,
89 if (params.empty() || params.size() > 3)
92 CXFA_Node* pNode = ToNode(runtime->ToXFAObject(params[0]));
97 if (params.size() >= 2) {
98 WideString tmp_unit = runtime->ToWideString(params[1]);
100 unit =
std::move(tmp_unit);
102 int32_t iIndex = params.size() >= 3 ? runtime->ToInt32(params[2]) : 0;
104 CXFA_ContentLayoutItem* pLayoutItem =
105 ToContentLayoutItem(pDocLayout->GetLayoutItem(pNode));
109 while (iIndex > 0 && pLayoutItem) {
119 switch (layoutModel) {
144 pdfium::span<v8::Local<v8::Value>> params) {
145 return DoHWXYInternal(runtime, params, HWXY::kH);
149 pdfium::span<v8::Local<v8::Value>> params) {
150 return DoHWXYInternal(runtime, params, HWXY::kW);
154 pdfium::span<v8::Local<v8::Value>> params) {
155 return DoHWXYInternal(runtime, params, HWXY::kX);
159 pdfium::span<v8::Local<v8::Value>> params) {
160 return DoHWXYInternal(runtime, params, HWXY::kY);
170 int32_t iPageCount = 0;
171 int32_t iPageNum = pDocLayout->CountPages();
172 for (int32_t i = 0; i < iPageNum; i++) {
173 CXFA_ViewLayoutItem* pLayoutPage = pDocLayout->GetPage(i);
178 if (pMasterPage->JSObject()->GetInteger(
XFA_Attribute::Numbered))
186 pdfium::span<v8::Local<v8::Value>> params) {
187 return NumberedPageCount(runtime);
192 pdfium::span<v8::Local<v8::Value>> params) {
193 if (params.size() != 1)
196 CXFA_Node* pNode = ToNode(runtime->ToXFAObject(params[0]));
201 CXFA_ContentLayoutItem* pLayoutItem =
202 ToContentLayoutItem(pDocLayout->GetLayoutItem(pNode));
208 int32_t iPageSpan = iLast - iFirst + 1;
214 pdfium::span<v8::Local<v8::Value>> params) {
215 return PageInternals(runtime, params,
false);
218std::vector<CXFA_Node*> CJX_LayoutPseudoModel::GetObjArray(
219 CXFA_LayoutProcessor* pDocLayout,
221 const WideString& wsType,
223 CXFA_ViewLayoutItem* pLayoutPage = pDocLayout
->GetPage(iPageNo
);
225 return std::vector<CXFA_Node*>();
227 std::vector<CXFA_Node*> retArray;
235 pItem = pItem->GetNextSibling()) {
241 std::set<CXFA_Node*> formItems;
247 pItem = pItem->GetNextSibling()) {
251 CXFA_LayoutItemIterator iterator(pItem->GetFirstChild());
253 pChild = iterator.MoveToNext()) {
272 CXFA_LayoutItemIterator iterator(pItem);
274 pChild = iterator.MoveToNext()) {
308 pItem = pItem->GetNextSibling()) {
311 CXFA_LayoutItemIterator iterator(pItem->GetFirstChild());
313 pChild = iterator.MoveToNext()) {
328 CXFA_LayoutItemIterator iterator(pItem);
330 pChild = iterator.MoveToNext()) {
351 pdfium::span<v8::Local<v8::Value>> params) {
352 if (params.empty() || params.size() > 3)
356 if (params.size() >= 1)
357 iIndex = runtime->ToInt32(params[0]);
360 if (params.size() >= 2)
361 wsType = runtime->ToWideString(params[1]);
363 bool bOnPageArea =
false;
364 if (params.size() >= 3)
365 bOnPageArea = runtime->ToBoolean(params[2]);
373 auto* pArrayNodeList = cppgc::MakeGarbageCollected<CXFA_ArrayNodeList>(
374 pDoc->GetHeap()->GetAllocationHandle(), pDoc);
376 pArrayNodeList->SetArrayNodeList(
377 GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea));
381CJS_Result CJX_LayoutPseudoModel::absPageCount(
383 pdfium::span<v8::Local<v8::Value>> params) {
384 return AllPageCount(runtime);
387CJS_Result CJX_LayoutPseudoModel::absPageCountInBatch(
389 pdfium::span<v8::Local<v8::Value>> params) {
393CJS_Result CJX_LayoutPseudoModel::sheetCountInBatch(
395 pdfium::span<v8::Local<v8::Value>> params) {
401 pdfium::span<v8::Local<v8::Value>> params) {
403 auto* pLayoutProcessor =
GetDocument()->GetLayoutProcessor();
404 CXFA_Form* pFormRoot =
405 pRootNode->GetFirstChildByClass<CXFA_Form>(
XFA_Element::Form);
407 if (pFormRoot->GetFirstChild())
408 pLayoutProcessor->SetHasChangedContainer();
410 pLayoutProcessor->SetForceRelayout();
416 pdfium::span<v8::Local<v8::Value>> params) {
417 return pageSpan(runtime, params);
420CJS_Result CJX_LayoutPseudoModel::absPageInBatch(
422 pdfium::span<v8::Local<v8::Value>> params) {
423 if (params.size() != 1)
429CJS_Result CJX_LayoutPseudoModel::sheetInBatch(
431 pdfium::span<v8::Local<v8::Value>> params) {
432 if (params.size() != 1)
440 pdfium::span<v8::Local<v8::Value>> params) {
441 return PageInternals(runtime, params,
true);
444CJS_Result CJX_LayoutPseudoModel::relayoutPageArea(
446 pdfium::span<v8::Local<v8::Value>> params) {
452 pdfium::span<v8::Local<v8::Value>> params) {
453 return AllPageCount(runtime);
458 pdfium::span<v8::Local<v8::Value>> params) {
459 return PageInternals(runtime, params,
true);
462CJS_Result CJX_LayoutPseudoModel::PageInternals(
464 pdfium::span<v8::Local<v8::Value>> params,
466 if (params.size() != 1)
469 CXFA_Node* pNode = ToNode(runtime->ToXFAObject(params[0]));
474 CXFA_ContentLayoutItem* pLayoutItem =
475 ToContentLayoutItem(pDocLayout->GetLayoutItem(pNode));
480 return CJS_Result::Success(runtime->NewNumber(bAbsPage ? iPage : iPage + 1));
friend class EventParamScope
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
bool DynamicTypeIs(TypeTag eType) const override
~CJX_LayoutPseudoModel() override
void DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
CXFA_Document * GetDocument() const
virtual bool DynamicTypeIs(TypeTag eType) const
void ThrowException(v8::Isolate *pIsolate, const WideString &str) const
CXFA_ContentLayoutItem * GetNext() const
CFX_RectF GetRelativeRect() const
CXFA_ContentLayoutItem * GetLast()
CXFA_ContentLayoutItem * GetFirst()
CXFA_NodeOwner * GetNodeOwner()
CXFA_FFDocView::LayoutStatus GetLayoutStatus()
const CXFA_ViewLayoutItem * GetPage() const
CXFA_ContentLayoutItem * AsContentLayoutItem()
CXFA_Node * GetFormNode() const
CXFA_ViewLayoutItem * GetPage(int32_t index) const
static CXFA_LayoutProcessor * FromDocument(const CXFA_Document *pXFADoc)
void Set(float fValue, XFA_Unit eUnit)
float ToUnit(XFA_Unit eUnit) const
static XFA_Unit GetUnitFromString(WideStringView wsUnit)
void PersistList(CXFA_List *list)
XFA_Element GetElementType() const
CXFA_Node * GetMasterPage() const
static WideString FromASCII(ByteStringView str)
bool EqualsASCII(ByteStringView that) const
int FXSYS_roundf(float f)