summaryrefslogtreecommitdiff
path: root/xfa/fwl
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-19 10:07:20 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-19 14:16:31 +0000
commit0264e97bceaca69d0b0232ac680bd7b26e2db66a (patch)
tree85ea26e8a518469b74c3db58d5a814c102a3622c /xfa/fwl
parentb02aa61946a62639dd9d39bc00eff6f829b1e414 (diff)
downloadpdfium-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')
-rw-r--r--xfa/fwl/cfwl_datetimepicker.h2
-rw-r--r--xfa/fwl/cfwl_edit.cpp31
-rw-r--r--xfa/fwl/cfwl_edit.h2
3 files changed, 19 insertions, 16 deletions
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 <start, end> indices of the selection.
+ // Returns <start, count> of the selection.
std::pair<size_t, size_t> 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<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;
}
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 <start, end> indices of the selection.
+ // Returns <start, count> of the selection.
std::pair<size_t, size_t> GetSelection() const;
int32_t GetLimit() const;