1 // Copyright 2017 The PDFium Authors
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_draw.h"
8
9 #include "fxjs/fxv8.h"
10 #include "fxjs/xfa/cfxjse_value.h"
11 #include "third_party/base/check.h"
12 #include "v8/include/v8-primitive.h"
13 #include "v8/include/v8-value.h"
14 #include "xfa/fxfa/parser/cxfa_draw.h"
15
CJX_Draw(CXFA_Draw * node)16 CJX_Draw::CJX_Draw(CXFA_Draw* node) : CJX_Container(node) {}
17
18 CJX_Draw::~CJX_Draw() = default;
19
DynamicTypeIs(TypeTag eType) const20 bool CJX_Draw::DynamicTypeIs(TypeTag eType) const {
21 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
22 }
23
rawValue(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)24 void CJX_Draw::rawValue(v8::Isolate* pIsolate,
25 v8::Local<v8::Value>* pValue,
26 bool bSetting,
27 XFA_Attribute eAttribute) {
28 defaultValue(pIsolate, pValue, bSetting, eAttribute);
29 }
30
defaultValue(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)31 void CJX_Draw::defaultValue(v8::Isolate* pIsolate,
32 v8::Local<v8::Value>* pValue,
33 bool bSetting,
34 XFA_Attribute eAttribute) {
35 if (!bSetting) {
36 ByteString content = GetContent(true).ToUTF8();
37 *pValue = content.IsEmpty()
38 ? fxv8::NewNullHelper(pIsolate).As<v8::Value>()
39 : fxv8::NewStringHelper(pIsolate, content.AsStringView())
40 .As<v8::Value>();
41 return;
42 }
43
44 if (!pValue || !fxv8::IsString(*pValue))
45 return;
46
47 DCHECK(GetXFANode()->IsWidgetReady());
48 if (GetXFANode()->GetFFWidgetType() != XFA_FFWidgetType::kText)
49 return;
50
51 WideString wsNewValue = fxv8::ReentrantToWideStringHelper(pIsolate, *pValue);
52 SetContent(wsNewValue, wsNewValue, true, true, true);
53 }
54