summaryrefslogtreecommitdiff
path: root/fpdfsdk/pwl
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/pwl')
-rw-r--r--fpdfsdk/pwl/cpwl_combo_box.cpp4
-rw-r--r--fpdfsdk/pwl/cpwl_combo_box.h2
-rw-r--r--fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp97
-rw-r--r--fpdfsdk/pwl/cpwl_edit_ctrl.cpp9
-rw-r--r--fpdfsdk/pwl/cpwl_edit_ctrl.h2
-rw-r--r--fpdfsdk/pwl/cpwl_edit_embeddertest.cpp232
-rw-r--r--fpdfsdk/pwl/cpwl_wnd.cpp2
-rw-r--r--fpdfsdk/pwl/cpwl_wnd.h2
8 files changed, 314 insertions, 36 deletions
diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp
index 9514e55646..49254b8171 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box.cpp
@@ -184,9 +184,9 @@ CFX_WideString CPWL_ComboBox::GetSelectedText() {
return CFX_WideString();
}
-void CPWL_ComboBox::DeleteSelectedText() {
+void CPWL_ComboBox::ReplaceSelection(const CFX_WideString& text) {
if (m_pEdit)
- m_pEdit->DeleteSelectedText();
+ m_pEdit->ReplaceSelection(text);
}
CFX_WideString CPWL_ComboBox::GetText() const {
diff --git a/fpdfsdk/pwl/cpwl_combo_box.h b/fpdfsdk/pwl/cpwl_combo_box.h
index a50c4cee37..81e4256e18 100644
--- a/fpdfsdk/pwl/cpwl_combo_box.h
+++ b/fpdfsdk/pwl/cpwl_combo_box.h
@@ -63,7 +63,7 @@ class CPWL_ComboBox : public CPWL_Wnd {
void SetFocus() override;
void KillFocus() override;
CFX_WideString GetSelectedText() override;
- void DeleteSelectedText() override;
+ void ReplaceSelection(const CFX_WideString& text) override;
void SetFillerNotify(IPWL_Filler_Notify* pNotify);
diff --git a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
index 30fe32bc53..308ee4ac40 100644
--- a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
@@ -211,7 +211,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEntireTextSelection) {
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty());
}
@@ -222,7 +222,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionMiddle) {
GetCPWLComboBox()->SetEditSelection(12, 23);
EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetText().c_str());
}
@@ -234,7 +234,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionLeft) {
GetCPWLComboBox()->SetEditSelection(0, 5);
EXPECT_STREQ(L"ABCDE", GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetText().c_str());
}
@@ -246,7 +246,7 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteTextSelectionRight) {
GetCPWLComboBox()->SetEditSelection(45, 50);
EXPECT_STREQ(L"nopqr", GetCPWLComboBox()->GetSelectedText().c_str());
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm",
GetCPWLComboBox()->GetText().c_str());
}
@@ -255,7 +255,94 @@ TEST_F(CPWLComboBoxEditEmbeddertest, DeleteEmptyTextSelection) {
FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
TypeTextIntoTextField(50);
- GetCPWLComboBox()->DeleteSelectedText();
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLComboBox()->GetText().c_str());
}
+
+TEST_F(CPWLComboBoxEditEmbeddertest, InsertTextInEmptyEditableComboBox) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"Hello", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextInPopulatedEditableComboBoxLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ // Move cursor to beginning of user-editable combobox text field.
+ EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotUserEditable(),
+ FWL_VKEY_Home, 0));
+
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"HelloABCDEFGHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextInPopulatedEditableComboBoxMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ // Move cursor to middle of user-editable combobox text field.
+ for (int i = 0; i < 5; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotUserEditable(),
+ FWL_VKEY_Left, 0));
+ }
+
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEHelloFGHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextInPopulatedEditableComboBoxRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEFGHIJHello", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(0, -1);
+ EXPECT_STREQ(L"ABCDEFGHIJ", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"Hello", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(0, 5);
+ EXPECT_STREQ(L"ABCDE", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"HelloFGHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(2, 7);
+ EXPECT_STREQ(L"CDEFG", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABHelloHIJ", GetCPWLComboBox()->GetText().c_str());
+}
+
+TEST_F(CPWLComboBoxEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable());
+ TypeTextIntoTextField(10);
+
+ GetCPWLComboBox()->SetEditSelection(5, 10);
+ EXPECT_STREQ(L"FGHIJ", GetCPWLComboBox()->GetSelectedText().c_str());
+ GetCPWLComboBox()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEHello", GetCPWLComboBox()->GetText().c_str());
+}
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
index a852cb6231..1a7b0e4c49 100644
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
@@ -59,9 +59,12 @@ CFX_WideString CPWL_EditCtrl::GetSelectedText() {
return CFX_WideString();
}
-void CPWL_EditCtrl::DeleteSelectedText() {
- if (m_pEdit)
- m_pEdit->ClearSelection();
+void CPWL_EditCtrl::ReplaceSelection(const CFX_WideString& text) {
+ if (!m_pEdit)
+ return;
+
+ m_pEdit->ClearSelection();
+ m_pEdit->InsertText(text, FX_CHARSET_Default);
}
void CPWL_EditCtrl::RePosChildWnd() {
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.h b/fpdfsdk/pwl/cpwl_edit_ctrl.h
index 4fb86fab62..03dc4be1e1 100644
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.h
+++ b/fpdfsdk/pwl/cpwl_edit_ctrl.h
@@ -61,7 +61,7 @@ class CPWL_EditCtrl : public CPWL_Wnd {
float GetFontSize() const override;
void SetCursor() override;
CFX_WideString GetSelectedText() override;
- void DeleteSelectedText() override;
+ void ReplaceSelection(const CFX_WideString& text) override;
void SetCaret(bool bVisible,
const CFX_PointF& ptHead,
diff --git a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
index 98cc44ab86..34569b2491 100644
--- a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
@@ -24,35 +24,44 @@ class CPWLEditEmbeddertest : public EmbedderTest {
}
void CreateAndInitializeFormPDF() {
- EXPECT_TRUE(OpenDocument("text_form.pdf"));
+ EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
m_page = LoadPage(0);
ASSERT_TRUE(m_page);
- CPDFSDK_FormFillEnvironment* pFormFillEnv =
- static_cast<CPDFSDK_FormFillEnvironment*>(form_handle());
-
- {
- CBA_AnnotIterator iter(pFormFillEnv->GetPageView(0),
- CPDF_Annot::Subtype::WIDGET);
- m_pAnnot = iter.GetFirstAnnot();
- CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot();
- ASSERT_EQ(m_pAnnot, pLastAnnot);
- ASSERT_TRUE(m_pAnnot);
- ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, m_pAnnot->GetAnnotSubtype());
- }
+ m_pFormFillEnv = static_cast<CPDFSDK_FormFillEnvironment*>(form_handle());
+ CBA_AnnotIterator iter(m_pFormFillEnv->GetPageView(0),
+ CPDF_Annot::Subtype::WIDGET);
+ // Normal text field.
+ m_pAnnot = iter.GetFirstAnnot();
+ ASSERT_TRUE(m_pAnnot);
+ ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, m_pAnnot->GetAnnotSubtype());
+
+ // Read-only text field.
+ CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnot);
+
+ // Pre-filled text field with char limit of 10.
+ m_pAnnotCharLimit = iter.GetNextAnnot(pAnnotReadOnly);
+ ASSERT_TRUE(m_pAnnotCharLimit);
+ ASSERT_EQ(CPDF_Annot::Subtype::WIDGET,
+ m_pAnnotCharLimit->GetAnnotSubtype());
+ CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot();
+ ASSERT_EQ(m_pAnnotCharLimit, pLastAnnot);
+ }
+ void FormFillerAndWindowSetup(CPDFSDK_Annot* pAnnotTextField) {
CFFL_InteractiveFormFiller* pInteractiveFormFiller =
- pFormFillEnv->GetInteractiveFormFiller();
+ m_pFormFillEnv->GetInteractiveFormFiller();
{
- CPDFSDK_Annot::ObservedPtr pObserved(m_pAnnot);
+ CPDFSDK_Annot::ObservedPtr pObserved(pAnnotTextField);
EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(&pObserved, 0));
}
- m_pFormFiller = pInteractiveFormFiller->GetFormFiller(m_pAnnot, false);
+ m_pFormFiller =
+ pInteractiveFormFiller->GetFormFiller(pAnnotTextField, false);
ASSERT_TRUE(m_pFormFiller);
CPWL_Wnd* pWindow =
- m_pFormFiller->GetPDFWindow(pFormFillEnv->GetPageView(0), false);
+ m_pFormFiller->GetPDFWindow(m_pFormFillEnv->GetPageView(0), false);
ASSERT_TRUE(pWindow);
ASSERT_EQ(PWL_CLASSNAME_EDIT, pWindow->GetClassName());
@@ -70,15 +79,19 @@ class CPWLEditEmbeddertest : public EmbedderTest {
CPWL_Edit* GetCPWLEdit() { return m_pEdit; }
CFFL_FormFiller* GetCFFLFormFiller() { return m_pFormFiller; }
CPDFSDK_Annot* GetCPDFSDKAnnot() { return m_pAnnot; }
+ CPDFSDK_Annot* GetCPDFSDKAnnotCharLimit() { return m_pAnnotCharLimit; }
private:
FPDF_PAGE m_page;
CPWL_Edit* m_pEdit;
CFFL_FormFiller* m_pFormFiller;
CPDFSDK_Annot* m_pAnnot;
+ CPDFSDK_Annot* m_pAnnotCharLimit;
+ CPDFSDK_FormFillEnvironment* m_pFormFillEnv;
};
TEST_F(CPWLEditEmbeddertest, TypeText) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty());
EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'a', 0));
EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'b', 0));
@@ -88,6 +101,7 @@ TEST_F(CPWLEditEmbeddertest, TypeText) {
}
TEST_F(CPWLEditEmbeddertest, GetSelectedTextEmptyAndBasic) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
// Attempt to set selection before text has been typed to test that
// selection is identified as empty.
//
@@ -104,6 +118,7 @@ TEST_F(CPWLEditEmbeddertest, GetSelectedTextEmptyAndBasic) {
}
TEST_F(CPWLEditEmbeddertest, GetSelectedTextFragments) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
TypeTextIntoTextField(50);
GetCPWLEdit()->SetSelection(0, 0);
@@ -133,53 +148,226 @@ TEST_F(CPWLEditEmbeddertest, GetSelectedTextFragments) {
}
TEST_F(CPWLEditEmbeddertest, DeleteEntireTextSelection) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
TypeTextIntoTextField(50);
GetCPWLEdit()->SetSelection(0, -1);
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLEdit()->GetSelectedText().c_str());
- GetCPWLEdit()->DeleteSelectedText();
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty());
}
TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
TypeTextIntoTextField(50);
GetCPWLEdit()->SetSelection(12, 23);
EXPECT_STREQ(L"MNOPQRSTUVW", GetCPWLEdit()->GetSelectedText().c_str());
- GetCPWLEdit()->DeleteSelectedText();
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLEdit()->GetText().c_str());
}
TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
TypeTextIntoTextField(50);
GetCPWLEdit()->SetSelection(0, 5);
EXPECT_STREQ(L"ABCDE", GetCPWLEdit()->GetSelectedText().c_str());
- GetCPWLEdit()->DeleteSelectedText();
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLEdit()->GetText().c_str());
}
TEST_F(CPWLEditEmbeddertest, DeleteTextSelectionRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
TypeTextIntoTextField(50);
GetCPWLEdit()->SetSelection(45, 50);
EXPECT_STREQ(L"nopqr", GetCPWLEdit()->GetSelectedText().c_str());
- GetCPWLEdit()->DeleteSelectedText();
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm",
GetCPWLEdit()->GetText().c_str());
}
TEST_F(CPWLEditEmbeddertest, DeleteEmptyTextSelection) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
TypeTextIntoTextField(50);
- GetCPWLEdit()->DeleteSelectedText();
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
EXPECT_STREQ(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqr",
GetCPWLEdit()->GetText().c_str());
}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInEmptyTextField) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"Hello", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedTextFieldLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ // Move cursor to beginning of text field.
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnot(), FWL_VKEY_Home, 0));
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"HelloABCDEFGHIJ", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedTextFieldMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ // Move cursor to middle of text field.
+ for (int i = 0; i < 5; ++i) {
+ EXPECT_TRUE(
+ GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnot(), FWL_VKEY_Left, 0));
+ }
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEHelloFGHIJ", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedTextFieldRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEFGHIJHello", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ GetCPWLEdit()->SetSelection(0, -1);
+ EXPECT_STREQ(L"ABCDEFGHIJ", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"Hello", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ GetCPWLEdit()->SetSelection(0, 5);
+ EXPECT_STREQ(L"ABCDE", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"HelloFGHIJ", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ GetCPWLEdit()->SetSelection(2, 7);
+ EXPECT_STREQ(L"CDEFG", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABHelloHIJ", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedTextFieldRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnot());
+ TypeTextIntoTextField(10);
+
+ GetCPWLEdit()->SetSelection(5, 10);
+ EXPECT_STREQ(L"FGHIJ", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hello"));
+ EXPECT_STREQ(L"ABCDEHello", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInEmptyCharLimitTextFieldOverflow) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->SetSelection(0, -1);
+ EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"Hippopotam", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInEmptyCharLimitTextFieldFit) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->SetSelection(0, -1);
+ EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString());
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Zebra"));
+ EXPECT_STREQ(L"Zebra", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedCharLimitTextFieldLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"HiElephant", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedCharLimitTextFieldMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ // Move cursor to middle of text field.
+ for (int i = 0; i < 5; ++i) {
+ EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotCharLimit(),
+ FWL_VKEY_Right, 0));
+ }
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"ElephHiant", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest, InsertTextInPopulatedCharLimitTextFieldRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ // Move cursor to end of text field.
+ EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(GetCPDFSDKAnnotCharLimit(),
+ FWL_VKEY_End, 0));
+
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"ElephantHi", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->SetSelection(0, -1);
+ EXPECT_STREQ(L"Elephant", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"Hippopotam", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->SetSelection(0, 4);
+ EXPECT_STREQ(L"Elep", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"Hippophant", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->SetSelection(2, 6);
+ EXPECT_STREQ(L"epha", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"ElHippopnt", GetCPWLEdit()->GetText().c_str());
+}
+
+TEST_F(CPWLEditEmbeddertest,
+ InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) {
+ FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit());
+ GetCPWLEdit()->SetSelection(4, 8);
+ EXPECT_STREQ(L"hant", GetCPWLEdit()->GetSelectedText().c_str());
+ GetCPWLEdit()->ReplaceSelection(CFX_WideString(L"Hippopotamus"));
+ EXPECT_STREQ(L"ElepHippop", GetCPWLEdit()->GetText().c_str());
+}
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 2269162260..c7bf23ce60 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -369,7 +369,7 @@ CFX_WideString CPWL_Wnd::GetSelectedText() {
return CFX_WideString();
}
-void CPWL_Wnd::DeleteSelectedText() {}
+void CPWL_Wnd::ReplaceSelection(const CFX_WideString& text) {}
bool CPWL_Wnd::OnMouseWheel(short zDelta,
const CFX_PointF& point,
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h
index 7c93216a58..15487a3c07 100644
--- a/fpdfsdk/pwl/cpwl_wnd.h
+++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -202,7 +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 void ReplaceSelection(const CFX_WideString& text);
virtual CFX_FloatRect GetFocusRect() const;
virtual CFX_FloatRect GetClientRect() const;