diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-02-16 17:01:00 -0800 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-21 15:18:27 +0000 |
commit | b1670b5cca9a59dfb612ef9eb891a70dd716bf9c (patch) | |
tree | e624b1ca93721894ff29a14bb52443bf4f952cf6 /fpdfsdk/javascript/event.cpp | |
parent | 026f3d306d339585612d63a9f6ac5ed8839a3179 (diff) | |
download | pdfium-b1670b5cca9a59dfb612ef9eb891a70dd716bf9c.tar.xz |
Pass CJS_Runtime to JS callbacks.
This is much more convenient, since only a fraction of them
need an IJS_EventContext, which can be obtained from the
CJS_Runtime.
Make GetCurrentEventContext() specific to CJS_Runtime, and
return the concrete type. This saves a lot of casting.
Change-Id: If79a3bcbf44de513f3caace153099234cc313d47
Reviewed-on: https://pdfium-review.googlesource.com/2793
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/event.cpp')
-rw-r--r-- | fpdfsdk/javascript/event.cpp | 102 |
1 files changed, 43 insertions, 59 deletions
diff --git a/fpdfsdk/javascript/event.cpp b/fpdfsdk/javascript/event.cpp index 48f3ce8a9c..88dce4b36a 100644 --- a/fpdfsdk/javascript/event.cpp +++ b/fpdfsdk/javascript/event.cpp @@ -48,11 +48,11 @@ event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} event::~event() {} -bool event::change(IJS_EventContext* cc, +bool event::change(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); CFX_WideString& wChange = pEvent->Change(); if (vp.IsSetting()) { if (vp.GetJSValue()->GetType() == CJS_Value::VT_string) @@ -63,99 +63,90 @@ bool event::change(IJS_EventContext* cc, return true; } -bool event::changeEx(IJS_EventContext* cc, +bool event::changeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->ChangeEx(); return true; } -bool event::commitKey(IJS_EventContext* cc, +bool event::commitKey(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->CommitKey(); return true; } -bool event::fieldFull(IJS_EventContext* cc, +bool event::fieldFull(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return false; - if (pEvent->FieldFull()) - vp << true; - else - vp << false; + vp << pEvent->FieldFull(); return true; } -bool event::keyDown(IJS_EventContext* cc, +bool event::keyDown(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (pEvent->KeyDown()) - vp << true; - else - vp << false; + vp << pEvent->KeyDown(); return true; } -bool event::modifier(IJS_EventContext* cc, +bool event::modifier(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (pEvent->Modifier()) - vp << true; - else - vp << false; + vp << pEvent->Modifier(); return true; } -bool event::name(IJS_EventContext* cc, +bool event::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Name(); return true; } -bool event::rc(IJS_EventContext* cc, +bool event::rc(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); bool& bRc = pEvent->Rc(); if (vp.IsSetting()) @@ -166,29 +157,29 @@ bool event::rc(IJS_EventContext* cc, return true; } -bool event::richChange(IJS_EventContext* cc, +bool event::richChange(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool event::richChangeEx(IJS_EventContext* cc, +bool event::richChangeEx(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool event::richValue(IJS_EventContext* cc, +bool event::richValue(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { return true; } -bool event::selEnd(IJS_EventContext* cc, +bool event::selEnd(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; @@ -202,11 +193,11 @@ bool event::selEnd(IJS_EventContext* cc, return true; } -bool event::selStart(IJS_EventContext* cc, +bool event::selStart(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; @@ -220,79 +211,76 @@ bool event::selStart(IJS_EventContext* cc, return true; } -bool event::shift(IJS_EventContext* cc, +bool event::shift(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); - if (pEvent->Shift()) - vp << true; - else - vp << false; + vp << pEvent->Shift(); return true; } -bool event::source(IJS_EventContext* cc, +bool event::source(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Source()->GetJSObject(); return true; } -bool event::target(IJS_EventContext* cc, +bool event::target(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Target_Field()->GetJSObject(); return true; } -bool event::targetName(IJS_EventContext* cc, +bool event::targetName(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; - CJS_EventContext* pContext = (CJS_EventContext*)cc; - CJS_EventHandler* pEvent = pContext->GetEventHandler(); + CJS_EventHandler* pEvent = + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->TargetName(); return true; } -bool event::type(IJS_EventContext* cc, +bool event::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); vp << pEvent->Type(); return true; } -bool event::value(IJS_EventContext* cc, +bool event::value(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); + pRuntime->GetCurrentEventContext()->GetEventHandler(); if (wcscmp((const wchar_t*)pEvent->Type(), L"Field") != 0) return false; @@ -309,19 +297,15 @@ bool event::value(IJS_EventContext* cc, return true; } -bool event::willCommit(IJS_EventContext* cc, +bool event::willCommit(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_EventHandler* pEvent = - static_cast<CJS_EventContext*>(cc)->GetEventHandler(); - - if (pEvent->WillCommit()) - vp << true; - else - vp << false; + pRuntime->GetCurrentEventContext()->GetEventHandler(); + vp << pEvent->WillCommit(); return true; } |