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