1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fxjs/xfa/cjx_boolean.h"
8 
9 #include "fxjs/xfa/cfxjse_value.h"
10 #include "xfa/fxfa/parser/cxfa_boolean.h"
11 
CJX_Boolean(CXFA_Boolean * node)12 CJX_Boolean::CJX_Boolean(CXFA_Boolean* node) : CJX_Object(node) {}
13 
14 CJX_Boolean::~CJX_Boolean() = default;
15 
DynamicTypeIs(TypeTag eType) const16 bool CJX_Boolean::DynamicTypeIs(TypeTag eType) const {
17   return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
18 }
19 
defaultValue(CFXJSE_Value * pValue,bool bSetting,XFA_Attribute eAttribute)20 void CJX_Boolean::defaultValue(CFXJSE_Value* pValue,
21                                bool bSetting,
22                                XFA_Attribute eAttribute) {
23   if (!bSetting) {
24     pValue->SetBoolean(GetContent(true).EqualsASCII("1"));
25     return;
26   }
27 
28   ByteString newValue;
29   if (pValue && !(pValue->IsNull() || pValue->IsUndefined()))
30     newValue = pValue->ToString();
31 
32   int32_t iValue = FXSYS_atoi(newValue.c_str());
33   WideString wsNewValue(iValue == 0 ? L"0" : L"1");
34   WideString wsFormatValue(wsNewValue);
35   CXFA_Node* pContainerNode = ToNode(GetXFAObject())->GetContainerNode();
36   if (pContainerNode)
37     wsFormatValue = pContainerNode->GetFormatDataValue(wsNewValue);
38 
39   SetContent(wsNewValue, wsFormatValue, true, true, true);
40 }
41 
value(CFXJSE_Value * pValue,bool bSetting,XFA_Attribute eAttribute)42 void CJX_Boolean::value(CFXJSE_Value* pValue,
43                         bool bSetting,
44                         XFA_Attribute eAttribute) {
45   defaultValue(pValue, bSetting, eAttribute);
46 }
47