Replace CXFA_LayoutProcessor's changed containers with a bool. No need to store the actual changed nodes, when a bool to indicate whether there are changed nodes will suffice. Iteratively change the call chain to get rid of the node pointer parameters. Also mark some methods as private. Change-Id: Id17b9df2ffa2de126395e5cb6a6a926113403a80 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86633 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/xfa/cjx_instancemanager.cpp b/fxjs/xfa/cjx_instancemanager.cpp index a29a23c..23feab7 100644 --- a/fxjs/xfa/cjx_instancemanager.cpp +++ b/fxjs/xfa/cjx_instancemanager.cpp
@@ -106,8 +106,7 @@ pNotify->RunNodeInitialize(pNewInstance); } } - GetDocument()->GetLayoutProcessor()->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + GetDocument()->GetLayoutProcessor()->SetHasChangedContainer(); return 0; } @@ -130,8 +129,7 @@ GetXFANode()->RemoveItem(pMoveInstance, false); GetXFANode()->InsertItem(pMoveInstance, iTo, iCount - 1, true); - GetDocument()->GetLayoutProcessor()->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + GetDocument()->GetLayoutProcessor()->SetHasChangedContainer(); return 0; } @@ -202,8 +200,7 @@ } } } - GetDocument()->GetLayoutProcessor()->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + GetDocument()->GetLayoutProcessor()->SetHasChangedContainer(); return CJS_Result::Success(); } @@ -250,8 +247,7 @@ CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); if (pNotify) { pNotify->RunNodeInitialize(pNewInstance); - GetDocument()->GetLayoutProcessor()->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + GetDocument()->GetLayoutProcessor()->SetHasChangedContainer(); } return CJS_Result::Success( @@ -292,8 +288,7 @@ CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); if (pNotify) { pNotify->RunNodeInitialize(pNewInstance); - GetDocument()->GetLayoutProcessor()->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + GetDocument()->GetLayoutProcessor()->SetHasChangedContainer(); } return CJS_Result::Success(
diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp index ffb12dd..344ab58 100644 --- a/fxjs/xfa/cjx_layoutpseudomodel.cpp +++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp
@@ -412,9 +412,8 @@ CXFA_Form* pFormRoot = pRootNode->GetFirstChildByClass<CXFA_Form>(XFA_Element::Form); if (pFormRoot) { - CXFA_Node* pContentRootNode = pFormRoot->GetFirstChild(); - if (pContentRootNode) - pLayoutProcessor->AddChangedContainer(pContentRootNode); + if (pFormRoot->GetFirstChild()) + pLayoutProcessor->SetHasChangedContainer(); } pLayoutProcessor->SetForceRelayout(); return CJS_Result::Success();
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index 1997f46..7c24967 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -434,8 +434,8 @@ } } -void CXFA_FFNotify::OnContainerChanged(CXFA_Node* pNode) { - m_pDoc->GetXFADoc()->GetLayoutProcessor()->AddChangedContainer(pNode); +void CXFA_FFNotify::OnContainerChanged() { + m_pDoc->GetXFADoc()->GetLayoutProcessor()->SetHasChangedContainer(); } void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) {
diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h index bf5cf31..51d9fa5 100644 --- a/xfa/fxfa/cxfa_ffnotify.h +++ b/xfa/fxfa/cxfa_ffnotify.h
@@ -46,7 +46,7 @@ XFA_Attribute eAttr, CXFA_Node* pParentNode, CXFA_Node* pWidgetNode); - void OnContainerChanged(CXFA_Node* pNode); + void OnContainerChanged(); void OnChildAdded(CXFA_Node* pSender); void OnChildRemoved();
diff --git a/xfa/fxfa/layout/cxfa_layoutprocessor.cpp b/xfa/fxfa/layout/cxfa_layoutprocessor.cpp index 9929cce..1a402cd 100644 --- a/xfa/fxfa/layout/cxfa_layoutprocessor.cpp +++ b/xfa/fxfa/layout/cxfa_layoutprocessor.cpp
@@ -8,7 +8,6 @@ #include "fxjs/gc/container_trace.h" #include "fxjs/xfa/cjx_object.h" -#include "third_party/base/containers/contains.h" #include "v8/include/cppgc/heap.h" #include "xfa/fxfa/layout/cxfa_contentlayoutitem.h" #include "xfa/fxfa/layout/cxfa_contentlayoutprocessor.h" @@ -36,7 +35,6 @@ CXFA_Document::LayoutProcessorIface::Trace(visitor); visitor->Trace(m_pViewLayoutProcessor); visitor->Trace(m_pContentLayoutProcessor); - ContainerTrace(visitor, m_rgChangedContainers); } void CXFA_LayoutProcessor::SetForceRelayout() { @@ -107,8 +105,8 @@ if (eStatus == CXFA_ContentLayoutProcessor::Result::kDone) { m_pViewLayoutProcessor->FinishPaginatedPageSets(); m_pViewLayoutProcessor->SyncLayoutData(); + m_bHasChangedContainers = false; m_bNeedLayout = false; - m_rgChangedContainers.clear(); } return 100 * (eStatus == CXFA_ContentLayoutProcessor::Result::kDone @@ -122,7 +120,7 @@ RestartLayout(); return DoLayout() == 100; } - return m_rgChangedContainers.empty(); + return !m_bHasChangedContainers; } int32_t CXFA_LayoutProcessor::CountPages() const { @@ -138,11 +136,10 @@ return pFormItem->JSObject()->GetLayoutItem(); } -void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { - if (!pdfium::Contains(m_rgChangedContainers, pContainer)) - m_rgChangedContainers.push_back(pContainer); +void CXFA_LayoutProcessor::SetHasChangedContainer() { + m_bHasChangedContainers = true; } bool CXFA_LayoutProcessor::NeedLayout() const { - return m_bNeedLayout || !m_rgChangedContainers.empty(); + return m_bNeedLayout || m_bHasChangedContainers; }
diff --git a/xfa/fxfa/layout/cxfa_layoutprocessor.h b/xfa/fxfa/layout/cxfa_layoutprocessor.h index 21a8b06..8c449cc 100644 --- a/xfa/fxfa/layout/cxfa_layoutprocessor.h +++ b/xfa/fxfa/layout/cxfa_layoutprocessor.h
@@ -9,8 +9,6 @@ #include <stdint.h> -#include <vector> - #include "core/fxcrt/unowned_ptr.h" #include "fxjs/gc/heap.h" #include "v8/include/cppgc/garbage-collected.h" @@ -39,11 +37,9 @@ // CXFA_Document::LayoutProcessorIface: void SetForceRelayout() override; - void AddChangedContainer(CXFA_Node* pContainer) override; + void SetHasChangedContainer() override; - cppgc::Heap* GetHeap() { return m_pHeap.Get(); } int32_t StartLayout(); - int32_t RestartLayout(); int32_t DoLayout(); bool IncrementLayout(); int32_t CountPages() const; @@ -58,13 +54,16 @@ private: explicit CXFA_LayoutProcessor(cppgc::Heap* pHeap); + + cppgc::Heap* GetHeap() { return m_pHeap.Get(); } bool NeedLayout() const; + int32_t RestartLayout(); UnownedPtr<cppgc::Heap> const m_pHeap; cppgc::Member<CXFA_ViewLayoutProcessor> m_pViewLayoutProcessor; cppgc::Member<CXFA_ContentLayoutProcessor> m_pContentLayoutProcessor; - std::vector<cppgc::Member<CXFA_Node>> m_rgChangedContainers; uint32_t m_nProgressCounter = 0; + bool m_bHasChangedContainers = false; bool m_bNeedLayout = true; };
diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h index 87d6795..7065772 100644 --- a/xfa/fxfa/parser/cxfa_document.h +++ b/xfa/fxfa/parser/cxfa_document.h
@@ -71,7 +71,7 @@ virtual void Trace(cppgc::Visitor* visitor) const; virtual void SetForceRelayout() = 0; - virtual void AddChangedContainer(CXFA_Node* pContainer) = 0; + virtual void SetHasChangedContainer() = 0; void SetDocument(CXFA_Document* pDocument) { m_pDocument = pDocument; } CXFA_Document* GetDocument() const { return m_pDocument; }
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 64bb803..4730394 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -2183,7 +2183,7 @@ case XFA_Element::Field: case XFA_Element::Subform: case XFA_Element::SubformSet: - pNotify->OnContainerChanged(this); + pNotify->OnContainerChanged(); pNotify->OnValueChanged(this, eAttribute, this, this); break; case XFA_Element::Sharptext: @@ -2231,7 +2231,7 @@ pParent = pParent->GetParent(); if (pParent) - pNotify->OnContainerChanged(pParent); + pNotify->OnContainerChanged(); } void CXFA_Node::SyncValue(const WideString& wsValue, bool bNotify) {