Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: fpdfsdk/src/pdfwindow/PWL_Caret.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/pdfwindow/PDFWindow.h" 7 #include "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h" 8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_Caret.h" 9 #include "../../include/pdfwindow/PWL_Caret.h"
10 #include "../../include/pdfwindow/PWL_Utils.h" 10 #include "../../include/pdfwindow/PWL_Utils.h"
11 11
12 #define PWL_CARET_FLASHINTERVAL»» 500 12 #define PWL_CARET_FLASHINTERVAL 500
13 13
14 ////////////////////////////////////////////////////////////////////// 14 //////////////////////////////////////////////////////////////////////
15 // Construction/Destruction 15 // Construction/Destruction
16 ////////////////////////////////////////////////////////////////////// 16 //////////////////////////////////////////////////////////////////////
17 17
18 CPWL_Caret::CPWL_Caret() : 18 CPWL_Caret::CPWL_Caret()
19 » m_bFlash(FALSE), 19 : m_bFlash(FALSE),
20 » m_ptHead(0,0), 20 m_ptHead(0, 0),
21 » m_ptFoot(0,0), 21 m_ptFoot(0, 0),
22 » m_fWidth(0.4f), 22 m_fWidth(0.4f),
23 » m_nDelay(0) 23 m_nDelay(0) {
24 {
25 } 24 }
26 25
27 CPWL_Caret::~CPWL_Caret() 26 CPWL_Caret::~CPWL_Caret() {
28 {
29 } 27 }
30 28
31 CFX_ByteString CPWL_Caret::GetClassName() const 29 CFX_ByteString CPWL_Caret::GetClassName() const {
32 { 30 return "CPWL_Caret";
33 » return "CPWL_Caret";
34 } 31 }
35 32
36 void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream) 33 void CPWL_Caret::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
37 { 34 GetCaretApp(sAppStream, CPDF_Point(0.0f, 0.0f));
38 » GetCaretApp(sAppStream,CPDF_Point(0.0f,0.0f));
39 } 35 }
40 36
41 void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUse r2Device) 37 void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice,
42 { 38 CPDF_Matrix* pUser2Device) {
43 » if (IsVisible() && m_bFlash) 39 if (IsVisible() && m_bFlash) {
44 » { 40 CPDF_Rect rcRect = GetCaretRect();
45 » » CPDF_Rect rcRect = GetCaretRect(); 41 CPDF_Rect rcClip = GetClipRect();
46 » » CPDF_Rect rcClip = GetClipRect();
47 42
48 » » CFX_PathData path; 43 CFX_PathData path;
49 44
50 » » path.SetPointCount(2); 45 path.SetPointCount(2);
51 » »
52 » » FX_FLOAT fCaretX = rcRect.left + m_fWidth * 0.5f;
53 » » FX_FLOAT fCaretTop = rcRect.top;
54 » » FX_FLOAT fCaretBottom = rcRect.bottom;
55 46
56 » » if (!rcClip.IsEmpty()) 47 FX_FLOAT fCaretX = rcRect.left + m_fWidth * 0.5f;
57 » » { 48 FX_FLOAT fCaretTop = rcRect.top;
58 » » » rcRect.Intersect(rcClip); 49 FX_FLOAT fCaretBottom = rcRect.bottom;
59 » » » if (!rcRect.IsEmpty())
60 » » » {
61 » » » » fCaretTop = rcRect.top;
62 » » » » fCaretBottom = rcRect.bottom;
63 » » » » path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOV ETO);
64 » » » » path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO );
65 » » » }
66 » » » else
67 » » » {
68 » » » » return;
69 » » » }
70 » » }
71 » » else
72 » » {
73 » » » path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
74 » » » path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
75 » » }
76 50
77 » » CFX_GraphStateData gsd; 51 if (!rcClip.IsEmpty()) {
78 » » gsd.m_LineWidth = m_fWidth; 52 rcRect.Intersect(rcClip);
53 if (!rcRect.IsEmpty()) {
54 fCaretTop = rcRect.top;
55 fCaretBottom = rcRect.bottom;
56 path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
57 path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
58 } else {
59 return;
60 }
61 } else {
62 path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO);
63 path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO);
64 }
79 65
80 » » pDevice->DrawPath(&path, pUser2Device, &gsd,0, ArgbEncode(255,0 ,0,0), FXFILL_ALTERNATE); 66 CFX_GraphStateData gsd;
81 » } 67 gsd.m_LineWidth = m_fWidth;
68
69 pDevice->DrawPath(&path,
70 pUser2Device,
71 &gsd,
72 0,
73 ArgbEncode(255, 0, 0, 0),
74 FXFILL_ALTERNATE);
75 }
82 } 76 }
83 77
84 void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf & sAppStream,const CPDF_Point & ptO ffset) 78 void CPWL_Caret::GetCaretApp(CFX_ByteTextBuf& sAppStream,
85 { 79 const CPDF_Point& ptOffset) {
86 » if (IsVisible() && m_bFlash) 80 if (IsVisible() && m_bFlash) {
87 » {» 81 CFX_ByteTextBuf sCaret;
88 » » CFX_ByteTextBuf sCaret;
89 82
90 » » CPDF_Rect rcRect = GetCaretRect(); 83 CPDF_Rect rcRect = GetCaretRect();
91 » » CPDF_Rect rcClip = GetClipRect(); 84 CPDF_Rect rcClip = GetClipRect();
92 85
93 » » rcRect = CPWL_Utils::OffsetRect(rcRect,ptOffset.x,ptOffset.y); 86 rcRect = CPWL_Utils::OffsetRect(rcRect, ptOffset.x, ptOffset.y);
94 » » rcClip = CPWL_Utils::OffsetRect(rcClip,ptOffset.x,ptOffset.y); 87 rcClip = CPWL_Utils::OffsetRect(rcClip, ptOffset.x, ptOffset.y);
95 88
96 » » sCaret << "q\n"; 89 sCaret << "q\n";
97 » » if (!rcClip.IsEmpty()) 90 if (!rcClip.IsEmpty()) {
98 » » { 91 sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " "
99 » » » sCaret << rcClip.left << " " << rcClip.bottom + 2.5f << " " 92 << rcClip.right - rcClip.left << " "
100 » » » » << rcClip.right - rcClip.left << " " << rcClip.t op - rcClip.bottom - 4.5f << " re W n\n"; 93 << rcClip.top - rcClip.bottom - 4.5f << " re W n\n";
101 » » } 94 }
102 » » sCaret << m_fWidth << " w\n0 G\n"; 95 sCaret << m_fWidth << " w\n0 G\n";
103 » » sCaret << rcRect.left + m_fWidth/2 << " " << rcRect.bottom << " m\n"; 96 sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.bottom << " m\n";
104 » » sCaret << rcRect.left + m_fWidth/2 << " " << rcRect.top << " l S \nQ\n";» 97 sCaret << rcRect.left + m_fWidth / 2 << " " << rcRect.top << " l S\nQ\n";
105 98
106 » » sAppStream << sCaret;» 99 sAppStream << sCaret;
107 » } 100 }
108 } 101 }
109 102
110 CFX_ByteString CPWL_Caret::GetCaretAppearanceStream(const CPDF_Point & ptOffset) 103 CFX_ByteString CPWL_Caret::GetCaretAppearanceStream(
111 { 104 const CPDF_Point& ptOffset) {
112 » CFX_ByteTextBuf sCaret; 105 CFX_ByteTextBuf sCaret;
113 » GetCaretApp(sCaret,ptOffset); 106 GetCaretApp(sCaret, ptOffset);
114 » return sCaret.GetByteString(); 107 return sCaret.GetByteString();
115 } 108 }
116 109
117 void CPWL_Caret::TimerProc() 110 void CPWL_Caret::TimerProc() {
118 { 111 if (m_nDelay > 0) {
119 » if (m_nDelay > 0) 112 m_nDelay--;
120 » { 113 } else {
121 » » m_nDelay--;» 114 m_bFlash = !m_bFlash;
122 » } 115 InvalidateRect();
123 » else 116 }
124 » {
125 » » m_bFlash = !m_bFlash;
126 » » InvalidateRect();
127 » }
128 } 117 }
129 118
130 CPDF_Rect CPWL_Caret::GetCaretRect() const 119 CPDF_Rect CPWL_Caret::GetCaretRect() const {
131 { 120 return CPDF_Rect(
132 » return CPDF_Rect(m_ptFoot.x, 121 m_ptFoot.x, m_ptFoot.y, m_ptHead.x + this->m_fWidth, m_ptHead.y);
133 » » » m_ptFoot.y,
134 » » » m_ptHead.x + this->m_fWidth,
135 » » » m_ptHead.y);
136 } 122 }
137 123
138 void CPWL_Caret::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPD F_Point & ptFoot) 124 void CPWL_Caret::SetCaret(FX_BOOL bVisible,
139 { 125 const CPDF_Point& ptHead,
140 » if (bVisible) 126 const CPDF_Point& ptFoot) {
141 » {» 127 if (bVisible) {
142 » » if (IsVisible()) 128 if (IsVisible()) {
143 » » { 129 if (m_ptHead.x != ptHead.x || m_ptHead.y != ptHead.y ||
144 » » » if (m_ptHead.x != ptHead.x || m_ptHead.y != ptHead.y || 130 m_ptFoot.x != ptFoot.x || m_ptFoot.y != ptFoot.y) {
145 » » » » » m_ptFoot.x != ptFoot.x || m_ptFoot.y != ptFoot.y) 131 this->m_ptHead = ptHead;
146 » » » { 132 this->m_ptFoot = ptFoot;
147 » » » » this->m_ptHead = ptHead;
148 » » » » this->m_ptFoot = ptFoot;
149 133
150 » » » » m_bFlash = TRUE; 134 m_bFlash = TRUE;
151 » » » » //Move(GetCaretRect(),FALSE,TRUE); 135 // Move(GetCaretRect(),FALSE,TRUE);
152 » » » » Move(m_rcInvalid, FALSE, TRUE); 136 Move(m_rcInvalid, FALSE, TRUE);
153 » » » } 137 }
154 » » } 138 } else {
155 » » else 139 this->m_ptHead = ptHead;
156 » » { 140 this->m_ptFoot = ptFoot;
157 » » » this->m_ptHead = ptHead;
158 » » » this->m_ptFoot = ptFoot;
159 141
160 » » » EndTimer(); 142 EndTimer();
161 » » » BeginTimer(PWL_CARET_FLASHINTERVAL); 143 BeginTimer(PWL_CARET_FLASHINTERVAL);
162 » » »
163 » » » CPWL_Wnd::SetVisible(TRUE);
164 » » » m_bFlash = TRUE;
165 144
166 » » » //Move(GetCaretRect(),FALSE,TRUE);» 145 CPWL_Wnd::SetVisible(TRUE);
167 » » » Move(m_rcInvalid, FALSE, TRUE); 146 m_bFlash = TRUE;
168 » » }» »
169 » }
170 » else
171 » {
172 » » this->m_ptHead = CPDF_Point(0,0);
173 » » this->m_ptFoot = CPDF_Point(0,0);
174 147
175 » » m_bFlash = FALSE; 148 // Move(GetCaretRect(),FALSE,TRUE);
176 » » if (IsVisible()) 149 Move(m_rcInvalid, FALSE, TRUE);
177 » » { 150 }
178 » » » EndTimer(); 151 } else {
179 » » » CPWL_Wnd::SetVisible(FALSE); 152 this->m_ptHead = CPDF_Point(0, 0);
180 » » }» » 153 this->m_ptFoot = CPDF_Point(0, 0);
181 » } 154
155 m_bFlash = FALSE;
156 if (IsVisible()) {
157 EndTimer();
158 CPWL_Wnd::SetVisible(FALSE);
159 }
160 }
182 } 161 }
183 162
184 void CPWL_Caret::InvalidateRect(CPDF_Rect * pRect) 163 void CPWL_Caret::InvalidateRect(CPDF_Rect* pRect) {
185 { 164 if (pRect) {
186 » if (pRect) 165 CPDF_Rect rcRefresh = CPWL_Utils::InflateRect(*pRect, 0.5f);
187 » { 166 rcRefresh.top += 1;
188 » » CPDF_Rect rcRefresh = CPWL_Utils::InflateRect(*pRect,0.5f); 167 rcRefresh.bottom -= 1;
189 » » rcRefresh.top += 1; 168
190 » » rcRefresh.bottom -= 1;» 169 CPWL_Wnd::InvalidateRect(&rcRefresh);
191 » » 170 } else
192 » » CPWL_Wnd::InvalidateRect(&rcRefresh); 171 CPWL_Wnd::InvalidateRect(pRect);
193 » }
194 » else
195 » » CPWL_Wnd::InvalidateRect(pRect);
196 } 172 }
197
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698