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 "fpdfsdk/cpdfsdk_formfillenvironment.h"
10#include "fpdfsdk/cpdfsdk_pageview.h"
11#include "third_party/base/check.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(static_cast<int>(name) == static_cast<int>(XFA_##name),
21 "FWL_VKEYCODE enum mismatch")
22
25CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NewLine);
27CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Return);
29CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Control);
32CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Capital);
34CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Hangul);
39CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Escape);
40CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Convert);
41CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NonConvert);
42CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Accept);
43CHECK_FWL_VKEY_ENUM____(FWL_VKEY_ModeChange);
53CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Select);
55CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Execute);
56CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Snapshot);
57CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Insert);
58CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Delete);
97CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Command);
101CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad0);
102CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad1);
103CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad2);
104CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad3);
105CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad4);
106CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad5);
107CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad6);
108CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad7);
109CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad8);
110CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NumPad9);
111CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Multiply);
113CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Separator);
114CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Subtract);
115CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Decimal);
116CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Divide);
141CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NunLock);
142CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Scroll);
143CHECK_FWL_VKEY_ENUM____(FWL_VKEY_LShift);
144CHECK_FWL_VKEY_ENUM____(FWL_VKEY_RShift);
145CHECK_FWL_VKEY_ENUM____(FWL_VKEY_LControl);
146CHECK_FWL_VKEY_ENUM____(FWL_VKEY_RControl);
149CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Back);
150CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Forward);
151CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Refresh);
152CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Stop);
153CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Search);
154CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Favorites);
155CHECK_FWL_VKEY_ENUM____(FWL_VKEY_BROWSER_Home);
156CHECK_FWL_VKEY_ENUM____(FWL_VKEY_VOLUME_Mute);
157CHECK_FWL_VKEY_ENUM____(FWL_VKEY_VOLUME_Down);
158CHECK_FWL_VKEY_ENUM____(FWL_VKEY_VOLUME_Up);
159CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_NEXT_Track);
160CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_PREV_Track);
161CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_Stop);
162CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_PLAY_Pause);
163CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_Mail);
164CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_MEDIA_Select);
165CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_APP1);
166CHECK_FWL_VKEY_ENUM____(FWL_VKEY_MEDIA_LAUNCH_APP2);
168CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Plus);
169CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Comma);
170CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Minus);
171CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Period);
179CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_102);
180CHECK_FWL_VKEY_ENUM____(FWL_VKEY_ProcessKey);
181CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Packet);
188CHECK_FWL_VKEY_ENUM____(FWL_VKEY_NoName);
190CHECK_FWL_VKEY_ENUM____(FWL_VKEY_OEM_Clear);
191CHECK_FWL_VKEY_ENUM____(FWL_VKEY_Unknown);
192
193#undef CHECK_FWL_VKEY_ENUM____
194
195namespace {
196
197Mask<XFA_FWL_KeyFlag> GetKeyFlags(Mask<FWL_EVENTFLAG> input) {
198 Mask<XFA_FWL_KeyFlag> results;
199
200 if (input & FWL_EVENTFLAG_ControlKey)
201 results |= XFA_FWL_KeyFlag::kCtrl;
203 results |= XFA_FWL_KeyFlag::kLButton;
205 results |= XFA_FWL_KeyFlag::kMButton;
207 results |= XFA_FWL_KeyFlag::kRButton;
208 if (input & FWL_EVENTFLAG_ShiftKey)
209 results |= XFA_FWL_KeyFlag::kShift;
210 if (input & FWL_EVENTFLAG_AltKey)
211 results |= XFA_FWL_KeyFlag::kAlt;
212
213 return results;
214}
215
216} // namespace
217
218CPDFXFA_Widget::CPDFXFA_Widget(CXFA_FFWidget* pXFAFFWidget,
219 CPDFSDK_PageView* pPageView)
221
222CPDFXFA_Widget::~CPDFXFA_Widget() = default;
223
224CPDFXFA_Widget* CPDFXFA_Widget::AsXFAWidget() {
225 return this;
226}
227
229 return this;
230}
231
232CPDF_Annot::Subtype CPDFXFA_Widget::GetAnnotSubtype() const {
234}
235
239
240void CPDFXFA_Widget::OnDraw(CFX_RenderDevice* pDevice,
241 const CFX_Matrix& mtUser2Device,
242 bool bDrawAnnots) {
243 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
244 if (!widget_handler)
245 return;
246
247 CFGAS_GEGraphics gs(pDevice);
248 bool is_highlight = GetPageView()->GetFormFillEnv()->GetFocusAnnot() != this;
249 widget_handler->RenderWidget(GetXFAFFWidget(), &gs, mtUser2Device,
250 is_highlight);
251
252 // to do highlight and shadow
253}
254
255bool CPDFXFA_Widget::DoHitTest(const CFX_PointF& point) {
256 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
257 if (!widget_handler)
258 return false;
259
260 return widget_handler->HitTest(GetXFAFFWidget(), point) !=
262}
263
264bool CPDFXFA_Widget::OnChangedFocus() {
265 CXFA_FFDocView* doc_view = GetDocView();
266 if (!doc_view)
267 return false;
268
270 if (doc_view->SetFocus(widget))
271 return false;
272
273 return doc_view->GetFocusWidget() != widget;
274}
275
276CFX_FloatRect CPDFXFA_Widget::GetViewBBox() {
278 CXFA_Node* node = widget->GetNode();
279 DCHECK(node->IsWidgetReady());
280
281 CFX_RectF bbox =
285
286 CFX_FloatRect result = bbox.ToFloatRect();
287 result.Inflate(1.0f, 1.0f);
288 return result;
289}
290
291void CPDFXFA_Widget::OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) {
292 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
293 if (widget_handler)
295}
296
297void CPDFXFA_Widget::OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) {
298 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
299 if (widget_handler)
301}
302
303bool CPDFXFA_Widget::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags,
304 const CFX_PointF& point) {
305 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
306 return widget_handler && widget_handler->OnLButtonDown(
307 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
308}
309
310bool CPDFXFA_Widget::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags,
311 const CFX_PointF& point) {
312 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
313 return widget_handler && widget_handler->OnLButtonUp(
314 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
315}
316
317bool CPDFXFA_Widget::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags,
318 const CFX_PointF& point) {
319 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
320 return widget_handler && widget_handler->OnLButtonDblClk(
321 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
322}
323
324bool CPDFXFA_Widget::OnMouseMove(Mask<FWL_EVENTFLAG> nFlags,
325 const CFX_PointF& point) {
326 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
327 return widget_handler && widget_handler->OnMouseMove(
328 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
329}
330
331bool CPDFXFA_Widget::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags,
332 const CFX_PointF& point,
333 const CFX_Vector& delta) {
334 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
335 return widget_handler &&
336 widget_handler->OnMouseWheel(GetXFAFFWidget(), GetKeyFlags(nFlags),
337 point, delta);
338}
339
340bool CPDFXFA_Widget::OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags,
341 const CFX_PointF& point) {
342 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
343 return widget_handler && widget_handler->OnRButtonDown(
344 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
345}
346
347bool CPDFXFA_Widget::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags,
348 const CFX_PointF& point) {
349 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
350 return widget_handler && widget_handler->OnRButtonUp(
351 GetXFAFFWidget(), GetKeyFlags(nFlags), point);
352}
353
354bool CPDFXFA_Widget::OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) {
355 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
356 return widget_handler &&
357 widget_handler->OnChar(GetXFAFFWidget(), nChar, GetKeyFlags(nFlags));
358}
359
360bool CPDFXFA_Widget::OnKeyDown(FWL_VKEYCODE nKeyCode,
361 Mask<FWL_EVENTFLAG> nFlags) {
362 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
363 return widget_handler &&
364 widget_handler->OnKeyDown(GetXFAFFWidget(),
365 static_cast<XFA_FWL_VKEYCODE>(nKeyCode),
366 GetKeyFlags(nFlags));
367}
368
369bool CPDFXFA_Widget::OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) {
370 return true;
371}
372
373bool CPDFXFA_Widget::OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) {
374 CXFA_FFDocView* doc_view = GetDocView();
375 if (doc_view)
376 doc_view->SetFocus(nullptr);
377 return true;
378}
379
380bool CPDFXFA_Widget::CanUndo() {
381 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
382 return widget_handler && widget_handler->CanUndo(GetXFAFFWidget());
383}
384
385bool CPDFXFA_Widget::CanRedo() {
386 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
387 return widget_handler && widget_handler->CanRedo(GetXFAFFWidget());
388}
389
390bool CPDFXFA_Widget::Undo() {
391 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
392 return widget_handler && widget_handler->Undo(GetXFAFFWidget());
393}
394
395bool CPDFXFA_Widget::Redo() {
396 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
397 return widget_handler && widget_handler->Redo(GetXFAFFWidget());
398}
399
400WideString CPDFXFA_Widget::GetText() {
401 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
402 if (!widget_handler)
403 return WideString();
404 return widget_handler->GetText(GetXFAFFWidget());
405}
406
407WideString CPDFXFA_Widget::GetSelectedText() {
408 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
409 if (!widget_handler)
410 return WideString();
411 return widget_handler->GetSelectedText(GetXFAFFWidget());
412}
413
414void CPDFXFA_Widget::ReplaceAndKeepSelection(const WideString& text) {
415 // XFA does not seem to support IME input at all. Therefore we don't bother
416 // to keep selection for IMEs.
418}
419
420void CPDFXFA_Widget::ReplaceSelection(const WideString& text) {
421 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
422 if (widget_handler)
423 widget_handler->PasteText(GetXFAFFWidget(), text);
424}
425
426bool CPDFXFA_Widget::SelectAllText() {
427 CXFA_FFWidgetHandler* widget_handler = GetWidgetHandler();
428 return widget_handler && widget_handler->SelectAllText(GetXFAFFWidget());
429}
430
431bool CPDFXFA_Widget::SetIndexSelected(int index, bool selected) {
432 return false;
433}
434
435bool CPDFXFA_Widget::IsIndexSelected(int index) {
436 return false;
437}
438
439CXFA_FFDocView* CPDFXFA_Widget::GetDocView() {
440 CXFA_FFPageView* page_view = GetXFAFFWidget()->GetPageView();
441 return page_view ? page_view->GetDocView() : nullptr;
442}
443
444CXFA_FFWidgetHandler* CPDFXFA_Widget::GetWidgetHandler() {
445 CXFA_FFDocView* doc_view = GetDocView();
446 return doc_view ? doc_view->GetWidgetHandler() : nullptr;
447}
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)
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()
#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
XFA_FWL_KeyFlag
FWL_WidgetHit