summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp15
-rw-r--r--core/fpdfdoc/cpvt_wordplace.h80
-rw-r--r--core/fpdfdoc/cpvt_wordrange.h38
-rw-r--r--core/fpdfdoc/csection.cpp6
-rw-r--r--fpdfsdk/fxedit/fxet_edit.cpp493
-rw-r--r--fpdfsdk/fxedit/fxet_edit.h4
-rw-r--r--fpdfsdk/pdfwindow/PWL_Edit.cpp18
-rw-r--r--fpdfsdk/pdfwindow/PWL_Utils.cpp25
8 files changed, 310 insertions, 369 deletions
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 24dd9b065d..4e46969dc4 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -432,9 +432,7 @@ void CPDF_VariableText::SetText(const CFX_WideString& swText) {
if (swText.GetAt(i + 1) == 0x0A)
i += 1;
- wp.nSecIndex++;
- wp.nLineIndex = 0;
- wp.nWordIndex = -1;
+ wp.AdvanceSection();
AddSection(wp, secinfo);
}
break;
@@ -443,9 +441,7 @@ void CPDF_VariableText::SetText(const CFX_WideString& swText) {
if (swText.GetAt(i + 1) == 0x0D)
i += 1;
- wp.nSecIndex++;
- wp.nLineIndex = 0;
- wp.nWordIndex = -1;
+ wp.AdvanceSection();
AddSection(wp, secinfo);
}
break;
@@ -537,7 +533,7 @@ CPVT_WordPlace CPDF_VariableText::GetPrevWordPlace(
return GetEndWordPlace();
CSection* pSection = m_SectionArray[place.nSecIndex].get();
- if (place.WordCmp(pSection->GetBeginWordPlace()) > 0)
+ if (place > pSection->GetBeginWordPlace())
return pSection->GetPrevWordPlace(place);
if (!pdfium::IndexInBounds(m_SectionArray, place.nSecIndex - 1))
return GetBeginWordPlace();
@@ -552,7 +548,7 @@ CPVT_WordPlace CPDF_VariableText::GetNextWordPlace(
return GetEndWordPlace();
CSection* pSection = m_SectionArray[place.nSecIndex].get();
- if (place.WordCmp(pSection->GetEndWordPlace()) < 0)
+ if (place < pSection->GetEndWordPlace())
return pSection->GetNextWordPlace(place);
if (!pdfium::IndexInBounds(m_SectionArray, place.nSecIndex + 1))
return GetEndWordPlace();
@@ -638,8 +634,7 @@ CPVT_WordPlace CPDF_VariableText::GetDownWordPlace(
return pSection->SearchWordPlace(pt.x - pSection->m_SecInfo.rcSection.left,
temp);
}
- ++temp.nSecIndex;
- temp.nLineIndex = 0;
+ temp.AdvanceSection();
if (!pdfium::IndexInBounds(m_SectionArray, temp.nSecIndex))
return place;
diff --git a/core/fpdfdoc/cpvt_wordplace.h b/core/fpdfdoc/cpvt_wordplace.h
index f4a6b087b9..c0a1a9cd5c 100644
--- a/core/fpdfdoc/cpvt_wordplace.h
+++ b/core/fpdfdoc/cpvt_wordplace.h
@@ -14,55 +14,55 @@ struct CPVT_WordPlace {
CPVT_WordPlace(int32_t other_nSecIndex,
int32_t other_nLineIndex,
- int32_t other_nWordIndex) {
- nSecIndex = other_nSecIndex;
- nLineIndex = other_nLineIndex;
- nWordIndex = other_nWordIndex;
+ int32_t other_nWordIndex)
+ : nSecIndex(other_nSecIndex),
+ nLineIndex(other_nLineIndex),
+ nWordIndex(other_nWordIndex) {}
+
+ void Reset() {
+ nSecIndex = -1;
+ nLineIndex = -1;
+ nWordIndex = -1;
}
- void Default() { nSecIndex = nLineIndex = nWordIndex = -1; }
+ void AdvanceSection() {
+ nSecIndex++;
+ nLineIndex = 0;
+ nWordIndex = -1;
+ }
- bool operator==(const CPVT_WordPlace& wp) const {
+ inline bool operator==(const CPVT_WordPlace& wp) const {
return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex &&
wp.nWordIndex == nWordIndex;
}
-
- bool operator!=(const CPVT_WordPlace& wp) const { return !(*this == wp); }
-
- inline int32_t WordCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex > wp.nSecIndex)
- return 1;
- if (nSecIndex < wp.nSecIndex)
- return -1;
- if (nLineIndex > wp.nLineIndex)
- return 1;
- if (nLineIndex < wp.nLineIndex)
- return -1;
- if (nWordIndex > wp.nWordIndex)
- return 1;
- if (nWordIndex < wp.nWordIndex)
- return -1;
- return 0;
+ inline bool operator!=(const CPVT_WordPlace& wp) const {
+ return !(*this == wp);
}
-
- inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex > wp.nSecIndex)
- return 1;
- if (nSecIndex < wp.nSecIndex)
- return -1;
- if (nLineIndex > wp.nLineIndex)
- return 1;
- if (nLineIndex < wp.nLineIndex)
- return -1;
- return 0;
+ inline bool operator<(const CPVT_WordPlace& wp) const {
+ if (nSecIndex != wp.nSecIndex)
+ return nSecIndex < wp.nSecIndex;
+ if (nLineIndex != wp.nLineIndex)
+ return nLineIndex < wp.nLineIndex;
+ return nWordIndex < wp.nWordIndex;
+ }
+ inline bool operator>(const CPVT_WordPlace& wp) const {
+ if (nSecIndex != wp.nSecIndex)
+ return nSecIndex > wp.nSecIndex;
+ if (nLineIndex != wp.nLineIndex)
+ return nLineIndex > wp.nLineIndex;
+ return nWordIndex > wp.nWordIndex;
+ }
+ inline bool operator<=(const CPVT_WordPlace& wp) const {
+ return *this < wp || *this == wp;
+ }
+ inline bool operator>=(const CPVT_WordPlace& wp) const {
+ return *this > wp || *this == wp;
}
- inline int32_t SecCmp(const CPVT_WordPlace& wp) const {
- if (nSecIndex > wp.nSecIndex)
- return 1;
- if (nSecIndex < wp.nSecIndex)
- return -1;
- return 0;
+ inline int32_t LineCmp(const CPVT_WordPlace& wp) const {
+ if (nSecIndex != wp.nSecIndex)
+ return nSecIndex - wp.nSecIndex;
+ return nLineIndex - wp.nLineIndex;
}
int32_t nSecIndex;
diff --git a/core/fpdfdoc/cpvt_wordrange.h b/core/fpdfdoc/cpvt_wordrange.h
index b291e50e53..ed06d6f0de 100644
--- a/core/fpdfdoc/cpvt_wordrange.h
+++ b/core/fpdfdoc/cpvt_wordrange.h
@@ -7,49 +7,51 @@
#ifndef CORE_FPDFDOC_CPVT_WORDRANGE_H_
#define CORE_FPDFDOC_CPVT_WORDRANGE_H_
+#include <utility>
+
#include "core/fpdfdoc/cpvt_wordplace.h"
#include "core/fxcrt/fx_system.h"
struct CPVT_WordRange {
CPVT_WordRange() {}
- CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) {
- Set(begin, end);
+ CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end)
+ : BeginPos(begin), EndPos(end) {
+ Normalize();
}
- void Default() {
- BeginPos.Default();
- EndPos.Default();
+ void Reset() {
+ BeginPos.Reset();
+ EndPos.Reset();
}
void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) {
BeginPos = begin;
EndPos = end;
- SwapWordPlace();
+ Normalize();
}
void SetBeginPos(const CPVT_WordPlace& begin) {
BeginPos = begin;
- SwapWordPlace();
+ Normalize();
}
void SetEndPos(const CPVT_WordPlace& end) {
EndPos = end;
- SwapWordPlace();
+ Normalize();
}
- bool IsExist() const { return BeginPos != EndPos; }
-
- bool operator!=(const CPVT_WordRange& wr) const {
- return wr.BeginPos != BeginPos || wr.EndPos != EndPos;
+ inline bool IsEmpty() const { return BeginPos == EndPos; }
+ inline bool operator==(const CPVT_WordRange& wr) const {
+ return wr.BeginPos == BeginPos && wr.EndPos == EndPos;
+ }
+ inline bool operator!=(const CPVT_WordRange& wr) const {
+ return !(*this == wr);
}
- void SwapWordPlace() {
- if (BeginPos.WordCmp(EndPos) > 0) {
- CPVT_WordPlace place = EndPos;
- EndPos = BeginPos;
- BeginPos = place;
- }
+ void Normalize() {
+ if (BeginPos > EndPos)
+ std::swap(BeginPos, EndPos);
}
CPVT_WordPlace BeginPos;
diff --git a/core/fpdfdoc/csection.cpp b/core/fpdfdoc/csection.cpp
index 6198d780fd..b6f45a274c 100644
--- a/core/fpdfdoc/csection.cpp
+++ b/core/fpdfdoc/csection.cpp
@@ -237,14 +237,14 @@ void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) {
void CSection::ClearWords(const CPVT_WordRange& PlaceRange) {
CPVT_WordPlace SecBeginPos = GetBeginWordPlace();
CPVT_WordPlace SecEndPos = GetEndWordPlace();
- if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) {
- if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
+ if (PlaceRange.BeginPos >= SecBeginPos) {
+ if (PlaceRange.EndPos <= SecEndPos) {
ClearMidWords(PlaceRange.BeginPos.nWordIndex,
PlaceRange.EndPos.nWordIndex);
} else {
ClearRightWords(PlaceRange.BeginPos.nWordIndex);
}
- } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
+ } else if (PlaceRange.EndPos <= SecEndPos) {
ClearLeftWords(PlaceRange.EndPos.nWordIndex);
} else {
m_WordArray.clear();
diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp
index 0a5c3d940f..20f584e183 100644
--- a/fpdfsdk/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/fxedit/fxet_edit.cpp
@@ -459,23 +459,24 @@ CFXEU_Backspace::CFXEU_Backspace(CFX_Edit* pEdit,
CFXEU_Backspace::~CFXEU_Backspace() {}
void CFXEU_Backspace::Redo() {
- if (m_pEdit) {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpOld);
- m_pEdit->Backspace(false, true);
- }
+ if (!m_pEdit)
+ return;
+
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpOld);
+ m_pEdit->Backspace(false, true);
}
void CFXEU_Backspace::Undo() {
- if (m_pEdit) {
- m_pEdit->SelectNone();
- m_pEdit->SetCaret(m_wpNew);
- if (m_wpNew.SecCmp(m_wpOld) != 0) {
- m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, false, true);
- } else {
- m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, false, true);
- }
- }
+ if (!m_pEdit)
+ return;
+
+ m_pEdit->SelectNone();
+ m_pEdit->SetCaret(m_wpNew);
+ if (m_wpNew.nSecIndex != m_wpOld.nSecIndex)
+ m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, false, true);
+ else
+ m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, false, true);
}
CFXEU_Delete::CFXEU_Delete(CFX_Edit* pEdit,
@@ -591,7 +592,7 @@ CFX_ByteString CFX_Edit::GetEditAppearanceStream(CFX_Edit* pEdit,
while (pIterator->NextWord()) {
CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0)
+ if (pRange && place > pRange->EndPos)
break;
if (bContinuous) {
@@ -689,7 +690,7 @@ CFX_ByteString CFX_Edit::GetSelectAppearanceStream(
CFX_Edit* pEdit,
const CFX_PointF& ptOffset,
const CPVT_WordRange* pRange) {
- if (!pRange || !pRange->IsExist())
+ if (!pRange || pRange->IsEmpty())
return CFX_ByteString();
CFX_Edit_Iterator* pIterator = pEdit->GetIterator();
@@ -698,7 +699,7 @@ CFX_ByteString CFX_Edit::GetSelectAppearanceStream(
CFX_ByteTextBuf sRet;
while (pIterator->NextWord()) {
CPVT_WordPlace place = pIterator->GetAt();
- if (place.WordCmp(pRange->EndPos) > 0)
+ if (place > pRange->EndPos)
break;
CPVT_Word word;
@@ -757,12 +758,11 @@ void CFX_Edit::DrawEdit(CFX_RenderDevice* pDevice,
CPVT_WordPlace oldplace;
while (pIterator->NextWord()) {
CPVT_WordPlace place = pIterator->GetAt();
- if (pRange && place.WordCmp(pRange->EndPos) > 0)
+ if (pRange && place > pRange->EndPos)
break;
- if (wrSelect.IsExist()) {
- bSelect = place.WordCmp(wrSelect.BeginPos) > 0 &&
- place.WordCmp(wrSelect.EndPos) <= 0;
+ if (!wrSelect.IsEmpty()) {
+ bSelect = place > wrSelect.BeginPos && place <= wrSelect.EndPos;
crCurFill = bSelect ? crWhite : crTextFill;
}
if (pSystemHandler && pSystemHandler->IsSelectionImplemented()) {
@@ -980,42 +980,36 @@ void CFX_Edit::SetSel(int32_t nStartChar, int32_t nEndChar) {
}
void CFX_Edit::SetSel(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) {
- if (m_pVT->IsValid()) {
- SelectNone();
-
- m_SelState.Set(begin, end);
-
- SetCaret(m_SelState.EndPos);
+ if (!m_pVT->IsValid())
+ return;
- if (m_SelState.IsExist()) {
- ScrollToCaret();
- Refresh();
- SetCaretInfo();
- } else {
- ScrollToCaret();
- SetCaretInfo();
- }
- }
+ SelectNone();
+ m_SelState.Set(begin, end);
+ SetCaret(m_SelState.EndPos);
+ ScrollToCaret();
+ if (!m_SelState.IsEmpty())
+ Refresh();
+ SetCaretInfo();
}
void CFX_Edit::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
nStartChar = -1;
nEndChar = -1;
+ if (!m_pVT->IsValid())
+ return;
- if (m_pVT->IsValid()) {
- if (m_SelState.IsExist()) {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
- } else {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
- }
- } else {
- nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
- nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
- }
+ if (m_SelState.IsEmpty()) {
+ nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
+ nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
+ return;
}
+ if (m_SelState.BeginPos < m_SelState.EndPos) {
+ nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
+ nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
+ return;
+ }
+ nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
+ nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
}
int32_t CFX_Edit::GetCaret() const {
@@ -1031,7 +1025,6 @@ CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const {
CFX_WideString CFX_Edit::GetText() const {
CFX_WideString swRet;
-
if (!m_pVT->IsValid())
return swRet;
@@ -1042,22 +1035,17 @@ CFX_WideString CFX_Edit::GetText() const {
CPVT_WordPlace oldplace = pIterator->GetAt();
while (pIterator->NextWord()) {
CPVT_WordPlace place = pIterator->GetAt();
-
if (pIterator->GetWord(wordinfo))
swRet += wordinfo.Word;
-
- if (oldplace.SecCmp(place) != 0)
+ if (oldplace.nSecIndex != place.nSecIndex)
swRet += L"\r\n";
-
oldplace = place;
}
-
return swRet;
}
CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const {
CFX_WideString swRet;
-
if (!m_pVT->IsValid())
return swRet;
@@ -1071,18 +1059,14 @@ CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const {
CPVT_WordPlace oldplace = wrTemp.BeginPos;
while (pIterator->NextWord()) {
CPVT_WordPlace place = pIterator->GetAt();
- if (place.WordCmp(wrTemp.EndPos) > 0)
+ if (place > wrTemp.EndPos)
break;
-
if (pIterator->GetWord(wordinfo))
swRet += wordinfo.Word;
-
- if (oldplace.SecCmp(place) != 0)
+ if (oldplace.nSecIndex != place.nSecIndex)
swRet += L"\r\n";
-
oldplace = place;
}
-
return swRet;
}
@@ -1242,27 +1226,25 @@ void CFX_Edit::SetContentChanged() {
}
void CFX_Edit::SelectAll() {
- if (m_pVT->IsValid()) {
- m_SelState = CFX_Edit_Select(GetWholeWordRange());
- SetCaret(m_SelState.EndPos);
-
- ScrollToCaret();
- Refresh();
- SetCaretInfo();
- }
+ if (!m_pVT->IsValid())
+ return;
+ m_SelState = CFX_Edit_Select(GetWholeWordRange());
+ SetCaret(m_SelState.EndPos);
+ ScrollToCaret();
+ Refresh();
+ SetCaretInfo();
}
void CFX_Edit::SelectNone() {
- if (m_pVT->IsValid()) {
- if (m_SelState.IsExist()) {
- m_SelState.Default();
- Refresh();
- }
- }
+ if (!m_pVT->IsValid() || m_SelState.IsEmpty())
+ return;
+
+ m_SelState.Reset();
+ Refresh();
}
bool CFX_Edit::IsSelected() const {
- return m_SelState.IsExist();
+ return !m_SelState.IsEmpty();
}
CFX_PointF CFX_Edit::VTToEdit(const CFX_PointF& point) const {
@@ -1520,12 +1502,11 @@ void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) {
while (pIterator->NextWord()) {
place = pIterator->GetAt();
- if (place.WordCmp(wrTemp.EndPos) > 0)
+ if (place > wrTemp.EndPos)
break;
pIterator->GetWord(wordinfo);
pIterator->GetLine(lineinfo);
-
if (place.LineCmp(wrTemp.BeginPos) == 0 ||
place.LineCmp(wrTemp.EndPos) == 0) {
CFX_FloatRect rcWord(wordinfo.ptWord.x,
@@ -1589,7 +1570,7 @@ void CFX_Edit::SetCaretInfo() {
}
m_bNotifyFlag = true;
- m_pNotify->IOnSetCaret(!m_SelState.IsExist(), VTToEdit(ptHead),
+ m_pNotify->IOnSetCaret(m_SelState.IsEmpty(), VTToEdit(ptHead),
VTToEdit(ptFoot), m_wpCaret);
m_bNotifyFlag = false;
}
@@ -1597,256 +1578,246 @@ void CFX_Edit::SetCaretInfo() {
}
void CFX_Edit::SetCaret(int32_t nPos) {
- if (m_pVT->IsValid()) {
- SelectNone();
- SetCaret(m_pVT->WordIndexToWordPlace(nPos));
- m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (!m_pVT->IsValid())
+ return;
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
+ SelectNone();
+ SetCaret(m_pVT->WordIndexToWordPlace(nPos));
+ m_SelState.Set(m_wpCaret, m_wpCaret);
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
}
void CFX_Edit::OnMouseDown(const CFX_PointF& point, bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- SelectNone();
- SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
- m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (!m_pVT->IsValid())
+ return;
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
+ SelectNone();
+ SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
+ m_SelState.Set(m_wpCaret, m_wpCaret);
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
}
void CFX_Edit::OnMouseMove(const CFX_PointF& point, bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
+ if (!m_pVT->IsValid())
+ return;
- if (m_wpCaret != m_wpOldCaret) {
- m_SelState.SetEndPos(m_wpCaret);
+ SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
+ if (m_wpCaret == m_wpOldCaret)
+ return;
- ScrollToCaret();
- Refresh();
- SetCaretOrigin();
- SetCaretInfo();
- }
- }
+ m_SelState.SetEndPos(m_wpCaret);
+ ScrollToCaret();
+ Refresh();
+ SetCaretOrigin();
+ SetCaretInfo();
}
void CFX_Edit::OnVK_UP(bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- SetCaret(m_pVT->GetUpWordPlace(m_wpCaret, m_ptCaret));
-
- if (bShift) {
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ if (!m_pVT->IsValid())
+ return;
- if (m_wpOldCaret != m_wpCaret) {
- ScrollToCaret();
- Refresh();
- SetCaretInfo();
- }
- } else {
- SelectNone();
+ SetCaret(m_pVT->GetUpWordPlace(m_wpCaret, m_ptCaret));
+ if (bShift) {
+ if (m_SelState.IsEmpty())
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ else
+ m_SelState.SetEndPos(m_wpCaret);
+ if (m_wpOldCaret != m_wpCaret) {
ScrollToCaret();
+ Refresh();
SetCaretInfo();
}
+ } else {
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
}
}
void CFX_Edit::OnVK_DOWN(bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- SetCaret(m_pVT->GetDownWordPlace(m_wpCaret, m_ptCaret));
-
- if (bShift) {
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ if (!m_pVT->IsValid())
+ return;
- if (m_wpOldCaret != m_wpCaret) {
- ScrollToCaret();
- Refresh();
- SetCaretInfo();
- }
- } else {
- SelectNone();
+ SetCaret(m_pVT->GetDownWordPlace(m_wpCaret, m_ptCaret));
+ if (bShift) {
+ if (m_SelState.IsEmpty())
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ else
+ m_SelState.SetEndPos(m_wpCaret);
+ if (m_wpOldCaret != m_wpCaret) {
ScrollToCaret();
+ Refresh();
SetCaretInfo();
}
+ } else {
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
}
}
void CFX_Edit::OnVK_LEFT(bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- if (bShift) {
- if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
- SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+ if (!m_pVT->IsValid())
+ return;
+ if (bShift) {
+ if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) {
SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+ }
+ SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+ if (m_SelState.IsEmpty())
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ else
+ m_SelState.SetEndPos(m_wpCaret);
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
+ if (m_wpOldCaret != m_wpCaret) {
+ ScrollToCaret();
+ Refresh();
+ SetCaretInfo();
+ }
+ } else {
+ if (!m_SelState.IsEmpty()) {
+ if (m_SelState.BeginPos < m_SelState.EndPos)
+ SetCaret(m_SelState.BeginPos);
else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ SetCaret(m_SelState.EndPos);
- if (m_wpOldCaret != m_wpCaret) {
- ScrollToCaret();
- Refresh();
- SetCaretInfo();
- }
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
} else {
- if (m_SelState.IsExist()) {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- } else {
- if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
- SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
-
+ if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) {
SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
}
+ SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
}
}
}
void CFX_Edit::OnVK_RIGHT(bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- if (bShift) {
+ if (!m_pVT->IsValid())
+ return;
+
+ if (bShift) {
+ SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+ if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
- if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
- SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+ if (m_SelState.IsEmpty())
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ else
+ m_SelState.SetEndPos(m_wpCaret);
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
+ if (m_wpOldCaret != m_wpCaret) {
+ ScrollToCaret();
+ Refresh();
+ SetCaretInfo();
+ }
+ } else {
+ if (!m_SelState.IsEmpty()) {
+ if (m_SelState.BeginPos > m_SelState.EndPos)
+ SetCaret(m_SelState.BeginPos);
else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ SetCaret(m_SelState.EndPos);
- if (m_wpOldCaret != m_wpCaret) {
- ScrollToCaret();
- Refresh();
- SetCaretInfo();
- }
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
} else {
- if (m_SelState.IsExist()) {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- } else {
+ SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
+ if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
+ m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) {
SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
-
- if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
- m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
- SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
}
+ ScrollToCaret();
+ SetCaretOrigin();
+ SetCaretInfo();
}
}
}
void CFX_Edit::OnVK_HOME(bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- if (bShift) {
+ if (!m_pVT->IsValid())
+ return;
+
+ if (bShift) {
+ if (bCtrl)
+ SetCaret(m_pVT->GetBeginWordPlace());
+ else
+ SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
+
+ if (m_SelState.IsEmpty())
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ else
+ m_SelState.SetEndPos(m_wpCaret);
+
+ ScrollToCaret();
+ Refresh();
+ SetCaretInfo();
+ } else {
+ if (!m_SelState.IsEmpty()) {
+ SetCaret(std::min(m_SelState.BeginPos, m_SelState.EndPos));
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
+ } else {
if (bCtrl)
SetCaret(m_pVT->GetBeginWordPlace());
else
SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
-
ScrollToCaret();
- Refresh();
+ SetCaretOrigin();
SetCaretInfo();
- } else {
- if (m_SelState.IsExist()) {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- } else {
- if (bCtrl)
- SetCaret(m_pVT->GetBeginWordPlace());
- else
- SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
}
}
}
void CFX_Edit::OnVK_END(bool bShift, bool bCtrl) {
- if (m_pVT->IsValid()) {
- if (bShift) {
+ if (!m_pVT->IsValid())
+ return;
+
+ if (bShift) {
+ if (bCtrl)
+ SetCaret(m_pVT->GetEndWordPlace());
+ else
+ SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
+
+ if (m_SelState.IsEmpty())
+ m_SelState.Set(m_wpOldCaret, m_wpCaret);
+ else
+ m_SelState.SetEndPos(m_wpCaret);
+
+ ScrollToCaret();
+ Refresh();
+ SetCaretInfo();
+ } else {
+ if (!m_SelState.IsEmpty()) {
+ SetCaret(std::max(m_SelState.BeginPos, m_SelState.EndPos));
+ SelectNone();
+ ScrollToCaret();
+ SetCaretInfo();
+ } else {
if (bCtrl)
SetCaret(m_pVT->GetEndWordPlace());
else
SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
- if (m_SelState.IsExist())
- m_SelState.SetEndPos(m_wpCaret);
- else
- m_SelState.Set(m_wpOldCaret, m_wpCaret);
-
ScrollToCaret();
- Refresh();
+ SetCaretOrigin();
SetCaretInfo();
- } else {
- if (m_SelState.IsExist()) {
- if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0)
- SetCaret(m_SelState.BeginPos);
- else
- SetCaret(m_SelState.EndPos);
-
- SelectNone();
- ScrollToCaret();
- SetCaretInfo();
- } else {
- if (bCtrl)
- SetCaret(m_pVT->GetEndWordPlace());
- else
- SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
-
- ScrollToCaret();
- SetCaretOrigin();
- SetCaretInfo();
- }
}
}
}
@@ -1928,7 +1899,7 @@ bool CFX_Edit::Backspace(bool bAddUndo, bool bPaint) {
return false;
if (bAddUndo && m_bEnableUndo) {
- if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) {
+ if (m_wpCaret.nSecIndex != m_wpOldCaret.nSecIndex) {
AddEditUndoItem(pdfium::MakeUnique<CFXEU_Backspace>(
this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
section.SecProps, section.WordProps));
@@ -2003,7 +1974,7 @@ bool CFX_Edit::Empty() {
}
bool CFX_Edit::Clear(bool bAddUndo, bool bPaint) {
- if (!m_pVT->IsValid() || !m_SelState.IsExist())
+ if (!m_pVT->IsValid() || m_SelState.IsEmpty())
return false;
CPVT_WordRange range = m_SelState.ConvertToWordRange();
@@ -2255,9 +2226,9 @@ CPVT_WordRange CFX_Edit_Select::ConvertToWordRange() const {
return CPVT_WordRange(BeginPos, EndPos);
}
-void CFX_Edit_Select::Default() {
- BeginPos.Default();
- EndPos.Default();
+void CFX_Edit_Select::Reset() {
+ BeginPos.Reset();
+ EndPos.Reset();
}
void CFX_Edit_Select::Set(const CPVT_WordPlace& begin,
@@ -2274,8 +2245,8 @@ void CFX_Edit_Select::SetEndPos(const CPVT_WordPlace& end) {
EndPos = end;
}
-bool CFX_Edit_Select::IsExist() const {
- return BeginPos != EndPos;
+bool CFX_Edit_Select::IsEmpty() const {
+ return BeginPos == EndPos;
}
CFX_Edit_RectArray::CFX_Edit_RectArray() {}
diff --git a/fpdfsdk/fxedit/fxet_edit.h b/fpdfsdk/fxedit/fxet_edit.h
index 4fcb5569c3..08a13a87bd 100644
--- a/fpdfsdk/fxedit/fxet_edit.h
+++ b/fpdfsdk/fxedit/fxet_edit.h
@@ -90,13 +90,13 @@ class CFX_Edit_Select {
CFX_Edit_Select(const CPVT_WordPlace& begin, const CPVT_WordPlace& end);
explicit CFX_Edit_Select(const CPVT_WordRange& range);
- void Default();
+ void Reset();
void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end);
void SetBeginPos(const CPVT_WordPlace& begin);
void SetEndPos(const CPVT_WordPlace& end);
CPVT_WordRange ConvertToWordRange() const;
- bool IsExist() const;
+ bool IsEmpty() const;
CPVT_WordPlace BeginPos;
CPVT_WordPlace EndPos;
diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp
index f84c38e23b..4b9e0d2f49 100644
--- a/fpdfsdk/pdfwindow/PWL_Edit.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp
@@ -6,6 +6,7 @@
#include "fpdfsdk/pdfwindow/PWL_Edit.h"
+#include <algorithm>
#include <memory>
#include <vector>
@@ -791,21 +792,8 @@ void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
const CPVT_WordRange& wr2) {
- CPVT_WordRange wrRet;
-
- if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
- wrRet.BeginPos = wr1.BeginPos;
- } else {
- wrRet.BeginPos = wr2.BeginPos;
- }
-
- if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
- wrRet.EndPos = wr2.EndPos;
- } else {
- wrRet.EndPos = wr1.EndPos;
- }
-
- return wrRet;
+ return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos),
+ std::max(wr1.EndPos, wr2.EndPos));
}
CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
diff --git a/fpdfsdk/pdfwindow/PWL_Utils.cpp b/fpdfsdk/pdfwindow/PWL_Utils.cpp
index f78b590150..08b5e3013a 100644
--- a/fpdfsdk/pdfwindow/PWL_Utils.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Utils.cpp
@@ -26,28 +26,13 @@ CFX_FloatRect CPWL_Utils::OffsetRect(const CFX_FloatRect& rect,
CPVT_WordRange CPWL_Utils::OverlapWordRange(const CPVT_WordRange& wr1,
const CPVT_WordRange& wr2) {
- CPVT_WordRange wrRet;
-
- if (wr2.EndPos.WordCmp(wr1.BeginPos) < 0 ||
- wr2.BeginPos.WordCmp(wr1.EndPos) > 0)
- return wrRet;
- if (wr1.EndPos.WordCmp(wr2.BeginPos) < 0 ||
- wr1.BeginPos.WordCmp(wr2.EndPos) > 0)
- return wrRet;
-
- if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
- wrRet.BeginPos = wr2.BeginPos;
- } else {
- wrRet.BeginPos = wr1.BeginPos;
+ if (wr2.EndPos < wr1.BeginPos || wr2.BeginPos > wr1.EndPos ||
+ wr1.EndPos < wr2.BeginPos || wr1.BeginPos > wr2.EndPos) {
+ return CPVT_WordRange();
}
- if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
- wrRet.EndPos = wr1.EndPos;
- } else {
- wrRet.EndPos = wr2.EndPos;
- }
-
- return wrRet;
+ return CPVT_WordRange(std::max(wr1.BeginPos, wr2.BeginPos),
+ std::min(wr1.EndPos, wr2.EndPos));
}
CFX_ByteString CPWL_Utils::GetAP_Check(const CFX_FloatRect& crBBox) {