From 24ef63300f167ac63fb1f7fe8d3323ed6bce1695 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 24 Jul 2017 10:52:57 -0400 Subject: Move xfa/fxfa/app to xfa/fxfa There currently exists a weird split where some files exist in xfa/fxfa and some files exist in xfa/fxfa/app. This CL removes the app/ folder and moves all files up to the parent directory. Change-Id: I00c87851a1ebc5a7a636eb9a17b58ba3f1708a84 Reviewed-on: https://pdfium-review.googlesource.com/8810 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- BUILD.gn | 140 +-- xfa/fde/css/cfde_cssstyleselector.cpp | 2 +- xfa/fgas/layout/cfx_breakpiece.h | 2 +- xfa/fgas/layout/cfx_rtfbreak.h | 2 +- xfa/fwl/cfwl_app.cpp | 2 +- xfa/fwl/cfwl_widgetmgr.cpp | 2 +- xfa/fwl/theme/cfwl_edittp.cpp | 2 +- xfa/fxfa/app/cxfa_csstagprovider.cpp | 12 - xfa/fxfa/app/cxfa_csstagprovider.h | 39 - xfa/fxfa/app/cxfa_ffarc.cpp | 33 - xfa/fxfa/app/cxfa_ffarc.h | 23 - xfa/fxfa/app/cxfa_ffbarcode.cpp | 226 ---- xfa/fxfa/app/cxfa_ffbarcode.h | 103 -- xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp | 25 - xfa/fxfa/app/cxfa_ffcheckbutton.cpp | 345 ------ xfa/fxfa/app/cxfa_ffcheckbutton.h | 46 - xfa/fxfa/app/cxfa_ffcombobox.cpp | 360 ------ xfa/fxfa/app/cxfa_ffcombobox.h | 69 -- xfa/fxfa/app/cxfa_ffdatetimeedit.cpp | 213 ---- xfa/fxfa/app/cxfa_ffdatetimeedit.h | 47 - xfa/fxfa/app/cxfa_ffdraw.cpp | 16 - xfa/fxfa/app/cxfa_ffdraw.h | 19 - xfa/fxfa/app/cxfa_ffexclgroup.cpp | 30 - xfa/fxfa/app/cxfa_ffexclgroup.h | 24 - xfa/fxfa/app/cxfa_fffield.cpp | 785 ------------- xfa/fxfa/app/cxfa_fffield.h | 99 -- xfa/fxfa/app/cxfa_ffimage.cpp | 72 -- xfa/fxfa/app/cxfa_ffimage.h | 26 - xfa/fxfa/app/cxfa_ffimageedit.cpp | 143 --- xfa/fxfa/app/cxfa_ffimageedit.h | 37 - xfa/fxfa/app/cxfa_ffline.cpp | 99 -- xfa/fxfa/app/cxfa_ffline.h | 26 - xfa/fxfa/app/cxfa_fflistbox.cpp | 210 ---- xfa/fxfa/app/cxfa_fflistbox.h | 40 - xfa/fxfa/app/cxfa_ffnotify.cpp | 540 --------- xfa/fxfa/app/cxfa_ffnotify.h | 77 -- xfa/fxfa/app/cxfa_ffnumericedit.cpp | 97 -- xfa/fxfa/app/cxfa_ffnumericedit.h | 31 - xfa/fxfa/app/cxfa_ffpasswordedit.cpp | 64 -- xfa/fxfa/app/cxfa_ffpasswordedit.h | 24 - xfa/fxfa/app/cxfa_ffpushbutton.cpp | 240 ---- xfa/fxfa/app/cxfa_ffpushbutton.h | 54 - xfa/fxfa/app/cxfa_ffrectangle.cpp | 34 - xfa/fxfa/app/cxfa_ffrectangle.h | 23 - xfa/fxfa/app/cxfa_ffsignature.cpp | 114 -- xfa/fxfa/app/cxfa_ffsignature.h | 42 - xfa/fxfa/app/cxfa_ffsubform.cpp | 17 - xfa/fxfa/app/cxfa_ffsubform.h | 19 - xfa/fxfa/app/cxfa_fftext.cpp | 163 --- xfa/fxfa/app/cxfa_fftext.h | 32 - xfa/fxfa/app/cxfa_fftextedit.cpp | 359 ------ xfa/fxfa/app/cxfa_fftextedit.h | 57 - xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp | 38 - xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h | 28 - xfa/fxfa/app/cxfa_fwltheme.cpp | 284 ----- xfa/fxfa/app/cxfa_fwltheme.h | 70 -- xfa/fxfa/app/cxfa_linkuserdata.cpp | 12 - xfa/fxfa/app/cxfa_linkuserdata.h | 29 - xfa/fxfa/app/cxfa_loadercontext.cpp | 21 - xfa/fxfa/app/cxfa_loadercontext.h | 40 - xfa/fxfa/app/cxfa_pieceline.cpp | 13 - xfa/fxfa/app/cxfa_pieceline.h | 26 - xfa/fxfa/app/cxfa_textlayout.cpp | 1304 ---------------------- xfa/fxfa/app/cxfa_textlayout.h | 136 --- xfa/fxfa/app/cxfa_textparsecontext.cpp | 17 - xfa/fxfa/app/cxfa_textparsecontext.h | 39 - xfa/fxfa/app/cxfa_textparser.cpp | 625 ----------- xfa/fxfa/app/cxfa_textparser.h | 104 -- xfa/fxfa/app/cxfa_textparser_unittest.cpp | 40 - xfa/fxfa/app/cxfa_textpiece.cpp | 13 - xfa/fxfa/app/cxfa_textpiece.h | 41 - xfa/fxfa/app/cxfa_textprovider.cpp | 166 --- xfa/fxfa/app/cxfa_textprovider.h | 50 - xfa/fxfa/app/cxfa_texttabstopscontext.cpp | 32 - xfa/fxfa/app/cxfa_texttabstopscontext.h | 39 - xfa/fxfa/app/cxfa_textuserdata.cpp | 23 - xfa/fxfa/app/cxfa_textuserdata.h | 32 - xfa/fxfa/cxfa_csstagprovider.cpp | 12 + xfa/fxfa/cxfa_csstagprovider.h | 39 + xfa/fxfa/cxfa_ffapp.cpp | 4 +- xfa/fxfa/cxfa_ffarc.cpp | 33 + xfa/fxfa/cxfa_ffarc.h | 23 + xfa/fxfa/cxfa_ffbarcode.cpp | 226 ++++ xfa/fxfa/cxfa_ffbarcode.h | 103 ++ xfa/fxfa/cxfa_ffbarcode_unittest.cpp | 25 + xfa/fxfa/cxfa_ffcheckbutton.cpp | 345 ++++++ xfa/fxfa/cxfa_ffcheckbutton.h | 46 + xfa/fxfa/cxfa_ffcombobox.cpp | 360 ++++++ xfa/fxfa/cxfa_ffcombobox.h | 69 ++ xfa/fxfa/cxfa_ffdatetimeedit.cpp | 213 ++++ xfa/fxfa/cxfa_ffdatetimeedit.h | 47 + xfa/fxfa/cxfa_ffdoc.cpp | 2 +- xfa/fxfa/cxfa_ffdocview.cpp | 26 +- xfa/fxfa/cxfa_ffdraw.cpp | 16 + xfa/fxfa/cxfa_ffdraw.h | 19 + xfa/fxfa/cxfa_ffexclgroup.cpp | 30 + xfa/fxfa/cxfa_ffexclgroup.h | 24 + xfa/fxfa/cxfa_fffield.cpp | 785 +++++++++++++ xfa/fxfa/cxfa_fffield.h | 99 ++ xfa/fxfa/cxfa_ffimage.cpp | 72 ++ xfa/fxfa/cxfa_ffimage.h | 26 + xfa/fxfa/cxfa_ffimageedit.cpp | 143 +++ xfa/fxfa/cxfa_ffimageedit.h | 37 + xfa/fxfa/cxfa_ffline.cpp | 99 ++ xfa/fxfa/cxfa_ffline.h | 26 + xfa/fxfa/cxfa_fflistbox.cpp | 210 ++++ xfa/fxfa/cxfa_fflistbox.h | 40 + xfa/fxfa/cxfa_ffnotify.cpp | 540 +++++++++ xfa/fxfa/cxfa_ffnotify.h | 77 ++ xfa/fxfa/cxfa_ffnumericedit.cpp | 97 ++ xfa/fxfa/cxfa_ffnumericedit.h | 31 + xfa/fxfa/cxfa_ffpageview.cpp | 10 +- xfa/fxfa/cxfa_ffpasswordedit.cpp | 64 ++ xfa/fxfa/cxfa_ffpasswordedit.h | 24 + xfa/fxfa/cxfa_ffpushbutton.cpp | 240 ++++ xfa/fxfa/cxfa_ffpushbutton.h | 54 + xfa/fxfa/cxfa_ffrectangle.cpp | 34 + xfa/fxfa/cxfa_ffrectangle.h | 23 + xfa/fxfa/cxfa_ffsignature.cpp | 114 ++ xfa/fxfa/cxfa_ffsignature.h | 42 + xfa/fxfa/cxfa_ffsubform.cpp | 17 + xfa/fxfa/cxfa_ffsubform.h | 19 + xfa/fxfa/cxfa_fftext.cpp | 163 +++ xfa/fxfa/cxfa_fftext.h | 32 + xfa/fxfa/cxfa_fftextedit.cpp | 359 ++++++ xfa/fxfa/cxfa_fftextedit.h | 57 + xfa/fxfa/cxfa_ffwidget.cpp | 2 +- xfa/fxfa/cxfa_ffwidgethandler.cpp | 4 +- xfa/fxfa/cxfa_fwladapterwidgetmgr.cpp | 38 + xfa/fxfa/cxfa_fwladapterwidgetmgr.h | 28 + xfa/fxfa/cxfa_fwltheme.cpp | 284 +++++ xfa/fxfa/cxfa_fwltheme.h | 70 ++ xfa/fxfa/cxfa_linkuserdata.cpp | 12 + xfa/fxfa/cxfa_linkuserdata.h | 29 + xfa/fxfa/cxfa_loadercontext.cpp | 21 + xfa/fxfa/cxfa_loadercontext.h | 40 + xfa/fxfa/cxfa_pieceline.cpp | 13 + xfa/fxfa/cxfa_pieceline.h | 26 + xfa/fxfa/cxfa_textlayout.cpp | 1304 ++++++++++++++++++++++ xfa/fxfa/cxfa_textlayout.h | 136 +++ xfa/fxfa/cxfa_textparsecontext.cpp | 16 + xfa/fxfa/cxfa_textparsecontext.h | 39 + xfa/fxfa/cxfa_textparser.cpp | 625 +++++++++++ xfa/fxfa/cxfa_textparser.h | 104 ++ xfa/fxfa/cxfa_textparser_unittest.cpp | 40 + xfa/fxfa/cxfa_textpiece.cpp | 13 + xfa/fxfa/cxfa_textpiece.h | 41 + xfa/fxfa/cxfa_textprovider.cpp | 166 +++ xfa/fxfa/cxfa_textprovider.h | 50 + xfa/fxfa/cxfa_texttabstopscontext.cpp | 32 + xfa/fxfa/cxfa_texttabstopscontext.h | 39 + xfa/fxfa/cxfa_textuserdata.cpp | 23 + xfa/fxfa/cxfa_textuserdata.h | 32 + xfa/fxfa/cxfa_widgetacc.cpp | 4 +- xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp | 2 +- xfa/fxfa/parser/cscript_eventpseudomodel.cpp | 2 +- xfa/fxfa/parser/cscript_hostpseudomodel.cpp | 2 +- xfa/fxfa/parser/cscript_layoutpseudomodel.cpp | 2 +- xfa/fxfa/parser/cscript_signaturepseudomodel.cpp | 2 +- xfa/fxfa/parser/cxfa_document.cpp | 2 +- xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 2 +- xfa/fxfa/parser/cxfa_layoutitem.cpp | 2 +- xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 2 +- xfa/fxfa/parser/cxfa_node.cpp | 2 +- xfa/fxfa/parser/cxfa_object.cpp | 2 +- xfa/fxfa/parser/cxfa_scriptcontext.cpp | 2 +- xfa/fxfa/parser/cxfa_widgetdata.cpp | 2 +- 167 files changed, 8490 insertions(+), 8491 deletions(-) delete mode 100644 xfa/fxfa/app/cxfa_csstagprovider.cpp delete mode 100644 xfa/fxfa/app/cxfa_csstagprovider.h delete mode 100644 xfa/fxfa/app/cxfa_ffarc.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffarc.h delete mode 100644 xfa/fxfa/app/cxfa_ffbarcode.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffbarcode.h delete mode 100644 xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffcheckbutton.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffcheckbutton.h delete mode 100644 xfa/fxfa/app/cxfa_ffcombobox.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffcombobox.h delete mode 100644 xfa/fxfa/app/cxfa_ffdatetimeedit.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffdatetimeedit.h delete mode 100644 xfa/fxfa/app/cxfa_ffdraw.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffdraw.h delete mode 100644 xfa/fxfa/app/cxfa_ffexclgroup.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffexclgroup.h delete mode 100644 xfa/fxfa/app/cxfa_fffield.cpp delete mode 100644 xfa/fxfa/app/cxfa_fffield.h delete mode 100644 xfa/fxfa/app/cxfa_ffimage.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffimage.h delete mode 100644 xfa/fxfa/app/cxfa_ffimageedit.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffimageedit.h delete mode 100644 xfa/fxfa/app/cxfa_ffline.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffline.h delete mode 100644 xfa/fxfa/app/cxfa_fflistbox.cpp delete mode 100644 xfa/fxfa/app/cxfa_fflistbox.h delete mode 100644 xfa/fxfa/app/cxfa_ffnotify.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffnotify.h delete mode 100644 xfa/fxfa/app/cxfa_ffnumericedit.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffnumericedit.h delete mode 100644 xfa/fxfa/app/cxfa_ffpasswordedit.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffpasswordedit.h delete mode 100644 xfa/fxfa/app/cxfa_ffpushbutton.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffpushbutton.h delete mode 100644 xfa/fxfa/app/cxfa_ffrectangle.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffrectangle.h delete mode 100644 xfa/fxfa/app/cxfa_ffsignature.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffsignature.h delete mode 100644 xfa/fxfa/app/cxfa_ffsubform.cpp delete mode 100644 xfa/fxfa/app/cxfa_ffsubform.h delete mode 100644 xfa/fxfa/app/cxfa_fftext.cpp delete mode 100644 xfa/fxfa/app/cxfa_fftext.h delete mode 100644 xfa/fxfa/app/cxfa_fftextedit.cpp delete mode 100644 xfa/fxfa/app/cxfa_fftextedit.h delete mode 100644 xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp delete mode 100644 xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h delete mode 100644 xfa/fxfa/app/cxfa_fwltheme.cpp delete mode 100644 xfa/fxfa/app/cxfa_fwltheme.h delete mode 100644 xfa/fxfa/app/cxfa_linkuserdata.cpp delete mode 100644 xfa/fxfa/app/cxfa_linkuserdata.h delete mode 100644 xfa/fxfa/app/cxfa_loadercontext.cpp delete mode 100644 xfa/fxfa/app/cxfa_loadercontext.h delete mode 100644 xfa/fxfa/app/cxfa_pieceline.cpp delete mode 100644 xfa/fxfa/app/cxfa_pieceline.h delete mode 100644 xfa/fxfa/app/cxfa_textlayout.cpp delete mode 100644 xfa/fxfa/app/cxfa_textlayout.h delete mode 100644 xfa/fxfa/app/cxfa_textparsecontext.cpp delete mode 100644 xfa/fxfa/app/cxfa_textparsecontext.h delete mode 100644 xfa/fxfa/app/cxfa_textparser.cpp delete mode 100644 xfa/fxfa/app/cxfa_textparser.h delete mode 100644 xfa/fxfa/app/cxfa_textparser_unittest.cpp delete mode 100644 xfa/fxfa/app/cxfa_textpiece.cpp delete mode 100644 xfa/fxfa/app/cxfa_textpiece.h delete mode 100644 xfa/fxfa/app/cxfa_textprovider.cpp delete mode 100644 xfa/fxfa/app/cxfa_textprovider.h delete mode 100644 xfa/fxfa/app/cxfa_texttabstopscontext.cpp delete mode 100644 xfa/fxfa/app/cxfa_texttabstopscontext.h delete mode 100644 xfa/fxfa/app/cxfa_textuserdata.cpp delete mode 100644 xfa/fxfa/app/cxfa_textuserdata.h create mode 100644 xfa/fxfa/cxfa_csstagprovider.cpp create mode 100644 xfa/fxfa/cxfa_csstagprovider.h create mode 100644 xfa/fxfa/cxfa_ffarc.cpp create mode 100644 xfa/fxfa/cxfa_ffarc.h create mode 100644 xfa/fxfa/cxfa_ffbarcode.cpp create mode 100644 xfa/fxfa/cxfa_ffbarcode.h create mode 100644 xfa/fxfa/cxfa_ffbarcode_unittest.cpp create mode 100644 xfa/fxfa/cxfa_ffcheckbutton.cpp create mode 100644 xfa/fxfa/cxfa_ffcheckbutton.h create mode 100644 xfa/fxfa/cxfa_ffcombobox.cpp create mode 100644 xfa/fxfa/cxfa_ffcombobox.h create mode 100644 xfa/fxfa/cxfa_ffdatetimeedit.cpp create mode 100644 xfa/fxfa/cxfa_ffdatetimeedit.h create mode 100644 xfa/fxfa/cxfa_ffdraw.cpp create mode 100644 xfa/fxfa/cxfa_ffdraw.h create mode 100644 xfa/fxfa/cxfa_ffexclgroup.cpp create mode 100644 xfa/fxfa/cxfa_ffexclgroup.h create mode 100644 xfa/fxfa/cxfa_fffield.cpp create mode 100644 xfa/fxfa/cxfa_fffield.h create mode 100644 xfa/fxfa/cxfa_ffimage.cpp create mode 100644 xfa/fxfa/cxfa_ffimage.h create mode 100644 xfa/fxfa/cxfa_ffimageedit.cpp create mode 100644 xfa/fxfa/cxfa_ffimageedit.h create mode 100644 xfa/fxfa/cxfa_ffline.cpp create mode 100644 xfa/fxfa/cxfa_ffline.h create mode 100644 xfa/fxfa/cxfa_fflistbox.cpp create mode 100644 xfa/fxfa/cxfa_fflistbox.h create mode 100644 xfa/fxfa/cxfa_ffnotify.cpp create mode 100644 xfa/fxfa/cxfa_ffnotify.h create mode 100644 xfa/fxfa/cxfa_ffnumericedit.cpp create mode 100644 xfa/fxfa/cxfa_ffnumericedit.h create mode 100644 xfa/fxfa/cxfa_ffpasswordedit.cpp create mode 100644 xfa/fxfa/cxfa_ffpasswordedit.h create mode 100644 xfa/fxfa/cxfa_ffpushbutton.cpp create mode 100644 xfa/fxfa/cxfa_ffpushbutton.h create mode 100644 xfa/fxfa/cxfa_ffrectangle.cpp create mode 100644 xfa/fxfa/cxfa_ffrectangle.h create mode 100644 xfa/fxfa/cxfa_ffsignature.cpp create mode 100644 xfa/fxfa/cxfa_ffsignature.h create mode 100644 xfa/fxfa/cxfa_ffsubform.cpp create mode 100644 xfa/fxfa/cxfa_ffsubform.h create mode 100644 xfa/fxfa/cxfa_fftext.cpp create mode 100644 xfa/fxfa/cxfa_fftext.h create mode 100644 xfa/fxfa/cxfa_fftextedit.cpp create mode 100644 xfa/fxfa/cxfa_fftextedit.h create mode 100644 xfa/fxfa/cxfa_fwladapterwidgetmgr.cpp create mode 100644 xfa/fxfa/cxfa_fwladapterwidgetmgr.h create mode 100644 xfa/fxfa/cxfa_fwltheme.cpp create mode 100644 xfa/fxfa/cxfa_fwltheme.h create mode 100644 xfa/fxfa/cxfa_linkuserdata.cpp create mode 100644 xfa/fxfa/cxfa_linkuserdata.h create mode 100644 xfa/fxfa/cxfa_loadercontext.cpp create mode 100644 xfa/fxfa/cxfa_loadercontext.h create mode 100644 xfa/fxfa/cxfa_pieceline.cpp create mode 100644 xfa/fxfa/cxfa_pieceline.h create mode 100644 xfa/fxfa/cxfa_textlayout.cpp create mode 100644 xfa/fxfa/cxfa_textlayout.h create mode 100644 xfa/fxfa/cxfa_textparsecontext.cpp create mode 100644 xfa/fxfa/cxfa_textparsecontext.h create mode 100644 xfa/fxfa/cxfa_textparser.cpp create mode 100644 xfa/fxfa/cxfa_textparser.h create mode 100644 xfa/fxfa/cxfa_textparser_unittest.cpp create mode 100644 xfa/fxfa/cxfa_textpiece.cpp create mode 100644 xfa/fxfa/cxfa_textpiece.h create mode 100644 xfa/fxfa/cxfa_textprovider.cpp create mode 100644 xfa/fxfa/cxfa_textprovider.h create mode 100644 xfa/fxfa/cxfa_texttabstopscontext.cpp create mode 100644 xfa/fxfa/cxfa_texttabstopscontext.h create mode 100644 xfa/fxfa/cxfa_textuserdata.cpp create mode 100644 xfa/fxfa/cxfa_textuserdata.h diff --git a/BUILD.gn b/BUILD.gn index 7d5232ceb0..9cc4500503 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1614,88 +1614,64 @@ if (pdf_enable_xfa) { "xfa/fwl/theme/cfwl_utils.h", "xfa/fwl/theme/cfwl_widgettp.cpp", "xfa/fwl/theme/cfwl_widgettp.h", - "xfa/fxfa/app/cxfa_csstagprovider.cpp", - "xfa/fxfa/app/cxfa_csstagprovider.h", - "xfa/fxfa/app/cxfa_ffarc.cpp", - "xfa/fxfa/app/cxfa_ffarc.h", - "xfa/fxfa/app/cxfa_ffbarcode.cpp", - "xfa/fxfa/app/cxfa_ffbarcode.h", - "xfa/fxfa/app/cxfa_ffcheckbutton.cpp", - "xfa/fxfa/app/cxfa_ffcheckbutton.h", - "xfa/fxfa/app/cxfa_ffcombobox.cpp", - "xfa/fxfa/app/cxfa_ffcombobox.h", - "xfa/fxfa/app/cxfa_ffdatetimeedit.cpp", - "xfa/fxfa/app/cxfa_ffdatetimeedit.h", - "xfa/fxfa/app/cxfa_ffdraw.cpp", - "xfa/fxfa/app/cxfa_ffdraw.h", - "xfa/fxfa/app/cxfa_ffexclgroup.cpp", - "xfa/fxfa/app/cxfa_ffexclgroup.h", - "xfa/fxfa/app/cxfa_fffield.cpp", - "xfa/fxfa/app/cxfa_fffield.h", - "xfa/fxfa/app/cxfa_ffimage.cpp", - "xfa/fxfa/app/cxfa_ffimage.h", - "xfa/fxfa/app/cxfa_ffimageedit.cpp", - "xfa/fxfa/app/cxfa_ffimageedit.h", - "xfa/fxfa/app/cxfa_ffline.cpp", - "xfa/fxfa/app/cxfa_ffline.h", - "xfa/fxfa/app/cxfa_fflistbox.cpp", - "xfa/fxfa/app/cxfa_fflistbox.h", - "xfa/fxfa/app/cxfa_ffnotify.cpp", - "xfa/fxfa/app/cxfa_ffnotify.h", - "xfa/fxfa/app/cxfa_ffnumericedit.cpp", - "xfa/fxfa/app/cxfa_ffnumericedit.h", - "xfa/fxfa/app/cxfa_ffpasswordedit.cpp", - "xfa/fxfa/app/cxfa_ffpasswordedit.h", - "xfa/fxfa/app/cxfa_ffpushbutton.cpp", - "xfa/fxfa/app/cxfa_ffpushbutton.h", - "xfa/fxfa/app/cxfa_ffrectangle.cpp", - "xfa/fxfa/app/cxfa_ffrectangle.h", - "xfa/fxfa/app/cxfa_ffsignature.cpp", - "xfa/fxfa/app/cxfa_ffsignature.h", - "xfa/fxfa/app/cxfa_ffsubform.cpp", - "xfa/fxfa/app/cxfa_ffsubform.h", - "xfa/fxfa/app/cxfa_fftext.cpp", - "xfa/fxfa/app/cxfa_fftext.h", - "xfa/fxfa/app/cxfa_fftextedit.cpp", - "xfa/fxfa/app/cxfa_fftextedit.h", - "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp", - "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h", - "xfa/fxfa/app/cxfa_fwltheme.cpp", - "xfa/fxfa/app/cxfa_fwltheme.h", - "xfa/fxfa/app/cxfa_linkuserdata.cpp", - "xfa/fxfa/app/cxfa_linkuserdata.h", - "xfa/fxfa/app/cxfa_loadercontext.cpp", - "xfa/fxfa/app/cxfa_loadercontext.h", - "xfa/fxfa/app/cxfa_pieceline.cpp", - "xfa/fxfa/app/cxfa_pieceline.h", - "xfa/fxfa/app/cxfa_textlayout.cpp", - "xfa/fxfa/app/cxfa_textlayout.h", - "xfa/fxfa/app/cxfa_textparsecontext.cpp", - "xfa/fxfa/app/cxfa_textparsecontext.h", - "xfa/fxfa/app/cxfa_textparser.cpp", - "xfa/fxfa/app/cxfa_textparser.h", - "xfa/fxfa/app/cxfa_textpiece.cpp", - "xfa/fxfa/app/cxfa_textpiece.h", - "xfa/fxfa/app/cxfa_textprovider.cpp", - "xfa/fxfa/app/cxfa_textprovider.h", - "xfa/fxfa/app/cxfa_texttabstopscontext.cpp", - "xfa/fxfa/app/cxfa_texttabstopscontext.h", - "xfa/fxfa/app/cxfa_textuserdata.cpp", - "xfa/fxfa/app/cxfa_textuserdata.h", + "xfa/fxfa/cxfa_csstagprovider.cpp", + "xfa/fxfa/cxfa_csstagprovider.h", "xfa/fxfa/cxfa_deffontmgr.cpp", "xfa/fxfa/cxfa_deffontmgr.h", "xfa/fxfa/cxfa_eventparam.cpp", "xfa/fxfa/cxfa_eventparam.h", "xfa/fxfa/cxfa_ffapp.cpp", "xfa/fxfa/cxfa_ffapp.h", + "xfa/fxfa/cxfa_ffarc.cpp", + "xfa/fxfa/cxfa_ffarc.h", + "xfa/fxfa/cxfa_ffbarcode.cpp", + "xfa/fxfa/cxfa_ffbarcode.h", + "xfa/fxfa/cxfa_ffcheckbutton.cpp", + "xfa/fxfa/cxfa_ffcheckbutton.h", + "xfa/fxfa/cxfa_ffcombobox.cpp", + "xfa/fxfa/cxfa_ffcombobox.h", + "xfa/fxfa/cxfa_ffdatetimeedit.cpp", + "xfa/fxfa/cxfa_ffdatetimeedit.h", "xfa/fxfa/cxfa_ffdoc.cpp", "xfa/fxfa/cxfa_ffdoc.h", "xfa/fxfa/cxfa_ffdochandler.cpp", "xfa/fxfa/cxfa_ffdochandler.h", "xfa/fxfa/cxfa_ffdocview.cpp", "xfa/fxfa/cxfa_ffdocview.h", + "xfa/fxfa/cxfa_ffdraw.cpp", + "xfa/fxfa/cxfa_ffdraw.h", + "xfa/fxfa/cxfa_ffexclgroup.cpp", + "xfa/fxfa/cxfa_ffexclgroup.h", + "xfa/fxfa/cxfa_fffield.cpp", + "xfa/fxfa/cxfa_fffield.h", + "xfa/fxfa/cxfa_ffimage.cpp", + "xfa/fxfa/cxfa_ffimage.h", + "xfa/fxfa/cxfa_ffimageedit.cpp", + "xfa/fxfa/cxfa_ffimageedit.h", + "xfa/fxfa/cxfa_ffline.cpp", + "xfa/fxfa/cxfa_ffline.h", + "xfa/fxfa/cxfa_fflistbox.cpp", + "xfa/fxfa/cxfa_fflistbox.h", + "xfa/fxfa/cxfa_ffnotify.cpp", + "xfa/fxfa/cxfa_ffnotify.h", + "xfa/fxfa/cxfa_ffnumericedit.cpp", + "xfa/fxfa/cxfa_ffnumericedit.h", "xfa/fxfa/cxfa_ffpageview.cpp", "xfa/fxfa/cxfa_ffpageview.h", + "xfa/fxfa/cxfa_ffpasswordedit.cpp", + "xfa/fxfa/cxfa_ffpasswordedit.h", + "xfa/fxfa/cxfa_ffpushbutton.cpp", + "xfa/fxfa/cxfa_ffpushbutton.h", + "xfa/fxfa/cxfa_ffrectangle.cpp", + "xfa/fxfa/cxfa_ffrectangle.h", + "xfa/fxfa/cxfa_ffsignature.cpp", + "xfa/fxfa/cxfa_ffsignature.h", + "xfa/fxfa/cxfa_ffsubform.cpp", + "xfa/fxfa/cxfa_ffsubform.h", + "xfa/fxfa/cxfa_fftext.cpp", + "xfa/fxfa/cxfa_fftext.h", + "xfa/fxfa/cxfa_fftextedit.cpp", + "xfa/fxfa/cxfa_fftextedit.h", "xfa/fxfa/cxfa_ffwidget.cpp", "xfa/fxfa/cxfa_ffwidget.h", "xfa/fxfa/cxfa_ffwidgethandler.cpp", @@ -1704,10 +1680,34 @@ if (pdf_enable_xfa) { "xfa/fxfa/cxfa_fileread.h", "xfa/fxfa/cxfa_fontmgr.cpp", "xfa/fxfa/cxfa_fontmgr.h", + "xfa/fxfa/cxfa_fwladapterwidgetmgr.cpp", + "xfa/fxfa/cxfa_fwladapterwidgetmgr.h", + "xfa/fxfa/cxfa_fwltheme.cpp", + "xfa/fxfa/cxfa_fwltheme.h", + "xfa/fxfa/cxfa_linkuserdata.cpp", + "xfa/fxfa/cxfa_linkuserdata.h", + "xfa/fxfa/cxfa_loadercontext.cpp", + "xfa/fxfa/cxfa_loadercontext.h", "xfa/fxfa/cxfa_pdffontmgr.cpp", "xfa/fxfa/cxfa_pdffontmgr.h", + "xfa/fxfa/cxfa_pieceline.cpp", + "xfa/fxfa/cxfa_pieceline.h", "xfa/fxfa/cxfa_rendercontext.cpp", "xfa/fxfa/cxfa_rendercontext.h", + "xfa/fxfa/cxfa_textlayout.cpp", + "xfa/fxfa/cxfa_textlayout.h", + "xfa/fxfa/cxfa_textparsecontext.cpp", + "xfa/fxfa/cxfa_textparsecontext.h", + "xfa/fxfa/cxfa_textparser.cpp", + "xfa/fxfa/cxfa_textparser.h", + "xfa/fxfa/cxfa_textpiece.cpp", + "xfa/fxfa/cxfa_textpiece.h", + "xfa/fxfa/cxfa_textprovider.cpp", + "xfa/fxfa/cxfa_textprovider.h", + "xfa/fxfa/cxfa_texttabstopscontext.cpp", + "xfa/fxfa/cxfa_texttabstopscontext.h", + "xfa/fxfa/cxfa_textuserdata.cpp", + "xfa/fxfa/cxfa_textuserdata.h", "xfa/fxfa/cxfa_widgetacc.cpp", "xfa/fxfa/cxfa_widgetacc.h", "xfa/fxfa/cxfa_widgetacciterator.cpp", @@ -1954,9 +1954,9 @@ test("pdfium_unittests") { "xfa/fgas/crt/cfgas_formatstring_unittest.cpp", "xfa/fgas/layout/cfx_rtfbreak_unittest.cpp", "xfa/fwl/cfx_barcode_unittest.cpp", - "xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp", - "xfa/fxfa/app/cxfa_textparser_unittest.cpp", "xfa/fxfa/cxfa_ffapp_unittest.cpp", + "xfa/fxfa/cxfa_ffbarcode_unittest.cpp", + "xfa/fxfa/cxfa_textparser_unittest.cpp", "xfa/fxfa/fm2js/cxfa_fmlexer_unittest.cpp", "xfa/fxfa/fm2js/cxfa_fmparse_unittest.cpp", "xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp", diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp index 2fe306faec..2213feb2be 100644 --- a/xfa/fde/css/cfde_cssstyleselector.cpp +++ b/xfa/fde/css/cfde_cssstyleselector.cpp @@ -21,7 +21,7 @@ #include "xfa/fde/css/cfde_cssstylesheet.h" #include "xfa/fde/css/cfde_csssyntaxparser.h" #include "xfa/fde/css/cfde_cssvaluelist.h" -#include "xfa/fxfa/app/cxfa_csstagprovider.h" +#include "xfa/fxfa/cxfa_csstagprovider.h" CFDE_CSSStyleSelector::CFDE_CSSStyleSelector(CFGAS_FontMgr* pFontMgr) : m_pFontMgr(pFontMgr), m_fDefFontSize(12.0f) {} diff --git a/xfa/fgas/layout/cfx_breakpiece.h b/xfa/fgas/layout/cfx_breakpiece.h index 807b5f769f..668245f3c0 100644 --- a/xfa/fgas/layout/cfx_breakpiece.h +++ b/xfa/fgas/layout/cfx_breakpiece.h @@ -13,7 +13,7 @@ #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/app/cxfa_textuserdata.h" +#include "xfa/fxfa/cxfa_textuserdata.h" class CFX_BreakPiece { public: diff --git a/xfa/fgas/layout/cfx_rtfbreak.h b/xfa/fgas/layout/cfx_rtfbreak.h index f900dcbe8a..bc5ab4a739 100644 --- a/xfa/fgas/layout/cfx_rtfbreak.h +++ b/xfa/fgas/layout/cfx_rtfbreak.h @@ -16,7 +16,7 @@ #include "core/fxcrt/fx_ucd.h" #include "core/fxge/cfx_renderdevice.h" #include "xfa/fgas/layout/cfx_break.h" -#include "xfa/fxfa/app/cxfa_textuserdata.h" +#include "xfa/fxfa/cxfa_textuserdata.h" class CFGAS_GEFont; diff --git a/xfa/fwl/cfwl_app.cpp b/xfa/fwl/cfwl_app.cpp index e762125ba8..58ca93de61 100644 --- a/xfa/fwl/cfwl_app.cpp +++ b/xfa/fwl/cfwl_app.cpp @@ -10,7 +10,7 @@ #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_widget.h" #include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" CFWL_App::CFWL_App(CXFA_FFApp* pAdapter) : m_pAdapterNative(pAdapter), diff --git a/xfa/fwl/cfwl_widgetmgr.cpp b/xfa/fwl/cfwl_widgetmgr.cpp index eb98f2ee81..d5b496a04b 100644 --- a/xfa/fwl/cfwl_widgetmgr.cpp +++ b/xfa/fwl/cfwl_widgetmgr.cpp @@ -12,8 +12,8 @@ #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_form.h" #include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" namespace { diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp index b04136ba23..19486fef16 100644 --- a/xfa/fwl/theme/cfwl_edittp.cpp +++ b/xfa/fwl/theme/cfwl_edittp.cpp @@ -9,8 +9,8 @@ #include "xfa/fwl/cfwl_edit.h" #include "xfa/fwl/cfwl_themebackground.h" #include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxfa/app/cxfa_fwltheme.h" #include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fwltheme.h" #include "xfa/fxgraphics/cxfa_color.h" #include "xfa/fxgraphics/cxfa_path.h" diff --git a/xfa/fxfa/app/cxfa_csstagprovider.cpp b/xfa/fxfa/app/cxfa_csstagprovider.cpp deleted file mode 100644 index ef5133e104..0000000000 --- a/xfa/fxfa/app/cxfa_csstagprovider.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_csstagprovider.h" - -CXFA_CSSTagProvider::CXFA_CSSTagProvider() - : m_bTagAvailable(false), m_bContent(false) {} - -CXFA_CSSTagProvider::~CXFA_CSSTagProvider() {} diff --git a/xfa/fxfa/app/cxfa_csstagprovider.h b/xfa/fxfa/app/cxfa_csstagprovider.h deleted file mode 100644 index f5db867390..0000000000 --- a/xfa/fxfa/app/cxfa_csstagprovider.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_CSSTAGPROVIDER_H_ -#define XFA_FXFA_APP_CXFA_CSSTAGPROVIDER_H_ - -#include - -#include "core/fxcrt/fx_string.h" - -class CXFA_CSSTagProvider { - public: - CXFA_CSSTagProvider(); - ~CXFA_CSSTagProvider(); - - CFX_WideString GetTagName() { return m_wsTagName; } - - void SetTagName(const CFX_WideString& wsName) { m_wsTagName = wsName; } - void SetAttribute(const CFX_WideString& wsAttr, - const CFX_WideString& wsValue) { - m_Attributes.insert({wsAttr, wsValue}); - } - - CFX_WideString GetAttribute(const CFX_WideString& wsAttr) { - return m_Attributes[wsAttr]; - } - - bool m_bTagAvailable; - bool m_bContent; - - private: - CFX_WideString m_wsTagName; - std::map m_Attributes; -}; - -#endif // XFA_FXFA_APP_CXFA_CSSTAGPROVIDER_H_ diff --git a/xfa/fxfa/app/cxfa_ffarc.cpp b/xfa/fxfa/app/cxfa_ffarc.cpp deleted file mode 100644 index 1a12fb5f23..0000000000 --- a/xfa/fxfa/app/cxfa_ffarc.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffarc.h" - -CXFA_FFArc::CXFA_FFArc(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFArc::~CXFA_FFArc() {} - -void CXFA_FFArc::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CXFA_Value value = m_pDataAcc->GetFormValue(); - if (!value) - return; - - CXFA_Arc arcObj = value.GetArc(); - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CFX_RectF rtArc = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rtArc, mgWidget); - - DrawBorder(pGS, arcObj, rtArc, &mtRotate); -} diff --git a/xfa/fxfa/app/cxfa_ffarc.h b/xfa/fxfa/app/cxfa_ffarc.h deleted file mode 100644 index f1bc82f1d2..0000000000 --- a/xfa/fxfa/app/cxfa_ffarc.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFARC_H_ -#define XFA_FXFA_APP_CXFA_FFARC_H_ - -#include "xfa/fxfa/app/cxfa_ffdraw.h" - -class CXFA_FFArc : public CXFA_FFDraw { - public: - explicit CXFA_FFArc(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFArc() override; - - // CXFA_FFWidget - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFARC_H_ diff --git a/xfa/fxfa/app/cxfa_ffbarcode.cpp b/xfa/fxfa/app/cxfa_ffbarcode.cpp deleted file mode 100644 index 7bbb60dd77..0000000000 --- a/xfa/fxfa/app/cxfa_ffbarcode.cpp +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffbarcode.h" - -#include - -#include "core/fxcrt/fx_extension.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/cfwl_app.h" -#include "xfa/fwl/cfwl_barcode.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -namespace { - -const BarCodeInfo g_BarCodeData[] = { - {0x7fb4a18, L"ean13", BarcodeType::ean13, BC_EAN13}, - {0x8d13a3d, L"code11", BarcodeType::code11, BC_UNKNOWN}, - {0x8d149a8, L"code49", BarcodeType::code49, BC_UNKNOWN}, - {0x8d16347, L"code93", BarcodeType::code93, BC_UNKNOWN}, - {0x91a92e2, L"upsMaxicode", BarcodeType::upsMaxicode, BC_UNKNOWN}, - {0xa7d48dc, L"fim", BarcodeType::fim, BC_UNKNOWN}, - {0xb359fe9, L"msi", BarcodeType::msi, BC_UNKNOWN}, - {0x121f738c, L"code2Of5Matrix", BarcodeType::code2Of5Matrix, BC_UNKNOWN}, - {0x15358616, L"ucc128", BarcodeType::ucc128, BC_UNKNOWN}, - {0x1f4bfa05, L"rfid", BarcodeType::rfid, BC_UNKNOWN}, - {0x1fda71bc, L"rss14Stacked", BarcodeType::rss14Stacked, BC_UNKNOWN}, - {0x22065087, L"ean8add2", BarcodeType::ean8add2, BC_UNKNOWN}, - {0x2206508a, L"ean8add5", BarcodeType::ean8add5, BC_UNKNOWN}, - {0x2278366c, L"codabar", BarcodeType::codabar, BC_CODABAR}, - {0x2a039a8d, L"telepen", BarcodeType::telepen, BC_UNKNOWN}, - {0x323ed337, L"upcApwcd", BarcodeType::upcApwcd, BC_UNKNOWN}, - {0x347a1846, L"postUSIMB", BarcodeType::postUSIMB, BC_UNKNOWN}, - {0x391bb836, L"code128", BarcodeType::code128, BC_CODE128}, - {0x398eddaf, L"dataMatrix", BarcodeType::dataMatrix, BC_DATAMATRIX}, - {0x3cff60a8, L"upcEadd2", BarcodeType::upcEadd2, BC_UNKNOWN}, - {0x3cff60ab, L"upcEadd5", BarcodeType::upcEadd5, BC_UNKNOWN}, - {0x402cb188, L"code2Of5Standard", BarcodeType::code2Of5Standard, - BC_UNKNOWN}, - {0x411764f7, L"aztec", BarcodeType::aztec, BC_UNKNOWN}, - {0x44d4e84c, L"ean8", BarcodeType::ean8, BC_EAN8}, - {0x48468902, L"ucc128sscc", BarcodeType::ucc128sscc, BC_UNKNOWN}, - {0x4880aea4, L"upcAadd2", BarcodeType::upcAadd2, BC_UNKNOWN}, - {0x4880aea7, L"upcAadd5", BarcodeType::upcAadd5, BC_UNKNOWN}, - {0x54f18256, L"code2Of5Industrial", BarcodeType::code2Of5Industrial, - BC_UNKNOWN}, - {0x58e15f25, L"rss14Limited", BarcodeType::rss14Limited, BC_UNKNOWN}, - {0x5c08d1b9, L"postAUSReplyPaid", BarcodeType::postAUSReplyPaid, - BC_UNKNOWN}, - {0x5fa700bd, L"rss14", BarcodeType::rss14, BC_UNKNOWN}, - {0x631a7e35, L"logmars", BarcodeType::logmars, BC_UNKNOWN}, - {0x6a236236, L"pdf417", BarcodeType::pdf417, BC_PDF417}, - {0x6d098ece, L"upcean2", BarcodeType::upcean2, BC_UNKNOWN}, - {0x6d098ed1, L"upcean5", BarcodeType::upcean5, BC_UNKNOWN}, - {0x76b04eed, L"code3Of9extended", BarcodeType::code3Of9extended, - BC_UNKNOWN}, - {0x7c7db84a, L"maxicode", BarcodeType::maxicode, BC_UNKNOWN}, - {0x8266f7f7, L"ucc128random", BarcodeType::ucc128random, BC_UNKNOWN}, - {0x83eca147, L"postUSDPBC", BarcodeType::postUSDPBC, BC_UNKNOWN}, - {0x8dd71de0, L"postAUSStandard", BarcodeType::postAUSStandard, BC_UNKNOWN}, - {0x98adad85, L"plessey", BarcodeType::plessey, BC_UNKNOWN}, - {0x9f84cce6, L"ean13pwcd", BarcodeType::ean13pwcd, BC_UNKNOWN}, - {0xb514fbe9, L"upcA", BarcodeType::upcA, BC_UPCA}, - {0xb514fbed, L"upcE", BarcodeType::upcE, BC_UNKNOWN}, - {0xb5c6a853, L"ean13add2", BarcodeType::ean13add2, BC_UNKNOWN}, - {0xb5c6a856, L"ean13add5", BarcodeType::ean13add5, BC_UNKNOWN}, - {0xb81fc512, L"postUKRM4SCC", BarcodeType::postUKRM4SCC, BC_UNKNOWN}, - {0xbad34b22, L"code128SSCC", BarcodeType::code128SSCC, BC_UNKNOWN}, - {0xbfbe0cf6, L"postUS5Zip", BarcodeType::postUS5Zip, BC_UNKNOWN}, - {0xc56618e8, L"pdf417macro", BarcodeType::pdf417macro, BC_UNKNOWN}, - {0xca730f8a, L"code2Of5Interleaved", BarcodeType::code2Of5Interleaved, - BC_UNKNOWN}, - {0xd0097ac6, L"rss14Expanded", BarcodeType::rss14Expanded, BC_UNKNOWN}, - {0xd25a0240, L"postAUSCust2", BarcodeType::postAUSCust2, BC_UNKNOWN}, - {0xd25a0241, L"postAUSCust3", BarcodeType::postAUSCust3, BC_UNKNOWN}, - {0xd53ed3e7, L"rss14Truncated", BarcodeType::rss14Truncated, BC_UNKNOWN}, - {0xe72bcd57, L"code128A", BarcodeType::code128A, BC_UNKNOWN}, - {0xe72bcd58, L"code128B", BarcodeType::code128B, BC_CODE128_B}, - {0xe72bcd59, L"code128C", BarcodeType::code128C, BC_CODE128_C}, - {0xee83c50f, L"rss14StackedOmni", BarcodeType::rss14StackedOmni, - BC_UNKNOWN}, - {0xf2a18f7e, L"QRCode", BarcodeType::QRCode, BC_QR_CODE}, - {0xfaeaf37f, L"postUSStandard", BarcodeType::postUSStandard, BC_UNKNOWN}, - {0xfb48155c, L"code3Of9", BarcodeType::code3Of9, BC_CODE39}, -}; - -} // namespace. - -// static -const BarCodeInfo* CXFA_FFBarcode::GetBarcodeTypeByName( - const CFX_WideStringC& wsName) { - if (wsName.IsEmpty()) - return nullptr; - - auto* it = std::lower_bound( - std::begin(g_BarCodeData), std::end(g_BarCodeData), - FX_HashCode_GetW(wsName, true), - [](const BarCodeInfo& arg, uint32_t hash) { return arg.uHash < hash; }); - - if (it != std::end(g_BarCodeData) && wsName == it->pName) - return it; - - return nullptr; -} - -CXFA_FFBarcode::CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFBarcode::~CXFA_FFBarcode() {} - -bool CXFA_FFBarcode::LoadWidget() { - auto pNew = pdfium::MakeUnique(GetFWLApp()); - CFWL_Barcode* pFWLBarcode = pNew.get(); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pFWLBarcode->SetText(wsText); - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFBarcode::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); - RenderCaption(pGS, &mtRotate); - CFX_RectF rtWidget = m_pNormalWidget->GetWidgetRect(); - - CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); - mt.Concat(mtRotate); - m_pNormalWidget->DrawWidget(pGS, &mt); -} - -void CXFA_FFBarcode::UpdateWidgetProperty() { - CXFA_FFTextEdit::UpdateWidgetProperty(); - - auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); - CFX_WideString wsType = GetDataAcc()->GetBarcodeType(); - const BarCodeInfo* pBarcodeInfo = GetBarcodeTypeByName(wsType.AsStringC()); - if (!pBarcodeInfo) - return; - - pBarCodeWidget->SetType(pBarcodeInfo->eBCType); - - CXFA_WidgetAcc* pAcc = GetDataAcc(); - int32_t intVal; - if (pAcc->GetBarcodeAttribute_CharEncoding(&intVal)) - pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal); - - bool boolVal; - if (pAcc->GetBarcodeAttribute_Checksum(&boolVal)) - pBarCodeWidget->SetCalChecksum(boolVal); - if (pAcc->GetBarcodeAttribute_DataLength(&intVal)) - pBarCodeWidget->SetDataLength(intVal); - - char charVal; - if (pAcc->GetBarcodeAttribute_StartChar(&charVal)) - pBarCodeWidget->SetStartChar(charVal); - if (pAcc->GetBarcodeAttribute_EndChar(&charVal)) - pBarCodeWidget->SetEndChar(charVal); - if (pAcc->GetBarcodeAttribute_ECLevel(&intVal)) - pBarCodeWidget->SetErrorCorrectionLevel(intVal); - if (pAcc->GetBarcodeAttribute_ModuleWidth(&intVal)) - pBarCodeWidget->SetModuleWidth(intVal); - if (pAcc->GetBarcodeAttribute_ModuleHeight(&intVal)) - pBarCodeWidget->SetModuleHeight(intVal); - if (pAcc->GetBarcodeAttribute_PrintChecksum(&boolVal)) - pBarCodeWidget->SetPrintChecksum(boolVal); - if (pAcc->GetBarcodeAttribute_TextLocation(&intVal)) - pBarCodeWidget->SetTextLocation((BC_TEXT_LOC)intVal); - if (pAcc->GetBarcodeAttribute_Truncate(&boolVal)) - pBarCodeWidget->SetTruncated(boolVal); - - float floatVal; - if (pAcc->GetBarcodeAttribute_WideNarrowRatio(&floatVal)) - pBarCodeWidget->SetWideNarrowRatio(static_cast(floatVal)); - if (pBarcodeInfo->eName == BarcodeType::code3Of9 || - pBarcodeInfo->eName == BarcodeType::ean8 || - pBarcodeInfo->eName == BarcodeType::ean13 || - pBarcodeInfo->eName == BarcodeType::upcA) { - pBarCodeWidget->SetPrintChecksum(true); - } -} - -bool CXFA_FFBarcode::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); - if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) - return false; - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) - return false; - return CXFA_FFTextEdit::OnLButtonDown(dwFlags, point); -} - -bool CXFA_FFBarcode::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); - if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) - return false; - return CXFA_FFTextEdit::OnRButtonDown(dwFlags, point); -} diff --git a/xfa/fxfa/app/cxfa_ffbarcode.h b/xfa/fxfa/app/cxfa_ffbarcode.h deleted file mode 100644 index 782aec39a1..0000000000 --- a/xfa/fxfa/app/cxfa_ffbarcode.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFBARCODE_H_ -#define XFA_FXFA_APP_CXFA_FFBARCODE_H_ - -#include "fxbarcode/BC_Library.h" -#include "xfa/fxfa/app/cxfa_fftextedit.h" -#include "xfa/fxfa/cxfa_ffpageview.h" - -enum class BarcodeType { - aztec, - codabar, - code11, - code128, - code128A, - code128B, - code128C, - code128SSCC, - code2Of5Industrial, - code2Of5Interleaved, - code2Of5Matrix, - code2Of5Standard, - code3Of9, - code3Of9extended, - code49, - code93, - dataMatrix, - ean13, - ean13add2, - ean13add5, - ean13pwcd, - ean8, - ean8add2, - ean8add5, - fim, - logmars, - maxicode, - msi, - pdf417, - pdf417macro, - plessey, - postAUSCust2, - postAUSCust3, - postAUSReplyPaid, - postAUSStandard, - postUKRM4SCC, - postUS5Zip, - postUSDPBC, - postUSIMB, - postUSStandard, - QRCode, - rfid, - rss14, - rss14Expanded, - rss14Limited, - rss14Stacked, - rss14StackedOmni, - rss14Truncated, - telepen, - ucc128, - ucc128random, - ucc128sscc, - upcA, - upcAadd2, - upcAadd5, - upcApwcd, - upcE, - upcEadd2, - upcEadd5, - upcean2, - upcean5, - upsMaxicode -}; - -struct BarCodeInfo { - uint32_t uHash; - const wchar_t* pName; - BarcodeType eName; - BC_TYPE eBCType; -}; - -class CXFA_FFBarcode : public CXFA_FFTextEdit { - public: - static const BarCodeInfo* GetBarcodeTypeByName(const CFX_WideStringC& wsName); - - explicit CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFBarcode() override; - - // CXFA_FFTextEdit - bool LoadWidget() override; - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - void UpdateWidgetProperty() override; - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFBARCODE_H_ diff --git a/xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp b/xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp deleted file mode 100644 index 65e44ade53..0000000000 --- a/xfa/fxfa/app/cxfa_ffbarcode_unittest.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "xfa/fxfa/app/cxfa_ffbarcode.h" - -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/base/ptr_util.h" - -TEST(XFA_FFBarcode, GetBarcodeTypeByName) { - EXPECT_EQ(nullptr, CXFA_FFBarcode::GetBarcodeTypeByName(L"")); - EXPECT_EQ(nullptr, CXFA_FFBarcode::GetBarcodeTypeByName(L"not_found")); - - auto* data = CXFA_FFBarcode::GetBarcodeTypeByName(L"ean13"); - ASSERT_NE(nullptr, data); - EXPECT_EQ(BarcodeType::ean13, data->eName); - - data = CXFA_FFBarcode::GetBarcodeTypeByName(L"pdf417"); - ASSERT_NE(nullptr, data); - EXPECT_EQ(BarcodeType::pdf417, data->eName); - - data = CXFA_FFBarcode::GetBarcodeTypeByName(L"code3Of9"); - ASSERT_NE(nullptr, data); - EXPECT_EQ(BarcodeType::code3Of9, data->eName); -} diff --git a/xfa/fxfa/app/cxfa_ffcheckbutton.cpp b/xfa/fxfa/app/cxfa_ffcheckbutton.cpp deleted file mode 100644 index c3fd6b9157..0000000000 --- a/xfa/fxfa/app/cxfa_ffcheckbutton.cpp +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" - -#include -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/cfwl_checkbox.h" -#include "xfa/fwl/cfwl_messagemouse.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/cxfa_ffexclgroup.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFCheckButton::~CXFA_FFCheckButton() {} - -bool CXFA_FFCheckButton::LoadWidget() { - auto pNew = pdfium::MakeUnique(GetFWLApp()); - CFWL_CheckBox* pCheckBox = pNew.get(); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - if (m_pDataAcc->IsRadioButton()) - pCheckBox->ModifyStylesEx(FWL_STYLEEXT_CKB_RadioButton, 0xFFFFFFFF); - - m_pNormalWidget->LockUpdate(); - UpdateWidgetProperty(); - SetFWLCheckState(m_pDataAcc->GetCheckState()); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFCheckButton::UpdateWidgetProperty() { - auto* pCheckBox = static_cast(m_pNormalWidget.get()); - if (!pCheckBox) - return; - - pCheckBox->SetBoxSize(m_pDataAcc->GetCheckButtonSize()); - uint32_t dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCross; - int32_t iCheckMark = m_pDataAcc->GetCheckButtonMark(); - switch (iCheckMark) { - case XFA_ATTRIBUTEENUM_Check: - dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCheck; - break; - case XFA_ATTRIBUTEENUM_Circle: - dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; - break; - case XFA_ATTRIBUTEENUM_Cross: - break; - case XFA_ATTRIBUTEENUM_Diamond: - dwStyleEx = FWL_STYLEEXT_CKB_SignShapeDiamond; - break; - case XFA_ATTRIBUTEENUM_Square: - dwStyleEx = FWL_STYLEEXT_CKB_SignShapeSquare; - break; - case XFA_ATTRIBUTEENUM_Star: - dwStyleEx = FWL_STYLEEXT_CKB_SignShapeStar; - break; - default: { - int32_t iShape = m_pDataAcc->GetCheckButtonShape(); - if (iShape == XFA_ATTRIBUTEENUM_Round) { - dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; - } - } break; - } - if (m_pDataAcc->IsAllowNeutral()) - dwStyleEx |= FWL_STYLEEXT_CKB_3State; - - pCheckBox->ModifyStylesEx( - dwStyleEx, FWL_STYLEEXT_CKB_SignShapeMask | FWL_STYLEEXT_CKB_3State); -} - -bool CXFA_FFCheckButton::PerformLayout() { - CXFA_FFWidget::PerformLayout(); - - float fCheckSize = m_pDataAcc->GetCheckButtonSize(); - CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); - CFX_RectF rtWidget = GetRectWithoutRotate(); - if (mgWidget) - XFA_RectWidthoutMargin(rtWidget, mgWidget); - - int32_t iCapPlacement = -1; - float fCapReserve = 0; - CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (caption && caption.GetPresence()) { - m_rtCaption = rtWidget; - iCapPlacement = caption.GetPlacementType(); - fCapReserve = caption.GetReserve(); - if (fCapReserve <= 0) { - if (iCapPlacement == XFA_ATTRIBUTEENUM_Top || - iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { - fCapReserve = rtWidget.height - fCheckSize; - } else { - fCapReserve = rtWidget.width - fCheckSize; - } - } - } - - int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; - int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; - if (CXFA_Para para = m_pDataAcc->GetPara()) { - iHorzAlign = para.GetHorizontalAlign(); - iVertAlign = para.GetVerticalAlign(); - } - - m_rtUI = rtWidget; - CXFA_Margin mgCap = caption.GetMargin(); - switch (iCapPlacement) { - case XFA_ATTRIBUTEENUM_Left: { - m_rtCaption.width = fCapReserve; - CapLeftRightPlacement(mgCap); - m_rtUI.width -= fCapReserve; - m_rtUI.left += fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Top: { - m_rtCaption.height = fCapReserve; - XFA_RectWidthoutMargin(m_rtCaption, mgCap); - m_rtUI.height -= fCapReserve; - m_rtUI.top += fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Right: { - m_rtCaption.left = m_rtCaption.right() - fCapReserve; - m_rtCaption.width = fCapReserve; - CapLeftRightPlacement(mgCap); - m_rtUI.width -= fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Bottom: { - m_rtCaption.top = m_rtCaption.bottom() - fCapReserve; - m_rtCaption.height = fCapReserve; - XFA_RectWidthoutMargin(m_rtCaption, mgCap); - m_rtUI.height -= fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Inline: - break; - default: - iHorzAlign = XFA_ATTRIBUTEENUM_Right; - break; - } - - if (iHorzAlign == XFA_ATTRIBUTEENUM_Center) - m_rtUI.left += (m_rtUI.width - fCheckSize) / 2; - else if (iHorzAlign == XFA_ATTRIBUTEENUM_Right) - m_rtUI.left = m_rtUI.right() - fCheckSize; - - if (iVertAlign == XFA_ATTRIBUTEENUM_Middle) - m_rtUI.top += (m_rtUI.height - fCheckSize) / 2; - else if (iVertAlign == XFA_ATTRIBUTEENUM_Bottom) - m_rtUI.top = m_rtUI.bottom() - fCheckSize; - - m_rtUI.width = fCheckSize; - m_rtUI.height = fCheckSize; - AddUIMargin(iCapPlacement); - m_rtCheckBox = m_rtUI; - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - if (borderUI) { - CXFA_Margin margin = borderUI.GetMargin(); - if (margin) - XFA_RectWidthoutMargin(m_rtUI, margin); - } - - m_rtUI.Normalize(); - LayoutCaption(); - SetFWLRect(); - if (m_pNormalWidget) - m_pNormalWidget->Update(); - - return true; -} - -void CXFA_FFCheckButton::CapLeftRightPlacement(CXFA_Margin mgCap) { - XFA_RectWidthoutMargin(m_rtCaption, mgCap); - if (m_rtCaption.height < 0) - m_rtCaption.top += m_rtCaption.height; - if (m_rtCaption.width < 0) { - m_rtCaption.left += m_rtCaption.width; - m_rtCaption.width = -m_rtCaption.width; - } -} - -void CXFA_FFCheckButton::AddUIMargin(int32_t iCapPlacement) { - CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); - m_rtUI.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2; - - float fLeftAddRight = rtUIMargin.left + rtUIMargin.width; - float fTopAddBottom = rtUIMargin.top + rtUIMargin.height; - if (m_rtUI.width < fLeftAddRight) { - if (iCapPlacement == XFA_ATTRIBUTEENUM_Right || - iCapPlacement == XFA_ATTRIBUTEENUM_Left) { - m_rtUI.left -= fLeftAddRight - m_rtUI.width; - } else { - m_rtUI.left -= 2 * (fLeftAddRight - m_rtUI.width); - } - m_rtUI.width += 2 * (fLeftAddRight - m_rtUI.width); - } - if (m_rtUI.height < fTopAddBottom) { - if (iCapPlacement == XFA_ATTRIBUTEENUM_Right) - m_rtUI.left -= fTopAddBottom - m_rtUI.height; - - m_rtUI.top -= fTopAddBottom - m_rtUI.height; - m_rtUI.height += 2 * (fTopAddBottom - m_rtUI.height); - } -} - -void CXFA_FFCheckButton::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - DrawBorder(pGS, borderUI, m_rtUI, &mtRotate, - m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round - ? XFA_DRAWBOX_ForceRound - : 0); - RenderCaption(pGS, &mtRotate); - DrawHighlight(pGS, &mtRotate, dwStatus, - m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round); - CFX_Matrix mt(1, 0, 0, 1, m_rtCheckBox.left, m_rtCheckBox.top); - mt.Concat(mtRotate); - GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, - &mt); -} - -bool CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, - const CFX_PointF& point) { - if (!m_pNormalWidget || !IsButtonDown()) - return false; - - SetButtonDown(false); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -XFA_CHECKSTATE CXFA_FFCheckButton::FWLState2XFAState() { - uint32_t dwState = m_pNormalWidget->GetStates(); - if (dwState & FWL_STATE_CKB_Checked) - return XFA_CHECKSTATE_On; - if (dwState & FWL_STATE_CKB_Neutral) - return XFA_CHECKSTATE_Neutral; - return XFA_CHECKSTATE_Off; -} - -bool CXFA_FFCheckButton::CommitData() { - XFA_CHECKSTATE eCheckState = FWLState2XFAState(); - m_pDataAcc->SetCheckState(eCheckState, true); - return true; -} - -bool CXFA_FFCheckButton::IsDataChanged() { - XFA_CHECKSTATE eCheckState = FWLState2XFAState(); - return m_pDataAcc->GetCheckState() != eCheckState; -} - -void CXFA_FFCheckButton::SetFWLCheckState(XFA_CHECKSTATE eCheckState) { - if (eCheckState == XFA_CHECKSTATE_Neutral) - m_pNormalWidget->SetStates(FWL_STATE_CKB_Neutral); - else if (eCheckState == XFA_CHECKSTATE_On) - m_pNormalWidget->SetStates(FWL_STATE_CKB_Checked); - else - m_pNormalWidget->RemoveStates(FWL_STATE_CKB_Checked); -} - -bool CXFA_FFCheckButton::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - XFA_CHECKSTATE eState = m_pDataAcc->GetCheckState(); - SetFWLCheckState(eState); - m_pNormalWidget->Update(); - return true; -} - -void CXFA_FFCheckButton::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - switch (pEvent->GetType()) { - case CFWL_Event::Type::CheckStateChanged: { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); - - CXFA_WidgetAcc* pFFExclGroup = m_pDataAcc->GetExclGroup(); - if (ProcessCommittedData()) { - eParam.m_pTarget = pFFExclGroup; - if (pFFExclGroup) { - m_pDocView->AddValidateWidget(pFFExclGroup); - m_pDocView->AddCalculateWidgetAcc(pFFExclGroup); - pFFExclGroup->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); - } - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); - } else { - SetFWLCheckState(m_pDataAcc->GetCheckState()); - } - if (pFFExclGroup) { - eParam.m_pTarget = pFFExclGroup; - pFFExclGroup->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); - } - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); - break; - } - default: - break; - } - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFCheckButton::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} diff --git a/xfa/fxfa/app/cxfa_ffcheckbutton.h b/xfa/fxfa/app/cxfa_ffcheckbutton.h deleted file mode 100644 index f092abbcf8..0000000000 --- a/xfa/fxfa/app/cxfa_ffcheckbutton.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFCHECKBUTTON_H_ -#define XFA_FXFA_APP_CXFA_FFCHECKBUTTON_H_ - -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/cxfa_ffpageview.h" - -class CXFA_FFCheckButton : public CXFA_FFField { - public: - explicit CXFA_FFCheckButton(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFCheckButton() override; - - // CXFA_FFField - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - - bool LoadWidget() override; - bool PerformLayout() override; - bool UpdateFWLData() override; - void UpdateWidgetProperty() override; - bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - void SetFWLCheckState(XFA_CHECKSTATE eCheckState); - - private: - bool CommitData() override; - bool IsDataChanged() override; - void CapLeftRightPlacement(CXFA_Margin mgCap); - void AddUIMargin(int32_t iCapPlacement); - XFA_CHECKSTATE FWLState2XFAState(); - - IFWL_WidgetDelegate* m_pOldDelegate; - CFX_RectF m_rtCheckBox; -}; - -#endif // XFA_FXFA_APP_CXFA_FFCHECKBUTTON_H_ diff --git a/xfa/fxfa/app/cxfa_ffcombobox.cpp b/xfa/fxfa/app/cxfa_ffcombobox.cpp deleted file mode 100644 index c317c1d90f..0000000000 --- a/xfa/fxfa/app/cxfa_ffcombobox.cpp +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffcombobox.h" - -#include -#include - -#include "xfa/fwl/cfwl_combobox.h" -#include "xfa/fwl/cfwl_eventselectchanged.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/cxfa_ffdocview.h" - -namespace { - -CFWL_ComboBox* ToComboBox(CFWL_Widget* widget) { - return static_cast(widget); -} - -} // namespace - -CXFA_FFComboBox::CXFA_FFComboBox(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFComboBox::~CXFA_FFComboBox() {} - -CFX_RectF CXFA_FFComboBox::GetBBox(uint32_t dwStatus, bool bDrawFocus) { - return bDrawFocus ? CFX_RectF() : CXFA_FFWidget::GetBBox(dwStatus); -} - -bool CXFA_FFComboBox::PtInActiveRect(const CFX_PointF& point) { - auto* pComboBox = ToComboBox(m_pNormalWidget.get()); - return pComboBox && pComboBox->GetBBox().Contains(point); -} - -bool CXFA_FFComboBox::LoadWidget() { - auto pNew = pdfium::MakeUnique(GetFWLApp()); - CFWL_ComboBox* pComboBox = pNew.get(); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) - pComboBox->AddString(label.AsStringC()); - - std::vector iSelArray = m_pDataAcc->GetSelectedItems(); - if (!iSelArray.empty()) { - pComboBox->SetCurSel(iSelArray.front()); - } else { - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); - pComboBox->SetEditText(wsText); - } - - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFComboBox::UpdateWidgetProperty() { - auto* pComboBox = ToComboBox(m_pNormalWidget.get()); - if (!pComboBox) - return; - - uint32_t dwExtendedStyle = 0; - uint32_t dwEditStyles = - FWL_STYLEEXT_EDT_ReadOnly | FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->IsChoiceListAllowTextEntry()) { - dwEditStyles &= ~FWL_STYLEEXT_EDT_ReadOnly; - dwExtendedStyle |= FWL_STYLEEXT_CMB_DropDown; - } - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; - dwExtendedStyle |= FWL_STYLEEXT_CMB_ReadOnly; - } - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; - - pComboBox->EditModifyStylesEx(dwEditStyles, 0xFFFFFFFF); -} - -bool CXFA_FFComboBox::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) - return false; - - GetDoc()->GetDocEnvironment()->PopupMenu(this, point); - return true; -} - -bool CXFA_FFComboBox::OnKillFocus(CXFA_FFWidget* pNewWidget) { - if (!ProcessCommittedData()) - UpdateFWLData(); - - CXFA_FFField::OnKillFocus(pNewWidget); - return true; -} - -void CXFA_FFComboBox::OpenDropDownList() { - ToComboBox(m_pNormalWidget.get())->OpenDropDownList(true); -} - -bool CXFA_FFComboBox::CommitData() { - return m_pDataAcc->SetValue(m_wsNewValue, XFA_VALUEPICTURE_Raw); -} - -bool CXFA_FFComboBox::IsDataChanged() { - auto* pFWLcombobox = ToComboBox(m_pNormalWidget.get()); - CFX_WideString wsText = pFWLcombobox->GetEditText(); - int32_t iCursel = pFWLcombobox->GetCurSel(); - if (iCursel >= 0) { - CFX_WideString wsSel = pFWLcombobox->GetTextByIndex(iCursel); - if (wsSel == wsText) - m_pDataAcc->GetChoiceListItem(wsText, iCursel, true); - } - - CFX_WideString wsOldValue; - m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Raw); - if (wsOldValue == wsText) - return false; - - m_wsNewValue = wsText; - return true; -} - -void CXFA_FFComboBox::FWLEventSelChange(CXFA_EventParam* pParam) { - pParam->m_eType = XFA_EVENT_Change; - pParam->m_pTarget = m_pDataAcc.Get(); - pParam->m_wsNewText = ToComboBox(m_pNormalWidget.get())->GetEditText(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, pParam); -} - -uint32_t CXFA_FFComboBox::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= - FWL_STYLEEXT_CMB_EditHCenter | FWL_STYLEEXT_CMB_ListItemCenterAlign; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditJustified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - break; - default: - dwExtendedStyle |= - FWL_STYLEEXT_CMB_EditHNear | FWL_STYLEEXT_CMB_ListItemLeftAlign; - break; - } - - switch (para.GetVerticalAlign()) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVNear; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFComboBox::UpdateFWLData() { - auto* pComboBox = ToComboBox(m_pNormalWidget.get()); - if (!pComboBox) - return false; - - std::vector iSelArray = m_pDataAcc->GetSelectedItems(); - if (!iSelArray.empty()) { - pComboBox->SetCurSel(iSelArray.front()); - } else { - CFX_WideString wsText; - pComboBox->SetCurSel(-1); - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); - pComboBox->SetEditText(wsText); - } - pComboBox->Update(); - return true; -} - -bool CXFA_FFComboBox::CanUndo() { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditCanUndo(); -} - -bool CXFA_FFComboBox::CanRedo() { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditCanRedo(); -} - -bool CXFA_FFComboBox::Undo() { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditUndo(); -} - -bool CXFA_FFComboBox::Redo() { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditRedo(); -} - -bool CXFA_FFComboBox::CanCopy() { - return ToComboBox(m_pNormalWidget.get())->EditCanCopy(); -} - -bool CXFA_FFComboBox::CanCut() { - return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open && - m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditCanCut(); -} - -bool CXFA_FFComboBox::CanPaste() { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open; -} - -bool CXFA_FFComboBox::CanSelectAll() { - return ToComboBox(m_pNormalWidget.get())->EditCanSelectAll(); -} - -bool CXFA_FFComboBox::Copy(CFX_WideString& wsCopy) { - return ToComboBox(m_pNormalWidget.get())->EditCopy(wsCopy); -} - -bool CXFA_FFComboBox::Cut(CFX_WideString& wsCut) { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditCut(wsCut); -} - -bool CXFA_FFComboBox::Paste(const CFX_WideString& wsPaste) { - return m_pDataAcc->IsChoiceListAllowTextEntry() && - ToComboBox(m_pNormalWidget.get())->EditPaste(wsPaste); -} - -void CXFA_FFComboBox::SelectAll() { - ToComboBox(m_pNormalWidget.get())->EditSelectAll(); -} - -void CXFA_FFComboBox::Delete() { - ToComboBox(m_pNormalWidget.get())->EditDelete(); -} - -void CXFA_FFComboBox::DeSelect() { - ToComboBox(m_pNormalWidget.get())->EditDeSelect(); -} - -void CXFA_FFComboBox::SetItemState(int32_t nIndex, bool bSelected) { - ToComboBox(m_pNormalWidget.get())->SetCurSel(bSelected ? nIndex : -1); - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFComboBox::InsertItem(const CFX_WideStringC& wsLabel, - int32_t nIndex) { - ToComboBox(m_pNormalWidget.get())->AddString(wsLabel); - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFComboBox::DeleteItem(int32_t nIndex) { - if (nIndex < 0) - ToComboBox(m_pNormalWidget.get())->RemoveAll(); - else - ToComboBox(m_pNormalWidget.get())->RemoveAt(nIndex); - - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFComboBox::OnTextChanged(CFWL_Widget* pWidget, - const CFX_WideString& wsChanged) { - CXFA_EventParam eParam; - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); - eParam.m_wsChange = wsChanged; - FWLEventSelChange(&eParam); -} - -void CXFA_FFComboBox::OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp) { - CXFA_EventParam eParam; - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); - FWLEventSelChange(&eParam); - if (m_pDataAcc->GetChoiceListCommitOn() == XFA_ATTRIBUTEENUM_Select && - bLButtonUp) { - m_pDocView->SetFocusWidgetAcc(nullptr); - } -} - -void CXFA_FFComboBox::OnPreOpen(CFWL_Widget* pWidget) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_PreOpen; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PreOpen, &eParam); -} - -void CXFA_FFComboBox::OnPostOpen(CFWL_Widget* pWidget) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_PostOpen; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PostOpen, &eParam); -} - -void CXFA_FFComboBox::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFComboBox::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - switch (pEvent->GetType()) { - case CFWL_Event::Type::SelectChanged: { - auto* postEvent = static_cast(pEvent); - OnSelectChanged(m_pNormalWidget.get(), postEvent->bLButtonUp); - break; - } - case CFWL_Event::Type::EditChanged: { - CFX_WideString wsChanged; - OnTextChanged(m_pNormalWidget.get(), wsChanged); - break; - } - case CFWL_Event::Type::PreDropDown: { - OnPreOpen(m_pNormalWidget.get()); - break; - } - case CFWL_Event::Type::PostDropDown: { - OnPostOpen(m_pNormalWidget.get()); - break; - } - default: - break; - } - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFComboBox::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} diff --git a/xfa/fxfa/app/cxfa_ffcombobox.h b/xfa/fxfa/app/cxfa_ffcombobox.h deleted file mode 100644 index de239b624a..0000000000 --- a/xfa/fxfa/app/cxfa_ffcombobox.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFCOMBOBOX_H_ -#define XFA_FXFA_APP_CXFA_FFCOMBOBOX_H_ - -#include "xfa/fxfa/app/cxfa_fffield.h" - -class CXFA_FFComboBox : public CXFA_FFField { - public: - explicit CXFA_FFComboBox(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFComboBox() override; - - // CXFA_FFField - CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; - bool LoadWidget() override; - void UpdateWidgetProperty() override; - bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; - bool CanUndo() override; - bool CanRedo() override; - bool Undo() override; - bool Redo() override; - - bool CanCopy() override; - bool CanCut() override; - bool CanPaste() override; - bool CanSelectAll() override; - bool Copy(CFX_WideString& wsCopy) override; - bool Cut(CFX_WideString& wsCut) override; - bool Paste(const CFX_WideString& wsPaste) override; - void SelectAll() override; - void Delete() override; - void DeSelect() override; - - // IFWL_WidgetDelegate - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - virtual void OpenDropDownList(); - - void OnTextChanged(CFWL_Widget* pWidget, const CFX_WideString& wsChanged); - void OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp); - void OnPreOpen(CFWL_Widget* pWidget); - void OnPostOpen(CFWL_Widget* pWidget); - void SetItemState(int32_t nIndex, bool bSelected); - void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex); - void DeleteItem(int32_t nIndex); - - private: - // CXFA_FFField - bool PtInActiveRect(const CFX_PointF& point) override; - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - - uint32_t GetAlignment(); - void FWLEventSelChange(CXFA_EventParam* pParam); - - CFX_WideString m_wsNewValue; - IFWL_WidgetDelegate* m_pOldDelegate; -}; - -#endif // XFA_FXFA_APP_CXFA_FFCOMBOBOX_H_ diff --git a/xfa/fxfa/app/cxfa_ffdatetimeedit.cpp b/xfa/fxfa/app/cxfa_ffdatetimeedit.cpp deleted file mode 100644 index 10a7b189f6..0000000000 --- a/xfa/fxfa/app/cxfa_ffdatetimeedit.cpp +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffdatetimeedit.h" - -#include - -#include "xfa/fwl/cfwl_datetimepicker.h" -#include "xfa/fwl/cfwl_eventselectchanged.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/parser/cxfa_localevalue.h" - -CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {} - -CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) { - if (bDrawFocus) - return CFX_RectF(); - return CXFA_FFWidget::GetBBox(dwStatus); -} - -bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) { - auto* pPicker = static_cast(m_pNormalWidget.get()); - return pPicker && pPicker->GetBBox().Contains(point); -} - -bool CXFA_FFDateTimeEdit::LoadWidget() { - auto pNewPicker = pdfium::MakeUnique(GetFWLApp()); - CFWL_DateTimePicker* pWidget = pNewPicker.get(); - m_pNormalWidget = std::move(pNewPicker); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetEditText(wsText); - if (CXFA_Value value = m_pDataAcc->GetFormValue()) { - switch (value.GetChildValueClassID()) { - case XFA_Element::Date: { - if (!wsText.IsEmpty()) { - CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - CFX_DateTime date = lcValue.GetDate(); - if (date.IsSet()) - pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); - } - } break; - default: - break; - } - } - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { - CFWL_DateTimePicker* pWidget = - static_cast(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat; - dwExtendedStyle |= UpdateUIProperty(); - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - uint32_t dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight; - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells > 0) { - dwEditStyles |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetEditLimit(iNumCells); - } - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; - } - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; - - pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); -} - -uint32_t CXFA_FFDateTimeEdit::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; - break; - } - - switch (para.GetVerticalAlign()) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFDateTimeEdit::CommitData() { - auto* pPicker = static_cast(m_pNormalWidget.get()); - if (!m_pDataAcc->SetValue(pPicker->GetEditText(), XFA_VALUEPICTURE_Edit)) - return false; - - m_pDataAcc->UpdateUIDisplay(this); - return true; -} - -bool CXFA_FFDateTimeEdit::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; - if (IsFocused()) - eType = XFA_VALUEPICTURE_Edit; - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, eType); - - auto* normalWidget = static_cast(m_pNormalWidget.get()); - normalWidget->SetEditText(wsText); - if (IsFocused() && !wsText.IsEmpty()) { - CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - CFX_DateTime date = lcValue.GetDate(); - if (lcValue.IsValid()) { - if (date.IsSet()) - normalWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); - } - } - m_pNormalWidget->Update(); - return true; -} - -bool CXFA_FFDateTimeEdit::IsDataChanged() { - if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) - return true; - - CFX_WideString wsText = - static_cast(m_pNormalWidget.get())->GetEditText(); - CFX_WideString wsOldValue; - m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); - return wsOldValue != wsText; -} - -void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, - int32_t iYear, - int32_t iMonth, - int32_t iDay) { - CFX_WideString wsPicture; - m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); - - CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); - date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); - - CFX_WideString wsDate; - date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), - XFA_VALUEPICTURE_Edit); - - auto* pDateTime = static_cast(m_pNormalWidget.get()); - pDateTime->SetEditText(wsDate); - pDateTime->Update(); - GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); - - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); -} - -void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { - if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { - auto* event = static_cast(pEvent); - OnSelectChanged(m_pNormalWidget.get(), event->iYear, event->iMonth, - event->iDay); - return; - } - CXFA_FFTextEdit::OnProcessEvent(pEvent); -} diff --git a/xfa/fxfa/app/cxfa_ffdatetimeedit.h b/xfa/fxfa/app/cxfa_ffdatetimeedit.h deleted file mode 100644 index c62f657fab..0000000000 --- a/xfa/fxfa/app/cxfa_ffdatetimeedit.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFDATETIMEEDIT_H_ -#define XFA_FXFA_APP_CXFA_FFDATETIMEEDIT_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "xfa/fxfa/app/cxfa_fftextedit.h" - -enum XFA_DATETIMETYPE { - XFA_DATETIMETYPE_Date = 0, - XFA_DATETIMETYPE_Time, - XFA_DATETIMETYPE_DateAndTime -}; - -class CFWL_Event; -class CFWL_Widget; - -class CXFA_FFDateTimeEdit : public CXFA_FFTextEdit { - public: - explicit CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFDateTimeEdit() override; - - // CXFA_FFTextEdit - CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; - bool LoadWidget() override; - void UpdateWidgetProperty() override; - void OnProcessEvent(CFWL_Event* pEvent) override; - - void OnSelectChanged(CFWL_Widget* pWidget, - int32_t iYear, - int32_t iMonth, - int32_t iDay); - - private: - bool PtInActiveRect(const CFX_PointF& point) override; - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - - uint32_t GetAlignment(); -}; - -#endif // XFA_FXFA_APP_CXFA_FFDATETIMEEDIT_H_ diff --git a/xfa/fxfa/app/cxfa_ffdraw.cpp b/xfa/fxfa/app/cxfa_ffdraw.cpp deleted file mode 100644 index 5736e77352..0000000000 --- a/xfa/fxfa/app/cxfa_ffdraw.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffdraw.h" - -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFDraw::CXFA_FFDraw(CXFA_WidgetAcc* pDataAcc) : CXFA_FFWidget(pDataAcc) {} - -CXFA_FFDraw::~CXFA_FFDraw() {} diff --git a/xfa/fxfa/app/cxfa_ffdraw.h b/xfa/fxfa/app/cxfa_ffdraw.h deleted file mode 100644 index 2a65ad0a78..0000000000 --- a/xfa/fxfa/app/cxfa_ffdraw.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFDRAW_H_ -#define XFA_FXFA_APP_CXFA_FFDRAW_H_ - -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -class CXFA_FFDraw : public CXFA_FFWidget { - public: - explicit CXFA_FFDraw(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFDraw() override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFDRAW_H_ diff --git a/xfa/fxfa/app/cxfa_ffexclgroup.cpp b/xfa/fxfa/app/cxfa_ffexclgroup.cpp deleted file mode 100644 index c881a79468..0000000000 --- a/xfa/fxfa/app/cxfa_ffexclgroup.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffexclgroup.h" - -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFExclGroup::CXFA_FFExclGroup(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFWidget(pDataAcc) {} - -CXFA_FFExclGroup::~CXFA_FFExclGroup() {} - -void CXFA_FFExclGroup::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); -} diff --git a/xfa/fxfa/app/cxfa_ffexclgroup.h b/xfa/fxfa/app/cxfa_ffexclgroup.h deleted file mode 100644 index 3575ad38af..0000000000 --- a/xfa/fxfa/app/cxfa_ffexclgroup.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFEXCLGROUP_H_ -#define XFA_FXFA_APP_CXFA_FFEXCLGROUP_H_ - -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -class CXFA_FFExclGroup : public CXFA_FFWidget { - public: - explicit CXFA_FFExclGroup(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFExclGroup() override; - - // CXFA_FFWidget - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFEXCLGROUP_H_ diff --git a/xfa/fxfa/app/cxfa_fffield.cpp b/xfa/fxfa/app/cxfa_fffield.cpp deleted file mode 100644 index bf98b99a8e..0000000000 --- a/xfa/fxfa/app/cxfa_fffield.cpp +++ /dev/null @@ -1,785 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_fffield.h" - -#include "xfa/fwl/cfwl_edit.h" -#include "xfa/fwl/cfwl_eventmouse.h" -#include "xfa/fwl/cfwl_messagekey.h" -#include "xfa/fwl/cfwl_messagekillfocus.h" -#include "xfa/fwl/cfwl_messagemouse.h" -#include "xfa/fwl/cfwl_messagemousewheel.h" -#include "xfa/fwl/cfwl_messagesetfocus.h" -#include "xfa/fwl/cfwl_picturebox.h" -#include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/cxfa_fwltheme.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxgraphics/cxfa_color.h" -#include "xfa/fxgraphics/cxfa_path.h" - -namespace { - -CXFA_FFField* ToField(CXFA_LayoutItem* widget) { - return static_cast(widget); -} - -} // namespace - -CXFA_FFField::CXFA_FFField(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFWidget(pDataAcc), m_pNormalWidget(nullptr) {} - -CXFA_FFField::~CXFA_FFField() { - CXFA_FFField::UnloadWidget(); -} - -CFX_RectF CXFA_FFField::GetBBox(uint32_t dwStatus, bool bDrawFocus) { - if (!bDrawFocus) - return CXFA_FFWidget::GetBBox(dwStatus); - - XFA_Element type = m_pDataAcc->GetUIType(); - if (type != XFA_Element::Button && type != XFA_Element::CheckButton && - type != XFA_Element::ImageEdit && type != XFA_Element::Signature && - type != XFA_Element::ChoiceList) { - return CFX_RectF(); - } - - CFX_RectF rtBox = m_rtUI; - GetRotateMatrix().TransformRect(rtBox); - return rtBox; -} - -void CXFA_FFField::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); - RenderCaption(pGS, &mtRotate); - DrawHighlight(pGS, &mtRotate, dwStatus, false); - - CFX_RectF rtWidget = m_pNormalWidget->GetWidgetRect(); - CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); - mt.Concat(mtRotate); - GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, - &mt); -} - -void CXFA_FFField::DrawHighlight(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus, - bool bEllipse) { - if (m_rtUI.IsEmpty() || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) - return; - - if (!(dwStatus & XFA_WidgetStatus_Highlight) || - m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { - return; - } - - CXFA_FFDoc* pDoc = GetDoc(); - CXFA_Color crHighlight(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc)); - pGS->SetFillColor(&crHighlight); - CXFA_Path path; - if (bEllipse) - path.AddEllipse(m_rtUI); - else - path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); - - pGS->FillPath(&path, FXFILL_WINDING, pMatrix); -} - -void CXFA_FFField::DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { - if (!(m_dwStatus & XFA_WidgetStatus_Focused)) - return; - - CXFA_Color cr(0xFF000000); - pGS->SetStrokeColor(&cr); - - float DashPattern[2] = {1, 1}; - pGS->SetLineDash(0.0f, DashPattern, 2); - pGS->SetLineWidth(0, false); - - CXFA_Path path; - path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); - pGS->StrokePath(&path, pMatrix); -} - -void CXFA_FFField::SetFWLThemeProvider() { - if (m_pNormalWidget) - m_pNormalWidget->SetThemeProvider(GetApp()->GetFWLTheme()); -} - -bool CXFA_FFField::IsLoaded() { - return m_pNormalWidget && CXFA_FFWidget::IsLoaded(); -} - -bool CXFA_FFField::LoadWidget() { - SetFWLThemeProvider(); - m_pDataAcc->LoadCaption(); - PerformLayout(); - return true; -} - -void CXFA_FFField::UnloadWidget() { - m_pNormalWidget.reset(); -} - -void CXFA_FFField::SetEditScrollOffset() { - XFA_Element eType = m_pDataAcc->GetUIType(); - if (eType != XFA_Element::TextEdit && eType != XFA_Element::NumericEdit && - eType != XFA_Element::PasswordEdit) { - return; - } - - float fScrollOffset = 0; - CXFA_FFField* pPrev = ToField(GetPrev()); - if (pPrev) { - CFX_RectF rtMargin = m_pDataAcc->GetUIMargin(); - fScrollOffset = -rtMargin.top; - } - - while (pPrev) { - fScrollOffset += pPrev->m_rtUI.height; - pPrev = ToField(pPrev->GetPrev()); - } - static_cast(m_pNormalWidget.get()) - ->SetScrollOffset(fScrollOffset); -} - -bool CXFA_FFField::PerformLayout() { - CXFA_FFWidget::PerformLayout(); - CapPlacement(); - LayoutCaption(); - SetFWLRect(); - SetEditScrollOffset(); - if (m_pNormalWidget) - m_pNormalWidget->Update(); - return true; -} - -void CXFA_FFField::CapPlacement() { - CFX_RectF rtWidget = GetRectWithoutRotate(); - CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); - if (mgWidget) { - CXFA_LayoutItem* pItem = this; - float fLeftInset = 0, fRightInset = 0, fTopInset = 0, fBottomInset = 0; - mgWidget.GetLeftInset(fLeftInset); - mgWidget.GetRightInset(fRightInset); - mgWidget.GetTopInset(fTopInset); - mgWidget.GetBottomInset(fBottomInset); - if (!pItem->GetPrev() && !pItem->GetNext()) { - rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); - } else { - if (!pItem->GetPrev()) - rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, 0); - else if (!pItem->GetNext()) - rtWidget.Deflate(fLeftInset, 0, fRightInset, fBottomInset); - else - rtWidget.Deflate(fLeftInset, 0, fRightInset, 0); - } - } - - XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; - float fCapReserve = 0; - CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { - iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); - if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && GetPrev()) { - m_rtCaption.Reset(); - } else if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && GetNext()) { - m_rtCaption.Reset(); - } else { - fCapReserve = caption.GetReserve(); - CXFA_LayoutItem* pItem = this; - if (!pItem->GetPrev() && !pItem->GetNext()) { - m_rtCaption = rtWidget; - } else { - pItem = pItem->GetFirst(); - m_rtCaption = pItem->GetRect(false); - pItem = pItem->GetNext(); - while (pItem) { - m_rtCaption.height += pItem->GetRect(false).Height(); - pItem = pItem->GetNext(); - } - XFA_RectWidthoutMargin(m_rtCaption, mgWidget); - } - - CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); - if (fCapReserve <= 0 && pCapTextLayout) { - CFX_SizeF size; - CFX_SizeF minSize; - CFX_SizeF maxSize; - pCapTextLayout->CalcSize(minSize, maxSize, size); - if (iCapPlacement == XFA_ATTRIBUTEENUM_Top || - iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { - fCapReserve = size.height; - } else { - fCapReserve = size.width; - } - } - } - } - - m_rtUI = rtWidget; - switch (iCapPlacement) { - case XFA_ATTRIBUTEENUM_Left: { - m_rtCaption.width = fCapReserve; - CapLeftRightPlacement(caption, rtWidget, iCapPlacement); - m_rtUI.width -= fCapReserve; - m_rtUI.left += fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Top: { - m_rtCaption.height = fCapReserve; - CapTopBottomPlacement(caption, rtWidget, iCapPlacement); - m_rtUI.top += fCapReserve; - m_rtUI.height -= fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Right: { - m_rtCaption.left = m_rtCaption.right() - fCapReserve; - m_rtCaption.width = fCapReserve; - CapLeftRightPlacement(caption, rtWidget, iCapPlacement); - m_rtUI.width -= fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Bottom: { - m_rtCaption.top = m_rtCaption.bottom() - fCapReserve; - m_rtCaption.height = fCapReserve; - CapTopBottomPlacement(caption, rtWidget, iCapPlacement); - m_rtUI.height -= fCapReserve; - break; - } - case XFA_ATTRIBUTEENUM_Inline: - break; - default: - break; - } - - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - if (borderUI) { - CXFA_Margin margin = borderUI.GetMargin(); - if (margin) - XFA_RectWidthoutMargin(m_rtUI, margin); - } - m_rtUI.Normalize(); -} - -void CXFA_FFField::CapTopBottomPlacement(CXFA_Caption caption, - const CFX_RectF& rtWidget, - int32_t iCapPlacement) { - CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); - m_rtCaption.left += rtUIMargin.left; - if (CXFA_Margin mgCap = caption.GetMargin()) { - XFA_RectWidthoutMargin(m_rtCaption, mgCap); - if (m_rtCaption.height < 0) - m_rtCaption.top += m_rtCaption.height; - } - - float fWidth = rtUIMargin.left + rtUIMargin.width; - float fHeight = m_rtCaption.height + rtUIMargin.top + rtUIMargin.height; - if (fWidth > rtWidget.width) - m_rtUI.width += fWidth - rtWidget.width; - - if (fHeight == XFA_DEFAULTUI_HEIGHT && m_rtUI.height < XFA_MINUI_HEIGHT) { - m_rtUI.height = XFA_MINUI_HEIGHT; - m_rtCaption.top += rtUIMargin.top + rtUIMargin.height; - } else if (fHeight > rtWidget.height) { - m_rtUI.height += fHeight - rtWidget.height; - if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) - m_rtCaption.top += fHeight - rtWidget.height; - } -} - -void CXFA_FFField::CapLeftRightPlacement(CXFA_Caption caption, - const CFX_RectF& rtWidget, - int32_t iCapPlacement) { - CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); - m_rtCaption.top += rtUIMargin.top; - m_rtCaption.height -= rtUIMargin.top; - if (CXFA_Margin mgCap = caption.GetMargin()) { - XFA_RectWidthoutMargin(m_rtCaption, mgCap); - if (m_rtCaption.height < 0) - m_rtCaption.top += m_rtCaption.height; - } - - float fWidth = m_rtCaption.width + rtUIMargin.left + rtUIMargin.width; - float fHeight = rtUIMargin.top + rtUIMargin.height; - if (fWidth > rtWidget.width) { - m_rtUI.width += fWidth - rtWidget.width; - if (iCapPlacement == XFA_ATTRIBUTEENUM_Right) - m_rtCaption.left += fWidth - rtWidget.width; - } - - if (fHeight == XFA_DEFAULTUI_HEIGHT && m_rtUI.height < XFA_MINUI_HEIGHT) { - m_rtUI.height = XFA_MINUI_HEIGHT; - m_rtCaption.top += rtUIMargin.top + rtUIMargin.height; - } else if (fHeight > rtWidget.height) { - m_rtUI.height += fHeight - rtWidget.height; - } -} - -void CXFA_FFField::UpdateFWL() { - if (m_pNormalWidget) - m_pNormalWidget->Update(); -} - -uint32_t CXFA_FFField::UpdateUIProperty() { - CXFA_Node* pUiNode = m_pDataAcc->GetUIChild(); - if (pUiNode && pUiNode->GetElementType() == XFA_Element::DefaultUi) - return FWL_STYLEEXT_EDT_ReadOnly; - return 0; -} - -void CXFA_FFField::SetFWLRect() { - if (!m_pNormalWidget) - return; - - CFX_RectF rtUi = m_rtUI; - if (rtUi.width < 1.0) - rtUi.width = 1.0; - if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - float fFontSize = m_pDataAcc->GetFontSize(); - if (rtUi.height < fFontSize) - rtUi.height = fFontSize; - } - m_pNormalWidget->SetWidgetRect(rtUi); -} - -bool CXFA_FFField::OnMouseEnter() { - if (!m_pNormalWidget) - return false; - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::Enter; - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnMouseExit() { - if (!m_pNormalWidget) - return false; - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::Leave; - TranslateFWLMessage(&ms); - return true; -} - -CFX_PointF CXFA_FFField::FWLToClient(const CFX_PointF& point) { - return m_pNormalWidget ? point - m_pNormalWidget->GetWidgetRect().TopLeft() - : point; -} - -bool CXFA_FFField::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - return false; - } - if (!PtInActiveRect(point)) - return false; - - SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - if (!IsButtonDown()) - return false; - - SetButtonDown(false); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonDblClk; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::Move; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnMouseWheel(uint32_t dwFlags, - int16_t zDelta, - const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - - CFWL_MessageMouseWheel ms(nullptr, m_pNormalWidget.get()); - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - ms.m_delta = CFX_PointF(zDelta, 0); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - return false; - } - if (!PtInActiveRect(point)) - return false; - - SetButtonDown(true); - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - if (!IsButtonDown()) - return false; - - SetButtonDown(false); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::RightButtonUp; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { - if (!m_pNormalWidget) - return false; - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::RightButtonDblClk; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnSetFocus(CXFA_FFWidget* pOldWidget) { - CXFA_FFWidget::OnSetFocus(pOldWidget); - if (!m_pNormalWidget) - return false; - - CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); - TranslateFWLMessage(&ms); - m_dwStatus |= XFA_WidgetStatus_Focused; - AddInvalidateRect(); - return true; -} - -bool CXFA_FFField::OnKillFocus(CXFA_FFWidget* pNewWidget) { - if (!m_pNormalWidget) - return CXFA_FFWidget::OnKillFocus(pNewWidget); - - CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); - TranslateFWLMessage(&ms); - m_dwStatus &= ~XFA_WidgetStatus_Focused; - AddInvalidateRect(); - CXFA_FFWidget::OnKillFocus(pNewWidget); - return true; -} - -bool CXFA_FFField::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { - if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) - return false; - - CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_KeyCommand::KeyDown; - ms.m_dwFlags = dwFlags; - ms.m_dwKeyCode = dwKeyCode; - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { - if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) - return false; - - CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_KeyCommand::KeyUp; - ms.m_dwFlags = dwFlags; - ms.m_dwKeyCode = dwKeyCode; - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFField::OnChar(uint32_t dwChar, uint32_t dwFlags) { - if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) - return false; - if (dwChar == FWL_VKEY_Tab) - return true; - if (!m_pNormalWidget) - return false; - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) - return false; - - CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_KeyCommand::Char; - ms.m_dwFlags = dwFlags; - ms.m_dwKeyCode = dwChar; - TranslateFWLMessage(&ms); - return true; -} - -FWL_WidgetHit CXFA_FFField::OnHitTest(const CFX_PointF& point) { - if (m_pNormalWidget && - m_pNormalWidget->HitTest(FWLToClient(point)) != FWL_WidgetHit::Unknown) { - return FWL_WidgetHit::Client; - } - - if (!GetRectWithoutRotate().Contains(point)) - return FWL_WidgetHit::Unknown; - if (m_rtCaption.Contains(point)) - return FWL_WidgetHit::Titlebar; - return FWL_WidgetHit::Border; -} - -bool CXFA_FFField::OnSetCursor(const CFX_PointF& point) { - return true; -} - -bool CXFA_FFField::PtInActiveRect(const CFX_PointF& point) { - return m_pNormalWidget && m_pNormalWidget->GetWidgetRect().Contains(point); -} - -void CXFA_FFField::LayoutCaption() { - CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); - if (!pCapTextLayout) - return; - - float fHeight = 0; - pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height), - &fHeight); - if (m_rtCaption.height < fHeight) - m_rtCaption.height = fHeight; -} - -void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { - CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); - if (!pCapTextLayout) - return; - - CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) - return; - - if (!pCapTextLayout->IsLoaded()) - pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height)); - - CFX_RectF rtClip = m_rtCaption; - rtClip.Intersect(GetRectWithoutRotate()); - CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); - CFX_Matrix mt(1, 0, 0, 1, m_rtCaption.left, m_rtCaption.top); - if (pMatrix) { - pMatrix->TransformRect(rtClip); - mt.Concat(*pMatrix); - } - pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); -} - -bool CXFA_FFField::ProcessCommittedData() { - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) - return false; - if (!IsDataChanged()) - return false; - if (CalculateOverride() != 1) - return false; - if (!CommitData()) - return false; - - m_pDocView->SetChangeMark(); - m_pDocView->AddValidateWidget(m_pDataAcc.Get()); - return true; -} - -int32_t CXFA_FFField::CalculateOverride() { - CXFA_WidgetAcc* pAcc = m_pDataAcc->GetExclGroup(); - if (!pAcc) - return CalculateWidgetAcc(m_pDataAcc.Get()); - if (CalculateWidgetAcc(pAcc) == 0) - return 0; - - CXFA_Node* pNode = pAcc->GetExclGroupFirstMember(); - if (!pNode) - return 1; - - CXFA_WidgetAcc* pWidgetAcc = nullptr; - while (pNode) { - pWidgetAcc = static_cast(pNode->GetWidgetData()); - if (!pWidgetAcc) - return 1; - if (CalculateWidgetAcc(pWidgetAcc) == 0) - return 0; - - pNode = pWidgetAcc->GetExclGroupNextMember(pNode); - } - return 1; -} - -int32_t CXFA_FFField::CalculateWidgetAcc(CXFA_WidgetAcc* pAcc) { - CXFA_Calculate calc = pAcc->GetCalculate(); - if (!calc) - return 1; - - XFA_VERSION version = pAcc->GetDoc()->GetXFADoc()->GetCurVersionMode(); - switch (calc.GetOverride()) { - case XFA_ATTRIBUTEENUM_Error: { - if (version <= XFA_VERSION_204) - return 1; - - IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); - if (pAppProvider) { - pAppProvider->MsgBox(L"You are not allowed to modify this field.", - L"Calculate Override", XFA_MBICON_Warning, - XFA_MB_OK); - } - return 0; - } - case XFA_ATTRIBUTEENUM_Warning: { - if (version <= XFA_VERSION_204) { - CXFA_Script script = calc.GetScript(); - if (!script) - return 1; - - CFX_WideString wsExpression; - script.GetExpression(wsExpression); - if (wsExpression.IsEmpty()) - return 1; - } - - if (pAcc->GetNode()->IsUserInteractive()) - return 1; - - IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); - if (!pAppProvider) - return 0; - - CFX_WideString wsMessage; - calc.GetMessageText(wsMessage); - if (!wsMessage.IsEmpty()) - wsMessage += L"\r\n"; - - wsMessage += L"Are you sure you want to modify this field?"; - if (pAppProvider->MsgBox(wsMessage, L"Calculate Override", - XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) { - pAcc->GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); - return 1; - } - return 0; - } - case XFA_ATTRIBUTEENUM_Ignore: - return 0; - case XFA_ATTRIBUTEENUM_Disabled: - pAcc->GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); - return 1; - default: - return 1; - } -} - -bool CXFA_FFField::CommitData() { - return false; -} - -bool CXFA_FFField::IsDataChanged() { - return false; -} - -void CXFA_FFField::TranslateFWLMessage(CFWL_Message* pMessage) { - GetApp()->GetWidgetMgrDelegate()->OnProcessMessageToForm(pMessage); -} - -void CXFA_FFField::OnProcessMessage(CFWL_Message* pMessage) {} - -void CXFA_FFField::OnProcessEvent(CFWL_Event* pEvent) { - switch (pEvent->GetType()) { - case CFWL_Event::Type::Mouse: { - CFWL_EventMouse* event = static_cast(pEvent); - if (event->m_dwCmd == FWL_MouseCommand::Enter) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_MouseEnter; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseEnter, &eParam); - } else if (event->m_dwCmd == FWL_MouseCommand::Leave) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_MouseExit; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseExit, &eParam); - } else if (event->m_dwCmd == FWL_MouseCommand::LeftButtonDown) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_MouseDown; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseDown, &eParam); - } else if (event->m_dwCmd == FWL_MouseCommand::LeftButtonUp) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_MouseUp; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseUp, &eParam); - } - break; - } - case CFWL_Event::Type::Click: { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Click; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); - break; - } - default: - break; - } -} - -void CXFA_FFField::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) {} diff --git a/xfa/fxfa/app/cxfa_fffield.h b/xfa/fxfa/app/cxfa_fffield.h deleted file mode 100644 index d2eba09a62..0000000000 --- a/xfa/fxfa/app/cxfa_fffield.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFFIELD_H_ -#define XFA_FXFA_APP_CXFA_FFFIELD_H_ - -#include - -#include "xfa/fwl/cfwl_widget.h" -#include "xfa/fwl/ifwl_widgetdelegate.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -#define XFA_MINUI_HEIGHT 4.32f -#define XFA_DEFAULTUI_HEIGHT 2.0f - -class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { - public: - explicit CXFA_FFField(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFField() override; - - // CXFA_FFWidget - CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - bool IsLoaded() override; - bool LoadWidget() override; - void UnloadWidget() override; - bool PerformLayout() override; - bool OnMouseEnter() override; - bool OnMouseExit() override; - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnMouseWheel(uint32_t dwFlags, - int16_t zDelta, - const CFX_PointF& point) override; - bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; - - bool OnSetFocus(CXFA_FFWidget* pOldWidget) override; - bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; - bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) override; - bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) override; - bool OnChar(uint32_t dwChar, uint32_t dwFlags) override; - FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; - bool OnSetCursor(const CFX_PointF& point) override; - - // IFWL_WidgetDelegate - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - void UpdateFWL(); - uint32_t UpdateUIProperty(); - - protected: - bool PtInActiveRect(const CFX_PointF& point) override; - - virtual void SetFWLRect(); - void SetFWLThemeProvider(); - CFWL_Widget* GetNormalWidget() { return m_pNormalWidget.get(); } - CFX_PointF FWLToClient(const CFX_PointF& point); - void LayoutCaption(); - void RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); - - int32_t CalculateOverride(); - int32_t CalculateWidgetAcc(CXFA_WidgetAcc* pAcc); - bool ProcessCommittedData(); - virtual bool CommitData(); - virtual bool IsDataChanged(); - void DrawHighlight(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus, - bool bEllipse); - void DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); - void TranslateFWLMessage(CFWL_Message* pMessage); - void CapPlacement(); - void CapTopBottomPlacement(CXFA_Caption caption, - const CFX_RectF& rtWidget, - int32_t iCapPlacement); - void CapLeftRightPlacement(CXFA_Caption caption, - const CFX_RectF& rtWidget, - int32_t iCapPlacement); - void SetEditScrollOffset(); - - std::unique_ptr m_pNormalWidget; - CFX_RectF m_rtUI; - CFX_RectF m_rtCaption; -}; - -#endif // XFA_FXFA_APP_CXFA_FFFIELD_H_ diff --git a/xfa/fxfa/app/cxfa_ffimage.cpp b/xfa/fxfa/app/cxfa_ffimage.cpp deleted file mode 100644 index cfcc9d6d7d..0000000000 --- a/xfa/fxfa/app/cxfa_ffimage.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffimage.h" - -#include "xfa/fxfa/app/cxfa_ffdraw.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFImage::CXFA_FFImage(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFImage::~CXFA_FFImage() { - CXFA_FFImage::UnloadWidget(); -} - -bool CXFA_FFImage::IsLoaded() { - return !!GetDataAcc()->GetImageImage(); -} - -bool CXFA_FFImage::LoadWidget() { - if (GetDataAcc()->GetImageImage()) - return true; - - GetDataAcc()->LoadImageImage(); - return CXFA_FFDraw::LoadWidget(); -} - -void CXFA_FFImage::UnloadWidget() { - GetDataAcc()->SetImageImage(nullptr); -} - -void CXFA_FFImage::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - - CFX_RetainPtr pDIBitmap = GetDataAcc()->GetImageImage(); - if (!pDIBitmap) - return; - - CFX_RectF rtImage = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rtImage, mgWidget); - - int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; - int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; - if (CXFA_Para para = m_pDataAcc->GetPara()) { - iHorzAlign = para.GetHorizontalAlign(); - iVertAlign = para.GetVerticalAlign(); - } - - CXFA_Value value = m_pDataAcc->GetFormValue(); - CXFA_Image imageObj = value.GetImage(); - int32_t iAspect = imageObj.GetAspect(); - int32_t iImageXDpi = 0; - int32_t iImageYDpi = 0; - m_pDataAcc->GetImageDpi(iImageXDpi, iImageYDpi); - XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, - iImageYDpi, iHorzAlign, iVertAlign); -} diff --git a/xfa/fxfa/app/cxfa_ffimage.h b/xfa/fxfa/app/cxfa_ffimage.h deleted file mode 100644 index aaa5df4048..0000000000 --- a/xfa/fxfa/app/cxfa_ffimage.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFIMAGE_H_ -#define XFA_FXFA_APP_CXFA_FFIMAGE_H_ - -#include "xfa/fxfa/app/cxfa_ffdraw.h" - -class CXFA_FFImage : public CXFA_FFDraw { - public: - explicit CXFA_FFImage(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFImage() override; - - // CXFA_FFWidget - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - bool IsLoaded() override; - bool LoadWidget() override; - void UnloadWidget() override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFIMAGE_H_ diff --git a/xfa/fxfa/app/cxfa_ffimageedit.cpp b/xfa/fxfa/app/cxfa_ffimageedit.cpp deleted file mode 100644 index 4019dd11d8..0000000000 --- a/xfa/fxfa/app/cxfa_ffimageedit.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffimageedit.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/cfwl_app.h" -#include "xfa/fwl/cfwl_messagemouse.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fwl/cfwl_picturebox.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFImageEdit::CXFA_FFImageEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFImageEdit::~CXFA_FFImageEdit() { - CXFA_FFImageEdit::UnloadWidget(); -} - -bool CXFA_FFImageEdit::LoadWidget() { - auto pNew = pdfium::MakeUnique(GetFWLApp()); - CFWL_PictureBox* pPictureBox = pNew.get(); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = pPictureBox->GetDelegate(); - pPictureBox->SetDelegate(this); - - CXFA_FFField::LoadWidget(); - if (!m_pDataAcc->GetImageEditImage()) - UpdateFWLData(); - - return true; -} - -void CXFA_FFImageEdit::UnloadWidget() { - m_pDataAcc->SetImageEditImage(nullptr); - CXFA_FFField::UnloadWidget(); -} - -void CXFA_FFImageEdit::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); - RenderCaption(pGS, &mtRotate); - CFX_RetainPtr pDIBitmap = m_pDataAcc->GetImageEditImage(); - if (!pDIBitmap) - return; - - CFX_RectF rtImage = m_pNormalWidget->GetWidgetRect(); - int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; - int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; - if (CXFA_Para para = m_pDataAcc->GetPara()) { - iHorzAlign = para.GetHorizontalAlign(); - iVertAlign = para.GetVerticalAlign(); - } - - int32_t iAspect = XFA_ATTRIBUTEENUM_Fit; - if (CXFA_Value value = m_pDataAcc->GetFormValue()) { - if (CXFA_Image imageObj = value.GetImage()) - iAspect = imageObj.GetAspect(); - } - - int32_t iImageXDpi = 0; - int32_t iImageYDpi = 0; - m_pDataAcc->GetImageEditDpi(iImageXDpi, iImageYDpi); - XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, - iImageYDpi, iHorzAlign, iVertAlign); -} - -bool CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, - const CFX_PointF& point) { - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) - return false; - if (!PtInActiveRect(point)) - return false; - - SetButtonDown(true); - - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -void CXFA_FFImageEdit::SetFWLRect() { - if (!m_pNormalWidget) - return; - - CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); - CFX_RectF rtImage(m_rtUI); - rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, - rtUIMargin.height); - m_pNormalWidget->SetWidgetRect(rtImage); -} - -bool CXFA_FFImageEdit::CommitData() { - return true; -} - -bool CXFA_FFImageEdit::UpdateFWLData() { - m_pDataAcc->SetImageEditImage(nullptr); - m_pDataAcc->LoadImageEditImage(); - return true; -} - -void CXFA_FFImageEdit::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFImageEdit::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} diff --git a/xfa/fxfa/app/cxfa_ffimageedit.h b/xfa/fxfa/app/cxfa_ffimageedit.h deleted file mode 100644 index c81af5eb08..0000000000 --- a/xfa/fxfa/app/cxfa_ffimageedit.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFIMAGEEDIT_H_ -#define XFA_FXFA_APP_CXFA_FFIMAGEEDIT_H_ - -#include "xfa/fxfa/app/cxfa_fffield.h" - -class CXFA_FFImageEdit : public CXFA_FFField { - public: - explicit CXFA_FFImageEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFImageEdit() override; - - // CXFA_FFField - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - bool LoadWidget() override; - void UnloadWidget() override; - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - private: - void SetFWLRect() override; - bool UpdateFWLData() override; - bool CommitData() override; - - IFWL_WidgetDelegate* m_pOldDelegate; -}; - -#endif // XFA_FXFA_APP_CXFA_FFIMAGEEDIT_H_ diff --git a/xfa/fxfa/app/cxfa_ffline.cpp b/xfa/fxfa/app/cxfa_ffline.cpp deleted file mode 100644 index 6c028dd340..0000000000 --- a/xfa/fxfa/app/cxfa_ffline.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffline.h" - -#include "xfa/fxgraphics/cxfa_color.h" -#include "xfa/fxgraphics/cxfa_graphics.h" -#include "xfa/fxgraphics/cxfa_path.h" - -CXFA_FFLine::CXFA_FFLine(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFLine::~CXFA_FFLine() {} - -void CXFA_FFLine::GetRectFromHand(CFX_RectF& rect, - int32_t iHand, - float fLineWidth) { - float fHalfWidth = fLineWidth / 2.0f; - if (rect.height < 1.0f) { - switch (iHand) { - case XFA_ATTRIBUTEENUM_Left: - rect.top -= fHalfWidth; - break; - case XFA_ATTRIBUTEENUM_Right: - rect.top += fHalfWidth; - } - } else if (rect.width < 1.0f) { - switch (iHand) { - case XFA_ATTRIBUTEENUM_Left: - rect.left += fHalfWidth; - break; - case XFA_ATTRIBUTEENUM_Right: - rect.left += fHalfWidth; - break; - } - } else { - switch (iHand) { - case XFA_ATTRIBUTEENUM_Left: - rect.Inflate(fHalfWidth, fHalfWidth); - break; - case XFA_ATTRIBUTEENUM_Right: - rect.Deflate(fHalfWidth, fHalfWidth); - break; - } - } -} - -void CXFA_FFLine::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CXFA_Value value = m_pDataAcc->GetFormValue(); - if (!value) - return; - - CXFA_Line lineObj = value.GetLine(); - FX_ARGB lineColor = 0xFF000000; - int32_t iStrokeType = 0; - float fLineWidth = 1.0f; - int32_t iCap = 0; - CXFA_Edge edge = lineObj.GetEdge(); - if (edge) { - if (edge.GetPresence() != XFA_ATTRIBUTEENUM_Visible) - return; - - lineColor = edge.GetColor(); - iStrokeType = edge.GetStrokeType(); - fLineWidth = edge.GetThickness(); - iCap = edge.GetCapType(); - } - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CFX_RectF rtLine = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rtLine, mgWidget); - - GetRectFromHand(rtLine, lineObj.GetHand(), fLineWidth); - CXFA_Path linePath; - if (lineObj.GetSlope() && rtLine.right() > 0.0f && rtLine.bottom() > 0.0f) - linePath.AddLine(rtLine.TopRight(), rtLine.BottomLeft()); - else - linePath.AddLine(rtLine.TopLeft(), rtLine.BottomRight()); - - CXFA_Color color(lineColor); - pGS->SaveGraphState(); - pGS->SetLineWidth(fLineWidth, true); - XFA_StrokeTypeSetLineDash(pGS, iStrokeType, iCap); - pGS->SetStrokeColor(&color); - pGS->SetLineCap(XFA_LineCapToFXGE(iCap)); - pGS->StrokePath(&linePath, &mtRotate); - pGS->RestoreGraphState(); -} diff --git a/xfa/fxfa/app/cxfa_ffline.h b/xfa/fxfa/app/cxfa_ffline.h deleted file mode 100644 index 7649f5a827..0000000000 --- a/xfa/fxfa/app/cxfa_ffline.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFLINE_H_ -#define XFA_FXFA_APP_CXFA_FFLINE_H_ - -#include "xfa/fxfa/app/cxfa_ffdraw.h" - -class CXFA_FFLine : public CXFA_FFDraw { - public: - explicit CXFA_FFLine(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFLine() override; - - // CXFA_FFWidget - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - - private: - void GetRectFromHand(CFX_RectF& rect, int32_t iHand, float fLineWidth); -}; - -#endif // XFA_FXFA_APP_CXFA_FFLINE_H_ diff --git a/xfa/fxfa/app/cxfa_fflistbox.cpp b/xfa/fxfa/app/cxfa_fflistbox.cpp deleted file mode 100644 index cc9100b5db..0000000000 --- a/xfa/fxfa/app/cxfa_fflistbox.cpp +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_fflistbox.h" - -#include -#include -#include - -#include "xfa/fwl/cfwl_listbox.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fwl/cfwl_widget.h" -#include "xfa/fxfa/cxfa_eventparam.h" - -namespace { - -CFWL_ListBox* ToListBox(CFWL_Widget* widget) { - return static_cast(widget); -} - -} // namespace - -CXFA_FFListBox::CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFListBox::~CXFA_FFListBox() { - if (!m_pNormalWidget) - return; - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); -} - -bool CXFA_FFListBox::LoadWidget() { - auto pNew = pdfium::MakeUnique( - GetFWLApp(), pdfium::MakeUnique(), nullptr); - CFWL_ListBox* pListBox = pNew.get(); - pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, - 0xFFFFFFFF); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) - pListBox->AddString(label.AsStringC()); - - uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; - if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) - dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection; - - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - for (int32_t selected : m_pDataAcc->GetSelectedItems()) - pListBox->SetSelItem(pListBox->GetItem(nullptr, selected), true); - - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) { - if (!ProcessCommittedData()) - UpdateFWLData(); - - CXFA_FFField::OnKillFocus(pNewFocus); - return true; -} - -bool CXFA_FFListBox::CommitData() { - auto* pListBox = ToListBox(m_pNormalWidget.get()); - std::vector iSelArray; - int32_t iSels = pListBox->CountSelItems(); - for (int32_t i = 0; i < iSels; ++i) - iSelArray.push_back(pListBox->GetSelIndex(i)); - - m_pDataAcc->SetSelectedItems(iSelArray, true, false, true); - return true; -} - -bool CXFA_FFListBox::IsDataChanged() { - std::vector iSelArray = m_pDataAcc->GetSelectedItems(); - int32_t iOldSels = pdfium::CollectionSize(iSelArray); - auto* pListBox = ToListBox(m_pNormalWidget.get()); - int32_t iSels = pListBox->CountSelItems(); - if (iOldSels != iSels) - return true; - - for (int32_t i = 0; i < iSels; ++i) { - CFWL_ListItem* hlistItem = pListBox->GetItem(nullptr, iSelArray[i]); - if (!(hlistItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)) - return true; - } - return false; -} - -uint32_t CXFA_FFListBox::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_LTB_CenterAlign; - break; - case XFA_ATTRIBUTEENUM_Justify: - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFListBox::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - auto* pListBox = ToListBox(m_pNormalWidget.get()); - std::vector iSelArray = m_pDataAcc->GetSelectedItems(); - std::vector selItemArray(iSelArray.size()); - std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(), - [pListBox](int32_t val) { return pListBox->GetSelItem(val); }); - - pListBox->SetSelItem(pListBox->GetSelItem(-1), false); - for (CFWL_ListItem* pItem : selItemArray) - pListBox->SetSelItem(pItem, true); - - m_pNormalWidget->Update(); - return true; -} - -void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); - - auto* pListBox = ToListBox(m_pNormalWidget.get()); - int32_t iSels = pListBox->CountSelItems(); - if (iSels > 0) { - CFWL_ListItem* item = pListBox->GetSelItem(0); - eParam.m_wsNewText = item ? item->GetText() : L""; - } - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); -} - -void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) { - auto* pListBox = ToListBox(m_pNormalWidget.get()); - pListBox->SetSelItem(pListBox->GetSelItem(nIndex), bSelected); - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFListBox::InsertItem(const CFX_WideStringC& wsLabel, - int32_t nIndex) { - CFX_WideString wsTemp(wsLabel); - ToListBox(m_pNormalWidget.get())->AddString(wsTemp.AsStringC()); - m_pNormalWidget->Update(); - AddInvalidateRect(); -} - -void CXFA_FFListBox::DeleteItem(int32_t nIndex) { - auto* pListBox = ToListBox(m_pNormalWidget.get()); - if (nIndex < 0) - pListBox->DeleteAll(); - else - pListBox->DeleteString(pListBox->GetItem(nullptr, nIndex)); - - pListBox->Update(); - AddInvalidateRect(); -} - -void CXFA_FFListBox::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - switch (pEvent->GetType()) { - case CFWL_Event::Type::SelectChanged: - OnSelectChanged(m_pNormalWidget.get()); - break; - default: - break; - } - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFListBox::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} diff --git a/xfa/fxfa/app/cxfa_fflistbox.h b/xfa/fxfa/app/cxfa_fflistbox.h deleted file mode 100644 index ac563cc86c..0000000000 --- a/xfa/fxfa/app/cxfa_fflistbox.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFLISTBOX_H_ -#define XFA_FXFA_APP_CXFA_FFLISTBOX_H_ - -#include "xfa/fxfa/app/cxfa_fffield.h" - -class CXFA_FFListBox : public CXFA_FFField { - public: - explicit CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFListBox() override; - - // CXFA_FFField - bool LoadWidget() override; - bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - void OnSelectChanged(CFWL_Widget* pWidget); - void SetItemState(int32_t nIndex, bool bSelected); - void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex); - void DeleteItem(int32_t nIndex); - - private: - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - - uint32_t GetAlignment(); - - IFWL_WidgetDelegate* m_pOldDelegate; -}; - -#endif // XFA_FXFA_APP_CXFA_FFLISTBOX_H_ diff --git a/xfa/fxfa/app/cxfa_ffnotify.cpp b/xfa/fxfa/app/cxfa_ffnotify.cpp deleted file mode 100644 index a660ffff12..0000000000 --- a/xfa/fxfa/app/cxfa_ffnotify.cpp +++ /dev/null @@ -1,540 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffnotify.h" - -#include "fxjs/cfxjse_value.h" -#include "xfa/fxfa/app/cxfa_ffarc.h" -#include "xfa/fxfa/app/cxfa_ffbarcode.h" -#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" -#include "xfa/fxfa/app/cxfa_ffcombobox.h" -#include "xfa/fxfa/app/cxfa_ffdatetimeedit.h" -#include "xfa/fxfa/app/cxfa_ffdraw.h" -#include "xfa/fxfa/app/cxfa_ffexclgroup.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_ffimage.h" -#include "xfa/fxfa/app/cxfa_ffimageedit.h" -#include "xfa/fxfa/app/cxfa_ffline.h" -#include "xfa/fxfa/app/cxfa_fflistbox.h" -#include "xfa/fxfa/app/cxfa_ffnumericedit.h" -#include "xfa/fxfa/app/cxfa_ffpasswordedit.h" -#include "xfa/fxfa/app/cxfa_ffpushbutton.h" -#include "xfa/fxfa/app/cxfa_ffrectangle.h" -#include "xfa/fxfa/app/cxfa_ffsignature.h" -#include "xfa/fxfa/app/cxfa_ffsubform.h" -#include "xfa/fxfa/app/cxfa_fftext.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/cxfa_textprovider.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/cxfa_ffwidgethandler.h" -#include "xfa/fxfa/parser/cxfa_node.h" - -namespace { - -CXFA_WidgetAcc* ToWidgetAcc(void* data) { - return static_cast(data); -} - -CXFA_FFListBox* ToListBox(CXFA_FFWidget* widget) { - return static_cast(widget); -} - -CXFA_FFComboBox* ToComboBox(CXFA_FFWidget* widget) { - return static_cast(widget); -} - -} // namespace - -static void XFA_FFDeleteWidgetAcc(void* pData) { - delete ToWidgetAcc(pData); -} - -static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteWidgetAcc = { - XFA_FFDeleteWidgetAcc, nullptr}; - -CXFA_FFNotify::CXFA_FFNotify(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} - -CXFA_FFNotify::~CXFA_FFNotify() {} - -void CXFA_FFNotify::OnPageEvent(CXFA_ContainerLayoutItem* pSender, - uint32_t dwEvent) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pSender->GetLayout()); - if (pDocView) - pDocView->OnPageEvent(pSender, dwEvent); -} - -void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender, - const wchar_t* pLabel, - const wchar_t* pValue, - int32_t iIndex) { - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender); - if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) - return; - - CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { - if (pWidget->IsLoaded()) { - if (pWidgetAcc->IsListBox()) - ToListBox(pWidget)->InsertItem(pLabel, iIndex); - else - ToComboBox(pWidget)->InsertItem(pLabel, iIndex); - } - } -} - -void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_WidgetData* pSender, - int32_t iIndex) { - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender); - if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) - return; - - CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { - if (pWidget->IsLoaded()) { - if (pWidgetAcc->IsListBox()) - ToListBox(pWidget)->DeleteItem(iIndex); - else - ToComboBox(pWidget)->DeleteItem(iIndex); - } - } -} - -CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) { - CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetDocLayout(); - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); - XFA_Element eType = pNode->GetElementType(); - if (eType == XFA_Element::PageArea) - return new CXFA_FFPageView(pDocView, pNode); - if (eType == XFA_Element::ContentArea) - return new CXFA_ContainerLayoutItem(pNode); - - CXFA_WidgetAcc* pAcc = ToWidgetAcc(pNode->GetWidgetData()); - if (!pAcc) - return new CXFA_ContentLayoutItem(pNode); - - CXFA_FFWidget* pWidget; - switch (pAcc->GetUIType()) { - case XFA_Element::Barcode: - pWidget = new CXFA_FFBarcode(pAcc); - break; - case XFA_Element::Button: - pWidget = new CXFA_FFPushButton(pAcc); - break; - case XFA_Element::CheckButton: - pWidget = new CXFA_FFCheckButton(pAcc); - break; - case XFA_Element::ChoiceList: { - if (pAcc->IsListBox()) - pWidget = new CXFA_FFListBox(pAcc); - else - pWidget = new CXFA_FFComboBox(pAcc); - } break; - case XFA_Element::DateTimeEdit: - pWidget = new CXFA_FFDateTimeEdit(pAcc); - break; - case XFA_Element::ImageEdit: - pWidget = new CXFA_FFImageEdit(pAcc); - break; - case XFA_Element::NumericEdit: - pWidget = new CXFA_FFNumericEdit(pAcc); - break; - case XFA_Element::PasswordEdit: - pWidget = new CXFA_FFPasswordEdit(pAcc); - break; - case XFA_Element::Signature: - pWidget = new CXFA_FFSignature(pAcc); - break; - case XFA_Element::TextEdit: - pWidget = new CXFA_FFTextEdit(pAcc); - break; - case XFA_Element::Arc: - pWidget = new CXFA_FFArc(pAcc); - break; - case XFA_Element::Line: - pWidget = new CXFA_FFLine(pAcc); - break; - case XFA_Element::Rectangle: - pWidget = new CXFA_FFRectangle(pAcc); - break; - case XFA_Element::Text: - pWidget = new CXFA_FFText(pAcc); - break; - case XFA_Element::Image: - pWidget = new CXFA_FFImage(pAcc); - break; - case XFA_Element::Draw: - pWidget = new CXFA_FFDraw(pAcc); - break; - case XFA_Element::Subform: - pWidget = new CXFA_FFSubForm(pAcc); - break; - case XFA_Element::ExclGroup: - pWidget = new CXFA_FFExclGroup(pAcc); - break; - case XFA_Element::DefaultUi: - default: - pWidget = nullptr; - break; - } - - if (pWidget) - pWidget->SetDocView(pDocView); - return pWidget; -} - -void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem, - float& fCalcWidth, - float& fCalcHeight) { - CXFA_WidgetAcc* pAcc = ToWidgetAcc(pItem->GetWidgetData()); - if (!pAcc) - return; - - pAcc->StartWidgetLayout(fCalcWidth, fCalcHeight); -} - -bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem, - int32_t iBlockIndex, - float& fCalcHeightPos) { - CXFA_WidgetAcc* pAcc = ToWidgetAcc(pItem->GetWidgetData()); - return pAcc && pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos); -} - -bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) { - bool bRet = false; - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return bRet; - - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pFormItem->GetWidgetData()); - if (!pWidgetAcc) - return bRet; - - CXFA_EventParam EventParam; - EventParam.m_eType = XFA_EVENT_Unknown; - CFXJSE_Value* pRetValue = nullptr; - int32_t iRet = - pWidgetAcc->ExecuteScript(CXFA_Script(pScript), &EventParam, &pRetValue); - if (iRet == XFA_EVENTERROR_Success && pRetValue) { - bRet = pRetValue->ToBoolean(); - delete pRetValue; - } - return bRet; -} - -int32_t CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode, - XFA_EVENTTYPE eEventType, - bool bIsFormReady, - bool bRecursive, - CXFA_WidgetAcc* pExclude) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return XFA_EVENTERROR_NotExist; - return pDocView->ExecEventActivityByDeepFirst( - pFormNode, eEventType, bIsFormReady, bRecursive, - pExclude ? pExclude->GetNode() : nullptr); -} - -void CXFA_FFNotify::AddCalcValidate(CXFA_Node* pNode) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pNode->GetWidgetData()); - if (!pWidgetAcc) - return; - - pDocView->AddCalculateWidgetAcc(pWidgetAcc); - pDocView->AddValidateWidget(pWidgetAcc); -} - -CXFA_FFDoc* CXFA_FFNotify::GetHDOC() { - return m_pDoc.Get(); -} - -IXFA_DocEnvironment* CXFA_FFNotify::GetDocEnvironment() const { - return m_pDoc->GetDocEnvironment(); -} - -IXFA_AppProvider* CXFA_FFNotify::GetAppProvider() { - return m_pDoc->GetApp()->GetAppProvider(); -} - -CXFA_FFWidgetHandler* CXFA_FFNotify::GetWidgetHandler() { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - return pDocView ? pDocView->GetWidgetHandler() : nullptr; -} - -CXFA_FFWidget* CXFA_FFNotify::GetHWidget(CXFA_LayoutItem* pLayoutItem) { - return XFA_GetWidgetFromLayoutItem(pLayoutItem); -} - -void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) { - if (hWidget->GetDataAcc()->GetUIType() != XFA_Element::ChoiceList) - return; - - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - pDocView->LockUpdate(); - ToComboBox(hWidget)->OpenDropDownList(); - pDocView->UnlockUpdate(); - pDocView->UpdateDocView(); -} - -CFX_WideString CXFA_FFNotify::GetCurrentDateTime() { - CFX_DateTime dataTime; - dataTime.Now(); - - CFX_WideString wsDateTime; - wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(), - dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(), - dataTime.GetMinute(), dataTime.GetSecond()); - return wsDateTime; -} - -void CXFA_FFNotify::ResetData(CXFA_WidgetData* pWidgetData) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - pDocView->ResetWidgetData(ToWidgetAcc(pWidgetData)); -} - -int32_t CXFA_FFNotify::GetLayoutStatus() { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - return pDocView ? pDocView->GetLayoutStatus() : 0; -} - -void CXFA_FFNotify::RunNodeInitialize(CXFA_Node* pNode) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - pDocView->AddNewFormNode(pNode); -} - -void CXFA_FFNotify::RunSubformIndexChange(CXFA_Node* pSubformNode) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - pDocView->AddIndexChangedSubform(pSubformNode); -} - -CXFA_Node* CXFA_FFNotify::GetFocusWidgetNode() { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return nullptr; - - CXFA_WidgetAcc* pAcc = pDocView->GetFocusWidgetAcc(); - return pAcc ? pAcc->GetNode() : nullptr; -} - -void CXFA_FFNotify::SetFocusWidgetNode(CXFA_Node* pNode) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - CXFA_WidgetAcc* pAcc = pNode ? ToWidgetAcc(pNode->GetWidgetData()) : nullptr; - pDocView->SetFocusWidgetAcc(pAcc); -} - -void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - XFA_Element eType = pNode->GetElementType(); - if (XFA_IsCreateWidget(eType)) { - CXFA_WidgetAcc* pAcc = new CXFA_WidgetAcc(pDocView, pNode); - pNode->SetObject(XFA_ATTRIBUTE_WidgetData, pAcc, &gs_XFADeleteWidgetAcc); - return; - } - switch (eType) { - case XFA_Element::BindItems: - pDocView->m_BindItems.push_back(pNode); - break; - case XFA_Element::Validate: - pNode->SetFlag(XFA_NodeFlag_NeedsInitApp, false); - break; - default: - break; - } -} - -void CXFA_FFNotify::OnValueChanging(CXFA_Node* pSender, XFA_ATTRIBUTE eAttr) { - if (eAttr != XFA_ATTRIBUTE_Presence) - return; - if (pSender->GetPacketID() & XFA_XDPPACKET_Datasets) - return; - if (!pSender->IsFormContainer()) - return; - - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End) - return; - - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender->GetWidgetData()); - if (!pWidgetAcc) - return; - - CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { - if (pWidget->IsLoaded()) - pWidget->AddInvalidateRect(); - } -} - -void CXFA_FFNotify::OnValueChanged(CXFA_Node* pSender, - XFA_ATTRIBUTE eAttr, - CXFA_Node* pParentNode, - CXFA_Node* pWidgetNode) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - if (!(pSender->GetPacketID() & XFA_XDPPACKET_Form)) { - if (eAttr == XFA_ATTRIBUTE_Value) - pDocView->AddCalculateNodeNotify(pSender); - return; - } - - XFA_Element eType = pParentNode->GetElementType(); - bool bIsContainerNode = pParentNode->IsContainerNode(); - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pWidgetNode->GetWidgetData()); - if (!pWidgetAcc) - return; - - bool bUpdateProperty = false; - pDocView->SetChangeMark(); - switch (eType) { - case XFA_Element::Caption: { - CXFA_TextLayout* pCapOut = pWidgetAcc->GetCaptionTextLayout(); - if (!pCapOut) - return; - - pCapOut->Unload(); - break; - } - case XFA_Element::Ui: - case XFA_Element::Para: - bUpdateProperty = true; - break; - default: - break; - } - if (bIsContainerNode && eAttr == XFA_ATTRIBUTE_Access) - bUpdateProperty = true; - - if (eAttr == XFA_ATTRIBUTE_Value) { - pDocView->AddCalculateNodeNotify(pSender); - if (eType == XFA_Element::Value || bIsContainerNode) { - if (bIsContainerNode) { - pWidgetAcc->UpdateUIDisplay(); - pDocView->AddCalculateWidgetAcc(pWidgetAcc); - pDocView->AddValidateWidget(pWidgetAcc); - } else if (pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent) - ->GetElementType() == XFA_Element::ExclGroup) { - pWidgetAcc->UpdateUIDisplay(); - } - return; - } - } - - CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { - if (!pWidget->IsLoaded()) - continue; - - if (bUpdateProperty) - pWidget->UpdateWidgetProperty(); - pWidget->PerformLayout(); - pWidget->AddInvalidateRect(); - } -} - -void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) { - if (!pSender->IsFormContainer()) - return; - - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - bool bLayoutReady = - !(pDocView->m_bInLayoutStatus) && - (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End); - if (bLayoutReady) - m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc.Get()); -} - -void CXFA_FFNotify::OnChildRemoved() { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); - if (!pDocView) - return; - - bool bLayoutReady = - !(pDocView->m_bInLayoutStatus) && - (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End); - if (bLayoutReady) - m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc.Get()); -} - -void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout, - CXFA_LayoutItem* pSender, - int32_t iPageIdx, - uint32_t dwStatus) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); - if (!pDocView) - return; - - CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender); - if (!pWidget) - return; - - CXFA_FFPageView* pNewPageView = pDocView->GetPageView(iPageIdx); - uint32_t dwFilter = XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable | - XFA_WidgetStatus_Printable; - pWidget->ModifyStatus(dwStatus, dwFilter); - CXFA_FFPageView* pPrePageView = pWidget->GetPageView(); - if (pPrePageView != pNewPageView || - (dwStatus & (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) == - (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) { - pWidget->SetPageView(pNewPageView); - m_pDoc->GetDocEnvironment()->WidgetPostAdd(pWidget, pWidget->GetDataAcc()); - } - if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End || - !(dwStatus & XFA_WidgetStatus_Visible)) { - return; - } - if (pWidget->IsLoaded()) { - if (pWidget->GetWidgetRect() != pWidget->RecacheWidgetRect()) - pWidget->PerformLayout(); - } else { - pWidget->LoadWidget(); - } - pWidget->AddInvalidateRect(nullptr); -} - -void CXFA_FFNotify::OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout, - CXFA_LayoutItem* pSender) { - CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); - if (!pDocView) - return; - - CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender); - if (!pWidget) - return; - - pDocView->DeleteLayoutItem(pWidget); - m_pDoc->GetDocEnvironment()->WidgetPreRemove(pWidget, pWidget->GetDataAcc()); - pWidget->AddInvalidateRect(nullptr); -} diff --git a/xfa/fxfa/app/cxfa_ffnotify.h b/xfa/fxfa/app/cxfa_ffnotify.h deleted file mode 100644 index 935a0c390b..0000000000 --- a/xfa/fxfa/app/cxfa_ffnotify.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFNOTIFY_H_ -#define XFA_FXFA_APP_CXFA_FFNOTIFY_H_ - -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/parser/cxfa_document.h" - -class CXFA_FFWidgetHandler; - -class CXFA_FFNotify { - public: - explicit CXFA_FFNotify(CXFA_FFDoc* pDoc); - ~CXFA_FFNotify(); - - void OnPageEvent(CXFA_ContainerLayoutItem* pSender, uint32_t dwEvent); - - void OnWidgetListItemAdded(CXFA_WidgetData* pSender, - const wchar_t* pLabel, - const wchar_t* pValue, - int32_t iIndex); - void OnWidgetListItemRemoved(CXFA_WidgetData* pSender, int32_t iIndex); - - // Node events - void OnNodeReady(CXFA_Node* pNode); - void OnValueChanging(CXFA_Node* pSender, XFA_ATTRIBUTE eAttr); - void OnValueChanged(CXFA_Node* pSender, - XFA_ATTRIBUTE eAttr, - CXFA_Node* pParentNode, - CXFA_Node* pWidgetNode); - void OnChildAdded(CXFA_Node* pSender); - void OnChildRemoved(); - - CXFA_LayoutItem* OnCreateLayoutItem(CXFA_Node* pNode); - void OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout, - CXFA_LayoutItem* pSender, - int32_t iPageIdx, - uint32_t dwStatus); - void OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout, - CXFA_LayoutItem* pSender); - - void StartFieldDrawLayout(CXFA_Node* pItem, - float& fCalcWidth, - float& fCalcHeight); - bool FindSplitPos(CXFA_Node* pItem, - int32_t iBlockIndex, - float& fCalcHeightPos); - bool RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem); - int32_t ExecEventByDeepFirst(CXFA_Node* pFormNode, - XFA_EVENTTYPE eEventType, - bool bIsFormReady = false, - bool bRecursive = true, - CXFA_WidgetAcc* pExclude = nullptr); - void AddCalcValidate(CXFA_Node* pNode); - CXFA_FFDoc* GetHDOC(); - IXFA_DocEnvironment* GetDocEnvironment() const; - IXFA_AppProvider* GetAppProvider(); - CXFA_FFWidgetHandler* GetWidgetHandler(); - CXFA_FFWidget* GetHWidget(CXFA_LayoutItem* pLayoutItem); - void OpenDropDownList(CXFA_FFWidget* hWidget); - CFX_WideString GetCurrentDateTime(); - void ResetData(CXFA_WidgetData* pWidgetData = nullptr); - int32_t GetLayoutStatus(); - void RunNodeInitialize(CXFA_Node* pNode); - void RunSubformIndexChange(CXFA_Node* pSubformNode); - CXFA_Node* GetFocusWidgetNode(); - void SetFocusWidgetNode(CXFA_Node* pNode); - - private: - CFX_UnownedPtr const m_pDoc; -}; - -#endif // XFA_FXFA_APP_CXFA_FFNOTIFY_H_ diff --git a/xfa/fxfa/app/cxfa_ffnumericedit.cpp b/xfa/fxfa/app/cxfa_ffnumericedit.cpp deleted file mode 100644 index 09ea524ee4..0000000000 --- a/xfa/fxfa/app/cxfa_ffnumericedit.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffnumericedit.h" - -#include - -#include "xfa/fwl/cfwl_edit.h" -#include "xfa/fwl/cfwl_eventvalidate.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/parser/cxfa_localevalue.h" - -CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} - -bool CXFA_FFNumericEdit::LoadWidget() { - auto pNewEdit = pdfium::MakeUnique( - GetFWLApp(), pdfium::MakeUnique(), nullptr); - CFWL_Edit* pWidget = pNewEdit.get(); - m_pNormalWidget = std::move(pNewEdit); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetText(wsText); - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFNumericEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = static_cast(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwExtendedStyle = - FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | - FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | - FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells > 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iNumCells); - } - dwExtendedStyle |= GetAlignment(); - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; - } - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); -} - -void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { - if (pEvent->GetType() == CFWL_Event::Type::Validate) { - CFWL_EventValidate* event = static_cast(pEvent); - event->bValidate = OnValidate(m_pNormalWidget.get(), event->wsInsert); - return; - } - CXFA_FFTextEdit::OnProcessEvent(pEvent); -} - -bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, - CFX_WideString& wsText) { - CFX_WideString wsPattern; - m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); - if (!wsPattern.IsEmpty()) - return true; - - int32_t iLeads = 0; - m_pDataAcc->GetLeadDigits(iLeads); - - int32_t iFracs = 0; - m_pDataAcc->GetFracDigits(iFracs); - - CFX_WideString wsFormat; - CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - widgetValue.GetNumericFormat(wsFormat, iLeads, iFracs); - return widgetValue.ValidateNumericTemp(wsText, wsFormat, - m_pDataAcc->GetLocal()); -} diff --git a/xfa/fxfa/app/cxfa_ffnumericedit.h b/xfa/fxfa/app/cxfa_ffnumericedit.h deleted file mode 100644 index 25e2304e87..0000000000 --- a/xfa/fxfa/app/cxfa_ffnumericedit.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFNUMERICEDIT_H_ -#define XFA_FXFA_APP_CXFA_FFNUMERICEDIT_H_ - -#include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/app/cxfa_fftextedit.h" - -class CFWL_Event; -class CFWL_Widget; -class CXFA_WidgetAcc; - -class CXFA_FFNumericEdit : public CXFA_FFTextEdit { - public: - explicit CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFNumericEdit() override; - - // CXFA_FFTextEdit - bool LoadWidget() override; - void UpdateWidgetProperty() override; - void OnProcessEvent(CFWL_Event* pEvent) override; - - private: - bool OnValidate(CFWL_Widget* pWidget, CFX_WideString& wsText); -}; - -#endif // XFA_FXFA_APP_CXFA_FFNUMERICEDIT_H_ diff --git a/xfa/fxfa/app/cxfa_ffpasswordedit.cpp b/xfa/fxfa/app/cxfa_ffpasswordedit.cpp deleted file mode 100644 index 1b404fa046..0000000000 --- a/xfa/fxfa/app/cxfa_ffpasswordedit.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffpasswordedit.h" - -#include - -#include "xfa/fwl/cfwl_edit.h" -#include "xfa/fwl/cfwl_notedriver.h" - -CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFTextEdit(pDataAcc) {} - -CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} - -bool CXFA_FFPasswordEdit::LoadWidget() { - auto pNewEdit = pdfium::MakeUnique( - GetFWLApp(), pdfium::MakeUnique(), nullptr); - CFWL_Edit* pWidget = pNewEdit.get(); - m_pNormalWidget = std::move(pNewEdit); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetText(wsText); - UpdateWidgetProperty(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFPasswordEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = static_cast(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwExtendedStyle = - FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | - FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - - CFX_WideString wsPassWord; - m_pDataAcc->GetPasswordChar(wsPassWord); - if (!wsPassWord.IsEmpty()) - pWidget->SetAliasChar(wsPassWord.GetAt(0)); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; - } - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); -} diff --git a/xfa/fxfa/app/cxfa_ffpasswordedit.h b/xfa/fxfa/app/cxfa_ffpasswordedit.h deleted file mode 100644 index 5d292d4df3..0000000000 --- a/xfa/fxfa/app/cxfa_ffpasswordedit.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFPASSWORDEDIT_H_ -#define XFA_FXFA_APP_CXFA_FFPASSWORDEDIT_H_ - -#include "xfa/fxfa/app/cxfa_fftextedit.h" - -class CXFA_WidgetAcc; - -class CXFA_FFPasswordEdit : public CXFA_FFTextEdit { - public: - explicit CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFPasswordEdit() override; - - // CXFA_FFTextEdit - bool LoadWidget() override; - void UpdateWidgetProperty() override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFPASSWORDEDIT_H_ diff --git a/xfa/fxfa/app/cxfa_ffpushbutton.cpp b/xfa/fxfa/app/cxfa_ffpushbutton.cpp deleted file mode 100644 index 44ec0d42d0..0000000000 --- a/xfa/fxfa/app/cxfa_ffpushbutton.cpp +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffpushbutton.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fwl/cfwl_pushbutton.h" -#include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/cxfa_textprovider.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cxfa_color.h" -#include "xfa/fxgraphics/cxfa_path.h" - -CXFA_FFPushButton::CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFPushButton::~CXFA_FFPushButton() { - CXFA_FFPushButton::UnloadWidget(); -} - -void CXFA_FFPushButton::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - RenderHighlightCaption(pGS, &mtRotate); - - CFX_RectF rtWidget = GetRectWithoutRotate(); - CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); - mt.Concat(mtRotate); - GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, - &mt); -} - -bool CXFA_FFPushButton::LoadWidget() { - ASSERT(!m_pNormalWidget); - auto pNew = pdfium::MakeUnique(GetFWLApp()); - CFWL_PushButton* pPushButton = pNew.get(); - m_pOldDelegate = pPushButton->GetDelegate(); - pPushButton->SetDelegate(this); - m_pNormalWidget = std::move(pNew); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pNormalWidget->LockUpdate(); - UpdateWidgetProperty(); - LoadHighlightCaption(); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFPushButton::UpdateWidgetProperty() { - uint32_t dwStyleEx = 0; - switch (m_pDataAcc->GetButtonHighlight()) { - case XFA_ATTRIBUTEENUM_Inverted: - dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteInverted; - break; - case XFA_ATTRIBUTEENUM_Outline: - dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteOutLine; - break; - case XFA_ATTRIBUTEENUM_Push: - dwStyleEx = XFA_FWL_PSBSTYLEEXT_HilitePush; - break; - default: - break; - } - m_pNormalWidget->ModifyStylesEx(dwStyleEx, 0xFFFFFFFF); -} - -void CXFA_FFPushButton::UnloadWidget() { - m_pRolloverTextLayout.reset(); - m_pDownTextLayout.reset(); - m_pRollProvider.reset(); - m_pDownProvider.reset(); - CXFA_FFField::UnloadWidget(); -} - -bool CXFA_FFPushButton::PerformLayout() { - CXFA_FFWidget::PerformLayout(); - CFX_RectF rtWidget = GetRectWithoutRotate(); - - m_rtUI = rtWidget; - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rtWidget, mgWidget); - - CXFA_Caption caption = m_pDataAcc->GetCaption(); - m_rtCaption = rtWidget; - if (CXFA_Margin mgCap = caption.GetMargin()) - XFA_RectWidthoutMargin(m_rtCaption, mgCap); - - LayoutHighlightCaption(); - SetFWLRect(); - if (m_pNormalWidget) - m_pNormalWidget->Update(); - - return true; -} -float CXFA_FFPushButton::GetLineWidth() { - CXFA_Border border = m_pDataAcc->GetBorder(false); - if (border && border.GetPresence() == XFA_ATTRIBUTEENUM_Visible) { - CXFA_Edge edge = border.GetEdge(0); - return edge.GetThickness(); - } - return 0; -} - -FX_ARGB CXFA_FFPushButton::GetLineColor() { - return 0xFF000000; -} - -FX_ARGB CXFA_FFPushButton::GetFillColor() { - return 0xFFFFFFFF; -} - -void CXFA_FFPushButton::LoadHighlightCaption() { - CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) - return; - - bool bRichText; - CFX_WideString wsRollover; - if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { - if (!m_pRollProvider) { - m_pRollProvider = pdfium::MakeUnique( - m_pDataAcc.Get(), XFA_TEXTPROVIDERTYPE_Rollover); - } - m_pRolloverTextLayout = - pdfium::MakeUnique(m_pRollProvider.get()); - } - CFX_WideString wsDown; - if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { - if (!m_pDownProvider) { - m_pDownProvider = pdfium::MakeUnique( - m_pDataAcc.Get(), XFA_TEXTPROVIDERTYPE_Down); - } - m_pDownTextLayout = - pdfium::MakeUnique(m_pDownProvider.get()); - } -} - -void CXFA_FFPushButton::LayoutHighlightCaption() { - CFX_SizeF sz(m_rtCaption.width, m_rtCaption.height); - LayoutCaption(); - if (m_pRolloverTextLayout) - m_pRolloverTextLayout->Layout(sz); - if (m_pDownTextLayout) - m_pDownTextLayout->Layout(sz); -} - -void CXFA_FFPushButton::RenderHighlightCaption(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix) { - CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); - CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) - return; - - CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); - CFX_RectF rtClip = m_rtCaption; - rtClip.Intersect(GetRectWithoutRotate()); - CFX_Matrix mt(1, 0, 0, 1, m_rtCaption.left, m_rtCaption.top); - if (pMatrix) { - pMatrix->TransformRect(rtClip); - mt.Concat(*pMatrix); - } - - uint32_t dwState = m_pNormalWidget->GetStates(); - if (m_pDownTextLayout && (dwState & FWL_STATE_PSB_Pressed) && - (dwState & FWL_STATE_PSB_Hovered)) { - if (m_pDownTextLayout->DrawString(pRenderDevice, mt, rtClip)) - return; - } else if (m_pRolloverTextLayout && (dwState & FWL_STATE_PSB_Hovered)) { - if (m_pRolloverTextLayout->DrawString(pRenderDevice, mt, rtClip)) - return; - } - - if (pCapTextLayout) - pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); -} - -void CXFA_FFPushButton::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFPushButton::OnProcessEvent(CFWL_Event* pEvent) { - m_pOldDelegate->OnProcessEvent(pEvent); - CXFA_FFField::OnProcessEvent(pEvent); -} - -void CXFA_FFPushButton::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HiliteInverted) { - if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && - (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { - CFX_RectF rtFill(0, 0, m_pNormalWidget->GetWidgetRect().Size()); - float fLineWith = GetLineWidth(); - rtFill.Deflate(fLineWith, fLineWith); - CXFA_Color cr(FXARGB_MAKE(128, 128, 255, 255)); - pGraphics->SetFillColor(&cr); - - CXFA_Path path; - path.AddRectangle(rtFill.left, rtFill.top, rtFill.width, rtFill.height); - pGraphics->FillPath(&path, FXFILL_WINDING, (CFX_Matrix*)pMatrix); - } - return; - } - - if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HiliteOutLine) { - if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && - (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { - float fLineWidth = GetLineWidth(); - CXFA_Color cr(FXARGB_MAKE(255, 128, 255, 255)); - pGraphics->SetStrokeColor(&cr); - pGraphics->SetLineWidth(fLineWidth); - - CXFA_Path path; - CFX_RectF rect = m_pNormalWidget->GetWidgetRect(); - path.AddRectangle(0, 0, rect.width, rect.height); - pGraphics->StrokePath(&path, (CFX_Matrix*)pMatrix); - } - } -} diff --git a/xfa/fxfa/app/cxfa_ffpushbutton.h b/xfa/fxfa/app/cxfa_ffpushbutton.h deleted file mode 100644 index e64ef706f3..0000000000 --- a/xfa/fxfa/app/cxfa_ffpushbutton.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFPUSHBUTTON_H_ -#define XFA_FXFA_APP_CXFA_FFPUSHBUTTON_H_ - -#include - -#include "xfa/fxfa/app/cxfa_fffield.h" - -#define XFA_FWL_PSBSTYLEEXT_HiliteNone (0L << 0) -#define XFA_FWL_PSBSTYLEEXT_HiliteInverted (1L << 0) -#define XFA_FWL_PSBSTYLEEXT_HilitePush (2L << 0) -#define XFA_FWL_PSBSTYLEEXT_HiliteOutLine (4L << 0) - -class CXFA_TextProvider; - -class CXFA_FFPushButton : public CXFA_FFField { - public: - explicit CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFPushButton() override; - - // CXFA_FFField - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - bool LoadWidget() override; - void UnloadWidget() override; - bool PerformLayout() override; - void UpdateWidgetProperty() override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - private: - void LoadHighlightCaption(); - void LayoutHighlightCaption(); - void RenderHighlightCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); - float GetLineWidth(); - FX_ARGB GetLineColor(); - FX_ARGB GetFillColor(); - - std::unique_ptr m_pRolloverTextLayout; - std::unique_ptr m_pDownTextLayout; - std::unique_ptr m_pRollProvider; - std::unique_ptr m_pDownProvider; - IFWL_WidgetDelegate* m_pOldDelegate; -}; - -#endif // XFA_FXFA_APP_CXFA_FFPUSHBUTTON_H_ diff --git a/xfa/fxfa/app/cxfa_ffrectangle.cpp b/xfa/fxfa/app/cxfa_ffrectangle.cpp deleted file mode 100644 index 89ae129cb1..0000000000 --- a/xfa/fxfa/app/cxfa_ffrectangle.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffrectangle.h" - -CXFA_FFRectangle::CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFRectangle::~CXFA_FFRectangle() {} - -void CXFA_FFRectangle::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CXFA_Value value = m_pDataAcc->GetFormValue(); - if (!value) - return; - - CXFA_Rectangle rtObj = value.GetRectangle(); - CFX_RectF rect = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) - XFA_RectWidthoutMargin(rect, mgWidget); - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - DrawBorder(pGS, rtObj, rect, &mtRotate); -} diff --git a/xfa/fxfa/app/cxfa_ffrectangle.h b/xfa/fxfa/app/cxfa_ffrectangle.h deleted file mode 100644 index 2ddb35dade..0000000000 --- a/xfa/fxfa/app/cxfa_ffrectangle.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFRECTANGLE_H_ -#define XFA_FXFA_APP_CXFA_FFRECTANGLE_H_ - -#include "xfa/fxfa/app/cxfa_ffdraw.h" - -class CXFA_FFRectangle : public CXFA_FFDraw { - public: - explicit CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFRectangle() override; - - // CXFA_FFWidget - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFRECTANGLE_H_ diff --git a/xfa/fxfa/app/cxfa_ffsignature.cpp b/xfa/fxfa/app/cxfa_ffsignature.cpp deleted file mode 100644 index 0afe5cc86a..0000000000 --- a/xfa/fxfa/app/cxfa_ffsignature.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffsignature.h" - -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFSignature::CXFA_FFSignature(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc) {} - -CXFA_FFSignature::~CXFA_FFSignature() {} - -bool CXFA_FFSignature::LoadWidget() { - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFSignature::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - - CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); - DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); - RenderCaption(pGS, &mtRotate); - DrawHighlight(pGS, &mtRotate, dwStatus, false); -} - -bool CXFA_FFSignature::OnMouseEnter() { - return false; -} - -bool CXFA_FFSignature::OnMouseExit() { - return false; -} - -bool CXFA_FFSignature::OnLButtonDown(uint32_t dwFlags, - const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnLButtonDblClk(uint32_t dwFlags, - const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnMouseWheel(uint32_t dwFlags, - int16_t zDelta, - const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnRButtonDown(uint32_t dwFlags, - const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnRButtonDblClk(uint32_t dwFlags, - const CFX_PointF& point) { - return false; -} - -bool CXFA_FFSignature::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { - return false; -} - -bool CXFA_FFSignature::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { - return false; -} - -bool CXFA_FFSignature::OnChar(uint32_t dwChar, uint32_t dwFlags) { - return false; -} - -FWL_WidgetHit CXFA_FFSignature::OnHitTest(const CFX_PointF& point) { - if (m_pNormalWidget && - m_pNormalWidget->HitTest(FWLToClient(point)) != FWL_WidgetHit::Unknown) { - return FWL_WidgetHit::Client; - } - - if (!GetRectWithoutRotate().Contains(point)) - return FWL_WidgetHit::Unknown; - if (m_rtCaption.Contains(point)) - return FWL_WidgetHit::Titlebar; - return FWL_WidgetHit::Client; -} - -bool CXFA_FFSignature::OnSetCursor(const CFX_PointF& point) { - return false; -} diff --git a/xfa/fxfa/app/cxfa_ffsignature.h b/xfa/fxfa/app/cxfa_ffsignature.h deleted file mode 100644 index 8d2a33e21a..0000000000 --- a/xfa/fxfa/app/cxfa_ffsignature.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFSIGNATURE_H_ -#define XFA_FXFA_APP_CXFA_FFSIGNATURE_H_ - -#include "xfa/fxfa/app/cxfa_fffield.h" - -class CXFA_FFSignature final : public CXFA_FFField { - public: - explicit CXFA_FFSignature(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFSignature() override; - - // CXFA_FFField - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - bool LoadWidget() override; - bool OnMouseEnter() override; - bool OnMouseExit() override; - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnMouseWheel(uint32_t dwFlags, - int16_t zDelta, - const CFX_PointF& pointy) override; - bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; - - bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) override; - bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) override; - bool OnChar(uint32_t dwChar, uint32_t dwFlags) override; - FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; - bool OnSetCursor(const CFX_PointF& point) override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFSIGNATURE_H_ diff --git a/xfa/fxfa/app/cxfa_ffsubform.cpp b/xfa/fxfa/app/cxfa_ffsubform.cpp deleted file mode 100644 index 80a7782917..0000000000 --- a/xfa/fxfa/app/cxfa_ffsubform.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_ffsubform.h" - -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -CXFA_FFSubForm::CXFA_FFSubForm(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFWidget(pDataAcc) {} - -CXFA_FFSubForm::~CXFA_FFSubForm() {} diff --git a/xfa/fxfa/app/cxfa_ffsubform.h b/xfa/fxfa/app/cxfa_ffsubform.h deleted file mode 100644 index d73e53de97..0000000000 --- a/xfa/fxfa/app/cxfa_ffsubform.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFSUBFORM_H_ -#define XFA_FXFA_APP_CXFA_FFSUBFORM_H_ - -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" - -class CXFA_FFSubForm : public CXFA_FFWidget { - public: - explicit CXFA_FFSubForm(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFSubForm() override; -}; - -#endif // XFA_FXFA_APP_CXFA_FFSUBFORM_H_ diff --git a/xfa/fxfa/app/cxfa_fftext.cpp b/xfa/fxfa/app/cxfa_fftext.cpp deleted file mode 100644 index 3d90e6cd4e..0000000000 --- a/xfa/fxfa/app/cxfa_fftext.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_fftext.h" - -#include "xfa/fwl/fwl_widgetdef.h" -#include "xfa/fwl/fwl_widgethit.h" -#include "xfa/fxfa/app/cxfa_ffdraw.h" -#include "xfa/fxfa/app/cxfa_linkuserdata.h" -#include "xfa/fxfa/app/cxfa_pieceline.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/cxfa_textpiece.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cxfa_graphics.h" - -CXFA_FFText::CXFA_FFText(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} - -CXFA_FFText::~CXFA_FFText() {} - -void CXFA_FFText::RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) { - if (!IsMatchVisibleStatus(dwStatus)) - return; - - CFX_Matrix mtRotate = GetRotateMatrix(); - if (pMatrix) - mtRotate.Concat(*pMatrix); - - CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); - - CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); - if (!pTextLayout) - return; - - CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); - CFX_RectF rtText = GetRectWithoutRotate(); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { - CXFA_LayoutItem* pItem = this; - if (!pItem->GetPrev() && !pItem->GetNext()) { - XFA_RectWidthoutMargin(rtText, mgWidget); - } else { - float fLeftInset; - float fRightInset; - float fTopInset = 0; - float fBottomInset = 0; - mgWidget.GetLeftInset(fLeftInset); - mgWidget.GetRightInset(fRightInset); - if (!pItem->GetPrev()) - mgWidget.GetTopInset(fTopInset); - else if (!pItem->GetNext()) - mgWidget.GetBottomInset(fBottomInset); - - rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); - } - } - - CFX_Matrix mt(1, 0, 0, 1, rtText.left, rtText.top); - CFX_RectF rtClip = rtText; - mtRotate.TransformRect(rtClip); - mt.Concat(mtRotate); - pTextLayout->DrawString(pRenderDevice, mt, rtClip, GetIndex()); -} - -bool CXFA_FFText::IsLoaded() { - CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); - return pTextLayout && !pTextLayout->m_bHasBlock; -} - -bool CXFA_FFText::PerformLayout() { - CXFA_FFDraw::PerformLayout(); - CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); - if (!pTextLayout) - return false; - if (!pTextLayout->m_bHasBlock) - return true; - - pTextLayout->m_Blocks.clear(); - CXFA_LayoutItem* pItem = this; - if (!pItem->GetPrev() && !pItem->GetNext()) - return true; - - pItem = pItem->GetFirst(); - while (pItem) { - CFX_RectF rtText = pItem->GetRect(false); - if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { - if (!pItem->GetPrev()) { - float fTopInset; - mgWidget.GetTopInset(fTopInset); - rtText.height -= fTopInset; - } else if (!pItem->GetNext()) { - float fBottomInset; - mgWidget.GetBottomInset(fBottomInset); - rtText.height -= fBottomInset; - } - } - pTextLayout->ItemBlocks(rtText, pItem->GetIndex()); - pItem = pItem->GetNext(); - } - pTextLayout->m_bHasBlock = false; - return true; -} - -bool CXFA_FFText::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (!GetRectWithoutRotate().Contains(point)) - return false; - - const wchar_t* wsURLContent = GetLinkURLAtPoint(point); - if (!wsURLContent) - return false; - - SetButtonDown(true); - return true; -} - -bool CXFA_FFText::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { - return GetRectWithoutRotate().Contains(point) && !!GetLinkURLAtPoint(point); -} - -bool CXFA_FFText::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - if (!IsButtonDown()) - return false; - - SetButtonDown(false); - const wchar_t* wsURLContent = GetLinkURLAtPoint(point); - if (!wsURLContent) - return false; - - CXFA_FFDoc* pDoc = GetDoc(); - pDoc->GetDocEnvironment()->GotoURL(pDoc, wsURLContent); - return true; -} - -FWL_WidgetHit CXFA_FFText::OnHitTest(const CFX_PointF& point) { - if (!GetRectWithoutRotate().Contains(point)) - return FWL_WidgetHit::Unknown; - if (!GetLinkURLAtPoint(point)) - return FWL_WidgetHit::Unknown; - return FWL_WidgetHit::HyperLink; -} - -const wchar_t* CXFA_FFText::GetLinkURLAtPoint(const CFX_PointF& point) { - CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); - if (!pTextLayout) - return nullptr; - - CFX_RectF rect = GetRectWithoutRotate(); - for (const auto& pPieceLine : *pTextLayout->GetPieceLines()) { - for (const auto& pPiece : pPieceLine->m_textPieces) { - if (pPiece->pLinkData && - pPiece->rtPiece.Contains(point - rect.TopLeft())) { - return pPiece->pLinkData->GetLinkURL(); - } - } - } - return nullptr; -} diff --git a/xfa/fxfa/app/cxfa_fftext.h b/xfa/fxfa/app/cxfa_fftext.h deleted file mode 100644 index df920f0266..0000000000 --- a/xfa/fxfa/app/cxfa_fftext.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFTEXT_H_ -#define XFA_FXFA_APP_CXFA_FFTEXT_H_ - -#include "xfa/fxfa/app/cxfa_ffdraw.h" - -class CXFA_FFText : public CXFA_FFDraw { - public: - explicit CXFA_FFText(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFText() override; - - // CXFA_FFWidget - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; - FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; - void RenderWidget(CXFA_Graphics* pGS, - CFX_Matrix* pMatrix, - uint32_t dwStatus) override; - bool IsLoaded() override; - bool PerformLayout() override; - - private: - const wchar_t* GetLinkURLAtPoint(const CFX_PointF& point); -}; - -#endif // XFA_FXFA_APP_CXFA_FFTEXT_H_ diff --git a/xfa/fxfa/app/cxfa_fftextedit.cpp b/xfa/fxfa/app/cxfa_fftextedit.cpp deleted file mode 100644 index 0d211eb7b4..0000000000 --- a/xfa/fxfa/app/cxfa_fftextedit.cpp +++ /dev/null @@ -1,359 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_fftextedit.h" - -#include - -#include "xfa/fwl/cfwl_datetimepicker.h" -#include "xfa/fwl/cfwl_edit.h" -#include "xfa/fwl/cfwl_eventcheckword.h" -#include "xfa/fwl/cfwl_eventtarget.h" -#include "xfa/fwl/cfwl_eventtextchanged.h" -#include "xfa/fwl/cfwl_messagekillfocus.h" -#include "xfa/fwl/cfwl_messagesetfocus.h" -#include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/parser/cxfa_node.h" - -CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} - -CXFA_FFTextEdit::~CXFA_FFTextEdit() { - if (m_pNormalWidget) { - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); - } -} - -bool CXFA_FFTextEdit::LoadWidget() { - auto pNewWidget = pdfium::MakeUnique( - GetFWLApp(), pdfium::MakeUnique(), nullptr); - CFWL_Edit* pFWLEdit = pNewWidget.get(); - m_pNormalWidget = std::move(pNewWidget); - m_pNormalWidget->SetLayoutItem(this); - - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), - m_pNormalWidget.get()); - m_pOldDelegate = m_pNormalWidget->GetDelegate(); - m_pNormalWidget->SetDelegate(this); - m_pNormalWidget->LockUpdate(); - UpdateWidgetProperty(); - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pFWLEdit->SetText(wsText); - m_pNormalWidget->UnlockUpdate(); - return CXFA_FFField::LoadWidget(); -} - -void CXFA_FFTextEdit::UpdateWidgetProperty() { - CFWL_Edit* pWidget = static_cast(m_pNormalWidget.get()); - if (!pWidget) - return; - - uint32_t dwStyle = 0; - uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | - FWL_STYLEEXT_EDT_OuterScrollbar | - FWL_STYLEEXT_EDT_LastLineHeight; - dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->IsMultiLine()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn; - if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { - dwStyle |= FWL_WGTSTYLE_VScroll; - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll; - } - } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - } - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || - !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; - dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; - } - - XFA_Element eType = XFA_Element::Unknown; - int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); - if (eType == XFA_Element::ExData) - iMaxChars = 0; - - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells == 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1); - } else if (iNumCells > 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iNumCells); - } else { - pWidget->SetLimit(iMaxChars); - } - dwExtendedStyle |= GetAlignment(); - m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF); - m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); -} - -bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (!PtInActiveRect(point)) - return false; - if (!IsFocused()) { - m_dwStatus |= XFA_WidgetStatus_Focused; - UpdateFWLData(); - AddInvalidateRect(); - } - - SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); - ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { - if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) - return false; - if (!PtInActiveRect(point)) - return false; - if (!IsFocused()) { - m_dwStatus |= XFA_WidgetStatus_Focused; - UpdateFWLData(); - AddInvalidateRect(); - } - - SetButtonDown(true); - CFWL_MessageMouse ms(nullptr, nullptr); - ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; - ms.m_dwFlags = dwFlags; - ms.m_pos = FWLToClient(point); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { - if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) - return false; - - GetDoc()->GetDocEnvironment()->PopupMenu(this, point); - return true; -} - -bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { - m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; - if (!IsFocused()) { - m_dwStatus |= XFA_WidgetStatus_Focused; - UpdateFWLData(); - AddInvalidateRect(); - } - CXFA_FFWidget::OnSetFocus(pOldWidget); - CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); - TranslateFWLMessage(&ms); - return true; -} - -bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { - CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); - TranslateFWLMessage(&ms); - m_dwStatus &= ~XFA_WidgetStatus_Focused; - - SetEditScrollOffset(); - ProcessCommittedData(); - UpdateFWLData(); - AddInvalidateRect(); - CXFA_FFWidget::OnKillFocus(pNewWidget); - - m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; - return true; -} - -bool CXFA_FFTextEdit::CommitData() { - CFX_WideString wsText = - static_cast(m_pNormalWidget.get())->GetText(); - if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { - m_pDataAcc->UpdateUIDisplay(this); - return true; - } - ValidateNumberField(wsText); - return false; -} - -void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { - CXFA_WidgetAcc* pAcc = GetDataAcc(); - if (!pAcc || pAcc->GetUIType() != XFA_Element::NumericEdit) - return; - - IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); - if (!pAppProvider) - return; - - CFX_WideString wsSomField; - pAcc->GetNode()->GetSOMExpression(wsSomField); - - CFX_WideString wsMessage; - wsMessage.Format(L"%s can not contain %s", wsText.c_str(), - wsSomField.c_str()); - pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), XFA_MBICON_Error, - XFA_MB_OK); -} - -bool CXFA_FFTextEdit::IsDataChanged() { - return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0; -} - -uint32_t CXFA_FFTextEdit::GetAlignment() { - CXFA_Para para = m_pDataAcc->GetPara(); - if (!para) - return 0; - - uint32_t dwExtendedStyle = 0; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; - break; - } - - switch (para.GetVerticalAlign()) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; - break; - } - return dwExtendedStyle; -} - -bool CXFA_FFTextEdit::UpdateFWLData() { - if (!m_pNormalWidget) - return false; - - CFWL_Edit* pEdit = static_cast(m_pNormalWidget.get()); - XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; - if (IsFocused()) - eType = XFA_VALUEPICTURE_Edit; - - bool bUpdate = false; - if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && - m_pDataAcc->GetNumberOfCells() < 0) { - XFA_Element elementType = XFA_Element::Unknown; - int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); - if (elementType == XFA_Element::ExData) - iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; - if (pEdit->GetLimit() != iMaxChars) { - pEdit->SetLimit(iMaxChars); - bUpdate = true; - } - } else if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { - int32_t nDataLen = 0; - if (eType == XFA_VALUEPICTURE_Edit) - m_pDataAcc->GetBarcodeAttribute_DataLength(&nDataLen); - pEdit->SetLimit(nDataLen); - bUpdate = true; - } - - CFX_WideString wsText; - m_pDataAcc->GetValue(wsText, eType); - - CFX_WideString wsOldText = pEdit->GetText(); - if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { - pEdit->SetText(wsText); - bUpdate = true; - } - if (bUpdate) - m_pNormalWidget->Update(); - - return true; -} - -void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, - const CFX_WideString& wsChanged, - const CFX_WideString& wsPrevText) { - m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged; - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Change; - eParam.m_wsChange = wsChanged; - eParam.m_pTarget = m_pDataAcc.Get(); - eParam.m_wsPrevText = wsPrevText; - CFWL_Edit* pEdit = static_cast(m_pNormalWidget.get()); - if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) { - CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; - eParam.m_wsNewText = pDateTime->GetEditText(); - int32_t iSels = pDateTime->CountSelRanges(); - if (iSels) - eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart); - } else { - eParam.m_wsNewText = pEdit->GetText(); - int32_t iSels = pEdit->CountSelRanges(); - if (iSels) - eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart); - } - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); -} - -void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { - CXFA_EventParam eParam; - eParam.m_eType = XFA_EVENT_Full; - eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); -} - -bool CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { - return sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit; -} - -void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { - m_pOldDelegate->OnProcessMessage(pMessage); -} - -void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { - CXFA_FFField::OnProcessEvent(pEvent); - switch (pEvent->GetType()) { - case CFWL_Event::Type::TextChanged: { - CFWL_EventTextChanged* event = - static_cast(pEvent); - CFX_WideString wsChange; - OnTextChanged(m_pNormalWidget.get(), wsChange, event->wsPrevText); - break; - } - case CFWL_Event::Type::TextFull: { - OnTextFull(m_pNormalWidget.get()); - break; - } - case CFWL_Event::Type::CheckWord: { - CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); - CFWL_EventCheckWord* event = static_cast(pEvent); - event->bCheckWord = CheckWord(event->bsWord.AsStringC()); - break; - } - default: - break; - } - m_pOldDelegate->OnProcessEvent(pEvent); -} - -void CXFA_FFTextEdit::OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); -} diff --git a/xfa/fxfa/app/cxfa_fftextedit.h b/xfa/fxfa/app/cxfa_fftextedit.h deleted file mode 100644 index 109a31a0de..0000000000 --- a/xfa/fxfa/app/cxfa_fftextedit.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FFTEXTEDIT_H_ -#define XFA_FXFA_APP_CXFA_FFTEXTEDIT_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/app/cxfa_fffield.h" - -class CFWL_Event; -class CFWL_Widget; -class CFX_Matrix; -class CXFA_FFWidget; -class CXFA_WidgetAcc; -class IFWL_WidgetDelegate; - -class CXFA_FFTextEdit : public CXFA_FFField { - public: - explicit CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc); - ~CXFA_FFTextEdit() override; - - // CXFA_FFField - bool LoadWidget() override; - void UpdateWidgetProperty() override; - bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; - bool OnSetFocus(CXFA_FFWidget* pOldWidget) override; - bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CXFA_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - - void OnTextChanged(CFWL_Widget* pWidget, - const CFX_WideString& wsChanged, - const CFX_WideString& wsPrevText); - void OnTextFull(CFWL_Widget* pWidget); - bool CheckWord(const CFX_ByteStringC& sWord); - - protected: - uint32_t GetAlignment(); - - IFWL_WidgetDelegate* m_pOldDelegate; - - private: - bool CommitData() override; - bool UpdateFWLData() override; - bool IsDataChanged() override; - void ValidateNumberField(const CFX_WideString& wsText); -}; - -#endif // XFA_FXFA_APP_CXFA_FFTEXTEDIT_H_ diff --git a/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp b/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp deleted file mode 100644 index 42362d858a..0000000000 --- a/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" - -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/cxfa_ffdoc.h" - -CXFA_FWLAdapterWidgetMgr::CXFA_FWLAdapterWidgetMgr() {} - -CXFA_FWLAdapterWidgetMgr::~CXFA_FWLAdapterWidgetMgr() {} - -void CXFA_FWLAdapterWidgetMgr::RepaintWidget(CFWL_Widget* pWidget) { - if (!pWidget) - return; - - CXFA_FFWidget* pFFWidget = pWidget->GetLayoutItem(); - if (!pFFWidget) - return; - - pFFWidget->AddInvalidateRect(nullptr); -} - -bool CXFA_FWLAdapterWidgetMgr::GetPopupPos(CFWL_Widget* pWidget, - float fMinHeight, - float fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup) { - CXFA_FFWidget* pFFWidget = pWidget->GetLayoutItem(); - CFX_RectF rtRotateAnchor(rtAnchor); - pFFWidget->GetRotateMatrix().TransformRect(rtRotateAnchor); - pFFWidget->GetDoc()->GetDocEnvironment()->GetPopupPos( - pFFWidget, fMinHeight, fMaxHeight, rtRotateAnchor, rtPopup); - return true; -} diff --git a/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h b/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h deleted file mode 100644 index f9126eac3f..0000000000 --- a/xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FWLADAPTERWIDGETMGR_H_ -#define XFA_FXFA_APP_CXFA_FWLADAPTERWIDGETMGR_H_ - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_system.h" - -class CFWL_Widget; - -class CXFA_FWLAdapterWidgetMgr { - public: - CXFA_FWLAdapterWidgetMgr(); - ~CXFA_FWLAdapterWidgetMgr(); - - void RepaintWidget(CFWL_Widget* pWidget); - bool GetPopupPos(CFWL_Widget* pWidget, - float fMinHeight, - float fMaxHeight, - const CFX_RectF& rtAnchor, - CFX_RectF& rtPopup); -}; - -#endif // XFA_FXFA_APP_CXFA_FWLADAPTERWIDGETMGR_H_ diff --git a/xfa/fxfa/app/cxfa_fwltheme.cpp b/xfa/fxfa/app/cxfa_fwltheme.cpp deleted file mode 100644 index 5ad0873e19..0000000000 --- a/xfa/fxfa/app/cxfa_fwltheme.cpp +++ /dev/null @@ -1,284 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_fwltheme.h" - -#include "core/fxcrt/fx_codepage.h" -#include "xfa/fde/cfde_textout.h" -#include "xfa/fgas/font/cfgas_gefont.h" -#include "xfa/fwl/cfwl_barcode.h" -#include "xfa/fwl/cfwl_caret.h" -#include "xfa/fwl/cfwl_checkbox.h" -#include "xfa/fwl/cfwl_combobox.h" -#include "xfa/fwl/cfwl_datetimepicker.h" -#include "xfa/fwl/cfwl_edit.h" -#include "xfa/fwl/cfwl_listbox.h" -#include "xfa/fwl/cfwl_monthcalendar.h" -#include "xfa/fwl/cfwl_picturebox.h" -#include "xfa/fwl/cfwl_pushbutton.h" -#include "xfa/fwl/cfwl_scrollbar.h" -#include "xfa/fwl/cfwl_themebackground.h" -#include "xfa/fwl/cfwl_themetext.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxgraphics/cxfa_color.h" - -namespace { - -const wchar_t* const g_FWLTheme_CalFonts[] = { - L"Arial", L"Courier New", L"DejaVu Sans", -}; - -const float kLineHeight = 12.0f; - -} // namespace - -CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget) { - CFWL_Widget* pOuter = pWidget; - while (pOuter && pOuter->GetOuter()) - pOuter = pOuter->GetOuter(); - return pOuter ? pOuter->GetLayoutItem() : nullptr; -} - -CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) - : m_pCheckBoxTP(pdfium::MakeUnique()), - m_pListBoxTP(pdfium::MakeUnique()), - m_pPictureBoxTP(pdfium::MakeUnique()), - m_pSrollBarTP(pdfium::MakeUnique()), - m_pEditTP(pdfium::MakeUnique()), - m_pComboBoxTP(pdfium::MakeUnique()), - m_pMonthCalendarTP(pdfium::MakeUnique()), - m_pDateTimePickerTP(pdfium::MakeUnique()), - m_pPushButtonTP(pdfium::MakeUnique()), - m_pCaretTP(pdfium::MakeUnique()), - m_pBarcodeTP(pdfium::MakeUnique()), - m_pTextOut(pdfium::MakeUnique()), - m_pCalendarFont(nullptr), - m_pApp(pApp) { - m_Rect.Reset(); - - for (size_t i = 0; !m_pCalendarFont && i < FX_ArraySize(g_FWLTheme_CalFonts); - ++i) { - m_pCalendarFont = CFGAS_GEFont::LoadFont(g_FWLTheme_CalFonts[i], 0, 0, - m_pApp->GetFDEFontMgr()); - } - if (!m_pCalendarFont) { - m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetFontByCodePage( - FX_CODEPAGE_MSWin_WesternEuropean, 0, nullptr); - } - - ASSERT(m_pCalendarFont); -} - -CXFA_FWLTheme::~CXFA_FWLTheme() { - m_pTextOut.reset(); - FWLTHEME_Release(); -} - -void CXFA_FWLTheme::DrawBackground(CFWL_ThemeBackground* pParams) { - GetTheme(pParams->m_pWidget)->DrawBackground(pParams); -} - -void CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) { - if (pParams->m_wsText.IsEmpty()) - return; - - if (pParams->m_pWidget->GetClassID() == FWL_Type::MonthCalendar) { - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); - if (!pWidget) - return; - - m_pTextOut->SetStyles(pParams->m_dwTTOStyles); - m_pTextOut->SetAlignment(pParams->m_iTTOAlign); - m_pTextOut->SetFont(m_pCalendarFont); - m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); - m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); - if ((pParams->m_iPart == CFWL_Part::DatesIn) && - !(pParams->m_dwStates & FWL_ITEMSTATE_MCD_Flag) && - (pParams->m_dwStates & - (CFWL_PartState_Hovered | CFWL_PartState_Selected))) { - m_pTextOut->SetTextColor(0xFFFFFFFF); - } - if (pParams->m_iPart == CFWL_Part::Caption) - m_pTextOut->SetTextColor(ArgbEncode(0xff, 0, 153, 255)); - - CXFA_Graphics* pGraphics = pParams->m_pGraphics; - CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice(); - if (!pRenderDevice) - return; - - m_pTextOut->SetRenderDevice(pRenderDevice); - CFX_Matrix mtPart = pParams->m_matrix; - CFX_Matrix* pMatrix = pGraphics->GetMatrix(); - if (pMatrix) { - mtPart.Concat(*pMatrix); - } - m_pTextOut->SetMatrix(mtPart); - m_pTextOut->DrawLogicText(pParams->m_wsText.c_str(), - pParams->m_wsText.GetLength(), pParams->m_rtPart); - return; - } - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); - if (!pWidget) - return; - - CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); - CXFA_Graphics* pGraphics = pParams->m_pGraphics; - CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice(); - if (!pRenderDevice) - return; - - m_pTextOut->SetRenderDevice(pRenderDevice); - m_pTextOut->SetStyles(pParams->m_dwTTOStyles); - m_pTextOut->SetAlignment(pParams->m_iTTOAlign); - m_pTextOut->SetFont(pAcc->GetFDEFont()); - m_pTextOut->SetFontSize(pAcc->GetFontSize()); - m_pTextOut->SetTextColor(pAcc->GetTextColor()); - CFX_Matrix mtPart = pParams->m_matrix; - CFX_Matrix* pMatrix = pGraphics->GetMatrix(); - if (pMatrix) - mtPart.Concat(*pMatrix); - - m_pTextOut->SetMatrix(mtPart); - m_pTextOut->DrawLogicText(pParams->m_wsText.c_str(), - pParams->m_wsText.GetLength(), pParams->m_rtPart); -} - -CFX_RectF CXFA_FWLTheme::GetUIMargin(CFWL_ThemePart* pThemePart) const { - CFX_RectF rect; - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget); - if (!pWidget) - return rect; - - CXFA_LayoutItem* pItem = pWidget; - CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); - rect = pWidgetAcc->GetUIMargin(); - if (CXFA_Para para = pWidgetAcc->GetPara()) { - rect.left += para.GetMarginLeft(); - if (pWidgetAcc->IsMultiLine()) - rect.width += para.GetMarginRight(); - } - if (!pItem->GetPrev()) { - if (pItem->GetNext()) - rect.height = 0; - } else if (!pItem->GetNext()) { - rect.top = 0; - } else { - rect.top = 0; - rect.height = 0; - } - return rect; -} - -float CXFA_FWLTheme::GetCXBorderSize() const { - return 1.0f; -} - -float CXFA_FWLTheme::GetCYBorderSize() const { - return 1.0f; -} - -float CXFA_FWLTheme::GetFontSize(CFWL_ThemePart* pThemePart) const { - if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) - return pWidget->GetDataAcc()->GetFontSize(); - return FWLTHEME_CAPACITY_FontSize; -} - -CFX_RetainPtr CXFA_FWLTheme::GetFont( - CFWL_ThemePart* pThemePart) const { - if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) - return pWidget->GetDataAcc()->GetFDEFont(); - return GetTheme(pThemePart->m_pWidget)->GetFont(); -} - -float CXFA_FWLTheme::GetLineHeight(CFWL_ThemePart* pThemePart) const { - if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) - return pWidget->GetDataAcc()->GetLineHeight(); - return kLineHeight; -} - -float CXFA_FWLTheme::GetScrollBarWidth() const { - return 9.0f; -} - -FX_COLORREF CXFA_FWLTheme::GetTextColor(CFWL_ThemePart* pThemePart) const { - if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) - return pWidget->GetDataAcc()->GetTextColor(); - return FWLTHEME_CAPACITY_TextColor; -} - -CFX_SizeF CXFA_FWLTheme::GetSpaceAboveBelow(CFWL_ThemePart* pThemePart) const { - CFX_SizeF sizeAboveBelow; - if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { - CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); - if (CXFA_Para para = pWidgetAcc->GetPara()) { - sizeAboveBelow.width = para.GetSpaceAbove(); - sizeAboveBelow.height = para.GetSpaceBelow(); - } - } - return sizeAboveBelow; -} - -void CXFA_FWLTheme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) { - if (pParams->m_pWidget->GetClassID() == FWL_Type::MonthCalendar) { - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); - if (!pWidget || !pParams || !m_pTextOut) - return; - - m_pTextOut->SetFont(m_pCalendarFont); - m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); - m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); - m_pTextOut->SetAlignment(pParams->m_iTTOAlign); - m_pTextOut->SetStyles(pParams->m_dwTTOStyles); - m_pTextOut->CalcLogicSize(pParams->m_wsText.c_str(), - pParams->m_wsText.GetLength(), rect); - } - - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); - if (!pWidget) - return; - - CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); - m_pTextOut->SetFont(pAcc->GetFDEFont()); - m_pTextOut->SetFontSize(pAcc->GetFontSize()); - m_pTextOut->SetTextColor(pAcc->GetTextColor()); - if (!pParams) - return; - - m_pTextOut->SetAlignment(pParams->m_iTTOAlign); - m_pTextOut->SetStyles(pParams->m_dwTTOStyles); - m_pTextOut->CalcLogicSize(pParams->m_wsText.c_str(), - pParams->m_wsText.GetLength(), rect); -} - -CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(CFWL_Widget* pWidget) const { - switch (pWidget->GetClassID()) { - case FWL_Type::CheckBox: - return m_pCheckBoxTP.get(); - case FWL_Type::ListBox: - return m_pListBoxTP.get(); - case FWL_Type::PictureBox: - return m_pPictureBoxTP.get(); - case FWL_Type::ScrollBar: - return m_pSrollBarTP.get(); - case FWL_Type::Edit: - return m_pEditTP.get(); - case FWL_Type::ComboBox: - return m_pComboBoxTP.get(); - case FWL_Type::MonthCalendar: - return m_pMonthCalendarTP.get(); - case FWL_Type::DateTimePicker: - return m_pDateTimePickerTP.get(); - case FWL_Type::PushButton: - return m_pPushButtonTP.get(); - case FWL_Type::Caret: - return m_pCaretTP.get(); - case FWL_Type::Barcode: - return m_pBarcodeTP.get(); - default: - return nullptr; - } -} diff --git a/xfa/fxfa/app/cxfa_fwltheme.h b/xfa/fxfa/app/cxfa_fwltheme.h deleted file mode 100644 index eaca99082d..0000000000 --- a/xfa/fxfa/app/cxfa_fwltheme.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_FWLTHEME_H_ -#define XFA_FXFA_APP_CXFA_FWLTHEME_H_ - -#include - -#include "xfa/fwl/ifwl_themeprovider.h" -#include "xfa/fwl/theme/cfwl_barcodetp.h" -#include "xfa/fwl/theme/cfwl_carettp.h" -#include "xfa/fwl/theme/cfwl_checkboxtp.h" -#include "xfa/fwl/theme/cfwl_comboboxtp.h" -#include "xfa/fwl/theme/cfwl_datetimepickertp.h" -#include "xfa/fwl/theme/cfwl_edittp.h" -#include "xfa/fwl/theme/cfwl_listboxtp.h" -#include "xfa/fwl/theme/cfwl_monthcalendartp.h" -#include "xfa/fwl/theme/cfwl_pictureboxtp.h" -#include "xfa/fwl/theme/cfwl_pushbuttontp.h" -#include "xfa/fwl/theme/cfwl_scrollbartp.h" -#include "xfa/fwl/theme/cfwl_widgettp.h" -#include "xfa/fxfa/cxfa_ffapp.h" - -class CXFA_FWLTheme final : public IFWL_ThemeProvider { - public: - explicit CXFA_FWLTheme(CXFA_FFApp* pApp); - ~CXFA_FWLTheme() override; - - // IFWL_ThemeProvider: - void DrawBackground(CFWL_ThemeBackground* pParams) override; - void DrawText(CFWL_ThemeText* pParams) override; - void CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) override; - float GetCXBorderSize() const override; - float GetCYBorderSize() const override; - CFX_RectF GetUIMargin(CFWL_ThemePart* pThemePart) const override; - float GetFontSize(CFWL_ThemePart* pThemePart) const override; - CFX_RetainPtr GetFont( - CFWL_ThemePart* pThemePart) const override; - float GetLineHeight(CFWL_ThemePart* pThemePart) const override; - float GetScrollBarWidth() const override; - FX_COLORREF GetTextColor(CFWL_ThemePart* pThemePart) const override; - CFX_SizeF GetSpaceAboveBelow(CFWL_ThemePart* pThemePart) const override; - - private: - CFWL_WidgetTP* GetTheme(CFWL_Widget* pWidget) const; - - std::unique_ptr m_pCheckBoxTP; - std::unique_ptr m_pListBoxTP; - std::unique_ptr m_pPictureBoxTP; - std::unique_ptr m_pSrollBarTP; - std::unique_ptr m_pEditTP; - std::unique_ptr m_pComboBoxTP; - std::unique_ptr m_pMonthCalendarTP; - std::unique_ptr m_pDateTimePickerTP; - std::unique_ptr m_pPushButtonTP; - std::unique_ptr m_pCaretTP; - std::unique_ptr m_pBarcodeTP; - std::unique_ptr m_pTextOut; - CFX_RetainPtr m_pCalendarFont; - CFX_WideString m_wsResource; - CFX_UnownedPtr const m_pApp; - CFX_RectF m_Rect; -}; - -CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget); - -#endif // XFA_FXFA_APP_CXFA_FWLTHEME_H_ diff --git a/xfa/fxfa/app/cxfa_linkuserdata.cpp b/xfa/fxfa/app/cxfa_linkuserdata.cpp deleted file mode 100644 index d657b28539..0000000000 --- a/xfa/fxfa/app/cxfa_linkuserdata.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_linkuserdata.h" - -CXFA_LinkUserData::CXFA_LinkUserData(wchar_t* pszText) - : m_wsURLContent(pszText) {} - -CXFA_LinkUserData::~CXFA_LinkUserData() {} diff --git a/xfa/fxfa/app/cxfa_linkuserdata.h b/xfa/fxfa/app/cxfa_linkuserdata.h deleted file mode 100644 index a3ccd92712..0000000000 --- a/xfa/fxfa/app/cxfa_linkuserdata.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_LINKUSERDATA_H_ -#define XFA_FXFA_APP_CXFA_LINKUSERDATA_H_ - -#include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" - -class CXFA_LinkUserData : public CFX_Retainable { - public: - template - friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); - - const wchar_t* GetLinkURL() const { return m_wsURLContent.c_str(); } - - private: - explicit CXFA_LinkUserData(wchar_t* pszText); - ~CXFA_LinkUserData() override; - - CFX_WideString m_wsURLContent; -}; - -#endif // XFA_FXFA_APP_CXFA_LINKUSERDATA_H_ diff --git a/xfa/fxfa/app/cxfa_loadercontext.cpp b/xfa/fxfa/app/cxfa_loadercontext.cpp deleted file mode 100644 index 2ac58ba07a..0000000000 --- a/xfa/fxfa/app/cxfa_loadercontext.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_loadercontext.h" - -CXFA_LoaderContext::CXFA_LoaderContext() - : m_bSaveLineHeight(false), - m_fWidth(0), - m_fHeight(0), - m_fLastPos(0), - m_fStartLineOffset(0), - m_iChar(0), - m_iTotalLines(-1), - m_dwFlags(0), - m_pXMLNode(nullptr), - m_pNode(nullptr) {} - -CXFA_LoaderContext::~CXFA_LoaderContext() {} diff --git a/xfa/fxfa/app/cxfa_loadercontext.h b/xfa/fxfa/app/cxfa_loadercontext.h deleted file mode 100644 index 553252e200..0000000000 --- a/xfa/fxfa/app/cxfa_loadercontext.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_LOADERCONTEXT_H_ -#define XFA_FXFA_APP_CXFA_LOADERCONTEXT_H_ - -#include - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" - -class CFX_XMLNode; -class CXFA_Node; - -class CXFA_LoaderContext { - public: - CXFA_LoaderContext(); - ~CXFA_LoaderContext(); - - bool m_bSaveLineHeight; - float m_fWidth; - float m_fHeight; - float m_fLastPos; - float m_fStartLineOffset; - int32_t m_iChar; - int32_t m_iLines; - int32_t m_iTotalLines; - uint32_t m_dwFlags; - CFX_XMLNode* m_pXMLNode; - CXFA_Node* m_pNode; - CFX_RetainPtr m_pParentStyle; - std::vector m_lineHeights; - std::vector m_BlocksHeight; -}; - -#endif // XFA_FXFA_APP_CXFA_LOADERCONTEXT_H_ diff --git a/xfa/fxfa/app/cxfa_pieceline.cpp b/xfa/fxfa/app/cxfa_pieceline.cpp deleted file mode 100644 index 2e1ea55f1c..0000000000 --- a/xfa/fxfa/app/cxfa_pieceline.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_pieceline.h" - -#include "xfa/fxfa/app/cxfa_textpiece.h" - -CXFA_PieceLine::CXFA_PieceLine() {} - -CXFA_PieceLine::~CXFA_PieceLine() {} diff --git a/xfa/fxfa/app/cxfa_pieceline.h b/xfa/fxfa/app/cxfa_pieceline.h deleted file mode 100644 index 6b17ebfb11..0000000000 --- a/xfa/fxfa/app/cxfa_pieceline.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_PIECELINE_H_ -#define XFA_FXFA_APP_CXFA_PIECELINE_H_ - -#include -#include - -#include "core/fxcrt/fx_basic.h" - -class CXFA_TextPiece; - -class CXFA_PieceLine { - public: - CXFA_PieceLine(); - ~CXFA_PieceLine(); - - std::vector> m_textPieces; - std::vector m_charCounts; -}; - -#endif // XFA_FXFA_APP_CXFA_PIECELINE_H_ diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp deleted file mode 100644 index 489df9ab9c..0000000000 --- a/xfa/fxfa/app/cxfa_textlayout.cpp +++ /dev/null @@ -1,1304 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_textlayout.h" - -#include -#include - -#include "core/fxcrt/xml/cfx_xmlelement.h" -#include "core/fxcrt/xml/cfx_xmlnode.h" -#include "core/fxcrt/xml/cfx_xmltext.h" -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_brush.h" -#include "xfa/fde/cfde_path.h" -#include "xfa/fde/cfde_pen.h" -#include "xfa/fde/cfde_renderdevice.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fxfa/app/cxfa_linkuserdata.h" -#include "xfa/fxfa/app/cxfa_loadercontext.h" -#include "xfa/fxfa/app/cxfa_pieceline.h" -#include "xfa/fxfa/app/cxfa_textparsecontext.h" -#include "xfa/fxfa/app/cxfa_textpiece.h" -#include "xfa/fxfa/app/cxfa_textprovider.h" -#include "xfa/fxfa/app/cxfa_texttabstopscontext.h" -#include "xfa/fxfa/app/cxfa_textuserdata.h" -#include "xfa/fxfa/parser/cxfa_font.h" -#include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_para.h" - -#define XFA_LOADERCNTXTFLG_FILTERSPACE 0x001 - -CXFA_TextLayout::CXFA_TextLayout(CXFA_TextProvider* pTextProvider) - : m_bHasBlock(false), - m_pTextProvider(pTextProvider), - m_pTextDataNode(nullptr), - m_bRichText(false), - m_iLines(0), - m_fMaxWidth(0), - m_bBlockContinue(true) { - ASSERT(m_pTextProvider); -} - -CXFA_TextLayout::~CXFA_TextLayout() { - m_textParser.Reset(); - Unload(); -} - -void CXFA_TextLayout::Unload() { - m_pieceLines.clear(); - m_pBreak.reset(); -} - -void CXFA_TextLayout::GetTextDataNode() { - if (!m_pTextProvider) - return; - - CXFA_Node* pNode = m_pTextProvider->GetTextNode(m_bRichText); - if (pNode && m_bRichText) - m_textParser.Reset(); - - m_pTextDataNode = pNode; -} - -CFX_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { - if (!m_bRichText) - return nullptr; - - CFX_XMLNode* pXMLRoot = m_pTextDataNode->GetXMLMappingNode(); - if (!pXMLRoot) - return nullptr; - - CFX_XMLNode* pXMLContainer = nullptr; - for (CFX_XMLNode* pXMLChild = pXMLRoot->GetNodeItem(CFX_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (pXMLChild->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast(pXMLChild); - CFX_WideString wsTag = pXMLElement->GetLocalTagName(); - if (wsTag == L"body" || wsTag == L"html") { - pXMLContainer = pXMLChild; - break; - } - } - } - return pXMLContainer; -} - -std::unique_ptr CXFA_TextLayout::CreateBreak(bool bDefault) { - uint32_t dwStyle = FX_LAYOUTSTYLE_ExpandTab; - if (!bDefault) - dwStyle |= FX_LAYOUTSTYLE_Pagination; - - auto pBreak = pdfium::MakeUnique(dwStyle); - pBreak->SetLineBreakTolerance(1); - pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, nullptr)); - pBreak->SetFontSize(m_textParser.GetFontSize(m_pTextProvider, nullptr)); - return pBreak; -} - -void CXFA_TextLayout::InitBreak(float fLineWidth) { - CXFA_Font font = m_pTextProvider->GetFontNode(); - CXFA_Para para = m_pTextProvider->GetParaNode(); - float fStart = 0; - float fStartPos = 0; - if (para) { - CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - iAlign = CFX_RTFLineAlignment::Center; - break; - case XFA_ATTRIBUTEENUM_Right: - iAlign = CFX_RTFLineAlignment::Right; - break; - case XFA_ATTRIBUTEENUM_Justify: - iAlign = CFX_RTFLineAlignment::Justified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - iAlign = CFX_RTFLineAlignment::Distributed; - break; - } - m_pBreak->SetAlignment(iAlign); - - fStart = para.GetMarginLeft(); - if (m_pTextProvider->IsCheckButtonAndAutoWidth()) { - if (iAlign != CFX_RTFLineAlignment::Left) - fLineWidth -= para.GetMarginRight(); - } else { - fLineWidth -= para.GetMarginRight(); - } - if (fLineWidth < 0) - fLineWidth = fStart; - - fStartPos = fStart; - float fIndent = para.GetTextIndent(); - if (fIndent > 0) - fStartPos += fIndent; - } - - m_pBreak->SetLineBoundary(fStart, fLineWidth); - m_pBreak->SetLineStartPos(fStartPos); - if (font) { - m_pBreak->SetHorizontalScale((int32_t)font.GetHorizontalScale()); - m_pBreak->SetVerticalScale((int32_t)font.GetVerticalScale()); - m_pBreak->SetCharSpace(font.GetLetterSpacing()); - } - - float fFontSize = m_textParser.GetFontSize(m_pTextProvider, nullptr); - m_pBreak->SetFontSize(fFontSize); - m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, nullptr)); - m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); -} - -void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, - FDE_CSSDisplay eDisplay, - float fLineWidth, - CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle) { - if (!pStyle) { - InitBreak(fLineWidth); - return; - } - - if (eDisplay == FDE_CSSDisplay::Block || - eDisplay == FDE_CSSDisplay::ListItem) { - CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; - switch (pStyle->GetTextAlign()) { - case FDE_CSSTextAlign::Right: - iAlign = CFX_RTFLineAlignment::Right; - break; - case FDE_CSSTextAlign::Center: - iAlign = CFX_RTFLineAlignment::Center; - break; - case FDE_CSSTextAlign::Justify: - iAlign = CFX_RTFLineAlignment::Justified; - break; - case FDE_CSSTextAlign::JustifyAll: - iAlign = CFX_RTFLineAlignment::Distributed; - break; - default: - break; - } - m_pBreak->SetAlignment(iAlign); - - float fStart = 0; - const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); - const FDE_CSSRect* pPaddingRect = pStyle->GetPaddingWidth(); - if (pRect) { - fStart = pRect->left.GetValue(); - fLineWidth -= pRect->right.GetValue(); - if (pPaddingRect) { - fStart += pPaddingRect->left.GetValue(); - fLineWidth -= pPaddingRect->right.GetValue(); - } - if (eDisplay == FDE_CSSDisplay::ListItem) { - const FDE_CSSRect* pParRect = pParentStyle->GetMarginWidth(); - const FDE_CSSRect* pParPaddingRect = pParentStyle->GetPaddingWidth(); - if (pParRect) { - fStart += pParRect->left.GetValue(); - fLineWidth -= pParRect->right.GetValue(); - if (pParPaddingRect) { - fStart += pParPaddingRect->left.GetValue(); - fLineWidth -= pParPaddingRect->right.GetValue(); - } - } - FDE_CSSRect pNewRect; - pNewRect.left.Set(FDE_CSSLengthUnit::Point, fStart); - pNewRect.right.Set(FDE_CSSLengthUnit::Point, pRect->right.GetValue()); - pNewRect.top.Set(FDE_CSSLengthUnit::Point, pRect->top.GetValue()); - pNewRect.bottom.Set(FDE_CSSLengthUnit::Point, pRect->bottom.GetValue()); - pStyle->SetMarginWidth(pNewRect); - } - } - m_pBreak->SetLineBoundary(fStart, fLineWidth); - float fIndent = pStyle->GetTextIndent().GetValue(); - if (fIndent > 0) - fStart += fIndent; - - m_pBreak->SetLineStartPos(fStart); - m_pBreak->SetTabWidth(m_textParser.GetTabInterval(pStyle)); - if (!m_pTabstopContext) - m_pTabstopContext = pdfium::MakeUnique(); - m_textParser.GetTabstops(pStyle, m_pTabstopContext.get()); - for (const auto& stop : m_pTabstopContext->m_tabstops) - m_pBreak->AddPositionedTab(stop.fTabstops); - } - float fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); - m_pBreak->SetFontSize(fFontSize); - m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); - m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, pStyle)); - m_pBreak->SetHorizontalScale( - m_textParser.GetHorScale(m_pTextProvider, pStyle, pXMLNode)); - m_pBreak->SetVerticalScale(m_textParser.GetVerScale(m_pTextProvider, pStyle)); - m_pBreak->SetCharSpace(pStyle->GetLetterSpacing().GetValue()); -} - -int32_t CXFA_TextLayout::GetText(CFX_WideString& wsText) { - GetTextDataNode(); - wsText.clear(); - if (!m_bRichText) - wsText = m_pTextDataNode->GetContent(); - return wsText.GetLength(); -} - -float CXFA_TextLayout::GetLayoutHeight() { - if (!m_pLoader) - return 0; - - if (m_pLoader->m_lineHeights.empty() && m_pLoader->m_fWidth > 0) { - CFX_SizeF szMax(m_pLoader->m_fWidth, m_pLoader->m_fHeight); - CFX_SizeF szDef; - m_pLoader->m_bSaveLineHeight = true; - m_pLoader->m_fLastPos = 0; - CalcSize(szMax, szMax, szDef); - m_pLoader->m_bSaveLineHeight = false; - return szDef.height; - } - - float fHeight = m_pLoader->m_fHeight; - if (fHeight < 0.1f) { - fHeight = 0; - for (float value : m_pLoader->m_lineHeights) - fHeight += value; - } - return fHeight; -} - -float CXFA_TextLayout::StartLayout(float fWidth) { - if (!m_pLoader) - m_pLoader = pdfium::MakeUnique(); - - if (fWidth < 0 || - (m_pLoader->m_fWidth > -1 && fabs(fWidth - m_pLoader->m_fWidth) > 0)) { - m_pLoader->m_lineHeights.clear(); - m_Blocks.clear(); - Unload(); - m_pLoader->m_fStartLineOffset = 0; - } - m_pLoader->m_fWidth = fWidth; - - if (fWidth < 0) { - CFX_SizeF szMax; - CFX_SizeF szDef; - m_pLoader->m_bSaveLineHeight = true; - m_pLoader->m_fLastPos = 0; - CalcSize(szMax, szMax, szDef); - m_pLoader->m_bSaveLineHeight = false; - fWidth = szDef.width; - } - return fWidth; -} - -bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, - float& fCalcHeight, - float fContentAreaHeight, - float fTextHeight) { - if (!m_pLoader) - return false; - - int32_t iBlockCount = pdfium::CollectionSize(m_Blocks); - float fHeight = fTextHeight; - if (fHeight < 0) - fHeight = GetLayoutHeight(); - - m_pLoader->m_fHeight = fHeight; - if (fContentAreaHeight < 0) - return false; - - m_bHasBlock = true; - if (iBlockCount == 0 && fHeight > 0) { - fHeight = fTextHeight - GetLayoutHeight(); - if (fHeight > 0) { - int32_t iAlign = m_textParser.GetVAlign(m_pTextProvider); - if (iAlign == XFA_ATTRIBUTEENUM_Middle) - fHeight /= 2.0f; - else if (iAlign != XFA_ATTRIBUTEENUM_Bottom) - fHeight = 0; - m_pLoader->m_fStartLineOffset = fHeight; - } - } - - float fLinePos = m_pLoader->m_fStartLineOffset; - int32_t iLineIndex = 0; - if (iBlockCount > 1) { - if (iBlockCount >= (iBlockIndex + 1) * 2) { - iLineIndex = m_Blocks[iBlockIndex * 2]; - } else { - iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; - } - if (!m_pLoader->m_BlocksHeight.empty()) { - for (int32_t i = 0; i < iBlockIndex; i++) - fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; - } - } - - int32_t iCount = pdfium::CollectionSize(m_pLoader->m_lineHeights); - int32_t i = 0; - for (i = iLineIndex; i < iCount; i++) { - float fLineHeight = m_pLoader->m_lineHeights[i]; - if (i == iLineIndex && fLineHeight - fContentAreaHeight > 0.001) { - fCalcHeight = 0; - return true; - } - if (fLinePos + fLineHeight - fContentAreaHeight > 0.001) { - if (iBlockCount >= (iBlockIndex + 1) * 2) { - m_Blocks[iBlockIndex * 2] = iLineIndex; - m_Blocks[iBlockIndex * 2 + 1] = i - iLineIndex; - } else { - m_Blocks.push_back(iLineIndex); - m_Blocks.push_back(i - iLineIndex); - } - if (i == iLineIndex) { - if (fCalcHeight <= fLinePos) { - if (pdfium::CollectionSize(m_pLoader->m_BlocksHeight) > - iBlockIndex * 2 && - (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { - m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; - } else { - m_pLoader->m_BlocksHeight.push_back((float)iBlockIndex); - m_pLoader->m_BlocksHeight.push_back(fCalcHeight); - } - } - return true; - } - - fCalcHeight = fLinePos; - return true; - } - fLinePos += fLineHeight; - } - return false; -} - -int32_t CXFA_TextLayout::CountBlocks() const { - int32_t iCount = pdfium::CollectionSize(m_Blocks) / 2; - return iCount > 0 ? iCount : 1; -} - -bool CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize, - const CFX_SizeF& maxSize, - CFX_SizeF& defaultSize) { - defaultSize.width = maxSize.width; - if (defaultSize.width < 1) - defaultSize.width = 0xFFFF; - - m_pBreak = CreateBreak(false); - float fLinePos = 0; - m_iLines = 0; - m_fMaxWidth = 0; - Loader(defaultSize, fLinePos, false); - if (fLinePos < 0.1f) - fLinePos = m_textParser.GetFontSize(m_pTextProvider, nullptr); - - m_pTabstopContext.reset(); - defaultSize = CFX_SizeF(m_fMaxWidth, fLinePos); - return true; -} - -bool CXFA_TextLayout::Layout(const CFX_SizeF& size, float* fHeight) { - if (size.width < 1) - return false; - - Unload(); - m_pBreak = CreateBreak(true); - if (m_pLoader) { - m_pLoader->m_iTotalLines = -1; - m_pLoader->m_iChar = 0; - } - - m_iLines = 0; - float fLinePos = 0; - Loader(size, fLinePos, true); - UpdateAlign(size.height, fLinePos); - m_pTabstopContext.reset(); - if (fHeight) - *fHeight = fLinePos; - return true; -} - -bool CXFA_TextLayout::Layout(int32_t iBlock) { - if (!m_pLoader || iBlock < 0 || iBlock >= CountBlocks()) - return false; - if (m_pLoader->m_fWidth < 1) - return false; - - m_pLoader->m_iTotalLines = -1; - m_iLines = 0; - float fLinePos = 0; - CXFA_Node* pNode = nullptr; - CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); - int32_t iCount = pdfium::CollectionSize(m_Blocks); - int32_t iBlocksHeightCount = - pdfium::CollectionSize(m_pLoader->m_BlocksHeight); - iBlocksHeightCount /= 2; - if (iBlock < iBlocksHeightCount) - return true; - if (iBlock == iBlocksHeightCount) { - Unload(); - m_pBreak = CreateBreak(true); - fLinePos = m_pLoader->m_fStartLineOffset; - for (int32_t i = 0; i < iBlocksHeightCount; i++) - fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; - - m_pLoader->m_iChar = 0; - if (iCount > 1) - m_pLoader->m_iTotalLines = m_Blocks[iBlock * 2 + 1]; - - Loader(szText, fLinePos, true); - if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) - UpdateAlign(szText.height, fLinePos); - } else if (m_pTextDataNode) { - iBlock *= 2; - if (iBlock < iCount - 2) - m_pLoader->m_iTotalLines = m_Blocks[iBlock + 1]; - - m_pBreak->Reset(); - if (m_bRichText) { - CFX_XMLNode* pContainerNode = GetXMLContainerNode(); - if (!pContainerNode) - return true; - - CFX_XMLNode* pXMLNode = m_pLoader->m_pXMLNode; - if (!pXMLNode) - return true; - - CFX_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; - for (; pXMLNode; - pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, - true, nullptr)) { - break; - } - } - while (!pXMLNode) { - pXMLNode = pSaveXMLNode->GetNodeItem(CFX_XMLNode::Parent); - if (pXMLNode == pContainerNode) - break; - if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, - true, nullptr, false)) { - break; - } - pSaveXMLNode = pXMLNode; - pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling); - if (!pXMLNode) - continue; - for (; pXMLNode; - pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (!LoadRichText(pXMLNode, szText, fLinePos, - m_pLoader->m_pParentStyle, true, nullptr)) { - break; - } - } - } - } else { - pNode = m_pLoader->m_pNode; - if (!pNode) - return true; - LoadText(pNode, szText, fLinePos, true); - } - } - if (iBlock == iCount) { - m_pTabstopContext.reset(); - m_pLoader.reset(); - } - return true; -} - -void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { - if (!m_pLoader) - return; - - int32_t iCountHeight = - pdfium::CollectionSize(m_pLoader->m_lineHeights); - if (iCountHeight == 0) - return; - - bool bEndItem = true; - int32_t iBlockCount = pdfium::CollectionSize(m_Blocks); - float fLinePos = m_pLoader->m_fStartLineOffset; - int32_t iLineIndex = 0; - if (iBlockIndex > 0) { - int32_t iBlockHeightCount = - pdfium::CollectionSize(m_pLoader->m_BlocksHeight); - iBlockHeightCount /= 2; - if (iBlockHeightCount >= iBlockIndex) { - for (int32_t i = 0; i < iBlockIndex; i++) - fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; - } else { - fLinePos = 0; - } - iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; - } - - int32_t i = 0; - for (i = iLineIndex; i < iCountHeight; i++) { - float fLineHeight = m_pLoader->m_lineHeights[i]; - if (fLinePos + fLineHeight - rtText.height > 0.001) { - m_Blocks.push_back(iLineIndex); - m_Blocks.push_back(i - iLineIndex); - bEndItem = false; - break; - } - fLinePos += fLineHeight; - } - if (iCountHeight > 0 && (i - iLineIndex) > 0 && bEndItem) { - m_Blocks.push_back(iLineIndex); - m_Blocks.push_back(i - iLineIndex); - } -} - -bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, - const CFX_Matrix& tmDoc2Device, - const CFX_RectF& rtClip, - int32_t iBlock) { - if (!pFxDevice) - return false; - - auto pDevice = pdfium::MakeUnique(pFxDevice); - pDevice->SaveState(); - pDevice->SetClipRect(rtClip); - - auto pSolidBrush = pdfium::MakeUnique(); - auto pPen = pdfium::MakeUnique(); - if (m_pieceLines.empty()) { - int32_t iBlockCount = CountBlocks(); - for (int32_t i = 0; i < iBlockCount; i++) - Layout(i); - } - - FXTEXT_CHARPOS* pCharPos = nullptr; - int32_t iCharCount = 0; - int32_t iLineStart = 0; - int32_t iPieceLines = pdfium::CollectionSize(m_pieceLines); - int32_t iCount = pdfium::CollectionSize(m_Blocks); - if (iCount > 0) { - iBlock *= 2; - if (iBlock < iCount) { - iLineStart = m_Blocks[iBlock]; - iPieceLines = m_Blocks[iBlock + 1]; - } else { - iPieceLines = 0; - } - } - - for (int32_t i = 0; i < iPieceLines; i++) { - if (i + iLineStart >= pdfium::CollectionSize(m_pieceLines)) - break; - - CXFA_PieceLine* pPieceLine = m_pieceLines[i + iLineStart].get(); - int32_t iPieces = pdfium::CollectionSize(pPieceLine->m_textPieces); - int32_t j = 0; - for (j = 0; j < iPieces; j++) { - const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[j].get(); - int32_t iChars = pPiece->iChars; - if (iCharCount < iChars) { - FX_Free(pCharPos); - pCharPos = FX_Alloc(FXTEXT_CHARPOS, iChars); - iCharCount = iChars; - } - memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); - RenderString(pDevice.get(), pSolidBrush.get(), pPieceLine, j, pCharPos, - tmDoc2Device); - } - for (j = 0; j < iPieces; j++) { - RenderPath(pDevice.get(), pPen.get(), pPieceLine, j, pCharPos, - tmDoc2Device); - } - } - pDevice->RestoreState(); - FX_Free(pCharPos); - return iPieceLines > 0; -} - -void CXFA_TextLayout::UpdateAlign(float fHeight, float fBottom) { - fHeight -= fBottom; - if (fHeight < 0.1f) - return; - - switch (m_textParser.GetVAlign(m_pTextProvider)) { - case XFA_ATTRIBUTEENUM_Middle: - fHeight /= 2.0f; - break; - case XFA_ATTRIBUTEENUM_Bottom: - break; - default: - return; - } - - for (const auto& pPieceLine : m_pieceLines) { - for (const auto& pPiece : pPieceLine->m_textPieces) - pPiece->rtPiece.top += fHeight; - } -} - -bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, - float& fLinePos, - bool bSavePieces) { - GetTextDataNode(); - if (!m_pTextDataNode) - return true; - - if (m_bRichText) { - CFX_XMLNode* pXMLContainer = GetXMLContainerNode(); - if (pXMLContainer) { - if (!m_textParser.IsParsed()) - m_textParser.DoParse(pXMLContainer, m_pTextProvider); - - auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider); - LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces, - nullptr); - } - } else { - LoadText(m_pTextDataNode, szText, fLinePos, bSavePieces); - } - return true; -} - -void CXFA_TextLayout::LoadText(CXFA_Node* pNode, - const CFX_SizeF& szText, - float& fLinePos, - bool bSavePieces) { - InitBreak(szText.width); - - CXFA_Para para = m_pTextProvider->GetParaNode(); - float fSpaceAbove = 0; - if (para) { - fSpaceAbove = para.GetSpaceAbove(); - if (fSpaceAbove < 0.1f) { - fSpaceAbove = 0; - } - int32_t verAlign = para.GetVerticalAlign(); - switch (verAlign) { - case XFA_ATTRIBUTEENUM_Top: - case XFA_ATTRIBUTEENUM_Middle: - case XFA_ATTRIBUTEENUM_Bottom: { - fLinePos += fSpaceAbove; - break; - } - } - } - - CFX_WideString wsText = pNode->GetContent(); - wsText.TrimRight(L" "); - bool bRet = AppendChar(wsText, fLinePos, fSpaceAbove, bSavePieces); - if (bRet && m_pLoader) - m_pLoader->m_pNode = pNode; - else - EndBreak(CFX_BreakType::Paragraph, fLinePos, bSavePieces); -} - -bool CXFA_TextLayout::LoadRichText( - CFX_XMLNode* pXMLNode, - const CFX_SizeF& szText, - float& fLinePos, - const CFX_RetainPtr& pParentStyle, - bool bSavePieces, - CFX_RetainPtr pLinkData, - bool bEndBreak, - bool bIsOl, - int32_t iLiCount) { - if (!pXMLNode) - return false; - - CXFA_TextParseContext* pContext = - m_textParser.GetParseContextFromMap(pXMLNode); - FDE_CSSDisplay eDisplay = FDE_CSSDisplay::None; - bool bContentNode = false; - float fSpaceBelow = 0; - CFX_RetainPtr pStyle; - CFX_WideString wsName; - if (bEndBreak) { - bool bCurOl = false; - bool bCurLi = false; - CFX_XMLElement* pElement = nullptr; - if (pContext) { - if (m_bBlockContinue || - (m_pLoader && pXMLNode == m_pLoader->m_pXMLNode)) { - m_bBlockContinue = true; - } - if (pXMLNode->GetType() == FX_XMLNODE_Text) { - bContentNode = true; - } else if (pXMLNode->GetType() == FX_XMLNODE_Element) { - pElement = static_cast(pXMLNode); - wsName = pElement->GetLocalTagName(); - } - if (wsName == L"ol") { - bIsOl = true; - bCurOl = true; - } - if (m_bBlockContinue || bContentNode == false) { - eDisplay = pContext->GetDisplay(); - if (eDisplay != FDE_CSSDisplay::Block && - eDisplay != FDE_CSSDisplay::Inline && - eDisplay != FDE_CSSDisplay::ListItem) { - return true; - } - - pStyle = m_textParser.ComputeStyle(pXMLNode, pParentStyle.Get()); - InitBreak(bContentNode ? pParentStyle.Get() : pStyle.Get(), eDisplay, - szText.width, pXMLNode, pParentStyle.Get()); - if ((eDisplay == FDE_CSSDisplay::Block || - eDisplay == FDE_CSSDisplay::ListItem) && - pStyle && - (wsName.IsEmpty() || (wsName != L"body" && wsName != L"html" && - wsName != L"ol" && wsName != L"ul"))) { - const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); - if (pRect) { - fLinePos += pRect->top.GetValue(); - fSpaceBelow = pRect->bottom.GetValue(); - } - } - - if (wsName == L"a") { - ASSERT(pElement); - CFX_WideString wsLinkContent = pElement->GetString(L"href"); - if (!wsLinkContent.IsEmpty()) { - pLinkData = pdfium::MakeRetain( - wsLinkContent.GetBuffer(wsLinkContent.GetLength())); - wsLinkContent.ReleaseBuffer(wsLinkContent.GetLength()); - } - } - - int32_t iTabCount = m_textParser.CountTabs( - bContentNode ? pParentStyle.Get() : pStyle.Get()); - bool bSpaceRun = m_textParser.IsSpaceRun( - bContentNode ? pParentStyle.Get() : pStyle.Get()); - CFX_WideString wsText; - if (bContentNode && iTabCount == 0) { - wsText = static_cast(pXMLNode)->GetText(); - } else if (wsName == L"br") { - wsText = L'\n'; - } else if (wsName == L"li") { - bCurLi = true; - if (bIsOl) - wsText.Format(L"%d. ", iLiCount); - else - wsText = 0x00B7 + CFX_WideStringC(L" ", 1); - } else if (!bContentNode) { - if (iTabCount > 0) { - while (iTabCount-- > 0) - wsText += L'\t'; - } else { - m_textParser.GetEmbbedObj(m_pTextProvider, pXMLNode, wsText); - } - } - - int32_t iLength = wsText.GetLength(); - if (iLength > 0 && bContentNode && !bSpaceRun) - ProcessText(wsText); - - if (m_pLoader) { - if (wsText.GetLength() > 0 && - (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { - wsText.TrimLeft(0x20); - } - if (FDE_CSSDisplay::Block == eDisplay) { - m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; - } else if (FDE_CSSDisplay::Inline == eDisplay && - (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { - m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; - } else if (wsText.GetLength() > 0 && - (0x20 == wsText.GetAt(wsText.GetLength() - 1))) { - m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; - } else if (wsText.GetLength() != 0) { - m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; - } - } - - if (wsText.GetLength() > 0) { - if (!m_pLoader || m_pLoader->m_iChar == 0) { - auto pUserData = pdfium::MakeRetain( - bContentNode ? pParentStyle : pStyle, pLinkData); - m_pBreak->SetUserData(pUserData); - } - - if (AppendChar(wsText, fLinePos, 0, bSavePieces)) { - if (m_pLoader) - m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; - if (IsEnd(bSavePieces)) { - if (m_pLoader && m_pLoader->m_iTotalLines > -1) { - m_pLoader->m_pXMLNode = pXMLNode; - m_pLoader->m_pParentStyle = pParentStyle; - } - return false; - } - return true; - } - } - } - } - - for (CFX_XMLNode* pChildNode = - pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); - pChildNode; - pChildNode = pChildNode->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (bCurOl) - iLiCount++; - - if (!LoadRichText(pChildNode, szText, fLinePos, - pContext ? pStyle : pParentStyle, bSavePieces, - pLinkData, true, bIsOl, iLiCount)) - return false; - } - - if (m_pLoader) { - if (FDE_CSSDisplay::Block == eDisplay) - m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; - } - if (bCurLi) - EndBreak(CFX_BreakType::Line, fLinePos, bSavePieces); - } else { - if (pContext) - eDisplay = pContext->GetDisplay(); - } - - if (m_bBlockContinue) { - if (pContext && !bContentNode) { - CFX_BreakType dwStatus = (eDisplay == FDE_CSSDisplay::Block) - ? CFX_BreakType::Paragraph - : CFX_BreakType::Piece; - EndBreak(dwStatus, fLinePos, bSavePieces); - if (eDisplay == FDE_CSSDisplay::Block) { - fLinePos += fSpaceBelow; - if (m_pTabstopContext) - m_pTabstopContext->RemoveAll(); - } - if (IsEnd(bSavePieces)) { - if (m_pLoader && m_pLoader->m_iTotalLines > -1) { - m_pLoader->m_pXMLNode = - pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling); - m_pLoader->m_pParentStyle = pParentStyle; - } - return false; - } - } - } - return true; -} - -bool CXFA_TextLayout::AppendChar(const CFX_WideString& wsText, - float& fLinePos, - float fSpaceAbove, - bool bSavePieces) { - CFX_BreakType dwStatus = CFX_BreakType::None; - int32_t iChar = 0; - if (m_pLoader) - iChar = m_pLoader->m_iChar; - - int32_t iLength = wsText.GetLength(); - for (int32_t i = iChar; i < iLength; i++) { - wchar_t wch = wsText.GetAt(i); - if (wch == 0xA0) - wch = 0x20; - - dwStatus = m_pBreak->AppendChar(wch); - if (dwStatus != CFX_BreakType::None && dwStatus != CFX_BreakType::Piece) { - AppendTextLine(dwStatus, fLinePos, bSavePieces); - if (IsEnd(bSavePieces)) { - if (m_pLoader) - m_pLoader->m_iChar = i; - return true; - } - if (dwStatus == CFX_BreakType::Paragraph && m_bRichText) - fLinePos += fSpaceAbove; - } - } - if (m_pLoader) - m_pLoader->m_iChar = 0; - - return false; -} - -bool CXFA_TextLayout::IsEnd(bool bSavePieces) { - if (!bSavePieces) - return false; - if (m_pLoader && m_pLoader->m_iTotalLines > 0) - return m_iLines >= m_pLoader->m_iTotalLines; - return false; -} - -void CXFA_TextLayout::ProcessText(CFX_WideString& wsText) { - int32_t iLen = wsText.GetLength(); - if (iLen == 0) - return; - - wchar_t* psz = wsText.GetBuffer(iLen); - int32_t iTrimLeft = 0; - wchar_t wch = 0, wPrev = 0; - for (int32_t i = 0; i < iLen; i++) { - wch = psz[i]; - if (wch < 0x20) - wch = 0x20; - if (wch == 0x20 && wPrev == 0x20) - continue; - - wPrev = wch; - psz[iTrimLeft++] = wch; - } - wsText.ReleaseBuffer(iLen); - wsText = wsText.Left(iTrimLeft); -} - -void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, - float& fLinePos, - bool bSavePieces) { - dwStatus = m_pBreak->EndBreak(dwStatus); - if (dwStatus != CFX_BreakType::None && dwStatus != CFX_BreakType::Piece) - AppendTextLine(dwStatus, fLinePos, bSavePieces, true); -} - -void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, - CXFA_PieceLine* pPieceLine) { - if (!pStyle || !pPieceLine) - return; - - if (!m_pTabstopContext || m_pTabstopContext->m_tabstops.empty()) - return; - - int32_t iPieces = pdfium::CollectionSize(pPieceLine->m_textPieces); - if (iPieces == 0) - return; - - CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get(); - int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; - int32_t iCount = m_textParser.CountTabs(pStyle); - if (!pdfium::IndexInBounds(m_pTabstopContext->m_tabstops, iTabstopsIndex)) - return; - - if (iCount > 0) { - iTabstopsIndex++; - m_pTabstopContext->m_bTabstops = true; - float fRight = 0; - if (iPieces > 1) { - CXFA_TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get(); - fRight = p->rtPiece.right(); - } - m_pTabstopContext->m_fTabWidth = - pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; - } else if (iTabstopsIndex > -1) { - float fLeft = 0; - if (m_pTabstopContext->m_bTabstops) { - uint32_t dwAlign = m_pTabstopContext->m_tabstops[iTabstopsIndex].dwAlign; - if (dwAlign == FX_HashCode_GetW(L"center", false)) { - fLeft = pPiece->rtPiece.width / 2.0f; - } else if (dwAlign == FX_HashCode_GetW(L"right", false) || - dwAlign == FX_HashCode_GetW(L"before", false)) { - fLeft = pPiece->rtPiece.width; - } else if (dwAlign == FX_HashCode_GetW(L"decimal", false)) { - int32_t iChars = pPiece->iChars; - for (int32_t i = 0; i < iChars; i++) { - if (pPiece->szText[i] == L'.') - break; - - fLeft += pPiece->Widths[i] / 20000.0f; - } - } - m_pTabstopContext->m_fLeft = - std::min(fLeft, m_pTabstopContext->m_fTabWidth); - m_pTabstopContext->m_bTabstops = false; - m_pTabstopContext->m_fTabWidth = 0; - } - pPiece->rtPiece.left -= m_pTabstopContext->m_fLeft; - } -} - -void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, - float& fLinePos, - bool bSavePieces, - bool bEndBreak) { - int32_t iPieces = m_pBreak->CountBreakPieces(); - if (iPieces < 1) - return; - - CFX_RetainPtr pStyle; - if (bSavePieces) { - auto pNew = pdfium::MakeUnique(); - CXFA_PieceLine* pPieceLine = pNew.get(); - m_pieceLines.push_back(std::move(pNew)); - if (m_pTabstopContext) - m_pTabstopContext->Reset(); - - float fLineStep = 0, fBaseLine = 0; - int32_t i = 0; - for (i = 0; i < iPieces; i++) { - const CFX_BreakPiece* pPiece = m_pBreak->GetBreakPieceUnstable(i); - CXFA_TextUserData* pUserData = pPiece->m_pUserData.Get(); - if (pUserData) - pStyle = pUserData->m_pStyle; - float fVerScale = pPiece->m_iVerticalScale / 100.0f; - - auto pTP = pdfium::MakeUnique(); - pTP->iChars = pPiece->m_iChars; - pTP->szText = pPiece->GetString(); - pTP->Widths = pPiece->GetWidths(); - pTP->iBidiLevel = pPiece->m_iBidiLevel; - pTP->iHorScale = pPiece->m_iHorizontalScale; - pTP->iVerScale = pPiece->m_iVerticalScale; - m_textParser.GetUnderline(m_pTextProvider, pStyle.Get(), pTP->iUnderline, - pTP->iPeriod); - m_textParser.GetLinethrough(m_pTextProvider, pStyle.Get(), - pTP->iLineThrough); - pTP->dwColor = m_textParser.GetColor(m_pTextProvider, pStyle.Get()); - pTP->pFont = m_textParser.GetFont(m_pTextProvider, pStyle.Get()); - pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle.Get()); - pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f; - pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f; - pTP->rtPiece.height = (float)pPiece->m_iFontSize * fVerScale / 20.0f; - float fBaseLineTemp = - m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); - pTP->rtPiece.top = fBaseLineTemp; - - float fLineHeight = m_textParser.GetLineHeight( - m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); - if (fBaseLineTemp > 0) { - float fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; - if (fLineHeight < fLineHeightTmp) - fLineHeight = fLineHeightTmp; - else - fBaseLineTemp = 0; - } else if (fBaseLine < -fBaseLineTemp) { - fBaseLine = -fBaseLineTemp; - } - fLineStep = std::max(fLineStep, fLineHeight); - pTP->pLinkData = pUserData ? pUserData->m_pLinkData : nullptr; - pPieceLine->m_textPieces.push_back(std::move(pTP)); - DoTabstops(pStyle.Get(), pPieceLine); - } - for (const auto& pTP : pPieceLine->m_textPieces) { - float& fTop = pTP->rtPiece.top; - float fBaseLineTemp = fTop; - fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp; - fTop = std::max(0.0f, fTop); - } - fLinePos += fLineStep + fBaseLine; - } else { - float fLineStep = 0; - float fLineWidth = 0; - for (int32_t i = 0; i < iPieces; i++) { - const CFX_BreakPiece* pPiece = m_pBreak->GetBreakPieceUnstable(i); - CXFA_TextUserData* pUserData = pPiece->m_pUserData.Get(); - if (pUserData) - pStyle = pUserData->m_pStyle; - float fVerScale = pPiece->m_iVerticalScale / 100.0f; - float fBaseLine = m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); - float fLineHeight = m_textParser.GetLineHeight( - m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); - if (fBaseLine > 0) { - float fLineHeightTmp = - fBaseLine + (float)pPiece->m_iFontSize * fVerScale / 20.0f; - if (fLineHeight < fLineHeightTmp) { - fLineHeight = fLineHeightTmp; - } - } - fLineStep = std::max(fLineStep, fLineHeight); - fLineWidth += pPiece->m_iWidth / 20000.0f; - } - fLinePos += fLineStep; - m_fMaxWidth = std::max(m_fMaxWidth, fLineWidth); - if (m_pLoader && m_pLoader->m_bSaveLineHeight) { - float fHeight = fLinePos - m_pLoader->m_fLastPos; - m_pLoader->m_fLastPos = fLinePos; - m_pLoader->m_lineHeights.push_back(fHeight); - } - } - - m_pBreak->ClearBreakPieces(); - if (dwStatus == CFX_BreakType::Paragraph) { - m_pBreak->Reset(); - if (!pStyle && bEndBreak) { - CXFA_Para para = m_pTextProvider->GetParaNode(); - if (para) { - float fStartPos = para.GetMarginLeft(); - float fIndent = para.GetTextIndent(); - if (fIndent > 0) - fStartPos += fIndent; - - float fSpaceBelow = para.GetSpaceBelow(); - if (fSpaceBelow < 0.1f) - fSpaceBelow = 0; - - m_pBreak->SetLineStartPos(fStartPos); - fLinePos += fSpaceBelow; - } - } - } - - if (pStyle) { - float fStart = 0; - const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); - if (pRect) - fStart = pRect->left.GetValue(); - - float fTextIndent = pStyle->GetTextIndent().GetValue(); - if (fTextIndent < 0) - fStart -= fTextIndent; - - m_pBreak->SetLineStartPos(fStart); - } - m_iLines++; -} - -void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, - CFDE_Brush* pBrush, - CXFA_PieceLine* pPieceLine, - int32_t iPiece, - FXTEXT_CHARPOS* pCharPos, - const CFX_Matrix& tmDoc2Device) { - const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); - int32_t iCount = GetDisplayPos(pPiece, pCharPos); - if (iCount > 0) { - pBrush->SetColor(pPiece->dwColor); - pDevice->DrawString(pBrush, pPiece->pFont, pCharPos, iCount, - pPiece->fFontSize, &tmDoc2Device); - } - pPieceLine->m_charCounts.push_back(iCount); -} - -void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, - CFDE_Pen* pPen, - CXFA_PieceLine* pPieceLine, - int32_t iPiece, - FXTEXT_CHARPOS* pCharPos, - const CFX_Matrix& tmDoc2Device) { - CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); - bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2; - bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; - if (bNoUnderline && bNoLineThrough) - return; - - pPen->SetColor(pPiece->dwColor); - auto pPath = pdfium::MakeUnique(); - int32_t iChars = GetDisplayPos(pPiece, pCharPos); - if (iChars > 0) { - CFX_PointF pt1, pt2; - float fEndY = pCharPos[0].m_Origin.y + 1.05f; - if (pPiece->iPeriod == XFA_ATTRIBUTEENUM_Word) { - for (int32_t i = 0; i < pPiece->iUnderline; i++) { - for (int32_t j = 0; j < iChars; j++) { - pt1.x = pCharPos[j].m_Origin.x; - pt2.x = - pt1.x + pCharPos[j].m_FontCharWidth * pPiece->fFontSize / 1000.0f; - pt1.y = pt2.y = fEndY; - pPath->AddLine(pt1, pt2); - } - fEndY += 2.0f; - } - } else { - pt1.x = pCharPos[0].m_Origin.x; - pt2.x = - pCharPos[iChars - 1].m_Origin.x + - pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; - for (int32_t i = 0; i < pPiece->iUnderline; i++) { - pt1.y = pt2.y = fEndY; - pPath->AddLine(pt1, pt2); - fEndY += 2.0f; - } - } - fEndY = pCharPos[0].m_Origin.y - pPiece->rtPiece.height * 0.25f; - pt1.x = pCharPos[0].m_Origin.x; - pt2.x = pCharPos[iChars - 1].m_Origin.x + - pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; - for (int32_t i = 0; i < pPiece->iLineThrough; i++) { - pt1.y = pt2.y = fEndY; - pPath->AddLine(pt1, pt2); - fEndY += 2.0f; - } - } else { - if (bNoLineThrough && - (bNoUnderline || pPiece->iPeriod != XFA_ATTRIBUTEENUM_All)) { - return; - } - int32_t iCharsTmp = 0; - int32_t iPiecePrev = iPiece; - int32_t iPieceNext = iPiece; - while (iPiecePrev > 0) { - iPiecePrev--; - iCharsTmp = pPieceLine->m_charCounts[iPiecePrev]; - if (iCharsTmp > 0) - break; - } - if (iCharsTmp == 0) - return; - - iCharsTmp = 0; - int32_t iPieces = pdfium::CollectionSize(pPieceLine->m_textPieces); - while (iPieceNext < iPieces - 1) { - iPieceNext++; - iCharsTmp = pPieceLine->m_charCounts[iPieceNext]; - if (iCharsTmp > 0) - break; - } - if (iCharsTmp == 0) - return; - - float fOrgX = 0.0f; - float fEndX = 0.0f; - pPiece = pPieceLine->m_textPieces[iPiecePrev].get(); - iChars = GetDisplayPos(pPiece, pCharPos); - if (iChars < 1) - return; - - fOrgX = pCharPos[iChars - 1].m_Origin.x + - pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; - pPiece = pPieceLine->m_textPieces[iPieceNext].get(); - iChars = GetDisplayPos(pPiece, pCharPos); - if (iChars < 1) - return; - - fEndX = pCharPos[0].m_Origin.x; - CFX_PointF pt1; - CFX_PointF pt2; - pt1.x = fOrgX; - pt2.x = fEndX; - float fEndY = pCharPos[0].m_Origin.y + 1.05f; - for (int32_t i = 0; i < pPiece->iUnderline; i++) { - pt1.y = fEndY; - pt2.y = fEndY; - pPath->AddLine(pt1, pt2); - fEndY += 2.0f; - } - fEndY = pCharPos[0].m_Origin.y - pPiece->rtPiece.height * 0.25f; - for (int32_t i = 0; i < pPiece->iLineThrough; i++) { - pt1.y = fEndY; - pt2.y = fEndY; - pPath->AddLine(pt1, pt2); - fEndY += 2.0f; - } - } - pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); -} - -int32_t CXFA_TextLayout::GetDisplayPos(const CXFA_TextPiece* pPiece, - FXTEXT_CHARPOS* pCharPos, - bool bCharCode) { - if (!pPiece) - return 0; - - FX_RTFTEXTOBJ tr; - if (!ToRun(pPiece, &tr)) - return 0; - return m_pBreak->GetDisplayPos(&tr, pCharPos, bCharCode); -} - -bool CXFA_TextLayout::ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr) { - int32_t iLength = pPiece->iChars; - if (iLength < 1) - return false; - - tr->pStr = pPiece->szText; - tr->pFont = pPiece->pFont; - tr->pRect = &pPiece->rtPiece; - tr->pWidths = pPiece->Widths; - tr->iLength = iLength; - tr->fFontSize = pPiece->fFontSize; - tr->iBidiLevel = pPiece->iBidiLevel; - tr->wLineBreakChar = L'\n'; - tr->iVerticalScale = pPiece->iVerScale; - tr->iHorizontalScale = pPiece->iHorScale; - return true; -} diff --git a/xfa/fxfa/app/cxfa_textlayout.h b/xfa/fxfa/app/cxfa_textlayout.h deleted file mode 100644 index e8c203fcc1..0000000000 --- a/xfa/fxfa/app/cxfa_textlayout.h +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTLAYOUT_H_ -#define XFA_FXFA_APP_CXFA_TEXTLAYOUT_H_ - -#include -#include - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/fde_css.h" -#include "xfa/fgas/layout/cfx_rtfbreak.h" -#include "xfa/fxfa/app/cxfa_textparser.h" - -class CFDE_Brush; -class CFDE_CSSComputedStyle; -class CFDE_Pen; -class CFDE_RenderDevice; -class CFX_XMLNode; -class CFX_RTFBreak; -class CXFA_LoaderContext; -class CXFA_LinkUserData; -class CXFA_Node; -class CXFA_PieceLine; -class CXFA_TextProvider; -class CXFA_TextTabstopsContext; -class CXFA_TextPiece; - -class CXFA_TextLayout { - public: - explicit CXFA_TextLayout(CXFA_TextProvider* pTextProvider); - ~CXFA_TextLayout(); - - int32_t GetText(CFX_WideString& wsText); - float GetLayoutHeight(); - float StartLayout(float fWidth = -1); - bool DoLayout(int32_t iBlockIndex, - float& fCalcHeight, - float fContentAreaHeight = -1, - float fTextHeight = -1); - - bool CalcSize(const CFX_SizeF& minSize, - const CFX_SizeF& maxSize, - CFX_SizeF& defaultSize); - bool Layout(const CFX_SizeF& size, float* fHeight = nullptr); - void ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex); - bool DrawString(CFX_RenderDevice* pFxDevice, - const CFX_Matrix& tmDoc2Device, - const CFX_RectF& rtClip, - int32_t iBlock = 0); - bool IsLoaded() const { return !m_pieceLines.empty(); } - void Unload(); - const std::vector>* GetPieceLines() const { - return &m_pieceLines; - } - - bool m_bHasBlock; - std::vector m_Blocks; - - private: - void GetTextDataNode(); - CFX_XMLNode* GetXMLContainerNode(); - std::unique_ptr CreateBreak(bool bDefault); - void InitBreak(float fLineWidth); - void InitBreak(CFDE_CSSComputedStyle* pStyle, - FDE_CSSDisplay eDisplay, - float fLineWidth, - CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle = nullptr); - bool Loader(const CFX_SizeF& szText, - float& fLinePos, - bool bSavePieces = true); - void LoadText(CXFA_Node* pNode, - const CFX_SizeF& szText, - float& fLinePos, - bool bSavePieces); - bool LoadRichText(CFX_XMLNode* pXMLNode, - const CFX_SizeF& szText, - float& fLinePos, - const CFX_RetainPtr& pParentStyle, - bool bSavePieces, - CFX_RetainPtr pLinkData, - bool bEndBreak = true, - bool bIsOl = false, - int32_t iLiCount = 0); - bool AppendChar(const CFX_WideString& wsText, - float& fLinePos, - float fSpaceAbove, - bool bSavePieces); - void AppendTextLine(CFX_BreakType dwStatus, - float& fLinePos, - bool bSavePieces, - bool bEndBreak = false); - void EndBreak(CFX_BreakType dwStatus, float& fLinePos, bool bDefault); - bool IsEnd(bool bSavePieces); - void ProcessText(CFX_WideString& wsText); - void UpdateAlign(float fHeight, float fBottom); - void RenderString(CFDE_RenderDevice* pDevice, - CFDE_Brush* pBrush, - CXFA_PieceLine* pPieceLine, - int32_t iPiece, - FXTEXT_CHARPOS* pCharPos, - const CFX_Matrix& tmDoc2Device); - void RenderPath(CFDE_RenderDevice* pDevice, - CFDE_Pen* pPen, - CXFA_PieceLine* pPieceLine, - int32_t iPiece, - FXTEXT_CHARPOS* pCharPos, - const CFX_Matrix& tmDoc2Device); - int32_t GetDisplayPos(const CXFA_TextPiece* pPiece, - FXTEXT_CHARPOS* pCharPos, - bool bCharCode = false); - bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr); - void DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); - bool Layout(int32_t iBlock); - int32_t CountBlocks() const; - - CXFA_TextProvider* m_pTextProvider; - CXFA_Node* m_pTextDataNode; - bool m_bRichText; - std::unique_ptr m_pBreak; - std::unique_ptr m_pLoader; - int32_t m_iLines; - float m_fMaxWidth; - CXFA_TextParser m_textParser; - std::vector> m_pieceLines; - std::unique_ptr m_pTabstopContext; - bool m_bBlockContinue; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTLAYOUT_H_ diff --git a/xfa/fxfa/app/cxfa_textparsecontext.cpp b/xfa/fxfa/app/cxfa_textparsecontext.cpp deleted file mode 100644 index 851d84456b..0000000000 --- a/xfa/fxfa/app/cxfa_textparsecontext.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_textparsecontext.h" - -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" - -CXFA_TextParseContext::CXFA_TextParseContext() - : m_pParentStyle(nullptr), - m_eDisplay(FDE_CSSDisplay::None) {} - -CXFA_TextParseContext::~CXFA_TextParseContext() {} diff --git a/xfa/fxfa/app/cxfa_textparsecontext.h b/xfa/fxfa/app/cxfa_textparsecontext.h deleted file mode 100644 index 514d5d7478..0000000000 --- a/xfa/fxfa/app/cxfa_textparsecontext.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTPARSECONTEXT_H_ -#define XFA_FXFA_APP_CXFA_TEXTPARSECONTEXT_H_ - -#include -#include - -#include "third_party/base/stl_util.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/fde_css.h" - -class CFDE_CSSComputedStyle; - -class CXFA_TextParseContext { - public: - CXFA_TextParseContext(); - ~CXFA_TextParseContext(); - - void SetDisplay(FDE_CSSDisplay eDisplay) { m_eDisplay = eDisplay; } - FDE_CSSDisplay GetDisplay() const { return m_eDisplay; } - - void SetDecls(std::vector&& decl) { - decls_ = std::move(decl); - } - const std::vector& GetDecls() { return decls_; } - - CFX_RetainPtr m_pParentStyle; - - private: - std::vector decls_; - FDE_CSSDisplay m_eDisplay; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTPARSECONTEXT_H_ diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp deleted file mode 100644 index 8bdb0a8372..0000000000 --- a/xfa/fxfa/app/cxfa_textparser.cpp +++ /dev/null @@ -1,625 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_textparser.h" - -#include -#include -#include - -#include "core/fxcrt/fx_codepage.h" -#include "core/fxcrt/xml/cfx_xmlelement.h" -#include "core/fxcrt/xml/cfx_xmlnode.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fde/css/cfde_cssstylesheet.h" -#include "xfa/fde/css/fde_css.h" -#include "xfa/fgas/font/cfgas_fontmgr.h" -#include "xfa/fxfa/app/cxfa_csstagprovider.h" -#include "xfa/fxfa/app/cxfa_textparsecontext.h" -#include "xfa/fxfa/app/cxfa_textprovider.h" -#include "xfa/fxfa/app/cxfa_texttabstopscontext.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_fontmgr.h" -#include "xfa/fxfa/parser/cxfa_measurement.h" - -namespace { - -enum class TabStopStatus { - Error, - EOS, - None, - Alignment, - StartLeader, - Leader, - Location, -}; - -} // namespace - -CXFA_TextParser::CXFA_TextParser() - : m_bParsed(false), m_cssInitialized(false) {} - -CXFA_TextParser::~CXFA_TextParser() {} - -void CXFA_TextParser::Reset() { - m_mapXMLNodeToParseContext.clear(); - m_bParsed = false; -} - -void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { - if (!pTextProvider) - return; - - if (!m_pSelector) { - CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); - CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr(); - ASSERT(pFontMgr); - m_pSelector = pdfium::MakeUnique(pFontMgr); - CXFA_Font font = pTextProvider->GetFontNode(); - m_pSelector->SetDefFontSize(font ? font.GetFontSize() : 10.0f); - } - - if (m_cssInitialized) - return; - - m_cssInitialized = true; - auto uaSheet = LoadDefaultSheetStyle(); - m_pSelector->SetUAStyleSheet(std::move(uaSheet)); - m_pSelector->UpdateStyleIndex(); -} - -std::unique_ptr CXFA_TextParser::LoadDefaultSheetStyle() { - static const wchar_t s_pStyle[] = - L"html,body,ol,p,ul{display:block}" - L"li{display:list-item}" - L"ol,ul{padding-left:33px;margin:1.12em 0}" - L"ol{list-style-type:decimal}" - L"a{color:#0000ff;text-decoration:underline}" - L"b{font-weight:bolder}" - L"i{font-style:italic}" - L"sup{vertical-align:+15em;font-size:.66em}" - L"sub{vertical-align:-15em;font-size:.66em}"; - - auto sheet = pdfium::MakeUnique(); - return sheet->LoadBuffer(s_pStyle, FXSYS_wcslen(s_pStyle)) ? std::move(sheet) - : nullptr; -} - -CFX_RetainPtr CXFA_TextParser::CreateRootStyle( - CXFA_TextProvider* pTextProvider) { - CXFA_Font font = pTextProvider->GetFontNode(); - CXFA_Para para = pTextProvider->GetParaNode(); - auto pStyle = m_pSelector->CreateComputedStyle(nullptr); - float fLineHeight = 0; - float fFontSize = 10; - - if (para) { - fLineHeight = para.GetLineHeight(); - FDE_CSSLength indent; - indent.Set(FDE_CSSLengthUnit::Point, para.GetTextIndent()); - pStyle->SetTextIndent(indent); - FDE_CSSTextAlign hAlign = FDE_CSSTextAlign::Left; - switch (para.GetHorizontalAlign()) { - case XFA_ATTRIBUTEENUM_Center: - hAlign = FDE_CSSTextAlign::Center; - break; - case XFA_ATTRIBUTEENUM_Right: - hAlign = FDE_CSSTextAlign::Right; - break; - case XFA_ATTRIBUTEENUM_Justify: - hAlign = FDE_CSSTextAlign::Justify; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - hAlign = FDE_CSSTextAlign::JustifyAll; - break; - } - pStyle->SetTextAlign(hAlign); - FDE_CSSRect rtMarginWidth; - rtMarginWidth.left.Set(FDE_CSSLengthUnit::Point, para.GetMarginLeft()); - rtMarginWidth.top.Set(FDE_CSSLengthUnit::Point, para.GetSpaceAbove()); - rtMarginWidth.right.Set(FDE_CSSLengthUnit::Point, para.GetMarginRight()); - rtMarginWidth.bottom.Set(FDE_CSSLengthUnit::Point, para.GetSpaceBelow()); - pStyle->SetMarginWidth(rtMarginWidth); - } - - if (font) { - pStyle->SetColor(font.GetColor()); - pStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFontStyle::Italic - : FDE_CSSFontStyle::Normal); - pStyle->SetFontWeight(font.IsBold() ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); - pStyle->SetNumberVerticalAlign(-font.GetBaselineShift()); - fFontSize = font.GetFontSize(); - FDE_CSSLength letterSpacing; - letterSpacing.Set(FDE_CSSLengthUnit::Point, font.GetLetterSpacing()); - pStyle->SetLetterSpacing(letterSpacing); - uint32_t dwDecoration = 0; - if (font.GetLineThrough() > 0) - dwDecoration |= FDE_CSSTEXTDECORATION_LineThrough; - if (font.GetUnderline() > 1) - dwDecoration |= FDE_CSSTEXTDECORATION_Double; - else if (font.GetUnderline() > 0) - dwDecoration |= FDE_CSSTEXTDECORATION_Underline; - - pStyle->SetTextDecoration(dwDecoration); - } - pStyle->SetLineHeight(fLineHeight); - pStyle->SetFontSize(fFontSize); - return pStyle; -} - -CFX_RetainPtr CXFA_TextParser::CreateStyle( - CFDE_CSSComputedStyle* pParentStyle) { - auto pNewStyle = m_pSelector->CreateComputedStyle(pParentStyle); - ASSERT(pNewStyle); - if (!pParentStyle) - return pNewStyle; - - uint32_t dwDecoration = pParentStyle->GetTextDecoration(); - float fBaseLine = 0; - if (pParentStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) - fBaseLine = pParentStyle->GetNumberVerticalAlign(); - - pNewStyle->SetTextDecoration(dwDecoration); - pNewStyle->SetNumberVerticalAlign(fBaseLine); - - const FDE_CSSRect* pRect = pParentStyle->GetMarginWidth(); - if (pRect) - pNewStyle->SetMarginWidth(*pRect); - return pNewStyle; -} - -CFX_RetainPtr CXFA_TextParser::ComputeStyle( - CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle) { - auto it = m_mapXMLNodeToParseContext.find(pXMLNode); - if (it == m_mapXMLNodeToParseContext.end()) - return nullptr; - - CXFA_TextParseContext* pContext = it->second.get(); - if (!pContext) - return nullptr; - - pContext->m_pParentStyle.Reset(pParentStyle); - - auto tagProvider = ParseTagInfo(pXMLNode); - if (tagProvider->m_bContent) - return nullptr; - - auto pStyle = CreateStyle(pParentStyle); - m_pSelector->ComputeStyle(pContext->GetDecls(), - tagProvider->GetAttribute(L"style"), - tagProvider->GetAttribute(L"align"), pStyle.Get()); - return pStyle; -} - -void CXFA_TextParser::DoParse(CFX_XMLNode* pXMLContainer, - CXFA_TextProvider* pTextProvider) { - if (!pXMLContainer || !pTextProvider || m_bParsed) - return; - - m_bParsed = true; - InitCSSData(pTextProvider); - auto pRootStyle = CreateRootStyle(pTextProvider); - ParseRichText(pXMLContainer, pRootStyle.Get()); -} - -void CXFA_TextParser::ParseRichText(CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle) { - if (!pXMLNode) - return; - - auto tagProvider = ParseTagInfo(pXMLNode); - if (!tagProvider->m_bTagAvailable) - return; - - CFX_RetainPtr pNewStyle; - if ((tagProvider->GetTagName() != L"body") || - (tagProvider->GetTagName() != L"html")) { - auto pTextContext = pdfium::MakeUnique(); - FDE_CSSDisplay eDisplay = FDE_CSSDisplay::Inline; - if (!tagProvider->m_bContent) { - auto declArray = - m_pSelector->MatchDeclarations(tagProvider->GetTagName()); - pNewStyle = CreateStyle(pParentStyle); - m_pSelector->ComputeStyle(declArray, tagProvider->GetAttribute(L"style"), - tagProvider->GetAttribute(L"align"), - pNewStyle.Get()); - - if (!declArray.empty()) - pTextContext->SetDecls(std::move(declArray)); - - eDisplay = pNewStyle->GetDisplay(); - } - pTextContext->SetDisplay(eDisplay); - m_mapXMLNodeToParseContext[pXMLNode] = std::move(pTextContext); - } - - for (CFX_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { - ParseRichText(pXMLChild, pNewStyle.Get()); - } -} - -bool CXFA_TextParser::TagValidate(const CFX_WideString& wsName) const { - static const uint32_t s_XFATagName[] = { - 0x61, // a - 0x62, // b - 0x69, // i - 0x70, // p - 0x0001f714, // br - 0x00022a55, // li - 0x000239bb, // ol - 0x00025881, // ul - 0x0bd37faa, // sub - 0x0bd37fb8, // sup - 0xa73e3af2, // span - 0xb182eaae, // body - 0xdb8ac455, // html - }; - static const int32_t s_iCount = FX_ArraySize(s_XFATagName); - - return std::binary_search(s_XFATagName, s_XFATagName + s_iCount, - FX_HashCode_GetW(wsName.AsStringC(), true)); -} - -std::unique_ptr CXFA_TextParser::ParseTagInfo( - CFX_XMLNode* pXMLNode) { - auto tagProvider = pdfium::MakeUnique(); - - CFX_WideString wsName; - if (pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pXMLElement = static_cast(pXMLNode); - wsName = pXMLElement->GetLocalTagName(); - tagProvider->SetTagName(wsName); - tagProvider->m_bTagAvailable = TagValidate(wsName); - - CFX_WideString wsValue = pXMLElement->GetString(L"style"); - if (!wsValue.IsEmpty()) - tagProvider->SetAttribute(L"style", wsValue); - } else if (pXMLNode->GetType() == FX_XMLNODE_Text) { - tagProvider->m_bTagAvailable = true; - tagProvider->m_bContent = true; - } - return tagProvider; -} - -int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { - CXFA_Para para = pTextProvider->GetParaNode(); - return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; -} - -float CXFA_TextParser::GetTabInterval(CFDE_CSSComputedStyle* pStyle) const { - CFX_WideString wsValue; - if (pStyle && pStyle->GetCustomStyle(L"tab-interval", wsValue)) - return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); - return 36; -} - -int32_t CXFA_TextParser::CountTabs(CFDE_CSSComputedStyle* pStyle) const { - CFX_WideString wsValue; - if (pStyle && pStyle->GetCustomStyle(L"xfa-tab-count", wsValue)) - return wsValue.GetInteger(); - return 0; -} - -bool CXFA_TextParser::IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const { - CFX_WideString wsValue; - if (pStyle && pStyle->GetCustomStyle(L"xfa-spacerun", wsValue)) { - wsValue.MakeLower(); - return wsValue == L"yes"; - } - return false; -} - -CFX_RetainPtr CXFA_TextParser::GetFont( - CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { - CFX_WideStringC wsFamily = L"Courier"; - uint32_t dwStyle = 0; - CXFA_Font font = pTextProvider->GetFontNode(); - if (font) { - font.GetTypeface(wsFamily); - if (font.IsBold()) - dwStyle |= FX_FONTSTYLE_Bold; - if (font.IsItalic()) - dwStyle |= FX_FONTSTYLE_Italic; - } - - if (pStyle) { - int32_t iCount = pStyle->CountFontFamilies(); - if (iCount > 0) - wsFamily = pStyle->GetFontFamily(iCount - 1).AsStringC(); - - dwStyle = 0; - if (pStyle->GetFontWeight() > FXFONT_FW_NORMAL) - dwStyle |= FX_FONTSTYLE_Bold; - if (pStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) - dwStyle |= FX_FONTSTYLE_Italic; - } - - CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); - CXFA_FontMgr* pFontMgr = pDoc->GetApp()->GetXFAFontMgr(); - return pFontMgr->GetFont(pDoc, wsFamily, dwStyle); -} - -float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { - if (pStyle) - return pStyle->GetFontSize(); - - CXFA_Font font = pTextProvider->GetFontNode(); - if (font) - return font.GetFontSize(); - return 10; -} - -int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - CFX_XMLNode* pXMLNode) const { - if (pStyle) { - CFX_WideString wsValue; - if (pStyle->GetCustomStyle(L"xfa-font-horizontal-scale", wsValue)) - return wsValue.GetInteger(); - - while (pXMLNode) { - auto it = m_mapXMLNodeToParseContext.find(pXMLNode); - if (it != m_mapXMLNodeToParseContext.end()) { - CXFA_TextParseContext* pContext = it->second.get(); - if (pContext && pContext->m_pParentStyle && - pContext->m_pParentStyle->GetCustomStyle( - L"xfa-font-horizontal-scale", wsValue)) { - return wsValue.GetInteger(); - } - } - pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::Parent); - } - } - - if (CXFA_Font font = pTextProvider->GetFontNode()) - return static_cast(font.GetHorizontalScale()); - return 100; -} - -int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { - if (pStyle) { - CFX_WideString wsValue; - if (pStyle->GetCustomStyle(L"xfa-font-vertical-scale", wsValue)) - return wsValue.GetInteger(); - } - - if (CXFA_Font font = pTextProvider->GetFontNode()) - return (int32_t)font.GetVerticalScale(); - return 100; -} - -void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - int32_t& iUnderline, - int32_t& iPeriod) const { - iUnderline = 0; - iPeriod = XFA_ATTRIBUTEENUM_All; - if (!pStyle) { - CXFA_Font font = pTextProvider->GetFontNode(); - if (font) { - iUnderline = font.GetUnderline(); - iPeriod = font.GetUnderlinePeriod(); - } - return; - } - - uint32_t dwDecoration = pStyle->GetTextDecoration(); - if (dwDecoration & FDE_CSSTEXTDECORATION_Double) - iUnderline = 2; - else if (dwDecoration & FDE_CSSTEXTDECORATION_Underline) - iUnderline = 1; - - CFX_WideString wsValue; - if (pStyle->GetCustomStyle(L"underlinePeriod", wsValue)) { - if (wsValue == L"word") - iPeriod = XFA_ATTRIBUTEENUM_Word; - } else if (CXFA_Font font = pTextProvider->GetFontNode()) { - iPeriod = font.GetUnderlinePeriod(); - } -} - -void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - int32_t& iLinethrough) const { - if (pStyle) { - uint32_t dwDecoration = pStyle->GetTextDecoration(); - iLinethrough = (dwDecoration & FDE_CSSTEXTDECORATION_LineThrough) ? 1 : 0; - return; - } - - CXFA_Font font = pTextProvider->GetFontNode(); - if (font) - iLinethrough = font.GetLineThrough(); -} - -FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { - if (pStyle) - return pStyle->GetColor(); - if (CXFA_Font font = pTextProvider->GetFontNode()) - return font.GetColor(); - - return 0xFF000000; -} - -float CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { - if (pStyle) { - if (pStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) - return pStyle->GetNumberVerticalAlign(); - } else if (CXFA_Font font = pTextProvider->GetFontNode()) { - return font.GetBaselineShift(); - } - return 0; -} - -float CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - bool bFirst, - float fVerScale) const { - float fLineHeight = 0; - if (pStyle) - fLineHeight = pStyle->GetLineHeight(); - else if (CXFA_Para para = pTextProvider->GetParaNode()) - fLineHeight = para.GetLineHeight(); - - if (bFirst) { - float fFontSize = GetFontSize(pTextProvider, pStyle); - if (fLineHeight < 0.1f) - fLineHeight = fFontSize; - else - fLineHeight = std::min(fLineHeight, fFontSize); - } else if (fLineHeight < 0.1f) { - fLineHeight = GetFontSize(pTextProvider, pStyle) * 1.2f; - } - fLineHeight *= fVerScale; - return fLineHeight; -} - -bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, - CFX_XMLNode* pXMLNode, - CFX_WideString& wsValue) { - wsValue.clear(); - if (!pXMLNode) - return false; - - bool bRet = false; - if (pXMLNode->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pElement = static_cast(pXMLNode); - CFX_WideString wsAttr = pElement->GetString(L"xfa:embed"); - if (wsAttr.IsEmpty()) - return false; - if (wsAttr.GetAt(0) == L'#') - wsAttr.Delete(0); - - CFX_WideString ws = pElement->GetString(L"xfa:embedType"); - if (ws.IsEmpty()) - ws = L"som"; - else - ws.MakeLower(); - - bool bURI = (ws == L"uri"); - if (!bURI && ws != L"som") - return false; - - ws = pElement->GetString(L"xfa:embedMode"); - if (ws.IsEmpty()) - ws = L"formatted"; - else - ws.MakeLower(); - - bool bRaw = (ws == L"raw"); - if (!bRaw && ws != L"formatted") - return false; - - bRet = pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue); - } - return bRet; -} - -CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( - CFX_XMLNode* pXMLNode) { - auto it = m_mapXMLNodeToParseContext.find(pXMLNode); - return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr; -} - -bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, - CXFA_TextTabstopsContext* pTabstopContext) { - if (!pStyle || !pTabstopContext) - return false; - - CFX_WideString wsValue; - if (!pStyle->GetCustomStyle(L"xfa-tab-stops", wsValue) && - !pStyle->GetCustomStyle(L"tab-stops", wsValue)) { - return false; - } - - int32_t iLength = wsValue.GetLength(); - const wchar_t* pTabStops = wsValue.c_str(); - int32_t iCur = 0; - int32_t iLast = 0; - CFX_WideString wsAlign; - TabStopStatus eStatus = TabStopStatus::None; - wchar_t ch; - while (iCur < iLength) { - ch = pTabStops[iCur]; - switch (eStatus) { - case TabStopStatus::None: - if (ch <= ' ') { - iCur++; - } else { - eStatus = TabStopStatus::Alignment; - iLast = iCur; - } - break; - case TabStopStatus::Alignment: - if (ch == ' ') { - wsAlign = CFX_WideStringC(pTabStops + iLast, iCur - iLast); - eStatus = TabStopStatus::StartLeader; - iCur++; - while (iCur < iLength && pTabStops[iCur] <= ' ') - iCur++; - iLast = iCur; - } else { - iCur++; - } - break; - case TabStopStatus::StartLeader: - if (ch != 'l') { - eStatus = TabStopStatus::Location; - } else { - int32_t iCount = 0; - while (iCur < iLength) { - ch = pTabStops[iCur]; - iCur++; - if (ch == '(') { - iCount++; - } else if (ch == ')') { - iCount--; - if (iCount == 0) - break; - } - } - while (iCur < iLength && pTabStops[iCur] <= ' ') - iCur++; - - iLast = iCur; - eStatus = TabStopStatus::Location; - } - break; - case TabStopStatus::Location: - if (ch == ' ') { - uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); - CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); - float fPos = ms.ToUnit(XFA_UNIT_Pt); - pTabstopContext->Append(dwHashCode, fPos); - wsAlign.clear(); - eStatus = TabStopStatus::None; - } - iCur++; - break; - default: - break; - } - } - - if (!wsAlign.IsEmpty()) { - uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); - CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); - float fPos = ms.ToUnit(XFA_UNIT_Pt); - pTabstopContext->Append(dwHashCode, fPos); - } - return true; -} diff --git a/xfa/fxfa/app/cxfa_textparser.h b/xfa/fxfa/app/cxfa_textparser.h deleted file mode 100644 index 04bd51fafe..0000000000 --- a/xfa/fxfa/app/cxfa_textparser.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTPARSER_H_ -#define XFA_FXFA_APP_CXFA_TEXTPARSER_H_ - -#include -#include - -#include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fgas/font/cfgas_gefont.h" - -class CFDE_CSSComputedStyle; -class CFDE_CSSStyleSelector; -class CFDE_CSSStyleSheet; -class CFX_XMLNode; -class CXFA_CSSTagProvider; -class CXFA_TextParseContext; -class CXFA_TextProvider; -class CXFA_TextTabstopsContext; - -class CXFA_TextParser { - public: - CXFA_TextParser(); - virtual ~CXFA_TextParser(); - - void Reset(); - void DoParse(CFX_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); - - CFX_RetainPtr CreateRootStyle( - CXFA_TextProvider* pTextProvider); - CFX_RetainPtr ComputeStyle( - CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle); - - bool IsParsed() const { return m_bParsed; } - - int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; - - float GetTabInterval(CFDE_CSSComputedStyle* pStyle) const; - int32_t CountTabs(CFDE_CSSComputedStyle* pStyle) const; - - bool IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const; - bool GetTabstops(CFDE_CSSComputedStyle* pStyle, - CXFA_TextTabstopsContext* pTabstopContext); - - CFX_RetainPtr GetFont(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; - float GetFontSize(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; - - int32_t GetHorScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - CFX_XMLNode* pXMLNode) const; - int32_t GetVerScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; - - void GetUnderline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - int32_t& iUnderline, - int32_t& iPeriod) const; - void GetLinethrough(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - int32_t& iLinethrough) const; - FX_ARGB GetColor(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; - float GetBaseline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; - float GetLineHeight(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, - bool bFirst, - float fVerScale) const; - - bool GetEmbbedObj(CXFA_TextProvider* pTextProvider, - CFX_XMLNode* pXMLNode, - CFX_WideString& wsValue); - CXFA_TextParseContext* GetParseContextFromMap(CFX_XMLNode* pXMLNode); - - protected: - bool TagValidate(const CFX_WideString& str) const; - - private: - void InitCSSData(CXFA_TextProvider* pTextProvider); - void ParseRichText(CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle); - std::unique_ptr ParseTagInfo(CFX_XMLNode* pXMLNode); - std::unique_ptr LoadDefaultSheetStyle(); - CFX_RetainPtr CreateStyle( - CFDE_CSSComputedStyle* pParentStyle); - - bool m_bParsed; - bool m_cssInitialized; - std::unique_ptr m_pSelector; - std::map> - m_mapXMLNodeToParseContext; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTPARSER_H_ diff --git a/xfa/fxfa/app/cxfa_textparser_unittest.cpp b/xfa/fxfa/app/cxfa_textparser_unittest.cpp deleted file mode 100644 index 82a0110468..0000000000 --- a/xfa/fxfa/app/cxfa_textparser_unittest.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "xfa/fxfa/app/cxfa_textparser.h" - -#include "testing/gtest/include/gtest/gtest.h" - -class CXFA_TestTextParser : public CXFA_TextParser { - public: - CXFA_TestTextParser() : CXFA_TextParser() {} - - private: - // Add test cases as friends to access protected member functions. - FRIEND_TEST(CXFA_TextParser, TagValidate); -}; - -TEST(CXFA_TextParser, TagValidate) { - CXFA_TestTextParser parser; - EXPECT_TRUE(parser.TagValidate(L"br")); - EXPECT_TRUE(parser.TagValidate(L"Br")); - EXPECT_TRUE(parser.TagValidate(L"BR")); - EXPECT_TRUE(parser.TagValidate(L"a")); - EXPECT_TRUE(parser.TagValidate(L"b")); - EXPECT_TRUE(parser.TagValidate(L"i")); - EXPECT_TRUE(parser.TagValidate(L"p")); - EXPECT_TRUE(parser.TagValidate(L"li")); - EXPECT_TRUE(parser.TagValidate(L"ol")); - EXPECT_TRUE(parser.TagValidate(L"ul")); - EXPECT_TRUE(parser.TagValidate(L"sub")); - EXPECT_TRUE(parser.TagValidate(L"sup")); - EXPECT_TRUE(parser.TagValidate(L"span")); - EXPECT_TRUE(parser.TagValidate(L"body")); - EXPECT_TRUE(parser.TagValidate(L"html")); - - EXPECT_FALSE(parser.TagValidate(L"")); - EXPECT_FALSE(parser.TagValidate(L"tml")); - EXPECT_FALSE(parser.TagValidate(L"xhtml")); - EXPECT_FALSE(parser.TagValidate(L"htmlx")); -} diff --git a/xfa/fxfa/app/cxfa_textpiece.cpp b/xfa/fxfa/app/cxfa_textpiece.cpp deleted file mode 100644 index 4cbad0a475..0000000000 --- a/xfa/fxfa/app/cxfa_textpiece.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_textpiece.h" - -#include "xfa/fxfa/app/cxfa_linkuserdata.h" - -CXFA_TextPiece::CXFA_TextPiece() {} - -CXFA_TextPiece::~CXFA_TextPiece() {} diff --git a/xfa/fxfa/app/cxfa_textpiece.h b/xfa/fxfa/app/cxfa_textpiece.h deleted file mode 100644 index 0fba66ef52..0000000000 --- a/xfa/fxfa/app/cxfa_textpiece.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTPIECE_H_ -#define XFA_FXFA_APP_CXFA_TEXTPIECE_H_ - -#include - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxge/fx_dib.h" -#include "xfa/fgas/font/cfgas_gefont.h" - -class CXFA_LinkUserData; - -class CXFA_TextPiece { - public: - CXFA_TextPiece(); - ~CXFA_TextPiece(); - - CFX_WideString szText; - std::vector Widths; - int32_t iChars; - int32_t iHorScale; - int32_t iVerScale; - int32_t iBidiLevel; - int32_t iUnderline; - int32_t iPeriod; - int32_t iLineThrough; - FX_ARGB dwColor; - float fFontSize; - CFX_RectF rtPiece; - CFX_RetainPtr pFont; - CFX_RetainPtr pLinkData; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTPIECE_H_ diff --git a/xfa/fxfa/app/cxfa_textprovider.cpp b/xfa/fxfa/app/cxfa_textprovider.cpp deleted file mode 100644 index 01bc021f8c..0000000000 --- a/xfa/fxfa/app/cxfa_textprovider.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_textprovider.h" - -#include -#include -#include - -#include "core/fxcrt/xml/cfx_xmlelement.h" -#include "core/fxcrt/xml/cfx_xmlnode.h" -#include "fxjs/cfxjse_value.h" -#include "third_party/base/ptr_util.h" -#include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_textout.h" -#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/cxfa_eventparam.h" -#include "xfa/fxfa/cxfa_ffapp.h" -#include "xfa/fxfa/cxfa_ffdoc.h" -#include "xfa/fxfa/cxfa_ffdocview.h" -#include "xfa/fxfa/cxfa_ffpageview.h" -#include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/cxfa_fontmgr.h" -#include "xfa/fxfa/parser/cxfa_layoutprocessor.h" -#include "xfa/fxfa/parser/cxfa_localevalue.h" -#include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_scriptcontext.h" -#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" - -CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { - bRichText = false; - - if (m_eType == XFA_TEXTPROVIDERTYPE_Text) { - CXFA_Node* pElementNode = m_pWidgetAcc->GetNode(); - CXFA_Node* pValueNode = pElementNode->GetChild(0, XFA_Element::Value); - if (!pValueNode) - return nullptr; - - CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); - if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { - CFX_WideString wsContentType; - pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); - if (wsContentType == L"text/html") - bRichText = true; - } - return pChildNode; - } - - if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) { - CXFA_Node* pBind = m_pWidgetAcc->GetDatasets(); - CFX_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); - ASSERT(pXMLNode); - for (CFX_XMLNode* pXMLChild = - pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); - pXMLChild; - pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (pXMLChild->GetType() == FX_XMLNODE_Element) { - CFX_XMLElement* pElement = static_cast(pXMLChild); - if (XFA_RecognizeRichText(pElement)) - bRichText = true; - } - } - return pBind; - } - - if (m_eType == XFA_TEXTPROVIDERTYPE_Caption) { - CXFA_Node* pCaptionNode = - m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Caption); - if (!pCaptionNode) - return nullptr; - - CXFA_Node* pValueNode = pCaptionNode->GetChild(0, XFA_Element::Value); - if (!pValueNode) - return nullptr; - - CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); - if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { - CFX_WideString wsContentType; - pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); - if (wsContentType == L"text/html") - bRichText = true; - } - return pChildNode; - } - - CXFA_Node* pItemNode = - m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Items); - if (!pItemNode) - return nullptr; - - CXFA_Node* pNode = pItemNode->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pNode) { - CFX_WideStringC wsName; - pNode->TryCData(XFA_ATTRIBUTE_Name, wsName); - if (m_eType == XFA_TEXTPROVIDERTYPE_Rollover && wsName == L"rollover") - return pNode; - if (m_eType == XFA_TEXTPROVIDERTYPE_Down && wsName == L"down") - return pNode; - - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); - } - return nullptr; -} - -CXFA_Para CXFA_TextProvider::GetParaNode() { - if (m_eType == XFA_TEXTPROVIDERTYPE_Text) - return m_pWidgetAcc->GetPara(); - - CXFA_Node* pNode = m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Caption); - return CXFA_Para(pNode->GetChild(0, XFA_Element::Para)); -} - -CXFA_Font CXFA_TextProvider::GetFontNode() { - if (m_eType == XFA_TEXTPROVIDERTYPE_Text) - return m_pWidgetAcc->GetFont(false); - - CXFA_Node* pNode = m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Caption); - pNode = pNode->GetChild(0, XFA_Element::Font); - return pNode ? CXFA_Font(pNode) : m_pWidgetAcc->GetFont(false); -} - -bool CXFA_TextProvider::IsCheckButtonAndAutoWidth() { - XFA_Element eType = m_pWidgetAcc->GetUIType(); - if (eType != XFA_Element::CheckButton) - return false; - - float fWidth = 0; - return !m_pWidgetAcc->GetWidth(fWidth); -} - -bool CXFA_TextProvider::GetEmbbedObj(bool bURI, - bool bRaw, - const CFX_WideString& wsAttr, - CFX_WideString& wsValue) { - if (m_eType != XFA_TEXTPROVIDERTYPE_Text) - return false; - - if (!bURI) - return false; - - CXFA_Node* pWidgetNode = m_pWidgetAcc->GetNode(); - CXFA_Node* pParent = pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent); - CXFA_Document* pDocument = pWidgetNode->GetDocument(); - CXFA_Node* pIDNode = nullptr; - CXFA_WidgetAcc* pEmbAcc = nullptr; - if (pParent) - pIDNode = pDocument->GetNodeByID(pParent, wsAttr.AsStringC()); - - if (!pIDNode) { - pIDNode = pDocument->GetNodeByID( - ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Form)), wsAttr.AsStringC()); - } - if (pIDNode) - pEmbAcc = static_cast(pIDNode->GetWidgetData()); - - if (!pEmbAcc) - return false; - - pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); - return true; -} diff --git a/xfa/fxfa/app/cxfa_textprovider.h b/xfa/fxfa/app/cxfa_textprovider.h deleted file mode 100644 index 08fc6f38e2..0000000000 --- a/xfa/fxfa/app/cxfa_textprovider.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTPROVIDER_H_ -#define XFA_FXFA_APP_CXFA_TEXTPROVIDER_H_ - -#include "core/fxcrt/fx_string.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/cxfa_widgetacc.h" -#include "xfa/fxfa/parser/cxfa_font.h" -#include "xfa/fxfa/parser/cxfa_para.h" - -class CXFA_FFDoc; -class CXFA_Node; - -enum XFA_TEXTPROVIDERTYPE { - XFA_TEXTPROVIDERTYPE_Text, - XFA_TEXTPROVIDERTYPE_Datasets, - XFA_TEXTPROVIDERTYPE_Caption, - XFA_TEXTPROVIDERTYPE_Rollover, - XFA_TEXTPROVIDERTYPE_Down, -}; - -class CXFA_TextProvider { - public: - CXFA_TextProvider(CXFA_WidgetAcc* pWidgetAcc, XFA_TEXTPROVIDERTYPE eType) - : m_pWidgetAcc(pWidgetAcc), m_eType(eType) { - ASSERT(m_pWidgetAcc); - } - ~CXFA_TextProvider() {} - - CXFA_Node* GetTextNode(bool& bRichText); - CXFA_Para GetParaNode(); - CXFA_Font GetFontNode(); - bool IsCheckButtonAndAutoWidth(); - CXFA_FFDoc* GetDocNode() { return m_pWidgetAcc->GetDoc(); } - bool GetEmbbedObj(bool bURI, - bool bRaw, - const CFX_WideString& wsAttr, - CFX_WideString& wsValue); - - private: - CXFA_WidgetAcc* m_pWidgetAcc; - XFA_TEXTPROVIDERTYPE m_eType; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTPROVIDER_H_ diff --git a/xfa/fxfa/app/cxfa_texttabstopscontext.cpp b/xfa/fxfa/app/cxfa_texttabstopscontext.cpp deleted file mode 100644 index 58ceb21a4b..0000000000 --- a/xfa/fxfa/app/cxfa_texttabstopscontext.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_texttabstopscontext.h" - -CXFA_TextTabstopsContext::CXFA_TextTabstopsContext() - : m_iTabIndex(-1), m_bTabstops(false), m_fTabWidth(0), m_fLeft(0) {} - -CXFA_TextTabstopsContext::~CXFA_TextTabstopsContext() {} - -void CXFA_TextTabstopsContext::Append(uint32_t dwAlign, float fTabstops) { - XFA_TABSTOPS tabstop; - tabstop.dwAlign = dwAlign; - tabstop.fTabstops = fTabstops; - - auto it = std::lower_bound(m_tabstops.begin(), m_tabstops.end(), tabstop); - m_tabstops.insert(it, tabstop); -} - -void CXFA_TextTabstopsContext::RemoveAll() { - m_tabstops.clear(); -} - -void CXFA_TextTabstopsContext::Reset() { - m_iTabIndex = -1; - m_bTabstops = false; - m_fTabWidth = 0; - m_fLeft = 0; -} diff --git a/xfa/fxfa/app/cxfa_texttabstopscontext.h b/xfa/fxfa/app/cxfa_texttabstopscontext.h deleted file mode 100644 index 9be10dd61d..0000000000 --- a/xfa/fxfa/app/cxfa_texttabstopscontext.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTTABSTOPSCONTEXT_H_ -#define XFA_FXFA_APP_CXFA_TEXTTABSTOPSCONTEXT_H_ - -#include - -#include "core/fxcrt/fx_basic.h" - -struct XFA_TABSTOPS { - uint32_t dwAlign; - float fTabstops; - - bool operator<(const XFA_TABSTOPS& that) const { - return fTabstops < that.fTabstops; - } -}; - -class CXFA_TextTabstopsContext { - public: - CXFA_TextTabstopsContext(); - ~CXFA_TextTabstopsContext(); - - void Append(uint32_t dwAlign, float fTabstops); - void RemoveAll(); - void Reset(); - - int32_t m_iTabIndex; - bool m_bTabstops; - float m_fTabWidth; - float m_fLeft; - std::vector m_tabstops; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTTABSTOPSCONTEXT_H_ diff --git a/xfa/fxfa/app/cxfa_textuserdata.cpp b/xfa/fxfa/app/cxfa_textuserdata.cpp deleted file mode 100644 index e4e549316a..0000000000 --- a/xfa/fxfa/app/cxfa_textuserdata.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/app/cxfa_textuserdata.h" - -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fde/css/fde_css.h" -#include "xfa/fxfa/app/cxfa_linkuserdata.h" - -CXFA_TextUserData::CXFA_TextUserData( - const CFX_RetainPtr& pStyle) - : m_pStyle(pStyle) {} - -CXFA_TextUserData::CXFA_TextUserData( - const CFX_RetainPtr& pStyle, - const CFX_RetainPtr& pLinkData) - : m_pStyle(pStyle), m_pLinkData(pLinkData) {} - -CXFA_TextUserData::~CXFA_TextUserData() {} diff --git a/xfa/fxfa/app/cxfa_textuserdata.h b/xfa/fxfa/app/cxfa_textuserdata.h deleted file mode 100644 index 18a20cdc2a..0000000000 --- a/xfa/fxfa/app/cxfa_textuserdata.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_APP_CXFA_TEXTUSERDATA_H_ -#define XFA_FXFA_APP_CXFA_TEXTUSERDATA_H_ - -#include "core/fxcrt/cfx_retain_ptr.h" -#include "core/fxcrt/fx_basic.h" - -class CFDE_CSSComputedStyle; -class CXFA_LinkUserData; - -class CXFA_TextUserData : public CFX_Retainable { - public: - template - friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); - - CFX_RetainPtr m_pStyle; - CFX_RetainPtr m_pLinkData; - - private: - explicit CXFA_TextUserData( - const CFX_RetainPtr& pStyle); - CXFA_TextUserData(const CFX_RetainPtr& pStyle, - const CFX_RetainPtr& pLinkData); - ~CXFA_TextUserData() override; -}; - -#endif // XFA_FXFA_APP_CXFA_TEXTUSERDATA_H_ diff --git a/xfa/fxfa/cxfa_csstagprovider.cpp b/xfa/fxfa/cxfa_csstagprovider.cpp new file mode 100644 index 0000000000..98d00d4807 --- /dev/null +++ b/xfa/fxfa/cxfa_csstagprovider.cpp @@ -0,0 +1,12 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_csstagprovider.h" + +CXFA_CSSTagProvider::CXFA_CSSTagProvider() + : m_bTagAvailable(false), m_bContent(false) {} + +CXFA_CSSTagProvider::~CXFA_CSSTagProvider() {} diff --git a/xfa/fxfa/cxfa_csstagprovider.h b/xfa/fxfa/cxfa_csstagprovider.h new file mode 100644 index 0000000000..058740b732 --- /dev/null +++ b/xfa/fxfa/cxfa_csstagprovider.h @@ -0,0 +1,39 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_CSSTAGPROVIDER_H_ +#define XFA_FXFA_CXFA_CSSTAGPROVIDER_H_ + +#include + +#include "core/fxcrt/fx_string.h" + +class CXFA_CSSTagProvider { + public: + CXFA_CSSTagProvider(); + ~CXFA_CSSTagProvider(); + + CFX_WideString GetTagName() { return m_wsTagName; } + + void SetTagName(const CFX_WideString& wsName) { m_wsTagName = wsName; } + void SetAttribute(const CFX_WideString& wsAttr, + const CFX_WideString& wsValue) { + m_Attributes.insert({wsAttr, wsValue}); + } + + CFX_WideString GetAttribute(const CFX_WideString& wsAttr) { + return m_Attributes[wsAttr]; + } + + bool m_bTagAvailable; + bool m_bContent; + + private: + CFX_WideString m_wsTagName; + std::map m_Attributes; +}; + +#endif // XFA_FXFA_CXFA_CSSTAGPROVIDER_H_ diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp index cb308f2c46..b766cdc40f 100644 --- a/xfa/fxfa/cxfa_ffapp.cpp +++ b/xfa/fxfa/cxfa_ffapp.cpp @@ -16,12 +16,12 @@ #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fwl/cfwl_widgetmgr.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/app/cxfa_fwltheme.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdochandler.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" #include "xfa/fxfa/cxfa_fontmgr.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/cxfa_fwltheme.h" CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) : m_pProvider(pProvider) { // Ensure fully initialized before making an app based on |this|. diff --git a/xfa/fxfa/cxfa_ffarc.cpp b/xfa/fxfa/cxfa_ffarc.cpp new file mode 100644 index 0000000000..6c2fa4e2cc --- /dev/null +++ b/xfa/fxfa/cxfa_ffarc.cpp @@ -0,0 +1,33 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffarc.h" + +CXFA_FFArc::CXFA_FFArc(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFArc::~CXFA_FFArc() {} + +void CXFA_FFArc::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CXFA_Value value = m_pDataAcc->GetFormValue(); + if (!value) + return; + + CXFA_Arc arcObj = value.GetArc(); + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CFX_RectF rtArc = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rtArc, mgWidget); + + DrawBorder(pGS, arcObj, rtArc, &mtRotate); +} diff --git a/xfa/fxfa/cxfa_ffarc.h b/xfa/fxfa/cxfa_ffarc.h new file mode 100644 index 0000000000..7d8aabcaaf --- /dev/null +++ b/xfa/fxfa/cxfa_ffarc.h @@ -0,0 +1,23 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFARC_H_ +#define XFA_FXFA_CXFA_FFARC_H_ + +#include "xfa/fxfa/cxfa_ffdraw.h" + +class CXFA_FFArc : public CXFA_FFDraw { + public: + explicit CXFA_FFArc(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFArc() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; +}; + +#endif // XFA_FXFA_CXFA_FFARC_H_ diff --git a/xfa/fxfa/cxfa_ffbarcode.cpp b/xfa/fxfa/cxfa_ffbarcode.cpp new file mode 100644 index 0000000000..eff9cec603 --- /dev/null +++ b/xfa/fxfa/cxfa_ffbarcode.cpp @@ -0,0 +1,226 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffbarcode.h" + +#include + +#include "core/fxcrt/fx_extension.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_barcode.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" + +namespace { + +const BarCodeInfo g_BarCodeData[] = { + {0x7fb4a18, L"ean13", BarcodeType::ean13, BC_EAN13}, + {0x8d13a3d, L"code11", BarcodeType::code11, BC_UNKNOWN}, + {0x8d149a8, L"code49", BarcodeType::code49, BC_UNKNOWN}, + {0x8d16347, L"code93", BarcodeType::code93, BC_UNKNOWN}, + {0x91a92e2, L"upsMaxicode", BarcodeType::upsMaxicode, BC_UNKNOWN}, + {0xa7d48dc, L"fim", BarcodeType::fim, BC_UNKNOWN}, + {0xb359fe9, L"msi", BarcodeType::msi, BC_UNKNOWN}, + {0x121f738c, L"code2Of5Matrix", BarcodeType::code2Of5Matrix, BC_UNKNOWN}, + {0x15358616, L"ucc128", BarcodeType::ucc128, BC_UNKNOWN}, + {0x1f4bfa05, L"rfid", BarcodeType::rfid, BC_UNKNOWN}, + {0x1fda71bc, L"rss14Stacked", BarcodeType::rss14Stacked, BC_UNKNOWN}, + {0x22065087, L"ean8add2", BarcodeType::ean8add2, BC_UNKNOWN}, + {0x2206508a, L"ean8add5", BarcodeType::ean8add5, BC_UNKNOWN}, + {0x2278366c, L"codabar", BarcodeType::codabar, BC_CODABAR}, + {0x2a039a8d, L"telepen", BarcodeType::telepen, BC_UNKNOWN}, + {0x323ed337, L"upcApwcd", BarcodeType::upcApwcd, BC_UNKNOWN}, + {0x347a1846, L"postUSIMB", BarcodeType::postUSIMB, BC_UNKNOWN}, + {0x391bb836, L"code128", BarcodeType::code128, BC_CODE128}, + {0x398eddaf, L"dataMatrix", BarcodeType::dataMatrix, BC_DATAMATRIX}, + {0x3cff60a8, L"upcEadd2", BarcodeType::upcEadd2, BC_UNKNOWN}, + {0x3cff60ab, L"upcEadd5", BarcodeType::upcEadd5, BC_UNKNOWN}, + {0x402cb188, L"code2Of5Standard", BarcodeType::code2Of5Standard, + BC_UNKNOWN}, + {0x411764f7, L"aztec", BarcodeType::aztec, BC_UNKNOWN}, + {0x44d4e84c, L"ean8", BarcodeType::ean8, BC_EAN8}, + {0x48468902, L"ucc128sscc", BarcodeType::ucc128sscc, BC_UNKNOWN}, + {0x4880aea4, L"upcAadd2", BarcodeType::upcAadd2, BC_UNKNOWN}, + {0x4880aea7, L"upcAadd5", BarcodeType::upcAadd5, BC_UNKNOWN}, + {0x54f18256, L"code2Of5Industrial", BarcodeType::code2Of5Industrial, + BC_UNKNOWN}, + {0x58e15f25, L"rss14Limited", BarcodeType::rss14Limited, BC_UNKNOWN}, + {0x5c08d1b9, L"postAUSReplyPaid", BarcodeType::postAUSReplyPaid, + BC_UNKNOWN}, + {0x5fa700bd, L"rss14", BarcodeType::rss14, BC_UNKNOWN}, + {0x631a7e35, L"logmars", BarcodeType::logmars, BC_UNKNOWN}, + {0x6a236236, L"pdf417", BarcodeType::pdf417, BC_PDF417}, + {0x6d098ece, L"upcean2", BarcodeType::upcean2, BC_UNKNOWN}, + {0x6d098ed1, L"upcean5", BarcodeType::upcean5, BC_UNKNOWN}, + {0x76b04eed, L"code3Of9extended", BarcodeType::code3Of9extended, + BC_UNKNOWN}, + {0x7c7db84a, L"maxicode", BarcodeType::maxicode, BC_UNKNOWN}, + {0x8266f7f7, L"ucc128random", BarcodeType::ucc128random, BC_UNKNOWN}, + {0x83eca147, L"postUSDPBC", BarcodeType::postUSDPBC, BC_UNKNOWN}, + {0x8dd71de0, L"postAUSStandard", BarcodeType::postAUSStandard, BC_UNKNOWN}, + {0x98adad85, L"plessey", BarcodeType::plessey, BC_UNKNOWN}, + {0x9f84cce6, L"ean13pwcd", BarcodeType::ean13pwcd, BC_UNKNOWN}, + {0xb514fbe9, L"upcA", BarcodeType::upcA, BC_UPCA}, + {0xb514fbed, L"upcE", BarcodeType::upcE, BC_UNKNOWN}, + {0xb5c6a853, L"ean13add2", BarcodeType::ean13add2, BC_UNKNOWN}, + {0xb5c6a856, L"ean13add5", BarcodeType::ean13add5, BC_UNKNOWN}, + {0xb81fc512, L"postUKRM4SCC", BarcodeType::postUKRM4SCC, BC_UNKNOWN}, + {0xbad34b22, L"code128SSCC", BarcodeType::code128SSCC, BC_UNKNOWN}, + {0xbfbe0cf6, L"postUS5Zip", BarcodeType::postUS5Zip, BC_UNKNOWN}, + {0xc56618e8, L"pdf417macro", BarcodeType::pdf417macro, BC_UNKNOWN}, + {0xca730f8a, L"code2Of5Interleaved", BarcodeType::code2Of5Interleaved, + BC_UNKNOWN}, + {0xd0097ac6, L"rss14Expanded", BarcodeType::rss14Expanded, BC_UNKNOWN}, + {0xd25a0240, L"postAUSCust2", BarcodeType::postAUSCust2, BC_UNKNOWN}, + {0xd25a0241, L"postAUSCust3", BarcodeType::postAUSCust3, BC_UNKNOWN}, + {0xd53ed3e7, L"rss14Truncated", BarcodeType::rss14Truncated, BC_UNKNOWN}, + {0xe72bcd57, L"code128A", BarcodeType::code128A, BC_UNKNOWN}, + {0xe72bcd58, L"code128B", BarcodeType::code128B, BC_CODE128_B}, + {0xe72bcd59, L"code128C", BarcodeType::code128C, BC_CODE128_C}, + {0xee83c50f, L"rss14StackedOmni", BarcodeType::rss14StackedOmni, + BC_UNKNOWN}, + {0xf2a18f7e, L"QRCode", BarcodeType::QRCode, BC_QR_CODE}, + {0xfaeaf37f, L"postUSStandard", BarcodeType::postUSStandard, BC_UNKNOWN}, + {0xfb48155c, L"code3Of9", BarcodeType::code3Of9, BC_CODE39}, +}; + +} // namespace. + +// static +const BarCodeInfo* CXFA_FFBarcode::GetBarcodeTypeByName( + const CFX_WideStringC& wsName) { + if (wsName.IsEmpty()) + return nullptr; + + auto* it = std::lower_bound( + std::begin(g_BarCodeData), std::end(g_BarCodeData), + FX_HashCode_GetW(wsName, true), + [](const BarCodeInfo& arg, uint32_t hash) { return arg.uHash < hash; }); + + if (it != std::end(g_BarCodeData) && wsName == it->pName) + return it; + + return nullptr; +} + +CXFA_FFBarcode::CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFBarcode::~CXFA_FFBarcode() {} + +bool CXFA_FFBarcode::LoadWidget() { + auto pNew = pdfium::MakeUnique(GetFWLApp()); + CFWL_Barcode* pFWLBarcode = pNew.get(); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pFWLBarcode->SetText(wsText); + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFBarcode::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); + RenderCaption(pGS, &mtRotate); + CFX_RectF rtWidget = m_pNormalWidget->GetWidgetRect(); + + CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); + mt.Concat(mtRotate); + m_pNormalWidget->DrawWidget(pGS, &mt); +} + +void CXFA_FFBarcode::UpdateWidgetProperty() { + CXFA_FFTextEdit::UpdateWidgetProperty(); + + auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); + CFX_WideString wsType = GetDataAcc()->GetBarcodeType(); + const BarCodeInfo* pBarcodeInfo = GetBarcodeTypeByName(wsType.AsStringC()); + if (!pBarcodeInfo) + return; + + pBarCodeWidget->SetType(pBarcodeInfo->eBCType); + + CXFA_WidgetAcc* pAcc = GetDataAcc(); + int32_t intVal; + if (pAcc->GetBarcodeAttribute_CharEncoding(&intVal)) + pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal); + + bool boolVal; + if (pAcc->GetBarcodeAttribute_Checksum(&boolVal)) + pBarCodeWidget->SetCalChecksum(boolVal); + if (pAcc->GetBarcodeAttribute_DataLength(&intVal)) + pBarCodeWidget->SetDataLength(intVal); + + char charVal; + if (pAcc->GetBarcodeAttribute_StartChar(&charVal)) + pBarCodeWidget->SetStartChar(charVal); + if (pAcc->GetBarcodeAttribute_EndChar(&charVal)) + pBarCodeWidget->SetEndChar(charVal); + if (pAcc->GetBarcodeAttribute_ECLevel(&intVal)) + pBarCodeWidget->SetErrorCorrectionLevel(intVal); + if (pAcc->GetBarcodeAttribute_ModuleWidth(&intVal)) + pBarCodeWidget->SetModuleWidth(intVal); + if (pAcc->GetBarcodeAttribute_ModuleHeight(&intVal)) + pBarCodeWidget->SetModuleHeight(intVal); + if (pAcc->GetBarcodeAttribute_PrintChecksum(&boolVal)) + pBarCodeWidget->SetPrintChecksum(boolVal); + if (pAcc->GetBarcodeAttribute_TextLocation(&intVal)) + pBarCodeWidget->SetTextLocation((BC_TEXT_LOC)intVal); + if (pAcc->GetBarcodeAttribute_Truncate(&boolVal)) + pBarCodeWidget->SetTruncated(boolVal); + + float floatVal; + if (pAcc->GetBarcodeAttribute_WideNarrowRatio(&floatVal)) + pBarCodeWidget->SetWideNarrowRatio(static_cast(floatVal)); + if (pBarcodeInfo->eName == BarcodeType::code3Of9 || + pBarcodeInfo->eName == BarcodeType::ean8 || + pBarcodeInfo->eName == BarcodeType::ean13 || + pBarcodeInfo->eName == BarcodeType::upcA) { + pBarCodeWidget->SetPrintChecksum(true); + } +} + +bool CXFA_FFBarcode::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); + if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) + return false; + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) + return false; + return CXFA_FFTextEdit::OnLButtonDown(dwFlags, point); +} + +bool CXFA_FFBarcode::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + auto* pBarCodeWidget = static_cast(m_pNormalWidget.get()); + if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) + return false; + return CXFA_FFTextEdit::OnRButtonDown(dwFlags, point); +} diff --git a/xfa/fxfa/cxfa_ffbarcode.h b/xfa/fxfa/cxfa_ffbarcode.h new file mode 100644 index 0000000000..c9b36b3bde --- /dev/null +++ b/xfa/fxfa/cxfa_ffbarcode.h @@ -0,0 +1,103 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFBARCODE_H_ +#define XFA_FXFA_CXFA_FFBARCODE_H_ + +#include "fxbarcode/BC_Library.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_fftextedit.h" + +enum class BarcodeType { + aztec, + codabar, + code11, + code128, + code128A, + code128B, + code128C, + code128SSCC, + code2Of5Industrial, + code2Of5Interleaved, + code2Of5Matrix, + code2Of5Standard, + code3Of9, + code3Of9extended, + code49, + code93, + dataMatrix, + ean13, + ean13add2, + ean13add5, + ean13pwcd, + ean8, + ean8add2, + ean8add5, + fim, + logmars, + maxicode, + msi, + pdf417, + pdf417macro, + plessey, + postAUSCust2, + postAUSCust3, + postAUSReplyPaid, + postAUSStandard, + postUKRM4SCC, + postUS5Zip, + postUSDPBC, + postUSIMB, + postUSStandard, + QRCode, + rfid, + rss14, + rss14Expanded, + rss14Limited, + rss14Stacked, + rss14StackedOmni, + rss14Truncated, + telepen, + ucc128, + ucc128random, + ucc128sscc, + upcA, + upcAadd2, + upcAadd5, + upcApwcd, + upcE, + upcEadd2, + upcEadd5, + upcean2, + upcean5, + upsMaxicode +}; + +struct BarCodeInfo { + uint32_t uHash; + const wchar_t* pName; + BarcodeType eName; + BC_TYPE eBCType; +}; + +class CXFA_FFBarcode : public CXFA_FFTextEdit { + public: + static const BarCodeInfo* GetBarcodeTypeByName(const CFX_WideStringC& wsName); + + explicit CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFBarcode() override; + + // CXFA_FFTextEdit + bool LoadWidget() override; + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + void UpdateWidgetProperty() override; + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; +}; + +#endif // XFA_FXFA_CXFA_FFBARCODE_H_ diff --git a/xfa/fxfa/cxfa_ffbarcode_unittest.cpp b/xfa/fxfa/cxfa_ffbarcode_unittest.cpp new file mode 100644 index 0000000000..455b5a6ac0 --- /dev/null +++ b/xfa/fxfa/cxfa_ffbarcode_unittest.cpp @@ -0,0 +1,25 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "xfa/fxfa/cxfa_ffbarcode.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/base/ptr_util.h" + +TEST(XFA_FFBarcode, GetBarcodeTypeByName) { + EXPECT_EQ(nullptr, CXFA_FFBarcode::GetBarcodeTypeByName(L"")); + EXPECT_EQ(nullptr, CXFA_FFBarcode::GetBarcodeTypeByName(L"not_found")); + + auto* data = CXFA_FFBarcode::GetBarcodeTypeByName(L"ean13"); + ASSERT_NE(nullptr, data); + EXPECT_EQ(BarcodeType::ean13, data->eName); + + data = CXFA_FFBarcode::GetBarcodeTypeByName(L"pdf417"); + ASSERT_NE(nullptr, data); + EXPECT_EQ(BarcodeType::pdf417, data->eName); + + data = CXFA_FFBarcode::GetBarcodeTypeByName(L"code3Of9"); + ASSERT_NE(nullptr, data); + EXPECT_EQ(BarcodeType::code3Of9, data->eName); +} diff --git a/xfa/fxfa/cxfa_ffcheckbutton.cpp b/xfa/fxfa/cxfa_ffcheckbutton.cpp new file mode 100644 index 0000000000..c1dae57df8 --- /dev/null +++ b/xfa/fxfa/cxfa_ffcheckbutton.cpp @@ -0,0 +1,345 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffcheckbutton.h" + +#include +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_checkbox.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffexclgroup.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFCheckButton::~CXFA_FFCheckButton() {} + +bool CXFA_FFCheckButton::LoadWidget() { + auto pNew = pdfium::MakeUnique(GetFWLApp()); + CFWL_CheckBox* pCheckBox = pNew.get(); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + if (m_pDataAcc->IsRadioButton()) + pCheckBox->ModifyStylesEx(FWL_STYLEEXT_CKB_RadioButton, 0xFFFFFFFF); + + m_pNormalWidget->LockUpdate(); + UpdateWidgetProperty(); + SetFWLCheckState(m_pDataAcc->GetCheckState()); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFCheckButton::UpdateWidgetProperty() { + auto* pCheckBox = static_cast(m_pNormalWidget.get()); + if (!pCheckBox) + return; + + pCheckBox->SetBoxSize(m_pDataAcc->GetCheckButtonSize()); + uint32_t dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCross; + int32_t iCheckMark = m_pDataAcc->GetCheckButtonMark(); + switch (iCheckMark) { + case XFA_ATTRIBUTEENUM_Check: + dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCheck; + break; + case XFA_ATTRIBUTEENUM_Circle: + dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; + break; + case XFA_ATTRIBUTEENUM_Cross: + break; + case XFA_ATTRIBUTEENUM_Diamond: + dwStyleEx = FWL_STYLEEXT_CKB_SignShapeDiamond; + break; + case XFA_ATTRIBUTEENUM_Square: + dwStyleEx = FWL_STYLEEXT_CKB_SignShapeSquare; + break; + case XFA_ATTRIBUTEENUM_Star: + dwStyleEx = FWL_STYLEEXT_CKB_SignShapeStar; + break; + default: { + int32_t iShape = m_pDataAcc->GetCheckButtonShape(); + if (iShape == XFA_ATTRIBUTEENUM_Round) { + dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; + } + } break; + } + if (m_pDataAcc->IsAllowNeutral()) + dwStyleEx |= FWL_STYLEEXT_CKB_3State; + + pCheckBox->ModifyStylesEx( + dwStyleEx, FWL_STYLEEXT_CKB_SignShapeMask | FWL_STYLEEXT_CKB_3State); +} + +bool CXFA_FFCheckButton::PerformLayout() { + CXFA_FFWidget::PerformLayout(); + + float fCheckSize = m_pDataAcc->GetCheckButtonSize(); + CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); + CFX_RectF rtWidget = GetRectWithoutRotate(); + if (mgWidget) + XFA_RectWidthoutMargin(rtWidget, mgWidget); + + int32_t iCapPlacement = -1; + float fCapReserve = 0; + CXFA_Caption caption = m_pDataAcc->GetCaption(); + if (caption && caption.GetPresence()) { + m_rtCaption = rtWidget; + iCapPlacement = caption.GetPlacementType(); + fCapReserve = caption.GetReserve(); + if (fCapReserve <= 0) { + if (iCapPlacement == XFA_ATTRIBUTEENUM_Top || + iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { + fCapReserve = rtWidget.height - fCheckSize; + } else { + fCapReserve = rtWidget.width - fCheckSize; + } + } + } + + int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; + int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; + if (CXFA_Para para = m_pDataAcc->GetPara()) { + iHorzAlign = para.GetHorizontalAlign(); + iVertAlign = para.GetVerticalAlign(); + } + + m_rtUI = rtWidget; + CXFA_Margin mgCap = caption.GetMargin(); + switch (iCapPlacement) { + case XFA_ATTRIBUTEENUM_Left: { + m_rtCaption.width = fCapReserve; + CapLeftRightPlacement(mgCap); + m_rtUI.width -= fCapReserve; + m_rtUI.left += fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Top: { + m_rtCaption.height = fCapReserve; + XFA_RectWidthoutMargin(m_rtCaption, mgCap); + m_rtUI.height -= fCapReserve; + m_rtUI.top += fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Right: { + m_rtCaption.left = m_rtCaption.right() - fCapReserve; + m_rtCaption.width = fCapReserve; + CapLeftRightPlacement(mgCap); + m_rtUI.width -= fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Bottom: { + m_rtCaption.top = m_rtCaption.bottom() - fCapReserve; + m_rtCaption.height = fCapReserve; + XFA_RectWidthoutMargin(m_rtCaption, mgCap); + m_rtUI.height -= fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Inline: + break; + default: + iHorzAlign = XFA_ATTRIBUTEENUM_Right; + break; + } + + if (iHorzAlign == XFA_ATTRIBUTEENUM_Center) + m_rtUI.left += (m_rtUI.width - fCheckSize) / 2; + else if (iHorzAlign == XFA_ATTRIBUTEENUM_Right) + m_rtUI.left = m_rtUI.right() - fCheckSize; + + if (iVertAlign == XFA_ATTRIBUTEENUM_Middle) + m_rtUI.top += (m_rtUI.height - fCheckSize) / 2; + else if (iVertAlign == XFA_ATTRIBUTEENUM_Bottom) + m_rtUI.top = m_rtUI.bottom() - fCheckSize; + + m_rtUI.width = fCheckSize; + m_rtUI.height = fCheckSize; + AddUIMargin(iCapPlacement); + m_rtCheckBox = m_rtUI; + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + if (borderUI) { + CXFA_Margin margin = borderUI.GetMargin(); + if (margin) + XFA_RectWidthoutMargin(m_rtUI, margin); + } + + m_rtUI.Normalize(); + LayoutCaption(); + SetFWLRect(); + if (m_pNormalWidget) + m_pNormalWidget->Update(); + + return true; +} + +void CXFA_FFCheckButton::CapLeftRightPlacement(CXFA_Margin mgCap) { + XFA_RectWidthoutMargin(m_rtCaption, mgCap); + if (m_rtCaption.height < 0) + m_rtCaption.top += m_rtCaption.height; + if (m_rtCaption.width < 0) { + m_rtCaption.left += m_rtCaption.width; + m_rtCaption.width = -m_rtCaption.width; + } +} + +void CXFA_FFCheckButton::AddUIMargin(int32_t iCapPlacement) { + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); + m_rtUI.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2; + + float fLeftAddRight = rtUIMargin.left + rtUIMargin.width; + float fTopAddBottom = rtUIMargin.top + rtUIMargin.height; + if (m_rtUI.width < fLeftAddRight) { + if (iCapPlacement == XFA_ATTRIBUTEENUM_Right || + iCapPlacement == XFA_ATTRIBUTEENUM_Left) { + m_rtUI.left -= fLeftAddRight - m_rtUI.width; + } else { + m_rtUI.left -= 2 * (fLeftAddRight - m_rtUI.width); + } + m_rtUI.width += 2 * (fLeftAddRight - m_rtUI.width); + } + if (m_rtUI.height < fTopAddBottom) { + if (iCapPlacement == XFA_ATTRIBUTEENUM_Right) + m_rtUI.left -= fTopAddBottom - m_rtUI.height; + + m_rtUI.top -= fTopAddBottom - m_rtUI.height; + m_rtUI.height += 2 * (fTopAddBottom - m_rtUI.height); + } +} + +void CXFA_FFCheckButton::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + DrawBorder(pGS, borderUI, m_rtUI, &mtRotate, + m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round + ? XFA_DRAWBOX_ForceRound + : 0); + RenderCaption(pGS, &mtRotate); + DrawHighlight(pGS, &mtRotate, dwStatus, + m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round); + CFX_Matrix mt(1, 0, 0, 1, m_rtCheckBox.left, m_rtCheckBox.top); + mt.Concat(mtRotate); + GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, + &mt); +} + +bool CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, + const CFX_PointF& point) { + if (!m_pNormalWidget || !IsButtonDown()) + return false; + + SetButtonDown(false); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +XFA_CHECKSTATE CXFA_FFCheckButton::FWLState2XFAState() { + uint32_t dwState = m_pNormalWidget->GetStates(); + if (dwState & FWL_STATE_CKB_Checked) + return XFA_CHECKSTATE_On; + if (dwState & FWL_STATE_CKB_Neutral) + return XFA_CHECKSTATE_Neutral; + return XFA_CHECKSTATE_Off; +} + +bool CXFA_FFCheckButton::CommitData() { + XFA_CHECKSTATE eCheckState = FWLState2XFAState(); + m_pDataAcc->SetCheckState(eCheckState, true); + return true; +} + +bool CXFA_FFCheckButton::IsDataChanged() { + XFA_CHECKSTATE eCheckState = FWLState2XFAState(); + return m_pDataAcc->GetCheckState() != eCheckState; +} + +void CXFA_FFCheckButton::SetFWLCheckState(XFA_CHECKSTATE eCheckState) { + if (eCheckState == XFA_CHECKSTATE_Neutral) + m_pNormalWidget->SetStates(FWL_STATE_CKB_Neutral); + else if (eCheckState == XFA_CHECKSTATE_On) + m_pNormalWidget->SetStates(FWL_STATE_CKB_Checked); + else + m_pNormalWidget->RemoveStates(FWL_STATE_CKB_Checked); +} + +bool CXFA_FFCheckButton::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + XFA_CHECKSTATE eState = m_pDataAcc->GetCheckState(); + SetFWLCheckState(eState); + m_pNormalWidget->Update(); + return true; +} + +void CXFA_FFCheckButton::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + switch (pEvent->GetType()) { + case CFWL_Event::Type::CheckStateChanged: { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); + + CXFA_WidgetAcc* pFFExclGroup = m_pDataAcc->GetExclGroup(); + if (ProcessCommittedData()) { + eParam.m_pTarget = pFFExclGroup; + if (pFFExclGroup) { + m_pDocView->AddValidateWidget(pFFExclGroup); + m_pDocView->AddCalculateWidgetAcc(pFFExclGroup); + pFFExclGroup->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); + } + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); + } else { + SetFWLCheckState(m_pDataAcc->GetCheckState()); + } + if (pFFExclGroup) { + eParam.m_pTarget = pFFExclGroup; + pFFExclGroup->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); + } + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); + break; + } + default: + break; + } + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFCheckButton::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/xfa/fxfa/cxfa_ffcheckbutton.h b/xfa/fxfa/cxfa_ffcheckbutton.h new file mode 100644 index 0000000000..d6fd09d2c9 --- /dev/null +++ b/xfa/fxfa/cxfa_ffcheckbutton.h @@ -0,0 +1,46 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFCHECKBUTTON_H_ +#define XFA_FXFA_CXFA_FFCHECKBUTTON_H_ + +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" + +class CXFA_FFCheckButton : public CXFA_FFField { + public: + explicit CXFA_FFCheckButton(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFCheckButton() override; + + // CXFA_FFField + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + + bool LoadWidget() override; + bool PerformLayout() override; + bool UpdateFWLData() override; + void UpdateWidgetProperty() override; + bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + void SetFWLCheckState(XFA_CHECKSTATE eCheckState); + + private: + bool CommitData() override; + bool IsDataChanged() override; + void CapLeftRightPlacement(CXFA_Margin mgCap); + void AddUIMargin(int32_t iCapPlacement); + XFA_CHECKSTATE FWLState2XFAState(); + + IFWL_WidgetDelegate* m_pOldDelegate; + CFX_RectF m_rtCheckBox; +}; + +#endif // XFA_FXFA_CXFA_FFCHECKBUTTON_H_ diff --git a/xfa/fxfa/cxfa_ffcombobox.cpp b/xfa/fxfa/cxfa_ffcombobox.cpp new file mode 100644 index 0000000000..e256616521 --- /dev/null +++ b/xfa/fxfa/cxfa_ffcombobox.cpp @@ -0,0 +1,360 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffcombobox.h" + +#include +#include + +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffdocview.h" + +namespace { + +CFWL_ComboBox* ToComboBox(CFWL_Widget* widget) { + return static_cast(widget); +} + +} // namespace + +CXFA_FFComboBox::CXFA_FFComboBox(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFComboBox::~CXFA_FFComboBox() {} + +CFX_RectF CXFA_FFComboBox::GetBBox(uint32_t dwStatus, bool bDrawFocus) { + return bDrawFocus ? CFX_RectF() : CXFA_FFWidget::GetBBox(dwStatus); +} + +bool CXFA_FFComboBox::PtInActiveRect(const CFX_PointF& point) { + auto* pComboBox = ToComboBox(m_pNormalWidget.get()); + return pComboBox && pComboBox->GetBBox().Contains(point); +} + +bool CXFA_FFComboBox::LoadWidget() { + auto pNew = pdfium::MakeUnique(GetFWLApp()); + CFWL_ComboBox* pComboBox = pNew.get(); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) + pComboBox->AddString(label.AsStringC()); + + std::vector iSelArray = m_pDataAcc->GetSelectedItems(); + if (!iSelArray.empty()) { + pComboBox->SetCurSel(iSelArray.front()); + } else { + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); + pComboBox->SetEditText(wsText); + } + + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFComboBox::UpdateWidgetProperty() { + auto* pComboBox = ToComboBox(m_pNormalWidget.get()); + if (!pComboBox) + return; + + uint32_t dwExtendedStyle = 0; + uint32_t dwEditStyles = + FWL_STYLEEXT_EDT_ReadOnly | FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + if (m_pDataAcc->IsChoiceListAllowTextEntry()) { + dwEditStyles &= ~FWL_STYLEEXT_EDT_ReadOnly; + dwExtendedStyle |= FWL_STYLEEXT_CMB_DropDown; + } + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; + dwExtendedStyle |= FWL_STYLEEXT_CMB_ReadOnly; + } + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); + + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; + + pComboBox->EditModifyStylesEx(dwEditStyles, 0xFFFFFFFF); +} + +bool CXFA_FFComboBox::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) + return false; + + GetDoc()->GetDocEnvironment()->PopupMenu(this, point); + return true; +} + +bool CXFA_FFComboBox::OnKillFocus(CXFA_FFWidget* pNewWidget) { + if (!ProcessCommittedData()) + UpdateFWLData(); + + CXFA_FFField::OnKillFocus(pNewWidget); + return true; +} + +void CXFA_FFComboBox::OpenDropDownList() { + ToComboBox(m_pNormalWidget.get())->OpenDropDownList(true); +} + +bool CXFA_FFComboBox::CommitData() { + return m_pDataAcc->SetValue(m_wsNewValue, XFA_VALUEPICTURE_Raw); +} + +bool CXFA_FFComboBox::IsDataChanged() { + auto* pFWLcombobox = ToComboBox(m_pNormalWidget.get()); + CFX_WideString wsText = pFWLcombobox->GetEditText(); + int32_t iCursel = pFWLcombobox->GetCurSel(); + if (iCursel >= 0) { + CFX_WideString wsSel = pFWLcombobox->GetTextByIndex(iCursel); + if (wsSel == wsText) + m_pDataAcc->GetChoiceListItem(wsText, iCursel, true); + } + + CFX_WideString wsOldValue; + m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Raw); + if (wsOldValue == wsText) + return false; + + m_wsNewValue = wsText; + return true; +} + +void CXFA_FFComboBox::FWLEventSelChange(CXFA_EventParam* pParam) { + pParam->m_eType = XFA_EVENT_Change; + pParam->m_pTarget = m_pDataAcc.Get(); + pParam->m_wsNewText = ToComboBox(m_pNormalWidget.get())->GetEditText(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, pParam); +} + +uint32_t CXFA_FFComboBox::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= + FWL_STYLEEXT_CMB_EditHCenter | FWL_STYLEEXT_CMB_ListItemCenterAlign; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditJustified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + break; + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + break; + default: + dwExtendedStyle |= + FWL_STYLEEXT_CMB_EditHNear | FWL_STYLEEXT_CMB_ListItemLeftAlign; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVNear; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFComboBox::UpdateFWLData() { + auto* pComboBox = ToComboBox(m_pNormalWidget.get()); + if (!pComboBox) + return false; + + std::vector iSelArray = m_pDataAcc->GetSelectedItems(); + if (!iSelArray.empty()) { + pComboBox->SetCurSel(iSelArray.front()); + } else { + CFX_WideString wsText; + pComboBox->SetCurSel(-1); + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); + pComboBox->SetEditText(wsText); + } + pComboBox->Update(); + return true; +} + +bool CXFA_FFComboBox::CanUndo() { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditCanUndo(); +} + +bool CXFA_FFComboBox::CanRedo() { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditCanRedo(); +} + +bool CXFA_FFComboBox::Undo() { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditUndo(); +} + +bool CXFA_FFComboBox::Redo() { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditRedo(); +} + +bool CXFA_FFComboBox::CanCopy() { + return ToComboBox(m_pNormalWidget.get())->EditCanCopy(); +} + +bool CXFA_FFComboBox::CanCut() { + return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open && + m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditCanCut(); +} + +bool CXFA_FFComboBox::CanPaste() { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open; +} + +bool CXFA_FFComboBox::CanSelectAll() { + return ToComboBox(m_pNormalWidget.get())->EditCanSelectAll(); +} + +bool CXFA_FFComboBox::Copy(CFX_WideString& wsCopy) { + return ToComboBox(m_pNormalWidget.get())->EditCopy(wsCopy); +} + +bool CXFA_FFComboBox::Cut(CFX_WideString& wsCut) { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditCut(wsCut); +} + +bool CXFA_FFComboBox::Paste(const CFX_WideString& wsPaste) { + return m_pDataAcc->IsChoiceListAllowTextEntry() && + ToComboBox(m_pNormalWidget.get())->EditPaste(wsPaste); +} + +void CXFA_FFComboBox::SelectAll() { + ToComboBox(m_pNormalWidget.get())->EditSelectAll(); +} + +void CXFA_FFComboBox::Delete() { + ToComboBox(m_pNormalWidget.get())->EditDelete(); +} + +void CXFA_FFComboBox::DeSelect() { + ToComboBox(m_pNormalWidget.get())->EditDeSelect(); +} + +void CXFA_FFComboBox::SetItemState(int32_t nIndex, bool bSelected) { + ToComboBox(m_pNormalWidget.get())->SetCurSel(bSelected ? nIndex : -1); + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFComboBox::InsertItem(const CFX_WideStringC& wsLabel, + int32_t nIndex) { + ToComboBox(m_pNormalWidget.get())->AddString(wsLabel); + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFComboBox::DeleteItem(int32_t nIndex) { + if (nIndex < 0) + ToComboBox(m_pNormalWidget.get())->RemoveAll(); + else + ToComboBox(m_pNormalWidget.get())->RemoveAt(nIndex); + + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFComboBox::OnTextChanged(CFWL_Widget* pWidget, + const CFX_WideString& wsChanged) { + CXFA_EventParam eParam; + m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + eParam.m_wsChange = wsChanged; + FWLEventSelChange(&eParam); +} + +void CXFA_FFComboBox::OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp) { + CXFA_EventParam eParam; + m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + FWLEventSelChange(&eParam); + if (m_pDataAcc->GetChoiceListCommitOn() == XFA_ATTRIBUTEENUM_Select && + bLButtonUp) { + m_pDocView->SetFocusWidgetAcc(nullptr); + } +} + +void CXFA_FFComboBox::OnPreOpen(CFWL_Widget* pWidget) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_PreOpen; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PreOpen, &eParam); +} + +void CXFA_FFComboBox::OnPostOpen(CFWL_Widget* pWidget) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_PostOpen; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PostOpen, &eParam); +} + +void CXFA_FFComboBox::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFComboBox::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + switch (pEvent->GetType()) { + case CFWL_Event::Type::SelectChanged: { + auto* postEvent = static_cast(pEvent); + OnSelectChanged(m_pNormalWidget.get(), postEvent->bLButtonUp); + break; + } + case CFWL_Event::Type::EditChanged: { + CFX_WideString wsChanged; + OnTextChanged(m_pNormalWidget.get(), wsChanged); + break; + } + case CFWL_Event::Type::PreDropDown: { + OnPreOpen(m_pNormalWidget.get()); + break; + } + case CFWL_Event::Type::PostDropDown: { + OnPostOpen(m_pNormalWidget.get()); + break; + } + default: + break; + } + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFComboBox::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/xfa/fxfa/cxfa_ffcombobox.h b/xfa/fxfa/cxfa_ffcombobox.h new file mode 100644 index 0000000000..6c93646195 --- /dev/null +++ b/xfa/fxfa/cxfa_ffcombobox.h @@ -0,0 +1,69 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFCOMBOBOX_H_ +#define XFA_FXFA_CXFA_FFCOMBOBOX_H_ + +#include "xfa/fxfa/cxfa_fffield.h" + +class CXFA_FFComboBox : public CXFA_FFField { + public: + explicit CXFA_FFComboBox(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFComboBox() override; + + // CXFA_FFField + CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; + bool LoadWidget() override; + void UpdateWidgetProperty() override; + bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; + bool CanUndo() override; + bool CanRedo() override; + bool Undo() override; + bool Redo() override; + + bool CanCopy() override; + bool CanCut() override; + bool CanPaste() override; + bool CanSelectAll() override; + bool Copy(CFX_WideString& wsCopy) override; + bool Cut(CFX_WideString& wsCut) override; + bool Paste(const CFX_WideString& wsPaste) override; + void SelectAll() override; + void Delete() override; + void DeSelect() override; + + // IFWL_WidgetDelegate + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + virtual void OpenDropDownList(); + + void OnTextChanged(CFWL_Widget* pWidget, const CFX_WideString& wsChanged); + void OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp); + void OnPreOpen(CFWL_Widget* pWidget); + void OnPostOpen(CFWL_Widget* pWidget); + void SetItemState(int32_t nIndex, bool bSelected); + void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex); + void DeleteItem(int32_t nIndex); + + private: + // CXFA_FFField + bool PtInActiveRect(const CFX_PointF& point) override; + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + + uint32_t GetAlignment(); + void FWLEventSelChange(CXFA_EventParam* pParam); + + CFX_WideString m_wsNewValue; + IFWL_WidgetDelegate* m_pOldDelegate; +}; + +#endif // XFA_FXFA_CXFA_FFCOMBOBOX_H_ diff --git a/xfa/fxfa/cxfa_ffdatetimeedit.cpp b/xfa/fxfa/cxfa_ffdatetimeedit.cpp new file mode 100644 index 0000000000..b47175aa84 --- /dev/null +++ b/xfa/fxfa/cxfa_ffdatetimeedit.cpp @@ -0,0 +1,213 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffdatetimeedit.h" + +#include + +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_eventselectchanged.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" + +CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {} + +CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) { + if (bDrawFocus) + return CFX_RectF(); + return CXFA_FFWidget::GetBBox(dwStatus); +} + +bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) { + auto* pPicker = static_cast(m_pNormalWidget.get()); + return pPicker && pPicker->GetBBox().Contains(point); +} + +bool CXFA_FFDateTimeEdit::LoadWidget() { + auto pNewPicker = pdfium::MakeUnique(GetFWLApp()); + CFWL_DateTimePicker* pWidget = pNewPicker.get(); + m_pNormalWidget = std::move(pNewPicker); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pWidget->SetEditText(wsText); + if (CXFA_Value value = m_pDataAcc->GetFormValue()) { + switch (value.GetChildValueClassID()) { + case XFA_Element::Date: { + if (!wsText.IsEmpty()) { + CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); + CFX_DateTime date = lcValue.GetDate(); + if (date.IsSet()) + pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); + } + } break; + default: + break; + } + } + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { + CFWL_DateTimePicker* pWidget = + static_cast(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat; + dwExtendedStyle |= UpdateUIProperty(); + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); + uint32_t dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight; + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); + if (iNumCells > 0) { + dwEditStyles |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetEditLimit(iNumCells); + } + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; + } + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; + + pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); +} + +uint32_t CXFA_FFDateTimeEdit::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFDateTimeEdit::CommitData() { + auto* pPicker = static_cast(m_pNormalWidget.get()); + if (!m_pDataAcc->SetValue(pPicker->GetEditText(), XFA_VALUEPICTURE_Edit)) + return false; + + m_pDataAcc->UpdateUIDisplay(this); + return true; +} + +bool CXFA_FFDateTimeEdit::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; + if (IsFocused()) + eType = XFA_VALUEPICTURE_Edit; + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, eType); + + auto* normalWidget = static_cast(m_pNormalWidget.get()); + normalWidget->SetEditText(wsText); + if (IsFocused() && !wsText.IsEmpty()) { + CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc.Get()); + CFX_DateTime date = lcValue.GetDate(); + if (lcValue.IsValid()) { + if (date.IsSet()) + normalWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); + } + } + m_pNormalWidget->Update(); + return true; +} + +bool CXFA_FFDateTimeEdit::IsDataChanged() { + if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) + return true; + + CFX_WideString wsText = + static_cast(m_pNormalWidget.get())->GetEditText(); + CFX_WideString wsOldValue; + m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); + return wsOldValue != wsText; +} + +void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, + int32_t iYear, + int32_t iMonth, + int32_t iDay) { + CFX_WideString wsPicture; + m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit); + + CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr()); + date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); + + CFX_WideString wsDate; + date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), + XFA_VALUEPICTURE_Edit); + + auto* pDateTime = static_cast(m_pNormalWidget.get()); + pDateTime->SetEditText(wsDate); + pDateTime->Update(); + GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); + + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); +} + +void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { + if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) { + auto* event = static_cast(pEvent); + OnSelectChanged(m_pNormalWidget.get(), event->iYear, event->iMonth, + event->iDay); + return; + } + CXFA_FFTextEdit::OnProcessEvent(pEvent); +} diff --git a/xfa/fxfa/cxfa_ffdatetimeedit.h b/xfa/fxfa/cxfa_ffdatetimeedit.h new file mode 100644 index 0000000000..8b95164214 --- /dev/null +++ b/xfa/fxfa/cxfa_ffdatetimeedit.h @@ -0,0 +1,47 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFDATETIMEEDIT_H_ +#define XFA_FXFA_CXFA_FFDATETIMEEDIT_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "xfa/fxfa/cxfa_fftextedit.h" + +enum XFA_DATETIMETYPE { + XFA_DATETIMETYPE_Date = 0, + XFA_DATETIMETYPE_Time, + XFA_DATETIMETYPE_DateAndTime +}; + +class CFWL_Event; +class CFWL_Widget; + +class CXFA_FFDateTimeEdit : public CXFA_FFTextEdit { + public: + explicit CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFDateTimeEdit() override; + + // CXFA_FFTextEdit + CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; + bool LoadWidget() override; + void UpdateWidgetProperty() override; + void OnProcessEvent(CFWL_Event* pEvent) override; + + void OnSelectChanged(CFWL_Widget* pWidget, + int32_t iYear, + int32_t iMonth, + int32_t iDay); + + private: + bool PtInActiveRect(const CFX_PointF& point) override; + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + + uint32_t GetAlignment(); +}; + +#endif // XFA_FXFA_CXFA_FFDATETIMEEDIT_H_ diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 326fc7f228..3ed0ea0455 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -22,9 +22,9 @@ #include "core/fxcrt/xml/cfx_xmlnode.h" #include "third_party/base/ptr_util.h" #include "xfa/fwl/cfwl_notedriver.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/cxfa_fileread.h" #include "xfa/fxfa/cxfa_fontmgr.h" diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 03a692be83..8d1ec2338a 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -9,24 +9,24 @@ #include "core/fxcrt/fx_extension.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffbarcode.h" -#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" -#include "xfa/fxfa/app/cxfa_ffdraw.h" -#include "xfa/fxfa/app/cxfa_ffexclgroup.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_ffimage.h" -#include "xfa/fxfa/app/cxfa_ffimageedit.h" -#include "xfa/fxfa/app/cxfa_ffpushbutton.h" -#include "xfa/fxfa/app/cxfa_ffsignature.h" -#include "xfa/fxfa/app/cxfa_ffsubform.h" -#include "xfa/fxfa/app/cxfa_fftext.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" -#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffbarcode.h" +#include "xfa/fxfa/cxfa_ffcheckbutton.h" #include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdraw.h" +#include "xfa/fxfa/cxfa_ffexclgroup.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffimage.h" +#include "xfa/fxfa/cxfa_ffimageedit.h" #include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffpushbutton.h" +#include "xfa/fxfa/cxfa_ffsignature.h" +#include "xfa/fxfa/cxfa_ffsubform.h" +#include "xfa/fxfa/cxfa_fftext.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_widgetacciterator.h" #include "xfa/fxfa/parser/cxfa_binditems.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" diff --git a/xfa/fxfa/cxfa_ffdraw.cpp b/xfa/fxfa/cxfa_ffdraw.cpp new file mode 100644 index 0000000000..920073352a --- /dev/null +++ b/xfa/fxfa/cxfa_ffdraw.cpp @@ -0,0 +1,16 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffdraw.h" + +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFDraw::CXFA_FFDraw(CXFA_WidgetAcc* pDataAcc) : CXFA_FFWidget(pDataAcc) {} + +CXFA_FFDraw::~CXFA_FFDraw() {} diff --git a/xfa/fxfa/cxfa_ffdraw.h b/xfa/fxfa/cxfa_ffdraw.h new file mode 100644 index 0000000000..3ca106ac07 --- /dev/null +++ b/xfa/fxfa/cxfa_ffdraw.h @@ -0,0 +1,19 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFDRAW_H_ +#define XFA_FXFA_CXFA_FFDRAW_H_ + +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +class CXFA_FFDraw : public CXFA_FFWidget { + public: + explicit CXFA_FFDraw(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFDraw() override; +}; + +#endif // XFA_FXFA_CXFA_FFDRAW_H_ diff --git a/xfa/fxfa/cxfa_ffexclgroup.cpp b/xfa/fxfa/cxfa_ffexclgroup.cpp new file mode 100644 index 0000000000..cf6fafa72e --- /dev/null +++ b/xfa/fxfa/cxfa_ffexclgroup.cpp @@ -0,0 +1,30 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffexclgroup.h" + +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFExclGroup::CXFA_FFExclGroup(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFWidget(pDataAcc) {} + +CXFA_FFExclGroup::~CXFA_FFExclGroup() {} + +void CXFA_FFExclGroup::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); +} diff --git a/xfa/fxfa/cxfa_ffexclgroup.h b/xfa/fxfa/cxfa_ffexclgroup.h new file mode 100644 index 0000000000..a67b24b78d --- /dev/null +++ b/xfa/fxfa/cxfa_ffexclgroup.h @@ -0,0 +1,24 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFEXCLGROUP_H_ +#define XFA_FXFA_CXFA_FFEXCLGROUP_H_ + +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +class CXFA_FFExclGroup : public CXFA_FFWidget { + public: + explicit CXFA_FFExclGroup(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFExclGroup() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; +}; + +#endif // XFA_FXFA_CXFA_FFEXCLGROUP_H_ diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp new file mode 100644 index 0000000000..2826589c90 --- /dev/null +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -0,0 +1,785 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fffield.h" + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventmouse.h" +#include "xfa/fwl/cfwl_messagekey.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_messagemousewheel.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_picturebox.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fwltheme.h" +#include "xfa/fxfa/cxfa_textlayout.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" + +namespace { + +CXFA_FFField* ToField(CXFA_LayoutItem* widget) { + return static_cast(widget); +} + +} // namespace + +CXFA_FFField::CXFA_FFField(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFWidget(pDataAcc), m_pNormalWidget(nullptr) {} + +CXFA_FFField::~CXFA_FFField() { + CXFA_FFField::UnloadWidget(); +} + +CFX_RectF CXFA_FFField::GetBBox(uint32_t dwStatus, bool bDrawFocus) { + if (!bDrawFocus) + return CXFA_FFWidget::GetBBox(dwStatus); + + XFA_Element type = m_pDataAcc->GetUIType(); + if (type != XFA_Element::Button && type != XFA_Element::CheckButton && + type != XFA_Element::ImageEdit && type != XFA_Element::Signature && + type != XFA_Element::ChoiceList) { + return CFX_RectF(); + } + + CFX_RectF rtBox = m_rtUI; + GetRotateMatrix().TransformRect(rtBox); + return rtBox; +} + +void CXFA_FFField::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); + RenderCaption(pGS, &mtRotate); + DrawHighlight(pGS, &mtRotate, dwStatus, false); + + CFX_RectF rtWidget = m_pNormalWidget->GetWidgetRect(); + CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); + mt.Concat(mtRotate); + GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, + &mt); +} + +void CXFA_FFField::DrawHighlight(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus, + bool bEllipse) { + if (m_rtUI.IsEmpty() || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) + return; + + if (!(dwStatus & XFA_WidgetStatus_Highlight) || + m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { + return; + } + + CXFA_FFDoc* pDoc = GetDoc(); + CXFA_Color crHighlight(pDoc->GetDocEnvironment()->GetHighlightColor(pDoc)); + pGS->SetFillColor(&crHighlight); + CXFA_Path path; + if (bEllipse) + path.AddEllipse(m_rtUI); + else + path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); + + pGS->FillPath(&path, FXFILL_WINDING, pMatrix); +} + +void CXFA_FFField::DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { + if (!(m_dwStatus & XFA_WidgetStatus_Focused)) + return; + + CXFA_Color cr(0xFF000000); + pGS->SetStrokeColor(&cr); + + float DashPattern[2] = {1, 1}; + pGS->SetLineDash(0.0f, DashPattern, 2); + pGS->SetLineWidth(0, false); + + CXFA_Path path; + path.AddRectangle(m_rtUI.left, m_rtUI.top, m_rtUI.width, m_rtUI.height); + pGS->StrokePath(&path, pMatrix); +} + +void CXFA_FFField::SetFWLThemeProvider() { + if (m_pNormalWidget) + m_pNormalWidget->SetThemeProvider(GetApp()->GetFWLTheme()); +} + +bool CXFA_FFField::IsLoaded() { + return m_pNormalWidget && CXFA_FFWidget::IsLoaded(); +} + +bool CXFA_FFField::LoadWidget() { + SetFWLThemeProvider(); + m_pDataAcc->LoadCaption(); + PerformLayout(); + return true; +} + +void CXFA_FFField::UnloadWidget() { + m_pNormalWidget.reset(); +} + +void CXFA_FFField::SetEditScrollOffset() { + XFA_Element eType = m_pDataAcc->GetUIType(); + if (eType != XFA_Element::TextEdit && eType != XFA_Element::NumericEdit && + eType != XFA_Element::PasswordEdit) { + return; + } + + float fScrollOffset = 0; + CXFA_FFField* pPrev = ToField(GetPrev()); + if (pPrev) { + CFX_RectF rtMargin = m_pDataAcc->GetUIMargin(); + fScrollOffset = -rtMargin.top; + } + + while (pPrev) { + fScrollOffset += pPrev->m_rtUI.height; + pPrev = ToField(pPrev->GetPrev()); + } + static_cast(m_pNormalWidget.get()) + ->SetScrollOffset(fScrollOffset); +} + +bool CXFA_FFField::PerformLayout() { + CXFA_FFWidget::PerformLayout(); + CapPlacement(); + LayoutCaption(); + SetFWLRect(); + SetEditScrollOffset(); + if (m_pNormalWidget) + m_pNormalWidget->Update(); + return true; +} + +void CXFA_FFField::CapPlacement() { + CFX_RectF rtWidget = GetRectWithoutRotate(); + CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); + if (mgWidget) { + CXFA_LayoutItem* pItem = this; + float fLeftInset = 0, fRightInset = 0, fTopInset = 0, fBottomInset = 0; + mgWidget.GetLeftInset(fLeftInset); + mgWidget.GetRightInset(fRightInset); + mgWidget.GetTopInset(fTopInset); + mgWidget.GetBottomInset(fBottomInset); + if (!pItem->GetPrev() && !pItem->GetNext()) { + rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); + } else { + if (!pItem->GetPrev()) + rtWidget.Deflate(fLeftInset, fTopInset, fRightInset, 0); + else if (!pItem->GetNext()) + rtWidget.Deflate(fLeftInset, 0, fRightInset, fBottomInset); + else + rtWidget.Deflate(fLeftInset, 0, fRightInset, 0); + } + } + + XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; + float fCapReserve = 0; + CXFA_Caption caption = m_pDataAcc->GetCaption(); + if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { + iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); + if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && GetPrev()) { + m_rtCaption.Reset(); + } else if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && GetNext()) { + m_rtCaption.Reset(); + } else { + fCapReserve = caption.GetReserve(); + CXFA_LayoutItem* pItem = this; + if (!pItem->GetPrev() && !pItem->GetNext()) { + m_rtCaption = rtWidget; + } else { + pItem = pItem->GetFirst(); + m_rtCaption = pItem->GetRect(false); + pItem = pItem->GetNext(); + while (pItem) { + m_rtCaption.height += pItem->GetRect(false).Height(); + pItem = pItem->GetNext(); + } + XFA_RectWidthoutMargin(m_rtCaption, mgWidget); + } + + CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); + if (fCapReserve <= 0 && pCapTextLayout) { + CFX_SizeF size; + CFX_SizeF minSize; + CFX_SizeF maxSize; + pCapTextLayout->CalcSize(minSize, maxSize, size); + if (iCapPlacement == XFA_ATTRIBUTEENUM_Top || + iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { + fCapReserve = size.height; + } else { + fCapReserve = size.width; + } + } + } + } + + m_rtUI = rtWidget; + switch (iCapPlacement) { + case XFA_ATTRIBUTEENUM_Left: { + m_rtCaption.width = fCapReserve; + CapLeftRightPlacement(caption, rtWidget, iCapPlacement); + m_rtUI.width -= fCapReserve; + m_rtUI.left += fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Top: { + m_rtCaption.height = fCapReserve; + CapTopBottomPlacement(caption, rtWidget, iCapPlacement); + m_rtUI.top += fCapReserve; + m_rtUI.height -= fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Right: { + m_rtCaption.left = m_rtCaption.right() - fCapReserve; + m_rtCaption.width = fCapReserve; + CapLeftRightPlacement(caption, rtWidget, iCapPlacement); + m_rtUI.width -= fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Bottom: { + m_rtCaption.top = m_rtCaption.bottom() - fCapReserve; + m_rtCaption.height = fCapReserve; + CapTopBottomPlacement(caption, rtWidget, iCapPlacement); + m_rtUI.height -= fCapReserve; + break; + } + case XFA_ATTRIBUTEENUM_Inline: + break; + default: + break; + } + + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + if (borderUI) { + CXFA_Margin margin = borderUI.GetMargin(); + if (margin) + XFA_RectWidthoutMargin(m_rtUI, margin); + } + m_rtUI.Normalize(); +} + +void CXFA_FFField::CapTopBottomPlacement(CXFA_Caption caption, + const CFX_RectF& rtWidget, + int32_t iCapPlacement) { + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); + m_rtCaption.left += rtUIMargin.left; + if (CXFA_Margin mgCap = caption.GetMargin()) { + XFA_RectWidthoutMargin(m_rtCaption, mgCap); + if (m_rtCaption.height < 0) + m_rtCaption.top += m_rtCaption.height; + } + + float fWidth = rtUIMargin.left + rtUIMargin.width; + float fHeight = m_rtCaption.height + rtUIMargin.top + rtUIMargin.height; + if (fWidth > rtWidget.width) + m_rtUI.width += fWidth - rtWidget.width; + + if (fHeight == XFA_DEFAULTUI_HEIGHT && m_rtUI.height < XFA_MINUI_HEIGHT) { + m_rtUI.height = XFA_MINUI_HEIGHT; + m_rtCaption.top += rtUIMargin.top + rtUIMargin.height; + } else if (fHeight > rtWidget.height) { + m_rtUI.height += fHeight - rtWidget.height; + if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) + m_rtCaption.top += fHeight - rtWidget.height; + } +} + +void CXFA_FFField::CapLeftRightPlacement(CXFA_Caption caption, + const CFX_RectF& rtWidget, + int32_t iCapPlacement) { + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); + m_rtCaption.top += rtUIMargin.top; + m_rtCaption.height -= rtUIMargin.top; + if (CXFA_Margin mgCap = caption.GetMargin()) { + XFA_RectWidthoutMargin(m_rtCaption, mgCap); + if (m_rtCaption.height < 0) + m_rtCaption.top += m_rtCaption.height; + } + + float fWidth = m_rtCaption.width + rtUIMargin.left + rtUIMargin.width; + float fHeight = rtUIMargin.top + rtUIMargin.height; + if (fWidth > rtWidget.width) { + m_rtUI.width += fWidth - rtWidget.width; + if (iCapPlacement == XFA_ATTRIBUTEENUM_Right) + m_rtCaption.left += fWidth - rtWidget.width; + } + + if (fHeight == XFA_DEFAULTUI_HEIGHT && m_rtUI.height < XFA_MINUI_HEIGHT) { + m_rtUI.height = XFA_MINUI_HEIGHT; + m_rtCaption.top += rtUIMargin.top + rtUIMargin.height; + } else if (fHeight > rtWidget.height) { + m_rtUI.height += fHeight - rtWidget.height; + } +} + +void CXFA_FFField::UpdateFWL() { + if (m_pNormalWidget) + m_pNormalWidget->Update(); +} + +uint32_t CXFA_FFField::UpdateUIProperty() { + CXFA_Node* pUiNode = m_pDataAcc->GetUIChild(); + if (pUiNode && pUiNode->GetElementType() == XFA_Element::DefaultUi) + return FWL_STYLEEXT_EDT_ReadOnly; + return 0; +} + +void CXFA_FFField::SetFWLRect() { + if (!m_pNormalWidget) + return; + + CFX_RectF rtUi = m_rtUI; + if (rtUi.width < 1.0) + rtUi.width = 1.0; + if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + float fFontSize = m_pDataAcc->GetFontSize(); + if (rtUi.height < fFontSize) + rtUi.height = fFontSize; + } + m_pNormalWidget->SetWidgetRect(rtUi); +} + +bool CXFA_FFField::OnMouseEnter() { + if (!m_pNormalWidget) + return false; + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::Enter; + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnMouseExit() { + if (!m_pNormalWidget) + return false; + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::Leave; + TranslateFWLMessage(&ms); + return true; +} + +CFX_PointF CXFA_FFField::FWLToClient(const CFX_PointF& point) { + return m_pNormalWidget ? point - m_pNormalWidget->GetWidgetRect().TopLeft() + : point; +} + +bool CXFA_FFField::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + return false; + } + if (!PtInActiveRect(point)) + return false; + + SetButtonDown(true); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + if (!IsButtonDown()) + return false; + + SetButtonDown(false); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonDblClk; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::Move; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnMouseWheel(uint32_t dwFlags, + int16_t zDelta, + const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + + CFWL_MessageMouseWheel ms(nullptr, m_pNormalWidget.get()); + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + ms.m_delta = CFX_PointF(zDelta, 0); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + return false; + } + if (!PtInActiveRect(point)) + return false; + + SetButtonDown(true); + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + if (!IsButtonDown()) + return false; + + SetButtonDown(false); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::RightButtonUp; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { + if (!m_pNormalWidget) + return false; + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::RightButtonDblClk; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnSetFocus(CXFA_FFWidget* pOldWidget) { + CXFA_FFWidget::OnSetFocus(pOldWidget); + if (!m_pNormalWidget) + return false; + + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); + TranslateFWLMessage(&ms); + m_dwStatus |= XFA_WidgetStatus_Focused; + AddInvalidateRect(); + return true; +} + +bool CXFA_FFField::OnKillFocus(CXFA_FFWidget* pNewWidget) { + if (!m_pNormalWidget) + return CXFA_FFWidget::OnKillFocus(pNewWidget); + + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); + TranslateFWLMessage(&ms); + m_dwStatus &= ~XFA_WidgetStatus_Focused; + AddInvalidateRect(); + CXFA_FFWidget::OnKillFocus(pNewWidget); + return true; +} + +bool CXFA_FFField::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { + if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) + return false; + + CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_KeyCommand::KeyDown; + ms.m_dwFlags = dwFlags; + ms.m_dwKeyCode = dwKeyCode; + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { + if (!m_pNormalWidget || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) + return false; + + CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_KeyCommand::KeyUp; + ms.m_dwFlags = dwFlags; + ms.m_dwKeyCode = dwKeyCode; + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFField::OnChar(uint32_t dwChar, uint32_t dwFlags) { + if (!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) + return false; + if (dwChar == FWL_VKEY_Tab) + return true; + if (!m_pNormalWidget) + return false; + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) + return false; + + CFWL_MessageKey ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_KeyCommand::Char; + ms.m_dwFlags = dwFlags; + ms.m_dwKeyCode = dwChar; + TranslateFWLMessage(&ms); + return true; +} + +FWL_WidgetHit CXFA_FFField::OnHitTest(const CFX_PointF& point) { + if (m_pNormalWidget && + m_pNormalWidget->HitTest(FWLToClient(point)) != FWL_WidgetHit::Unknown) { + return FWL_WidgetHit::Client; + } + + if (!GetRectWithoutRotate().Contains(point)) + return FWL_WidgetHit::Unknown; + if (m_rtCaption.Contains(point)) + return FWL_WidgetHit::Titlebar; + return FWL_WidgetHit::Border; +} + +bool CXFA_FFField::OnSetCursor(const CFX_PointF& point) { + return true; +} + +bool CXFA_FFField::PtInActiveRect(const CFX_PointF& point) { + return m_pNormalWidget && m_pNormalWidget->GetWidgetRect().Contains(point); +} + +void CXFA_FFField::LayoutCaption() { + CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); + if (!pCapTextLayout) + return; + + float fHeight = 0; + pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height), + &fHeight); + if (m_rtCaption.height < fHeight) + m_rtCaption.height = fHeight; +} + +void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { + CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); + if (!pCapTextLayout) + return; + + CXFA_Caption caption = m_pDataAcc->GetCaption(); + if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) + return; + + if (!pCapTextLayout->IsLoaded()) + pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height)); + + CFX_RectF rtClip = m_rtCaption; + rtClip.Intersect(GetRectWithoutRotate()); + CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); + CFX_Matrix mt(1, 0, 0, 1, m_rtCaption.left, m_rtCaption.top); + if (pMatrix) { + pMatrix->TransformRect(rtClip); + mt.Concat(*pMatrix); + } + pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); +} + +bool CXFA_FFField::ProcessCommittedData() { + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) + return false; + if (!IsDataChanged()) + return false; + if (CalculateOverride() != 1) + return false; + if (!CommitData()) + return false; + + m_pDocView->SetChangeMark(); + m_pDocView->AddValidateWidget(m_pDataAcc.Get()); + return true; +} + +int32_t CXFA_FFField::CalculateOverride() { + CXFA_WidgetAcc* pAcc = m_pDataAcc->GetExclGroup(); + if (!pAcc) + return CalculateWidgetAcc(m_pDataAcc.Get()); + if (CalculateWidgetAcc(pAcc) == 0) + return 0; + + CXFA_Node* pNode = pAcc->GetExclGroupFirstMember(); + if (!pNode) + return 1; + + CXFA_WidgetAcc* pWidgetAcc = nullptr; + while (pNode) { + pWidgetAcc = static_cast(pNode->GetWidgetData()); + if (!pWidgetAcc) + return 1; + if (CalculateWidgetAcc(pWidgetAcc) == 0) + return 0; + + pNode = pWidgetAcc->GetExclGroupNextMember(pNode); + } + return 1; +} + +int32_t CXFA_FFField::CalculateWidgetAcc(CXFA_WidgetAcc* pAcc) { + CXFA_Calculate calc = pAcc->GetCalculate(); + if (!calc) + return 1; + + XFA_VERSION version = pAcc->GetDoc()->GetXFADoc()->GetCurVersionMode(); + switch (calc.GetOverride()) { + case XFA_ATTRIBUTEENUM_Error: { + if (version <= XFA_VERSION_204) + return 1; + + IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); + if (pAppProvider) { + pAppProvider->MsgBox(L"You are not allowed to modify this field.", + L"Calculate Override", XFA_MBICON_Warning, + XFA_MB_OK); + } + return 0; + } + case XFA_ATTRIBUTEENUM_Warning: { + if (version <= XFA_VERSION_204) { + CXFA_Script script = calc.GetScript(); + if (!script) + return 1; + + CFX_WideString wsExpression; + script.GetExpression(wsExpression); + if (wsExpression.IsEmpty()) + return 1; + } + + if (pAcc->GetNode()->IsUserInteractive()) + return 1; + + IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); + if (!pAppProvider) + return 0; + + CFX_WideString wsMessage; + calc.GetMessageText(wsMessage); + if (!wsMessage.IsEmpty()) + wsMessage += L"\r\n"; + + wsMessage += L"Are you sure you want to modify this field?"; + if (pAppProvider->MsgBox(wsMessage, L"Calculate Override", + XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) { + pAcc->GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); + return 1; + } + return 0; + } + case XFA_ATTRIBUTEENUM_Ignore: + return 0; + case XFA_ATTRIBUTEENUM_Disabled: + pAcc->GetNode()->SetFlag(XFA_NodeFlag_UserInteractive, false); + return 1; + default: + return 1; + } +} + +bool CXFA_FFField::CommitData() { + return false; +} + +bool CXFA_FFField::IsDataChanged() { + return false; +} + +void CXFA_FFField::TranslateFWLMessage(CFWL_Message* pMessage) { + GetApp()->GetWidgetMgrDelegate()->OnProcessMessageToForm(pMessage); +} + +void CXFA_FFField::OnProcessMessage(CFWL_Message* pMessage) {} + +void CXFA_FFField::OnProcessEvent(CFWL_Event* pEvent) { + switch (pEvent->GetType()) { + case CFWL_Event::Type::Mouse: { + CFWL_EventMouse* event = static_cast(pEvent); + if (event->m_dwCmd == FWL_MouseCommand::Enter) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_MouseEnter; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseEnter, &eParam); + } else if (event->m_dwCmd == FWL_MouseCommand::Leave) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_MouseExit; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseExit, &eParam); + } else if (event->m_dwCmd == FWL_MouseCommand::LeftButtonDown) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_MouseDown; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseDown, &eParam); + } else if (event->m_dwCmd == FWL_MouseCommand::LeftButtonUp) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_MouseUp; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_MouseUp, &eParam); + } + break; + } + case CFWL_Event::Type::Click: { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Click; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Click, &eParam); + break; + } + default: + break; + } +} + +void CXFA_FFField::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) {} diff --git a/xfa/fxfa/cxfa_fffield.h b/xfa/fxfa/cxfa_fffield.h new file mode 100644 index 0000000000..06f7a2d06b --- /dev/null +++ b/xfa/fxfa/cxfa_fffield.h @@ -0,0 +1,99 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFFIELD_H_ +#define XFA_FXFA_CXFA_FFFIELD_H_ + +#include + +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fwl/ifwl_widgetdelegate.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +#define XFA_MINUI_HEIGHT 4.32f +#define XFA_DEFAULTUI_HEIGHT 2.0f + +class CXFA_FFField : public CXFA_FFWidget, public IFWL_WidgetDelegate { + public: + explicit CXFA_FFField(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFField() override; + + // CXFA_FFWidget + CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false) override; + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + bool IsLoaded() override; + bool LoadWidget() override; + void UnloadWidget() override; + bool PerformLayout() override; + bool OnMouseEnter() override; + bool OnMouseExit() override; + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnMouseWheel(uint32_t dwFlags, + int16_t zDelta, + const CFX_PointF& point) override; + bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; + + bool OnSetFocus(CXFA_FFWidget* pOldWidget) override; + bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; + bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) override; + bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) override; + bool OnChar(uint32_t dwChar, uint32_t dwFlags) override; + FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; + bool OnSetCursor(const CFX_PointF& point) override; + + // IFWL_WidgetDelegate + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + void UpdateFWL(); + uint32_t UpdateUIProperty(); + + protected: + bool PtInActiveRect(const CFX_PointF& point) override; + + virtual void SetFWLRect(); + void SetFWLThemeProvider(); + CFWL_Widget* GetNormalWidget() { return m_pNormalWidget.get(); } + CFX_PointF FWLToClient(const CFX_PointF& point); + void LayoutCaption(); + void RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); + + int32_t CalculateOverride(); + int32_t CalculateWidgetAcc(CXFA_WidgetAcc* pAcc); + bool ProcessCommittedData(); + virtual bool CommitData(); + virtual bool IsDataChanged(); + void DrawHighlight(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus, + bool bEllipse); + void DrawFocus(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); + void TranslateFWLMessage(CFWL_Message* pMessage); + void CapPlacement(); + void CapTopBottomPlacement(CXFA_Caption caption, + const CFX_RectF& rtWidget, + int32_t iCapPlacement); + void CapLeftRightPlacement(CXFA_Caption caption, + const CFX_RectF& rtWidget, + int32_t iCapPlacement); + void SetEditScrollOffset(); + + std::unique_ptr m_pNormalWidget; + CFX_RectF m_rtUI; + CFX_RectF m_rtCaption; +}; + +#endif // XFA_FXFA_CXFA_FFFIELD_H_ diff --git a/xfa/fxfa/cxfa_ffimage.cpp b/xfa/fxfa/cxfa_ffimage.cpp new file mode 100644 index 0000000000..75f8c3609b --- /dev/null +++ b/xfa/fxfa/cxfa_ffimage.cpp @@ -0,0 +1,72 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffimage.h" + +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdraw.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFImage::CXFA_FFImage(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFImage::~CXFA_FFImage() { + CXFA_FFImage::UnloadWidget(); +} + +bool CXFA_FFImage::IsLoaded() { + return !!GetDataAcc()->GetImageImage(); +} + +bool CXFA_FFImage::LoadWidget() { + if (GetDataAcc()->GetImageImage()) + return true; + + GetDataAcc()->LoadImageImage(); + return CXFA_FFDraw::LoadWidget(); +} + +void CXFA_FFImage::UnloadWidget() { + GetDataAcc()->SetImageImage(nullptr); +} + +void CXFA_FFImage::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + + CFX_RetainPtr pDIBitmap = GetDataAcc()->GetImageImage(); + if (!pDIBitmap) + return; + + CFX_RectF rtImage = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rtImage, mgWidget); + + int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; + int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; + if (CXFA_Para para = m_pDataAcc->GetPara()) { + iHorzAlign = para.GetHorizontalAlign(); + iVertAlign = para.GetVerticalAlign(); + } + + CXFA_Value value = m_pDataAcc->GetFormValue(); + CXFA_Image imageObj = value.GetImage(); + int32_t iAspect = imageObj.GetAspect(); + int32_t iImageXDpi = 0; + int32_t iImageYDpi = 0; + m_pDataAcc->GetImageDpi(iImageXDpi, iImageYDpi); + XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, + iImageYDpi, iHorzAlign, iVertAlign); +} diff --git a/xfa/fxfa/cxfa_ffimage.h b/xfa/fxfa/cxfa_ffimage.h new file mode 100644 index 0000000000..e58983fdca --- /dev/null +++ b/xfa/fxfa/cxfa_ffimage.h @@ -0,0 +1,26 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFIMAGE_H_ +#define XFA_FXFA_CXFA_FFIMAGE_H_ + +#include "xfa/fxfa/cxfa_ffdraw.h" + +class CXFA_FFImage : public CXFA_FFDraw { + public: + explicit CXFA_FFImage(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFImage() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + bool IsLoaded() override; + bool LoadWidget() override; + void UnloadWidget() override; +}; + +#endif // XFA_FXFA_CXFA_FFIMAGE_H_ diff --git a/xfa/fxfa/cxfa_ffimageedit.cpp b/xfa/fxfa/cxfa_ffimageedit.cpp new file mode 100644 index 0000000000..02eeb98d84 --- /dev/null +++ b/xfa/fxfa/cxfa_ffimageedit.cpp @@ -0,0 +1,143 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffimageedit.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_app.h" +#include "xfa/fwl/cfwl_messagemouse.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_picturebox.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFImageEdit::CXFA_FFImageEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFImageEdit::~CXFA_FFImageEdit() { + CXFA_FFImageEdit::UnloadWidget(); +} + +bool CXFA_FFImageEdit::LoadWidget() { + auto pNew = pdfium::MakeUnique(GetFWLApp()); + CFWL_PictureBox* pPictureBox = pNew.get(); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = pPictureBox->GetDelegate(); + pPictureBox->SetDelegate(this); + + CXFA_FFField::LoadWidget(); + if (!m_pDataAcc->GetImageEditImage()) + UpdateFWLData(); + + return true; +} + +void CXFA_FFImageEdit::UnloadWidget() { + m_pDataAcc->SetImageEditImage(nullptr); + CXFA_FFField::UnloadWidget(); +} + +void CXFA_FFImageEdit::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); + RenderCaption(pGS, &mtRotate); + CFX_RetainPtr pDIBitmap = m_pDataAcc->GetImageEditImage(); + if (!pDIBitmap) + return; + + CFX_RectF rtImage = m_pNormalWidget->GetWidgetRect(); + int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; + int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; + if (CXFA_Para para = m_pDataAcc->GetPara()) { + iHorzAlign = para.GetHorizontalAlign(); + iVertAlign = para.GetVerticalAlign(); + } + + int32_t iAspect = XFA_ATTRIBUTEENUM_Fit; + if (CXFA_Value value = m_pDataAcc->GetFormValue()) { + if (CXFA_Image imageObj = value.GetImage()) + iAspect = imageObj.GetAspect(); + } + + int32_t iImageXDpi = 0; + int32_t iImageYDpi = 0; + m_pDataAcc->GetImageEditDpi(iImageXDpi, iImageYDpi); + XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, + iImageYDpi, iHorzAlign, iVertAlign); +} + +bool CXFA_FFImageEdit::OnLButtonDown(uint32_t dwFlags, + const CFX_PointF& point) { + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) + return false; + if (!PtInActiveRect(point)) + return false; + + SetButtonDown(true); + + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +void CXFA_FFImageEdit::SetFWLRect() { + if (!m_pNormalWidget) + return; + + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); + CFX_RectF rtImage(m_rtUI); + rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, + rtUIMargin.height); + m_pNormalWidget->SetWidgetRect(rtImage); +} + +bool CXFA_FFImageEdit::CommitData() { + return true; +} + +bool CXFA_FFImageEdit::UpdateFWLData() { + m_pDataAcc->SetImageEditImage(nullptr); + m_pDataAcc->LoadImageEditImage(); + return true; +} + +void CXFA_FFImageEdit::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFImageEdit::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFImageEdit::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/xfa/fxfa/cxfa_ffimageedit.h b/xfa/fxfa/cxfa_ffimageedit.h new file mode 100644 index 0000000000..2d0a649775 --- /dev/null +++ b/xfa/fxfa/cxfa_ffimageedit.h @@ -0,0 +1,37 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFIMAGEEDIT_H_ +#define XFA_FXFA_CXFA_FFIMAGEEDIT_H_ + +#include "xfa/fxfa/cxfa_fffield.h" + +class CXFA_FFImageEdit : public CXFA_FFField { + public: + explicit CXFA_FFImageEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFImageEdit() override; + + // CXFA_FFField + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + bool LoadWidget() override; + void UnloadWidget() override; + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + private: + void SetFWLRect() override; + bool UpdateFWLData() override; + bool CommitData() override; + + IFWL_WidgetDelegate* m_pOldDelegate; +}; + +#endif // XFA_FXFA_CXFA_FFIMAGEEDIT_H_ diff --git a/xfa/fxfa/cxfa_ffline.cpp b/xfa/fxfa/cxfa_ffline.cpp new file mode 100644 index 0000000000..e371034d79 --- /dev/null +++ b/xfa/fxfa/cxfa_ffline.cpp @@ -0,0 +1,99 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffline.h" + +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_graphics.h" +#include "xfa/fxgraphics/cxfa_path.h" + +CXFA_FFLine::CXFA_FFLine(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFLine::~CXFA_FFLine() {} + +void CXFA_FFLine::GetRectFromHand(CFX_RectF& rect, + int32_t iHand, + float fLineWidth) { + float fHalfWidth = fLineWidth / 2.0f; + if (rect.height < 1.0f) { + switch (iHand) { + case XFA_ATTRIBUTEENUM_Left: + rect.top -= fHalfWidth; + break; + case XFA_ATTRIBUTEENUM_Right: + rect.top += fHalfWidth; + } + } else if (rect.width < 1.0f) { + switch (iHand) { + case XFA_ATTRIBUTEENUM_Left: + rect.left += fHalfWidth; + break; + case XFA_ATTRIBUTEENUM_Right: + rect.left += fHalfWidth; + break; + } + } else { + switch (iHand) { + case XFA_ATTRIBUTEENUM_Left: + rect.Inflate(fHalfWidth, fHalfWidth); + break; + case XFA_ATTRIBUTEENUM_Right: + rect.Deflate(fHalfWidth, fHalfWidth); + break; + } + } +} + +void CXFA_FFLine::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CXFA_Value value = m_pDataAcc->GetFormValue(); + if (!value) + return; + + CXFA_Line lineObj = value.GetLine(); + FX_ARGB lineColor = 0xFF000000; + int32_t iStrokeType = 0; + float fLineWidth = 1.0f; + int32_t iCap = 0; + CXFA_Edge edge = lineObj.GetEdge(); + if (edge) { + if (edge.GetPresence() != XFA_ATTRIBUTEENUM_Visible) + return; + + lineColor = edge.GetColor(); + iStrokeType = edge.GetStrokeType(); + fLineWidth = edge.GetThickness(); + iCap = edge.GetCapType(); + } + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CFX_RectF rtLine = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rtLine, mgWidget); + + GetRectFromHand(rtLine, lineObj.GetHand(), fLineWidth); + CXFA_Path linePath; + if (lineObj.GetSlope() && rtLine.right() > 0.0f && rtLine.bottom() > 0.0f) + linePath.AddLine(rtLine.TopRight(), rtLine.BottomLeft()); + else + linePath.AddLine(rtLine.TopLeft(), rtLine.BottomRight()); + + CXFA_Color color(lineColor); + pGS->SaveGraphState(); + pGS->SetLineWidth(fLineWidth, true); + XFA_StrokeTypeSetLineDash(pGS, iStrokeType, iCap); + pGS->SetStrokeColor(&color); + pGS->SetLineCap(XFA_LineCapToFXGE(iCap)); + pGS->StrokePath(&linePath, &mtRotate); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/cxfa_ffline.h b/xfa/fxfa/cxfa_ffline.h new file mode 100644 index 0000000000..a5c7ee19f6 --- /dev/null +++ b/xfa/fxfa/cxfa_ffline.h @@ -0,0 +1,26 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFLINE_H_ +#define XFA_FXFA_CXFA_FFLINE_H_ + +#include "xfa/fxfa/cxfa_ffdraw.h" + +class CXFA_FFLine : public CXFA_FFDraw { + public: + explicit CXFA_FFLine(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFLine() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + + private: + void GetRectFromHand(CFX_RectF& rect, int32_t iHand, float fLineWidth); +}; + +#endif // XFA_FXFA_CXFA_FFLINE_H_ diff --git a/xfa/fxfa/cxfa_fflistbox.cpp b/xfa/fxfa/cxfa_fflistbox.cpp new file mode 100644 index 0000000000..c086953a29 --- /dev/null +++ b/xfa/fxfa/cxfa_fflistbox.cpp @@ -0,0 +1,210 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fflistbox.h" + +#include +#include +#include + +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_widget.h" +#include "xfa/fxfa/cxfa_eventparam.h" + +namespace { + +CFWL_ListBox* ToListBox(CFWL_Widget* widget) { + return static_cast(widget); +} + +} // namespace + +CXFA_FFListBox::CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFListBox::~CXFA_FFListBox() { + if (!m_pNormalWidget) + return; + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); +} + +bool CXFA_FFListBox::LoadWidget() { + auto pNew = pdfium::MakeUnique( + GetFWLApp(), pdfium::MakeUnique(), nullptr); + CFWL_ListBox* pListBox = pNew.get(); + pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, + 0xFFFFFFFF); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + for (const auto& label : m_pDataAcc->GetChoiceListItems(false)) + pListBox->AddString(label.AsStringC()); + + uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; + if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) + dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection; + + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); + for (int32_t selected : m_pDataAcc->GetSelectedItems()) + pListBox->SetSelItem(pListBox->GetItem(nullptr, selected), true); + + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) { + if (!ProcessCommittedData()) + UpdateFWLData(); + + CXFA_FFField::OnKillFocus(pNewFocus); + return true; +} + +bool CXFA_FFListBox::CommitData() { + auto* pListBox = ToListBox(m_pNormalWidget.get()); + std::vector iSelArray; + int32_t iSels = pListBox->CountSelItems(); + for (int32_t i = 0; i < iSels; ++i) + iSelArray.push_back(pListBox->GetSelIndex(i)); + + m_pDataAcc->SetSelectedItems(iSelArray, true, false, true); + return true; +} + +bool CXFA_FFListBox::IsDataChanged() { + std::vector iSelArray = m_pDataAcc->GetSelectedItems(); + int32_t iOldSels = pdfium::CollectionSize(iSelArray); + auto* pListBox = ToListBox(m_pNormalWidget.get()); + int32_t iSels = pListBox->CountSelItems(); + if (iOldSels != iSels) + return true; + + for (int32_t i = 0; i < iSels; ++i) { + CFWL_ListItem* hlistItem = pListBox->GetItem(nullptr, iSelArray[i]); + if (!(hlistItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)) + return true; + } + return false; +} + +uint32_t CXFA_FFListBox::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_LTB_CenterAlign; + break; + case XFA_ATTRIBUTEENUM_Justify: + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + break; + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFListBox::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + auto* pListBox = ToListBox(m_pNormalWidget.get()); + std::vector iSelArray = m_pDataAcc->GetSelectedItems(); + std::vector selItemArray(iSelArray.size()); + std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(), + [pListBox](int32_t val) { return pListBox->GetSelItem(val); }); + + pListBox->SetSelItem(pListBox->GetSelItem(-1), false); + for (CFWL_ListItem* pItem : selItemArray) + pListBox->SetSelItem(pItem, true); + + m_pNormalWidget->Update(); + return true; +} + +void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + + auto* pListBox = ToListBox(m_pNormalWidget.get()); + int32_t iSels = pListBox->CountSelItems(); + if (iSels > 0) { + CFWL_ListItem* item = pListBox->GetSelItem(0); + eParam.m_wsNewText = item ? item->GetText() : L""; + } + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); +} + +void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) { + auto* pListBox = ToListBox(m_pNormalWidget.get()); + pListBox->SetSelItem(pListBox->GetSelItem(nIndex), bSelected); + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFListBox::InsertItem(const CFX_WideStringC& wsLabel, + int32_t nIndex) { + CFX_WideString wsTemp(wsLabel); + ToListBox(m_pNormalWidget.get())->AddString(wsTemp.AsStringC()); + m_pNormalWidget->Update(); + AddInvalidateRect(); +} + +void CXFA_FFListBox::DeleteItem(int32_t nIndex) { + auto* pListBox = ToListBox(m_pNormalWidget.get()); + if (nIndex < 0) + pListBox->DeleteAll(); + else + pListBox->DeleteString(pListBox->GetItem(nullptr, nIndex)); + + pListBox->Update(); + AddInvalidateRect(); +} + +void CXFA_FFListBox::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + switch (pEvent->GetType()) { + case CFWL_Event::Type::SelectChanged: + OnSelectChanged(m_pNormalWidget.get()); + break; + default: + break; + } + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFListBox::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/xfa/fxfa/cxfa_fflistbox.h b/xfa/fxfa/cxfa_fflistbox.h new file mode 100644 index 0000000000..f89df4c529 --- /dev/null +++ b/xfa/fxfa/cxfa_fflistbox.h @@ -0,0 +1,40 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFLISTBOX_H_ +#define XFA_FXFA_CXFA_FFLISTBOX_H_ + +#include "xfa/fxfa/cxfa_fffield.h" + +class CXFA_FFListBox : public CXFA_FFField { + public: + explicit CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFListBox() override; + + // CXFA_FFField + bool LoadWidget() override; + bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + void OnSelectChanged(CFWL_Widget* pWidget); + void SetItemState(int32_t nIndex, bool bSelected); + void InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex); + void DeleteItem(int32_t nIndex); + + private: + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + + uint32_t GetAlignment(); + + IFWL_WidgetDelegate* m_pOldDelegate; +}; + +#endif // XFA_FXFA_CXFA_FFLISTBOX_H_ diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp new file mode 100644 index 0000000000..27ff31c32e --- /dev/null +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -0,0 +1,540 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffnotify.h" + +#include "fxjs/cfxjse_value.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffarc.h" +#include "xfa/fxfa/cxfa_ffbarcode.h" +#include "xfa/fxfa/cxfa_ffcheckbutton.h" +#include "xfa/fxfa/cxfa_ffcombobox.h" +#include "xfa/fxfa/cxfa_ffdatetimeedit.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffdraw.h" +#include "xfa/fxfa/cxfa_ffexclgroup.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffimage.h" +#include "xfa/fxfa/cxfa_ffimageedit.h" +#include "xfa/fxfa/cxfa_ffline.h" +#include "xfa/fxfa/cxfa_fflistbox.h" +#include "xfa/fxfa/cxfa_ffnumericedit.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffpasswordedit.h" +#include "xfa/fxfa/cxfa_ffpushbutton.h" +#include "xfa/fxfa/cxfa_ffrectangle.h" +#include "xfa/fxfa/cxfa_ffsignature.h" +#include "xfa/fxfa/cxfa_ffsubform.h" +#include "xfa/fxfa/cxfa_fftext.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_ffwidgethandler.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/cxfa_textlayout.h" +#include "xfa/fxfa/cxfa_textprovider.h" +#include "xfa/fxfa/parser/cxfa_node.h" + +namespace { + +CXFA_WidgetAcc* ToWidgetAcc(void* data) { + return static_cast(data); +} + +CXFA_FFListBox* ToListBox(CXFA_FFWidget* widget) { + return static_cast(widget); +} + +CXFA_FFComboBox* ToComboBox(CXFA_FFWidget* widget) { + return static_cast(widget); +} + +} // namespace + +static void XFA_FFDeleteWidgetAcc(void* pData) { + delete ToWidgetAcc(pData); +} + +static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteWidgetAcc = { + XFA_FFDeleteWidgetAcc, nullptr}; + +CXFA_FFNotify::CXFA_FFNotify(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} + +CXFA_FFNotify::~CXFA_FFNotify() {} + +void CXFA_FFNotify::OnPageEvent(CXFA_ContainerLayoutItem* pSender, + uint32_t dwEvent) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pSender->GetLayout()); + if (pDocView) + pDocView->OnPageEvent(pSender, dwEvent); +} + +void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender, + const wchar_t* pLabel, + const wchar_t* pValue, + int32_t iIndex) { + CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender); + if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) + return; + + CXFA_FFWidget* pWidget = nullptr; + while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { + if (pWidget->IsLoaded()) { + if (pWidgetAcc->IsListBox()) + ToListBox(pWidget)->InsertItem(pLabel, iIndex); + else + ToComboBox(pWidget)->InsertItem(pLabel, iIndex); + } + } +} + +void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_WidgetData* pSender, + int32_t iIndex) { + CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender); + if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) + return; + + CXFA_FFWidget* pWidget = nullptr; + while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { + if (pWidget->IsLoaded()) { + if (pWidgetAcc->IsListBox()) + ToListBox(pWidget)->DeleteItem(iIndex); + else + ToComboBox(pWidget)->DeleteItem(iIndex); + } + } +} + +CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) { + CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetDocLayout(); + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); + XFA_Element eType = pNode->GetElementType(); + if (eType == XFA_Element::PageArea) + return new CXFA_FFPageView(pDocView, pNode); + if (eType == XFA_Element::ContentArea) + return new CXFA_ContainerLayoutItem(pNode); + + CXFA_WidgetAcc* pAcc = ToWidgetAcc(pNode->GetWidgetData()); + if (!pAcc) + return new CXFA_ContentLayoutItem(pNode); + + CXFA_FFWidget* pWidget; + switch (pAcc->GetUIType()) { + case XFA_Element::Barcode: + pWidget = new CXFA_FFBarcode(pAcc); + break; + case XFA_Element::Button: + pWidget = new CXFA_FFPushButton(pAcc); + break; + case XFA_Element::CheckButton: + pWidget = new CXFA_FFCheckButton(pAcc); + break; + case XFA_Element::ChoiceList: { + if (pAcc->IsListBox()) + pWidget = new CXFA_FFListBox(pAcc); + else + pWidget = new CXFA_FFComboBox(pAcc); + } break; + case XFA_Element::DateTimeEdit: + pWidget = new CXFA_FFDateTimeEdit(pAcc); + break; + case XFA_Element::ImageEdit: + pWidget = new CXFA_FFImageEdit(pAcc); + break; + case XFA_Element::NumericEdit: + pWidget = new CXFA_FFNumericEdit(pAcc); + break; + case XFA_Element::PasswordEdit: + pWidget = new CXFA_FFPasswordEdit(pAcc); + break; + case XFA_Element::Signature: + pWidget = new CXFA_FFSignature(pAcc); + break; + case XFA_Element::TextEdit: + pWidget = new CXFA_FFTextEdit(pAcc); + break; + case XFA_Element::Arc: + pWidget = new CXFA_FFArc(pAcc); + break; + case XFA_Element::Line: + pWidget = new CXFA_FFLine(pAcc); + break; + case XFA_Element::Rectangle: + pWidget = new CXFA_FFRectangle(pAcc); + break; + case XFA_Element::Text: + pWidget = new CXFA_FFText(pAcc); + break; + case XFA_Element::Image: + pWidget = new CXFA_FFImage(pAcc); + break; + case XFA_Element::Draw: + pWidget = new CXFA_FFDraw(pAcc); + break; + case XFA_Element::Subform: + pWidget = new CXFA_FFSubForm(pAcc); + break; + case XFA_Element::ExclGroup: + pWidget = new CXFA_FFExclGroup(pAcc); + break; + case XFA_Element::DefaultUi: + default: + pWidget = nullptr; + break; + } + + if (pWidget) + pWidget->SetDocView(pDocView); + return pWidget; +} + +void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem, + float& fCalcWidth, + float& fCalcHeight) { + CXFA_WidgetAcc* pAcc = ToWidgetAcc(pItem->GetWidgetData()); + if (!pAcc) + return; + + pAcc->StartWidgetLayout(fCalcWidth, fCalcHeight); +} + +bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem, + int32_t iBlockIndex, + float& fCalcHeightPos) { + CXFA_WidgetAcc* pAcc = ToWidgetAcc(pItem->GetWidgetData()); + return pAcc && pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos); +} + +bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) { + bool bRet = false; + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return bRet; + + CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pFormItem->GetWidgetData()); + if (!pWidgetAcc) + return bRet; + + CXFA_EventParam EventParam; + EventParam.m_eType = XFA_EVENT_Unknown; + CFXJSE_Value* pRetValue = nullptr; + int32_t iRet = + pWidgetAcc->ExecuteScript(CXFA_Script(pScript), &EventParam, &pRetValue); + if (iRet == XFA_EVENTERROR_Success && pRetValue) { + bRet = pRetValue->ToBoolean(); + delete pRetValue; + } + return bRet; +} + +int32_t CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode, + XFA_EVENTTYPE eEventType, + bool bIsFormReady, + bool bRecursive, + CXFA_WidgetAcc* pExclude) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return XFA_EVENTERROR_NotExist; + return pDocView->ExecEventActivityByDeepFirst( + pFormNode, eEventType, bIsFormReady, bRecursive, + pExclude ? pExclude->GetNode() : nullptr); +} + +void CXFA_FFNotify::AddCalcValidate(CXFA_Node* pNode) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pNode->GetWidgetData()); + if (!pWidgetAcc) + return; + + pDocView->AddCalculateWidgetAcc(pWidgetAcc); + pDocView->AddValidateWidget(pWidgetAcc); +} + +CXFA_FFDoc* CXFA_FFNotify::GetHDOC() { + return m_pDoc.Get(); +} + +IXFA_DocEnvironment* CXFA_FFNotify::GetDocEnvironment() const { + return m_pDoc->GetDocEnvironment(); +} + +IXFA_AppProvider* CXFA_FFNotify::GetAppProvider() { + return m_pDoc->GetApp()->GetAppProvider(); +} + +CXFA_FFWidgetHandler* CXFA_FFNotify::GetWidgetHandler() { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + return pDocView ? pDocView->GetWidgetHandler() : nullptr; +} + +CXFA_FFWidget* CXFA_FFNotify::GetHWidget(CXFA_LayoutItem* pLayoutItem) { + return XFA_GetWidgetFromLayoutItem(pLayoutItem); +} + +void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) { + if (hWidget->GetDataAcc()->GetUIType() != XFA_Element::ChoiceList) + return; + + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + pDocView->LockUpdate(); + ToComboBox(hWidget)->OpenDropDownList(); + pDocView->UnlockUpdate(); + pDocView->UpdateDocView(); +} + +CFX_WideString CXFA_FFNotify::GetCurrentDateTime() { + CFX_DateTime dataTime; + dataTime.Now(); + + CFX_WideString wsDateTime; + wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(), + dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(), + dataTime.GetMinute(), dataTime.GetSecond()); + return wsDateTime; +} + +void CXFA_FFNotify::ResetData(CXFA_WidgetData* pWidgetData) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + pDocView->ResetWidgetData(ToWidgetAcc(pWidgetData)); +} + +int32_t CXFA_FFNotify::GetLayoutStatus() { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + return pDocView ? pDocView->GetLayoutStatus() : 0; +} + +void CXFA_FFNotify::RunNodeInitialize(CXFA_Node* pNode) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + pDocView->AddNewFormNode(pNode); +} + +void CXFA_FFNotify::RunSubformIndexChange(CXFA_Node* pSubformNode) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + pDocView->AddIndexChangedSubform(pSubformNode); +} + +CXFA_Node* CXFA_FFNotify::GetFocusWidgetNode() { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return nullptr; + + CXFA_WidgetAcc* pAcc = pDocView->GetFocusWidgetAcc(); + return pAcc ? pAcc->GetNode() : nullptr; +} + +void CXFA_FFNotify::SetFocusWidgetNode(CXFA_Node* pNode) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + CXFA_WidgetAcc* pAcc = pNode ? ToWidgetAcc(pNode->GetWidgetData()) : nullptr; + pDocView->SetFocusWidgetAcc(pAcc); +} + +void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + XFA_Element eType = pNode->GetElementType(); + if (XFA_IsCreateWidget(eType)) { + CXFA_WidgetAcc* pAcc = new CXFA_WidgetAcc(pDocView, pNode); + pNode->SetObject(XFA_ATTRIBUTE_WidgetData, pAcc, &gs_XFADeleteWidgetAcc); + return; + } + switch (eType) { + case XFA_Element::BindItems: + pDocView->m_BindItems.push_back(pNode); + break; + case XFA_Element::Validate: + pNode->SetFlag(XFA_NodeFlag_NeedsInitApp, false); + break; + default: + break; + } +} + +void CXFA_FFNotify::OnValueChanging(CXFA_Node* pSender, XFA_ATTRIBUTE eAttr) { + if (eAttr != XFA_ATTRIBUTE_Presence) + return; + if (pSender->GetPacketID() & XFA_XDPPACKET_Datasets) + return; + if (!pSender->IsFormContainer()) + return; + + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End) + return; + + CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender->GetWidgetData()); + if (!pWidgetAcc) + return; + + CXFA_FFWidget* pWidget = nullptr; + while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { + if (pWidget->IsLoaded()) + pWidget->AddInvalidateRect(); + } +} + +void CXFA_FFNotify::OnValueChanged(CXFA_Node* pSender, + XFA_ATTRIBUTE eAttr, + CXFA_Node* pParentNode, + CXFA_Node* pWidgetNode) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + if (!(pSender->GetPacketID() & XFA_XDPPACKET_Form)) { + if (eAttr == XFA_ATTRIBUTE_Value) + pDocView->AddCalculateNodeNotify(pSender); + return; + } + + XFA_Element eType = pParentNode->GetElementType(); + bool bIsContainerNode = pParentNode->IsContainerNode(); + CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pWidgetNode->GetWidgetData()); + if (!pWidgetAcc) + return; + + bool bUpdateProperty = false; + pDocView->SetChangeMark(); + switch (eType) { + case XFA_Element::Caption: { + CXFA_TextLayout* pCapOut = pWidgetAcc->GetCaptionTextLayout(); + if (!pCapOut) + return; + + pCapOut->Unload(); + break; + } + case XFA_Element::Ui: + case XFA_Element::Para: + bUpdateProperty = true; + break; + default: + break; + } + if (bIsContainerNode && eAttr == XFA_ATTRIBUTE_Access) + bUpdateProperty = true; + + if (eAttr == XFA_ATTRIBUTE_Value) { + pDocView->AddCalculateNodeNotify(pSender); + if (eType == XFA_Element::Value || bIsContainerNode) { + if (bIsContainerNode) { + pWidgetAcc->UpdateUIDisplay(); + pDocView->AddCalculateWidgetAcc(pWidgetAcc); + pDocView->AddValidateWidget(pWidgetAcc); + } else if (pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent) + ->GetElementType() == XFA_Element::ExclGroup) { + pWidgetAcc->UpdateUIDisplay(); + } + return; + } + } + + CXFA_FFWidget* pWidget = nullptr; + while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { + if (!pWidget->IsLoaded()) + continue; + + if (bUpdateProperty) + pWidget->UpdateWidgetProperty(); + pWidget->PerformLayout(); + pWidget->AddInvalidateRect(); + } +} + +void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) { + if (!pSender->IsFormContainer()) + return; + + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + bool bLayoutReady = + !(pDocView->m_bInLayoutStatus) && + (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End); + if (bLayoutReady) + m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc.Get()); +} + +void CXFA_FFNotify::OnChildRemoved() { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); + if (!pDocView) + return; + + bool bLayoutReady = + !(pDocView->m_bInLayoutStatus) && + (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End); + if (bLayoutReady) + m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc.Get()); +} + +void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout, + CXFA_LayoutItem* pSender, + int32_t iPageIdx, + uint32_t dwStatus) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); + if (!pDocView) + return; + + CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender); + if (!pWidget) + return; + + CXFA_FFPageView* pNewPageView = pDocView->GetPageView(iPageIdx); + uint32_t dwFilter = XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable | + XFA_WidgetStatus_Printable; + pWidget->ModifyStatus(dwStatus, dwFilter); + CXFA_FFPageView* pPrePageView = pWidget->GetPageView(); + if (pPrePageView != pNewPageView || + (dwStatus & (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) == + (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) { + pWidget->SetPageView(pNewPageView); + m_pDoc->GetDocEnvironment()->WidgetPostAdd(pWidget, pWidget->GetDataAcc()); + } + if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End || + !(dwStatus & XFA_WidgetStatus_Visible)) { + return; + } + if (pWidget->IsLoaded()) { + if (pWidget->GetWidgetRect() != pWidget->RecacheWidgetRect()) + pWidget->PerformLayout(); + } else { + pWidget->LoadWidget(); + } + pWidget->AddInvalidateRect(nullptr); +} + +void CXFA_FFNotify::OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout, + CXFA_LayoutItem* pSender) { + CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); + if (!pDocView) + return; + + CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender); + if (!pWidget) + return; + + pDocView->DeleteLayoutItem(pWidget); + m_pDoc->GetDocEnvironment()->WidgetPreRemove(pWidget, pWidget->GetDataAcc()); + pWidget->AddInvalidateRect(nullptr); +} diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h new file mode 100644 index 0000000000..12aca5ede3 --- /dev/null +++ b/xfa/fxfa/cxfa_ffnotify.h @@ -0,0 +1,77 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFNOTIFY_H_ +#define XFA_FXFA_CXFA_FFNOTIFY_H_ + +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/parser/cxfa_document.h" + +class CXFA_FFWidgetHandler; + +class CXFA_FFNotify { + public: + explicit CXFA_FFNotify(CXFA_FFDoc* pDoc); + ~CXFA_FFNotify(); + + void OnPageEvent(CXFA_ContainerLayoutItem* pSender, uint32_t dwEvent); + + void OnWidgetListItemAdded(CXFA_WidgetData* pSender, + const wchar_t* pLabel, + const wchar_t* pValue, + int32_t iIndex); + void OnWidgetListItemRemoved(CXFA_WidgetData* pSender, int32_t iIndex); + + // Node events + void OnNodeReady(CXFA_Node* pNode); + void OnValueChanging(CXFA_Node* pSender, XFA_ATTRIBUTE eAttr); + void OnValueChanged(CXFA_Node* pSender, + XFA_ATTRIBUTE eAttr, + CXFA_Node* pParentNode, + CXFA_Node* pWidgetNode); + void OnChildAdded(CXFA_Node* pSender); + void OnChildRemoved(); + + CXFA_LayoutItem* OnCreateLayoutItem(CXFA_Node* pNode); + void OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout, + CXFA_LayoutItem* pSender, + int32_t iPageIdx, + uint32_t dwStatus); + void OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout, + CXFA_LayoutItem* pSender); + + void StartFieldDrawLayout(CXFA_Node* pItem, + float& fCalcWidth, + float& fCalcHeight); + bool FindSplitPos(CXFA_Node* pItem, + int32_t iBlockIndex, + float& fCalcHeightPos); + bool RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem); + int32_t ExecEventByDeepFirst(CXFA_Node* pFormNode, + XFA_EVENTTYPE eEventType, + bool bIsFormReady = false, + bool bRecursive = true, + CXFA_WidgetAcc* pExclude = nullptr); + void AddCalcValidate(CXFA_Node* pNode); + CXFA_FFDoc* GetHDOC(); + IXFA_DocEnvironment* GetDocEnvironment() const; + IXFA_AppProvider* GetAppProvider(); + CXFA_FFWidgetHandler* GetWidgetHandler(); + CXFA_FFWidget* GetHWidget(CXFA_LayoutItem* pLayoutItem); + void OpenDropDownList(CXFA_FFWidget* hWidget); + CFX_WideString GetCurrentDateTime(); + void ResetData(CXFA_WidgetData* pWidgetData = nullptr); + int32_t GetLayoutStatus(); + void RunNodeInitialize(CXFA_Node* pNode); + void RunSubformIndexChange(CXFA_Node* pSubformNode); + CXFA_Node* GetFocusWidgetNode(); + void SetFocusWidgetNode(CXFA_Node* pNode); + + private: + CFX_UnownedPtr const m_pDoc; +}; + +#endif // XFA_FXFA_CXFA_FFNOTIFY_H_ diff --git a/xfa/fxfa/cxfa_ffnumericedit.cpp b/xfa/fxfa/cxfa_ffnumericedit.cpp new file mode 100644 index 0000000000..b397753c7e --- /dev/null +++ b/xfa/fxfa/cxfa_ffnumericedit.cpp @@ -0,0 +1,97 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffnumericedit.h" + +#include + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventvalidate.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" + +CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} + +bool CXFA_FFNumericEdit::LoadWidget() { + auto pNewEdit = pdfium::MakeUnique( + GetFWLApp(), pdfium::MakeUnique(), nullptr); + CFWL_Edit* pWidget = pNewEdit.get(); + m_pNormalWidget = std::move(pNewEdit); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pWidget->SetText(wsText); + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFNumericEdit::UpdateWidgetProperty() { + CFWL_Edit* pWidget = static_cast(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwExtendedStyle = + FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | + FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | + FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; + + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); + if (iNumCells > 0) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(iNumCells); + } + dwExtendedStyle |= GetAlignment(); + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; + } + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); +} + +void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { + if (pEvent->GetType() == CFWL_Event::Type::Validate) { + CFWL_EventValidate* event = static_cast(pEvent); + event->bValidate = OnValidate(m_pNormalWidget.get(), event->wsInsert); + return; + } + CXFA_FFTextEdit::OnProcessEvent(pEvent); +} + +bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, + CFX_WideString& wsText) { + CFX_WideString wsPattern; + m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); + if (!wsPattern.IsEmpty()) + return true; + + int32_t iLeads = 0; + m_pDataAcc->GetLeadDigits(iLeads); + + int32_t iFracs = 0; + m_pDataAcc->GetFracDigits(iFracs); + + CFX_WideString wsFormat; + CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get()); + widgetValue.GetNumericFormat(wsFormat, iLeads, iFracs); + return widgetValue.ValidateNumericTemp(wsText, wsFormat, + m_pDataAcc->GetLocal()); +} diff --git a/xfa/fxfa/cxfa_ffnumericedit.h b/xfa/fxfa/cxfa_ffnumericedit.h new file mode 100644 index 0000000000..ece0a49604 --- /dev/null +++ b/xfa/fxfa/cxfa_ffnumericedit.h @@ -0,0 +1,31 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFNUMERICEDIT_H_ +#define XFA_FXFA_CXFA_FFNUMERICEDIT_H_ + +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/cxfa_fftextedit.h" + +class CFWL_Event; +class CFWL_Widget; +class CXFA_WidgetAcc; + +class CXFA_FFNumericEdit : public CXFA_FFTextEdit { + public: + explicit CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFNumericEdit() override; + + // CXFA_FFTextEdit + bool LoadWidget() override; + void UpdateWidgetProperty() override; + void OnProcessEvent(CFWL_Event* pEvent) override; + + private: + bool OnValidate(CFWL_Widget* pWidget, CFX_WideString& wsText); +}; + +#endif // XFA_FXFA_CXFA_FFNUMERICEDIT_H_ diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp index 841318672f..9ba4432352 100644 --- a/xfa/fxfa/cxfa_ffpageview.cpp +++ b/xfa/fxfa/cxfa_ffpageview.cpp @@ -13,14 +13,14 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_rendercontext.h" -#include "xfa/fxfa/app/cxfa_ffcheckbutton.h" -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_ffimageedit.h" -#include "xfa/fxfa/app/cxfa_ffpushbutton.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/cxfa_ffcheckbutton.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffimageedit.h" +#include "xfa/fxfa/cxfa_ffpushbutton.h" #include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/parser/cxfa_node.h" namespace { diff --git a/xfa/fxfa/cxfa_ffpasswordedit.cpp b/xfa/fxfa/cxfa_ffpasswordedit.cpp new file mode 100644 index 0000000000..e0d9f33428 --- /dev/null +++ b/xfa/fxfa/cxfa_ffpasswordedit.cpp @@ -0,0 +1,64 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffpasswordedit.h" + +#include + +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_notedriver.h" + +CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFTextEdit(pDataAcc) {} + +CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {} + +bool CXFA_FFPasswordEdit::LoadWidget() { + auto pNewEdit = pdfium::MakeUnique( + GetFWLApp(), pdfium::MakeUnique(), nullptr); + CFWL_Edit* pWidget = pNewEdit.get(); + m_pNormalWidget = std::move(pNewEdit); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pWidget->SetText(wsText); + UpdateWidgetProperty(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFPasswordEdit::UpdateWidgetProperty() { + CFWL_Edit* pWidget = static_cast(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwExtendedStyle = + FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | + FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + + CFX_WideString wsPassWord; + m_pDataAcc->GetPasswordChar(wsPassWord); + if (!wsPassWord.IsEmpty()) + pWidget->SetAliasChar(wsPassWord.GetAt(0)); + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; + } + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); +} diff --git a/xfa/fxfa/cxfa_ffpasswordedit.h b/xfa/fxfa/cxfa_ffpasswordedit.h new file mode 100644 index 0000000000..7ff3600216 --- /dev/null +++ b/xfa/fxfa/cxfa_ffpasswordedit.h @@ -0,0 +1,24 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFPASSWORDEDIT_H_ +#define XFA_FXFA_CXFA_FFPASSWORDEDIT_H_ + +#include "xfa/fxfa/cxfa_fftextedit.h" + +class CXFA_WidgetAcc; + +class CXFA_FFPasswordEdit : public CXFA_FFTextEdit { + public: + explicit CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFPasswordEdit() override; + + // CXFA_FFTextEdit + bool LoadWidget() override; + void UpdateWidgetProperty() override; +}; + +#endif // XFA_FXFA_CXFA_FFPASSWORDEDIT_H_ diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp new file mode 100644 index 0000000000..a0594c7853 --- /dev/null +++ b/xfa/fxfa/cxfa_ffpushbutton.cpp @@ -0,0 +1,240 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffpushbutton.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fwl/cfwl_pushbutton.h" +#include "xfa/fwl/cfwl_widgetmgr.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_textlayout.h" +#include "xfa/fxfa/cxfa_textprovider.h" +#include "xfa/fxgraphics/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_path.h" + +CXFA_FFPushButton::CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFPushButton::~CXFA_FFPushButton() { + CXFA_FFPushButton::UnloadWidget(); +} + +void CXFA_FFPushButton::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + RenderHighlightCaption(pGS, &mtRotate); + + CFX_RectF rtWidget = GetRectWithoutRotate(); + CFX_Matrix mt(1, 0, 0, 1, rtWidget.left, rtWidget.top); + mt.Concat(mtRotate); + GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget.get(), pGS, + &mt); +} + +bool CXFA_FFPushButton::LoadWidget() { + ASSERT(!m_pNormalWidget); + auto pNew = pdfium::MakeUnique(GetFWLApp()); + CFWL_PushButton* pPushButton = pNew.get(); + m_pOldDelegate = pPushButton->GetDelegate(); + pPushButton->SetDelegate(this); + m_pNormalWidget = std::move(pNew); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pNormalWidget->LockUpdate(); + UpdateWidgetProperty(); + LoadHighlightCaption(); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFPushButton::UpdateWidgetProperty() { + uint32_t dwStyleEx = 0; + switch (m_pDataAcc->GetButtonHighlight()) { + case XFA_ATTRIBUTEENUM_Inverted: + dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteInverted; + break; + case XFA_ATTRIBUTEENUM_Outline: + dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteOutLine; + break; + case XFA_ATTRIBUTEENUM_Push: + dwStyleEx = XFA_FWL_PSBSTYLEEXT_HilitePush; + break; + default: + break; + } + m_pNormalWidget->ModifyStylesEx(dwStyleEx, 0xFFFFFFFF); +} + +void CXFA_FFPushButton::UnloadWidget() { + m_pRolloverTextLayout.reset(); + m_pDownTextLayout.reset(); + m_pRollProvider.reset(); + m_pDownProvider.reset(); + CXFA_FFField::UnloadWidget(); +} + +bool CXFA_FFPushButton::PerformLayout() { + CXFA_FFWidget::PerformLayout(); + CFX_RectF rtWidget = GetRectWithoutRotate(); + + m_rtUI = rtWidget; + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rtWidget, mgWidget); + + CXFA_Caption caption = m_pDataAcc->GetCaption(); + m_rtCaption = rtWidget; + if (CXFA_Margin mgCap = caption.GetMargin()) + XFA_RectWidthoutMargin(m_rtCaption, mgCap); + + LayoutHighlightCaption(); + SetFWLRect(); + if (m_pNormalWidget) + m_pNormalWidget->Update(); + + return true; +} +float CXFA_FFPushButton::GetLineWidth() { + CXFA_Border border = m_pDataAcc->GetBorder(false); + if (border && border.GetPresence() == XFA_ATTRIBUTEENUM_Visible) { + CXFA_Edge edge = border.GetEdge(0); + return edge.GetThickness(); + } + return 0; +} + +FX_ARGB CXFA_FFPushButton::GetLineColor() { + return 0xFF000000; +} + +FX_ARGB CXFA_FFPushButton::GetFillColor() { + return 0xFFFFFFFF; +} + +void CXFA_FFPushButton::LoadHighlightCaption() { + CXFA_Caption caption = m_pDataAcc->GetCaption(); + if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) + return; + + bool bRichText; + CFX_WideString wsRollover; + if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { + if (!m_pRollProvider) { + m_pRollProvider = pdfium::MakeUnique( + m_pDataAcc.Get(), XFA_TEXTPROVIDERTYPE_Rollover); + } + m_pRolloverTextLayout = + pdfium::MakeUnique(m_pRollProvider.get()); + } + CFX_WideString wsDown; + if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { + if (!m_pDownProvider) { + m_pDownProvider = pdfium::MakeUnique( + m_pDataAcc.Get(), XFA_TEXTPROVIDERTYPE_Down); + } + m_pDownTextLayout = + pdfium::MakeUnique(m_pDownProvider.get()); + } +} + +void CXFA_FFPushButton::LayoutHighlightCaption() { + CFX_SizeF sz(m_rtCaption.width, m_rtCaption.height); + LayoutCaption(); + if (m_pRolloverTextLayout) + m_pRolloverTextLayout->Layout(sz); + if (m_pDownTextLayout) + m_pDownTextLayout->Layout(sz); +} + +void CXFA_FFPushButton::RenderHighlightCaption(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix) { + CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); + CXFA_Caption caption = m_pDataAcc->GetCaption(); + if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) + return; + + CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); + CFX_RectF rtClip = m_rtCaption; + rtClip.Intersect(GetRectWithoutRotate()); + CFX_Matrix mt(1, 0, 0, 1, m_rtCaption.left, m_rtCaption.top); + if (pMatrix) { + pMatrix->TransformRect(rtClip); + mt.Concat(*pMatrix); + } + + uint32_t dwState = m_pNormalWidget->GetStates(); + if (m_pDownTextLayout && (dwState & FWL_STATE_PSB_Pressed) && + (dwState & FWL_STATE_PSB_Hovered)) { + if (m_pDownTextLayout->DrawString(pRenderDevice, mt, rtClip)) + return; + } else if (m_pRolloverTextLayout && (dwState & FWL_STATE_PSB_Hovered)) { + if (m_pRolloverTextLayout->DrawString(pRenderDevice, mt, rtClip)) + return; + } + + if (pCapTextLayout) + pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); +} + +void CXFA_FFPushButton::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFPushButton::OnProcessEvent(CFWL_Event* pEvent) { + m_pOldDelegate->OnProcessEvent(pEvent); + CXFA_FFField::OnProcessEvent(pEvent); +} + +void CXFA_FFPushButton::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HiliteInverted) { + if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && + (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { + CFX_RectF rtFill(0, 0, m_pNormalWidget->GetWidgetRect().Size()); + float fLineWith = GetLineWidth(); + rtFill.Deflate(fLineWith, fLineWith); + CXFA_Color cr(FXARGB_MAKE(128, 128, 255, 255)); + pGraphics->SetFillColor(&cr); + + CXFA_Path path; + path.AddRectangle(rtFill.left, rtFill.top, rtFill.width, rtFill.height); + pGraphics->FillPath(&path, FXFILL_WINDING, (CFX_Matrix*)pMatrix); + } + return; + } + + if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HiliteOutLine) { + if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && + (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { + float fLineWidth = GetLineWidth(); + CXFA_Color cr(FXARGB_MAKE(255, 128, 255, 255)); + pGraphics->SetStrokeColor(&cr); + pGraphics->SetLineWidth(fLineWidth); + + CXFA_Path path; + CFX_RectF rect = m_pNormalWidget->GetWidgetRect(); + path.AddRectangle(0, 0, rect.width, rect.height); + pGraphics->StrokePath(&path, (CFX_Matrix*)pMatrix); + } + } +} diff --git a/xfa/fxfa/cxfa_ffpushbutton.h b/xfa/fxfa/cxfa_ffpushbutton.h new file mode 100644 index 0000000000..e8b8909bb2 --- /dev/null +++ b/xfa/fxfa/cxfa_ffpushbutton.h @@ -0,0 +1,54 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFPUSHBUTTON_H_ +#define XFA_FXFA_CXFA_FFPUSHBUTTON_H_ + +#include + +#include "xfa/fxfa/cxfa_fffield.h" + +#define XFA_FWL_PSBSTYLEEXT_HiliteNone (0L << 0) +#define XFA_FWL_PSBSTYLEEXT_HiliteInverted (1L << 0) +#define XFA_FWL_PSBSTYLEEXT_HilitePush (2L << 0) +#define XFA_FWL_PSBSTYLEEXT_HiliteOutLine (4L << 0) + +class CXFA_TextProvider; + +class CXFA_FFPushButton : public CXFA_FFField { + public: + explicit CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFPushButton() override; + + // CXFA_FFField + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + bool LoadWidget() override; + void UnloadWidget() override; + bool PerformLayout() override; + void UpdateWidgetProperty() override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + private: + void LoadHighlightCaption(); + void LayoutHighlightCaption(); + void RenderHighlightCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix); + float GetLineWidth(); + FX_ARGB GetLineColor(); + FX_ARGB GetFillColor(); + + std::unique_ptr m_pRolloverTextLayout; + std::unique_ptr m_pDownTextLayout; + std::unique_ptr m_pRollProvider; + std::unique_ptr m_pDownProvider; + IFWL_WidgetDelegate* m_pOldDelegate; +}; + +#endif // XFA_FXFA_CXFA_FFPUSHBUTTON_H_ diff --git a/xfa/fxfa/cxfa_ffrectangle.cpp b/xfa/fxfa/cxfa_ffrectangle.cpp new file mode 100644 index 0000000000..670ad2b98f --- /dev/null +++ b/xfa/fxfa/cxfa_ffrectangle.cpp @@ -0,0 +1,34 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffrectangle.h" + +CXFA_FFRectangle::CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFRectangle::~CXFA_FFRectangle() {} + +void CXFA_FFRectangle::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CXFA_Value value = m_pDataAcc->GetFormValue(); + if (!value) + return; + + CXFA_Rectangle rtObj = value.GetRectangle(); + CFX_RectF rect = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) + XFA_RectWidthoutMargin(rect, mgWidget); + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + DrawBorder(pGS, rtObj, rect, &mtRotate); +} diff --git a/xfa/fxfa/cxfa_ffrectangle.h b/xfa/fxfa/cxfa_ffrectangle.h new file mode 100644 index 0000000000..bec5d080a0 --- /dev/null +++ b/xfa/fxfa/cxfa_ffrectangle.h @@ -0,0 +1,23 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFRECTANGLE_H_ +#define XFA_FXFA_CXFA_FFRECTANGLE_H_ + +#include "xfa/fxfa/cxfa_ffdraw.h" + +class CXFA_FFRectangle : public CXFA_FFDraw { + public: + explicit CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFRectangle() override; + + // CXFA_FFWidget + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; +}; + +#endif // XFA_FXFA_CXFA_FFRECTANGLE_H_ diff --git a/xfa/fxfa/cxfa_ffsignature.cpp b/xfa/fxfa/cxfa_ffsignature.cpp new file mode 100644 index 0000000000..96de0a69b0 --- /dev/null +++ b/xfa/fxfa/cxfa_ffsignature.cpp @@ -0,0 +1,114 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffsignature.h" + +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFSignature::CXFA_FFSignature(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc) {} + +CXFA_FFSignature::~CXFA_FFSignature() {} + +bool CXFA_FFSignature::LoadWidget() { + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFSignature::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + + CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); + DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); + RenderCaption(pGS, &mtRotate); + DrawHighlight(pGS, &mtRotate, dwStatus, false); +} + +bool CXFA_FFSignature::OnMouseEnter() { + return false; +} + +bool CXFA_FFSignature::OnMouseExit() { + return false; +} + +bool CXFA_FFSignature::OnLButtonDown(uint32_t dwFlags, + const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnLButtonDblClk(uint32_t dwFlags, + const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnMouseWheel(uint32_t dwFlags, + int16_t zDelta, + const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnRButtonDown(uint32_t dwFlags, + const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnRButtonDblClk(uint32_t dwFlags, + const CFX_PointF& point) { + return false; +} + +bool CXFA_FFSignature::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { + return false; +} + +bool CXFA_FFSignature::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { + return false; +} + +bool CXFA_FFSignature::OnChar(uint32_t dwChar, uint32_t dwFlags) { + return false; +} + +FWL_WidgetHit CXFA_FFSignature::OnHitTest(const CFX_PointF& point) { + if (m_pNormalWidget && + m_pNormalWidget->HitTest(FWLToClient(point)) != FWL_WidgetHit::Unknown) { + return FWL_WidgetHit::Client; + } + + if (!GetRectWithoutRotate().Contains(point)) + return FWL_WidgetHit::Unknown; + if (m_rtCaption.Contains(point)) + return FWL_WidgetHit::Titlebar; + return FWL_WidgetHit::Client; +} + +bool CXFA_FFSignature::OnSetCursor(const CFX_PointF& point) { + return false; +} diff --git a/xfa/fxfa/cxfa_ffsignature.h b/xfa/fxfa/cxfa_ffsignature.h new file mode 100644 index 0000000000..b4b9f8e5b9 --- /dev/null +++ b/xfa/fxfa/cxfa_ffsignature.h @@ -0,0 +1,42 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFSIGNATURE_H_ +#define XFA_FXFA_CXFA_FFSIGNATURE_H_ + +#include "xfa/fxfa/cxfa_fffield.h" + +class CXFA_FFSignature final : public CXFA_FFField { + public: + explicit CXFA_FFSignature(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFSignature() override; + + // CXFA_FFField + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + bool LoadWidget() override; + bool OnMouseEnter() override; + bool OnMouseExit() override; + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnMouseWheel(uint32_t dwFlags, + int16_t zDelta, + const CFX_PointF& pointy) override; + bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) override; + + bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) override; + bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) override; + bool OnChar(uint32_t dwChar, uint32_t dwFlags) override; + FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; + bool OnSetCursor(const CFX_PointF& point) override; +}; + +#endif // XFA_FXFA_CXFA_FFSIGNATURE_H_ diff --git a/xfa/fxfa/cxfa_ffsubform.cpp b/xfa/fxfa/cxfa_ffsubform.cpp new file mode 100644 index 0000000000..9345e66dd7 --- /dev/null +++ b/xfa/fxfa/cxfa_ffsubform.cpp @@ -0,0 +1,17 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_ffsubform.h" + +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +CXFA_FFSubForm::CXFA_FFSubForm(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFWidget(pDataAcc) {} + +CXFA_FFSubForm::~CXFA_FFSubForm() {} diff --git a/xfa/fxfa/cxfa_ffsubform.h b/xfa/fxfa/cxfa_ffsubform.h new file mode 100644 index 0000000000..051bd271bf --- /dev/null +++ b/xfa/fxfa/cxfa_ffsubform.h @@ -0,0 +1,19 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFSUBFORM_H_ +#define XFA_FXFA_CXFA_FFSUBFORM_H_ + +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" + +class CXFA_FFSubForm : public CXFA_FFWidget { + public: + explicit CXFA_FFSubForm(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFSubForm() override; +}; + +#endif // XFA_FXFA_CXFA_FFSUBFORM_H_ diff --git a/xfa/fxfa/cxfa_fftext.cpp b/xfa/fxfa/cxfa_fftext.cpp new file mode 100644 index 0000000000..9b646230c2 --- /dev/null +++ b/xfa/fxfa/cxfa_fftext.cpp @@ -0,0 +1,163 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fftext.h" + +#include "xfa/fwl/fwl_widgetdef.h" +#include "xfa/fwl/fwl_widgethit.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdraw.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_linkuserdata.h" +#include "xfa/fxfa/cxfa_pieceline.h" +#include "xfa/fxfa/cxfa_textlayout.h" +#include "xfa/fxfa/cxfa_textpiece.h" +#include "xfa/fxgraphics/cxfa_graphics.h" + +CXFA_FFText::CXFA_FFText(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} + +CXFA_FFText::~CXFA_FFText() {} + +void CXFA_FFText::RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) { + if (!IsMatchVisibleStatus(dwStatus)) + return; + + CFX_Matrix mtRotate = GetRotateMatrix(); + if (pMatrix) + mtRotate.Concat(*pMatrix); + + CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); + + CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); + if (!pTextLayout) + return; + + CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); + CFX_RectF rtText = GetRectWithoutRotate(); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { + CXFA_LayoutItem* pItem = this; + if (!pItem->GetPrev() && !pItem->GetNext()) { + XFA_RectWidthoutMargin(rtText, mgWidget); + } else { + float fLeftInset; + float fRightInset; + float fTopInset = 0; + float fBottomInset = 0; + mgWidget.GetLeftInset(fLeftInset); + mgWidget.GetRightInset(fRightInset); + if (!pItem->GetPrev()) + mgWidget.GetTopInset(fTopInset); + else if (!pItem->GetNext()) + mgWidget.GetBottomInset(fBottomInset); + + rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); + } + } + + CFX_Matrix mt(1, 0, 0, 1, rtText.left, rtText.top); + CFX_RectF rtClip = rtText; + mtRotate.TransformRect(rtClip); + mt.Concat(mtRotate); + pTextLayout->DrawString(pRenderDevice, mt, rtClip, GetIndex()); +} + +bool CXFA_FFText::IsLoaded() { + CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); + return pTextLayout && !pTextLayout->m_bHasBlock; +} + +bool CXFA_FFText::PerformLayout() { + CXFA_FFDraw::PerformLayout(); + CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); + if (!pTextLayout) + return false; + if (!pTextLayout->m_bHasBlock) + return true; + + pTextLayout->m_Blocks.clear(); + CXFA_LayoutItem* pItem = this; + if (!pItem->GetPrev() && !pItem->GetNext()) + return true; + + pItem = pItem->GetFirst(); + while (pItem) { + CFX_RectF rtText = pItem->GetRect(false); + if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { + if (!pItem->GetPrev()) { + float fTopInset; + mgWidget.GetTopInset(fTopInset); + rtText.height -= fTopInset; + } else if (!pItem->GetNext()) { + float fBottomInset; + mgWidget.GetBottomInset(fBottomInset); + rtText.height -= fBottomInset; + } + } + pTextLayout->ItemBlocks(rtText, pItem->GetIndex()); + pItem = pItem->GetNext(); + } + pTextLayout->m_bHasBlock = false; + return true; +} + +bool CXFA_FFText::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (!GetRectWithoutRotate().Contains(point)) + return false; + + const wchar_t* wsURLContent = GetLinkURLAtPoint(point); + if (!wsURLContent) + return false; + + SetButtonDown(true); + return true; +} + +bool CXFA_FFText::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { + return GetRectWithoutRotate().Contains(point) && !!GetLinkURLAtPoint(point); +} + +bool CXFA_FFText::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + if (!IsButtonDown()) + return false; + + SetButtonDown(false); + const wchar_t* wsURLContent = GetLinkURLAtPoint(point); + if (!wsURLContent) + return false; + + CXFA_FFDoc* pDoc = GetDoc(); + pDoc->GetDocEnvironment()->GotoURL(pDoc, wsURLContent); + return true; +} + +FWL_WidgetHit CXFA_FFText::OnHitTest(const CFX_PointF& point) { + if (!GetRectWithoutRotate().Contains(point)) + return FWL_WidgetHit::Unknown; + if (!GetLinkURLAtPoint(point)) + return FWL_WidgetHit::Unknown; + return FWL_WidgetHit::HyperLink; +} + +const wchar_t* CXFA_FFText::GetLinkURLAtPoint(const CFX_PointF& point) { + CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); + if (!pTextLayout) + return nullptr; + + CFX_RectF rect = GetRectWithoutRotate(); + for (const auto& pPieceLine : *pTextLayout->GetPieceLines()) { + for (const auto& pPiece : pPieceLine->m_textPieces) { + if (pPiece->pLinkData && + pPiece->rtPiece.Contains(point - rect.TopLeft())) { + return pPiece->pLinkData->GetLinkURL(); + } + } + } + return nullptr; +} diff --git a/xfa/fxfa/cxfa_fftext.h b/xfa/fxfa/cxfa_fftext.h new file mode 100644 index 0000000000..00c57c7cfc --- /dev/null +++ b/xfa/fxfa/cxfa_fftext.h @@ -0,0 +1,32 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFTEXT_H_ +#define XFA_FXFA_CXFA_FFTEXT_H_ + +#include "xfa/fxfa/cxfa_ffdraw.h" + +class CXFA_FFText : public CXFA_FFDraw { + public: + explicit CXFA_FFText(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFText() override; + + // CXFA_FFWidget + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) override; + FWL_WidgetHit OnHitTest(const CFX_PointF& point) override; + void RenderWidget(CXFA_Graphics* pGS, + CFX_Matrix* pMatrix, + uint32_t dwStatus) override; + bool IsLoaded() override; + bool PerformLayout() override; + + private: + const wchar_t* GetLinkURLAtPoint(const CFX_PointF& point); +}; + +#endif // XFA_FXFA_CXFA_FFTEXT_H_ diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp new file mode 100644 index 0000000000..9d6cffb2d7 --- /dev/null +++ b/xfa/fxfa/cxfa_fftextedit.cpp @@ -0,0 +1,359 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fftextedit.h" + +#include + +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_eventcheckword.h" +#include "xfa/fwl/cfwl_eventtarget.h" +#include "xfa/fwl/cfwl_eventtextchanged.h" +#include "xfa/fwl/cfwl_messagekillfocus.h" +#include "xfa/fwl/cfwl_messagesetfocus.h" +#include "xfa/fwl/cfwl_notedriver.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/parser/cxfa_node.h" + +CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc) + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} + +CXFA_FFTextEdit::~CXFA_FFTextEdit() { + if (m_pNormalWidget) { + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); + } +} + +bool CXFA_FFTextEdit::LoadWidget() { + auto pNewWidget = pdfium::MakeUnique( + GetFWLApp(), pdfium::MakeUnique(), nullptr); + CFWL_Edit* pFWLEdit = pNewWidget.get(); + m_pNormalWidget = std::move(pNewWidget); + m_pNormalWidget->SetLayoutItem(this); + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(), + m_pNormalWidget.get()); + m_pOldDelegate = m_pNormalWidget->GetDelegate(); + m_pNormalWidget->SetDelegate(this); + m_pNormalWidget->LockUpdate(); + UpdateWidgetProperty(); + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + pFWLEdit->SetText(wsText); + m_pNormalWidget->UnlockUpdate(); + return CXFA_FFField::LoadWidget(); +} + +void CXFA_FFTextEdit::UpdateWidgetProperty() { + CFWL_Edit* pWidget = static_cast(m_pNormalWidget.get()); + if (!pWidget) + return; + + uint32_t dwStyle = 0; + uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | + FWL_STYLEEXT_EDT_OuterScrollbar | + FWL_STYLEEXT_EDT_LastLineHeight; + dwExtendedStyle |= UpdateUIProperty(); + if (m_pDataAcc->IsMultiLine()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn; + if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + dwStyle |= FWL_WGTSTYLE_VScroll; + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll; + } + } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; + } + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || + !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; + dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; + } + + XFA_Element eType = XFA_Element::Unknown; + int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); + if (eType == XFA_Element::ExData) + iMaxChars = 0; + + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); + if (iNumCells == 0) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1); + } else if (iNumCells > 0) { + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(iNumCells); + } else { + pWidget->SetLimit(iMaxChars); + } + dwExtendedStyle |= GetAlignment(); + m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF); + m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); +} + +bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (!PtInActiveRect(point)) + return false; + if (!IsFocused()) { + m_dwStatus |= XFA_WidgetStatus_Focused; + UpdateFWLData(); + AddInvalidateRect(); + } + + SetButtonDown(true); + CFWL_MessageMouse ms(nullptr, m_pNormalWidget.get()); + ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { + if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) + return false; + if (!PtInActiveRect(point)) + return false; + if (!IsFocused()) { + m_dwStatus |= XFA_WidgetStatus_Focused; + UpdateFWLData(); + AddInvalidateRect(); + } + + SetButtonDown(true); + CFWL_MessageMouse ms(nullptr, nullptr); + ms.m_dwCmd = FWL_MouseCommand::RightButtonDown; + ms.m_dwFlags = dwFlags; + ms.m_pos = FWLToClient(point); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { + if (!CXFA_FFField::OnRButtonUp(dwFlags, point)) + return false; + + GetDoc()->GetDocEnvironment()->PopupMenu(this, point); + return true; +} + +bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { + m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; + if (!IsFocused()) { + m_dwStatus |= XFA_WidgetStatus_Focused; + UpdateFWLData(); + AddInvalidateRect(); + } + CXFA_FFWidget::OnSetFocus(pOldWidget); + CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget.get()); + TranslateFWLMessage(&ms); + return true; +} + +bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { + CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); + TranslateFWLMessage(&ms); + m_dwStatus &= ~XFA_WidgetStatus_Focused; + + SetEditScrollOffset(); + ProcessCommittedData(); + UpdateFWLData(); + AddInvalidateRect(); + CXFA_FFWidget::OnKillFocus(pNewWidget); + + m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; + return true; +} + +bool CXFA_FFTextEdit::CommitData() { + CFX_WideString wsText = + static_cast(m_pNormalWidget.get())->GetText(); + if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { + m_pDataAcc->UpdateUIDisplay(this); + return true; + } + ValidateNumberField(wsText); + return false; +} + +void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { + CXFA_WidgetAcc* pAcc = GetDataAcc(); + if (!pAcc || pAcc->GetUIType() != XFA_Element::NumericEdit) + return; + + IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); + if (!pAppProvider) + return; + + CFX_WideString wsSomField; + pAcc->GetNode()->GetSOMExpression(wsSomField); + + CFX_WideString wsMessage; + wsMessage.Format(L"%s can not contain %s", wsText.c_str(), + wsSomField.c_str()); + pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), XFA_MBICON_Error, + XFA_MB_OK); +} + +bool CXFA_FFTextEdit::IsDataChanged() { + return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0; +} + +uint32_t CXFA_FFTextEdit::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + + uint32_t dwExtendedStyle = 0; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; + break; + } + return dwExtendedStyle; +} + +bool CXFA_FFTextEdit::UpdateFWLData() { + if (!m_pNormalWidget) + return false; + + CFWL_Edit* pEdit = static_cast(m_pNormalWidget.get()); + XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; + if (IsFocused()) + eType = XFA_VALUEPICTURE_Edit; + + bool bUpdate = false; + if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && + m_pDataAcc->GetNumberOfCells() < 0) { + XFA_Element elementType = XFA_Element::Unknown; + int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); + if (elementType == XFA_Element::ExData) + iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; + if (pEdit->GetLimit() != iMaxChars) { + pEdit->SetLimit(iMaxChars); + bUpdate = true; + } + } else if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { + int32_t nDataLen = 0; + if (eType == XFA_VALUEPICTURE_Edit) + m_pDataAcc->GetBarcodeAttribute_DataLength(&nDataLen); + pEdit->SetLimit(nDataLen); + bUpdate = true; + } + + CFX_WideString wsText; + m_pDataAcc->GetValue(wsText, eType); + + CFX_WideString wsOldText = pEdit->GetText(); + if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { + pEdit->SetText(wsText); + bUpdate = true; + } + if (bUpdate) + m_pNormalWidget->Update(); + + return true; +} + +void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, + const CFX_WideString& wsChanged, + const CFX_WideString& wsPrevText) { + m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged; + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Change; + eParam.m_wsChange = wsChanged; + eParam.m_pTarget = m_pDataAcc.Get(); + eParam.m_wsPrevText = wsPrevText; + CFWL_Edit* pEdit = static_cast(m_pNormalWidget.get()); + if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) { + CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; + eParam.m_wsNewText = pDateTime->GetEditText(); + int32_t iSels = pDateTime->CountSelRanges(); + if (iSels) + eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart); + } else { + eParam.m_wsNewText = pEdit->GetText(); + int32_t iSels = pEdit->CountSelRanges(); + if (iSels) + eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart); + } + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); +} + +void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { + CXFA_EventParam eParam; + eParam.m_eType = XFA_EVENT_Full; + eParam.m_pTarget = m_pDataAcc.Get(); + m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); +} + +bool CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { + return sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit; +} + +void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { + m_pOldDelegate->OnProcessMessage(pMessage); +} + +void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { + CXFA_FFField::OnProcessEvent(pEvent); + switch (pEvent->GetType()) { + case CFWL_Event::Type::TextChanged: { + CFWL_EventTextChanged* event = + static_cast(pEvent); + CFX_WideString wsChange; + OnTextChanged(m_pNormalWidget.get(), wsChange, event->wsPrevText); + break; + } + case CFWL_Event::Type::TextFull: { + OnTextFull(m_pNormalWidget.get()); + break; + } + case CFWL_Event::Type::CheckWord: { + CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); + CFWL_EventCheckWord* event = static_cast(pEvent); + event->bCheckWord = CheckWord(event->bsWord.AsStringC()); + break; + } + default: + break; + } + m_pOldDelegate->OnProcessEvent(pEvent); +} + +void CXFA_FFTextEdit::OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); +} diff --git a/xfa/fxfa/cxfa_fftextedit.h b/xfa/fxfa/cxfa_fftextedit.h new file mode 100644 index 0000000000..48656adfc1 --- /dev/null +++ b/xfa/fxfa/cxfa_fftextedit.h @@ -0,0 +1,57 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FFTEXTEDIT_H_ +#define XFA_FXFA_CXFA_FFTEXTEDIT_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/cxfa_fffield.h" + +class CFWL_Event; +class CFWL_Widget; +class CFX_Matrix; +class CXFA_FFWidget; +class CXFA_WidgetAcc; +class IFWL_WidgetDelegate; + +class CXFA_FFTextEdit : public CXFA_FFField { + public: + explicit CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc); + ~CXFA_FFTextEdit() override; + + // CXFA_FFField + bool LoadWidget() override; + void UpdateWidgetProperty() override; + bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) override; + bool OnSetFocus(CXFA_FFWidget* pOldWidget) override; + bool OnKillFocus(CXFA_FFWidget* pNewWidget) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CXFA_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + + void OnTextChanged(CFWL_Widget* pWidget, + const CFX_WideString& wsChanged, + const CFX_WideString& wsPrevText); + void OnTextFull(CFWL_Widget* pWidget); + bool CheckWord(const CFX_ByteStringC& sWord); + + protected: + uint32_t GetAlignment(); + + IFWL_WidgetDelegate* m_pOldDelegate; + + private: + bool CommitData() override; + bool UpdateFWLData() override; + bool IsDataChanged() override; + void ValidateNumberField(const CFX_WideString& wsText); +}; + +#endif // XFA_FXFA_CXFA_FFTEXTEDIT_H_ diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 2573ff4f6b..8dc767e5ee 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -21,12 +21,12 @@ #include "core/fxge/dib/cfx_imagerenderer.h" #include "core/fxge/dib/cfx_imagetransformer.h" #include "xfa/fwl/fwl_widgethit.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_textlayout.h" #include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cxfa_corner.h" #include "xfa/fxfa/parser/cxfa_node.h" diff --git a/xfa/fxfa/cxfa_ffwidgethandler.cpp b/xfa/fxfa/cxfa_ffwidgethandler.cpp index b703f746e8..c78b5e8837 100644 --- a/xfa/fxfa/cxfa_ffwidgethandler.cpp +++ b/xfa/fxfa/cxfa_ffwidgethandler.cpp @@ -8,11 +8,11 @@ #include -#include "xfa/fxfa/app/cxfa_fffield.h" -#include "xfa/fxfa/app/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_fffield.h" #include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" diff --git a/xfa/fxfa/cxfa_fwladapterwidgetmgr.cpp b/xfa/fxfa/cxfa_fwladapterwidgetmgr.cpp new file mode 100644 index 0000000000..f4e7527478 --- /dev/null +++ b/xfa/fxfa/cxfa_fwladapterwidgetmgr.cpp @@ -0,0 +1,38 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" + +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_fffield.h" + +CXFA_FWLAdapterWidgetMgr::CXFA_FWLAdapterWidgetMgr() {} + +CXFA_FWLAdapterWidgetMgr::~CXFA_FWLAdapterWidgetMgr() {} + +void CXFA_FWLAdapterWidgetMgr::RepaintWidget(CFWL_Widget* pWidget) { + if (!pWidget) + return; + + CXFA_FFWidget* pFFWidget = pWidget->GetLayoutItem(); + if (!pFFWidget) + return; + + pFFWidget->AddInvalidateRect(nullptr); +} + +bool CXFA_FWLAdapterWidgetMgr::GetPopupPos(CFWL_Widget* pWidget, + float fMinHeight, + float fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup) { + CXFA_FFWidget* pFFWidget = pWidget->GetLayoutItem(); + CFX_RectF rtRotateAnchor(rtAnchor); + pFFWidget->GetRotateMatrix().TransformRect(rtRotateAnchor); + pFFWidget->GetDoc()->GetDocEnvironment()->GetPopupPos( + pFFWidget, fMinHeight, fMaxHeight, rtRotateAnchor, rtPopup); + return true; +} diff --git a/xfa/fxfa/cxfa_fwladapterwidgetmgr.h b/xfa/fxfa/cxfa_fwladapterwidgetmgr.h new file mode 100644 index 0000000000..f5c4ce160e --- /dev/null +++ b/xfa/fxfa/cxfa_fwladapterwidgetmgr.h @@ -0,0 +1,28 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FWLADAPTERWIDGETMGR_H_ +#define XFA_FXFA_CXFA_FWLADAPTERWIDGETMGR_H_ + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_system.h" + +class CFWL_Widget; + +class CXFA_FWLAdapterWidgetMgr { + public: + CXFA_FWLAdapterWidgetMgr(); + ~CXFA_FWLAdapterWidgetMgr(); + + void RepaintWidget(CFWL_Widget* pWidget); + bool GetPopupPos(CFWL_Widget* pWidget, + float fMinHeight, + float fMaxHeight, + const CFX_RectF& rtAnchor, + CFX_RectF& rtPopup); +}; + +#endif // XFA_FXFA_CXFA_FWLADAPTERWIDGETMGR_H_ diff --git a/xfa/fxfa/cxfa_fwltheme.cpp b/xfa/fxfa/cxfa_fwltheme.cpp new file mode 100644 index 0000000000..89ce0dbfbc --- /dev/null +++ b/xfa/fxfa/cxfa_fwltheme.cpp @@ -0,0 +1,284 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_fwltheme.h" + +#include "core/fxcrt/fx_codepage.h" +#include "xfa/fde/cfde_textout.h" +#include "xfa/fgas/font/cfgas_gefont.h" +#include "xfa/fwl/cfwl_barcode.h" +#include "xfa/fwl/cfwl_caret.h" +#include "xfa/fwl/cfwl_checkbox.h" +#include "xfa/fwl/cfwl_combobox.h" +#include "xfa/fwl/cfwl_datetimepicker.h" +#include "xfa/fwl/cfwl_edit.h" +#include "xfa/fwl/cfwl_listbox.h" +#include "xfa/fwl/cfwl_monthcalendar.h" +#include "xfa/fwl/cfwl_picturebox.h" +#include "xfa/fwl/cfwl_pushbutton.h" +#include "xfa/fwl/cfwl_scrollbar.h" +#include "xfa/fwl/cfwl_themebackground.h" +#include "xfa/fwl/cfwl_themetext.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxgraphics/cxfa_color.h" + +namespace { + +const wchar_t* const g_FWLTheme_CalFonts[] = { + L"Arial", L"Courier New", L"DejaVu Sans", +}; + +const float kLineHeight = 12.0f; + +} // namespace + +CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget) { + CFWL_Widget* pOuter = pWidget; + while (pOuter && pOuter->GetOuter()) + pOuter = pOuter->GetOuter(); + return pOuter ? pOuter->GetLayoutItem() : nullptr; +} + +CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) + : m_pCheckBoxTP(pdfium::MakeUnique()), + m_pListBoxTP(pdfium::MakeUnique()), + m_pPictureBoxTP(pdfium::MakeUnique()), + m_pSrollBarTP(pdfium::MakeUnique()), + m_pEditTP(pdfium::MakeUnique()), + m_pComboBoxTP(pdfium::MakeUnique()), + m_pMonthCalendarTP(pdfium::MakeUnique()), + m_pDateTimePickerTP(pdfium::MakeUnique()), + m_pPushButtonTP(pdfium::MakeUnique()), + m_pCaretTP(pdfium::MakeUnique()), + m_pBarcodeTP(pdfium::MakeUnique()), + m_pTextOut(pdfium::MakeUnique()), + m_pCalendarFont(nullptr), + m_pApp(pApp) { + m_Rect.Reset(); + + for (size_t i = 0; !m_pCalendarFont && i < FX_ArraySize(g_FWLTheme_CalFonts); + ++i) { + m_pCalendarFont = CFGAS_GEFont::LoadFont(g_FWLTheme_CalFonts[i], 0, 0, + m_pApp->GetFDEFontMgr()); + } + if (!m_pCalendarFont) { + m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetFontByCodePage( + FX_CODEPAGE_MSWin_WesternEuropean, 0, nullptr); + } + + ASSERT(m_pCalendarFont); +} + +CXFA_FWLTheme::~CXFA_FWLTheme() { + m_pTextOut.reset(); + FWLTHEME_Release(); +} + +void CXFA_FWLTheme::DrawBackground(CFWL_ThemeBackground* pParams) { + GetTheme(pParams->m_pWidget)->DrawBackground(pParams); +} + +void CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) { + if (pParams->m_wsText.IsEmpty()) + return; + + if (pParams->m_pWidget->GetClassID() == FWL_Type::MonthCalendar) { + CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); + if (!pWidget) + return; + + m_pTextOut->SetStyles(pParams->m_dwTTOStyles); + m_pTextOut->SetAlignment(pParams->m_iTTOAlign); + m_pTextOut->SetFont(m_pCalendarFont); + m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); + m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); + if ((pParams->m_iPart == CFWL_Part::DatesIn) && + !(pParams->m_dwStates & FWL_ITEMSTATE_MCD_Flag) && + (pParams->m_dwStates & + (CFWL_PartState_Hovered | CFWL_PartState_Selected))) { + m_pTextOut->SetTextColor(0xFFFFFFFF); + } + if (pParams->m_iPart == CFWL_Part::Caption) + m_pTextOut->SetTextColor(ArgbEncode(0xff, 0, 153, 255)); + + CXFA_Graphics* pGraphics = pParams->m_pGraphics; + CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice(); + if (!pRenderDevice) + return; + + m_pTextOut->SetRenderDevice(pRenderDevice); + CFX_Matrix mtPart = pParams->m_matrix; + CFX_Matrix* pMatrix = pGraphics->GetMatrix(); + if (pMatrix) { + mtPart.Concat(*pMatrix); + } + m_pTextOut->SetMatrix(mtPart); + m_pTextOut->DrawLogicText(pParams->m_wsText.c_str(), + pParams->m_wsText.GetLength(), pParams->m_rtPart); + return; + } + CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); + if (!pWidget) + return; + + CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); + CXFA_Graphics* pGraphics = pParams->m_pGraphics; + CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice(); + if (!pRenderDevice) + return; + + m_pTextOut->SetRenderDevice(pRenderDevice); + m_pTextOut->SetStyles(pParams->m_dwTTOStyles); + m_pTextOut->SetAlignment(pParams->m_iTTOAlign); + m_pTextOut->SetFont(pAcc->GetFDEFont()); + m_pTextOut->SetFontSize(pAcc->GetFontSize()); + m_pTextOut->SetTextColor(pAcc->GetTextColor()); + CFX_Matrix mtPart = pParams->m_matrix; + CFX_Matrix* pMatrix = pGraphics->GetMatrix(); + if (pMatrix) + mtPart.Concat(*pMatrix); + + m_pTextOut->SetMatrix(mtPart); + m_pTextOut->DrawLogicText(pParams->m_wsText.c_str(), + pParams->m_wsText.GetLength(), pParams->m_rtPart); +} + +CFX_RectF CXFA_FWLTheme::GetUIMargin(CFWL_ThemePart* pThemePart) const { + CFX_RectF rect; + CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget); + if (!pWidget) + return rect; + + CXFA_LayoutItem* pItem = pWidget; + CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); + rect = pWidgetAcc->GetUIMargin(); + if (CXFA_Para para = pWidgetAcc->GetPara()) { + rect.left += para.GetMarginLeft(); + if (pWidgetAcc->IsMultiLine()) + rect.width += para.GetMarginRight(); + } + if (!pItem->GetPrev()) { + if (pItem->GetNext()) + rect.height = 0; + } else if (!pItem->GetNext()) { + rect.top = 0; + } else { + rect.top = 0; + rect.height = 0; + } + return rect; +} + +float CXFA_FWLTheme::GetCXBorderSize() const { + return 1.0f; +} + +float CXFA_FWLTheme::GetCYBorderSize() const { + return 1.0f; +} + +float CXFA_FWLTheme::GetFontSize(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetFontSize(); + return FWLTHEME_CAPACITY_FontSize; +} + +CFX_RetainPtr CXFA_FWLTheme::GetFont( + CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetFDEFont(); + return GetTheme(pThemePart->m_pWidget)->GetFont(); +} + +float CXFA_FWLTheme::GetLineHeight(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetLineHeight(); + return kLineHeight; +} + +float CXFA_FWLTheme::GetScrollBarWidth() const { + return 9.0f; +} + +FX_COLORREF CXFA_FWLTheme::GetTextColor(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetTextColor(); + return FWLTHEME_CAPACITY_TextColor; +} + +CFX_SizeF CXFA_FWLTheme::GetSpaceAboveBelow(CFWL_ThemePart* pThemePart) const { + CFX_SizeF sizeAboveBelow; + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { + CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); + if (CXFA_Para para = pWidgetAcc->GetPara()) { + sizeAboveBelow.width = para.GetSpaceAbove(); + sizeAboveBelow.height = para.GetSpaceBelow(); + } + } + return sizeAboveBelow; +} + +void CXFA_FWLTheme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) { + if (pParams->m_pWidget->GetClassID() == FWL_Type::MonthCalendar) { + CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); + if (!pWidget || !pParams || !m_pTextOut) + return; + + m_pTextOut->SetFont(m_pCalendarFont); + m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); + m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); + m_pTextOut->SetAlignment(pParams->m_iTTOAlign); + m_pTextOut->SetStyles(pParams->m_dwTTOStyles); + m_pTextOut->CalcLogicSize(pParams->m_wsText.c_str(), + pParams->m_wsText.GetLength(), rect); + } + + CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget); + if (!pWidget) + return; + + CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); + m_pTextOut->SetFont(pAcc->GetFDEFont()); + m_pTextOut->SetFontSize(pAcc->GetFontSize()); + m_pTextOut->SetTextColor(pAcc->GetTextColor()); + if (!pParams) + return; + + m_pTextOut->SetAlignment(pParams->m_iTTOAlign); + m_pTextOut->SetStyles(pParams->m_dwTTOStyles); + m_pTextOut->CalcLogicSize(pParams->m_wsText.c_str(), + pParams->m_wsText.GetLength(), rect); +} + +CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(CFWL_Widget* pWidget) const { + switch (pWidget->GetClassID()) { + case FWL_Type::CheckBox: + return m_pCheckBoxTP.get(); + case FWL_Type::ListBox: + return m_pListBoxTP.get(); + case FWL_Type::PictureBox: + return m_pPictureBoxTP.get(); + case FWL_Type::ScrollBar: + return m_pSrollBarTP.get(); + case FWL_Type::Edit: + return m_pEditTP.get(); + case FWL_Type::ComboBox: + return m_pComboBoxTP.get(); + case FWL_Type::MonthCalendar: + return m_pMonthCalendarTP.get(); + case FWL_Type::DateTimePicker: + return m_pDateTimePickerTP.get(); + case FWL_Type::PushButton: + return m_pPushButtonTP.get(); + case FWL_Type::Caret: + return m_pCaretTP.get(); + case FWL_Type::Barcode: + return m_pBarcodeTP.get(); + default: + return nullptr; + } +} diff --git a/xfa/fxfa/cxfa_fwltheme.h b/xfa/fxfa/cxfa_fwltheme.h new file mode 100644 index 0000000000..9fbb068cc3 --- /dev/null +++ b/xfa/fxfa/cxfa_fwltheme.h @@ -0,0 +1,70 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_FWLTHEME_H_ +#define XFA_FXFA_CXFA_FWLTHEME_H_ + +#include + +#include "xfa/fwl/ifwl_themeprovider.h" +#include "xfa/fwl/theme/cfwl_barcodetp.h" +#include "xfa/fwl/theme/cfwl_carettp.h" +#include "xfa/fwl/theme/cfwl_checkboxtp.h" +#include "xfa/fwl/theme/cfwl_comboboxtp.h" +#include "xfa/fwl/theme/cfwl_datetimepickertp.h" +#include "xfa/fwl/theme/cfwl_edittp.h" +#include "xfa/fwl/theme/cfwl_listboxtp.h" +#include "xfa/fwl/theme/cfwl_monthcalendartp.h" +#include "xfa/fwl/theme/cfwl_pictureboxtp.h" +#include "xfa/fwl/theme/cfwl_pushbuttontp.h" +#include "xfa/fwl/theme/cfwl_scrollbartp.h" +#include "xfa/fwl/theme/cfwl_widgettp.h" +#include "xfa/fxfa/cxfa_ffapp.h" + +class CXFA_FWLTheme final : public IFWL_ThemeProvider { + public: + explicit CXFA_FWLTheme(CXFA_FFApp* pApp); + ~CXFA_FWLTheme() override; + + // IFWL_ThemeProvider: + void DrawBackground(CFWL_ThemeBackground* pParams) override; + void DrawText(CFWL_ThemeText* pParams) override; + void CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) override; + float GetCXBorderSize() const override; + float GetCYBorderSize() const override; + CFX_RectF GetUIMargin(CFWL_ThemePart* pThemePart) const override; + float GetFontSize(CFWL_ThemePart* pThemePart) const override; + CFX_RetainPtr GetFont( + CFWL_ThemePart* pThemePart) const override; + float GetLineHeight(CFWL_ThemePart* pThemePart) const override; + float GetScrollBarWidth() const override; + FX_COLORREF GetTextColor(CFWL_ThemePart* pThemePart) const override; + CFX_SizeF GetSpaceAboveBelow(CFWL_ThemePart* pThemePart) const override; + + private: + CFWL_WidgetTP* GetTheme(CFWL_Widget* pWidget) const; + + std::unique_ptr m_pCheckBoxTP; + std::unique_ptr m_pListBoxTP; + std::unique_ptr m_pPictureBoxTP; + std::unique_ptr m_pSrollBarTP; + std::unique_ptr m_pEditTP; + std::unique_ptr m_pComboBoxTP; + std::unique_ptr m_pMonthCalendarTP; + std::unique_ptr m_pDateTimePickerTP; + std::unique_ptr m_pPushButtonTP; + std::unique_ptr m_pCaretTP; + std::unique_ptr m_pBarcodeTP; + std::unique_ptr m_pTextOut; + CFX_RetainPtr m_pCalendarFont; + CFX_WideString m_wsResource; + CFX_UnownedPtr const m_pApp; + CFX_RectF m_Rect; +}; + +CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget); + +#endif // XFA_FXFA_CXFA_FWLTHEME_H_ diff --git a/xfa/fxfa/cxfa_linkuserdata.cpp b/xfa/fxfa/cxfa_linkuserdata.cpp new file mode 100644 index 0000000000..c32b74664c --- /dev/null +++ b/xfa/fxfa/cxfa_linkuserdata.cpp @@ -0,0 +1,12 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_linkuserdata.h" + +CXFA_LinkUserData::CXFA_LinkUserData(wchar_t* pszText) + : m_wsURLContent(pszText) {} + +CXFA_LinkUserData::~CXFA_LinkUserData() {} diff --git a/xfa/fxfa/cxfa_linkuserdata.h b/xfa/fxfa/cxfa_linkuserdata.h new file mode 100644 index 0000000000..a445aadd23 --- /dev/null +++ b/xfa/fxfa/cxfa_linkuserdata.h @@ -0,0 +1,29 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_LINKUSERDATA_H_ +#define XFA_FXFA_CXFA_LINKUSERDATA_H_ + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" + +class CXFA_LinkUserData : public CFX_Retainable { + public: + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); + + const wchar_t* GetLinkURL() const { return m_wsURLContent.c_str(); } + + private: + explicit CXFA_LinkUserData(wchar_t* pszText); + ~CXFA_LinkUserData() override; + + CFX_WideString m_wsURLContent; +}; + +#endif // XFA_FXFA_CXFA_LINKUSERDATA_H_ diff --git a/xfa/fxfa/cxfa_loadercontext.cpp b/xfa/fxfa/cxfa_loadercontext.cpp new file mode 100644 index 0000000000..05ba9f19d1 --- /dev/null +++ b/xfa/fxfa/cxfa_loadercontext.cpp @@ -0,0 +1,21 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_loadercontext.h" + +CXFA_LoaderContext::CXFA_LoaderContext() + : m_bSaveLineHeight(false), + m_fWidth(0), + m_fHeight(0), + m_fLastPos(0), + m_fStartLineOffset(0), + m_iChar(0), + m_iTotalLines(-1), + m_dwFlags(0), + m_pXMLNode(nullptr), + m_pNode(nullptr) {} + +CXFA_LoaderContext::~CXFA_LoaderContext() {} diff --git a/xfa/fxfa/cxfa_loadercontext.h b/xfa/fxfa/cxfa_loadercontext.h new file mode 100644 index 0000000000..5bf8ed3661 --- /dev/null +++ b/xfa/fxfa/cxfa_loadercontext.h @@ -0,0 +1,40 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_LOADERCONTEXT_H_ +#define XFA_FXFA_CXFA_LOADERCONTEXT_H_ + +#include + +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_system.h" +#include "xfa/fde/css/cfde_csscomputedstyle.h" + +class CFX_XMLNode; +class CXFA_Node; + +class CXFA_LoaderContext { + public: + CXFA_LoaderContext(); + ~CXFA_LoaderContext(); + + bool m_bSaveLineHeight; + float m_fWidth; + float m_fHeight; + float m_fLastPos; + float m_fStartLineOffset; + int32_t m_iChar; + int32_t m_iLines; + int32_t m_iTotalLines; + uint32_t m_dwFlags; + CFX_XMLNode* m_pXMLNode; + CXFA_Node* m_pNode; + CFX_RetainPtr m_pParentStyle; + std::vector m_lineHeights; + std::vector m_BlocksHeight; +}; + +#endif // XFA_FXFA_CXFA_LOADERCONTEXT_H_ diff --git a/xfa/fxfa/cxfa_pieceline.cpp b/xfa/fxfa/cxfa_pieceline.cpp new file mode 100644 index 0000000000..6570ad59ec --- /dev/null +++ b/xfa/fxfa/cxfa_pieceline.cpp @@ -0,0 +1,13 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_pieceline.h" + +#include "xfa/fxfa/cxfa_textpiece.h" + +CXFA_PieceLine::CXFA_PieceLine() {} + +CXFA_PieceLine::~CXFA_PieceLine() {} diff --git a/xfa/fxfa/cxfa_pieceline.h b/xfa/fxfa/cxfa_pieceline.h new file mode 100644 index 0000000000..82af0e5265 --- /dev/null +++ b/xfa/fxfa/cxfa_pieceline.h @@ -0,0 +1,26 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_PIECELINE_H_ +#define XFA_FXFA_CXFA_PIECELINE_H_ + +#include +#include + +#include "core/fxcrt/fx_basic.h" + +class CXFA_TextPiece; + +class CXFA_PieceLine { + public: + CXFA_PieceLine(); + ~CXFA_PieceLine(); + + std::vector> m_textPieces; + std::vector m_charCounts; +}; + +#endif // XFA_FXFA_CXFA_PIECELINE_H_ diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp new file mode 100644 index 0000000000..138587c2fc --- /dev/null +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -0,0 +1,1304 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_textlayout.h" + +#include +#include + +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlnode.h" +#include "core/fxcrt/xml/cfx_xmltext.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" +#include "xfa/fde/cfde_brush.h" +#include "xfa/fde/cfde_path.h" +#include "xfa/fde/cfde_pen.h" +#include "xfa/fde/cfde_renderdevice.h" +#include "xfa/fde/css/cfde_csscomputedstyle.h" +#include "xfa/fde/css/cfde_cssstyleselector.h" +#include "xfa/fxfa/cxfa_linkuserdata.h" +#include "xfa/fxfa/cxfa_loadercontext.h" +#include "xfa/fxfa/cxfa_pieceline.h" +#include "xfa/fxfa/cxfa_textparsecontext.h" +#include "xfa/fxfa/cxfa_textpiece.h" +#include "xfa/fxfa/cxfa_textprovider.h" +#include "xfa/fxfa/cxfa_texttabstopscontext.h" +#include "xfa/fxfa/cxfa_textuserdata.h" +#include "xfa/fxfa/parser/cxfa_font.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_para.h" + +#define XFA_LOADERCNTXTFLG_FILTERSPACE 0x001 + +CXFA_TextLayout::CXFA_TextLayout(CXFA_TextProvider* pTextProvider) + : m_bHasBlock(false), + m_pTextProvider(pTextProvider), + m_pTextDataNode(nullptr), + m_bRichText(false), + m_iLines(0), + m_fMaxWidth(0), + m_bBlockContinue(true) { + ASSERT(m_pTextProvider); +} + +CXFA_TextLayout::~CXFA_TextLayout() { + m_textParser.Reset(); + Unload(); +} + +void CXFA_TextLayout::Unload() { + m_pieceLines.clear(); + m_pBreak.reset(); +} + +void CXFA_TextLayout::GetTextDataNode() { + if (!m_pTextProvider) + return; + + CXFA_Node* pNode = m_pTextProvider->GetTextNode(m_bRichText); + if (pNode && m_bRichText) + m_textParser.Reset(); + + m_pTextDataNode = pNode; +} + +CFX_XMLNode* CXFA_TextLayout::GetXMLContainerNode() { + if (!m_bRichText) + return nullptr; + + CFX_XMLNode* pXMLRoot = m_pTextDataNode->GetXMLMappingNode(); + if (!pXMLRoot) + return nullptr; + + CFX_XMLNode* pXMLContainer = nullptr; + for (CFX_XMLNode* pXMLChild = pXMLRoot->GetNodeItem(CFX_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (pXMLChild->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pXMLElement = static_cast(pXMLChild); + CFX_WideString wsTag = pXMLElement->GetLocalTagName(); + if (wsTag == L"body" || wsTag == L"html") { + pXMLContainer = pXMLChild; + break; + } + } + } + return pXMLContainer; +} + +std::unique_ptr CXFA_TextLayout::CreateBreak(bool bDefault) { + uint32_t dwStyle = FX_LAYOUTSTYLE_ExpandTab; + if (!bDefault) + dwStyle |= FX_LAYOUTSTYLE_Pagination; + + auto pBreak = pdfium::MakeUnique(dwStyle); + pBreak->SetLineBreakTolerance(1); + pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, nullptr)); + pBreak->SetFontSize(m_textParser.GetFontSize(m_pTextProvider, nullptr)); + return pBreak; +} + +void CXFA_TextLayout::InitBreak(float fLineWidth) { + CXFA_Font font = m_pTextProvider->GetFontNode(); + CXFA_Para para = m_pTextProvider->GetParaNode(); + float fStart = 0; + float fStartPos = 0; + if (para) { + CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + iAlign = CFX_RTFLineAlignment::Center; + break; + case XFA_ATTRIBUTEENUM_Right: + iAlign = CFX_RTFLineAlignment::Right; + break; + case XFA_ATTRIBUTEENUM_Justify: + iAlign = CFX_RTFLineAlignment::Justified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + iAlign = CFX_RTFLineAlignment::Distributed; + break; + } + m_pBreak->SetAlignment(iAlign); + + fStart = para.GetMarginLeft(); + if (m_pTextProvider->IsCheckButtonAndAutoWidth()) { + if (iAlign != CFX_RTFLineAlignment::Left) + fLineWidth -= para.GetMarginRight(); + } else { + fLineWidth -= para.GetMarginRight(); + } + if (fLineWidth < 0) + fLineWidth = fStart; + + fStartPos = fStart; + float fIndent = para.GetTextIndent(); + if (fIndent > 0) + fStartPos += fIndent; + } + + m_pBreak->SetLineBoundary(fStart, fLineWidth); + m_pBreak->SetLineStartPos(fStartPos); + if (font) { + m_pBreak->SetHorizontalScale((int32_t)font.GetHorizontalScale()); + m_pBreak->SetVerticalScale((int32_t)font.GetVerticalScale()); + m_pBreak->SetCharSpace(font.GetLetterSpacing()); + } + + float fFontSize = m_textParser.GetFontSize(m_pTextProvider, nullptr); + m_pBreak->SetFontSize(fFontSize); + m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, nullptr)); + m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); +} + +void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, + FDE_CSSDisplay eDisplay, + float fLineWidth, + CFX_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle) { + if (!pStyle) { + InitBreak(fLineWidth); + return; + } + + if (eDisplay == FDE_CSSDisplay::Block || + eDisplay == FDE_CSSDisplay::ListItem) { + CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; + switch (pStyle->GetTextAlign()) { + case FDE_CSSTextAlign::Right: + iAlign = CFX_RTFLineAlignment::Right; + break; + case FDE_CSSTextAlign::Center: + iAlign = CFX_RTFLineAlignment::Center; + break; + case FDE_CSSTextAlign::Justify: + iAlign = CFX_RTFLineAlignment::Justified; + break; + case FDE_CSSTextAlign::JustifyAll: + iAlign = CFX_RTFLineAlignment::Distributed; + break; + default: + break; + } + m_pBreak->SetAlignment(iAlign); + + float fStart = 0; + const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); + const FDE_CSSRect* pPaddingRect = pStyle->GetPaddingWidth(); + if (pRect) { + fStart = pRect->left.GetValue(); + fLineWidth -= pRect->right.GetValue(); + if (pPaddingRect) { + fStart += pPaddingRect->left.GetValue(); + fLineWidth -= pPaddingRect->right.GetValue(); + } + if (eDisplay == FDE_CSSDisplay::ListItem) { + const FDE_CSSRect* pParRect = pParentStyle->GetMarginWidth(); + const FDE_CSSRect* pParPaddingRect = pParentStyle->GetPaddingWidth(); + if (pParRect) { + fStart += pParRect->left.GetValue(); + fLineWidth -= pParRect->right.GetValue(); + if (pParPaddingRect) { + fStart += pParPaddingRect->left.GetValue(); + fLineWidth -= pParPaddingRect->right.GetValue(); + } + } + FDE_CSSRect pNewRect; + pNewRect.left.Set(FDE_CSSLengthUnit::Point, fStart); + pNewRect.right.Set(FDE_CSSLengthUnit::Point, pRect->right.GetValue()); + pNewRect.top.Set(FDE_CSSLengthUnit::Point, pRect->top.GetValue()); + pNewRect.bottom.Set(FDE_CSSLengthUnit::Point, pRect->bottom.GetValue()); + pStyle->SetMarginWidth(pNewRect); + } + } + m_pBreak->SetLineBoundary(fStart, fLineWidth); + float fIndent = pStyle->GetTextIndent().GetValue(); + if (fIndent > 0) + fStart += fIndent; + + m_pBreak->SetLineStartPos(fStart); + m_pBreak->SetTabWidth(m_textParser.GetTabInterval(pStyle)); + if (!m_pTabstopContext) + m_pTabstopContext = pdfium::MakeUnique(); + m_textParser.GetTabstops(pStyle, m_pTabstopContext.get()); + for (const auto& stop : m_pTabstopContext->m_tabstops) + m_pBreak->AddPositionedTab(stop.fTabstops); + } + float fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle); + m_pBreak->SetFontSize(fFontSize); + m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); + m_pBreak->SetFont(m_textParser.GetFont(m_pTextProvider, pStyle)); + m_pBreak->SetHorizontalScale( + m_textParser.GetHorScale(m_pTextProvider, pStyle, pXMLNode)); + m_pBreak->SetVerticalScale(m_textParser.GetVerScale(m_pTextProvider, pStyle)); + m_pBreak->SetCharSpace(pStyle->GetLetterSpacing().GetValue()); +} + +int32_t CXFA_TextLayout::GetText(CFX_WideString& wsText) { + GetTextDataNode(); + wsText.clear(); + if (!m_bRichText) + wsText = m_pTextDataNode->GetContent(); + return wsText.GetLength(); +} + +float CXFA_TextLayout::GetLayoutHeight() { + if (!m_pLoader) + return 0; + + if (m_pLoader->m_lineHeights.empty() && m_pLoader->m_fWidth > 0) { + CFX_SizeF szMax(m_pLoader->m_fWidth, m_pLoader->m_fHeight); + CFX_SizeF szDef; + m_pLoader->m_bSaveLineHeight = true; + m_pLoader->m_fLastPos = 0; + CalcSize(szMax, szMax, szDef); + m_pLoader->m_bSaveLineHeight = false; + return szDef.height; + } + + float fHeight = m_pLoader->m_fHeight; + if (fHeight < 0.1f) { + fHeight = 0; + for (float value : m_pLoader->m_lineHeights) + fHeight += value; + } + return fHeight; +} + +float CXFA_TextLayout::StartLayout(float fWidth) { + if (!m_pLoader) + m_pLoader = pdfium::MakeUnique(); + + if (fWidth < 0 || + (m_pLoader->m_fWidth > -1 && fabs(fWidth - m_pLoader->m_fWidth) > 0)) { + m_pLoader->m_lineHeights.clear(); + m_Blocks.clear(); + Unload(); + m_pLoader->m_fStartLineOffset = 0; + } + m_pLoader->m_fWidth = fWidth; + + if (fWidth < 0) { + CFX_SizeF szMax; + CFX_SizeF szDef; + m_pLoader->m_bSaveLineHeight = true; + m_pLoader->m_fLastPos = 0; + CalcSize(szMax, szMax, szDef); + m_pLoader->m_bSaveLineHeight = false; + fWidth = szDef.width; + } + return fWidth; +} + +bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, + float& fCalcHeight, + float fContentAreaHeight, + float fTextHeight) { + if (!m_pLoader) + return false; + + int32_t iBlockCount = pdfium::CollectionSize(m_Blocks); + float fHeight = fTextHeight; + if (fHeight < 0) + fHeight = GetLayoutHeight(); + + m_pLoader->m_fHeight = fHeight; + if (fContentAreaHeight < 0) + return false; + + m_bHasBlock = true; + if (iBlockCount == 0 && fHeight > 0) { + fHeight = fTextHeight - GetLayoutHeight(); + if (fHeight > 0) { + int32_t iAlign = m_textParser.GetVAlign(m_pTextProvider); + if (iAlign == XFA_ATTRIBUTEENUM_Middle) + fHeight /= 2.0f; + else if (iAlign != XFA_ATTRIBUTEENUM_Bottom) + fHeight = 0; + m_pLoader->m_fStartLineOffset = fHeight; + } + } + + float fLinePos = m_pLoader->m_fStartLineOffset; + int32_t iLineIndex = 0; + if (iBlockCount > 1) { + if (iBlockCount >= (iBlockIndex + 1) * 2) { + iLineIndex = m_Blocks[iBlockIndex * 2]; + } else { + iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; + } + if (!m_pLoader->m_BlocksHeight.empty()) { + for (int32_t i = 0; i < iBlockIndex; i++) + fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; + } + } + + int32_t iCount = pdfium::CollectionSize(m_pLoader->m_lineHeights); + int32_t i = 0; + for (i = iLineIndex; i < iCount; i++) { + float fLineHeight = m_pLoader->m_lineHeights[i]; + if (i == iLineIndex && fLineHeight - fContentAreaHeight > 0.001) { + fCalcHeight = 0; + return true; + } + if (fLinePos + fLineHeight - fContentAreaHeight > 0.001) { + if (iBlockCount >= (iBlockIndex + 1) * 2) { + m_Blocks[iBlockIndex * 2] = iLineIndex; + m_Blocks[iBlockIndex * 2 + 1] = i - iLineIndex; + } else { + m_Blocks.push_back(iLineIndex); + m_Blocks.push_back(i - iLineIndex); + } + if (i == iLineIndex) { + if (fCalcHeight <= fLinePos) { + if (pdfium::CollectionSize(m_pLoader->m_BlocksHeight) > + iBlockIndex * 2 && + (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { + m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; + } else { + m_pLoader->m_BlocksHeight.push_back((float)iBlockIndex); + m_pLoader->m_BlocksHeight.push_back(fCalcHeight); + } + } + return true; + } + + fCalcHeight = fLinePos; + return true; + } + fLinePos += fLineHeight; + } + return false; +} + +int32_t CXFA_TextLayout::CountBlocks() const { + int32_t iCount = pdfium::CollectionSize(m_Blocks) / 2; + return iCount > 0 ? iCount : 1; +} + +bool CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize, + const CFX_SizeF& maxSize, + CFX_SizeF& defaultSize) { + defaultSize.width = maxSize.width; + if (defaultSize.width < 1) + defaultSize.width = 0xFFFF; + + m_pBreak = CreateBreak(false); + float fLinePos = 0; + m_iLines = 0; + m_fMaxWidth = 0; + Loader(defaultSize, fLinePos, false); + if (fLinePos < 0.1f) + fLinePos = m_textParser.GetFontSize(m_pTextProvider, nullptr); + + m_pTabstopContext.reset(); + defaultSize = CFX_SizeF(m_fMaxWidth, fLinePos); + return true; +} + +bool CXFA_TextLayout::Layout(const CFX_SizeF& size, float* fHeight) { + if (size.width < 1) + return false; + + Unload(); + m_pBreak = CreateBreak(true); + if (m_pLoader) { + m_pLoader->m_iTotalLines = -1; + m_pLoader->m_iChar = 0; + } + + m_iLines = 0; + float fLinePos = 0; + Loader(size, fLinePos, true); + UpdateAlign(size.height, fLinePos); + m_pTabstopContext.reset(); + if (fHeight) + *fHeight = fLinePos; + return true; +} + +bool CXFA_TextLayout::Layout(int32_t iBlock) { + if (!m_pLoader || iBlock < 0 || iBlock >= CountBlocks()) + return false; + if (m_pLoader->m_fWidth < 1) + return false; + + m_pLoader->m_iTotalLines = -1; + m_iLines = 0; + float fLinePos = 0; + CXFA_Node* pNode = nullptr; + CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); + int32_t iCount = pdfium::CollectionSize(m_Blocks); + int32_t iBlocksHeightCount = + pdfium::CollectionSize(m_pLoader->m_BlocksHeight); + iBlocksHeightCount /= 2; + if (iBlock < iBlocksHeightCount) + return true; + if (iBlock == iBlocksHeightCount) { + Unload(); + m_pBreak = CreateBreak(true); + fLinePos = m_pLoader->m_fStartLineOffset; + for (int32_t i = 0; i < iBlocksHeightCount; i++) + fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; + + m_pLoader->m_iChar = 0; + if (iCount > 1) + m_pLoader->m_iTotalLines = m_Blocks[iBlock * 2 + 1]; + + Loader(szText, fLinePos, true); + if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) + UpdateAlign(szText.height, fLinePos); + } else if (m_pTextDataNode) { + iBlock *= 2; + if (iBlock < iCount - 2) + m_pLoader->m_iTotalLines = m_Blocks[iBlock + 1]; + + m_pBreak->Reset(); + if (m_bRichText) { + CFX_XMLNode* pContainerNode = GetXMLContainerNode(); + if (!pContainerNode) + return true; + + CFX_XMLNode* pXMLNode = m_pLoader->m_pXMLNode; + if (!pXMLNode) + return true; + + CFX_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; + for (; pXMLNode; + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, + true, nullptr)) { + break; + } + } + while (!pXMLNode) { + pXMLNode = pSaveXMLNode->GetNodeItem(CFX_XMLNode::Parent); + if (pXMLNode == pContainerNode) + break; + if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, + true, nullptr, false)) { + break; + } + pSaveXMLNode = pXMLNode; + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling); + if (!pXMLNode) + continue; + for (; pXMLNode; + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (!LoadRichText(pXMLNode, szText, fLinePos, + m_pLoader->m_pParentStyle, true, nullptr)) { + break; + } + } + } + } else { + pNode = m_pLoader->m_pNode; + if (!pNode) + return true; + LoadText(pNode, szText, fLinePos, true); + } + } + if (iBlock == iCount) { + m_pTabstopContext.reset(); + m_pLoader.reset(); + } + return true; +} + +void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { + if (!m_pLoader) + return; + + int32_t iCountHeight = + pdfium::CollectionSize(m_pLoader->m_lineHeights); + if (iCountHeight == 0) + return; + + bool bEndItem = true; + int32_t iBlockCount = pdfium::CollectionSize(m_Blocks); + float fLinePos = m_pLoader->m_fStartLineOffset; + int32_t iLineIndex = 0; + if (iBlockIndex > 0) { + int32_t iBlockHeightCount = + pdfium::CollectionSize(m_pLoader->m_BlocksHeight); + iBlockHeightCount /= 2; + if (iBlockHeightCount >= iBlockIndex) { + for (int32_t i = 0; i < iBlockIndex; i++) + fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; + } else { + fLinePos = 0; + } + iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; + } + + int32_t i = 0; + for (i = iLineIndex; i < iCountHeight; i++) { + float fLineHeight = m_pLoader->m_lineHeights[i]; + if (fLinePos + fLineHeight - rtText.height > 0.001) { + m_Blocks.push_back(iLineIndex); + m_Blocks.push_back(i - iLineIndex); + bEndItem = false; + break; + } + fLinePos += fLineHeight; + } + if (iCountHeight > 0 && (i - iLineIndex) > 0 && bEndItem) { + m_Blocks.push_back(iLineIndex); + m_Blocks.push_back(i - iLineIndex); + } +} + +bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, + const CFX_Matrix& tmDoc2Device, + const CFX_RectF& rtClip, + int32_t iBlock) { + if (!pFxDevice) + return false; + + auto pDevice = pdfium::MakeUnique(pFxDevice); + pDevice->SaveState(); + pDevice->SetClipRect(rtClip); + + auto pSolidBrush = pdfium::MakeUnique(); + auto pPen = pdfium::MakeUnique(); + if (m_pieceLines.empty()) { + int32_t iBlockCount = CountBlocks(); + for (int32_t i = 0; i < iBlockCount; i++) + Layout(i); + } + + FXTEXT_CHARPOS* pCharPos = nullptr; + int32_t iCharCount = 0; + int32_t iLineStart = 0; + int32_t iPieceLines = pdfium::CollectionSize(m_pieceLines); + int32_t iCount = pdfium::CollectionSize(m_Blocks); + if (iCount > 0) { + iBlock *= 2; + if (iBlock < iCount) { + iLineStart = m_Blocks[iBlock]; + iPieceLines = m_Blocks[iBlock + 1]; + } else { + iPieceLines = 0; + } + } + + for (int32_t i = 0; i < iPieceLines; i++) { + if (i + iLineStart >= pdfium::CollectionSize(m_pieceLines)) + break; + + CXFA_PieceLine* pPieceLine = m_pieceLines[i + iLineStart].get(); + int32_t iPieces = pdfium::CollectionSize(pPieceLine->m_textPieces); + int32_t j = 0; + for (j = 0; j < iPieces; j++) { + const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[j].get(); + int32_t iChars = pPiece->iChars; + if (iCharCount < iChars) { + FX_Free(pCharPos); + pCharPos = FX_Alloc(FXTEXT_CHARPOS, iChars); + iCharCount = iChars; + } + memset(pCharPos, 0, iCharCount * sizeof(FXTEXT_CHARPOS)); + RenderString(pDevice.get(), pSolidBrush.get(), pPieceLine, j, pCharPos, + tmDoc2Device); + } + for (j = 0; j < iPieces; j++) { + RenderPath(pDevice.get(), pPen.get(), pPieceLine, j, pCharPos, + tmDoc2Device); + } + } + pDevice->RestoreState(); + FX_Free(pCharPos); + return iPieceLines > 0; +} + +void CXFA_TextLayout::UpdateAlign(float fHeight, float fBottom) { + fHeight -= fBottom; + if (fHeight < 0.1f) + return; + + switch (m_textParser.GetVAlign(m_pTextProvider)) { + case XFA_ATTRIBUTEENUM_Middle: + fHeight /= 2.0f; + break; + case XFA_ATTRIBUTEENUM_Bottom: + break; + default: + return; + } + + for (const auto& pPieceLine : m_pieceLines) { + for (const auto& pPiece : pPieceLine->m_textPieces) + pPiece->rtPiece.top += fHeight; + } +} + +bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, + float& fLinePos, + bool bSavePieces) { + GetTextDataNode(); + if (!m_pTextDataNode) + return true; + + if (m_bRichText) { + CFX_XMLNode* pXMLContainer = GetXMLContainerNode(); + if (pXMLContainer) { + if (!m_textParser.IsParsed()) + m_textParser.DoParse(pXMLContainer, m_pTextProvider); + + auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider); + LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces, + nullptr); + } + } else { + LoadText(m_pTextDataNode, szText, fLinePos, bSavePieces); + } + return true; +} + +void CXFA_TextLayout::LoadText(CXFA_Node* pNode, + const CFX_SizeF& szText, + float& fLinePos, + bool bSavePieces) { + InitBreak(szText.width); + + CXFA_Para para = m_pTextProvider->GetParaNode(); + float fSpaceAbove = 0; + if (para) { + fSpaceAbove = para.GetSpaceAbove(); + if (fSpaceAbove < 0.1f) { + fSpaceAbove = 0; + } + int32_t verAlign = para.GetVerticalAlign(); + switch (verAlign) { + case XFA_ATTRIBUTEENUM_Top: + case XFA_ATTRIBUTEENUM_Middle: + case XFA_ATTRIBUTEENUM_Bottom: { + fLinePos += fSpaceAbove; + break; + } + } + } + + CFX_WideString wsText = pNode->GetContent(); + wsText.TrimRight(L" "); + bool bRet = AppendChar(wsText, fLinePos, fSpaceAbove, bSavePieces); + if (bRet && m_pLoader) + m_pLoader->m_pNode = pNode; + else + EndBreak(CFX_BreakType::Paragraph, fLinePos, bSavePieces); +} + +bool CXFA_TextLayout::LoadRichText( + CFX_XMLNode* pXMLNode, + const CFX_SizeF& szText, + float& fLinePos, + const CFX_RetainPtr& pParentStyle, + bool bSavePieces, + CFX_RetainPtr pLinkData, + bool bEndBreak, + bool bIsOl, + int32_t iLiCount) { + if (!pXMLNode) + return false; + + CXFA_TextParseContext* pContext = + m_textParser.GetParseContextFromMap(pXMLNode); + FDE_CSSDisplay eDisplay = FDE_CSSDisplay::None; + bool bContentNode = false; + float fSpaceBelow = 0; + CFX_RetainPtr pStyle; + CFX_WideString wsName; + if (bEndBreak) { + bool bCurOl = false; + bool bCurLi = false; + CFX_XMLElement* pElement = nullptr; + if (pContext) { + if (m_bBlockContinue || + (m_pLoader && pXMLNode == m_pLoader->m_pXMLNode)) { + m_bBlockContinue = true; + } + if (pXMLNode->GetType() == FX_XMLNODE_Text) { + bContentNode = true; + } else if (pXMLNode->GetType() == FX_XMLNODE_Element) { + pElement = static_cast(pXMLNode); + wsName = pElement->GetLocalTagName(); + } + if (wsName == L"ol") { + bIsOl = true; + bCurOl = true; + } + if (m_bBlockContinue || bContentNode == false) { + eDisplay = pContext->GetDisplay(); + if (eDisplay != FDE_CSSDisplay::Block && + eDisplay != FDE_CSSDisplay::Inline && + eDisplay != FDE_CSSDisplay::ListItem) { + return true; + } + + pStyle = m_textParser.ComputeStyle(pXMLNode, pParentStyle.Get()); + InitBreak(bContentNode ? pParentStyle.Get() : pStyle.Get(), eDisplay, + szText.width, pXMLNode, pParentStyle.Get()); + if ((eDisplay == FDE_CSSDisplay::Block || + eDisplay == FDE_CSSDisplay::ListItem) && + pStyle && + (wsName.IsEmpty() || (wsName != L"body" && wsName != L"html" && + wsName != L"ol" && wsName != L"ul"))) { + const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); + if (pRect) { + fLinePos += pRect->top.GetValue(); + fSpaceBelow = pRect->bottom.GetValue(); + } + } + + if (wsName == L"a") { + ASSERT(pElement); + CFX_WideString wsLinkContent = pElement->GetString(L"href"); + if (!wsLinkContent.IsEmpty()) { + pLinkData = pdfium::MakeRetain( + wsLinkContent.GetBuffer(wsLinkContent.GetLength())); + wsLinkContent.ReleaseBuffer(wsLinkContent.GetLength()); + } + } + + int32_t iTabCount = m_textParser.CountTabs( + bContentNode ? pParentStyle.Get() : pStyle.Get()); + bool bSpaceRun = m_textParser.IsSpaceRun( + bContentNode ? pParentStyle.Get() : pStyle.Get()); + CFX_WideString wsText; + if (bContentNode && iTabCount == 0) { + wsText = static_cast(pXMLNode)->GetText(); + } else if (wsName == L"br") { + wsText = L'\n'; + } else if (wsName == L"li") { + bCurLi = true; + if (bIsOl) + wsText.Format(L"%d. ", iLiCount); + else + wsText = 0x00B7 + CFX_WideStringC(L" ", 1); + } else if (!bContentNode) { + if (iTabCount > 0) { + while (iTabCount-- > 0) + wsText += L'\t'; + } else { + m_textParser.GetEmbbedObj(m_pTextProvider, pXMLNode, wsText); + } + } + + int32_t iLength = wsText.GetLength(); + if (iLength > 0 && bContentNode && !bSpaceRun) + ProcessText(wsText); + + if (m_pLoader) { + if (wsText.GetLength() > 0 && + (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { + wsText.TrimLeft(0x20); + } + if (FDE_CSSDisplay::Block == eDisplay) { + m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; + } else if (FDE_CSSDisplay::Inline == eDisplay && + (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { + m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; + } else if (wsText.GetLength() > 0 && + (0x20 == wsText.GetAt(wsText.GetLength() - 1))) { + m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; + } else if (wsText.GetLength() != 0) { + m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; + } + } + + if (wsText.GetLength() > 0) { + if (!m_pLoader || m_pLoader->m_iChar == 0) { + auto pUserData = pdfium::MakeRetain( + bContentNode ? pParentStyle : pStyle, pLinkData); + m_pBreak->SetUserData(pUserData); + } + + if (AppendChar(wsText, fLinePos, 0, bSavePieces)) { + if (m_pLoader) + m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; + if (IsEnd(bSavePieces)) { + if (m_pLoader && m_pLoader->m_iTotalLines > -1) { + m_pLoader->m_pXMLNode = pXMLNode; + m_pLoader->m_pParentStyle = pParentStyle; + } + return false; + } + return true; + } + } + } + } + + for (CFX_XMLNode* pChildNode = + pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); + pChildNode; + pChildNode = pChildNode->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (bCurOl) + iLiCount++; + + if (!LoadRichText(pChildNode, szText, fLinePos, + pContext ? pStyle : pParentStyle, bSavePieces, + pLinkData, true, bIsOl, iLiCount)) + return false; + } + + if (m_pLoader) { + if (FDE_CSSDisplay::Block == eDisplay) + m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; + } + if (bCurLi) + EndBreak(CFX_BreakType::Line, fLinePos, bSavePieces); + } else { + if (pContext) + eDisplay = pContext->GetDisplay(); + } + + if (m_bBlockContinue) { + if (pContext && !bContentNode) { + CFX_BreakType dwStatus = (eDisplay == FDE_CSSDisplay::Block) + ? CFX_BreakType::Paragraph + : CFX_BreakType::Piece; + EndBreak(dwStatus, fLinePos, bSavePieces); + if (eDisplay == FDE_CSSDisplay::Block) { + fLinePos += fSpaceBelow; + if (m_pTabstopContext) + m_pTabstopContext->RemoveAll(); + } + if (IsEnd(bSavePieces)) { + if (m_pLoader && m_pLoader->m_iTotalLines > -1) { + m_pLoader->m_pXMLNode = + pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling); + m_pLoader->m_pParentStyle = pParentStyle; + } + return false; + } + } + } + return true; +} + +bool CXFA_TextLayout::AppendChar(const CFX_WideString& wsText, + float& fLinePos, + float fSpaceAbove, + bool bSavePieces) { + CFX_BreakType dwStatus = CFX_BreakType::None; + int32_t iChar = 0; + if (m_pLoader) + iChar = m_pLoader->m_iChar; + + int32_t iLength = wsText.GetLength(); + for (int32_t i = iChar; i < iLength; i++) { + wchar_t wch = wsText.GetAt(i); + if (wch == 0xA0) + wch = 0x20; + + dwStatus = m_pBreak->AppendChar(wch); + if (dwStatus != CFX_BreakType::None && dwStatus != CFX_BreakType::Piece) { + AppendTextLine(dwStatus, fLinePos, bSavePieces); + if (IsEnd(bSavePieces)) { + if (m_pLoader) + m_pLoader->m_iChar = i; + return true; + } + if (dwStatus == CFX_BreakType::Paragraph && m_bRichText) + fLinePos += fSpaceAbove; + } + } + if (m_pLoader) + m_pLoader->m_iChar = 0; + + return false; +} + +bool CXFA_TextLayout::IsEnd(bool bSavePieces) { + if (!bSavePieces) + return false; + if (m_pLoader && m_pLoader->m_iTotalLines > 0) + return m_iLines >= m_pLoader->m_iTotalLines; + return false; +} + +void CXFA_TextLayout::ProcessText(CFX_WideString& wsText) { + int32_t iLen = wsText.GetLength(); + if (iLen == 0) + return; + + wchar_t* psz = wsText.GetBuffer(iLen); + int32_t iTrimLeft = 0; + wchar_t wch = 0, wPrev = 0; + for (int32_t i = 0; i < iLen; i++) { + wch = psz[i]; + if (wch < 0x20) + wch = 0x20; + if (wch == 0x20 && wPrev == 0x20) + continue; + + wPrev = wch; + psz[iTrimLeft++] = wch; + } + wsText.ReleaseBuffer(iLen); + wsText = wsText.Left(iTrimLeft); +} + +void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, + float& fLinePos, + bool bSavePieces) { + dwStatus = m_pBreak->EndBreak(dwStatus); + if (dwStatus != CFX_BreakType::None && dwStatus != CFX_BreakType::Piece) + AppendTextLine(dwStatus, fLinePos, bSavePieces, true); +} + +void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, + CXFA_PieceLine* pPieceLine) { + if (!pStyle || !pPieceLine) + return; + + if (!m_pTabstopContext || m_pTabstopContext->m_tabstops.empty()) + return; + + int32_t iPieces = pdfium::CollectionSize(pPieceLine->m_textPieces); + if (iPieces == 0) + return; + + CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPieces - 1].get(); + int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; + int32_t iCount = m_textParser.CountTabs(pStyle); + if (!pdfium::IndexInBounds(m_pTabstopContext->m_tabstops, iTabstopsIndex)) + return; + + if (iCount > 0) { + iTabstopsIndex++; + m_pTabstopContext->m_bTabstops = true; + float fRight = 0; + if (iPieces > 1) { + CXFA_TextPiece* p = pPieceLine->m_textPieces[iPieces - 2].get(); + fRight = p->rtPiece.right(); + } + m_pTabstopContext->m_fTabWidth = + pPiece->rtPiece.width + pPiece->rtPiece.left - fRight; + } else if (iTabstopsIndex > -1) { + float fLeft = 0; + if (m_pTabstopContext->m_bTabstops) { + uint32_t dwAlign = m_pTabstopContext->m_tabstops[iTabstopsIndex].dwAlign; + if (dwAlign == FX_HashCode_GetW(L"center", false)) { + fLeft = pPiece->rtPiece.width / 2.0f; + } else if (dwAlign == FX_HashCode_GetW(L"right", false) || + dwAlign == FX_HashCode_GetW(L"before", false)) { + fLeft = pPiece->rtPiece.width; + } else if (dwAlign == FX_HashCode_GetW(L"decimal", false)) { + int32_t iChars = pPiece->iChars; + for (int32_t i = 0; i < iChars; i++) { + if (pPiece->szText[i] == L'.') + break; + + fLeft += pPiece->Widths[i] / 20000.0f; + } + } + m_pTabstopContext->m_fLeft = + std::min(fLeft, m_pTabstopContext->m_fTabWidth); + m_pTabstopContext->m_bTabstops = false; + m_pTabstopContext->m_fTabWidth = 0; + } + pPiece->rtPiece.left -= m_pTabstopContext->m_fLeft; + } +} + +void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, + float& fLinePos, + bool bSavePieces, + bool bEndBreak) { + int32_t iPieces = m_pBreak->CountBreakPieces(); + if (iPieces < 1) + return; + + CFX_RetainPtr pStyle; + if (bSavePieces) { + auto pNew = pdfium::MakeUnique(); + CXFA_PieceLine* pPieceLine = pNew.get(); + m_pieceLines.push_back(std::move(pNew)); + if (m_pTabstopContext) + m_pTabstopContext->Reset(); + + float fLineStep = 0, fBaseLine = 0; + int32_t i = 0; + for (i = 0; i < iPieces; i++) { + const CFX_BreakPiece* pPiece = m_pBreak->GetBreakPieceUnstable(i); + CXFA_TextUserData* pUserData = pPiece->m_pUserData.Get(); + if (pUserData) + pStyle = pUserData->m_pStyle; + float fVerScale = pPiece->m_iVerticalScale / 100.0f; + + auto pTP = pdfium::MakeUnique(); + pTP->iChars = pPiece->m_iChars; + pTP->szText = pPiece->GetString(); + pTP->Widths = pPiece->GetWidths(); + pTP->iBidiLevel = pPiece->m_iBidiLevel; + pTP->iHorScale = pPiece->m_iHorizontalScale; + pTP->iVerScale = pPiece->m_iVerticalScale; + m_textParser.GetUnderline(m_pTextProvider, pStyle.Get(), pTP->iUnderline, + pTP->iPeriod); + m_textParser.GetLinethrough(m_pTextProvider, pStyle.Get(), + pTP->iLineThrough); + pTP->dwColor = m_textParser.GetColor(m_pTextProvider, pStyle.Get()); + pTP->pFont = m_textParser.GetFont(m_pTextProvider, pStyle.Get()); + pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle.Get()); + pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f; + pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f; + pTP->rtPiece.height = (float)pPiece->m_iFontSize * fVerScale / 20.0f; + float fBaseLineTemp = + m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); + pTP->rtPiece.top = fBaseLineTemp; + + float fLineHeight = m_textParser.GetLineHeight( + m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); + if (fBaseLineTemp > 0) { + float fLineHeightTmp = fBaseLineTemp + pTP->rtPiece.height; + if (fLineHeight < fLineHeightTmp) + fLineHeight = fLineHeightTmp; + else + fBaseLineTemp = 0; + } else if (fBaseLine < -fBaseLineTemp) { + fBaseLine = -fBaseLineTemp; + } + fLineStep = std::max(fLineStep, fLineHeight); + pTP->pLinkData = pUserData ? pUserData->m_pLinkData : nullptr; + pPieceLine->m_textPieces.push_back(std::move(pTP)); + DoTabstops(pStyle.Get(), pPieceLine); + } + for (const auto& pTP : pPieceLine->m_textPieces) { + float& fTop = pTP->rtPiece.top; + float fBaseLineTemp = fTop; + fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp; + fTop = std::max(0.0f, fTop); + } + fLinePos += fLineStep + fBaseLine; + } else { + float fLineStep = 0; + float fLineWidth = 0; + for (int32_t i = 0; i < iPieces; i++) { + const CFX_BreakPiece* pPiece = m_pBreak->GetBreakPieceUnstable(i); + CXFA_TextUserData* pUserData = pPiece->m_pUserData.Get(); + if (pUserData) + pStyle = pUserData->m_pStyle; + float fVerScale = pPiece->m_iVerticalScale / 100.0f; + float fBaseLine = m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); + float fLineHeight = m_textParser.GetLineHeight( + m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); + if (fBaseLine > 0) { + float fLineHeightTmp = + fBaseLine + (float)pPiece->m_iFontSize * fVerScale / 20.0f; + if (fLineHeight < fLineHeightTmp) { + fLineHeight = fLineHeightTmp; + } + } + fLineStep = std::max(fLineStep, fLineHeight); + fLineWidth += pPiece->m_iWidth / 20000.0f; + } + fLinePos += fLineStep; + m_fMaxWidth = std::max(m_fMaxWidth, fLineWidth); + if (m_pLoader && m_pLoader->m_bSaveLineHeight) { + float fHeight = fLinePos - m_pLoader->m_fLastPos; + m_pLoader->m_fLastPos = fLinePos; + m_pLoader->m_lineHeights.push_back(fHeight); + } + } + + m_pBreak->ClearBreakPieces(); + if (dwStatus == CFX_BreakType::Paragraph) { + m_pBreak->Reset(); + if (!pStyle && bEndBreak) { + CXFA_Para para = m_pTextProvider->GetParaNode(); + if (para) { + float fStartPos = para.GetMarginLeft(); + float fIndent = para.GetTextIndent(); + if (fIndent > 0) + fStartPos += fIndent; + + float fSpaceBelow = para.GetSpaceBelow(); + if (fSpaceBelow < 0.1f) + fSpaceBelow = 0; + + m_pBreak->SetLineStartPos(fStartPos); + fLinePos += fSpaceBelow; + } + } + } + + if (pStyle) { + float fStart = 0; + const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); + if (pRect) + fStart = pRect->left.GetValue(); + + float fTextIndent = pStyle->GetTextIndent().GetValue(); + if (fTextIndent < 0) + fStart -= fTextIndent; + + m_pBreak->SetLineStartPos(fStart); + } + m_iLines++; +} + +void CXFA_TextLayout::RenderString(CFDE_RenderDevice* pDevice, + CFDE_Brush* pBrush, + CXFA_PieceLine* pPieceLine, + int32_t iPiece, + FXTEXT_CHARPOS* pCharPos, + const CFX_Matrix& tmDoc2Device) { + const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); + int32_t iCount = GetDisplayPos(pPiece, pCharPos); + if (iCount > 0) { + pBrush->SetColor(pPiece->dwColor); + pDevice->DrawString(pBrush, pPiece->pFont, pCharPos, iCount, + pPiece->fFontSize, &tmDoc2Device); + } + pPieceLine->m_charCounts.push_back(iCount); +} + +void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice, + CFDE_Pen* pPen, + CXFA_PieceLine* pPieceLine, + int32_t iPiece, + FXTEXT_CHARPOS* pCharPos, + const CFX_Matrix& tmDoc2Device) { + CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get(); + bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2; + bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; + if (bNoUnderline && bNoLineThrough) + return; + + pPen->SetColor(pPiece->dwColor); + auto pPath = pdfium::MakeUnique(); + int32_t iChars = GetDisplayPos(pPiece, pCharPos); + if (iChars > 0) { + CFX_PointF pt1, pt2; + float fEndY = pCharPos[0].m_Origin.y + 1.05f; + if (pPiece->iPeriod == XFA_ATTRIBUTEENUM_Word) { + for (int32_t i = 0; i < pPiece->iUnderline; i++) { + for (int32_t j = 0; j < iChars; j++) { + pt1.x = pCharPos[j].m_Origin.x; + pt2.x = + pt1.x + pCharPos[j].m_FontCharWidth * pPiece->fFontSize / 1000.0f; + pt1.y = pt2.y = fEndY; + pPath->AddLine(pt1, pt2); + } + fEndY += 2.0f; + } + } else { + pt1.x = pCharPos[0].m_Origin.x; + pt2.x = + pCharPos[iChars - 1].m_Origin.x + + pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; + for (int32_t i = 0; i < pPiece->iUnderline; i++) { + pt1.y = pt2.y = fEndY; + pPath->AddLine(pt1, pt2); + fEndY += 2.0f; + } + } + fEndY = pCharPos[0].m_Origin.y - pPiece->rtPiece.height * 0.25f; + pt1.x = pCharPos[0].m_Origin.x; + pt2.x = pCharPos[iChars - 1].m_Origin.x + + pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; + for (int32_t i = 0; i < pPiece->iLineThrough; i++) { + pt1.y = pt2.y = fEndY; + pPath->AddLine(pt1, pt2); + fEndY += 2.0f; + } + } else { + if (bNoLineThrough && + (bNoUnderline || pPiece->iPeriod != XFA_ATTRIBUTEENUM_All)) { + return; + } + int32_t iCharsTmp = 0; + int32_t iPiecePrev = iPiece; + int32_t iPieceNext = iPiece; + while (iPiecePrev > 0) { + iPiecePrev--; + iCharsTmp = pPieceLine->m_charCounts[iPiecePrev]; + if (iCharsTmp > 0) + break; + } + if (iCharsTmp == 0) + return; + + iCharsTmp = 0; + int32_t iPieces = pdfium::CollectionSize(pPieceLine->m_textPieces); + while (iPieceNext < iPieces - 1) { + iPieceNext++; + iCharsTmp = pPieceLine->m_charCounts[iPieceNext]; + if (iCharsTmp > 0) + break; + } + if (iCharsTmp == 0) + return; + + float fOrgX = 0.0f; + float fEndX = 0.0f; + pPiece = pPieceLine->m_textPieces[iPiecePrev].get(); + iChars = GetDisplayPos(pPiece, pCharPos); + if (iChars < 1) + return; + + fOrgX = pCharPos[iChars - 1].m_Origin.x + + pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f; + pPiece = pPieceLine->m_textPieces[iPieceNext].get(); + iChars = GetDisplayPos(pPiece, pCharPos); + if (iChars < 1) + return; + + fEndX = pCharPos[0].m_Origin.x; + CFX_PointF pt1; + CFX_PointF pt2; + pt1.x = fOrgX; + pt2.x = fEndX; + float fEndY = pCharPos[0].m_Origin.y + 1.05f; + for (int32_t i = 0; i < pPiece->iUnderline; i++) { + pt1.y = fEndY; + pt2.y = fEndY; + pPath->AddLine(pt1, pt2); + fEndY += 2.0f; + } + fEndY = pCharPos[0].m_Origin.y - pPiece->rtPiece.height * 0.25f; + for (int32_t i = 0; i < pPiece->iLineThrough; i++) { + pt1.y = fEndY; + pt2.y = fEndY; + pPath->AddLine(pt1, pt2); + fEndY += 2.0f; + } + } + pDevice->DrawPath(pPen, 1, pPath.get(), &tmDoc2Device); +} + +int32_t CXFA_TextLayout::GetDisplayPos(const CXFA_TextPiece* pPiece, + FXTEXT_CHARPOS* pCharPos, + bool bCharCode) { + if (!pPiece) + return 0; + + FX_RTFTEXTOBJ tr; + if (!ToRun(pPiece, &tr)) + return 0; + return m_pBreak->GetDisplayPos(&tr, pCharPos, bCharCode); +} + +bool CXFA_TextLayout::ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr) { + int32_t iLength = pPiece->iChars; + if (iLength < 1) + return false; + + tr->pStr = pPiece->szText; + tr->pFont = pPiece->pFont; + tr->pRect = &pPiece->rtPiece; + tr->pWidths = pPiece->Widths; + tr->iLength = iLength; + tr->fFontSize = pPiece->fFontSize; + tr->iBidiLevel = pPiece->iBidiLevel; + tr->wLineBreakChar = L'\n'; + tr->iVerticalScale = pPiece->iVerScale; + tr->iHorizontalScale = pPiece->iHorScale; + return true; +} diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h new file mode 100644 index 0000000000..079fff8fe2 --- /dev/null +++ b/xfa/fxfa/cxfa_textlayout.h @@ -0,0 +1,136 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTLAYOUT_H_ +#define XFA_FXFA_CXFA_TEXTLAYOUT_H_ + +#include +#include + +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "xfa/fde/css/fde_css.h" +#include "xfa/fgas/layout/cfx_rtfbreak.h" +#include "xfa/fxfa/cxfa_textparser.h" + +class CFDE_Brush; +class CFDE_CSSComputedStyle; +class CFDE_Pen; +class CFDE_RenderDevice; +class CFX_XMLNode; +class CFX_RTFBreak; +class CXFA_LoaderContext; +class CXFA_LinkUserData; +class CXFA_Node; +class CXFA_PieceLine; +class CXFA_TextProvider; +class CXFA_TextTabstopsContext; +class CXFA_TextPiece; + +class CXFA_TextLayout { + public: + explicit CXFA_TextLayout(CXFA_TextProvider* pTextProvider); + ~CXFA_TextLayout(); + + int32_t GetText(CFX_WideString& wsText); + float GetLayoutHeight(); + float StartLayout(float fWidth = -1); + bool DoLayout(int32_t iBlockIndex, + float& fCalcHeight, + float fContentAreaHeight = -1, + float fTextHeight = -1); + + bool CalcSize(const CFX_SizeF& minSize, + const CFX_SizeF& maxSize, + CFX_SizeF& defaultSize); + bool Layout(const CFX_SizeF& size, float* fHeight = nullptr); + void ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex); + bool DrawString(CFX_RenderDevice* pFxDevice, + const CFX_Matrix& tmDoc2Device, + const CFX_RectF& rtClip, + int32_t iBlock = 0); + bool IsLoaded() const { return !m_pieceLines.empty(); } + void Unload(); + const std::vector>* GetPieceLines() const { + return &m_pieceLines; + } + + bool m_bHasBlock; + std::vector m_Blocks; + + private: + void GetTextDataNode(); + CFX_XMLNode* GetXMLContainerNode(); + std::unique_ptr CreateBreak(bool bDefault); + void InitBreak(float fLineWidth); + void InitBreak(CFDE_CSSComputedStyle* pStyle, + FDE_CSSDisplay eDisplay, + float fLineWidth, + CFX_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle = nullptr); + bool Loader(const CFX_SizeF& szText, + float& fLinePos, + bool bSavePieces = true); + void LoadText(CXFA_Node* pNode, + const CFX_SizeF& szText, + float& fLinePos, + bool bSavePieces); + bool LoadRichText(CFX_XMLNode* pXMLNode, + const CFX_SizeF& szText, + float& fLinePos, + const CFX_RetainPtr& pParentStyle, + bool bSavePieces, + CFX_RetainPtr pLinkData, + bool bEndBreak = true, + bool bIsOl = false, + int32_t iLiCount = 0); + bool AppendChar(const CFX_WideString& wsText, + float& fLinePos, + float fSpaceAbove, + bool bSavePieces); + void AppendTextLine(CFX_BreakType dwStatus, + float& fLinePos, + bool bSavePieces, + bool bEndBreak = false); + void EndBreak(CFX_BreakType dwStatus, float& fLinePos, bool bDefault); + bool IsEnd(bool bSavePieces); + void ProcessText(CFX_WideString& wsText); + void UpdateAlign(float fHeight, float fBottom); + void RenderString(CFDE_RenderDevice* pDevice, + CFDE_Brush* pBrush, + CXFA_PieceLine* pPieceLine, + int32_t iPiece, + FXTEXT_CHARPOS* pCharPos, + const CFX_Matrix& tmDoc2Device); + void RenderPath(CFDE_RenderDevice* pDevice, + CFDE_Pen* pPen, + CXFA_PieceLine* pPieceLine, + int32_t iPiece, + FXTEXT_CHARPOS* pCharPos, + const CFX_Matrix& tmDoc2Device); + int32_t GetDisplayPos(const CXFA_TextPiece* pPiece, + FXTEXT_CHARPOS* pCharPos, + bool bCharCode = false); + bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr); + void DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); + bool Layout(int32_t iBlock); + int32_t CountBlocks() const; + + CXFA_TextProvider* m_pTextProvider; + CXFA_Node* m_pTextDataNode; + bool m_bRichText; + std::unique_ptr m_pBreak; + std::unique_ptr m_pLoader; + int32_t m_iLines; + float m_fMaxWidth; + CXFA_TextParser m_textParser; + std::vector> m_pieceLines; + std::unique_ptr m_pTabstopContext; + bool m_bBlockContinue; +}; + +#endif // XFA_FXFA_CXFA_TEXTLAYOUT_H_ diff --git a/xfa/fxfa/cxfa_textparsecontext.cpp b/xfa/fxfa/cxfa_textparsecontext.cpp new file mode 100644 index 0000000000..7231f388e2 --- /dev/null +++ b/xfa/fxfa/cxfa_textparsecontext.cpp @@ -0,0 +1,16 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_textparsecontext.h" + +#include "xfa/fde/css/cfde_csscomputedstyle.h" +#include "xfa/fde/css/cfde_cssdeclaration.h" +#include "xfa/fde/css/cfde_cssstyleselector.h" + +CXFA_TextParseContext::CXFA_TextParseContext() + : m_pParentStyle(nullptr), m_eDisplay(FDE_CSSDisplay::None) {} + +CXFA_TextParseContext::~CXFA_TextParseContext() {} diff --git a/xfa/fxfa/cxfa_textparsecontext.h b/xfa/fxfa/cxfa_textparsecontext.h new file mode 100644 index 0000000000..c3236570e5 --- /dev/null +++ b/xfa/fxfa/cxfa_textparsecontext.h @@ -0,0 +1,39 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTPARSECONTEXT_H_ +#define XFA_FXFA_CXFA_TEXTPARSECONTEXT_H_ + +#include +#include + +#include "third_party/base/stl_util.h" +#include "xfa/fde/css/cfde_cssdeclaration.h" +#include "xfa/fde/css/fde_css.h" + +class CFDE_CSSComputedStyle; + +class CXFA_TextParseContext { + public: + CXFA_TextParseContext(); + ~CXFA_TextParseContext(); + + void SetDisplay(FDE_CSSDisplay eDisplay) { m_eDisplay = eDisplay; } + FDE_CSSDisplay GetDisplay() const { return m_eDisplay; } + + void SetDecls(std::vector&& decl) { + decls_ = std::move(decl); + } + const std::vector& GetDecls() { return decls_; } + + CFX_RetainPtr m_pParentStyle; + + private: + std::vector decls_; + FDE_CSSDisplay m_eDisplay; +}; + +#endif // XFA_FXFA_CXFA_TEXTPARSECONTEXT_H_ diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp new file mode 100644 index 0000000000..2bc0096962 --- /dev/null +++ b/xfa/fxfa/cxfa_textparser.cpp @@ -0,0 +1,625 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_textparser.h" + +#include +#include +#include + +#include "core/fxcrt/fx_codepage.h" +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlnode.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fde/css/cfde_csscomputedstyle.h" +#include "xfa/fde/css/cfde_cssstyleselector.h" +#include "xfa/fde/css/cfde_cssstylesheet.h" +#include "xfa/fde/css/fde_css.h" +#include "xfa/fgas/font/cfgas_fontmgr.h" +#include "xfa/fxfa/cxfa_csstagprovider.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_fontmgr.h" +#include "xfa/fxfa/cxfa_textparsecontext.h" +#include "xfa/fxfa/cxfa_textprovider.h" +#include "xfa/fxfa/cxfa_texttabstopscontext.h" +#include "xfa/fxfa/parser/cxfa_measurement.h" + +namespace { + +enum class TabStopStatus { + Error, + EOS, + None, + Alignment, + StartLeader, + Leader, + Location, +}; + +} // namespace + +CXFA_TextParser::CXFA_TextParser() + : m_bParsed(false), m_cssInitialized(false) {} + +CXFA_TextParser::~CXFA_TextParser() {} + +void CXFA_TextParser::Reset() { + m_mapXMLNodeToParseContext.clear(); + m_bParsed = false; +} + +void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { + if (!pTextProvider) + return; + + if (!m_pSelector) { + CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); + CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr(); + ASSERT(pFontMgr); + m_pSelector = pdfium::MakeUnique(pFontMgr); + CXFA_Font font = pTextProvider->GetFontNode(); + m_pSelector->SetDefFontSize(font ? font.GetFontSize() : 10.0f); + } + + if (m_cssInitialized) + return; + + m_cssInitialized = true; + auto uaSheet = LoadDefaultSheetStyle(); + m_pSelector->SetUAStyleSheet(std::move(uaSheet)); + m_pSelector->UpdateStyleIndex(); +} + +std::unique_ptr CXFA_TextParser::LoadDefaultSheetStyle() { + static const wchar_t s_pStyle[] = + L"html,body,ol,p,ul{display:block}" + L"li{display:list-item}" + L"ol,ul{padding-left:33px;margin:1.12em 0}" + L"ol{list-style-type:decimal}" + L"a{color:#0000ff;text-decoration:underline}" + L"b{font-weight:bolder}" + L"i{font-style:italic}" + L"sup{vertical-align:+15em;font-size:.66em}" + L"sub{vertical-align:-15em;font-size:.66em}"; + + auto sheet = pdfium::MakeUnique(); + return sheet->LoadBuffer(s_pStyle, FXSYS_wcslen(s_pStyle)) ? std::move(sheet) + : nullptr; +} + +CFX_RetainPtr CXFA_TextParser::CreateRootStyle( + CXFA_TextProvider* pTextProvider) { + CXFA_Font font = pTextProvider->GetFontNode(); + CXFA_Para para = pTextProvider->GetParaNode(); + auto pStyle = m_pSelector->CreateComputedStyle(nullptr); + float fLineHeight = 0; + float fFontSize = 10; + + if (para) { + fLineHeight = para.GetLineHeight(); + FDE_CSSLength indent; + indent.Set(FDE_CSSLengthUnit::Point, para.GetTextIndent()); + pStyle->SetTextIndent(indent); + FDE_CSSTextAlign hAlign = FDE_CSSTextAlign::Left; + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + hAlign = FDE_CSSTextAlign::Center; + break; + case XFA_ATTRIBUTEENUM_Right: + hAlign = FDE_CSSTextAlign::Right; + break; + case XFA_ATTRIBUTEENUM_Justify: + hAlign = FDE_CSSTextAlign::Justify; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + hAlign = FDE_CSSTextAlign::JustifyAll; + break; + } + pStyle->SetTextAlign(hAlign); + FDE_CSSRect rtMarginWidth; + rtMarginWidth.left.Set(FDE_CSSLengthUnit::Point, para.GetMarginLeft()); + rtMarginWidth.top.Set(FDE_CSSLengthUnit::Point, para.GetSpaceAbove()); + rtMarginWidth.right.Set(FDE_CSSLengthUnit::Point, para.GetMarginRight()); + rtMarginWidth.bottom.Set(FDE_CSSLengthUnit::Point, para.GetSpaceBelow()); + pStyle->SetMarginWidth(rtMarginWidth); + } + + if (font) { + pStyle->SetColor(font.GetColor()); + pStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFontStyle::Italic + : FDE_CSSFontStyle::Normal); + pStyle->SetFontWeight(font.IsBold() ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); + pStyle->SetNumberVerticalAlign(-font.GetBaselineShift()); + fFontSize = font.GetFontSize(); + FDE_CSSLength letterSpacing; + letterSpacing.Set(FDE_CSSLengthUnit::Point, font.GetLetterSpacing()); + pStyle->SetLetterSpacing(letterSpacing); + uint32_t dwDecoration = 0; + if (font.GetLineThrough() > 0) + dwDecoration |= FDE_CSSTEXTDECORATION_LineThrough; + if (font.GetUnderline() > 1) + dwDecoration |= FDE_CSSTEXTDECORATION_Double; + else if (font.GetUnderline() > 0) + dwDecoration |= FDE_CSSTEXTDECORATION_Underline; + + pStyle->SetTextDecoration(dwDecoration); + } + pStyle->SetLineHeight(fLineHeight); + pStyle->SetFontSize(fFontSize); + return pStyle; +} + +CFX_RetainPtr CXFA_TextParser::CreateStyle( + CFDE_CSSComputedStyle* pParentStyle) { + auto pNewStyle = m_pSelector->CreateComputedStyle(pParentStyle); + ASSERT(pNewStyle); + if (!pParentStyle) + return pNewStyle; + + uint32_t dwDecoration = pParentStyle->GetTextDecoration(); + float fBaseLine = 0; + if (pParentStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) + fBaseLine = pParentStyle->GetNumberVerticalAlign(); + + pNewStyle->SetTextDecoration(dwDecoration); + pNewStyle->SetNumberVerticalAlign(fBaseLine); + + const FDE_CSSRect* pRect = pParentStyle->GetMarginWidth(); + if (pRect) + pNewStyle->SetMarginWidth(*pRect); + return pNewStyle; +} + +CFX_RetainPtr CXFA_TextParser::ComputeStyle( + CFX_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle) { + auto it = m_mapXMLNodeToParseContext.find(pXMLNode); + if (it == m_mapXMLNodeToParseContext.end()) + return nullptr; + + CXFA_TextParseContext* pContext = it->second.get(); + if (!pContext) + return nullptr; + + pContext->m_pParentStyle.Reset(pParentStyle); + + auto tagProvider = ParseTagInfo(pXMLNode); + if (tagProvider->m_bContent) + return nullptr; + + auto pStyle = CreateStyle(pParentStyle); + m_pSelector->ComputeStyle(pContext->GetDecls(), + tagProvider->GetAttribute(L"style"), + tagProvider->GetAttribute(L"align"), pStyle.Get()); + return pStyle; +} + +void CXFA_TextParser::DoParse(CFX_XMLNode* pXMLContainer, + CXFA_TextProvider* pTextProvider) { + if (!pXMLContainer || !pTextProvider || m_bParsed) + return; + + m_bParsed = true; + InitCSSData(pTextProvider); + auto pRootStyle = CreateRootStyle(pTextProvider); + ParseRichText(pXMLContainer, pRootStyle.Get()); +} + +void CXFA_TextParser::ParseRichText(CFX_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle) { + if (!pXMLNode) + return; + + auto tagProvider = ParseTagInfo(pXMLNode); + if (!tagProvider->m_bTagAvailable) + return; + + CFX_RetainPtr pNewStyle; + if ((tagProvider->GetTagName() != L"body") || + (tagProvider->GetTagName() != L"html")) { + auto pTextContext = pdfium::MakeUnique(); + FDE_CSSDisplay eDisplay = FDE_CSSDisplay::Inline; + if (!tagProvider->m_bContent) { + auto declArray = + m_pSelector->MatchDeclarations(tagProvider->GetTagName()); + pNewStyle = CreateStyle(pParentStyle); + m_pSelector->ComputeStyle(declArray, tagProvider->GetAttribute(L"style"), + tagProvider->GetAttribute(L"align"), + pNewStyle.Get()); + + if (!declArray.empty()) + pTextContext->SetDecls(std::move(declArray)); + + eDisplay = pNewStyle->GetDisplay(); + } + pTextContext->SetDisplay(eDisplay); + m_mapXMLNodeToParseContext[pXMLNode] = std::move(pTextContext); + } + + for (CFX_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { + ParseRichText(pXMLChild, pNewStyle.Get()); + } +} + +bool CXFA_TextParser::TagValidate(const CFX_WideString& wsName) const { + static const uint32_t s_XFATagName[] = { + 0x61, // a + 0x62, // b + 0x69, // i + 0x70, // p + 0x0001f714, // br + 0x00022a55, // li + 0x000239bb, // ol + 0x00025881, // ul + 0x0bd37faa, // sub + 0x0bd37fb8, // sup + 0xa73e3af2, // span + 0xb182eaae, // body + 0xdb8ac455, // html + }; + static const int32_t s_iCount = FX_ArraySize(s_XFATagName); + + return std::binary_search(s_XFATagName, s_XFATagName + s_iCount, + FX_HashCode_GetW(wsName.AsStringC(), true)); +} + +std::unique_ptr CXFA_TextParser::ParseTagInfo( + CFX_XMLNode* pXMLNode) { + auto tagProvider = pdfium::MakeUnique(); + + CFX_WideString wsName; + if (pXMLNode->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pXMLElement = static_cast(pXMLNode); + wsName = pXMLElement->GetLocalTagName(); + tagProvider->SetTagName(wsName); + tagProvider->m_bTagAvailable = TagValidate(wsName); + + CFX_WideString wsValue = pXMLElement->GetString(L"style"); + if (!wsValue.IsEmpty()) + tagProvider->SetAttribute(L"style", wsValue); + } else if (pXMLNode->GetType() == FX_XMLNODE_Text) { + tagProvider->m_bTagAvailable = true; + tagProvider->m_bContent = true; + } + return tagProvider; +} + +int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { + CXFA_Para para = pTextProvider->GetParaNode(); + return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; +} + +float CXFA_TextParser::GetTabInterval(CFDE_CSSComputedStyle* pStyle) const { + CFX_WideString wsValue; + if (pStyle && pStyle->GetCustomStyle(L"tab-interval", wsValue)) + return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); + return 36; +} + +int32_t CXFA_TextParser::CountTabs(CFDE_CSSComputedStyle* pStyle) const { + CFX_WideString wsValue; + if (pStyle && pStyle->GetCustomStyle(L"xfa-tab-count", wsValue)) + return wsValue.GetInteger(); + return 0; +} + +bool CXFA_TextParser::IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const { + CFX_WideString wsValue; + if (pStyle && pStyle->GetCustomStyle(L"xfa-spacerun", wsValue)) { + wsValue.MakeLower(); + return wsValue == L"yes"; + } + return false; +} + +CFX_RetainPtr CXFA_TextParser::GetFont( + CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { + CFX_WideStringC wsFamily = L"Courier"; + uint32_t dwStyle = 0; + CXFA_Font font = pTextProvider->GetFontNode(); + if (font) { + font.GetTypeface(wsFamily); + if (font.IsBold()) + dwStyle |= FX_FONTSTYLE_Bold; + if (font.IsItalic()) + dwStyle |= FX_FONTSTYLE_Italic; + } + + if (pStyle) { + int32_t iCount = pStyle->CountFontFamilies(); + if (iCount > 0) + wsFamily = pStyle->GetFontFamily(iCount - 1).AsStringC(); + + dwStyle = 0; + if (pStyle->GetFontWeight() > FXFONT_FW_NORMAL) + dwStyle |= FX_FONTSTYLE_Bold; + if (pStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) + dwStyle |= FX_FONTSTYLE_Italic; + } + + CXFA_FFDoc* pDoc = pTextProvider->GetDocNode(); + CXFA_FontMgr* pFontMgr = pDoc->GetApp()->GetXFAFontMgr(); + return pFontMgr->GetFont(pDoc, wsFamily, dwStyle); +} + +float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { + if (pStyle) + return pStyle->GetFontSize(); + + CXFA_Font font = pTextProvider->GetFontNode(); + if (font) + return font.GetFontSize(); + return 10; +} + +int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + CFX_XMLNode* pXMLNode) const { + if (pStyle) { + CFX_WideString wsValue; + if (pStyle->GetCustomStyle(L"xfa-font-horizontal-scale", wsValue)) + return wsValue.GetInteger(); + + while (pXMLNode) { + auto it = m_mapXMLNodeToParseContext.find(pXMLNode); + if (it != m_mapXMLNodeToParseContext.end()) { + CXFA_TextParseContext* pContext = it->second.get(); + if (pContext && pContext->m_pParentStyle && + pContext->m_pParentStyle->GetCustomStyle( + L"xfa-font-horizontal-scale", wsValue)) { + return wsValue.GetInteger(); + } + } + pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::Parent); + } + } + + if (CXFA_Font font = pTextProvider->GetFontNode()) + return static_cast(font.GetHorizontalScale()); + return 100; +} + +int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { + if (pStyle) { + CFX_WideString wsValue; + if (pStyle->GetCustomStyle(L"xfa-font-vertical-scale", wsValue)) + return wsValue.GetInteger(); + } + + if (CXFA_Font font = pTextProvider->GetFontNode()) + return (int32_t)font.GetVerticalScale(); + return 100; +} + +void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + int32_t& iUnderline, + int32_t& iPeriod) const { + iUnderline = 0; + iPeriod = XFA_ATTRIBUTEENUM_All; + if (!pStyle) { + CXFA_Font font = pTextProvider->GetFontNode(); + if (font) { + iUnderline = font.GetUnderline(); + iPeriod = font.GetUnderlinePeriod(); + } + return; + } + + uint32_t dwDecoration = pStyle->GetTextDecoration(); + if (dwDecoration & FDE_CSSTEXTDECORATION_Double) + iUnderline = 2; + else if (dwDecoration & FDE_CSSTEXTDECORATION_Underline) + iUnderline = 1; + + CFX_WideString wsValue; + if (pStyle->GetCustomStyle(L"underlinePeriod", wsValue)) { + if (wsValue == L"word") + iPeriod = XFA_ATTRIBUTEENUM_Word; + } else if (CXFA_Font font = pTextProvider->GetFontNode()) { + iPeriod = font.GetUnderlinePeriod(); + } +} + +void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + int32_t& iLinethrough) const { + if (pStyle) { + uint32_t dwDecoration = pStyle->GetTextDecoration(); + iLinethrough = (dwDecoration & FDE_CSSTEXTDECORATION_LineThrough) ? 1 : 0; + return; + } + + CXFA_Font font = pTextProvider->GetFontNode(); + if (font) + iLinethrough = font.GetLineThrough(); +} + +FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { + if (pStyle) + return pStyle->GetColor(); + if (CXFA_Font font = pTextProvider->GetFontNode()) + return font.GetColor(); + + return 0xFF000000; +} + +float CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const { + if (pStyle) { + if (pStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) + return pStyle->GetNumberVerticalAlign(); + } else if (CXFA_Font font = pTextProvider->GetFontNode()) { + return font.GetBaselineShift(); + } + return 0; +} + +float CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + bool bFirst, + float fVerScale) const { + float fLineHeight = 0; + if (pStyle) + fLineHeight = pStyle->GetLineHeight(); + else if (CXFA_Para para = pTextProvider->GetParaNode()) + fLineHeight = para.GetLineHeight(); + + if (bFirst) { + float fFontSize = GetFontSize(pTextProvider, pStyle); + if (fLineHeight < 0.1f) + fLineHeight = fFontSize; + else + fLineHeight = std::min(fLineHeight, fFontSize); + } else if (fLineHeight < 0.1f) { + fLineHeight = GetFontSize(pTextProvider, pStyle) * 1.2f; + } + fLineHeight *= fVerScale; + return fLineHeight; +} + +bool CXFA_TextParser::GetEmbbedObj(CXFA_TextProvider* pTextProvider, + CFX_XMLNode* pXMLNode, + CFX_WideString& wsValue) { + wsValue.clear(); + if (!pXMLNode) + return false; + + bool bRet = false; + if (pXMLNode->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pElement = static_cast(pXMLNode); + CFX_WideString wsAttr = pElement->GetString(L"xfa:embed"); + if (wsAttr.IsEmpty()) + return false; + if (wsAttr.GetAt(0) == L'#') + wsAttr.Delete(0); + + CFX_WideString ws = pElement->GetString(L"xfa:embedType"); + if (ws.IsEmpty()) + ws = L"som"; + else + ws.MakeLower(); + + bool bURI = (ws == L"uri"); + if (!bURI && ws != L"som") + return false; + + ws = pElement->GetString(L"xfa:embedMode"); + if (ws.IsEmpty()) + ws = L"formatted"; + else + ws.MakeLower(); + + bool bRaw = (ws == L"raw"); + if (!bRaw && ws != L"formatted") + return false; + + bRet = pTextProvider->GetEmbbedObj(bURI, bRaw, wsAttr, wsValue); + } + return bRet; +} + +CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( + CFX_XMLNode* pXMLNode) { + auto it = m_mapXMLNodeToParseContext.find(pXMLNode); + return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr; +} + +bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, + CXFA_TextTabstopsContext* pTabstopContext) { + if (!pStyle || !pTabstopContext) + return false; + + CFX_WideString wsValue; + if (!pStyle->GetCustomStyle(L"xfa-tab-stops", wsValue) && + !pStyle->GetCustomStyle(L"tab-stops", wsValue)) { + return false; + } + + int32_t iLength = wsValue.GetLength(); + const wchar_t* pTabStops = wsValue.c_str(); + int32_t iCur = 0; + int32_t iLast = 0; + CFX_WideString wsAlign; + TabStopStatus eStatus = TabStopStatus::None; + wchar_t ch; + while (iCur < iLength) { + ch = pTabStops[iCur]; + switch (eStatus) { + case TabStopStatus::None: + if (ch <= ' ') { + iCur++; + } else { + eStatus = TabStopStatus::Alignment; + iLast = iCur; + } + break; + case TabStopStatus::Alignment: + if (ch == ' ') { + wsAlign = CFX_WideStringC(pTabStops + iLast, iCur - iLast); + eStatus = TabStopStatus::StartLeader; + iCur++; + while (iCur < iLength && pTabStops[iCur] <= ' ') + iCur++; + iLast = iCur; + } else { + iCur++; + } + break; + case TabStopStatus::StartLeader: + if (ch != 'l') { + eStatus = TabStopStatus::Location; + } else { + int32_t iCount = 0; + while (iCur < iLength) { + ch = pTabStops[iCur]; + iCur++; + if (ch == '(') { + iCount++; + } else if (ch == ')') { + iCount--; + if (iCount == 0) + break; + } + } + while (iCur < iLength && pTabStops[iCur] <= ' ') + iCur++; + + iLast = iCur; + eStatus = TabStopStatus::Location; + } + break; + case TabStopStatus::Location: + if (ch == ' ') { + uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); + CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); + float fPos = ms.ToUnit(XFA_UNIT_Pt); + pTabstopContext->Append(dwHashCode, fPos); + wsAlign.clear(); + eStatus = TabStopStatus::None; + } + iCur++; + break; + default: + break; + } + } + + if (!wsAlign.IsEmpty()) { + uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); + CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); + float fPos = ms.ToUnit(XFA_UNIT_Pt); + pTabstopContext->Append(dwHashCode, fPos); + } + return true; +} diff --git a/xfa/fxfa/cxfa_textparser.h b/xfa/fxfa/cxfa_textparser.h new file mode 100644 index 0000000000..3c1b6039d0 --- /dev/null +++ b/xfa/fxfa/cxfa_textparser.h @@ -0,0 +1,104 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTPARSER_H_ +#define XFA_FXFA_CXFA_TEXTPARSER_H_ + +#include +#include + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" +#include "core/fxge/fx_dib.h" +#include "xfa/fgas/font/cfgas_gefont.h" + +class CFDE_CSSComputedStyle; +class CFDE_CSSStyleSelector; +class CFDE_CSSStyleSheet; +class CFX_XMLNode; +class CXFA_CSSTagProvider; +class CXFA_TextParseContext; +class CXFA_TextProvider; +class CXFA_TextTabstopsContext; + +class CXFA_TextParser { + public: + CXFA_TextParser(); + virtual ~CXFA_TextParser(); + + void Reset(); + void DoParse(CFX_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); + + CFX_RetainPtr CreateRootStyle( + CXFA_TextProvider* pTextProvider); + CFX_RetainPtr ComputeStyle( + CFX_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle); + + bool IsParsed() const { return m_bParsed; } + + int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; + + float GetTabInterval(CFDE_CSSComputedStyle* pStyle) const; + int32_t CountTabs(CFDE_CSSComputedStyle* pStyle) const; + + bool IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const; + bool GetTabstops(CFDE_CSSComputedStyle* pStyle, + CXFA_TextTabstopsContext* pTabstopContext); + + CFX_RetainPtr GetFont(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; + float GetFontSize(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; + + int32_t GetHorScale(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + CFX_XMLNode* pXMLNode) const; + int32_t GetVerScale(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; + + void GetUnderline(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + int32_t& iUnderline, + int32_t& iPeriod) const; + void GetLinethrough(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + int32_t& iLinethrough) const; + FX_ARGB GetColor(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; + float GetBaseline(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle) const; + float GetLineHeight(CXFA_TextProvider* pTextProvider, + CFDE_CSSComputedStyle* pStyle, + bool bFirst, + float fVerScale) const; + + bool GetEmbbedObj(CXFA_TextProvider* pTextProvider, + CFX_XMLNode* pXMLNode, + CFX_WideString& wsValue); + CXFA_TextParseContext* GetParseContextFromMap(CFX_XMLNode* pXMLNode); + + protected: + bool TagValidate(const CFX_WideString& str) const; + + private: + void InitCSSData(CXFA_TextProvider* pTextProvider); + void ParseRichText(CFX_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle); + std::unique_ptr ParseTagInfo(CFX_XMLNode* pXMLNode); + std::unique_ptr LoadDefaultSheetStyle(); + CFX_RetainPtr CreateStyle( + CFDE_CSSComputedStyle* pParentStyle); + + bool m_bParsed; + bool m_cssInitialized; + std::unique_ptr m_pSelector; + std::map> + m_mapXMLNodeToParseContext; +}; + +#endif // XFA_FXFA_CXFA_TEXTPARSER_H_ diff --git a/xfa/fxfa/cxfa_textparser_unittest.cpp b/xfa/fxfa/cxfa_textparser_unittest.cpp new file mode 100644 index 0000000000..bd748cd494 --- /dev/null +++ b/xfa/fxfa/cxfa_textparser_unittest.cpp @@ -0,0 +1,40 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "xfa/fxfa/cxfa_textparser.h" + +#include "testing/gtest/include/gtest/gtest.h" + +class CXFA_TestTextParser : public CXFA_TextParser { + public: + CXFA_TestTextParser() : CXFA_TextParser() {} + + private: + // Add test cases as friends to access protected member functions. + FRIEND_TEST(CXFA_TextParser, TagValidate); +}; + +TEST(CXFA_TextParser, TagValidate) { + CXFA_TestTextParser parser; + EXPECT_TRUE(parser.TagValidate(L"br")); + EXPECT_TRUE(parser.TagValidate(L"Br")); + EXPECT_TRUE(parser.TagValidate(L"BR")); + EXPECT_TRUE(parser.TagValidate(L"a")); + EXPECT_TRUE(parser.TagValidate(L"b")); + EXPECT_TRUE(parser.TagValidate(L"i")); + EXPECT_TRUE(parser.TagValidate(L"p")); + EXPECT_TRUE(parser.TagValidate(L"li")); + EXPECT_TRUE(parser.TagValidate(L"ol")); + EXPECT_TRUE(parser.TagValidate(L"ul")); + EXPECT_TRUE(parser.TagValidate(L"sub")); + EXPECT_TRUE(parser.TagValidate(L"sup")); + EXPECT_TRUE(parser.TagValidate(L"span")); + EXPECT_TRUE(parser.TagValidate(L"body")); + EXPECT_TRUE(parser.TagValidate(L"html")); + + EXPECT_FALSE(parser.TagValidate(L"")); + EXPECT_FALSE(parser.TagValidate(L"tml")); + EXPECT_FALSE(parser.TagValidate(L"xhtml")); + EXPECT_FALSE(parser.TagValidate(L"htmlx")); +} diff --git a/xfa/fxfa/cxfa_textpiece.cpp b/xfa/fxfa/cxfa_textpiece.cpp new file mode 100644 index 0000000000..87a5e3fff2 --- /dev/null +++ b/xfa/fxfa/cxfa_textpiece.cpp @@ -0,0 +1,13 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_textpiece.h" + +#include "xfa/fxfa/cxfa_linkuserdata.h" + +CXFA_TextPiece::CXFA_TextPiece() {} + +CXFA_TextPiece::~CXFA_TextPiece() {} diff --git a/xfa/fxfa/cxfa_textpiece.h b/xfa/fxfa/cxfa_textpiece.h new file mode 100644 index 0000000000..453257d5ec --- /dev/null +++ b/xfa/fxfa/cxfa_textpiece.h @@ -0,0 +1,41 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTPIECE_H_ +#define XFA_FXFA_CXFA_TEXTPIECE_H_ + +#include + +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxge/fx_dib.h" +#include "xfa/fgas/font/cfgas_gefont.h" + +class CXFA_LinkUserData; + +class CXFA_TextPiece { + public: + CXFA_TextPiece(); + ~CXFA_TextPiece(); + + CFX_WideString szText; + std::vector Widths; + int32_t iChars; + int32_t iHorScale; + int32_t iVerScale; + int32_t iBidiLevel; + int32_t iUnderline; + int32_t iPeriod; + int32_t iLineThrough; + FX_ARGB dwColor; + float fFontSize; + CFX_RectF rtPiece; + CFX_RetainPtr pFont; + CFX_RetainPtr pLinkData; +}; + +#endif // XFA_FXFA_CXFA_TEXTPIECE_H_ diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp new file mode 100644 index 0000000000..16a2b58a8a --- /dev/null +++ b/xfa/fxfa/cxfa_textprovider.cpp @@ -0,0 +1,166 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_textprovider.h" + +#include +#include +#include + +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlnode.h" +#include "fxjs/cfxjse_value.h" +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" +#include "xfa/fde/cfde_textout.h" +#include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffapp.h" +#include "xfa/fxfa/cxfa_ffcheckbutton.h" +#include "xfa/fxfa/cxfa_ffdoc.h" +#include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffpageview.h" +#include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_fontmgr.h" +#include "xfa/fxfa/cxfa_fwladapterwidgetmgr.h" +#include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" + +CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { + bRichText = false; + + if (m_eType == XFA_TEXTPROVIDERTYPE_Text) { + CXFA_Node* pElementNode = m_pWidgetAcc->GetNode(); + CXFA_Node* pValueNode = pElementNode->GetChild(0, XFA_Element::Value); + if (!pValueNode) + return nullptr; + + CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); + if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { + CFX_WideString wsContentType; + pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); + if (wsContentType == L"text/html") + bRichText = true; + } + return pChildNode; + } + + if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) { + CXFA_Node* pBind = m_pWidgetAcc->GetDatasets(); + CFX_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); + ASSERT(pXMLNode); + for (CFX_XMLNode* pXMLChild = + pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); + pXMLChild; + pXMLChild = pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling)) { + if (pXMLChild->GetType() == FX_XMLNODE_Element) { + CFX_XMLElement* pElement = static_cast(pXMLChild); + if (XFA_RecognizeRichText(pElement)) + bRichText = true; + } + } + return pBind; + } + + if (m_eType == XFA_TEXTPROVIDERTYPE_Caption) { + CXFA_Node* pCaptionNode = + m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Caption); + if (!pCaptionNode) + return nullptr; + + CXFA_Node* pValueNode = pCaptionNode->GetChild(0, XFA_Element::Value); + if (!pValueNode) + return nullptr; + + CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); + if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { + CFX_WideString wsContentType; + pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); + if (wsContentType == L"text/html") + bRichText = true; + } + return pChildNode; + } + + CXFA_Node* pItemNode = + m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Items); + if (!pItemNode) + return nullptr; + + CXFA_Node* pNode = pItemNode->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pNode) { + CFX_WideStringC wsName; + pNode->TryCData(XFA_ATTRIBUTE_Name, wsName); + if (m_eType == XFA_TEXTPROVIDERTYPE_Rollover && wsName == L"rollover") + return pNode; + if (m_eType == XFA_TEXTPROVIDERTYPE_Down && wsName == L"down") + return pNode; + + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); + } + return nullptr; +} + +CXFA_Para CXFA_TextProvider::GetParaNode() { + if (m_eType == XFA_TEXTPROVIDERTYPE_Text) + return m_pWidgetAcc->GetPara(); + + CXFA_Node* pNode = m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Caption); + return CXFA_Para(pNode->GetChild(0, XFA_Element::Para)); +} + +CXFA_Font CXFA_TextProvider::GetFontNode() { + if (m_eType == XFA_TEXTPROVIDERTYPE_Text) + return m_pWidgetAcc->GetFont(false); + + CXFA_Node* pNode = m_pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Caption); + pNode = pNode->GetChild(0, XFA_Element::Font); + return pNode ? CXFA_Font(pNode) : m_pWidgetAcc->GetFont(false); +} + +bool CXFA_TextProvider::IsCheckButtonAndAutoWidth() { + XFA_Element eType = m_pWidgetAcc->GetUIType(); + if (eType != XFA_Element::CheckButton) + return false; + + float fWidth = 0; + return !m_pWidgetAcc->GetWidth(fWidth); +} + +bool CXFA_TextProvider::GetEmbbedObj(bool bURI, + bool bRaw, + const CFX_WideString& wsAttr, + CFX_WideString& wsValue) { + if (m_eType != XFA_TEXTPROVIDERTYPE_Text) + return false; + + if (!bURI) + return false; + + CXFA_Node* pWidgetNode = m_pWidgetAcc->GetNode(); + CXFA_Node* pParent = pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent); + CXFA_Document* pDocument = pWidgetNode->GetDocument(); + CXFA_Node* pIDNode = nullptr; + CXFA_WidgetAcc* pEmbAcc = nullptr; + if (pParent) + pIDNode = pDocument->GetNodeByID(pParent, wsAttr.AsStringC()); + + if (!pIDNode) { + pIDNode = pDocument->GetNodeByID( + ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Form)), wsAttr.AsStringC()); + } + if (pIDNode) + pEmbAcc = static_cast(pIDNode->GetWidgetData()); + + if (!pEmbAcc) + return false; + + pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); + return true; +} diff --git a/xfa/fxfa/cxfa_textprovider.h b/xfa/fxfa/cxfa_textprovider.h new file mode 100644 index 0000000000..0772490d90 --- /dev/null +++ b/xfa/fxfa/cxfa_textprovider.h @@ -0,0 +1,50 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTPROVIDER_H_ +#define XFA_FXFA_CXFA_TEXTPROVIDER_H_ + +#include "core/fxcrt/fx_string.h" +#include "xfa/fxfa/cxfa_textlayout.h" +#include "xfa/fxfa/cxfa_widgetacc.h" +#include "xfa/fxfa/parser/cxfa_font.h" +#include "xfa/fxfa/parser/cxfa_para.h" + +class CXFA_FFDoc; +class CXFA_Node; + +enum XFA_TEXTPROVIDERTYPE { + XFA_TEXTPROVIDERTYPE_Text, + XFA_TEXTPROVIDERTYPE_Datasets, + XFA_TEXTPROVIDERTYPE_Caption, + XFA_TEXTPROVIDERTYPE_Rollover, + XFA_TEXTPROVIDERTYPE_Down, +}; + +class CXFA_TextProvider { + public: + CXFA_TextProvider(CXFA_WidgetAcc* pWidgetAcc, XFA_TEXTPROVIDERTYPE eType) + : m_pWidgetAcc(pWidgetAcc), m_eType(eType) { + ASSERT(m_pWidgetAcc); + } + ~CXFA_TextProvider() {} + + CXFA_Node* GetTextNode(bool& bRichText); + CXFA_Para GetParaNode(); + CXFA_Font GetFontNode(); + bool IsCheckButtonAndAutoWidth(); + CXFA_FFDoc* GetDocNode() { return m_pWidgetAcc->GetDoc(); } + bool GetEmbbedObj(bool bURI, + bool bRaw, + const CFX_WideString& wsAttr, + CFX_WideString& wsValue); + + private: + CXFA_WidgetAcc* m_pWidgetAcc; + XFA_TEXTPROVIDERTYPE m_eType; +}; + +#endif // XFA_FXFA_CXFA_TEXTPROVIDER_H_ diff --git a/xfa/fxfa/cxfa_texttabstopscontext.cpp b/xfa/fxfa/cxfa_texttabstopscontext.cpp new file mode 100644 index 0000000000..39476f7c2c --- /dev/null +++ b/xfa/fxfa/cxfa_texttabstopscontext.cpp @@ -0,0 +1,32 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_texttabstopscontext.h" + +CXFA_TextTabstopsContext::CXFA_TextTabstopsContext() + : m_iTabIndex(-1), m_bTabstops(false), m_fTabWidth(0), m_fLeft(0) {} + +CXFA_TextTabstopsContext::~CXFA_TextTabstopsContext() {} + +void CXFA_TextTabstopsContext::Append(uint32_t dwAlign, float fTabstops) { + XFA_TABSTOPS tabstop; + tabstop.dwAlign = dwAlign; + tabstop.fTabstops = fTabstops; + + auto it = std::lower_bound(m_tabstops.begin(), m_tabstops.end(), tabstop); + m_tabstops.insert(it, tabstop); +} + +void CXFA_TextTabstopsContext::RemoveAll() { + m_tabstops.clear(); +} + +void CXFA_TextTabstopsContext::Reset() { + m_iTabIndex = -1; + m_bTabstops = false; + m_fTabWidth = 0; + m_fLeft = 0; +} diff --git a/xfa/fxfa/cxfa_texttabstopscontext.h b/xfa/fxfa/cxfa_texttabstopscontext.h new file mode 100644 index 0000000000..7124fd88fe --- /dev/null +++ b/xfa/fxfa/cxfa_texttabstopscontext.h @@ -0,0 +1,39 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTTABSTOPSCONTEXT_H_ +#define XFA_FXFA_CXFA_TEXTTABSTOPSCONTEXT_H_ + +#include + +#include "core/fxcrt/fx_basic.h" + +struct XFA_TABSTOPS { + uint32_t dwAlign; + float fTabstops; + + bool operator<(const XFA_TABSTOPS& that) const { + return fTabstops < that.fTabstops; + } +}; + +class CXFA_TextTabstopsContext { + public: + CXFA_TextTabstopsContext(); + ~CXFA_TextTabstopsContext(); + + void Append(uint32_t dwAlign, float fTabstops); + void RemoveAll(); + void Reset(); + + int32_t m_iTabIndex; + bool m_bTabstops; + float m_fTabWidth; + float m_fLeft; + std::vector m_tabstops; +}; + +#endif // XFA_FXFA_CXFA_TEXTTABSTOPSCONTEXT_H_ diff --git a/xfa/fxfa/cxfa_textuserdata.cpp b/xfa/fxfa/cxfa_textuserdata.cpp new file mode 100644 index 0000000000..4cec6b300a --- /dev/null +++ b/xfa/fxfa/cxfa_textuserdata.cpp @@ -0,0 +1,23 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/cxfa_textuserdata.h" + +#include "xfa/fde/css/cfde_csscomputedstyle.h" +#include "xfa/fde/css/cfde_cssstyleselector.h" +#include "xfa/fde/css/fde_css.h" +#include "xfa/fxfa/cxfa_linkuserdata.h" + +CXFA_TextUserData::CXFA_TextUserData( + const CFX_RetainPtr& pStyle) + : m_pStyle(pStyle) {} + +CXFA_TextUserData::CXFA_TextUserData( + const CFX_RetainPtr& pStyle, + const CFX_RetainPtr& pLinkData) + : m_pStyle(pStyle), m_pLinkData(pLinkData) {} + +CXFA_TextUserData::~CXFA_TextUserData() {} diff --git a/xfa/fxfa/cxfa_textuserdata.h b/xfa/fxfa/cxfa_textuserdata.h new file mode 100644 index 0000000000..c9e90aa40f --- /dev/null +++ b/xfa/fxfa/cxfa_textuserdata.h @@ -0,0 +1,32 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_CXFA_TEXTUSERDATA_H_ +#define XFA_FXFA_CXFA_TEXTUSERDATA_H_ + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_basic.h" + +class CFDE_CSSComputedStyle; +class CXFA_LinkUserData; + +class CXFA_TextUserData : public CFX_Retainable { + public: + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); + + CFX_RetainPtr m_pStyle; + CFX_RetainPtr m_pLinkData; + + private: + explicit CXFA_TextUserData( + const CFX_RetainPtr& pStyle); + CXFA_TextUserData(const CFX_RetainPtr& pStyle, + const CFX_RetainPtr& pLinkData); + ~CXFA_TextUserData() override; +}; + +#endif // XFA_FXFA_CXFA_TEXTUSERDATA_H_ diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 3c136df0ff..0ed941f6bd 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -13,13 +13,13 @@ #include "core/fxcrt/xml/cfx_xmlnode.h" #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_textout.h" -#include "xfa/fxfa/app/cxfa_textlayout.h" -#include "xfa/fxfa/app/cxfa_textprovider.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/cxfa_fontmgr.h" +#include "xfa/fxfa/cxfa_textlayout.h" +#include "xfa/fxfa/cxfa_textprovider.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_node.h" diff --git a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp index 5f1a4d2989..bea1f32d23 100644 --- a/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/cxfa_fm2jscontext.cpp @@ -17,7 +17,7 @@ #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/fm2js/cxfa_fmparse.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" diff --git a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp index ede59871f1..45f1171321 100644 --- a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp @@ -7,8 +7,8 @@ #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidgethandler.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index d9eb5d699f..2db6677877 100644 --- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -9,7 +9,7 @@ #include #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp index 130c9f0843..8eeb0ff30f 100644 --- a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -10,7 +10,7 @@ #include "fxjs/cfxjse_arguments.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_arraynodelist.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" diff --git a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp index 023d3e541f..c746a4e76f 100644 --- a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" #include "fxjs/cfxjse_arguments.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index ec80866bb0..16b999b9e3 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "core/fxcrt/fx_extension.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cscript_datawindow.h" #include "xfa/fxfa/parser/cscript_eventpseudomodel.h" #include "xfa/fxfa/parser/cscript_hostpseudomodel.h" diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index 694b24dc27..f7a019d2d8 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -14,7 +14,7 @@ #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" diff --git a/xfa/fxfa/parser/cxfa_layoutitem.cpp b/xfa/fxfa/parser/cxfa_layoutitem.cpp index a769da0f2a..a670d30ae0 100644 --- a/xfa/fxfa/parser/cxfa_layoutitem.cpp +++ b/xfa/fxfa/parser/cxfa_layoutitem.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_layoutitem.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_measurement.h" diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index 0bf091ed34..a3f4ce9519 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -7,7 +7,7 @@ #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_containerlayoutitem.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 5c4f8d102e..11c2c3c35e 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -23,8 +23,8 @@ #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_arraynodelist.h" #include "xfa/fxfa/parser/cxfa_attachnodelist.h" diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp index 32aed5de1b..8ebedf9fed 100644 --- a/xfa/fxfa/parser/cxfa_object.cpp +++ b/xfa/fxfa/parser/cxfa_object.cpp @@ -8,7 +8,7 @@ #include "core/fxcrt/fx_extension.h" #include "fxjs/cfxjse_value.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodelist.h" diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp index fcf22442f1..115cd5651e 100644 --- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp +++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp @@ -14,8 +14,8 @@ #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_eventparam.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" #include "xfa/fxfa/parser/cxfa_node.h" diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index cd4aa57332..cbe0d14c91 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -10,7 +10,7 @@ #include "core/fxcrt/fx_extension.h" #include "fxbarcode/BC_Library.h" #include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/cxfa_ffnotify.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_event.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" -- cgit v1.2.3