summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/pdfwindow')
-rw-r--r--fpdfsdk/pdfwindow/cpwl_combo_box.cpp5
-rw-r--r--fpdfsdk/pdfwindow/cpwl_combo_box.h1
-rw-r--r--fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp72
-rw-r--r--fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp5
-rw-r--r--fpdfsdk/pdfwindow/cpwl_edit_ctrl.h1
-rw-r--r--fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp62
-rw-r--r--fpdfsdk/pdfwindow/cpwl_wnd.cpp2
-rw-r--r--fpdfsdk/pdfwindow/cpwl_wnd.h1
8 files changed, 149 insertions, 0 deletions
diff --git a/fpdfsdk/pdfwindow/cpwl_combo_box.cpp b/fpdfsdk/pdfwindow/cpwl_combo_box.cpp
index 8de2f1e733..90c8cc6dc0 100644
--- a/fpdfsdk/pdfwindow/cpwl_combo_box.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_combo_box.cpp
@@ -184,6 +184,11 @@ CFX_WideString CPWL_ComboBox::GetSelectedText() {
return CFX_WideString();
}
+void CPWL_ComboBox::DeleteSelectedText() {
+ if (m_pEdit)
+ m_pEdit->DeleteSelectedText();
+}
+
CFX_WideString CPWL_ComboBox::GetText() const {
if (m_pEdit) {
return m_pEdit->GetText();
diff --git a/fpdfsdk/pdfwindow/cpwl_combo_box.h b/fpdfsdk/pdfwindow/cpwl_combo_box.h
index 12c0fe9878..530ff0a07e 100644
--- a/fpdfsdk/pdfwindow/cpwl_combo_box.h
+++ b/fpdfsdk/pdfwindow/cpwl_combo_box.h
@@ -63,6 +63,7 @@ class CPWL_ComboBox : public CPWL_Wnd {
void SetFocus() override;
void KillFocus() override;
CFX_WideString GetSelectedText() override;
+ void DeleteSelectedText() override;
void SetFillerNotify(IPWL_Filler_Notify* pNotify);
diff --git a/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp b/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp
index 9ca994f2e1..3224284ee2 100644
--- a/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_combo_box_embeddertest.cpp
@@ -194,3 +194,75 @@ TEST_F(CPWLComboBoxEditEmbeddertest, GetSelectedTextFragmentsEditable) {
GetCPWLComboBox()->SetEditSelection(49, 50);
EXPECT_STREQ(L"r", GetCPWLComboBox()->GetSelectedText().c_str());
}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEntireTextSelection) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0));
+ }
+
+ GetCPWLComboBox()->SetEditSelection(0, -1);
+ EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLComboBox()->GetSelectedText().c_str());
+
+ GetCPWLComboBox()->DeleteSelectedText();
+ EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0));
+ }
+
+ GetCPWLComboBox()->SetEditSelection(12, 23);
+ EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLComboBox()->GetSelectedText().c_str());
+
+ GetCPWLComboBox()->DeleteSelectedText();
+ EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0));
+ }
+
+ GetCPWLComboBox()->SetEditSelection(0, 5);
+ EXPECT_STREQ(L"ABCDE", GetCPWLComboBox()->GetSelectedText().c_str());
+
+ GetCPWLComboBox()->DeleteSelectedText();
+ EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0));
+ }
+
+ GetCPWLComboBox()->SetEditSelection(45, 50);
+ EXPECT_STREQ(L"nopqr", GetCPWLComboBox()->GetSelectedText().c_str());
+
+ GetCPWLComboBox()->DeleteSelectedText();
+ EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm",
+ GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEmptyTextSelection) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', 0));
+ }
+
+ GetCPWLComboBox()->DeleteSelectedText();
+ EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLComboBox()->GetText().c_str());
+}
diff --git a/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp
index c7e1f14499..a3aac19e20 100644
--- a/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.cpp
@@ -59,6 +59,11 @@ CFX_WideString CPWL_EditCtrl::GetSelectedText() {
return CFX_WideString();
}
+void CPWL_EditCtrl::DeleteSelectedText() {
+ if (m_pEdit)
+ m_pEdit->ClearSelection();
+}
+
void CPWL_EditCtrl::RePosChildWnd() {
m_pEdit->SetPlateRect(GetClientRect());
}
diff --git a/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h
index ef6989e637..30c2d63419 100644
--- a/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h
+++ b/fpdfsdk/pdfwindow/cpwl_edit_ctrl.h
@@ -61,6 +61,7 @@ class CPWL_EditCtrl : public CPWL_Wnd {
float GetFontSize() const override;
void SetCursor() override;
CFX_WideString GetSelectedText() override;
+ void DeleteSelectedText() override;
void SetCaret(bool bVisible,
const CFX_PointF& ptHead,
diff --git a/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp b/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp
index 9b15ad887d..2b1bbd4445 100644
--- a/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_edit_embeddertest.cpp
@@ -123,3 +123,65 @@ TEST_F(CPWLEditEmbeddertest, GetSelectedTextFragments) {
GetCPWLEdit()->SetSelection(49, 50);
EXPECT_STREQ(L"r", GetCPWLEdit()->GetSelectedText().c_str());
}
+
+TEST_F(CPWLEditEmbeddertest, DeleteEntireTextSelection) {
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0));
+ }
+
+ GetCPWLEdit()->SetSelection(0, -1);
+ EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLEdit()->GetSelectedText().c_str());
+
+ GetCPWLEdit()->DeleteSelectedText();
+ EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty());
+}
+
+TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionMiddle) {
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0));
+ }
+
+ GetCPWLEdit()->SetSelection(12, 23);
+ EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str());
+
+ GetCPWLEdit()->DeleteSelectedText();
+ EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionLeft) {
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0));
+ }
+
+ GetCPWLEdit()->SetSelection(0, 5);
+ EXPECT_STREQ(L"ABCDE", GetCPWLEdit()->GetSelectedText().c_str());
+
+ GetCPWLEdit()->DeleteSelectedText();
+ EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionRight) {
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0));
+ }
+
+ GetCPWLEdit()->SetSelection(45, 50);
+ EXPECT_STREQ(L"nopqr", GetCPWLEdit()->GetSelectedText().c_str());
+
+ GetCPWLEdit()->DeleteSelectedText();
+ EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm",
+ GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, DeleteEmptyTextSelection) {
+ for (int i = 0; i < 50; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), i + 'A', 0));
+ }
+
+ GetCPWLEdit()->DeleteSelectedText();
+ EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
+ GetCPWLEdit()->GetText().c_str());
+}
diff --git a/fpdfsdk/pdfwindow/cpwl_wnd.cpp b/fpdfsdk/pdfwindow/cpwl_wnd.cpp
index 663a763e3c..58824afdbd 100644
--- a/fpdfsdk/pdfwindow/cpwl_wnd.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_wnd.cpp
@@ -369,6 +369,8 @@ CFX_WideString CPWL_Wnd::GetSelectedText() {
return CFX_WideString();
}
+void CPWL_Wnd::DeleteSelectedText() {}
+
bool CPWL_Wnd::OnMouseWheel(short zDelta,
const CFX_PointF& point,
uint32_t nFlag) {
diff --git a/fpdfsdk/pdfwindow/cpwl_wnd.h b/fpdfsdk/pdfwindow/cpwl_wnd.h
index b22c5dba21..d56369cb52 100644
--- a/fpdfsdk/pdfwindow/cpwl_wnd.h
+++ b/fpdfsdk/pdfwindow/cpwl_wnd.h
@@ -202,6 +202,7 @@ class CPWL_Wnd : public CPWL_TimerHandler, public CFX_Observable<CPWL_Wnd> {
virtual float GetFontSize() const;
virtual CFX_WideString GetSelectedText();
+ virtual void DeleteSelectedText();
virtual CFX_FloatRect GetFocusRect() const;
virtual CFX_FloatRect GetClientRect() const;