summaryrefslogtreecommitdiff
path: root/fxjs/cjs_field.cpp
AgeCommit message (Collapse)Author
2018-08-17Rename CJS_Return to CJS_Result.Tom Sepez
"Return" is a verb, and "return" is a reserved-word at that, so avoid using it as part of a class name. Fully mechanical change apart from rename. Change-Id: I120e453e8ba001c4ab74a39e2da6aa6eb590835f Reviewed-on: https://pdfium-review.googlesource.com/40532 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-17Introduce safer CJS_Return::Success() and Failure().Tom Sepez
Avoid the possibility of ever re-introducing the issue noticed last week. Remove some redundant JSGetStringFromID() calls. Change-Id: I56687c2191bd72e378f747083f34080e50cbe490 Reviewed-on: https://pdfium-review.googlesource.com/40490 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-16Replace optional bool bNotify with enum type.Tom Sepez
Adds clarity to the call sites. Change-Id: Id4deed9adda2ad79f0847d618792429044d4f7d6 Reviewed-on: https://pdfium-review.googlesource.com/40351 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-14Remove optional argument from NewFXJSBoundObject().Tom Sepez
Additionally, we have a pre-existing enum type that is more meaningful than just a boolean. Change-Id: Ie6ad13a3c9b22e34dedf7a5a9b5b9cc2a49b1f03 Reviewed-on: https://pdfium-review.googlesource.com/40190 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-08Move ByteString::FromUnicode() to WideString::ToDefANSI()Tom Sepez
Turns out that "FromUnicode" is misleading in that, on linux, it simply removes any characters beyond 0xFF and passes the rest unchanged, so no unicode decoding actually takes place. On Windows, it passes it into the system function specifying FX_CODEPAGE_DefANSI, converting it into the so-called "default ANSI code plane", passing some characters, converting others to '?' and still others to 'A'. Either way, nothing resembling UTF8 comes out of this, so pick a better name. These now immediately look suspicious, so a follow-up CL will see which ones should really be WideString::UTF8Encode() instead. Making this a normal method on a widestring rather than a static method on a bytestring feels more natural; this is parallel to the UTF8Encode and UTF16LE_Encode functions. Add a test that shows these conversions. Change-Id: Ia7551b47199eba61b5c328a97bfe9176ac8e583c Reviewed-on: https://pdfium-review.googlesource.com/39690 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-26Be more careful casting to widget subclasses.Tom Sepez
Part of the effort to reduce unchecked static casts. Change-Id: I1bff1c53aa7c5804660de4b65cf01523d70fcbb7 Reviewed-on: https://pdfium-review.googlesource.com/38896 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-12Move CJS_Field private methods into an anonymous namespace.Lei Zhang
Change-Id: Ib758cfc97a4e2bb94f58afa999608f77c0972336 Reviewed-on: https://pdfium-review.googlesource.com/37730 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-07-12Remove parameter to CJS_Field::GetFormFields().Lei Zhang
It is always the same value. Also mark ValueIsOccur() as const. Change-Id: Ifdfc33f8213ed272e7d36e1e4c2de1d2070fbcbd Reviewed-on: https://pdfium-review.googlesource.com/37712 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-12Add CJS_Field::GetFirstFormField().Lei Zhang
Its what many CJS_Field methods really want to do. Change-Id: I18cf61a15be7b783b795c61a5c26c42ef5d82127 Reviewed-on: https://pdfium-review.googlesource.com/37711 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-12Add more helper functions to check field types in CJS_Field.Lei Zhang
These types are commonly checked together. - IsComboBoxOrListBox() - IsComboBoxOrTextField() Change-Id: Ia363bd9822f8dfe61e11cf552ec516f9403a8fcc Reviewed-on: https://pdfium-review.googlesource.com/37673 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-12Add a IsCheckBoxOrRadioButton() helper for CJS_Field.Lei Zhang
Change-Id: I0e06d641d482cbcd2cf33f327d9504e55a772157 Reviewed-on: https://pdfium-review.googlesource.com/37672 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-06-26Use ObservedPtr for CJS_Field::m_pJSFieldTom Sepez
Bug: 856354 Change-Id: Ic0ac4d189dff6f4688a6c5feb745fe8c5a5ed4bb Reviewed-on: https://pdfium-review.googlesource.com/36150 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-20Re-work some more c_str() usage.Tom Sepez
Many of these are converting ByteString => c_str => ByteStringView, since the ByteStringView ctor is implicit. This is unfortunate, since that involves a strlen() which the ByteString already knows if we use AsStringView() instead. This changed one test result where we can now return the string "\0" instead of "" -- since strlen no longer eats the NUL. This seems consistent, say, with String.fromCharCode(). Change-Id: I17f68d1a1f4b352960208f9148e68ab4c4d78bd2 Reviewed-on: https://pdfium-review.googlesource.com/35590 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-12Rework "Make common page base class."Tom Sepez
Re-landing of https://pdfium-review.googlesource.com/c/pdfium/+/32892 This time, however, we do not build on the previous CL which cached pages. This CL by itself should be OK but was reverted only because it was blocking earlier reverts. Change-Id: I067d5f07373eeac6cced5d0c113ea40e5f8dcd15 Reviewed-on: https://pdfium-review.googlesource.com/34910 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-11Use spans in CJS_Object.Tom Sepez
Avoid explicitly having to count items in arrays. Change-Id: I24a91db45e8a8530f38afcc273e824ffb70a6cb9 Reviewed-on: https://pdfium-review.googlesource.com/34710 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-06-08Ensure CJS_Return() with error always includes a message.Tom Sepez
Change the signature of the constructors to make it impossible to do this otherwise. Change-Id: I14e88d98a1128f2d599459ce9337cd6d079469fe Reviewed-on: https://pdfium-review.googlesource.com/34531 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-06Stop using some v8::Context slot to find runtime.Tom Sepez
Instead, use the object binding's pointer. Puts the cart back behind the horse. Change-Id: I4c06ae991b871c6e90b0e6c70b69886addca2354 Reviewed-on: https://pdfium-review.googlesource.com/33630 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-05Tidy parser lifecycle state machine in CPDF_PageObjectHolder.Tom Sepez
Only update state in CPDF_PageObjectHolder itself. Make more data private. Remove CPDF_Page::GetPageBBox() as exact duplicate of CPDF_PageObjectHolder::GetBBox(). Change-Id: I083ec33f61a1490e7a5e673c9787751af15a6cd1 Reviewed-on: https://pdfium-review.googlesource.com/33810 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-04Make CJS_Objects track CJS_Runtime (and hence the document itself)Tom Sepez
Precursor to removing some more v8::Context slot dependency. There's a cost to maintaining the set of observers, but since these objects are tied to V8 lifetimes, not C++ lifetimes, we want to be very wary of the document going away unexpectedly. Change-Id: I579f58a460aa50b88cb861227c9aca9a8a83ce12 Reviewed-on: https://pdfium-review.googlesource.com/33471 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-04Revert "Make common page base class for XFA and non-XFA."Tom Sepez
This reverts commit d06cc38b76685b002c51b227ae43b8314d926ad8. Reason for revert: blocking previous revert Change-Id: I74f8b80852c671440cca5fabef30e69cde9e2063 Reviewed-on: https://pdfium-review.googlesource.com/33713 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-05-30Make common page base class for XFA and non-XFA.Tom Sepez
Now that both are ref-counted, we can replace ifdef's with some polymorphism. Bug: pdfium:760 Change-Id: Ie22ea259c9af56fa569f0af268b8e7065789a3f2 Reviewed-on: https://pdfium-review.googlesource.com/32892 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-04-27Remove argument from CPDFSDK_FormFillEnvironment::GetCurrentPageTom Sepez
Small tidying. The form fill environment is 1:1 with documents, and already knows its underlying document. The callers all first obtain this from the FFE and then pass it back into it. Change-Id: I33835c1dc847ca67f2cc633c87af2f6e003ef58a Reviewed-on: https://pdfium-review.googlesource.com/31591 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-04-03Remove DefaultAppearance HasColor and return an optional insteadDan Sinclair
This CL converts CPDF_DefaultAppearance to return Optional<CFX_Color:Type> items instead of having a HasColor. This saves the double parse of the appearance stream. Change-Id: Ib3c136da6e2adfb559e495de1d299cce0b4ad25f Reviewed-on: https://pdfium-review.googlesource.com/29630 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-03-28Remove CPDF_DefaultAppearance reference paramsDan Sinclair
This CL converts the CPDF_DefaultAppearance::GetColor methods to return instead of using reference parameters. Change-Id: I9ba6bf060a536290a83d3c9ce6e115511f28664c Reviewed-on: https://pdfium-review.googlesource.com/29410 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-02-07Split creation of ordinary object and bound objects in FXJS.chromium/3343Tom Sepez
One can be performed by the CJS_V8 layer, the other requires the full FXJS mechanism. Avoids using -1 as a special case. Change-Id: I4a14ccb6a7fea393f84b70a07ada03b1a83c7d36 Reviewed-on: https://pdfium-review.googlesource.com/25830 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-02-05Fold CJS_EmbedObj classes into CJS_Object classesDan Sinclair
This CL removes the CJS_EmbedObj class and various subclasses and folds the subclasses into their CJS_Object counterparts. Change-Id: If6b882a4995c0b1bf83ac783f5c27ba9216c2d5c Reviewed-on: https://pdfium-review.googlesource.com/25410 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2018-02-05Remove the CJS_EmbedObj template param from JSConstructor.Dan Sinclair
Each of the CJS_Objects can create their CJS_EmbedObj's internally and we don't need to do it though the JSConstructor. This also removes the need for the SetEmbedObj method in CJS_Object. Change-Id: Ib0535ad922b370634fd1e622a04860a96c4f2825 Reviewed-on: https://pdfium-review.googlesource.com/25370 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-02-05Use unique pointer in CFXJS_PerObjectData.Tom Sepez
Also use the actual type information, not void* and remove casts. Template function not required to wrap virtual dtors. Change-Id: I9397cae136c3c395a368a1ef0ce8162d9b586076 Reviewed-on: https://pdfium-review.googlesource.com/25290 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-01-29Kill some bare |new|s in cjs_field.cppTom Sepez
Change-Id: Id4d9f21d94d8b21199846ec5f7613590fd20579e Reviewed-on: https://pdfium-review.googlesource.com/24310 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-01-29Fix identical if/else blocks.Lei Zhang
The CPWL_EditImpl::Backspace() instance occurred in commit 671a799. The other two instances where known cases. BUG=chromium:805881 Change-Id: Iae7cb8534e85342069d8753ced88543dad751e92 Reviewed-on: https://pdfium-review.googlesource.com/24050 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-01-12Use enum for tracking form field typesRyan Harrison
Within PDFium use enum class for better type safety when working with form field types. These values will still be converted to ints as part of the public API, since that is the existing API. This work is preperation for extending the number of form field types to have more specific entries for XFA. BUG=pdfium:952,chromium:763129,chromium:592758 Change-Id: Ie6c29f02ae22be782ff36eb87d27f1a4bf2c099e Reviewed-on: https://pdfium-review.googlesource.com/22742 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2017-12-12[js] Convert to using size instead of sentinelsDan Sinclair
This CL changes the DefineMethod, DefineProps and DefineConsts methods to pass a size instead of depending on a sentinel value in the definition arrays. Change-Id: Ie054544124290c0833a8b21af175a203ca99591a Reviewed-on: https://pdfium-review.googlesource.com/20551 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-10-30Convert JS resource into enum classchromium/3254Dan Sinclair
This CL converts the #defines into an enum class. Change-Id: I895e29e1d46a7a82d7be896f5776eb00d28559f5 Reviewed-on: https://pdfium-review.googlesource.com/17091 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-10-30Move fpdfsdk/javascript to fxjs/Dan Sinclair
This CL moves all of the CJS files into fxjs. The :javascript build rule is removed and :fxjs is used instead. Change-Id: I1701b308f51317d0346c7401b43812c3f43a27bf Reviewed-on: https://pdfium-review.googlesource.com/17047 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>