More master side changes for convergence with XFA.
[pdfium.git] / fpdfsdk / src / javascript / JS_EventHandler.cpp
index 1eee92d..cb86fde 100644 (file)
@@ -4,16 +4,16 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "../../include/javascript/JavaScript.h"
+#include "JS_EventHandler.h"
+
 #include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/Field.h"
+#include "Document.h"
+#include "Field.h"
+#include "JS_Context.h"
+#include "JS_Define.h"
+#include "JS_Object.h"
+#include "JS_Runtime.h"
+#include "JS_Value.h"
 
 /* ---------------------------- CJS_EventHandler ---------------------------- */
 
@@ -611,67 +611,47 @@ FX_BOOL CJS_EventHandler::Shift() {
 }
 
 Field* CJS_EventHandler::Source() {
-  ASSERT(m_pJSContext != NULL);
-
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+  v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
+  ASSERT(!pDocObj.IsEmpty());
 
-  JSFXObject pDocObj = JS_NewFxDynamicObj(
-      *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
-  ASSERT(pDocObj.IsEmpty() == FALSE);
-  JSFXObject pFieldObj = JS_NewFxDynamicObj(
-      *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
-  ASSERT(pFieldObj.IsEmpty() == FALSE);
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
+  ASSERT(!pFieldObj.IsEmpty());
 
-  CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
-  ASSERT(pJSDocument != NULL);
+  CJS_Document* pJSDocument =
+      (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
-  ASSERT(pDocument != NULL);
-  if (m_pTargetDoc != NULL)
-    pDocument->AttachDoc(m_pTargetDoc);
-  else
-    pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
-  // if (m_pSourceField == NULL)
-  //  return NULL;
-  // CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);
-  // CPDF_FormField* pFormField = pWidget->GetFormField();
-  // ASSERT(pFormField);
-  // CFX_WideString csFieldName = pFormField->GetFullName();
-  CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
-  ASSERT(pJSField != NULL);
+  pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
+                                    : m_pJSContext->GetReaderDocument());
+
+  CJS_Field* pJSField =
+      (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
   Field* pField = (Field*)pJSField->GetEmbedObject();
-  ASSERT(pField != NULL);
   pField->AttachField(pDocument, m_strSourceName);
   return pField;
 }
 
 Field* CJS_EventHandler::Target_Field() {
-  ASSERT(m_pJSContext != NULL);
-
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+  v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
+  ASSERT(!pDocObj.IsEmpty());
 
-  JSFXObject pDocObj = JS_NewFxDynamicObj(
-      *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
-  ASSERT(pDocObj.IsEmpty() == FALSE);
-  JSFXObject pFieldObj = JS_NewFxDynamicObj(
-      *pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
-  ASSERT(pFieldObj.IsEmpty() == FALSE);
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
+  ASSERT(!pFieldObj.IsEmpty());
 
-  CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
-  ASSERT(pJSDocument != NULL);
+  CJS_Document* pJSDocument =
+      (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
   Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
-  ASSERT(pDocument != NULL);
-  if (m_pTargetDoc != NULL)
-    pDocument->AttachDoc(m_pTargetDoc);
-  else
-    pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
-  CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
-  ASSERT(pJSField != NULL);
+  pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
+                                    : m_pJSContext->GetReaderDocument());
 
+  CJS_Field* pJSField =
+      (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
   Field* pField = (Field*)pJSField->GetEmbedObject();
-  ASSERT(pField != NULL);
-
   pField->AttachField(pDocument, m_strTargetName);
   return pField;
 }