summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_layoutprocessor.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-07-21 12:03:01 -0700
committerCommit bot <commit-bot@chromium.org>2016-07-21 12:03:02 -0700
commit0b851fffe118d8be26e776256144a6b85495ce74 (patch)
tree909dd6a08a506894f1953fb00e8afc8c27c8dd8e /xfa/fxfa/parser/cxfa_layoutprocessor.cpp
parent9eb0db1d7f6273de7eb28b0e1490eaf893e3bfb5 (diff)
downloadpdfium-0b851fffe118d8be26e776256144a6b85495ce74.tar.xz
Rename xfa_doclayout and xfa_document_layout_imp files.
This Cl moves the xfa_doclayout and xfa_document_layout_imp files to have names based off of their classes. Review-Url: https://codereview.chromium.org/2170473002
Diffstat (limited to 'xfa/fxfa/parser/cxfa_layoutprocessor.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_layoutprocessor.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp
new file mode 100644
index 0000000000..7ebe5285e3
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp
@@ -0,0 +1,163 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
+
+#include "xfa/fxfa/parser/cxfa_measurement.h"
+#include "xfa/fxfa/parser/xfa_document.h"
+#include "xfa/fxfa/parser/xfa_document_datamerger_imp.h"
+#include "xfa/fxfa/parser/xfa_layout_appadapter.h"
+#include "xfa/fxfa/parser/xfa_layout_itemlayout.h"
+#include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h"
+#include "xfa/fxfa/parser/xfa_localemgr.h"
+#include "xfa/fxfa/parser/xfa_object.h"
+#include "xfa/fxfa/parser/xfa_utils.h"
+
+CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() {
+ if (!m_pLayoutProcessor) {
+ m_pLayoutProcessor = new CXFA_LayoutProcessor(this);
+ ASSERT(m_pLayoutProcessor);
+ }
+ return m_pLayoutProcessor;
+}
+
+CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() {
+ return GetLayoutProcessor();
+}
+
+CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument)
+ : m_pDocument(pDocument),
+ m_pRootItemLayoutProcessor(nullptr),
+ m_pLayoutPageMgr(nullptr),
+ m_nProgressCounter(0),
+ m_bNeeLayout(TRUE) {}
+
+CXFA_LayoutProcessor::~CXFA_LayoutProcessor() {
+ ClearLayoutData();
+}
+
+CXFA_Document* CXFA_LayoutProcessor::GetDocument() const {
+ return m_pDocument;
+}
+
+int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) {
+ if (!bForceRestart && !IsNeedLayout())
+ return 100;
+
+ delete m_pRootItemLayoutProcessor;
+ m_pRootItemLayoutProcessor = nullptr;
+ m_nProgressCounter = 0;
+ CXFA_Node* pFormPacketNode =
+ ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
+ if (!pFormPacketNode)
+ return -1;
+
+ CXFA_Node* pFormRoot =
+ pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform);
+ if (!pFormRoot)
+ return -1;
+ if (!m_pLayoutPageMgr)
+ m_pLayoutPageMgr = new CXFA_LayoutPageMgr(this);
+ if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot))
+ return -1;
+ if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot))
+ return -1;
+ m_pRootItemLayoutProcessor =
+ new CXFA_ItemLayoutProcessor(pFormRoot, m_pLayoutPageMgr);
+ m_nProgressCounter = 1;
+ return 0;
+}
+
+int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) {
+ if (m_nProgressCounter < 1)
+ return -1;
+
+ XFA_ItemLayoutProcessorResult eStatus;
+ CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode();
+ FX_FLOAT fPosX = pFormNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt);
+ FX_FLOAT fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt);
+ do {
+ FX_FLOAT fAvailHeight = m_pLayoutPageMgr->GetAvailHeight();
+ eStatus =
+ m_pRootItemLayoutProcessor->DoLayout(TRUE, fAvailHeight, fAvailHeight);
+ if (eStatus != XFA_ItemLayoutProcessorResult_Done)
+ m_nProgressCounter++;
+
+ CXFA_ContentLayoutItem* pLayoutItem =
+ m_pRootItemLayoutProcessor->ExtractLayoutItem();
+ if (pLayoutItem)
+ pLayoutItem->m_sPos = CFX_PointF(fPosX, fPosY);
+
+ m_pLayoutPageMgr->SubmitContentItem(pLayoutItem, eStatus);
+ } while (eStatus != XFA_ItemLayoutProcessorResult_Done &&
+ (!pPause || !pPause->NeedToPauseNow()));
+
+ if (eStatus == XFA_ItemLayoutProcessorResult_Done) {
+ m_pLayoutPageMgr->FinishPaginatedPageSets();
+ m_pLayoutPageMgr->SyncLayoutData();
+ m_bNeeLayout = FALSE;
+ m_rgChangedContainers.RemoveAll();
+ }
+ return 100 * (eStatus == XFA_ItemLayoutProcessorResult_Done
+ ? m_nProgressCounter
+ : m_nProgressCounter - 1) /
+ m_nProgressCounter;
+}
+
+FX_BOOL CXFA_LayoutProcessor::IncrementLayout() {
+ if (m_bNeeLayout) {
+ StartLayout(TRUE);
+ return DoLayout(nullptr) == 100;
+ }
+
+ for (int32_t i = 0, c = m_rgChangedContainers.GetSize(); i < c; i++) {
+ CXFA_Node* pNode = m_rgChangedContainers[i];
+ CXFA_Node* pParentNode =
+ pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode);
+ if (!pParentNode)
+ return FALSE;
+ if (!CXFA_ItemLayoutProcessor::IncrementRelayoutNode(this, pNode,
+ pParentNode)) {
+ return FALSE;
+ }
+ }
+ m_rgChangedContainers.RemoveAll();
+ return TRUE;
+}
+
+int32_t CXFA_LayoutProcessor::CountPages() const {
+ return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPageCount() : 0;
+}
+
+CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetPage(int32_t index) const {
+ return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetPage(index) : nullptr;
+}
+
+CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) {
+ return static_cast<CXFA_LayoutItem*>(
+ pFormItem->GetUserData(XFA_LAYOUTITEMKEY));
+}
+
+void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) {
+ if (m_rgChangedContainers.Find(pContainer) < 0)
+ m_rgChangedContainers.Add(pContainer);
+}
+
+CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const {
+ return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr;
+}
+
+void CXFA_LayoutProcessor::ClearLayoutData() {
+ delete m_pLayoutPageMgr;
+ m_pLayoutPageMgr = nullptr;
+ delete m_pRootItemLayoutProcessor;
+ m_pRootItemLayoutProcessor = nullptr;
+ m_nProgressCounter = 0;
+}
+
+FX_BOOL CXFA_LayoutProcessor::IsNeedLayout() {
+ return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0;
+}