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
cfwl_widget.cpp
Go to the documentation of this file.
1// Copyright 2014 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 "xfa/fwl/cfwl_widget.h"
8
9#include <algorithm>
10#include <utility>
11#include <vector>
12
13#include "third_party/base/check.h"
14#include "v8/include/cppgc/visitor.h"
15#include "xfa/fde/cfde_textout.h"
16#include "xfa/fwl/cfwl_app.h"
17#include "xfa/fwl/cfwl_combobox.h"
18#include "xfa/fwl/cfwl_event.h"
19#include "xfa/fwl/cfwl_eventmouse.h"
20#include "xfa/fwl/cfwl_messagekey.h"
21#include "xfa/fwl/cfwl_messagekillfocus.h"
22#include "xfa/fwl/cfwl_messagemouse.h"
23#include "xfa/fwl/cfwl_messagemousewheel.h"
24#include "xfa/fwl/cfwl_messagesetfocus.h"
25#include "xfa/fwl/cfwl_notedriver.h"
26#include "xfa/fwl/cfwl_themebackground.h"
27#include "xfa/fwl/cfwl_themepart.h"
28#include "xfa/fwl/cfwl_themetext.h"
29#include "xfa/fwl/cfwl_widgetmgr.h"
30#include "xfa/fwl/ifwl_themeprovider.h"
31
32namespace {
33
34constexpr float kCalcHeight = 2048.0f;
35constexpr float kCalcWidth = 2048.0f;
36constexpr float kCalcMultiLineDefWidth = 120.0f;
37
38} // namespace
39
40CFWL_Widget::CFWL_Widget(CFWL_App* app,
41 const Properties& properties,
42 CFWL_Widget* pOuter)
43 : m_Properties(properties),
47 m_pWidgetMgr->InsertWidget(m_pOuter, this);
48}
49
50CFWL_Widget::~CFWL_Widget() = default;
51
53 CHECK(!IsLocked()); // Prefer hard stop to UaF.
54 NotifyDriver();
55 m_pWidgetMgr->RemoveWidget(this);
56}
57
58void CFWL_Widget::Trace(cppgc::Visitor* visitor) const {
59 visitor->Trace(m_pAdapterIface);
60 visitor->Trace(m_pFWLApp);
61 visitor->Trace(m_pWidgetMgr);
62 visitor->Trace(m_pDelegate);
63 visitor->Trace(m_pOuter);
64}
65
66bool CFWL_Widget::IsForm() const {
67 return false;
68}
69
73
77
79 if (!HasBorder())
80 return;
81
82 float fBorder = GetCXBorderSize();
83 rect.Inflate(fBorder, fBorder);
84}
85
87 m_WidgetRect = rect;
88}
89
93
94void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded,
95 uint32_t dwStylesRemoved) {
96 m_Properties.m_dwStyles &= ~dwStylesRemoved;
97 m_Properties.m_dwStyles |= dwStylesAdded;
98}
99
100void CFWL_Widget::ModifyStyleExts(uint32_t dwStyleExtsAdded,
101 uint32_t dwStyleExtsRemoved) {
102 m_Properties.m_dwStyleExts &= ~dwStyleExtsRemoved;
103 m_Properties.m_dwStyleExts |= dwStyleExtsAdded;
104}
105
106static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr,
107 CFWL_Widget* widget,
108 CFWL_NoteDriver* noteDriver) {
109 CFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget);
110 while (child) {
111 noteDriver->NotifyTargetHide(child);
112 NotifyHideChildWidget(widgetMgr, child, noteDriver);
113 child = widgetMgr->GetNextSiblingWidget(child);
114 }
115}
116
117void CFWL_Widget::SetStates(uint32_t dwStates) {
118 m_Properties.m_dwStates |= dwStates;
119 if (IsVisible())
120 return;
121
122 CFWL_NoteDriver* noteDriver = GetFWLApp()->GetNoteDriver();
123 noteDriver->NotifyTargetHide(this);
124
125 CFWL_WidgetMgr* widgetMgr = GetFWLApp()->GetWidgetMgr();
126 CFWL_Widget* child = widgetMgr->GetFirstChildWidget(this);
127 while (child) {
128 noteDriver->NotifyTargetHide(child);
129 NotifyHideChildWidget(widgetMgr, child, noteDriver);
130 child = widgetMgr->GetNextSiblingWidget(child);
131 }
132}
133
134void CFWL_Widget::RemoveStates(uint32_t dwStates) {
135 m_Properties.m_dwStates &= ~dwStates;
136}
137
145
147 const CFX_PointF& point) {
148 CFX_SizeF szOffset;
149 if (IsParent(pWidget)) {
150 szOffset = GetOffsetFromParent(pWidget);
151 } else {
152 szOffset = pWidget->GetOffsetFromParent(this);
153 szOffset.width = -szOffset.width;
154 szOffset.height = -szOffset.height;
155 }
156 return point + CFX_PointF(szOffset.width, szOffset.height);
157}
158
160 CFWL_Widget* parent = GetParent();
161 std::vector<CFWL_Widget*> parents;
162 while (parent) {
163 parents.push_back(parent);
164 parent = parent->GetParent();
165 }
166
167 CFX_Matrix matrix;
168 for (size_t i = parents.size(); i >= 2; i--) {
169 CFX_RectF rect = parents[i - 2]->GetWidgetRect();
170 matrix.TranslatePrepend(rect.left, rect.top);
171 }
172 return matrix;
173}
174
178
179bool CFWL_Widget::IsEnabled() const {
181}
182
186
190
195
196bool CFWL_Widget::IsPopup() const {
198}
199
200bool CFWL_Widget::IsChild() const {
202}
203
205 CFWL_Widget* pOuter = const_cast<CFWL_Widget*>(this);
206 while (pOuter->GetOuter())
207 pOuter = pOuter->GetOuter();
208 return pOuter;
209}
210
217
221
225
229
230CFX_SizeF CFWL_Widget::CalcTextSize(const WideString& wsText, bool bMultiLine) {
231 CFWL_ThemeText calPart(CFWL_ThemePart::Part::kNone, this, nullptr);
232 calPart.m_wsText = wsText;
233 if (bMultiLine)
234 calPart.m_dwTTOStyles.line_wrap_ = true;
235 else
236 calPart.m_dwTTOStyles.single_line_ = true;
237
239 float fWidth = bMultiLine ? kCalcMultiLineDefWidth : kCalcWidth;
240 CFX_RectF rect(0, 0, fWidth, kCalcHeight);
242 return CFX_SizeF(rect.width, rect.height);
243}
244
245void CFWL_Widget::CalcTextRect(const WideString& wsText,
246 const FDE_TextStyle& dwTTOStyles,
247 FDE_TextAlignment iTTOAlign,
248 CFX_RectF* pRect) {
249 CFWL_ThemeText calPart(CFWL_ThemePart::Part::kNone, this, nullptr);
250 calPart.m_wsText = wsText;
251 calPart.m_dwTTOStyles = dwTTOStyles;
252 calPart.m_iTTOAlign = iTTOAlign;
254}
255
256void CFWL_Widget::SetGrab(bool bSet) {
257 CFWL_NoteDriver* pDriver = GetFWLApp()->GetNoteDriver();
258 pDriver->SetGrab(bSet ? this : nullptr);
259}
260
262 CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
263 pNoteDriver->UnregisterEventTarget(this);
264}
265
267 if (m_pOuter) {
268 m_pOuter->GetDelegate()->OnProcessEvent(pEvent);
269 return;
270 }
271 CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
272 pNoteDriver->SendEvent(pEvent);
273}
274
275void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) {
276 m_pWidgetMgr->RepaintWidget(this, pRect);
277}
278
279void CFWL_Widget::DrawBackground(CFGAS_GEGraphics* pGraphics,
280 CFWL_ThemePart::Part iPartBk,
281 const CFX_Matrix& mtMatrix) {
282 CFWL_ThemeBackground param(iPartBk, this, pGraphics);
283 param.m_matrix = mtMatrix;
286}
287
289 CFWL_ThemePart::Part iPartBorder,
290 const CFX_Matrix& matrix) {
291 CFWL_ThemeBackground param(iPartBorder, this, pGraphics);
292 param.m_matrix = matrix;
295}
296
297void CFWL_Widget::NotifyDriver() {
298 CFWL_NoteDriver* pDriver = GetFWLApp()->GetNoteDriver();
299 pDriver->NotifyTargetDestroy(this);
300}
301
302CFX_SizeF CFWL_Widget::GetOffsetFromParent(CFWL_Widget* pParent) {
303 if (pParent == this)
304 return CFX_SizeF();
305
306 CFX_SizeF szRet(m_WidgetRect.left, m_WidgetRect.top);
307 CFWL_WidgetMgr* pWidgetMgr = GetFWLApp()->GetWidgetMgr();
308 CFWL_Widget* pDstWidget = GetParent();
309 while (pDstWidget && pDstWidget != pParent) {
310 CFX_RectF rtDst = pDstWidget->GetWidgetRect();
311 szRet += CFX_SizeF(rtDst.left, rtDst.top);
312 pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget);
313 }
314 return szRet;
315}
316
317bool CFWL_Widget::IsParent(CFWL_Widget* pParent) {
318 CFWL_Widget* pUpWidget = GetParent();
319 while (pUpWidget) {
320 if (pUpWidget == pParent)
321 return true;
322 pUpWidget = pUpWidget->GetParent();
323 }
324 return false;
325}
326
328 CFWL_Widget* pWidget = pMessage->GetDstTarget();
329 if (!pWidget)
330 return;
331
332 switch (pMessage->GetType()) {
334 CFWL_MessageMouse* pMsgMouse = static_cast<CFWL_MessageMouse*>(pMessage);
335 CFWL_EventMouse evt(pWidget, pWidget, pMsgMouse->m_dwCmd);
336 pWidget->DispatchEvent(&evt);
337 break;
338 }
339 default:
340 break;
341 }
342}
343
345
347 : widget_(widget) {
348 widget_->LockUpdate();
349}
350
352 widget_->UnlockUpdate();
353}
FDE_TextAlignment
Definition cfde_data.h:12
static void NotifyHideChildWidget(CFWL_WidgetMgr *widgetMgr, CFWL_Widget *widget, CFWL_NoteDriver *noteDriver)
#define FWL_STYLE_WGT_Child
Definition cfwl_widget.h:34
#define FWL_STYLE_WGT_Popup
Definition cfwl_widget.h:33
#define FWL_STATE_WGT_Invisible
Definition cfwl_widget.h:43
#define FWL_STYLE_WGT_OverLapper
Definition cfwl_widget.h:32
#define FWL_STATE_WGT_Disabled
Definition cfwl_widget.h:41
#define FWL_STYLE_WGT_Border
Definition cfwl_widget.h:36
#define FWL_STYLE_WGT_WindowTypeMask
Definition cfwl_widget.h:35
CFWL_NoteDriver * GetNoteDriver() const
Definition cfwl_app.h:47
CFWL_WidgetMgr * GetWidgetMgr() const
Definition cfwl_app.h:46
IFWL_ThemeProvider * GetThemeProvider() const
Definition cfwl_app.h:42
CFWL_EventMouse(CFWL_Widget *pSrcTarget, CFWL_Widget *pDstTarget, CFWL_MessageMouse::MouseCommand cmd)
const MouseCommand m_dwCmd
Type GetType() const
CFWL_Widget * GetDstTarget() const
void NotifyTargetHide(CFWL_Widget *pNoteTarget)
void SendEvent(CFWL_Event *pNote)
void UnregisterEventTarget(CFWL_Widget *pListener)
void SetGrab(CFWL_Widget *pGrab)
void NotifyTargetDestroy(CFWL_Widget *pNoteTarget)
CFWL_ThemeBackground(Part iPart, CFWL_Widget *pWidget, CFGAS_GEGraphics *pGraphics)
CFX_RectF m_PartRect
CFX_Matrix m_matrix
FDE_TextStyle m_dwTTOStyles
CFWL_ThemeText(Part iPart, CFWL_Widget *pWidget, CFGAS_GEGraphics *pGraphics)
FDE_TextAlignment m_iTTOAlign
CFWL_Widget * GetNextSiblingWidget(CFWL_Widget *pWidget) const
CFWL_Widget * GetFirstChildWidget(CFWL_Widget *pWidget) const
CFWL_Widget * GetParentWidget(const CFWL_Widget *pWidget) const
ScopedUpdateLock(CFWL_Widget *widget)
void InflateWidgetRect(CFX_RectF &rect)
CFWL_Widget(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
virtual void SetStates(uint32_t dwStates)
Properties m_Properties
CFWL_Widget * GetOuter() const
bool IsOverLapper() const
void OnProcessMessage(CFWL_Message *pMessage) override
bool IsVisible() const
virtual FWL_WidgetHit HitTest(const CFX_PointF &point)
float GetCXBorderSize() const
CFX_RectF GetEdgeRect() const
virtual bool IsForm() const
CFX_PointF TransformTo(CFWL_Widget *pWidget, const CFX_PointF &point)
bool HasBorder() const
CFX_RectF m_WidgetRect
void DrawBorder(CFGAS_GEGraphics *pGraphics, CFWL_ThemePart::Part iPartBorder, const CFX_Matrix &pMatrix)
void RepaintRect(const CFX_RectF &pRect)
virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
float GetCYBorderSize() const
virtual CFX_RectF GetWidgetRect()
IFWL_ThemeProvider * GetThemeProvider() const
void CalcTextRect(const WideString &wsText, const FDE_TextStyle &dwTTOStyles, FDE_TextAlignment iTTOAlign, CFX_RectF *pRect)
bool IsEnabled() const
void SetGrab(bool bSet)
virtual CFX_RectF GetClientRect()
void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved)
CFX_Matrix GetMatrix() const
virtual void RemoveStates(uint32_t dwStates)
bool IsPopup() const
~CFWL_Widget() override
void DispatchEvent(CFWL_Event *pEvent)
void OnProcessEvent(CFWL_Event *pEvent) override
CFWL_Widget * GetOutmost() const
void SetWidgetRect(const CFX_RectF &rect)
bool IsLocked() const
virtual void PreFinalize()
CFX_SizeF CalcTextSize(const WideString &wsText, bool bMultiLine)
CFX_RectF GetRelativeRect() const
void UnregisterEventTarget()
CFWL_App * GetFWLApp() const
bool IsChild() const
virtual CFX_RectF GetAutosizedWidgetRect()
CFX_Matrix & operator=(const CFX_Matrix &other)=default
void TranslatePrepend(float x, float y)
constexpr CFX_RectF()=default
void Inflate(float x, float y)
CFX_RectF & operator=(const CFX_RectF &other)=default
bool Contains(const PointType &p) const
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void Deflate(float x, float y)
virtual void DrawBackground(const CFWL_ThemeBackground &pParams)=0
virtual float GetCXBorderSize() const =0
virtual float GetCYBorderSize() const =0
virtual void CalcTextRect(const CFWL_ThemeText &pParams, CFX_RectF *pRect)=0
FWL_WidgetHit
#define CHECK(cvref)
bool single_line_
Definition cfde_data.h:29
bool line_wrap_
Definition cfde_data.h:30