Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdfxfa_widget.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
8
9#include "core/fxcrt/check.h"
10#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
11#include "fpdfsdk/cpdfsdk_pageview.h"
12#include "xfa/fgas/graphics/cfgas_gegraphics.h"
13#include "xfa/fxfa/cxfa_ffdocview.h"
14#include "xfa/fxfa/cxfa_ffpageview.h"
15#include "xfa/fxfa/cxfa_ffwidget.h"
16#include "xfa/fxfa/cxfa_ffwidgethandler.h"
17#include "xfa/fxfa/parser/cxfa_node.h"
18
19#define CHECK_FWL_VKEY_ENUM____(name)
20 static_assert(
21 static_cast<int>(name) == static_cast<int>(pdfium::XFA_##name),
22 "FWL_VKEYCODE enum mismatch")
23
26CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NewLine);
28CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Return);
30CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Control);
33CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Capital);
35CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Hangul);
40CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Escape);
41CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Convert);
42CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NonConvert);
43CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Accept);
44CHECK_FWL_VKEY_ENUM____(FWL_VKEY_ModeChange);
54CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Select);
56CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Execute);
57CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Snapshot);
58CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Insert);
59CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Delete);
98CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Command);
102CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad0);
103CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad1);
104CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad2);
105CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad3);
106CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad4);
107CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad5);
108CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad6);
109CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad7);
110CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad8);
111CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad9);
112CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Multiply);
114CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Separator);
115CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Subtract);
116CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Decimal);
117CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Divide);
142CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NunLock);
143CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Scroll);
144CHECK_FWL_VKEY_ENUM____(FWL_VKEY_LShift);
145CHECK_FWL_VKEY_ENUM____(FWL_VKEY_RShift);
146CHECK_FWL_VKEY_ENUM____(FWL_VKEY_LControl);
147CHECK_FWL_VKEY_ENUM____(FWL_VKEY_RControl);
150CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Back);
151CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Forward);
152CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Refresh);
153CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Stop);
154CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Search);
155CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Favorites);
156CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Home);
157CHECK_FWL_VKEY_ENUM____(FWL_VKEY_VOLUME_Mute);
158CHECK_FWL_VKEY_ENUM____(FWL_VKEY_VOLUME_Down);
159CHECK_FWL_VKEY_ENUM____(FWL_VKEY_VOLUME_Up);
160CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_NEXT_Track);
161CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_PREV_Track);
162CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_Stop);
163CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_PLAY_Pause);
164CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_Mail);
165CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_MEDIA_Select);
166CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_APP1);
167CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_APP2);
169CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Plus);
170CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Comma);
171CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Minus);
172CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Period);
180CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_102);
181CHECK_FWL_VKEY_ENUM____(FWL_VKEY_ProcessKey);
182CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Packet);
189CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NoName);
191CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Clear);
192CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Unknown);
193
194#undef CHECK_FWL_VKEY_ENUM____
195
196namespace {
197
198Mask<XFA_FWL_KeyFlag> GetKeyFlags(Mask<FWL_EVENTFLAG> input) {
199 Mask<XFA_FWL_KeyFlag> results;
200
201 if (input & FWL_EVENTFLAG_ControlKey)
202 results |= XFA_FWL_KeyFlag::kCtrl;
204 results |= XFA_FWL_KeyFlag::kLButton;
206 results |= XFA_FWL_KeyFlag::kMButton;
208 results |= XFA_FWL_KeyFlag::kRButton;
209 if (input & FWL_EVENTFLAG_ShiftKey)
210 results |= XFA_FWL_KeyFlag::kShift;
211 if (input & FWL_EVENTFLAG_AltKey)
212 results |= XFA_FWL_KeyFlag::kAlt;
213
214 return results;
215}
216
217} // namespace
218
219CPDFXFA_Widget::CPDFXFA_Widget(CXFA_FFWidget* pXFAFFWidget,
220 CPDFSDK_PageView* pPageView)
222
223CPDFXFA_Widget::~CPDFXFA_Widget() = default;
224
225CPDFXFA_Widget* CPDFXFA_Widget::AsXFAWidget() {
226 return this;
227}
228
230 return this;
231}
232
233CPDF_Annot::Subtype CPDFXFA_Widget::GetAnnotSubtype() const {
235}
236
240
241void CPDFXFA_Widget::OnDraw(CFX_RenderDevice* pDevice,
242 const CFX_Matrix& mtUser2Device,
243 bool bDrawAnnots) {
244 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
245 if (!widget_handler)
246 return;
247
248 CFGAS_GEGraphics gs(pDevice);
249 bool is_highlight = GetPageView()->GetFormFillEnv()->GetFocusAnnot() != this;
250 widget_handler->RenderWidget(GetXFAFFWidget(), &gs, mtUser2Device,
251 is_highlight);
252
253 // to do highlight and shadow
254}
255
256bool CPDFXFA_Widget::DoHitTest(const CFX_PointF& point) {
257 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
258 if (!widget_handler)
259 return false;
260
261 return widget_handler->HitTest(GetXFAFFWidget(), point) !=
263}
264
265bool CPDFXFA_Widget::OnChangedFocus() {
266 CXFA_FFDocView* doc_view = GetDocView();
267 if (!doc_view)
268 return false;
269
271 if (doc_view->SetFocus(widget))
272 return false;
273
274 return doc_view->GetFocusWidget() != widget;
275}
276
277CFX_FloatRect CPDFXFA_Widget::GetViewBBox() {
279 CXFA_Node* node = widget->GetNode();
280 DCHECK(node->IsWidgetReady());
281
282 CFX_RectF bbox =
286
287 CFX_FloatRect result = bbox.ToFloatRect();
288 result.Inflate(1.0f, 1.0f);
289 return result;
290}
291
292void CPDFXFA_Widget::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) {
293 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
294 if (widget_handler)
296}
297
298void CPDFXFA_Widget::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) {
299 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
300 if (widget_handler)
302}
303
304bool CPDFXFA_Widget::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
305 const CFX_PointF& point) {
306 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
307 return widget_handler && widget_handler->OnLButtonDown(
308 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
309}
310
311bool CPDFXFA_Widget::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
312 const CFX_PointF& point) {
313 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
314 return widget_handler && widget_handler->OnLButtonUp(
315 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
316}
317
318bool CPDFXFA_Widget::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
319 const CFX_PointF& point) {
320 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
321 return widget_handler && widget_handler->OnLButtonDblClk(
322 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
323}
324
325bool CPDFXFA_Widget::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
326 const CFX_PointF& point) {
327 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
328 return widget_handler && widget_handler->OnMouseMove(
329 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
330}
331
332bool CPDFXFA_Widget::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
333 const CFX_PointF& point,
334 const CFX_Vector& delta) {
335 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
336 return widget_handler &&
337 widget_handler->OnMouseWheel(GetXFAFFWidget(), GetKeyFlags(nFlags),
338 point, delta);
339}
340
341bool CPDFXFA_Widget::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
342 const CFX_PointF& point) {
343 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
344 return widget_handler && widget_handler->OnRButtonDown(
345 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
346}
347
348bool CPDFXFA_Widget::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
349 const CFX_PointF& point) {
350 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
351 return widget_handler && widget_handler->OnRButtonUp(
352 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
353}
354
355bool CPDFXFA_Widget::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
356 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
357 return widget_handler &&
358 widget_handler->OnChar(GetXFAFFWidget(), nChar, GetKeyFlags(nFlags));
359}
360
361bool CPDFXFA_Widget::OnKeyDown(FWL_VKEYCODE nKeyCode,
362 Mask<FWL_EVENTFLAG> nFlags) {
363 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
364 return widget_handler &&
365 widget_handler->OnKeyDown(GetXFAFFWidget(),
366 static_cast<XFA_FWL_VKEYCODE>(nKeyCode),
367 GetKeyFlags(nFlags));
368}
369
370bool CPDFXFA_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
371 return true;
372}
373
374bool CPDFXFA_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
375 CXFA_FFDocView* doc_view = GetDocView();
376 if (doc_view)
377 doc_view->SetFocus(nullptr);
378 return true;
379}
380
381bool CPDFXFA_Widget::CanUndo() {
382 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
383 return widget_handler && widget_handler->CanUndo(GetXFAFFWidget());
384}
385
386bool CPDFXFA_Widget::CanRedo() {
387 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
388 return widget_handler && widget_handler->CanRedo(GetXFAFFWidget());
389}
390
391bool CPDFXFA_Widget::Undo() {
392 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
393 return widget_handler && widget_handler->Undo(GetXFAFFWidget());
394}
395
396bool CPDFXFA_Widget::Redo() {
397 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
398 return widget_handler && widget_handler->Redo(GetXFAFFWidget());
399}
400
401WideString CPDFXFA_Widget::GetText() {
402 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
403 if (!widget_handler)
404 return WideString();
405 return widget_handler->GetText(GetXFAFFWidget());
406}
407
408WideString CPDFXFA_Widget::GetSelectedText() {
409 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
410 if (!widget_handler)
411 return WideString();
412 return widget_handler->GetSelectedText(GetXFAFFWidget());
413}
414
415void CPDFXFA_Widget::ReplaceAndKeepSelection(const WideString& text) {
416 // XFA does not seem to support IME input at all. Therefore we don't bother
417 // to keep selection for IMEs.
419}
420
421void CPDFXFA_Widget::ReplaceSelection(const WideString& text) {
422 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
423 if (widget_handler)
424 widget_handler->PasteText(GetXFAFFWidget(), text);
425}
426
427bool CPDFXFA_Widget::SelectAllText() {
428 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
429 return widget_handler && widget_handler->SelectAllText(GetXFAFFWidget());
430}
431
432bool CPDFXFA_Widget::SetIndexSelected(int index, bool selected) {
433 return false;
434}
435
436bool CPDFXFA_Widget::IsIndexSelected(int index) {
437 return false;
438}
439
440CXFA_FFDocView* CPDFXFA_Widget::GetDocView() {
441 CXFA_FFPageView* page_view = GetXFAFFWidget()->GetPageView();
442 return page_view ? page_view->GetDocView() : nullptr;
443}
444
445CXFA_FFWidgetHandler* CPDFXFA_Widget::GetWidgetHandler() {
446 CXFA_FFDocView* doc_view = GetDocView();
447 return doc_view ? doc_view->GetWidgetHandler() : nullptr;
448}
#define DCHECK
Definition check.h:33
CFGAS_GEGraphics(CFX_RenderDevice *renderDevice)
void Inflate(float x, float y)
CFX_FloatRect ToFloatRect() const
CPDFSDK_Annot(CPDFSDK_PageView *pPageView)
CPDFSDK_PageView * GetPageView() const
CXFA_FFWidget * GetXFAFFWidget() const
bool DoHitTest(const CFX_PointF &point) override
void ReplaceSelection(const WideString &text) override
~CPDFXFA_Widget() override
bool Redo() override
WideString GetSelectedText() override
void OnMouseEnter(Mask< FWL_EVENTFLAG > nFlags) override
bool Undo() override
bool OnSetFocus(Mask< FWL_EVENTFLAG > nFlags) override
bool SetIndexSelected(int index, bool selected) override
bool SelectAllText() override
bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
CFX_FloatRect GetViewBBox() override
bool CanUndo() override
bool OnKillFocus(Mask< FWL_EVENTFLAG > nFlags) override
bool IsIndexSelected(int index) override
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlags) override
bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
bool OnMouseWheel(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point, const CFX_Vector &delta) override
CPDF_Annot::Subtype GetAnnotSubtype() const override
bool OnRButtonDown(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
CPDFSDK_Annot::UnsafeInputHandlers * GetUnsafeInputHandlers() override
WideString GetText() override
CPDFXFA_Widget(CXFA_FFWidget *pXFAFFWidget, CPDFSDK_PageView *pPageView)
CPDFXFA_Widget * AsXFAWidget() override
void OnMouseExit(Mask< FWL_EVENTFLAG > nFlags) override
bool CanRedo() override
bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
CFX_FloatRect GetRect() const override
bool OnLButtonDblClk(Mask< FWL_EVENTFLAG > nFlags, const CFX_PointF &point) override
bool OnChar(uint32_t nChar, Mask< FWL_EVENTFLAG > nFlags) override
void OnDraw(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device, bool bDrawAnnots) override
void ReplaceAndKeepSelection(const WideString &text) override
CXFA_FFWidgetHandler * GetWidgetHandler()
bool SetFocus(CXFA_FFWidget *pNewFocus)
CXFA_FFWidget * GetFocusWidget() const
CXFA_FFDocView * GetDocView() const
WideString GetText(CXFA_FFWidget *widget)
bool Redo(CXFA_FFWidget *widget)
bool CanUndo(CXFA_FFWidget *widget)
bool CanRedo(CXFA_FFWidget *widget)
pdfium::FWL_WidgetHit HitTest(CXFA_FFWidget *pWidget, const CFX_PointF &point)
bool OnMouseEnter(CXFA_FFWidget *hWidget)
WideString GetSelectedText(CXFA_FFWidget *widget)
void RenderWidget(CXFA_FFWidget *hWidget, CFGAS_GEGraphics *pGS, const CFX_Matrix &matrix, bool bHighlight)
bool SelectAllText(CXFA_FFWidget *widget)
bool Undo(CXFA_FFWidget *widget)
void PasteText(CXFA_FFWidget *widget, const WideString &text)
bool OnMouseExit(CXFA_FFWidget *hWidget)
CXFA_Node * GetNode() const
virtual CFX_RectF GetBBox(FocusOption focus)
CXFA_ContentLayoutItem * GetLayoutItem() const
CXFA_FFPageView * GetPageView() const
XFA_FFWidgetType GetFFWidgetType()
WideString()=default
#define CHECK_FWL_VKEY_ENUM____(name)
XFA_FFWidgetType
@ FWL_EVENTFLAG_ShiftKey
@ FWL_EVENTFLAG_RightButtonDown
@ FWL_EVENTFLAG_LeftButtonDown
@ FWL_EVENTFLAG_MiddleButtonDown
@ FWL_EVENTFLAG_AltKey
@ FWL_EVENTFLAG_ControlKey
CFX_VTemplate< int32_t > CFX_Vector
CFX_PTemplate< float > CFX_PointF
fxcrt::WideString WideString
Definition widestring.h:207