From eb57e0d0b396606b39ef76a864b8bf9dd91a8ed8 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 6 Sep 2017 11:44:39 -0400 Subject: Implement word selection in CFDE_TextEditEngine This CL implements the needed logic in CFDE_TextEditEngine to handle word selection. Change-Id: I6b388c23655037fec107d68ec07d33638b959374 Reviewed-on: https://pdfium-review.googlesource.com/13211 Commit-Queue: dsinclair Reviewed-by: Ryan Harrison Reviewed-by: Henrique Nakashima --- core/fxcrt/cfx_wordbreak.cpp | 24 ++++++------------------ core/fxcrt/cfx_wordbreak.h | 10 ++++------ 2 files changed, 10 insertions(+), 24 deletions(-) (limited to 'core') diff --git a/core/fxcrt/cfx_wordbreak.cpp b/core/fxcrt/cfx_wordbreak.cpp index 7a5d8f7dcd..86c6d40522 100644 --- a/core/fxcrt/cfx_wordbreak.cpp +++ b/core/fxcrt/cfx_wordbreak.cpp @@ -2779,16 +2779,14 @@ FX_WordBreakProp GetWordBreakProperty(wchar_t wcCodePoint) { } // namespace -CFX_WordBreak::CFX_WordBreak() {} +CFX_WordBreak::CFX_WordBreak(std::unique_ptr pIter) + : m_pCurIter(std::move(pIter)) { + ASSERT(m_pCurIter); +} CFX_WordBreak::~CFX_WordBreak() {} -void CFX_WordBreak::Attach(IFX_CharIter* pIter) { - ASSERT(pIter); - m_pCurIter.reset(pIter); -} - -void CFX_WordBreak::SetAt(int32_t nIndex) { +std::pair CFX_WordBreak::BoundsAt(int32_t nIndex) { m_pPreIter.reset(); m_pCurIter->SetAt(nIndex); FindNextBreakPos(m_pCurIter.get(), true); @@ -2796,18 +2794,8 @@ void CFX_WordBreak::SetAt(int32_t nIndex) { m_pPreIter = std::move(m_pCurIter); m_pCurIter = m_pPreIter->Clone(); FindNextBreakPos(m_pCurIter.get(), false); -} - -int32_t CFX_WordBreak::GetWordPos() const { - return m_pPreIter->GetAt(); -} - -int32_t CFX_WordBreak::GetWordLength() const { - return m_pCurIter->GetAt() - m_pPreIter->GetAt() + 1; -} -bool CFX_WordBreak::IsEOF(bool bTail) const { - return m_pCurIter->IsEOF(bTail); + return {m_pPreIter->GetAt(), m_pCurIter->GetAt()}; } bool CFX_WordBreak::FindNextBreakPos(IFX_CharIter* pIter, bool bPrev) { diff --git a/core/fxcrt/cfx_wordbreak.h b/core/fxcrt/cfx_wordbreak.h index 59c071be03..6e94c71e95 100644 --- a/core/fxcrt/cfx_wordbreak.h +++ b/core/fxcrt/cfx_wordbreak.h @@ -8,22 +8,20 @@ #define CORE_FXCRT_CFX_WORDBREAK_H_ #include +#include class IFX_CharIter; class CFX_WordBreak { public: - CFX_WordBreak(); + explicit CFX_WordBreak(std::unique_ptr pIter); ~CFX_WordBreak(); - void Attach(IFX_CharIter* pIter); - void SetAt(int32_t nIndex); - int32_t GetWordPos() const; - int32_t GetWordLength() const; + // + std::pair BoundsAt(int32_t nIndex); private: bool FindNextBreakPos(IFX_CharIter* pIter, bool bPrev); - bool IsEOF(bool bTail) const; std::unique_ptr m_pPreIter; std::unique_ptr m_pCurIter; -- cgit v1.2.3