summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-08-16 16:38:27 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-17 16:13:14 +0000
commit0d2349b634bef51070f9ba4115ead47d240063bf (patch)
tree1d3f6240c445cd1ec59a49894bf03d297cad2914
parent022b4397f98e7bb6d283918c836a4d1d386ac9cc (diff)
downloadpdfium-0d2349b634bef51070f9ba4115ead47d240063bf.tar.xz
Turn caret movement into an enum class
This CL changes caret movement into an enum class and removes the MoveNone flag. Change-Id: I8a01b057942d45ceae9a6c3b95cfe3b8dc9ce9a5 Reviewed-on: https://pdfium-review.googlesource.com/11274 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--xfa/fde/cfde_txtedtengine.cpp22
-rw-r--r--xfa/fde/cfde_txtedtengine.h21
-rw-r--r--xfa/fwl/cfwl_comboedit.cpp2
-rw-r--r--xfa/fwl/cfwl_edit.cpp42
4 files changed, 36 insertions, 51 deletions
diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp
index e69f299e30..31cbfc0773 100644
--- a/xfa/fde/cfde_txtedtengine.cpp
+++ b/xfa/fde/cfde_txtedtengine.cpp
@@ -265,9 +265,7 @@ int32_t CFDE_TxtEdtEngine::SetCaretPos(int32_t nIndex, bool bBefore) {
return m_nCaret;
}
-int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret,
- bool bShift,
- bool bCtrl) {
+int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_CaretMove eMoveCaret, bool bShift) {
if (IsLocked() || !pdfium::IndexInBounds(m_PagePtrArray, m_nCaretPage))
return 0;
@@ -284,46 +282,44 @@ int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret,
}
switch (eMoveCaret) {
- case MC_Left: {
+ case FDE_CaretMove::Left: {
bool bBefore = true;
int32_t nIndex = MoveBackward(bBefore);
if (nIndex >= 0)
UpdateCaretRect(nIndex, bBefore);
break;
}
- case MC_Right: {
+ case FDE_CaretMove::Right: {
bool bBefore = true;
int32_t nIndex = MoveForward(bBefore);
if (nIndex >= 0)
UpdateCaretRect(nIndex, bBefore);
break;
}
- case MC_Up: {
+ case FDE_CaretMove::Up: {
CFX_PointF ptCaret;
if (MoveUp(ptCaret))
UpdateCaretIndex(ptCaret);
break;
}
- case MC_Down: {
+ case FDE_CaretMove::Down: {
CFX_PointF ptCaret;
if (MoveDown(ptCaret))
UpdateCaretIndex(ptCaret);
break;
}
- case MC_LineStart:
+ case FDE_CaretMove::LineStart:
MoveLineStart();
break;
- case MC_LineEnd:
+ case FDE_CaretMove::LineEnd:
MoveLineEnd();
break;
- case MC_Home:
+ case FDE_CaretMove::Home:
MoveHome();
break;
- case MC_End:
+ case FDE_CaretMove::End:
MoveEnd();
break;
- default:
- break;
}
if (bShift && m_nAnchorPos != -1 && (m_nAnchorPos != m_nCaret)) {
AddSelRange(std::min(m_nAnchorPos, m_nCaret), abs(m_nAnchorPos - m_nCaret));
diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h
index 31de49b4d2..9d472ce65a 100644
--- a/xfa/fde/cfde_txtedtengine.h
+++ b/xfa/fde/cfde_txtedtengine.h
@@ -38,16 +38,15 @@ class IFX_CharIter;
#define FDE_TEXTEDITLAYOUT_CombText (1L << 4)
#define FDE_TEXTEDITLAYOUT_LastLineHeight (1L << 8)
-enum FDE_TXTEDTMOVECARET {
- MC_MoveNone = 0,
- MC_Left,
- MC_Right,
- MC_Up,
- MC_Down,
- MC_LineStart,
- MC_LineEnd,
- MC_Home,
- MC_End,
+enum class FDE_CaretMove {
+ Left,
+ Right,
+ Up,
+ Down,
+ LineStart,
+ LineEnd,
+ Home,
+ End,
};
struct FDE_TXTEDTPARAMS {
@@ -109,7 +108,7 @@ class CFDE_TxtEdtEngine {
return IsLocked() ? 0 : m_nCaret + (m_bBefore ? 0 : 1);
}
int32_t SetCaretPos(int32_t nIndex, bool bBefore);
- int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, bool bShift, bool bCtrl);
+ int32_t MoveCaretPos(FDE_CaretMove eMoveCaret, bool bShift);
int32_t Insert(const CFX_WideString& str);
void Delete(bool bBackspace);
diff --git a/xfa/fwl/cfwl_comboedit.cpp b/xfa/fwl/cfwl_comboedit.cpp
index e7a2c6eb8f..68cde76707 100644
--- a/xfa/fwl/cfwl_comboedit.cpp
+++ b/xfa/fwl/cfwl_comboedit.cpp
@@ -28,7 +28,7 @@ void CFWL_ComboEdit::ClearSelected() {
void CFWL_ComboEdit::SetSelected() {
FlagFocus(true);
- GetTxtEdtEngine()->MoveCaretPos(MC_End, false, false);
+ GetTxtEdtEngine()->MoveCaretPos(FDE_CaretMove::End, false);
AddSelRange(0);
}
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 38f8f70498..0045c36858 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -1387,43 +1387,34 @@ void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) {
}
void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) {
- FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone;
bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift);
bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl);
- uint32_t dwKeyCode = pMsg->m_dwKeyCode;
- switch (dwKeyCode) {
- case FWL_VKEY_Left: {
- MoveCaret = MC_Left;
+ switch (pMsg->m_dwKeyCode) {
+ case FWL_VKEY_Left:
+ m_EdtEngine.MoveCaretPos(FDE_CaretMove::Left, bShift);
break;
- }
- case FWL_VKEY_Right: {
- MoveCaret = MC_Right;
+ case FWL_VKEY_Right:
+ m_EdtEngine.MoveCaretPos(FDE_CaretMove::Right, bShift);
break;
- }
- case FWL_VKEY_Up: {
- MoveCaret = MC_Up;
+ case FWL_VKEY_Up:
+ m_EdtEngine.MoveCaretPos(FDE_CaretMove::Up, bShift);
break;
- }
- case FWL_VKEY_Down: {
- MoveCaret = MC_Down;
- break;
- }
- case FWL_VKEY_Home: {
- MoveCaret = bCtrl ? MC_Home : MC_LineStart;
+ case FWL_VKEY_Down:
+ m_EdtEngine.MoveCaretPos(FDE_CaretMove::Down, bShift);
break;
- }
- case FWL_VKEY_End: {
- MoveCaret = bCtrl ? MC_End : MC_LineEnd;
+ case FWL_VKEY_Home:
+ m_EdtEngine.MoveCaretPos(
+ bCtrl ? FDE_CaretMove::Home : FDE_CaretMove::LineStart, bShift);
break;
- }
- case FWL_VKEY_Insert:
+ case FWL_VKEY_End:
+ m_EdtEngine.MoveCaretPos(
+ bCtrl ? FDE_CaretMove::End : FDE_CaretMove::LineEnd, bShift);
break;
case FWL_VKEY_Delete: {
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
break;
}
-
#if (_FX_OS_ == _FX_MACOSX_)
m_EdtEngine.Delete(true);
#else
@@ -1431,13 +1422,12 @@ void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) {
#endif
break;
}
+ case FWL_VKEY_Insert:
case FWL_VKEY_F2:
case FWL_VKEY_Tab:
default:
break;
}
- if (MoveCaret != MC_MoveNone)
- m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl);
}
void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) {