diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-12 18:54:48 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-12 18:54:48 +0000 |
commit | ebcbb85ea364605baf8e382ad66793bf1b4db029 (patch) | |
tree | 2c546368c63f65d7786a1ab9c818cb07b80d599c /fxjs | |
parent | 4b004930490e416a2a404deee5de4b97e649a1c1 (diff) | |
download | pdfium-ebcbb85ea364605baf8e382ad66793bf1b4db029.tar.xz |
Move Script_Som_Border{Width|Color} to CJX_Object
The CJX_Node isn't the root of the CJX hierarchy. This causes issues
now that CJX_Object has child objects which don't inherit from CJX_Node.
This CL moves Script_Som_Border{Width|Color} from CJX_Node to CJX_Object.
Change-Id: I07ba9ef2af675993c9f4d14cb74f48252a907569
Reviewed-on: https://pdfium-review.googlesource.com/20990
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/xfa/cjx_exclgroup.cpp | 2 | ||||
-rw-r--r-- | fxjs/xfa/cjx_field.cpp | 16 | ||||
-rw-r--r-- | fxjs/xfa/cjx_manifest.cpp | 2 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 56 | ||||
-rw-r--r-- | fxjs/xfa/cjx_node.h | 11 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.cpp | 83 | ||||
-rw-r--r-- | fxjs/xfa/cjx_object.h | 15 | ||||
-rw-r--r-- | fxjs/xfa/cjx_template.cpp | 10 |
8 files changed, 110 insertions, 85 deletions
diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp index e24be804e0..1041e3ffbb 100644 --- a/fxjs/xfa/cjx_exclgroup.cpp +++ b/fxjs/xfa/cjx_exclgroup.cpp @@ -86,7 +86,7 @@ CJS_Return CJX_ExclGroup::selectedMember( if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(runtime->NewNull()); diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp index 4b5f840322..857aa50d40 100644 --- a/fxjs/xfa/cjx_field.cpp +++ b/fxjs/xfa/cjx_field.cpp @@ -40,7 +40,7 @@ CJX_Field::~CJX_Field() {} CJS_Return CJX_Field::clearItems( CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>& params) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (pWidgetData) pWidgetData->DeleteItem(-1, true, false); return CJS_Return(true); @@ -81,7 +81,7 @@ CJS_Return CJX_Field::deleteItem( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(true); @@ -100,7 +100,7 @@ CJS_Return CJX_Field::getSaveItem( if (iIndex < 0) return CJS_Return(runtime->NewNull()); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(runtime->NewNull()); @@ -118,7 +118,7 @@ CJS_Return CJX_Field::boundItem( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(true); @@ -133,7 +133,7 @@ CJS_Return CJX_Field::getItemState( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(true); @@ -165,7 +165,7 @@ CJS_Return CJX_Field::getDisplayItem( if (iIndex < 0) return CJS_Return(runtime->NewNull()); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(runtime->NewNull()); @@ -183,7 +183,7 @@ CJS_Return CJX_Field::setItemState( if (params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(true); @@ -203,7 +203,7 @@ CJS_Return CJX_Field::addItem(CJS_V8* runtime, if (params.size() != 1 && params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); if (!pWidgetData) return CJS_Return(true); diff --git a/fxjs/xfa/cjx_manifest.cpp b/fxjs/xfa/cjx_manifest.cpp index 0f48b1d28b..d5c986a83b 100644 --- a/fxjs/xfa/cjx_manifest.cpp +++ b/fxjs/xfa/cjx_manifest.cpp @@ -27,6 +27,6 @@ CJS_Return CJX_Manifest::evaluate( if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); + CXFA_WidgetData* pWidgetData = GetWidgetData(); return CJS_Return(runtime->NewBoolean(!!pWidgetData)); } diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 8234fa6be7..c0a7f37675 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -789,58 +789,6 @@ void CJX_Node::Script_Boolean_Value(CFXJSE_Value* pValue, SetContent(wsNewValue, wsFormatValue, true, true, true); } -void CJX_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - CXFA_BorderData borderData = pWidgetData->GetBorderData(true); - int32_t iSize = borderData.CountEdges(); - if (bSetting) { - int32_t r = 0; - int32_t g = 0; - int32_t b = 0; - std::tie(r, g, b) = StrToRGB(pValue->ToWideString()); - FX_ARGB rgb = ArgbEncode(100, r, g, b); - for (int32_t i = 0; i < iSize; ++i) - borderData.GetEdgeData(i).SetColor(rgb); - - return; - } - - FX_ARGB color = borderData.GetEdgeData(0).GetColor(); - int32_t a; - int32_t r; - int32_t g; - int32_t b; - std::tie(a, r, g, b) = ArgbDecode(color); - pValue->SetString( - WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView()); -} - -void CJX_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) - return; - - CXFA_BorderData borderData = pWidgetData->GetBorderData(true); - if (bSetting) { - CXFA_Measurement thickness = borderData.GetEdgeData(0).GetMSThickness(); - pValue->SetString(thickness.ToString().UTF8Encode().AsStringView()); - return; - } - - WideString wsThickness = pValue->ToWideString(); - for (int32_t i = 0; i < borderData.CountEdges(); ++i) { - borderData.GetEdgeData(i).SetMSThickness( - CXFA_Measurement(wsThickness.AsStringView())); - } -} - void CJX_Node::Script_Som_FillColor(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { @@ -1343,10 +1291,6 @@ void CJX_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) {} -void CJX_Node::SetWidgetData(std::unique_ptr<CXFA_WidgetData> data) { - widget_data_ = std::move(data); -} - pdfium::Optional<WideString> CJX_Node::TryNamespace() { if (GetXFANode()->IsModelNode() || GetXFANode()->GetElementType() == XFA_Element::Packet) { diff --git a/fxjs/xfa/cjx_node.h b/fxjs/xfa/cjx_node.h index 2cf41a0735..8c42b340a8 100644 --- a/fxjs/xfa/cjx_node.h +++ b/fxjs/xfa/cjx_node.h @@ -8,7 +8,6 @@ #define FXJS_XFA_CJX_NODE_H_ #include <memory> -#include <utility> #include <vector> #include "core/fxcrt/unowned_ptr.h" @@ -47,9 +46,6 @@ class CJX_Node : public CJX_Tree { bool bSyncData); WideString GetContent(bool bScriptModify); - void SetWidgetData(std::unique_ptr<CXFA_WidgetData> data); - CXFA_WidgetData* GetWidgetData() const { return widget_data_.get(); } - void SetLayoutItem(CXFA_LayoutItem* item) { layout_item_ = item; } CXFA_LayoutItem* GetLayoutItem() const { return layout_item_.Get(); } @@ -126,12 +122,6 @@ class CJX_Node : public CJX_Tree { void Script_Som_Message(CFXJSE_Value* pValue, bool bSetting, XFA_SOM_MESSAGETYPE iMessageType); - void Script_Som_BorderColor(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); - void Script_Som_BorderWidth(CFXJSE_Value* pValue, - bool bSetting, - XFA_Attribute eAttribute); void Script_Som_FillColor(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute); @@ -239,7 +229,6 @@ class CJX_Node : public CJX_Tree { XFA_Element eType); private: - std::unique_ptr<CXFA_WidgetData> widget_data_; UnownedPtr<CXFA_LayoutItem> layout_item_; size_t calc_recursion_count_ = 0; static const CJX_MethodSpec MethodSpecs[]; diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index 4ba1d39394..5b21730df2 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -6,7 +6,7 @@ #include "fxjs/xfa/cjx_object.h" -#include <utility> +#include <tuple> #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/xml/cfx_xmltext.h" @@ -57,6 +57,37 @@ void XFA_DefaultFreeData(void* pData) {} XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {XFA_DefaultFreeData, nullptr}; +std::tuple<int32_t, int32_t, int32_t> StrToRGB(const WideString& strRGB) { + int32_t r = 0; + int32_t g = 0; + int32_t b = 0; + + size_t iIndex = 0; + for (size_t i = 0; i < strRGB.GetLength(); ++i) { + wchar_t ch = strRGB[i]; + if (ch == L',') + ++iIndex; + if (iIndex > 2) + break; + + int32_t iValue = ch - L'0'; + if (iValue >= 0 && iValue <= 9) { + switch (iIndex) { + case 0: + r = r * 10 + iValue; + break; + case 1: + g = g * 10 + iValue; + break; + default: + b = b * 10 + iValue; + break; + } + } + } + return {r, g, b}; +} + } // namespace struct XFA_MAPDATABLOCK { @@ -893,3 +924,53 @@ void CJX_Object::Script_Attribute_Integer(CFXJSE_Value* pValue, } pValue->SetInteger(GetInteger(eAttribute)); } + +void CJX_Object::Script_Som_BorderColor(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!widget_data_) + return; + + CXFA_BorderData borderData = widget_data_->GetBorderData(true); + int32_t iSize = borderData.CountEdges(); + if (bSetting) { + int32_t r = 0; + int32_t g = 0; + int32_t b = 0; + std::tie(r, g, b) = StrToRGB(pValue->ToWideString()); + FX_ARGB rgb = ArgbEncode(100, r, g, b); + for (int32_t i = 0; i < iSize; ++i) + borderData.GetEdgeData(i).SetColor(rgb); + + return; + } + + FX_ARGB color = borderData.GetEdgeData(0).GetColor(); + int32_t a; + int32_t r; + int32_t g; + int32_t b; + std::tie(a, r, g, b) = ArgbDecode(color); + pValue->SetString( + WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView()); +} + +void CJX_Object::Script_Som_BorderWidth(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute) { + if (!widget_data_) + return; + + CXFA_BorderData borderData = widget_data_->GetBorderData(true); + if (bSetting) { + CXFA_Measurement thickness = borderData.GetEdgeData(0).GetMSThickness(); + pValue->SetString(thickness.ToString().UTF8Encode().AsStringView()); + return; + } + + WideString wsThickness = pValue->ToWideString(); + for (int32_t i = 0; i < borderData.CountEdges(); ++i) { + borderData.GetEdgeData(i).SetMSThickness( + CXFA_Measurement(wsThickness.AsStringView())); + } +} diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h index c191dcfd43..dfd2bbc929 100644 --- a/fxjs/xfa/cjx_object.h +++ b/fxjs/xfa/cjx_object.h @@ -9,6 +9,7 @@ #include <map> #include <memory> +#include <utility> #include <vector> #include "core/fxcrt/unowned_ptr.h" @@ -16,6 +17,7 @@ #include "core/fxcrt/xml/cfx_xmlelement.h" #include "third_party/base/optional.h" #include "xfa/fxfa/fxfa_basic.h" +#include "xfa/fxfa/parser/cxfa_widgetdata.h" class CFXJSE_Value; class CJS_V8; @@ -51,6 +53,11 @@ class CJX_Object { CXFA_Document* GetDocument() const; + void SetWidgetData(std::unique_ptr<CXFA_WidgetData> data) { + widget_data_ = std::move(data); + } + CXFA_WidgetData* GetWidgetData() const { return widget_data_.get(); } + bool HasMethod(const WideString& func) const; CJS_Return RunMethod(const WideString& func, const std::vector<v8::Local<v8::Value>>& params); @@ -85,6 +92,13 @@ class CJX_Object { bool bSetting, XFA_Attribute eAttribute); + void Script_Som_BorderColor(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + void Script_Som_BorderWidth(CFXJSE_Value* pValue, + bool bSetting, + XFA_Attribute eAttribute); + pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault); bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify); int32_t GetInteger(XFA_Attribute eAttr); @@ -164,6 +178,7 @@ class CJX_Object { void RemoveMapModuleKey(void* pKey); void MoveBufferMapData(CXFA_Object* pDstModule); + std::unique_ptr<CXFA_WidgetData> widget_data_; UnownedPtr<CXFA_Object> object_; std::unique_ptr<XFA_MAPMODULEDATA> map_module_data_; std::unique_ptr<CXFA_CalcData> calc_data_; diff --git a/fxjs/xfa/cjx_template.cpp b/fxjs/xfa/cjx_template.cpp index 8ba2bcab9e..d55fd66452 100644 --- a/fxjs/xfa/cjx_template.cpp +++ b/fxjs/xfa/cjx_template.cpp @@ -50,9 +50,7 @@ CJS_Return CJX_Template::execInitialize( const std::vector<v8::Local<v8::Value>>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - return CJS_Return(runtime->NewBoolean(!!pWidgetData)); + return CJS_Return(runtime->NewBoolean(!!GetWidgetData())); } CJS_Return CJX_Template::recalculate( @@ -68,9 +66,7 @@ CJS_Return CJX_Template::execCalculate( const std::vector<v8::Local<v8::Value>>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - return CJS_Return(runtime->NewBoolean(!!pWidgetData)); + return CJS_Return(runtime->NewBoolean(!!GetWidgetData())); } CJS_Return CJX_Template::execValidate( @@ -78,5 +74,5 @@ CJS_Return CJX_Template::execValidate( const std::vector<v8::Local<v8::Value>>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return(runtime->NewBoolean(!!GetXFANode()->GetWidgetData())); + return CJS_Return(runtime->NewBoolean(!!GetWidgetData())); } |