From fae5e26d983848089e35e2b53e9da24036661b08 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 20 Nov 2017 19:58:13 +0000 Subject: Make some CJS_EventHandler methods const. Change-Id: Ie95b6a4c2613b5e110d2dd1244dd4a87375f624f Reviewed-on: https://pdfium-review.googlesource.com/18750 Reviewed-by: Ryan Harrison Commit-Queue: Lei Zhang --- fxjs/cjs_event.cpp | 4 ++-- fxjs/cjs_eventhandler.cpp | 51 +++++++++++++++++++++++----------------------- fxjs/cjs_eventhandler.h | 30 ++++++++++++++------------- fxjs/cjs_publicmethods.cpp | 6 +++--- 4 files changed, 47 insertions(+), 44 deletions(-) (limited to 'fxjs') diff --git a/fxjs/cjs_event.cpp b/fxjs/cjs_event.cpp index 4e20bbc8ba..2d4508a30b 100644 --- a/fxjs/cjs_event.cpp +++ b/fxjs/cjs_event.cpp @@ -192,7 +192,7 @@ CJS_Return event::set_sel_end(CJS_Runtime* pRuntime, v8::Local vp) { if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return CJS_Return(true); - pEvent->SelEnd() = pRuntime->ToInt32(vp); + pEvent->SetSelEnd(pRuntime->ToInt32(vp)); return CJS_Return(true); } @@ -214,7 +214,7 @@ CJS_Return event::set_sel_start(CJS_Runtime* pRuntime, if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return CJS_Return(true); - pEvent->SelStart() = pRuntime->ToInt32(vp); + pEvent->SetSelStart(pRuntime->ToInt32(vp)); return CJS_Return(true); } diff --git a/fxjs/cjs_eventhandler.cpp b/fxjs/cjs_eventhandler.cpp index c052f9ed58..eb150b247b 100644 --- a/fxjs/cjs_eventhandler.cpp +++ b/fxjs/cjs_eventhandler.cpp @@ -404,7 +404,7 @@ void CJS_EventHandler::Destroy() { m_bValid = false; } -bool CJS_EventHandler::IsValid() { +bool CJS_EventHandler::IsValid() const { return m_bValid; } @@ -415,27 +415,27 @@ WideString& CJS_EventHandler::Change() { return m_WideStrChangeDu; } -WideString CJS_EventHandler::ChangeEx() { +const WideString& CJS_EventHandler::ChangeEx() { return m_WideStrChangeEx; } -int CJS_EventHandler::CommitKey() { +int CJS_EventHandler::CommitKey() const { return m_nCommitKey; } -bool CJS_EventHandler::FieldFull() { +bool CJS_EventHandler::FieldFull() const { return m_bFieldFull; } -bool CJS_EventHandler::KeyDown() { +bool CJS_EventHandler::KeyDown() const { return m_bKeyDown; } -bool CJS_EventHandler::Modifier() { +bool CJS_EventHandler::Modifier() const { return m_bModifier; } -const wchar_t* CJS_EventHandler::Name() { +const wchar_t* CJS_EventHandler::Name() const { switch (m_eEventType) { case JET_APP_INIT: return L"Init"; @@ -506,7 +506,7 @@ const wchar_t* CJS_EventHandler::Name() { } } -const wchar_t* CJS_EventHandler::Type() { +const wchar_t* CJS_EventHandler::Type() const { switch (m_eEventType) { case JET_APP_INIT: return L"App"; @@ -562,27 +562,28 @@ const wchar_t* CJS_EventHandler::Type() { } bool& CJS_EventHandler::Rc() { - if (m_pbRc) { - return *m_pbRc; - } - return m_bRcDu; + return m_pbRc ? *m_pbRc : m_bRcDu; } -int& CJS_EventHandler::SelEnd() { - if (m_pISelEnd) { - return *m_pISelEnd; - } - return m_nSelEndDu; +int CJS_EventHandler::SelEnd() const { + return m_pISelEnd ? *m_pISelEnd : m_nSelEndDu; } -int& CJS_EventHandler::SelStart() { - if (m_pISelStart) { - return *m_pISelStart; - } - return m_nSelStartDu; +int CJS_EventHandler::SelStart() const { + return m_pISelStart ? *m_pISelStart : m_nSelStartDu; +} + +void CJS_EventHandler::SetSelEnd(int value) { + int& target = m_pISelEnd ? *m_pISelEnd : m_nSelEndDu; + target = value; +} + +void CJS_EventHandler::SetSelStart(int value) { + int& target = m_pISelStart ? *m_pISelStart : m_nSelStartDu; + target = value; } -bool CJS_EventHandler::Shift() { +bool CJS_EventHandler::Shift() const { return m_bShift; } @@ -644,10 +645,10 @@ WideString& CJS_EventHandler::Value() { return *m_pValue; } -bool CJS_EventHandler::WillCommit() { +bool CJS_EventHandler::WillCommit() const { return m_bWillCommit; } -WideString CJS_EventHandler::TargetName() { +const WideString& CJS_EventHandler::TargetName() const { return m_strTargetName; } diff --git a/fxjs/cjs_eventhandler.h b/fxjs/cjs_eventhandler.h index cb7b3c09b1..87ce1dcca0 100644 --- a/fxjs/cjs_eventhandler.h +++ b/fxjs/cjs_eventhandler.h @@ -142,27 +142,29 @@ class CJS_EventHandler { void Initial(JS_EVENT_T type); void Destroy(); - bool IsValid(); + bool IsValid() const; WideString& Change(); - WideString ChangeEx(); - int CommitKey(); - bool FieldFull(); - bool KeyDown(); - bool Modifier(); - const wchar_t* Name(); - const wchar_t* Type(); + const WideString& ChangeEx(); + int CommitKey() const; + bool FieldFull() const; + bool KeyDown() const; + bool Modifier() const; + const wchar_t* Name() const; + const wchar_t* Type() const; bool& Rc(); - int& SelEnd(); - int& SelStart(); - bool Shift(); + int SelEnd() const; + int SelStart() const; + void SetSelEnd(int value); + void SetSelStart(int value); + bool Shift() const; Field* Source(); Field* Target_Field(); WideString& Value(); - bool WillCommit(); - WideString TargetName(); + bool WillCommit() const; + const WideString& TargetName() const; - JS_EVENT_T EventType() { return m_eEventType; } + JS_EVENT_T EventType() const { return m_eEventType; } UnownedPtr const m_pJSEventContext; JS_EVENT_T m_eEventType; diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index 856fa11732..f54bc5ba4d 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -1228,7 +1228,7 @@ CJS_Return CJS_PublicMethods::AFDate_KeystrokeEx( if (!pEvent->m_pValue) return CJS_Return(false); - WideString strValue = pEvent->Value(); + const WideString& strValue = pEvent->Value(); if (strValue.IsEmpty()) return CJS_Return(true); @@ -1369,7 +1369,7 @@ CJS_Return CJS_PublicMethods::AFSpecial_Format( if (!pEvent->m_pValue) return CJS_Return(false); - WideString wsSource = pEvent->Value(); + const WideString& wsSource = pEvent->Value(); WideString wsFormat; switch (pRuntime->ToInt32(params[0])) { case 0: @@ -1405,7 +1405,7 @@ CJS_Return CJS_PublicMethods::AFSpecial_KeystrokeEx( if (!pEvent->m_pValue) return CJS_Return(false); - WideString& valEvent = pEvent->Value(); + const WideString& valEvent = pEvent->Value(); WideString wstrMask = pRuntime->ToWideString(params[0]); if (wstrMask.IsEmpty()) return CJS_Return(true); -- cgit v1.2.3