summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-17 20:32:41 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-17 20:32:41 +0000
commita37989fe53097e4a0b6e87eb6ba01def1e13b675 (patch)
tree9267a150f8d58d96dc7e8448b235eda8561de75d /fpdfsdk
parent5ae6c564d16ce8b625df3d1950abc822f9ecc987 (diff)
downloadpdfium-a37989fe53097e4a0b6e87eb6ba01def1e13b675.tar.xz
Add FORM_OnLButtonDoubleClick().
The code for this already exists, but is not hooked up to a public API. Hook it up and add a test case. Change-Id: I2ebc8492d8b7347849ff06f664155c6d72ecf76f Reviewed-on: https://pdfium-review.googlesource.com/c/44130 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_annothandlermgr.cpp10
-rw-r--r--fpdfsdk/cpdfsdk_annothandlermgr.h4
-rw-r--r--fpdfsdk/cpdfsdk_pageview.cpp48
-rw-r--r--fpdfsdk/cpdfsdk_pageview.h1
-rw-r--r--fpdfsdk/fpdf_formfill.cpp16
-rw-r--r--fpdfsdk/fpdf_formfill_embeddertest.cpp23
-rw-r--r--fpdfsdk/fpdf_view_c_api_test.c1
7 files changed, 89 insertions, 14 deletions
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index ac22fe2d7b..7d253c8709 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -145,6 +145,16 @@ bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(
->OnLButtonUp(pPageView, pAnnot, nFlags, point);
}
+bool CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
+ CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot::ObservedPtr* pAnnot,
+ uint32_t nFlags,
+ const CFX_PointF& point) {
+ ASSERT(pAnnot->HasObservable());
+ return GetAnnotHandler(pAnnot->Get())
+ ->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
+}
+
bool CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(
CPDFSDK_PageView* pPageView,
CPDFSDK_Annot::ObservedPtr* pAnnot,
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.h b/fpdfsdk/cpdfsdk_annothandlermgr.h
index 690e46cd2e..eb8ef48057 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.h
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.h
@@ -69,6 +69,10 @@ class CPDFSDK_AnnotHandlerMgr {
CPDFSDK_Annot::ObservedPtr* pAnnot,
uint32_t nFlags,
const CFX_PointF& point);
+ bool Annot_OnLButtonDblClk(CPDFSDK_PageView* pPageView,
+ CPDFSDK_Annot::ObservedPtr* pAnnot,
+ uint32_t nFlags,
+ const CFX_PointF& point);
bool Annot_OnMouseMove(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot::ObservedPtr* pAnnot,
uint32_t nFlags,
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 4d9a905fd6..b0b5f8a68a 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -315,6 +315,40 @@ bool CPDFSDK_PageView::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
return true;
}
+bool CPDFSDK_PageView::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
+ m_pFormFillEnv->GetAnnotHandlerMgr();
+ CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point));
+ CPDFSDK_Annot::ObservedPtr pFocusAnnot(GetFocusAnnot());
+ if (pFocusAnnot && pFocusAnnot != pFXAnnot) {
+ // Last focus Annot gets a chance to handle the event.
+ if (pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFocusAnnot, nFlag, point))
+ return true;
+ }
+ return pFXAnnot &&
+ pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFXAnnot, nFlag, point);
+}
+
+bool CPDFSDK_PageView::OnLButtonDblClk(const CFX_PointF& point,
+ uint32_t nFlag) {
+ CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point));
+ if (!pAnnot) {
+ m_pFormFillEnv->KillFocusAnnot(nFlag);
+ return false;
+ }
+
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
+ m_pFormFillEnv->GetAnnotHandlerMgr();
+ if (!pAnnotHandlerMgr->Annot_OnLButtonDblClk(this, &pAnnot, nFlag, point))
+ return false;
+
+ if (!pAnnot)
+ return false;
+
+ m_pFormFillEnv->SetFocusAnnot(&pAnnot);
+ return true;
+}
+
#ifdef PDF_ENABLE_XFA
bool CPDFSDK_PageView::OnRButtonDown(const CFX_PointF& point, uint32_t nFlag) {
CPDFSDK_Annot::ObservedPtr pAnnot(GetFXWidgetAtPoint(point));
@@ -347,20 +381,6 @@ bool CPDFSDK_PageView::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
}
#endif // PDF_ENABLE_XFA
-bool CPDFSDK_PageView::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
- m_pFormFillEnv->GetAnnotHandlerMgr();
- CPDFSDK_Annot::ObservedPtr pFXAnnot(GetFXWidgetAtPoint(point));
- CPDFSDK_Annot::ObservedPtr pFocusAnnot(GetFocusAnnot());
- if (pFocusAnnot && pFocusAnnot != pFXAnnot) {
- // Last focus Annot gets a chance to handle the event.
- if (pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFocusAnnot, nFlag, point))
- return true;
- }
- return pFXAnnot &&
- pAnnotHandlerMgr->Annot_OnLButtonUp(this, &pFXAnnot, nFlag, point);
-}
-
bool CPDFSDK_PageView::OnMouseMove(const CFX_PointF& point, int nFlag) {
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
m_pFormFillEnv->GetAnnotHandlerMgr();
diff --git a/fpdfsdk/cpdfsdk_pageview.h b/fpdfsdk/cpdfsdk_pageview.h
index 4674c1bbb8..c3cbbc6f4f 100644
--- a/fpdfsdk/cpdfsdk_pageview.h
+++ b/fpdfsdk/cpdfsdk_pageview.h
@@ -65,6 +65,7 @@ class CPDFSDK_PageView final : public CPDF_Page::View {
bool OnFocus(const CFX_PointF& point, uint32_t nFlag);
bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag);
bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag);
+ bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag);
#ifdef PDF_ENABLE_XFA
bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag);
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 7b8215d9e2..4b23ce41b0 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -410,6 +410,22 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier);
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FORM_OnLButtonDoubleClick(FPDF_FORMHANDLE hHandle,
+ FPDF_PAGE page,
+ int modifier,
+ double page_x,
+ double page_y) {
+ CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
+ if (!pPageView)
+ return false;
+#ifdef PDF_ENABLE_CLICK_LOGGING
+ fprintf(stderr, "mousedown,doubleleft,%d,%d\n",
+ static_cast<int>(round(page_x)), static_cast<int>(round(page_y)));
+#endif // PDF_ENABLE_CLICK_LOGGING
+ return pPageView->OnLButtonDblClk(CFX_PointF(page_x, page_y), modifier);
+}
+
#ifdef PDF_ENABLE_XFA
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
FPDF_PAGE page,
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index e55997c740..99d30f3cc3 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -64,6 +64,12 @@ class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest {
FORM_OnLButtonUp(form_handle(), page_, 0, point.x, point.y);
}
+ void DoubleClickOnFormFieldAtPoint(const CFX_PointF& point) {
+ // Click on the text field or combobox as specified by coordinates.
+ FORM_OnMouseMove(form_handle(), page_, 0, point.x, point.y);
+ FORM_OnLButtonDoubleClick(form_handle(), page_, 0, point.x, point.y);
+ }
+
void TypeTextIntoTextField(int num_chars, const CFX_PointF& point) {
EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(point));
ClickOnFormFieldAtPoint(point);
@@ -1542,6 +1548,23 @@ TEST_F(FPDFFormFillTextFormEmbeddertest,
CheckSelection(L"ElepHippop");
}
+TEST_F(FPDFFormFillTextFormEmbeddertest, DoubleClickInTextField) {
+ CheckFocusedFieldText(L"");
+ ClickOnFormFieldAtPoint(RegularFormBegin());
+ CheckFocusedFieldText(L"");
+
+ // Test inserting text into empty text field.
+ std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
+ GetFPDFWideString(L"Hello World");
+ FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
+ CheckFocusedFieldText(L"Hello World");
+
+ // Make sure double clicking selects the entire line.
+ CheckSelection(L"");
+ DoubleClickOnFormFieldAtPoint(RegularFormBegin());
+ CheckSelection(L"Hello World");
+}
+
TEST_F(FPDFFormFillTextFormEmbeddertest, FocusChanges) {
static const CFX_PointF kNonFormPoint(1, 1);
CheckFocusedFieldText(L"");
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 3ec51e7799..ab184cc519 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -240,6 +240,7 @@ int CheckPDFiumCApi() {
CHK(FORM_OnFocus);
CHK(FORM_OnKeyDown);
CHK(FORM_OnKeyUp);
+ CHK(FORM_OnLButtonDoubleClick);
CHK(FORM_OnLButtonDown);
CHK(FORM_OnLButtonUp);
CHK(FORM_OnMouseMove);