summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-21 16:25:01 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-21 16:25:01 +0000
commite6e262844037dfc66e5118bcedf1c84d57f78706 (patch)
tree5e939e1be2b819b49e2ac050412de2179e123cc6 /xfa
parent120c19b6a19377c341658c342c4351eccbb59741 (diff)
downloadpdfium-e6e262844037dfc66e5118bcedf1c84d57f78706.tar.xz
Add CXFA_MarginData::Get*Inset helpers
This CL adds Get*Inset helpers to CXFA_MarginData which just return a default value of 0 if the Try*Inset method fails. Change-Id: I03b00b7a371c39e521f95952e965b4a3ef71d517 Reviewed-on: https://pdfium-review.googlesource.com/18870 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/cxfa_fffield.cpp12
-rw-r--r--xfa/fxfa/cxfa_fftext.cpp24
-rw-r--r--xfa/fxfa/cxfa_ffwidget.cpp11
-rw-r--r--xfa/fxfa/cxfa_widgetacc.cpp74
-rw-r--r--xfa/fxfa/parser/cxfa_margindata.cpp24
-rw-r--r--xfa/fxfa/parser/cxfa_margindata.h5
6 files changed, 62 insertions, 88 deletions
diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp
index b4142ba701..3b9b7c67c8 100644
--- a/xfa/fxfa/cxfa_fffield.cpp
+++ b/xfa/fxfa/cxfa_fffield.cpp
@@ -172,14 +172,10 @@ void CXFA_FFField::CapPlacement() {
CXFA_MarginData marginData = m_pDataAcc->GetMarginData();
if (marginData.HasValidNode()) {
CXFA_LayoutItem* pItem = this;
- float fLeftInset = 0;
- float fRightInset = 0;
- float fTopInset = 0;
- float fBottomInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryRightInset(fRightInset);
- marginData.TryTopInset(fTopInset);
- marginData.TryBottomInset(fBottomInset);
+ float fLeftInset = marginData.GetLeftInset();
+ float fRightInset = marginData.GetRightInset();
+ float fTopInset = marginData.GetTopInset();
+ float fBottomInset = marginData.GetBottomInset();
if (!pItem->GetPrev() && !pItem->GetNext()) {
rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset);
} else {
diff --git a/xfa/fxfa/cxfa_fftext.cpp b/xfa/fxfa/cxfa_fftext.cpp
index 6242b8ec17..606c22e130 100644
--- a/xfa/fxfa/cxfa_fftext.cpp
+++ b/xfa/fxfa/cxfa_fftext.cpp
@@ -46,18 +46,15 @@ void CXFA_FFText::RenderWidget(CXFA_Graphics* pGS,
if (!pItem->GetPrev() && !pItem->GetNext()) {
XFA_RectWidthoutMargin(rtText, marginData);
} else {
- float fLeftInset = 0;
- float fRightInset = 0;
float fTopInset = 0;
float fBottomInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryRightInset(fRightInset);
if (!pItem->GetPrev())
- marginData.TryTopInset(fTopInset);
+ fTopInset = marginData.GetTopInset();
else if (!pItem->GetNext())
- marginData.TryBottomInset(fBottomInset);
+ fBottomInset = marginData.GetBottomInset();
- rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset);
+ rtText.Deflate(marginData.GetLeftInset(), fTopInset,
+ marginData.GetRightInset(), fBottomInset);
}
}
@@ -90,15 +87,10 @@ bool CXFA_FFText::PerformLayout() {
CFX_RectF rtText = pItem->GetRect(false);
CXFA_MarginData marginData = m_pDataAcc->GetMarginData();
if (marginData.HasValidNode()) {
- if (!pItem->GetPrev()) {
- float fTopInset = 0;
- marginData.TryTopInset(fTopInset);
- rtText.height -= fTopInset;
- } else if (!pItem->GetNext()) {
- float fBottomInset = 0;
- marginData.TryBottomInset(fBottomInset);
- rtText.height -= fBottomInset;
- }
+ if (!pItem->GetPrev())
+ rtText.height -= marginData.GetTopInset();
+ else if (!pItem->GetNext())
+ rtText.height -= marginData.GetBottomInset();
}
pTextLayout->ItemBlocks(rtText, pItem->GetIndex());
pItem = pItem->GetNext();
diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp
index 00ab8cda0e..24e647a1cd 100644
--- a/xfa/fxfa/cxfa_ffwidget.cpp
+++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -2026,15 +2026,8 @@ void XFA_RectWidthoutMargin(CFX_RectF& rt,
if (!marginData.HasValidNode())
return;
- float fLeftInset = 0;
- float fTopInset = 0;
- float fRightInset = 0;
- float fBottomInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryTopInset(fTopInset);
- marginData.TryRightInset(fRightInset);
- marginData.TryBottomInset(fBottomInset);
- rt.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset);
+ rt.Deflate(marginData.GetLeftInset(), marginData.GetTopInset(),
+ marginData.GetRightInset(), marginData.GetBottomInset());
}
CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem) {
diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp
index b55adc04a4..cc9f38141f 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -731,14 +731,10 @@ void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) {
CXFA_MarginData captionMarginData = captionData.GetMarginData();
if (captionMarginData.HasValidNode()) {
- float fLeftInset = 0;
- float fTopInset = 0;
- float fRightInset = 0;
- float fBottomInset = 0;
- captionMarginData.TryLeftInset(fLeftInset);
- captionMarginData.TryTopInset(fTopInset);
- captionMarginData.TryRightInset(fRightInset);
- captionMarginData.TryBottomInset(fBottomInset);
+ float fLeftInset = captionMarginData.GetLeftInset();
+ float fTopInset = captionMarginData.GetTopInset();
+ float fRightInset = captionMarginData.GetRightInset();
+ float fBottomInset = captionMarginData.GetBottomInset();
if (bReserveExit) {
bVert ? (szCap.width += fLeftInset + fRightInset)
: (szCap.height += fTopInset + fBottomInset);
@@ -779,16 +775,8 @@ bool CXFA_WidgetAcc::CalculateFieldAutoSize(CFX_SizeF& size) {
bool CXFA_WidgetAcc::CalculateWidgetAutoSize(CFX_SizeF& size) {
CXFA_MarginData marginData = GetMarginData();
if (marginData.HasValidNode()) {
- float fLeftInset = 0;
- float fTopInset = 0;
- float fRightInset = 0;
- float fBottomInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryTopInset(fTopInset);
- marginData.TryRightInset(fRightInset);
- marginData.TryBottomInset(fBottomInset);
- size.width += fLeftInset + fRightInset;
- size.height += fTopInset + fBottomInset;
+ size.width += marginData.GetLeftInset() + marginData.GetRightInset();
+ size.height += marginData.GetTopInset() + marginData.GetBottomInset();
}
CXFA_ParaData paraData = GetParaData();
@@ -876,13 +864,9 @@ bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) {
CFX_RectF rtUIMargin = GetUIMargin();
size.width -= rtUIMargin.left + rtUIMargin.width;
CXFA_MarginData marginData = GetMarginData();
- if (marginData.HasValidNode()) {
- float fLeftInset = 0;
- float fRightInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryRightInset(fRightInset);
- size.width -= fLeftInset + fRightInset;
- }
+ if (marginData.HasValidNode())
+ size.width -= marginData.GetLeftInset() + marginData.GetRightInset();
+
CalculateTextContentSize(size);
size.height += rtUIMargin.top + rtUIMargin.height;
if (bCapExit) {
@@ -1023,13 +1007,8 @@ void CXFA_WidgetAcc::LoadText() {
float CXFA_WidgetAcc::CalculateWidgetAutoWidth(float fWidthCalc) {
CXFA_MarginData marginData = GetMarginData();
- if (marginData.HasValidNode()) {
- float fLeftInset = 0;
- float fRightInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryRightInset(fRightInset);
- fWidthCalc += fLeftInset + fRightInset;
- }
+ if (marginData.HasValidNode())
+ fWidthCalc += marginData.GetLeftInset() + marginData.GetRightInset();
float fMin = 0, fMax = 0;
if (GetMinWidth(fMin))
@@ -1042,25 +1021,15 @@ float CXFA_WidgetAcc::CalculateWidgetAutoWidth(float fWidthCalc) {
float CXFA_WidgetAcc::GetWidthWithoutMargin(float fWidthCalc) {
CXFA_MarginData marginData = GetMarginData();
- if (marginData.HasValidNode()) {
- float fLeftInset = 0;
- float fRightInset = 0;
- marginData.TryLeftInset(fLeftInset);
- marginData.TryRightInset(fRightInset);
- fWidthCalc -= fLeftInset + fRightInset;
- }
+ if (marginData.HasValidNode())
+ fWidthCalc -= marginData.GetLeftInset() + marginData.GetRightInset();
return fWidthCalc;
}
float CXFA_WidgetAcc::CalculateWidgetAutoHeight(float fHeightCalc) {
CXFA_MarginData marginData = GetMarginData();
- if (marginData.HasValidNode()) {
- float fTopInset = 0;
- float fBottomInset = 0;
- marginData.TryTopInset(fTopInset);
- marginData.TryBottomInset(fBottomInset);
- fHeightCalc += fTopInset + fBottomInset;
- }
+ if (marginData.HasValidNode())
+ fHeightCalc += marginData.GetTopInset() + marginData.GetBottomInset();
float fMin = 0, fMax = 0;
if (GetMinHeight(fMin))
@@ -1073,13 +1042,8 @@ float CXFA_WidgetAcc::CalculateWidgetAutoHeight(float fHeightCalc) {
float CXFA_WidgetAcc::GetHeightWithoutMargin(float fHeightCalc) {
CXFA_MarginData marginData = GetMarginData();
- if (marginData.HasValidNode()) {
- float fTopInset = 0;
- float fBottomInset = 0;
- marginData.TryTopInset(fTopInset);
- marginData.TryBottomInset(fBottomInset);
- fHeightCalc -= fTopInset + fBottomInset;
- }
+ if (marginData.HasValidNode())
+ fHeightCalc -= marginData.GetTopInset() + marginData.GetBottomInset();
return fHeightCalc;
}
@@ -1173,8 +1137,8 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, float& fCalcHeight) {
if (iBlockIndex == 0) {
CXFA_MarginData marginData = GetMarginData();
if (marginData.HasValidNode()) {
- marginData.TryTopInset(fTopInset);
- marginData.TryBottomInset(fBottomInset);
+ fTopInset = marginData.GetTopInset();
+ fBottomInset = marginData.GetBottomInset();
}
CFX_RectF rtUIMargin = GetUIMargin();
diff --git a/xfa/fxfa/parser/cxfa_margindata.cpp b/xfa/fxfa/parser/cxfa_margindata.cpp
index 2c5689cfa0..4eedaeb7e7 100644
--- a/xfa/fxfa/parser/cxfa_margindata.cpp
+++ b/xfa/fxfa/parser/cxfa_margindata.cpp
@@ -8,6 +8,30 @@
CXFA_MarginData::CXFA_MarginData(CXFA_Node* pNode) : CXFA_DataData(pNode) {}
+float CXFA_MarginData::GetLeftInset() const {
+ float left = 0;
+ TryLeftInset(left);
+ return left;
+}
+
+float CXFA_MarginData::GetTopInset() const {
+ float top = 0;
+ TryTopInset(top);
+ return top;
+}
+
+float CXFA_MarginData::GetRightInset() const {
+ float right = 0;
+ TryRightInset(right);
+ return right;
+}
+
+float CXFA_MarginData::GetBottomInset() const {
+ float bottom = 0;
+ TryBottomInset(bottom);
+ return bottom;
+}
+
bool CXFA_MarginData::TryLeftInset(float& fInset) const {
return TryMeasure(XFA_Attribute::LeftInset, fInset);
}
diff --git a/xfa/fxfa/parser/cxfa_margindata.h b/xfa/fxfa/parser/cxfa_margindata.h
index 6933c3d078..1a8b4d8be1 100644
--- a/xfa/fxfa/parser/cxfa_margindata.h
+++ b/xfa/fxfa/parser/cxfa_margindata.h
@@ -16,6 +16,11 @@ class CXFA_MarginData : public CXFA_DataData {
public:
explicit CXFA_MarginData(CXFA_Node* pNode);
+ float GetLeftInset() const;
+ float GetTopInset() const;
+ float GetRightInset() const;
+ float GetBottomInset() const;
+
bool TryLeftInset(float& fInset) const;
bool TryTopInset(float& fInset) const;
bool TryRightInset(float& fInset) const;