diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-09-19 10:07:20 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-19 14:16:31 +0000 |
commit | 0264e97bceaca69d0b0232ac680bd7b26e2db66a (patch) | |
tree | 85ea26e8a518469b74c3db58d5a814c102a3622c /xfa/fwl/cfwl_edit.cpp | |
parent | b02aa61946a62639dd9d39bc00eff6f829b1e414 (diff) | |
download | pdfium-0264e97bceaca69d0b0232ac680bd7b26e2db66a.tar.xz |
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 <dsinclair@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fwl/cfwl_edit.cpp')
-rw-r--r-- | xfa/fwl/cfwl_edit.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
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<CFX_RectF> rects = m_EdtEngine.GetCharacterRectsInRange( - sel_start, sel_end - sel_start + 1); + size_t count; + std::tie(sel_start, count) = m_EdtEngine.GetSelection(); + std::vector<CFX_RectF> 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; } |