Store object definition ID in each js_class.
[pdfium.git] / fpdfsdk / src / javascript / JS_EventHandler.cpp
index ce69e6b..dd5c442 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/javascript/JavaScript.h"\r
-#include "../../include/javascript/IJavaScript.h"\r
-#include "../../include/javascript/JS_EventHandler.h"\r
-//#include "../../include/javascript/JS_ResMgr.h"\r
-#include "../../include/javascript/JS_Context.h"\r
-#include "../../include/javascript/JS_Runtime.h"\r
-#include "../../include/javascript/JS_Define.h"\r
-#include "../../include/javascript/JS_Object.h"\r
-#include "../../include/javascript/JS_Value.h"\r
-#include "../../include/javascript/Document.h"\r
-#include "../../include/javascript/Field.h"\r
-\r
-/* ---------------------------- CJS_EventHandler ---------------------------- */\r
-\r
-CJS_EventHandler::CJS_EventHandler(CJS_Context * pContext)      :\r
-       m_pJSContext(pContext),\r
-       m_eEventType(JET_UNKNOWN),\r
-       m_bValid(FALSE),\r
-       m_pWideStrChange(NULL),\r
-       m_nCommitKey(-1),\r
-       m_bKeyDown(FALSE),\r
-       m_bModifier(FALSE),\r
-       m_bShift(FALSE),\r
-       m_pISelEnd(NULL),\r
-       m_nSelEndDu(0),\r
-       m_pISelStart(NULL),\r
-       m_nSelStartDu(0),\r
-       m_bWillCommit(FALSE),\r
-       m_pValue(NULL),\r
-       m_bFieldFull(FALSE),\r
-       m_pbRc(NULL),\r
-       m_bRcDu(FALSE),\r
-       m_pSourceDoc(NULL),\r
-       m_pTargetBookMark(NULL),\r
-       m_pTargetDoc(NULL),\r
-       m_pTargetAnnot(NULL)\r
-{\r
-}\r
-\r
-CJS_EventHandler::~CJS_EventHandler()\r
-{\r
-}\r
-\r
-void CJS_EventHandler::OnApp_Init()\r
-{\r
-       Initial(JET_APP_INIT);\r
-}\r
-\r
-void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName)\r
-{\r
-       Initial(JET_DOC_OPEN);\r
-\r
-       m_pTargetDoc = pDoc;\r
-       m_strTargetName = strTargetName;        \r
-}\r
-\r
-void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_DOC_WILLPRINT);\r
-\r
-       m_pTargetDoc = pDoc;    \r
-}\r
-\r
-void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_DOC_DIDPRINT);\r
-       \r
-       m_pTargetDoc = pDoc;            \r
-}\r
-\r
-void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_DOC_WILLSAVE);\r
-       m_pTargetDoc = pDoc;            \r
-}\r
-\r
-void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_DOC_DIDSAVE);       \r
-       \r
-       m_pTargetDoc = pDoc;    \r
-}\r
-\r
-void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_DOC_WILLCLOSE);\r
-\r
-       m_pTargetDoc = pDoc;    \r
-}\r
-\r
-void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_PAGE_OPEN);\r
-\r
-       m_pTargetDoc = pDoc;\r
-}\r
-\r
-void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_PAGE_CLOSE);\r
-       \r
-       m_pTargetDoc = pDoc;\r
-}\r
-\r
-void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_PAGE_INVIEW);\r
-       \r
-       m_pTargetDoc = pDoc;\r
-}\r
-\r
-void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc)\r
-{\r
-       Initial(JET_PAGE_OUTVIEW);\r
-       \r
-       m_pTargetDoc = pDoc;\r
-}\r
-\r
-void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)\r
-{\r
-       Initial(JET_FIELD_MOUSEENTER);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-\r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-}\r
-\r
-void CJS_EventHandler::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)\r
-{\r
-       Initial(JET_FIELD_MOUSEEXIT);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();       \r
-}\r
-\r
-void CJS_EventHandler::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)\r
-{\r
-       Initial(JET_FIELD_MOUSEDOWN);\r
-       m_eEventType = JET_FIELD_MOUSEDOWN;\r
-       \r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;      \r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-}\r
-\r
-void CJS_EventHandler::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)\r
-{\r
-       Initial(JET_FIELD_MOUSEUP);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-}\r
-\r
-void CJS_EventHandler::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, \r
-                                                                        const CFX_WideString& Value)\r
-{\r
-       Initial(JET_FIELD_FOCUS);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;  \r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-       m_pValue = (CFX_WideString*)&Value;\r
-}\r
-\r
-void CJS_EventHandler::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,\r
-                                                                       const CFX_WideString& Value)\r
-{\r
-       Initial(JET_FIELD_BLUR);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-       m_pValue = (CFX_WideString*)&Value;     \r
-}\r
-\r
-void CJS_EventHandler::OnField_Keystroke(int nCommitKey, CFX_WideString &strChange,\r
-                                                                                const CFX_WideString& strChangeEx, FX_BOOL KeyDown,\r
-                                                                                FX_BOOL bModifier, int& nSelEnd, int& nSelStart,\r
-                                                                                FX_BOOL bShift, CPDF_FormField* pTarget,\r
-                                                                                CFX_WideString& Value, FX_BOOL bWillCommit,\r
-                                                                                 FX_BOOL bFieldFull, FX_BOOL& bRc)\r
-{\r
-       Initial(JET_FIELD_KEYSTROKE);\r
-       \r
-       m_nCommitKey = nCommitKey;\r
-       m_pWideStrChange = &strChange;\r
-       m_WideStrChangeEx = strChangeEx;\r
-       m_bKeyDown = KeyDown;\r
-       m_bModifier = bModifier;\r
-       m_pISelEnd = &nSelEnd;\r
-       m_pISelStart = &nSelStart;\r
-       m_bShift = bShift;      \r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-       m_pValue = &Value;\r
-       m_bWillCommit = bWillCommit;    \r
-       m_pbRc = &bRc;\r
-       m_bFieldFull = bFieldFull;\r
-}\r
-\r
-void CJS_EventHandler::OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx,\r
-                                                                               FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift,\r
-                                                                               CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)\r
-{\r
-       Initial(JET_FIELD_VALIDATE);\r
-       \r
-       m_pWideStrChange = &strChange;\r
-       m_WideStrChangeEx = strChangeEx;        \r
-       m_bKeyDown = bKeyDown;\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-       m_pValue = &Value;      \r
-       m_pbRc = &bRc;  \r
-}\r
-\r
-void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, \r
-                                                                                CFX_WideString& Value, FX_BOOL& bRc)\r
-{\r
-       Initial(JET_FIELD_CALCULATE);\r
-\r
-       if (pSource)\r
-               m_strSourceName = pSource->GetFullName();\r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-    m_pValue = &Value;\r
-       m_pbRc = &bRc;\r
-}\r
-\r
-void CJS_EventHandler::OnField_Format(int nCommitKey, CPDF_FormField* pTarget,\r
-                                                                         CFX_WideString& Value, FX_BOOL bWillCommit)\r
-{\r
-       Initial(JET_FIELD_FORMAT);\r
-       \r
-       m_nCommitKey = nCommitKey;        \r
-       ASSERT(pTarget != NULL);\r
-       m_strTargetName = pTarget->GetFullName();\r
-       m_pValue = &Value;\r
-       m_bWillCommit = bWillCommit;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_FOCUS);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_BLUR);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_OPEN);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_CLOSE);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_MOUSEDOWN);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_MOUSEUP);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_MOUSEENTER);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_MOUSEEXIT);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_INVIEW);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)\r
-{\r
-       Initial(JET_SCREEN_OUTVIEW);\r
-\r
-       m_bModifier = bModifier;\r
-       m_bShift = bShift;\r
-       m_pTargetAnnot = pScreen;\r
-}\r
-\r
-void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget)\r
-{\r
-       Initial(JET_LINK_MOUSEUP);\r
-       \r
-       m_pTargetDoc = pTarget; \r
-}\r
-\r
-void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)\r
-{\r
-       Initial(JET_BOOKMARK_MOUSEUP);\r
-\r
-       m_pTargetBookMark = pBookMark;  \r
-}\r
-\r
-void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName)\r
-{\r
-       Initial(JET_MENU_EXEC);\r
-\r
-       m_pTargetDoc = pTarget;\r
-       m_strTargetName = strTargetName;\r
-}\r
-\r
-void CJS_EventHandler::OnExternal_Exec()\r
-{\r
-       Initial(JET_EXTERNAL_EXEC);\r
-}\r
-\r
-void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget)\r
-{\r
-       Initial(JET_BATCH_EXEC);\r
-\r
-       m_pTargetDoc = pTarget; \r
-}\r
-\r
-void CJS_EventHandler::OnConsole_Exec()\r
-{\r
-       Initial(JET_CONSOLE_EXEC);\r
-}\r
-\r
-\r
-void CJS_EventHandler::Initial(JS_EVENT_T type)\r
-{\r
-       m_eEventType = type;\r
-\r
-       m_strTargetName = L"";\r
-       m_strSourceName = L"";\r
-       m_pWideStrChange = NULL;\r
-       m_WideStrChangeDu = L"";\r
-       m_WideStrChangeEx = L"";\r
-       m_nCommitKey = -1;\r
-       m_bKeyDown = FALSE;\r
-       m_bModifier = FALSE;\r
-       m_bShift = FALSE;\r
-       m_pISelEnd = NULL;\r
-       m_nSelEndDu = 0;\r
-       m_pISelStart = NULL;\r
-       m_nSelStartDu = 0;\r
-       m_bWillCommit = FALSE;\r
-       m_pValue = NULL;\r
-       m_bFieldFull = FALSE;\r
-       m_pbRc = NULL;\r
-       m_bRcDu = FALSE;\r
-\r
-       m_pSourceDoc = NULL;\r
-       m_pTargetBookMark = NULL;\r
-       m_pTargetDoc = NULL;\r
-       m_pTargetAnnot = NULL;\r
-\r
-       m_bValid = TRUE;\r
-}\r
-\r
-void CJS_EventHandler::Destroy()\r
-{\r
-       m_bValid = FALSE;\r
-}\r
-\r
-FX_BOOL CJS_EventHandler::IsValid()\r
-{\r
-       return m_bValid;\r
-}\r
-\r
-CFX_WideString & CJS_EventHandler::Change()\r
-{\r
-       if (m_pWideStrChange != NULL)\r
-               return *m_pWideStrChange;\r
-       else\r
-       {\r
-               return m_WideStrChangeDu;\r
-       }\r
-}\r
-\r
-CFX_WideString CJS_EventHandler::ChangeEx()\r
-{\r
-       return m_WideStrChangeEx;\r
-}\r
-\r
-int CJS_EventHandler::CommitKey()\r
-{\r
-       return m_nCommitKey;\r
-}\r
-\r
-FX_BOOL CJS_EventHandler::FieldFull()\r
-{\r
-       return m_bFieldFull;\r
-}\r
-\r
-FX_BOOL CJS_EventHandler::KeyDown()\r
-{\r
-       return m_bKeyDown;\r
-}\r
-\r
-FX_BOOL CJS_EventHandler::Modifier()\r
-{\r
-       return m_bModifier;\r
-}\r
-\r
-FX_LPCWSTR CJS_EventHandler::Name()\r
-{\r
-       switch (m_eEventType)\r
-       {\r
-       case JET_APP_INIT:                      return (FX_LPCWSTR)L"Init";\r
-       case JET_BATCH_EXEC:            return (FX_LPCWSTR)L"Exec";\r
-       case JET_BOOKMARK_MOUSEUP:      return (FX_LPCWSTR)L"Mouse Up";\r
-       case JET_CONSOLE_EXEC:          return (FX_LPCWSTR)L"Exec";\r
-       case JET_DOC_DIDPRINT:          return (FX_LPCWSTR)L"DidPrint";\r
-       case JET_DOC_DIDSAVE:           return (FX_LPCWSTR)L"DidSave";\r
-       case JET_DOC_OPEN:                      return (FX_LPCWSTR)L"Open";\r
-       case JET_DOC_WILLCLOSE:         return (FX_LPCWSTR)L"WillClose";\r
-       case JET_DOC_WILLPRINT:         return (FX_LPCWSTR)L"WillPrint";\r
-       case JET_DOC_WILLSAVE:          return (FX_LPCWSTR)L"WillSave";\r
-       case JET_EXTERNAL_EXEC:         return (FX_LPCWSTR)L"Exec";\r
-       case JET_FIELD_FOCUS:           \r
-       case JET_SCREEN_FOCUS:          return (FX_LPCWSTR)L"Focus";\r
-       case JET_FIELD_BLUR:            \r
-       case JET_SCREEN_BLUR:           return (FX_LPCWSTR)L"Blur";\r
-       case JET_FIELD_MOUSEDOWN:\r
-       case JET_SCREEN_MOUSEDOWN:      return (FX_LPCWSTR)L"Mouse Down";\r
-       case JET_FIELD_MOUSEUP:         \r
-       case JET_SCREEN_MOUSEUP:        return (FX_LPCWSTR)L"Mouse Up";\r
-       case JET_FIELD_MOUSEENTER:\r
-       case JET_SCREEN_MOUSEENTER:     return (FX_LPCWSTR)L"Mouse Enter";\r
-       case JET_FIELD_MOUSEEXIT:\r
-       case JET_SCREEN_MOUSEEXIT:      return (FX_LPCWSTR)L"Mouse Exit";\r
-       case JET_FIELD_CALCULATE:       return (FX_LPCWSTR)L"Calculate";\r
-       case JET_FIELD_FORMAT:          return (FX_LPCWSTR)L"Format";\r
-       case JET_FIELD_KEYSTROKE:       return (FX_LPCWSTR)L"Keystroke";\r
-       case JET_FIELD_VALIDATE:        return (FX_LPCWSTR)L"Validate";\r
-       case JET_LINK_MOUSEUP:          return (FX_LPCWSTR)L"Mouse Up";\r
-       case JET_MENU_EXEC:                     return (FX_LPCWSTR)L"Exec";\r
-       case JET_PAGE_OPEN:             \r
-       case JET_SCREEN_OPEN:           return (FX_LPCWSTR)L"Open";\r
-       case JET_PAGE_CLOSE:\r
-       case JET_SCREEN_CLOSE:          return (FX_LPCWSTR)L"Close";\r
-       case JET_SCREEN_INVIEW: \r
-       case JET_PAGE_INVIEW:           return (FX_LPCWSTR)L"InView";\r
-       case JET_PAGE_OUTVIEW:\r
-       case JET_SCREEN_OUTVIEW:        return (FX_LPCWSTR)L"OutView";\r
-       default:\r
-               return (FX_LPCWSTR)L"";\r
-       }\r
-\r
-       return (FX_LPCWSTR)L"";\r
-}\r
-\r
-FX_LPCWSTR CJS_EventHandler::Type()\r
-{\r
-       switch (m_eEventType)\r
-       {\r
-       case JET_APP_INIT:                      return (FX_LPCWSTR)L"App";\r
-       case JET_BATCH_EXEC:            return (FX_LPCWSTR)L"Batch";\r
-       case JET_BOOKMARK_MOUSEUP:      return (FX_LPCWSTR)L"BookMark"; \r
-       case JET_CONSOLE_EXEC:          return (FX_LPCWSTR)L"Console";\r
-       case JET_DOC_DIDPRINT:\r
-       case JET_DOC_DIDSAVE:\r
-       case JET_DOC_OPEN:\r
-       case JET_DOC_WILLCLOSE:\r
-       case JET_DOC_WILLPRINT:\r
-       case JET_DOC_WILLSAVE:          return (FX_LPCWSTR)L"Doc";\r
-       case JET_EXTERNAL_EXEC:         return (FX_LPCWSTR)L"External";\r
-       case JET_FIELD_BLUR:\r
-       case JET_FIELD_FOCUS:\r
-       case JET_FIELD_MOUSEDOWN:\r
-       case JET_FIELD_MOUSEENTER:\r
-       case JET_FIELD_MOUSEEXIT:\r
-       case JET_FIELD_MOUSEUP:\r
-       case JET_FIELD_CALCULATE:\r
-       case JET_FIELD_FORMAT:\r
-       case JET_FIELD_KEYSTROKE:\r
-       case JET_FIELD_VALIDATE:        return (FX_LPCWSTR)L"Field";\r
-       case JET_SCREEN_FOCUS:\r
-       case JET_SCREEN_BLUR:\r
-       case JET_SCREEN_OPEN:\r
-       case JET_SCREEN_CLOSE:\r
-       case JET_SCREEN_MOUSEDOWN:\r
-       case JET_SCREEN_MOUSEUP:\r
-       case JET_SCREEN_MOUSEENTER:\r
-       case JET_SCREEN_MOUSEEXIT:\r
-       case JET_SCREEN_INVIEW:\r
-       case JET_SCREEN_OUTVIEW:        return (FX_LPCWSTR)L"Screen";\r
-       case JET_LINK_MOUSEUP:          return (FX_LPCWSTR)L"Link";     \r
-       case JET_MENU_EXEC:                     return (FX_LPCWSTR)L"Menu";\r
-       case JET_PAGE_OPEN:\r
-       case JET_PAGE_CLOSE:\r
-       case JET_PAGE_INVIEW:\r
-       case JET_PAGE_OUTVIEW:return (FX_LPCWSTR)L"Page";\r
-       default:\r
-               return (FX_LPCWSTR)L"";\r
-       }\r
-\r
-       return (FX_LPCWSTR)L"";\r
-}\r
-\r
-FX_BOOL& CJS_EventHandler::Rc()\r
-{\r
-       if (m_pbRc != NULL)\r
-               return *m_pbRc;\r
-       else\r
-       {           \r
-               return m_bRcDu;\r
-       }\r
-}\r
-\r
-int & CJS_EventHandler::SelEnd()\r
-{\r
-       if (m_pISelEnd != NULL)\r
-       {\r
-               return *m_pISelEnd;\r
-       }\r
-       else\r
-       {\r
-               return m_nSelEndDu;\r
-       }\r
-}\r
-\r
-int & CJS_EventHandler::SelStart()\r
-{\r
-       if (m_pISelStart != NULL)\r
-               return * m_pISelStart;\r
-       else\r
-       {\r
-               return m_nSelStartDu;\r
-       }\r
-}\r
-\r
-FX_BOOL CJS_EventHandler::Shift()\r
-{\r
-       return m_bShift;\r
-}\r
-\r
-Field* CJS_EventHandler::Source()\r
-{\r
-       ASSERT(m_pJSContext != NULL);\r
-\r
-       CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();\r
-\r
-       JSFXObject  pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));\r
-       ASSERT(pDocObj.IsEmpty() == FALSE);\r
-       JSFXObject  pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));\r
-       ASSERT(pFieldObj.IsEmpty() == FALSE);\r
-\r
-       CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);\r
-       ASSERT(pJSDocument != NULL);\r
-       Document* pDocument = (Document*)pJSDocument->GetEmbedObject();\r
-       ASSERT(pDocument != NULL);\r
-       if (m_pTargetDoc != NULL)\r
-               pDocument->AttachDoc(m_pTargetDoc);\r
-       else\r
-               pDocument->AttachDoc(m_pJSContext->GetReaderDocument());\r
-       \r
-       //if (m_pSourceField == NULL)\r
-       //      return NULL;\r
-       //CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);\r
-       //CPDF_FormField* pFormField = pWidget->GetFormField();\r
-       //ASSERT(pFormField);\r
-       //CFX_WideString csFieldName = pFormField->GetFullName();\r
-       CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);\r
-       ASSERT(pJSField != NULL);\r
-       Field * pField = (Field *)pJSField->GetEmbedObject(); \r
-       ASSERT(pField != NULL);\r
-       pField->AttachField(pDocument, m_strSourceName);\r
-       return pField;  \r
-}\r
-\r
-Field* CJS_EventHandler::Target_Field()\r
-{\r
-       ASSERT(m_pJSContext != NULL);\r
-\r
-       CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();\r
-\r
-       JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));\r
-       ASSERT(pDocObj.IsEmpty() == FALSE);\r
-       JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));\r
-       ASSERT(pFieldObj.IsEmpty() == FALSE);\r
-\r
-       CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);\r
-       ASSERT(pJSDocument != NULL);\r
-       Document* pDocument = (Document*)pJSDocument->GetEmbedObject();\r
-       ASSERT(pDocument != NULL);\r
-       if (m_pTargetDoc != NULL)\r
-               pDocument->AttachDoc(m_pTargetDoc);\r
-       else\r
-               pDocument->AttachDoc(m_pJSContext->GetReaderDocument());\r
-       \r
-       CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);\r
-       ASSERT(pJSField != NULL);\r
-\r
-       Field* pField = (Field *)pJSField->GetEmbedObject(); \r
-       ASSERT(pField != NULL);\r
-\r
-       pField->AttachField(pDocument, m_strTargetName);\r
-       return pField;  \r
-}\r
-\r
-CFX_WideString& CJS_EventHandler::Value()\r
-{\r
-       return *m_pValue;\r
-}\r
-\r
-FX_BOOL CJS_EventHandler::WillCommit()\r
-{\r
-       return m_bWillCommit;\r
-}\r
-\r
-CFX_WideString CJS_EventHandler::TargetName()\r
-{\r
-       return m_strTargetName;\r
-}\r
-\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "JS_EventHandler.h"
+
+#include "../../include/javascript/IJavaScript.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 ---------------------------- */
+
+CJS_EventHandler::CJS_EventHandler(CJS_Context* pContext)
+    : m_pJSContext(pContext),
+      m_eEventType(JET_UNKNOWN),
+      m_bValid(FALSE),
+      m_pWideStrChange(NULL),
+      m_nCommitKey(-1),
+      m_bKeyDown(FALSE),
+      m_bModifier(FALSE),
+      m_bShift(FALSE),
+      m_pISelEnd(NULL),
+      m_nSelEndDu(0),
+      m_pISelStart(NULL),
+      m_nSelStartDu(0),
+      m_bWillCommit(FALSE),
+      m_pValue(NULL),
+      m_bFieldFull(FALSE),
+      m_pbRc(NULL),
+      m_bRcDu(FALSE),
+      m_pSourceDoc(NULL),
+      m_pTargetBookMark(NULL),
+      m_pTargetDoc(NULL),
+      m_pTargetAnnot(NULL) {}
+
+CJS_EventHandler::~CJS_EventHandler() {}
+
+void CJS_EventHandler::OnApp_Init() {
+  Initial(JET_APP_INIT);
+}
+
+void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc,
+                                  const CFX_WideString& strTargetName) {
+  Initial(JET_DOC_OPEN);
+
+  m_pTargetDoc = pDoc;
+  m_strTargetName = strTargetName;
+}
+
+void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc) {
+  Initial(JET_DOC_WILLPRINT);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc) {
+  Initial(JET_DOC_DIDPRINT);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc) {
+  Initial(JET_DOC_WILLSAVE);
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc) {
+  Initial(JET_DOC_DIDSAVE);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc) {
+  Initial(JET_DOC_WILLCLOSE);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc) {
+  Initial(JET_PAGE_OPEN);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc) {
+  Initial(JET_PAGE_CLOSE);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc) {
+  Initial(JET_PAGE_INVIEW);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc) {
+  Initial(JET_PAGE_OUTVIEW);
+
+  m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier,
+                                          FX_BOOL bShift,
+                                          CPDF_FormField* pTarget) {
+  Initial(JET_FIELD_MOUSEENTER);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_MouseExit(FX_BOOL bModifier,
+                                         FX_BOOL bShift,
+                                         CPDF_FormField* pTarget) {
+  Initial(JET_FIELD_MOUSEEXIT);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_MouseDown(FX_BOOL bModifier,
+                                         FX_BOOL bShift,
+                                         CPDF_FormField* pTarget) {
+  Initial(JET_FIELD_MOUSEDOWN);
+  m_eEventType = JET_FIELD_MOUSEDOWN;
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_MouseUp(FX_BOOL bModifier,
+                                       FX_BOOL bShift,
+                                       CPDF_FormField* pTarget) {
+  Initial(JET_FIELD_MOUSEUP);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_Focus(FX_BOOL bModifier,
+                                     FX_BOOL bShift,
+                                     CPDF_FormField* pTarget,
+                                     const CFX_WideString& Value) {
+  Initial(JET_FIELD_FOCUS);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+  m_pValue = (CFX_WideString*)&Value;
+}
+
+void CJS_EventHandler::OnField_Blur(FX_BOOL bModifier,
+                                    FX_BOOL bShift,
+                                    CPDF_FormField* pTarget,
+                                    const CFX_WideString& Value) {
+  Initial(JET_FIELD_BLUR);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+  m_pValue = (CFX_WideString*)&Value;
+}
+
+void CJS_EventHandler::OnField_Keystroke(CFX_WideString& strChange,
+                                         const CFX_WideString& strChangeEx,
+                                         FX_BOOL KeyDown,
+                                         FX_BOOL bModifier,
+                                         int& nSelEnd,
+                                         int& nSelStart,
+                                         FX_BOOL bShift,
+                                         CPDF_FormField* pTarget,
+                                         CFX_WideString& Value,
+                                         FX_BOOL bWillCommit,
+                                         FX_BOOL bFieldFull,
+                                         FX_BOOL& bRc) {
+  Initial(JET_FIELD_KEYSTROKE);
+
+  m_nCommitKey = 0;
+  m_pWideStrChange = &strChange;
+  m_WideStrChangeEx = strChangeEx;
+  m_bKeyDown = KeyDown;
+  m_bModifier = bModifier;
+  m_pISelEnd = &nSelEnd;
+  m_pISelStart = &nSelStart;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+  m_pValue = &Value;
+  m_bWillCommit = bWillCommit;
+  m_pbRc = &bRc;
+  m_bFieldFull = bFieldFull;
+}
+
+void CJS_EventHandler::OnField_Validate(CFX_WideString& strChange,
+                                        const CFX_WideString& strChangeEx,
+                                        FX_BOOL bKeyDown,
+                                        FX_BOOL bModifier,
+                                        FX_BOOL bShift,
+                                        CPDF_FormField* pTarget,
+                                        CFX_WideString& Value,
+                                        FX_BOOL& bRc) {
+  Initial(JET_FIELD_VALIDATE);
+
+  m_pWideStrChange = &strChange;
+  m_WideStrChangeEx = strChangeEx;
+  m_bKeyDown = bKeyDown;
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+  m_pValue = &Value;
+  m_pbRc = &bRc;
+}
+
+void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource,
+                                         CPDF_FormField* pTarget,
+                                         CFX_WideString& Value,
+                                         FX_BOOL& bRc) {
+  Initial(JET_FIELD_CALCULATE);
+
+  if (pSource)
+    m_strSourceName = pSource->GetFullName();
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+  m_pValue = &Value;
+  m_pbRc = &bRc;
+}
+
+void CJS_EventHandler::OnField_Format(CPDF_FormField* pTarget,
+                                      CFX_WideString& Value,
+                                      FX_BOOL bWillCommit) {
+  Initial(JET_FIELD_FORMAT);
+
+  m_nCommitKey = 0;
+  ASSERT(pTarget != NULL);
+  m_strTargetName = pTarget->GetFullName();
+  m_pValue = &Value;
+  m_bWillCommit = bWillCommit;
+}
+
+void CJS_EventHandler::OnScreen_Focus(FX_BOOL bModifier,
+                                      FX_BOOL bShift,
+                                      CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_FOCUS);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_Blur(FX_BOOL bModifier,
+                                     FX_BOOL bShift,
+                                     CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_BLUR);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_Open(FX_BOOL bModifier,
+                                     FX_BOOL bShift,
+                                     CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_OPEN);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_Close(FX_BOOL bModifier,
+                                      FX_BOOL bShift,
+                                      CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_CLOSE);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseDown(FX_BOOL bModifier,
+                                          FX_BOOL bShift,
+                                          CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_MOUSEDOWN);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseUp(FX_BOOL bModifier,
+                                        FX_BOOL bShift,
+                                        CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_MOUSEUP);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseEnter(FX_BOOL bModifier,
+                                           FX_BOOL bShift,
+                                           CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_MOUSEENTER);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseExit(FX_BOOL bModifier,
+                                          FX_BOOL bShift,
+                                          CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_MOUSEEXIT);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_InView(FX_BOOL bModifier,
+                                       FX_BOOL bShift,
+                                       CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_INVIEW);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_OutView(FX_BOOL bModifier,
+                                        FX_BOOL bShift,
+                                        CPDFSDK_Annot* pScreen) {
+  Initial(JET_SCREEN_OUTVIEW);
+
+  m_bModifier = bModifier;
+  m_bShift = bShift;
+  m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget) {
+  Initial(JET_LINK_MOUSEUP);
+
+  m_pTargetDoc = pTarget;
+}
+
+void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) {
+  Initial(JET_BOOKMARK_MOUSEUP);
+
+  m_pTargetBookMark = pBookMark;
+}
+
+void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget,
+                                   const CFX_WideString& strTargetName) {
+  Initial(JET_MENU_EXEC);
+
+  m_pTargetDoc = pTarget;
+  m_strTargetName = strTargetName;
+}
+
+void CJS_EventHandler::OnExternal_Exec() {
+  Initial(JET_EXTERNAL_EXEC);
+}
+
+void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget) {
+  Initial(JET_BATCH_EXEC);
+
+  m_pTargetDoc = pTarget;
+}
+
+void CJS_EventHandler::OnConsole_Exec() {
+  Initial(JET_CONSOLE_EXEC);
+}
+
+void CJS_EventHandler::Initial(JS_EVENT_T type) {
+  m_eEventType = type;
+
+  m_strTargetName = L"";
+  m_strSourceName = L"";
+  m_pWideStrChange = NULL;
+  m_WideStrChangeDu = L"";
+  m_WideStrChangeEx = L"";
+  m_nCommitKey = -1;
+  m_bKeyDown = FALSE;
+  m_bModifier = FALSE;
+  m_bShift = FALSE;
+  m_pISelEnd = NULL;
+  m_nSelEndDu = 0;
+  m_pISelStart = NULL;
+  m_nSelStartDu = 0;
+  m_bWillCommit = FALSE;
+  m_pValue = NULL;
+  m_bFieldFull = FALSE;
+  m_pbRc = NULL;
+  m_bRcDu = FALSE;
+
+  m_pSourceDoc = NULL;
+  m_pTargetBookMark = NULL;
+  m_pTargetDoc = NULL;
+  m_pTargetAnnot = NULL;
+
+  m_bValid = TRUE;
+}
+
+void CJS_EventHandler::Destroy() {
+  m_bValid = FALSE;
+}
+
+FX_BOOL CJS_EventHandler::IsValid() {
+  return m_bValid;
+}
+
+CFX_WideString& CJS_EventHandler::Change() {
+  if (m_pWideStrChange) {
+    return *m_pWideStrChange;
+  }
+  return m_WideStrChangeDu;
+}
+
+CFX_WideString CJS_EventHandler::ChangeEx() {
+  return m_WideStrChangeEx;
+}
+
+int CJS_EventHandler::CommitKey() {
+  return m_nCommitKey;
+}
+
+FX_BOOL CJS_EventHandler::FieldFull() {
+  return m_bFieldFull;
+}
+
+FX_BOOL CJS_EventHandler::KeyDown() {
+  return m_bKeyDown;
+}
+
+FX_BOOL CJS_EventHandler::Modifier() {
+  return m_bModifier;
+}
+
+const FX_WCHAR* CJS_EventHandler::Name() {
+  switch (m_eEventType) {
+    case JET_APP_INIT:
+      return L"Init";
+    case JET_BATCH_EXEC:
+      return L"Exec";
+    case JET_BOOKMARK_MOUSEUP:
+      return L"Mouse Up";
+    case JET_CONSOLE_EXEC:
+      return L"Exec";
+    case JET_DOC_DIDPRINT:
+      return L"DidPrint";
+    case JET_DOC_DIDSAVE:
+      return L"DidSave";
+    case JET_DOC_OPEN:
+      return L"Open";
+    case JET_DOC_WILLCLOSE:
+      return L"WillClose";
+    case JET_DOC_WILLPRINT:
+      return L"WillPrint";
+    case JET_DOC_WILLSAVE:
+      return L"WillSave";
+    case JET_EXTERNAL_EXEC:
+      return L"Exec";
+    case JET_FIELD_FOCUS:
+    case JET_SCREEN_FOCUS:
+      return L"Focus";
+    case JET_FIELD_BLUR:
+    case JET_SCREEN_BLUR:
+      return L"Blur";
+    case JET_FIELD_MOUSEDOWN:
+    case JET_SCREEN_MOUSEDOWN:
+      return L"Mouse Down";
+    case JET_FIELD_MOUSEUP:
+    case JET_SCREEN_MOUSEUP:
+      return L"Mouse Up";
+    case JET_FIELD_MOUSEENTER:
+    case JET_SCREEN_MOUSEENTER:
+      return L"Mouse Enter";
+    case JET_FIELD_MOUSEEXIT:
+    case JET_SCREEN_MOUSEEXIT:
+      return L"Mouse Exit";
+    case JET_FIELD_CALCULATE:
+      return L"Calculate";
+    case JET_FIELD_FORMAT:
+      return L"Format";
+    case JET_FIELD_KEYSTROKE:
+      return L"Keystroke";
+    case JET_FIELD_VALIDATE:
+      return L"Validate";
+    case JET_LINK_MOUSEUP:
+      return L"Mouse Up";
+    case JET_MENU_EXEC:
+      return L"Exec";
+    case JET_PAGE_OPEN:
+    case JET_SCREEN_OPEN:
+      return L"Open";
+    case JET_PAGE_CLOSE:
+    case JET_SCREEN_CLOSE:
+      return L"Close";
+    case JET_SCREEN_INVIEW:
+    case JET_PAGE_INVIEW:
+      return L"InView";
+    case JET_PAGE_OUTVIEW:
+    case JET_SCREEN_OUTVIEW:
+      return L"OutView";
+    default:
+      return L"";
+  }
+
+  return L"";
+}
+
+const FX_WCHAR* CJS_EventHandler::Type() {
+  switch (m_eEventType) {
+    case JET_APP_INIT:
+      return L"App";
+    case JET_BATCH_EXEC:
+      return L"Batch";
+    case JET_BOOKMARK_MOUSEUP:
+      return L"BookMark";
+    case JET_CONSOLE_EXEC:
+      return L"Console";
+    case JET_DOC_DIDPRINT:
+    case JET_DOC_DIDSAVE:
+    case JET_DOC_OPEN:
+    case JET_DOC_WILLCLOSE:
+    case JET_DOC_WILLPRINT:
+    case JET_DOC_WILLSAVE:
+      return L"Doc";
+    case JET_EXTERNAL_EXEC:
+      return L"External";
+    case JET_FIELD_BLUR:
+    case JET_FIELD_FOCUS:
+    case JET_FIELD_MOUSEDOWN:
+    case JET_FIELD_MOUSEENTER:
+    case JET_FIELD_MOUSEEXIT:
+    case JET_FIELD_MOUSEUP:
+    case JET_FIELD_CALCULATE:
+    case JET_FIELD_FORMAT:
+    case JET_FIELD_KEYSTROKE:
+    case JET_FIELD_VALIDATE:
+      return L"Field";
+    case JET_SCREEN_FOCUS:
+    case JET_SCREEN_BLUR:
+    case JET_SCREEN_OPEN:
+    case JET_SCREEN_CLOSE:
+    case JET_SCREEN_MOUSEDOWN:
+    case JET_SCREEN_MOUSEUP:
+    case JET_SCREEN_MOUSEENTER:
+    case JET_SCREEN_MOUSEEXIT:
+    case JET_SCREEN_INVIEW:
+    case JET_SCREEN_OUTVIEW:
+      return L"Screen";
+    case JET_LINK_MOUSEUP:
+      return L"Link";
+    case JET_MENU_EXEC:
+      return L"Menu";
+    case JET_PAGE_OPEN:
+    case JET_PAGE_CLOSE:
+    case JET_PAGE_INVIEW:
+    case JET_PAGE_OUTVIEW:
+      return L"Page";
+    default:
+      return L"";
+  }
+
+  return L"";
+}
+
+FX_BOOL& CJS_EventHandler::Rc() {
+  if (m_pbRc) {
+    return *m_pbRc;
+  }
+  return m_bRcDu;
+}
+
+int& CJS_EventHandler::SelEnd() {
+  if (m_pISelEnd) {
+    return *m_pISelEnd;
+  }
+  return m_nSelEndDu;
+}
+
+int& CJS_EventHandler::SelStart() {
+  if (m_pISelStart) {
+    return *m_pISelStart;
+  }
+  return m_nSelStartDu;
+}
+
+FX_BOOL CJS_EventHandler::Shift() {
+  return m_bShift;
+}
+
+Field* CJS_EventHandler::Source() {
+  CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+  v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Document::g_nObjDefnID);
+  ASSERT(!pDocObj.IsEmpty());
+
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Field::g_nObjDefnID);
+  ASSERT(!pFieldObj.IsEmpty());
+
+  CJS_Document* pJSDocument =
+      (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
+  Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
+  pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
+                                    : m_pJSContext->GetReaderDocument());
+
+  CJS_Field* pJSField =
+      (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
+  Field* pField = (Field*)pJSField->GetEmbedObject();
+  pField->AttachField(pDocument, m_strSourceName);
+  return pField;
+}
+
+Field* CJS_EventHandler::Target_Field() {
+  CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+  v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Document::g_nObjDefnID);
+  ASSERT(!pDocObj.IsEmpty());
+
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Field::g_nObjDefnID);
+  ASSERT(!pFieldObj.IsEmpty());
+
+  CJS_Document* pJSDocument =
+      (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
+  Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
+  pDocument->AttachDoc(m_pTargetDoc ? m_pTargetDoc
+                                    : m_pJSContext->GetReaderDocument());
+
+  CJS_Field* pJSField =
+      (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pFieldObj);
+  Field* pField = (Field*)pJSField->GetEmbedObject();
+  pField->AttachField(pDocument, m_strTargetName);
+  return pField;
+}
+
+CFX_WideString& CJS_EventHandler::Value() {
+  return *m_pValue;
+}
+
+FX_BOOL CJS_EventHandler::WillCommit() {
+  return m_bWillCommit;
+}
+
+CFX_WideString CJS_EventHandler::TargetName() {
+  return m_strTargetName;
+}