Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cpwl_caret.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
"fpdfsdk/pwl/cpwl_caret.h"
8
9
#
include
<
sstream
>
10
#
include
<
utility
>
11
12
#
include
"core/fxge/cfx_fillrenderoptions.h"
13
#
include
"core/fxge/cfx_graphstatedata.h"
14
#
include
"core/fxge/cfx_path.h"
15
#
include
"core/fxge/cfx_renderdevice.h"
16
17
CPWL_Caret::
CPWL_Caret
(
18
const
CreateParams
& cp,
19
std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
20
:
CPWL_Wnd
(cp,
std
::move(pAttachedData)) {}
21
22
CPWL_Caret::~
CPWL_Caret
() =
default
;
23
24
void
CPWL_Caret::
DrawThisAppearance
(
CFX_RenderDevice
* pDevice,
25
const
CFX_Matrix
& mtUser2Device) {
26
if
(!
IsVisible
() || !m_bFlash)
27
return
;
28
29
CFX_FloatRect
rcRect = GetCaretRect();
30
CFX_FloatRect
rcClip =
GetClipRect
();
31
32
float
fCaretX = rcRect
.
left
+ m_fWidth * 0.5f;
33
float
fCaretTop = rcRect
.
top
;
34
float
fCaretBottom = rcRect
.
bottom
;
35
if
(!rcClip
.
IsEmpty
(
)
) {
36
rcRect
.
Intersect
(
rcClip
)
;
37
if
(rcRect
.
IsEmpty
(
)
)
38
return
;
39
40
fCaretTop = rcRect
.
top
;
41
fCaretBottom = rcRect
.
bottom
;
42
}
43
44
CFX_Path
path;
45
path
.
AppendPoint
(
CFX_PointF(fCaretX, fCaretBottom)
,
46
CFX_Path
::
Point
::
Type
::
kMove
)
;
47
path
.
AppendPoint
(
CFX_PointF(fCaretX, fCaretTop)
,
48
CFX_Path
::
Point
::
Type
::
kLine
)
;
49
50
CFX_GraphStateData
gsd;
51
gsd
.
m_LineWidth
= m_fWidth;
52
pDevice
->
DrawPath
(
path
,
&mtUser2Device
,
&gsd
,
0
,
ArgbEncode
(
255
,
0
,
0
,
0
)
,
53
CFX_FillRenderOptions
::
EvenOddOptions
(
)
)
;
54
}
55
56
void
CPWL_Caret::
OnTimerFired
() {
57
m_bFlash = !m_bFlash;
58
InvalidateRect
(
nullptr
)
;
59
// Note, |this| may no longer be viable at this point. If more work needs
60
// to be done, add an observer.
61
}
62
63
CFX_FloatRect
CPWL_Caret::GetCaretRect()
const
{
64
return
CFX_FloatRect(m_ptFoot.x, m_ptFoot.y, m_ptHead.x + m_fWidth,
65
m_ptHead.y);
66
}
67
68
void
CPWL_Caret::
SetCaret
(
bool
bVisible,
69
const
CFX_PointF
& ptHead,
70
const
CFX_PointF
& ptFoot) {
71
if
(!bVisible) {
72
m_ptHead = CFX_PointF();
73
m_ptFoot = CFX_PointF();
74
m_bFlash =
false
;
75
if
(!
IsVisible
())
76
return
;
77
78
m_pTimer.reset();
79
(
void
)
CPWL_Wnd
::
SetVisible
(
false
);
80
// Note, |this| may no longer be viable at this point. If more work needs
81
// to be done, check the return value of SetVisible().
82
return
;
83
}
84
85
if
(!
IsVisible
()) {
86
static
constexpr
int32_t kCaretFlashIntervalMs = 500;
87
88
m_ptHead = ptHead;
89
m_ptFoot = ptFoot;
90
m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(),
this
,
91
kCaretFlashIntervalMs);
92
93
if
(!
CPWL_Wnd
::
SetVisible
(
true
))
94
return
;
95
96
m_bFlash =
true
;
97
Move
(m_rcInvalid,
false
,
true
);
98
// Note, |this| may no longer be viable at this point. If more work needs
99
// to be done, check the return value of Move().
100
return
;
101
}
102
103
if
(m_ptHead == ptHead && m_ptFoot == ptFoot)
104
return
;
105
106
m_ptHead = ptHead;
107
m_ptFoot = ptFoot;
108
m_bFlash =
true
;
109
Move
(m_rcInvalid,
false
,
true
);
110
// Note, |this| may no longer be viable at this point. If more work
111
// needs to be done, check the return value of Move().
112
}
113
114
bool
CPWL_Caret::
InvalidateRect
(
const
CFX_FloatRect
* pRect) {
115
if
(!pRect)
116
return
CPWL_Wnd
::
InvalidateRect
(
nullptr
);
117
118
CFX_FloatRect
rcRefresh = *pRect;
119
if
(!rcRefresh
.
IsEmpty
(
)
) {
120
rcRefresh
.
Inflate
(
0.5f
,
0.5f
)
;
121
rcRefresh
.
Normalize
(
)
;
122
}
123
rcRefresh
.
top
+= 1;
124
rcRefresh
.
bottom
-= 1;
125
return
CPWL_Wnd
::
InvalidateRect
(&rcRefresh);
126
}
127
128
bool
CPWL_Caret::
SetVisible
(
bool
bVisible) {
129
return
true
;
130
}
CFX_FloatRect
Definition
fx_coordinates.h:185
CFX_FloatRect::IsEmpty
bool IsEmpty() const
Definition
fx_coordinates.h:200
CFX_FloatRect::left
float left
Definition
fx_coordinates.h:269
CFX_FloatRect::bottom
float bottom
Definition
fx_coordinates.h:270
CFX_FloatRect::Normalize
void Normalize()
Definition
fx_coordinates.cpp:154
CFX_FloatRect::Intersect
void Intersect(const CFX_FloatRect &other_rect)
Definition
fx_coordinates.cpp:161
CFX_FloatRect::Inflate
void Inflate(float x, float y)
Definition
fx_coordinates.cpp:245
CFX_FloatRect::top
float top
Definition
fx_coordinates.h:272
CFX_GraphStateData
Definition
cfx_graphstatedata.h:16
CFX_GraphStateData::m_LineWidth
float m_LineWidth
Definition
cfx_graphstatedata.h:34
CFX_Matrix
Definition
fx_coordinates.h:440
CFX_Path::Point
Definition
cfx_path.h:20
CFX_Path::Point::Type
Type
Definition
cfx_path.h:22
CFX_Path::Point::Type::kMove
@ kMove
Definition
cfx_path.h:22
CFX_Path::Point::Type::kLine
@ kLine
Definition
cfx_path.h:22
CFX_Path
Definition
cfx_path.h:18
CFX_Path::AppendPoint
void AppendPoint(const CFX_PointF &point, Point::Type type)
Definition
cfx_path.cpp:290
CFX_RenderDevice
Definition
cfx_renderdevice.h:39
CFX_RenderDevice::DrawPath
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options)
Definition
cfx_renderdevice.cpp:600
CPWL_Caret::SetVisible
bool SetVisible(bool bVisible) override
Definition
cpwl_caret.cpp:128
CPWL_Caret::InvalidateRect
bool InvalidateRect(const CFX_FloatRect *pRect) override
Definition
cpwl_caret.cpp:114
CPWL_Caret::DrawThisAppearance
void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device) override
Definition
cpwl_caret.cpp:24
CPWL_Caret::~CPWL_Caret
~CPWL_Caret() override
CPWL_Caret::SetCaret
void SetCaret(bool bVisible, const CFX_PointF &ptHead, const CFX_PointF &ptFoot)
Definition
cpwl_caret.cpp:68
CPWL_Caret::OnTimerFired
void OnTimerFired() override
Definition
cpwl_caret.cpp:56
CPWL_Caret::CPWL_Caret
CPWL_Caret(const CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData)
Definition
cpwl_caret.cpp:17
CPWL_Wnd::CreateParams
Definition
cpwl_wnd.h:96
CPWL_Wnd
Definition
cpwl_wnd.h:77
CPWL_Wnd::GetClipRect
const CFX_FloatRect & GetClipRect() const
Definition
cpwl_wnd.cpp:606
CPWL_Wnd::InvalidateRect
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
Definition
cpwl_wnd.cpp:278
CPWL_Wnd::IsVisible
bool IsVisible() const
Definition
cpwl_wnd.h:204
CPWL_Wnd::SetVisible
virtual bool SetVisible(bool bVisible)
Definition
cpwl_wnd.cpp:576
CPWL_Wnd::Move
bool Move(const CFX_FloatRect &rcNew, bool bReset, bool bRefresh)
Definition
cpwl_wnd.cpp:211
CFX_PointF
CFX_PTemplate< float > CFX_PointF
Definition
fx_coordinates.h:51
ArgbEncode
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition
fx_dib.h:188
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
CFX_FillRenderOptions
Definition
cfx_fillrenderoptions.h:11
CFX_FillRenderOptions::EvenOddOptions
static constexpr CFX_FillRenderOptions EvenOddOptions()
Definition
cfx_fillrenderoptions.h:26
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fpdfsdk
pwl
cpwl_caret.cpp
Generated on
for Qt by
1.18.0