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

Side by Side Diff: xfa/fwl/core/cfwl_edit.cpp

Issue 2535623002: Cleanup caret show/hide code (Closed)
Patch Set: Rebase to master Created 4 years 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
« no previous file with comments | « xfa/fwl/core/cfwl_edit.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "xfa/fwl/core/cfwl_edit.h" 7 #include "xfa/fwl/core/cfwl_edit.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 m_iMaxRecord(128) { 74 m_iMaxRecord(128) {
75 m_rtClient.Reset(); 75 m_rtClient.Reset();
76 m_rtEngine.Reset(); 76 m_rtEngine.Reset();
77 m_rtStatic.Reset(); 77 m_rtStatic.Reset();
78 78
79 InitCaret(); 79 InitCaret();
80 } 80 }
81 81
82 CFWL_Edit::~CFWL_Edit() { 82 CFWL_Edit::~CFWL_Edit() {
83 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) 83 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
84 ShowCaret(false); 84 HideCaret(nullptr);
85 ClearRecord(); 85 ClearRecord();
86 } 86 }
87 87
88 FWL_Type CFWL_Edit::GetClassID() const { 88 FWL_Type CFWL_Edit::GetClassID() const {
89 return FWL_Type::Edit; 89 return FWL_Type::Edit;
90 } 90 }
91 91
92 void CFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { 92 void CFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
93 if (!bAutoSize) { 93 if (!bAutoSize) {
94 rect = m_pProperties->m_rtWidget; 94 rect = m_pProperties->m_rtWidget;
(...skipping 23 matching lines...) Expand all
118 wsText, m_pProperties->m_pThemeProvider, 118 wsText, m_pProperties->m_pThemeProvider,
119 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); 119 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine));
120 rect.Set(0, 0, sz.x, sz.y); 120 rect.Set(0, 0, sz.x, sz.y);
121 } 121 }
122 CFWL_Widget::GetWidgetRect(rect, true); 122 CFWL_Widget::GetWidgetRect(rect, true);
123 } 123 }
124 124
125 void CFWL_Edit::SetStates(uint32_t dwStates, bool bSet) { 125 void CFWL_Edit::SetStates(uint32_t dwStates, bool bSet) {
126 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || 126 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) ||
127 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { 127 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
128 ShowCaret(false); 128 HideCaret(nullptr);
129 } 129 }
130 CFWL_Widget::SetStates(dwStates, bSet); 130 CFWL_Widget::SetStates(dwStates, bSet);
131 } 131 }
132 132
133 void CFWL_Edit::Update() { 133 void CFWL_Edit::Update() {
134 if (IsLocked()) 134 if (IsLocked())
135 return; 135 return;
136 if (!m_pProperties->m_pThemeProvider) 136 if (!m_pProperties->m_pThemeProvider)
137 m_pProperties->m_pThemeProvider = GetAvailableTheme(); 137 m_pProperties->m_pThemeProvider = GetAvailableTheme();
138 138
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 CFX_RectF rtClient; 883 CFX_RectF rtClient;
884 GetClientRect(rtClient); 884 GetClientRect(rtClient);
885 rtCaret.Intersect(rtClient); 885 rtCaret.Intersect(rtClient);
886 886
887 if (rtCaret.left > rtClient.right()) { 887 if (rtCaret.left > rtClient.right()) {
888 FX_FLOAT right = rtCaret.right(); 888 FX_FLOAT right = rtCaret.right();
889 rtCaret.left = rtClient.right() - 1; 889 rtCaret.left = rtClient.right() - 1;
890 rtCaret.width = right - rtCaret.left; 890 rtCaret.width = right - rtCaret.left;
891 } 891 }
892 892
893 bool bShow = 893 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty())
894 m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty(); 894 ShowCaret(&rtCaret);
895 ShowCaret(bShow, &rtCaret); 895 else
896 HideCaret(&rtCaret);
896 } 897 }
897 898
898 CFWL_ScrollBar* CFWL_Edit::UpdateScroll() { 899 CFWL_ScrollBar* CFWL_Edit::UpdateScroll() {
899 bool bShowHorz = 900 bool bShowHorz =
900 m_pHorzScrollBar && 901 m_pHorzScrollBar &&
901 ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); 902 ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0);
902 bool bShowVert = 903 bool bShowVert =
903 m_pVertScrollBar && 904 m_pVertScrollBar &&
904 ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); 905 ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0);
905 if (!bShowHorz && !bShowVert) 906 if (!bShowHorz && !bShowVert)
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 prop->m_pParent = this; 1160 prop->m_pParent = this;
1160 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; 1161 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
1161 1162
1162 CFWL_ScrollBar* sb = new CFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); 1163 CFWL_ScrollBar* sb = new CFWL_ScrollBar(m_pOwnerApp, std::move(prop), this);
1163 if (bVert) 1164 if (bVert)
1164 m_pVertScrollBar.reset(sb); 1165 m_pVertScrollBar.reset(sb);
1165 else 1166 else
1166 m_pHorzScrollBar.reset(sb); 1167 m_pHorzScrollBar.reset(sb);
1167 } 1168 }
1168 1169
1169 bool FWL_ShowCaret(CFWL_Widget* pWidget, 1170 void CFWL_Edit::ShowCaret(CFX_RectF* pRect) {
1170 bool bVisible,
1171 const CFX_RectF* pRtAnchor) {
1172 CXFA_FFWidget* pXFAWidget =
1173 static_cast<CXFA_FFWidget*>(pWidget->GetLayoutItem());
1174 if (!pXFAWidget)
1175 return false;
1176
1177 IXFA_DocEnvironment* pDocEnvironment =
1178 pXFAWidget->GetDoc()->GetDocEnvironment();
1179 if (!pDocEnvironment)
1180 return false;
1181
1182 if (bVisible) {
1183 CFX_Matrix mt;
1184 pXFAWidget->GetRotateMatrix(mt);
1185 CFX_RectF rt(*pRtAnchor);
1186 mt.TransformRect(rt);
1187 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt);
1188 return true;
1189 }
1190
1191 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor);
1192 return true;
1193 }
1194
1195 void CFWL_Edit::ShowCaret(bool bVisible, CFX_RectF* pRect) {
1196 if (m_pCaret) { 1171 if (m_pCaret) {
1197 m_pCaret->ShowCaret(bVisible); 1172 m_pCaret->ShowCaret();
1198 if (bVisible && !pRect->IsEmpty()) 1173 if (!pRect->IsEmpty())
1199 m_pCaret->SetWidgetRect(*pRect); 1174 m_pCaret->SetWidgetRect(*pRect);
1200 Repaint(&m_rtEngine); 1175 Repaint(&m_rtEngine);
1201 return; 1176 return;
1202 } 1177 }
1203 1178
1204 CFWL_Widget* pOuter = this; 1179 CFWL_Widget* pOuter = this;
1205 if (bVisible) { 1180 pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top);
1206 pRect->Offset(m_pProperties->m_rtWidget.left,
1207 m_pProperties->m_rtWidget.top);
1208 }
1209 while (pOuter->GetOuter()) { 1181 while (pOuter->GetOuter()) {
1210 pOuter = pOuter->GetOuter(); 1182 pOuter = pOuter->GetOuter();
1211 if (bVisible) { 1183
1212 CFX_RectF rtOuter; 1184 CFX_RectF rtOuter;
1213 pOuter->GetWidgetRect(rtOuter); 1185 pOuter->GetWidgetRect(rtOuter);
1214 pRect->Offset(rtOuter.left, rtOuter.top); 1186 pRect->Offset(rtOuter.left, rtOuter.top);
1215 }
1216 } 1187 }
1217 FWL_ShowCaret(pOuter, bVisible, pRect); 1188
1189 CXFA_FFWidget* pXFAWidget =
1190 static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem());
1191 if (!pXFAWidget)
1192 return;
1193
1194 IXFA_DocEnvironment* pDocEnvironment =
1195 pXFAWidget->GetDoc()->GetDocEnvironment();
1196 if (!pDocEnvironment)
1197 return;
1198
1199 CFX_Matrix mt;
1200 pXFAWidget->GetRotateMatrix(mt);
1201
1202 CFX_RectF rt(*pRect);
1203 mt.TransformRect(rt);
1204 pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt);
1205 }
1206
1207 void CFWL_Edit::HideCaret(CFX_RectF* pRect) {
1208 if (m_pCaret) {
1209 m_pCaret->HideCaret();
1210 Repaint(&m_rtEngine);
1211 return;
1212 }
1213
1214 CFWL_Widget* pOuter = this;
1215 while (pOuter->GetOuter())
1216 pOuter = pOuter->GetOuter();
1217
1218 CXFA_FFWidget* pXFAWidget =
1219 static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem());
1220 if (!pXFAWidget)
1221 return;
1222
1223 IXFA_DocEnvironment* pDocEnvironment =
1224 pXFAWidget->GetDoc()->GetDocEnvironment();
1225 if (!pDocEnvironment)
1226 return;
1227
1228 pDocEnvironment->DisplayCaret(pXFAWidget, false, pRect);
1218 } 1229 }
1219 1230
1220 bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { 1231 bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) {
1221 if (!m_bSetRange) 1232 if (!m_bSetRange)
1222 return true; 1233 return true;
1223 1234
1224 CFX_WideString wsText = m_EdtEngine.GetText(0); 1235 CFX_WideString wsText = m_EdtEngine.GetText(0);
1225 if (wsText.IsEmpty()) { 1236 if (wsText.IsEmpty()) {
1226 if (cNum == L'0') 1237 if (cNum == L'0')
1227 return false; 1238 return false;
(...skipping 15 matching lines...) Expand all
1243 } 1254 }
1244 1255
1245 if (wsText.GetInteger() <= m_iMax) 1256 if (wsText.GetInteger() <= m_iMax)
1246 return true; 1257 return true;
1247 return false; 1258 return false;
1248 } 1259 }
1249 1260
1250 void CFWL_Edit::InitCaret() { 1261 void CFWL_Edit::InitCaret() {
1251 if (!m_pCaret) { 1262 if (!m_pCaret) {
1252 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { 1263 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) {
1253 m_pCaret.reset(new CFWL_Caret( 1264 m_pCaret = pdfium::MakeUnique<CFWL_Caret>(
1254 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this)); 1265 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this);
1255 m_pCaret->SetParent(this); 1266 m_pCaret->SetParent(this);
1256 m_pCaret->SetStates(m_pProperties->m_dwStates); 1267 m_pCaret->SetStates(m_pProperties->m_dwStates);
1257 } 1268 }
1258 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) == 1269 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) ==
1259 0) { 1270 0) {
1260 m_pCaret.reset(); 1271 m_pCaret.reset();
1261 } 1272 }
1262 } 1273 }
1263 1274
1264 void CFWL_Edit::ClearRecord() { 1275 void CFWL_Edit::ClearRecord() {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 uint32_t dwStyleEx = GetStylesEx(); 1375 uint32_t dwStyleEx = GetStylesEx();
1365 bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret); 1376 bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret);
1366 if (bSet) { 1377 if (bSet) {
1367 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; 1378 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
1368 1379
1369 UpdateVAlignment(); 1380 UpdateVAlignment();
1370 UpdateOffset(); 1381 UpdateOffset();
1371 UpdateCaret(); 1382 UpdateCaret();
1372 } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { 1383 } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
1373 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; 1384 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
1374 ShowCaret(false); 1385 HideCaret(nullptr);
1375 if ((dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) { 1386 if ((dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) {
1376 int32_t nSel = CountSelRanges(); 1387 int32_t nSel = CountSelRanges();
1377 if (nSel > 0) { 1388 if (nSel > 0) {
1378 ClearSelections(); 1389 ClearSelections();
1379 bRepaint = true; 1390 bRepaint = true;
1380 } 1391 }
1381 m_EdtEngine.SetCaretPos(0, true); 1392 m_EdtEngine.SetCaretPos(0, true);
1382 UpdateOffset(); 1393 UpdateOffset();
1383 } 1394 }
1384 ClearRecord(); 1395 ClearRecord();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 UpdateOffset(pScrollBar, fPos - iCurPos); 1647 UpdateOffset(pScrollBar, fPos - iCurPos);
1637 UpdateCaret(); 1648 UpdateCaret();
1638 1649
1639 CFX_RectF rect; 1650 CFX_RectF rect;
1640 GetWidgetRect(rect); 1651 GetWidgetRect(rect);
1641 CFX_RectF rtInvalidate; 1652 CFX_RectF rtInvalidate;
1642 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); 1653 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2);
1643 Repaint(&rtInvalidate); 1654 Repaint(&rtInvalidate);
1644 return true; 1655 return true;
1645 } 1656 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/cfwl_edit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698