summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-20 19:14:17 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-20 19:14:17 +0000
commit4be873b32a85f475fa2b377371f859857e8f2b0e (patch)
tree0604c7b40ba7d4ebac4c119ff6e5fd532b45eb92 /xfa/fxfa
parent9273e0674ecf87929696ca89cbf16371edabc315 (diff)
downloadpdfium-4be873b32a85f475fa2b377371f859857e8f2b0e.tar.xz
Fix nits in CXFA_Node.
- Make methods const or move them into the anonymous namespace. - Make GetItemLabel() return the value. Change-Id: Ic6938d14e7efa09f1851950c28d3c855690d9aaf Reviewed-on: https://pdfium-review.googlesource.com/40650 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp97
-rw-r--r--xfa/fxfa/parser/cxfa_node.h7
2 files changed, 48 insertions, 56 deletions
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index a60e66584b..6b30f79210 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -368,6 +368,42 @@ float GetEdgeThickness(const std::vector<CXFA_Stroke*>& strokes,
return fThickness;
}
+WideString FormatNumStr(const WideString& wsValue, LocaleIface* pLocale) {
+ if (wsValue.IsEmpty())
+ return L"";
+
+ WideString wsSrcNum = wsValue;
+ WideString wsGroupSymbol = pLocale->GetGroupingSymbol();
+ bool bNeg = false;
+ if (wsSrcNum[0] == '-') {
+ bNeg = true;
+ wsSrcNum.Delete(0, 1);
+ }
+
+ auto dot_index = wsSrcNum.Find('.');
+ dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index;
+
+ if (dot_index.value() < 1)
+ return L"";
+
+ size_t nPos = dot_index.value() % 3;
+ WideString wsOutput;
+ for (size_t i = 0; i < dot_index.value(); i++) {
+ if (i % 3 == nPos && i != 0)
+ wsOutput += wsGroupSymbol;
+
+ wsOutput += wsSrcNum[i];
+ }
+ if (dot_index.value() < wsSrcNum.GetLength()) {
+ wsOutput += pLocale->GetDecimalSymbol();
+ wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1);
+ }
+ if (bNeg)
+ return pLocale->GetMinusSymbol() + wsOutput;
+
+ return wsOutput;
+}
+
} // namespace
class CXFA_WidgetLayoutData {
@@ -3050,7 +3086,7 @@ float CXFA_Node::CalculateWidgetAutoWidth(float fWidthCalc) {
return fWidthCalc;
}
-float CXFA_Node::GetWidthWithoutMargin(float fWidthCalc) {
+float CXFA_Node::GetWidthWithoutMargin(float fWidthCalc) const {
CXFA_Margin* margin = GetMarginIfExists();
if (margin)
fWidthCalc -= margin->GetLeftInset() + margin->GetRightInset();
@@ -3073,7 +3109,7 @@ float CXFA_Node::CalculateWidgetAutoHeight(float fHeightCalc) {
return fHeightCalc;
}
-float CXFA_Node::GetHeightWithoutMargin(float fHeightCalc) {
+float CXFA_Node::GetHeightWithoutMargin(float fHeightCalc) const {
CXFA_Margin* margin = GetMarginIfExists();
if (margin)
fHeightCalc -= margin->GetTopInset() + margin->GetBottomInset();
@@ -4079,22 +4115,17 @@ void CXFA_Node::InsertItem(const WideString& wsLabel,
wsValue.c_str(), nIndex);
}
-void CXFA_Node::GetItemLabel(const WideStringView& wsValue,
- WideString& wsLabel) {
- int32_t iCount = 0;
+WideString CXFA_Node::GetItemLabel(const WideStringView& wsValue) const {
std::vector<CXFA_Node*> listitems;
CXFA_Node* pItems = GetFirstChild();
for (; pItems; pItems = pItems->GetNextSibling()) {
if (pItems->GetElementType() != XFA_Element::Items)
continue;
- iCount++;
listitems.push_back(pItems);
}
- if (iCount <= 1) {
- wsLabel = wsValue;
- return;
- }
+ if (listitems.size() <= 1)
+ return WideString(wsValue);
CXFA_Node* pLabelItems = listitems[0];
bool bSave = pLabelItems->JSObject()->GetBoolean(XFA_Attribute::Save);
@@ -4105,8 +4136,8 @@ void CXFA_Node::GetItemLabel(const WideStringView& wsValue,
} else {
pSaveItems = listitems[1];
}
- iCount = 0;
+ int32_t iCount = 0;
int32_t iSearch = -1;
for (CXFA_Node* pChildItem = pSaveItems->GetFirstChild(); pChildItem;
pChildItem = pChildItem->GetNextSibling()) {
@@ -4117,12 +4148,11 @@ void CXFA_Node::GetItemLabel(const WideStringView& wsValue,
iCount++;
}
if (iSearch < 0)
- return;
+ return WideString();
CXFA_Node* pText =
pLabelItems->GetChild<CXFA_Node>(iSearch, XFA_Element::Unknown, false);
- if (pText)
- wsLabel = pText->JSObject()->GetContent(false);
+ return pText ? pText->JSObject()->GetContent(false) : WideString();
}
WideString CXFA_Node::GetItemValue(const WideStringView& wsLabel) {
@@ -4413,7 +4443,7 @@ WideString CXFA_Node::GetValue(XFA_VALUEPICTURE eValueType) {
WideString wsValue = JSObject()->GetContent(false);
if (eValueType == XFA_VALUEPICTURE_Display)
- GetItemLabel(wsValue.AsStringView(), wsValue);
+ wsValue = GetItemLabel(wsValue.AsStringView());
WideString wsPicture = GetPictureContent(eValueType);
CXFA_Node* pNode = GetUIChildNode();
@@ -4592,43 +4622,6 @@ WideString CXFA_Node::NormalizeNumStr(const WideString& wsValue) {
return wsOutput;
}
-WideString CXFA_Node::FormatNumStr(const WideString& wsValue,
- LocaleIface* pLocale) {
- if (wsValue.IsEmpty())
- return L"";
-
- WideString wsSrcNum = wsValue;
- WideString wsGroupSymbol = pLocale->GetGroupingSymbol();
- bool bNeg = false;
- if (wsSrcNum[0] == '-') {
- bNeg = true;
- wsSrcNum.Delete(0, 1);
- }
-
- auto dot_index = wsSrcNum.Find('.');
- dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index;
-
- if (dot_index.value() < 1)
- return L"";
-
- size_t nPos = dot_index.value() % 3;
- WideString wsOutput;
- for (size_t i = 0; i < dot_index.value(); i++) {
- if (i % 3 == nPos && i != 0)
- wsOutput += wsGroupSymbol;
-
- wsOutput += wsSrcNum[i];
- }
- if (dot_index.value() < wsSrcNum.GetLength()) {
- wsOutput += pLocale->GetDecimalSymbol();
- wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1);
- }
- if (bNeg)
- return pLocale->GetMinusSymbol() + wsOutput;
-
- return wsOutput;
-}
-
void CXFA_Node::InsertListTextItem(CXFA_Node* pItems,
const WideString& wsText,
int32_t nIndex) {
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 99930c6686..72e2a4eb4a 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -450,8 +450,8 @@ class CXFA_Node : public CXFA_Object {
bool CalculateImageAutoSize(CXFA_FFDoc* doc, CFX_SizeF* pSize);
float CalculateWidgetAutoHeight(float fHeightCalc);
float CalculateWidgetAutoWidth(float fWidthCalc);
- float GetWidthWithoutMargin(float fWidthCalc);
- float GetHeightWithoutMargin(float fHeightCalc);
+ float GetWidthWithoutMargin(float fWidthCalc) const;
+ float GetHeightWithoutMargin(float fHeightCalc) const;
void CalculateTextContentSize(CXFA_FFDoc* doc, CFX_SizeF* pSize);
CFX_SizeF CalculateAccWidthAndHeight(CXFA_FFDoc* doc, float fWidth);
void InitLayoutData();
@@ -460,8 +460,7 @@ class CXFA_Node : public CXFA_Object {
void InsertListTextItem(CXFA_Node* pItems,
const WideString& wsText,
int32_t nIndex);
- WideString FormatNumStr(const WideString& wsValue, LocaleIface* pLocale);
- void GetItemLabel(const WideStringView& wsValue, WideString& wsLabel);
+ WideString GetItemLabel(const WideStringView& wsValue) const;
std::pair<XFA_FFWidgetType, CXFA_Ui*> CreateChildUIAndValueNodesIfNeeded();
void CreateValueNodeIfNeeded(CXFA_Value* value, CXFA_Node* pUIChild);