7#include "fxjs/cjs_event_context.h"
9#include "core/fpdfdoc/cpdf_formfield.h"
10#include "core/fxcrt/autorestorer.h"
11#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
12#include "fxjs/cjs_field.h"
13#include "fxjs/cjs_runtime.h"
14#include "fxjs/js_define.h"
15#include "fxjs/js_resources.h"
16#include "third_party/base/check.h"
17#include "v8/include/v8-context.h"
18#include "v8/include/v8-isolate.h"
26 const WideString& script) {
27 v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
28 v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
29 v8::Local<v8::Context> context = m_pRuntime->GetV8Context();
30 v8::Context::Scope context_scope(context);
41 CJS_Runtime::FieldEvent event(TargetName(), EventKind());
42 if (!m_pRuntime->AddEventToSet(event)) {
47 absl::optional<IJS_Runtime::JS_Error> err;
48 if (script.GetLength() > 0)
49 err = m_pRuntime->ExecuteScript(script);
51 m_pRuntime->RemoveEventFromSet(event);
57 v8::Local<v8::Object> pDocObj = m_pRuntime->NewFXJSBoundObject(
58 CJS_Document::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
59 if (pDocObj.IsEmpty())
62 v8::Local<v8::Object> pFieldObj = m_pRuntime->NewFXJSBoundObject(
63 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
64 if (pFieldObj.IsEmpty())
68 auto* pJSDocument =
static_cast<CJS_Document*>(
69 CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pDocObj));
70 pJSDocument->SetFormFillEnv(pFormFillEnv);
72 auto* pJSField =
static_cast<CJS_Field*>(
73 CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pFieldObj));
79 v8::Local<v8::Object> pDocObj = m_pRuntime->NewFXJSBoundObject(
80 CJS_Document::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
81 if (pDocObj.IsEmpty())
84 v8::Local<v8::Object> pFieldObj = m_pRuntime->NewFXJSBoundObject(
85 CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
86 if (pFieldObj.IsEmpty())
90 auto* pJSDocument =
static_cast<CJS_Document*>(
91 CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pDocObj));
92 pJSDocument->SetFormFillEnv(pFormFillEnv);
94 auto* pJSField =
static_cast<CJS_Field*>(
95 CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pFieldObj));
100void CJS_EventContext::
OnDoc_Open(
const WideString& strTargetName) {
102 m_strTargetName = strTargetName;
145 m_bModifier = bModifier;
147 m_strTargetName = pTarget->GetFullName();
154 m_bModifier = bModifier;
156 m_strTargetName = pTarget->GetFullName();
163 m_bModifier = bModifier;
165 m_strTargetName = pTarget->GetFullName();
172 m_bModifier = bModifier;
174 m_strTargetName = pTarget->GetFullName();
180 WideString* pValue) {
183 m_bModifier = bModifier;
185 m_strTargetName = pTarget->GetFullName();
192 WideString* pValue) {
195 m_bModifier = bModifier;
197 m_strTargetName = pTarget->GetFullName();
202 const WideString& strChangeEx,
220 m_pWideStrChange = strChange;
221 m_WideStrChangeEx = strChangeEx;
222 m_bKeyDown = KeyDown;
223 m_bModifier = bModifier;
224 m_pISelEnd = pSelEnd;
225 m_pISelStart = pSelStart;
227 m_strTargetName = pTarget->GetFullName();
229 m_bWillCommit = bWillCommit;
231 m_bFieldFull = bFieldFull;
235 const WideString& strChangeEx,
245 m_pWideStrChange = strChange;
246 m_WideStrChangeEx = strChangeEx;
247 m_bKeyDown = bKeyDown;
248 m_bModifier = bModifier;
250 m_strTargetName = pTarget->GetFullName();
263 m_strSourceName = pSource->GetFullName();
264 m_strTargetName = pTarget->GetFullName();
270 WideString* pValue) {
274 m_strTargetName = pTarget->GetFullName();
276 m_bWillCommit =
true;
283void CJS_EventContext::Initialize(
Kind kind) {
285 m_strTargetName.clear();
286 m_strSourceName.clear();
287 m_pWideStrChange =
nullptr;
288 m_WideStrChangeDu.clear();
289 m_WideStrChangeEx.clear();
294 m_pISelEnd =
nullptr;
296 m_pISelStart =
nullptr;
298 m_bWillCommit =
false;
300 m_bFieldFull =
false;
306void CJS_EventContext::Destroy() {
322 return m_pWideStrChange ? *m_pWideStrChange : m_WideStrChangeDu;
325ByteStringView CJS_EventContext::
Name()
const {
350 return "Mouse Enter";
374ByteStringView CJS_EventContext::
Type()
const {
406bool& CJS_EventContext::
Rc() {
407 return m_pbRc ? *m_pbRc : m_bRcDu;
411 return m_pISelEnd ? *m_pISelEnd : m_nSelEndDu;
415 return m_pISelStart ? *m_pISelStart : m_nSelStartDu;
419 int& target = m_pISelEnd ? *m_pISelEnd : m_nSelEndDu;
424 int& target = m_pISelStart ? *m_pISelStart : m_nSelStartDu;
CJS_Field * TargetField()
void OnPage_Close() override
void OnField_Keystroke(WideString *strChange, const WideString &strChangeEx, bool bKeyDown, bool bModifier, int *nSelEnd, int *nSelStart, bool bShift, CPDF_FormField *pTarget, WideString *Value, bool bWillCommit, bool bFieldFull, bool *bRc) override
void OnField_Blur(bool bModifier, bool bShift, CPDF_FormField *pTarget, WideString *Value) override
~CJS_EventContext() override
void OnPage_Open() override
void OnDoc_Open(const WideString &strTargetName) override
WideString SourceName() const
WideString TargetName() const
CJS_EventContext(CJS_Runtime *pRuntime)
void OnField_Focus(bool bModifier, bool bShift, CPDF_FormField *pTarget, WideString *Value) override
void OnField_MouseEnter(bool bModifier, bool bShift, CPDF_FormField *pTarget) override
void OnField_MouseDown(bool bModifier, bool bShift, CPDF_FormField *pTarget) override
ByteStringView Name() const
void OnExternal_Exec() override
void OnField_Validate(WideString *strChange, const WideString &strChangeEx, bool bKeyDown, bool bModifier, bool bShift, CPDF_FormField *pTarget, WideString *Value, bool *bRc) override
void OnDoc_DidSave() override
bool IsUserGesture() const
void OnField_Format(CPDF_FormField *pTarget, WideString *Value) override
void OnField_MouseExit(bool bModifier, bool bShift, CPDF_FormField *pTarget) override
void OnDoc_WillSave() override
ByteStringView Type() const
void OnDoc_WillClose() override
void SetSelEnd(int value)
void OnPage_InView() override
CJS_Field * SourceField()
void OnField_Calculate(CPDF_FormField *pSource, CPDF_FormField *pTarget, WideString *pValue, bool *pRc) override
absl::optional< IJS_Runtime::JS_Error > RunScript(const WideString &script) override
void OnDoc_WillPrint() override
void OnDoc_DidPrint() override
void OnField_MouseUp(bool bModifier, bool bShift, CPDF_FormField *pTarget) override
void OnPage_OutView() override
void SetSelStart(int value)
CPDFSDK_FormFillEnvironment * GetFormFillEnv() const
WideString JSGetStringFromID(JSMessage msg)
JS_Error(int line, int column, const WideString &exception)