From b8777a2c5f38ea4d6fc74ea01a114d3e056c0fdb Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 20 Sep 2017 16:21:31 -0400 Subject: Add embeddertest for CFWL_Edit This CL adds two mouse selection tests for CFWL_Edit. In order to do so the needed selection code was added to the XFA widget handler and plumbed down to the CFWL_Edit field as needed. Bug: pdfium:840 Change-Id: Ia3b5f5d191494a4579c01524df8fb35b24cc0085 Reviewed-on: https://pdfium-review.googlesource.com/14530 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fwl/cfwl_edit.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'xfa/fwl/cfwl_edit.cpp') diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index 426d46e761..d1f0c99a39 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -1120,7 +1120,7 @@ void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { OnMouseMove(pMsg); break; case FWL_MouseCommand::RightButtonDown: - DoButtonDown(pMsg); + DoRButtonDown(pMsg); break; default: break; @@ -1159,17 +1159,11 @@ void CFWL_Edit::OnDrawWidget(CXFA_Graphics* pGraphics, DrawWidget(pGraphics, matrix); } -void CFWL_Edit::DoButtonDown(CFWL_MessageMouse* pMsg) { +void CFWL_Edit::DoRButtonDown(CFWL_MessageMouse* pMsg) { if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) SetFocus(true); - // TODO(dsinclair): Handle DoButtonDown - // bool bBefore = true; - // int32_t nIndex = - // std::max(0, pPage->GetCharIndex(DeviceToEngine(pMsg->m_pos), - // bBefore)); - - // SetCursorPosition(nIndex); + m_CursorPosition = m_EdtEngine.GetIndexForPoint(DeviceToEngine(pMsg->m_pos)); } void CFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { @@ -1206,7 +1200,9 @@ void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) { m_bLButtonDown = true; SetGrab(true); - DoButtonDown(pMsg); + + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + SetFocus(true); bool bRepaint = false; if (m_EdtEngine.HasSelection()) { @@ -1216,13 +1212,16 @@ void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) { size_t index_at_click = m_EdtEngine.GetIndexForPoint(DeviceToEngine(pMsg->m_pos)); + if (index_at_click != m_CursorPosition && !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift)) { size_t start = std::min(m_CursorPosition, index_at_click); size_t end = std::max(m_CursorPosition, index_at_click); - m_EdtEngine.SetSelection(start, end); + m_EdtEngine.SetSelection(start, end - start); bRepaint = true; + } else { + m_CursorPosition = index_at_click; } if (bRepaint) @@ -1259,14 +1258,16 @@ void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) { if (m_CursorPosition > length) SetCursorPosition(length); - size_t sel_start; - size_t count; - std::tie(sel_start, count) = m_EdtEngine.GetSelection(); - size_t original_end = sel_start + count; - sel_start = std::min(sel_start, m_CursorPosition); - m_EdtEngine.SetSelection( - std::min(sel_start, m_CursorPosition), - std::max(original_end, m_CursorPosition) - sel_start); + size_t sel_start = 0; + size_t count = 0; + if (m_EdtEngine.HasSelection()) + std::tie(sel_start, count) = m_EdtEngine.GetSelection(); + else + sel_start = old_cursor_pos; + + size_t start_pos = std::min(sel_start, m_CursorPosition); + size_t end_pos = std::max(sel_start, m_CursorPosition); + m_EdtEngine.SetSelection(start_pos, end_pos - start_pos); } void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) { -- cgit v1.2.3