From 90d9386825b872a0b668eac5dff3e268fa7ad16c Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 30 Jan 2018 21:38:40 +0000 Subject: Shuffle more code out of CXFA_Node This CL moves more code out of the CXFA_Node class and into specific subclasses. Change-Id: Idca36f251431bf7efd4da045aeabf097ab23f0ce Reviewed-on: https://pdfium-review.googlesource.com/24714 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/cxfa_ffbarcode.h | 2 +- xfa/fxfa/cxfa_ffcheckbutton.cpp | 2 +- xfa/fxfa/cxfa_ffcheckbutton.h | 2 +- xfa/fxfa/cxfa_ffnotify.cpp | 17 +++++++++++++---- xfa/fxfa/cxfa_ffpasswordedit.cpp | 8 +++++--- xfa/fxfa/cxfa_ffpasswordedit.h | 8 +++++++- xfa/fxfa/cxfa_ffpushbutton.cpp | 7 ++++--- xfa/fxfa/cxfa_ffpushbutton.h | 7 +++++-- xfa/fxfa/parser/cxfa_button.cpp | 4 ++++ xfa/fxfa/parser/cxfa_button.h | 2 ++ xfa/fxfa/parser/cxfa_checkbutton.cpp | 4 ++++ xfa/fxfa/parser/cxfa_checkbutton.h | 1 + xfa/fxfa/parser/cxfa_node.cpp | 34 +++++++--------------------------- xfa/fxfa/parser/cxfa_node.h | 3 --- xfa/fxfa/parser/cxfa_passwordedit.cpp | 4 ++++ xfa/fxfa/parser/cxfa_passwordedit.h | 1 + 16 files changed, 60 insertions(+), 46 deletions(-) diff --git a/xfa/fxfa/cxfa_ffbarcode.h b/xfa/fxfa/cxfa_ffbarcode.h index df62b8ee7f..7804ce3830 100644 --- a/xfa/fxfa/cxfa_ffbarcode.h +++ b/xfa/fxfa/cxfa_ffbarcode.h @@ -90,7 +90,7 @@ class CXFA_FFBarcode : public CXFA_FFTextEdit { public: static const BarCodeInfo* GetBarcodeTypeByName(const WideString& wsName); - explicit CXFA_FFBarcode(CXFA_Node* pNode, CXFA_Barcode* barcode); + CXFA_FFBarcode(CXFA_Node* pNode, CXFA_Barcode* barcode); ~CXFA_FFBarcode() override; // CXFA_FFTextEdit diff --git a/xfa/fxfa/cxfa_ffcheckbutton.cpp b/xfa/fxfa/cxfa_ffcheckbutton.cpp index 57233a0f56..f5f840847b 100644 --- a/xfa/fxfa/cxfa_ffcheckbutton.cpp +++ b/xfa/fxfa/cxfa_ffcheckbutton.cpp @@ -82,7 +82,7 @@ void CXFA_FFCheckButton::UpdateWidgetProperty() { dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; } break; } - if (m_pNode->IsAllowNeutral()) + if (button_->IsAllowNeutral()) dwStyleEx |= FWL_STYLEEXT_CKB_3State; pCheckBox->ModifyStylesEx( diff --git a/xfa/fxfa/cxfa_ffcheckbutton.h b/xfa/fxfa/cxfa_ffcheckbutton.h index d1fb21c47d..12519a9543 100644 --- a/xfa/fxfa/cxfa_ffcheckbutton.h +++ b/xfa/fxfa/cxfa_ffcheckbutton.h @@ -16,7 +16,7 @@ class CXFA_CheckButton; class CXFA_FFCheckButton : public CXFA_FFField { public: - explicit CXFA_FFCheckButton(CXFA_Node* pNode, CXFA_CheckButton* button); + CXFA_FFCheckButton(CXFA_Node* pNode, CXFA_CheckButton* button); ~CXFA_FFCheckButton() override; // CXFA_FFField diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index a929e1a57c..6802fd32b3 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -37,8 +37,10 @@ #include "xfa/fxfa/cxfa_textprovider.h" #include "xfa/fxfa/parser/cxfa_barcode.h" #include "xfa/fxfa/parser/cxfa_binditems.h" +#include "xfa/fxfa/parser/cxfa_button.h" #include "xfa/fxfa/parser/cxfa_checkbutton.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_passwordedit.h" namespace { @@ -118,9 +120,12 @@ CXFA_ContentLayoutItem* CXFA_FFNotify::OnCreateContentLayoutItem( pWidget = new CXFA_FFBarcode(pNode, static_cast(child)); break; } - case XFA_FFWidgetType::kButton: - pWidget = new CXFA_FFPushButton(pNode); + case XFA_FFWidgetType::kButton: { + CXFA_Node* child = pNode->GetUIChildNode(); + ASSERT(child->GetElementType() == XFA_Element::Button); + pWidget = new CXFA_FFPushButton(pNode, static_cast(child)); break; + } case XFA_FFWidgetType::kCheckButton: { CXFA_Node* child = pNode->GetUIChildNode(); ASSERT(child->GetElementType() == XFA_Element::CheckButton); @@ -143,9 +148,13 @@ CXFA_ContentLayoutItem* CXFA_FFNotify::OnCreateContentLayoutItem( case XFA_FFWidgetType::kNumericEdit: pWidget = new CXFA_FFNumericEdit(pNode); break; - case XFA_FFWidgetType::kPasswordEdit: - pWidget = new CXFA_FFPasswordEdit(pNode); + case XFA_FFWidgetType::kPasswordEdit: { + CXFA_Node* child = pNode->GetUIChildNode(); + ASSERT(child->GetElementType() == XFA_Element::PasswordEdit); + pWidget = new CXFA_FFPasswordEdit(pNode, + static_cast(child)); break; + } case XFA_FFWidgetType::kSignature: pWidget = new CXFA_FFSignature(pNode); break; diff --git a/xfa/fxfa/cxfa_ffpasswordedit.cpp b/xfa/fxfa/cxfa_ffpasswordedit.cpp index 4dc46c6dda..f49a990650 100644 --- a/xfa/fxfa/cxfa_ffpasswordedit.cpp +++ b/xfa/fxfa/cxfa_ffpasswordedit.cpp @@ -12,9 +12,11 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_passwordedit.h" -CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_Node* pNode) - : CXFA_FFTextEdit(pNode) {} +CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_Node* pNode, + CXFA_PasswordEdit* password_node) + : CXFA_FFTextEdit(pNode), password_node_(password_node) {} CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} @@ -49,7 +51,7 @@ void CXFA_FFPasswordEdit::UpdateWidgetProperty() { FWL_STYLEEXT_EDT_Password; dwExtendedStyle |= UpdateUIProperty(); - WideString password = m_pNode->GetPasswordChar(); + WideString password = password_node_->GetPasswordChar(); if (!password.IsEmpty()) pWidget->SetAliasChar(password[0]); if (!m_pNode->IsHorizontalScrollPolicyOff()) diff --git a/xfa/fxfa/cxfa_ffpasswordedit.h b/xfa/fxfa/cxfa_ffpasswordedit.h index 28528cd4f2..8f5093f181 100644 --- a/xfa/fxfa/cxfa_ffpasswordedit.h +++ b/xfa/fxfa/cxfa_ffpasswordedit.h @@ -7,16 +7,22 @@ #ifndef XFA_FXFA_CXFA_FFPASSWORDEDIT_H_ #define XFA_FXFA_CXFA_FFPASSWORDEDIT_H_ +#include "core/fxcrt/unowned_ptr.h" #include "xfa/fxfa/cxfa_fftextedit.h" +class CXFA_PasswordEdit; + class CXFA_FFPasswordEdit : public CXFA_FFTextEdit { public: - explicit CXFA_FFPasswordEdit(CXFA_Node* pNode); + CXFA_FFPasswordEdit(CXFA_Node* pNode, CXFA_PasswordEdit* password_node); ~CXFA_FFPasswordEdit() override; // CXFA_FFTextEdit bool LoadWidget() override; void UpdateWidgetProperty() override; + + private: + UnownedPtr password_node_; }; #endif // XFA_FXFA_CXFA_FFPASSWORDEDIT_H_ diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp index d0611bbd8c..7c556b81a8 100644 --- a/xfa/fxfa/cxfa_ffpushbutton.cpp +++ b/xfa/fxfa/cxfa_ffpushbutton.cpp @@ -19,13 +19,14 @@ #include "xfa/fxfa/cxfa_textlayout.h" #include "xfa/fxfa/cxfa_textprovider.h" #include "xfa/fxfa/parser/cxfa_border.h" +#include "xfa/fxfa/parser/cxfa_button.h" #include "xfa/fxfa/parser/cxfa_caption.h" #include "xfa/fxfa/parser/cxfa_edge.h" #include "xfa/fxgraphics/cxfa_gecolor.h" #include "xfa/fxgraphics/cxfa_gepath.h" -CXFA_FFPushButton::CXFA_FFPushButton(CXFA_Node* pNode) - : CXFA_FFField(pNode), m_pOldDelegate(nullptr) {} +CXFA_FFPushButton::CXFA_FFPushButton(CXFA_Node* pNode, CXFA_Button* button) + : CXFA_FFField(pNode), button_(button) {} CXFA_FFPushButton::~CXFA_FFPushButton() { CXFA_FFPushButton::UnloadWidget(); @@ -71,7 +72,7 @@ bool CXFA_FFPushButton::LoadWidget() { void CXFA_FFPushButton::UpdateWidgetProperty() { uint32_t dwStyleEx = 0; - switch (m_pNode->GetButtonHighlight()) { + switch (button_->GetHighlight()) { case XFA_AttributeEnum::Inverted: dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteInverted; break; diff --git a/xfa/fxfa/cxfa_ffpushbutton.h b/xfa/fxfa/cxfa_ffpushbutton.h index d0b0b885c7..e247ee5e39 100644 --- a/xfa/fxfa/cxfa_ffpushbutton.h +++ b/xfa/fxfa/cxfa_ffpushbutton.h @@ -9,18 +9,20 @@ #include +#include "core/fxcrt/unowned_ptr.h" #include "xfa/fxfa/cxfa_fffield.h" #define XFA_FWL_PSBSTYLEEXT_HiliteInverted (1L << 0) #define XFA_FWL_PSBSTYLEEXT_HilitePush (1L << 1) #define XFA_FWL_PSBSTYLEEXT_HiliteOutLine (1L << 2) +class CXFA_Button; class CXFA_TextLayout; class CXFA_TextProvider; class CXFA_FFPushButton : public CXFA_FFField { public: - explicit CXFA_FFPushButton(CXFA_Node* pNode); + CXFA_FFPushButton(CXFA_Node* pNode, CXFA_Button* button); ~CXFA_FFPushButton() override; // CXFA_FFField @@ -49,7 +51,8 @@ class CXFA_FFPushButton : public CXFA_FFField { std::unique_ptr m_pDownTextLayout; std::unique_ptr m_pRollProvider; std::unique_ptr m_pDownProvider; - IFWL_WidgetDelegate* m_pOldDelegate; + IFWL_WidgetDelegate* m_pOldDelegate = nullptr; + UnownedPtr button_; }; #endif // XFA_FXFA_CXFA_FFPUSHBUTTON_H_ diff --git a/xfa/fxfa/parser/cxfa_button.cpp b/xfa/fxfa/parser/cxfa_button.cpp index 7b56d2b712..4a951b3ee9 100644 --- a/xfa/fxfa/parser/cxfa_button.cpp +++ b/xfa/fxfa/parser/cxfa_button.cpp @@ -41,3 +41,7 @@ CXFA_Button::~CXFA_Button() {} XFA_FFWidgetType CXFA_Button::GetDefaultFFWidgetType() const { return XFA_FFWidgetType::kButton; } + +XFA_AttributeEnum CXFA_Button::GetHighlight() { + return JSObject()->GetEnum(XFA_Attribute::Highlight); +} diff --git a/xfa/fxfa/parser/cxfa_button.h b/xfa/fxfa/parser/cxfa_button.h index 75d62a6159..cea685fa4e 100644 --- a/xfa/fxfa/parser/cxfa_button.h +++ b/xfa/fxfa/parser/cxfa_button.h @@ -15,6 +15,8 @@ class CXFA_Button : public CXFA_Node { ~CXFA_Button() override; XFA_FFWidgetType GetDefaultFFWidgetType() const override; + + XFA_AttributeEnum GetHighlight(); }; #endif // XFA_FXFA_PARSER_CXFA_BUTTON_H_ diff --git a/xfa/fxfa/parser/cxfa_checkbutton.cpp b/xfa/fxfa/parser/cxfa_checkbutton.cpp index 59afe5ac98..6b5fa8fada 100644 --- a/xfa/fxfa/parser/cxfa_checkbutton.cpp +++ b/xfa/fxfa/parser/cxfa_checkbutton.cpp @@ -55,3 +55,7 @@ bool CXFA_CheckButton::IsRound() { XFA_AttributeEnum CXFA_CheckButton::GetMark() { return JSObject()->GetEnum(XFA_Attribute::Mark); } + +bool CXFA_CheckButton::IsAllowNeutral() { + return JSObject()->GetBoolean(XFA_Attribute::AllowNeutral); +} diff --git a/xfa/fxfa/parser/cxfa_checkbutton.h b/xfa/fxfa/parser/cxfa_checkbutton.h index b603dd0ca1..e239a46ecb 100644 --- a/xfa/fxfa/parser/cxfa_checkbutton.h +++ b/xfa/fxfa/parser/cxfa_checkbutton.h @@ -17,6 +17,7 @@ class CXFA_CheckButton : public CXFA_Node { XFA_FFWidgetType GetDefaultFFWidgetType() const override; bool IsRound(); + bool IsAllowNeutral(); XFA_AttributeEnum GetMark(); }; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 0c28f4b5c6..451c98f8f0 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -3523,13 +3523,6 @@ RetainPtr CXFA_Node::GetFDEFont(CXFA_FFDoc* doc) { dwFontStyle); } -XFA_AttributeEnum CXFA_Node::GetButtonHighlight() { - CXFA_Node* pUIChild = GetUIChildNode(); - if (pUIChild) - return pUIChild->JSObject()->GetEnum(XFA_Attribute::Highlight); - return XFA_AttributeEnum::Inverted; -} - bool CXFA_Node::HasButtonRollover() { CXFA_Items* pItems = GetChild(0, XFA_Element::Items, false); if (!pItems) @@ -3571,12 +3564,6 @@ float CXFA_Node::GetCheckButtonSize() { return CXFA_Measurement(10, XFA_Unit::Pt).ToUnit(XFA_Unit::Pt); } -bool CXFA_Node::IsAllowNeutral() { - CXFA_Node* pUIChild = GetUIChildNode(); - return pUIChild && - pUIChild->JSObject()->GetBoolean(XFA_Attribute::AllowNeutral); -} - XFA_CHECKSTATE CXFA_Node::GetCheckState() { WideString wsValue = GetRawValue(); if (wsValue.IsEmpty()) @@ -4232,12 +4219,6 @@ Optional CXFA_Node::GetNumberOfCells() { return {}; } -WideString CXFA_Node::GetPasswordChar() { - CXFA_Node* pUIChild = GetUIChildNode(); - return pUIChild ? pUIChild->JSObject()->GetCData(XFA_Attribute::PasswordChar) - : L"*"; -} - bool CXFA_Node::IsMultiLine() { CXFA_Node* pUIChild = GetUIChildNode(); return pUIChild && pUIChild->JSObject()->GetBoolean(XFA_Attribute::MultiLine); @@ -4327,13 +4308,11 @@ bool CXFA_Node::SetValue(XFA_VALUEPICTURE eValueType, bSyncData = true; } - } else { - if (eType == XFA_Element::NumericEdit) { - if (wsNewText != L"0") - wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); + } else if (eType == XFA_Element::NumericEdit) { + if (wsNewText != L"0") + wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); - bSyncData = true; - } + bSyncData = true; } if (eType != XFA_Element::NumericEdit || bSyncData) SyncValue(wsNewText, true); @@ -4432,7 +4411,7 @@ WideString CXFA_Node::GetValue(XFA_VALUEPICTURE eValueType) { if (!pNode) return wsValue; - switch (GetUIChildNode()->GetElementType()) { + switch (pNode->GetElementType()) { case XFA_Element::ChoiceList: { if (eValueType == XFA_VALUEPICTURE_Display) { int32_t iSelItemIndex = GetSelectedItem(0); @@ -4441,7 +4420,8 @@ WideString CXFA_Node::GetValue(XFA_VALUEPICTURE eValueType) { wsPicture.clear(); } } - } break; + break; + } case XFA_Element::NumericEdit: if (eValueType != XFA_VALUEPICTURE_Raw && wsPicture.IsEmpty()) { IFX_Locale* pLocale = GetLocale(); diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 819b2f9a40..dfe5ab0127 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -310,11 +310,9 @@ class CXFA_Node : public CXFA_Object { RetainPtr GetFDEFont(CXFA_FFDoc* doc); bool IsListBox(); - bool IsAllowNeutral(); bool IsRadioButton(); bool IsMultiLine(); - XFA_AttributeEnum GetButtonHighlight(); bool HasButtonRollover(); bool HasButtonDown(); @@ -375,7 +373,6 @@ class CXFA_Node : public CXFA_Object { WideString GetFormatDataValue(const WideString& wsValue); WideString NormalizeNumStr(const WideString& wsValue); - WideString GetPasswordChar(); std::pair GetMaxChars(); int32_t GetFracDigits(); int32_t GetLeadDigits(); diff --git a/xfa/fxfa/parser/cxfa_passwordedit.cpp b/xfa/fxfa/parser/cxfa_passwordedit.cpp index 68267af183..6d38c344fe 100644 --- a/xfa/fxfa/parser/cxfa_passwordedit.cpp +++ b/xfa/fxfa/parser/cxfa_passwordedit.cpp @@ -43,3 +43,7 @@ CXFA_PasswordEdit::~CXFA_PasswordEdit() {} XFA_FFWidgetType CXFA_PasswordEdit::GetDefaultFFWidgetType() const { return XFA_FFWidgetType::kPasswordEdit; } + +WideString CXFA_PasswordEdit::GetPasswordChar() { + return JSObject()->GetCData(XFA_Attribute::PasswordChar); +} diff --git a/xfa/fxfa/parser/cxfa_passwordedit.h b/xfa/fxfa/parser/cxfa_passwordedit.h index e390aaa2b1..6c8e8e5856 100644 --- a/xfa/fxfa/parser/cxfa_passwordedit.h +++ b/xfa/fxfa/parser/cxfa_passwordedit.h @@ -15,6 +15,7 @@ class CXFA_PasswordEdit : public CXFA_Node { ~CXFA_PasswordEdit() override; XFA_FFWidgetType GetDefaultFFWidgetType() const override; + WideString GetPasswordChar(); }; #endif // XFA_FXFA_PARSER_CXFA_PASSWORDEDIT_H_ -- cgit v1.2.3