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