From 2f265dbf12831dece93a6a932fd99e5737cd1afd Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 8 Jan 2018 12:28:27 -0500 Subject: Move proxy methods from CXFA_WidgetAcc to CXFA_Node This CL moves methods from WidgetAcc which just proxy to CXFA_Node. Change-Id: Icf1006b4be3f91077de411ed1a571b1507117602 Reviewed-on: https://pdfium-review.googlesource.com/22391 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_node.cpp | 127 ++++++++++++++++++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_node.h | 31 +++++++++++ xfa/fxfa/parser/xfa_utils.cpp | 2 +- 3 files changed, 159 insertions(+), 1 deletion(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 141c9f1c6c..86d2300cb4 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -29,15 +29,24 @@ #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_arraynodelist.h" #include "xfa/fxfa/parser/cxfa_attachnodelist.h" +#include "xfa/fxfa/parser/cxfa_bind.h" +#include "xfa/fxfa/parser/cxfa_border.h" +#include "xfa/fxfa/parser/cxfa_calculate.h" +#include "xfa/fxfa/parser/cxfa_caption.h" #include "xfa/fxfa/parser/cxfa_document.h" +#include "xfa/fxfa/parser/cxfa_font.h" #include "xfa/fxfa/parser/cxfa_keep.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_margin.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" #include "xfa/fxfa/parser/cxfa_occur.h" +#include "xfa/fxfa/parser/cxfa_para.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/cxfa_subform.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" +#include "xfa/fxfa/parser/cxfa_validate.h" +#include "xfa/fxfa/parser/cxfa_value.h" #include "xfa/fxfa/parser/xfa_basic_data.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -1533,3 +1542,121 @@ void CXFA_Node::SyncValue(const WideString& wsValue, bool bNotify) { JSObject()->SetContent(wsValue, wsFormatValue, bNotify, false, true); } + +WideString CXFA_Node::GetRawValue() { + return JSObject()->GetContent(false); +} + +int32_t CXFA_Node::GetRotate() { + Optional degrees = + JSObject()->TryInteger(XFA_Attribute::Rotate, false); + return degrees ? XFA_MapRotation(*degrees) / 90 * 90 : 0; +} + +CXFA_Border* CXFA_Node::GetBorder(bool bModified) { + return JSObject()->GetProperty(0, XFA_Element::Border, + bModified); +} + +CXFA_Caption* CXFA_Node::GetCaption() { + return JSObject()->GetProperty(0, XFA_Element::Caption, false); +} + +CXFA_Font* CXFA_Node::GetFont(bool bModified) { + return JSObject()->GetProperty(0, XFA_Element::Font, bModified); +} + +float CXFA_Node::GetFontSize() { + CXFA_Font* font = GetFont(false); + float fFontSize = font ? font->GetFontSize() : 10.0f; + return fFontSize < 0.1f ? 10.0f : fFontSize; +} + +float CXFA_Node::GetLineHeight() { + float fLineHeight = 0; + CXFA_Para* para = GetPara(); + if (para) + fLineHeight = para->GetLineHeight(); + if (fLineHeight < 1) + fLineHeight = GetFontSize() * 1.2f; + return fLineHeight; +} + +FX_ARGB CXFA_Node::GetTextColor() { + CXFA_Font* font = GetFont(false); + return font ? font->GetColor() : 0xFF000000; +} + +CXFA_Margin* CXFA_Node::GetMargin() { + return JSObject()->GetProperty(0, XFA_Element::Margin, false); +} + +CXFA_Para* CXFA_Node::GetPara() { + return JSObject()->GetProperty(0, XFA_Element::Para, false); +} + +bool CXFA_Node::IsOpenAccess() { + for (auto* pNode = this; pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_Parent, + XFA_ObjectType::ContainerNode)) { + XFA_AttributeEnum iAcc = pNode->JSObject()->GetEnum(XFA_Attribute::Access); + if (iAcc != XFA_AttributeEnum::Open) + return false; + } + return true; +} + +CXFA_Value* CXFA_Node::GetDefaultValue() { + CXFA_Node* pTemNode = GetTemplateNode(); + return pTemNode->JSObject()->GetProperty(0, XFA_Element::Value, + false); +} + +CXFA_Value* CXFA_Node::GetFormValue() { + return JSObject()->GetProperty(0, XFA_Element::Value, false); +} + +CXFA_Calculate* CXFA_Node::GetCalculate() { + return JSObject()->GetProperty(0, XFA_Element::Calculate, + false); +} + +CXFA_Validate* CXFA_Node::GetValidate(bool bModified) { + return JSObject()->GetProperty(0, XFA_Element::Validate, + bModified); +} + +CXFA_Bind* CXFA_Node::GetBind() { + return JSObject()->GetProperty(0, XFA_Element::Bind, false); +} + +Optional CXFA_Node::TryWidth() { + return JSObject()->TryMeasureAsFloat(XFA_Attribute::W); +} + +Optional CXFA_Node::TryHeight() { + return JSObject()->TryMeasureAsFloat(XFA_Attribute::H); +} + +Optional CXFA_Node::TryMinWidth() { + return JSObject()->TryMeasureAsFloat(XFA_Attribute::MinW); +} + +Optional CXFA_Node::TryMinHeight() { + return JSObject()->TryMeasureAsFloat(XFA_Attribute::MinH); +} + +Optional CXFA_Node::TryMaxWidth() { + return JSObject()->TryMeasureAsFloat(XFA_Attribute::MaxW); +} + +Optional CXFA_Node::TryMaxHeight() { + return JSObject()->TryMeasureAsFloat(XFA_Attribute::MaxH); +} + +CXFA_Node* CXFA_Node::GetExclGroup() { + CXFA_Node* pExcl = GetNodeItem(XFA_NODEITEM_Parent); + if (!pExcl || pExcl->GetElementType() != XFA_Element::ExclGroup) + return nullptr; + return pExcl; +} diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index c8adbfe080..4def12caaf 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -218,6 +218,37 @@ class CXFA_Node : public CXFA_Object { void SyncValue(const WideString& wsValue, bool bNotify); + bool IsOpenAccess(); + + CXFA_Border* GetBorder(bool bModified); + CXFA_Caption* GetCaption(); + + CXFA_Font* GetFont(bool bModified); + float GetFontSize(); + FX_ARGB GetTextColor(); + float GetLineHeight(); + + CXFA_Margin* GetMargin(); + CXFA_Para* GetPara(); + CXFA_Calculate* GetCalculate(); + CXFA_Validate* GetValidate(bool bModified); + + CXFA_Value* GetDefaultValue(); + CXFA_Value* GetFormValue(); + WideString GetRawValue(); + int32_t GetRotate(); + + CXFA_Bind* GetBind(); + + Optional TryWidth(); + Optional TryHeight(); + Optional TryMinWidth(); + Optional TryMinHeight(); + Optional TryMaxWidth(); + Optional TryMaxHeight(); + + CXFA_Node* GetExclGroup(); + protected: CXFA_Node(CXFA_Document* pDoc, XFA_PacketType ePacket, diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index c41835f19c..3342776adb 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp @@ -457,7 +457,7 @@ CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetAcc* pWidgetAcc) { iVTType = XFA_VT_NULL; break; } - return CXFA_LocaleValue(iVTType, pWidgetAcc->GetRawValue(), + return CXFA_LocaleValue(iVTType, pWidgetAcc->GetNode()->GetRawValue(), pWidgetAcc->GetNode()->GetDocument()->GetLocalMgr()); } -- cgit v1.2.3