From 0264e97bceaca69d0b0232ac680bd7b26e2db66a Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 19 Sep 2017 10:07:20 -0400 Subject: Convert selection to use count instead of end index This CL changes the Text Edit Engine code to use a count instead of an end index for the selection range. Using count lets us differentiate a selection at the beginning of 1 character and an empty selection. A few new tests were added to test unicode word break behaviour, some are not working yet and are commented out. Change-Id: Icce8f5003102ef0a850151ccdf16d3c2226d94bf Reviewed-on: https://pdfium-review.googlesource.com/13491 Commit-Queue: dsinclair Reviewed-by: Henrique Nakashima --- xfa/fwl/cfwl_datetimepicker.h | 2 +- xfa/fwl/cfwl_edit.cpp | 31 +++++++++++++++++-------------- xfa/fwl/cfwl_edit.h | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'xfa/fwl') diff --git a/xfa/fwl/cfwl_datetimepicker.h b/xfa/fwl/cfwl_datetimepicker.h index 276fea451d..97c5cd196e 100644 --- a/xfa/fwl/cfwl_datetimepicker.h +++ b/xfa/fwl/cfwl_datetimepicker.h @@ -53,7 +53,7 @@ class CFWL_DateTimePicker : public CFWL_Widget { WideString GetEditText() const; bool HasSelection() const { return m_pEdit->HasSelection(); } - // Returns indices of the selection. + // Returns of the selection. std::pair GetSelection() const { return m_pEdit->GetSelection(); } diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index 1bec1503fc..426d46e761 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -481,10 +481,10 @@ void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics, bool bShowSel = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); if (bShowSel && m_EdtEngine.HasSelection()) { size_t sel_start; - size_t sel_end; - std::tie(sel_start, sel_end) = m_EdtEngine.GetSelection(); - std::vector rects = m_EdtEngine.GetCharacterRectsInRange( - sel_start, sel_end - sel_start + 1); + size_t count; + std::tie(sel_start, count) = m_EdtEngine.GetSelection(); + std::vector rects = + m_EdtEngine.GetCharacterRectsInRange(sel_start, count); CXFA_Path path; for (auto& rect : rects) { @@ -1237,11 +1237,11 @@ void CFWL_Edit::OnLButtonUp(CFWL_MessageMouse* pMsg) { void CFWL_Edit::OnButtonDoubleClick(CFWL_MessageMouse* pMsg) { size_t click_idx = m_EdtEngine.GetIndexForPoint(DeviceToEngine(pMsg->m_pos)); size_t start_idx; - size_t end_idx; - std::tie(start_idx, end_idx) = m_EdtEngine.BoundsForWordAt(click_idx); + size_t count; + std::tie(start_idx, count) = m_EdtEngine.BoundsForWordAt(click_idx); - m_EdtEngine.SetSelection(start_idx, end_idx); - m_CursorPosition = end_idx; + m_EdtEngine.SetSelection(start_idx, count); + m_CursorPosition = start_idx + count; RepaintRect(m_rtEngine); } @@ -1260,10 +1260,13 @@ void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) { SetCursorPosition(length); size_t sel_start; - size_t sel_end; - std::tie(sel_start, sel_end) = m_EdtEngine.GetSelection(); - m_EdtEngine.SetSelection(std::min(sel_start, m_CursorPosition), - std::max(sel_end, m_CursorPosition)); + 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); } void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) { @@ -1273,8 +1276,8 @@ void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) { size_t sel_start = m_CursorPosition; if (m_EdtEngine.HasSelection()) { size_t start_idx; - size_t end_idx; - std::tie(start_idx, end_idx) = m_EdtEngine.GetSelection(); + size_t count; + std::tie(start_idx, count) = m_EdtEngine.GetSelection(); sel_start = start_idx; } diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h index e85baaaa38..cfebb25146 100644 --- a/xfa/fwl/cfwl_edit.h +++ b/xfa/fwl/cfwl_edit.h @@ -74,7 +74,7 @@ class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate { void SelectAll(); void ClearSelection(); bool HasSelection() const; - // Returns indices of the selection. + // Returns of the selection. std::pair GetSelection() const; int32_t GetLimit() const; -- cgit v1.2.3