summaryrefslogtreecommitdiff
path: root/xfa/fwl/core
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-12-07 17:12:59 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-07 17:12:59 -0800
commit919c0842b74d382e7ae60c85ff16642b646afbb9 (patch)
tree9518c8f10639f90cc63549a1bb068b43a0661d46 /xfa/fwl/core
parent4614b45a6592530c4cd930f139c366ce20d359f4 (diff)
downloadpdfium-919c0842b74d382e7ae60c85ff16642b646afbb9.tar.xz
Cleanup caret show/hide code
This CL splits the cursor code into specific show/hide methods to make it clearer what is happening at each point. Review-Url: https://codereview.chromium.org/2535623002
Diffstat (limited to 'xfa/fwl/core')
-rw-r--r--xfa/fwl/core/cfwl_caret.cpp14
-rw-r--r--xfa/fwl/core/cfwl_caret.h3
-rw-r--r--xfa/fwl/core/cfwl_comboedit.cpp2
-rw-r--r--xfa/fwl/core/cfwl_edit.cpp91
-rw-r--r--xfa/fwl/core/cfwl_edit.h3
5 files changed, 65 insertions, 48 deletions
diff --git a/xfa/fwl/core/cfwl_caret.cpp b/xfa/fwl/core/cfwl_caret.cpp
index b4ebf2cec8..b42945c6a8 100644
--- a/xfa/fwl/core/cfwl_caret.cpp
+++ b/xfa/fwl/core/cfwl_caret.cpp
@@ -55,15 +55,19 @@ void CFWL_Caret::DrawWidget(CFX_Graphics* pGraphics,
DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix);
}
-void CFWL_Caret::ShowCaret(bool bFlag) {
+void CFWL_Caret::ShowCaret() {
+ if (m_pTimerInfo)
+ m_pTimerInfo->StopTimer();
+ m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true);
+ SetStates(FWL_WGTSTATE_Invisible, false);
+}
+
+void CFWL_Caret::HideCaret() {
if (m_pTimerInfo) {
m_pTimerInfo->StopTimer();
m_pTimerInfo = nullptr;
}
- if (bFlag)
- m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true);
-
- SetStates(FWL_WGTSTATE_Invisible, !bFlag);
+ SetStates(FWL_WGTSTATE_Invisible, true);
}
void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics,
diff --git a/xfa/fwl/core/cfwl_caret.h b/xfa/fwl/core/cfwl_caret.h
index ad38f7a3ed..ada0405748 100644
--- a/xfa/fwl/core/cfwl_caret.h
+++ b/xfa/fwl/core/cfwl_caret.h
@@ -34,7 +34,8 @@ class CFWL_Caret : public CFWL_Widget {
const CFX_Matrix* pMatrix) override;
void Update() override;
- void ShowCaret(bool bFlag = true);
+ void ShowCaret();
+ void HideCaret();
private:
class Timer : public CFWL_Timer {
diff --git a/xfa/fwl/core/cfwl_comboedit.cpp b/xfa/fwl/core/cfwl_comboedit.cpp
index 32e4cbb2dc..8ee9da6f14 100644
--- a/xfa/fwl/core/cfwl_comboedit.cpp
+++ b/xfa/fwl/core/cfwl_comboedit.cpp
@@ -39,7 +39,7 @@ void CFWL_ComboEdit::FlagFocus(bool bSet) {
}
m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
- ShowCaret(false);
+ HideCaret(nullptr);
}
void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) {
diff --git a/xfa/fwl/core/cfwl_edit.cpp b/xfa/fwl/core/cfwl_edit.cpp
index 751bf4336a..0844da3713 100644
--- a/xfa/fwl/core/cfwl_edit.cpp
+++ b/xfa/fwl/core/cfwl_edit.cpp
@@ -81,7 +81,7 @@ CFWL_Edit::CFWL_Edit(const CFWL_App* app,
CFWL_Edit::~CFWL_Edit() {
if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
- ShowCaret(false);
+ HideCaret(nullptr);
ClearRecord();
}
@@ -125,7 +125,7 @@ void CFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
void CFWL_Edit::SetStates(uint32_t dwStates, bool bSet) {
if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) ||
(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
- ShowCaret(false);
+ HideCaret(nullptr);
}
CFWL_Widget::SetStates(dwStates, bSet);
}
@@ -890,9 +890,10 @@ void CFWL_Edit::UpdateCaret() {
rtCaret.width = right - rtCaret.left;
}
- bool bShow =
- m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty();
- ShowCaret(bShow, &rtCaret);
+ if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty())
+ ShowCaret(&rtCaret);
+ else
+ HideCaret(&rtCaret);
}
CFWL_ScrollBar* CFWL_Edit::UpdateScroll() {
@@ -1166,55 +1167,65 @@ void CFWL_Edit::InitScrollBar(bool bVert) {
m_pHorzScrollBar.reset(sb);
}
-bool FWL_ShowCaret(CFWL_Widget* pWidget,
- bool bVisible,
- const CFX_RectF* pRtAnchor) {
+void CFWL_Edit::ShowCaret(CFX_RectF* pRect) {
+ if (m_pCaret) {
+ m_pCaret->ShowCaret();
+ if (!pRect->IsEmpty())
+ m_pCaret->SetWidgetRect(*pRect);
+ Repaint(&m_rtEngine);
+ return;
+ }
+
+ CFWL_Widget* pOuter = this;
+ pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top);
+ while (pOuter->GetOuter()) {
+ pOuter = pOuter->GetOuter();
+
+ CFX_RectF rtOuter;
+ pOuter->GetWidgetRect(rtOuter);
+ pRect->Offset(rtOuter.left, rtOuter.top);
+ }
+
CXFA_FFWidget* pXFAWidget =
- static_cast<CXFA_FFWidget*>(pWidget->GetLayoutItem());
+ static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem());
if (!pXFAWidget)
- return false;
+ return;
IXFA_DocEnvironment* pDocEnvironment =
pXFAWidget->GetDoc()->GetDocEnvironment();
if (!pDocEnvironment)
- return false;
+ return;
- if (bVisible) {
- CFX_Matrix mt;
- pXFAWidget->GetRotateMatrix(mt);
- CFX_RectF rt(*pRtAnchor);
- mt.TransformRect(rt);
- pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt);
- return true;
- }
+ CFX_Matrix mt;
+ pXFAWidget->GetRotateMatrix(mt);
- pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor);
- return true;
+ CFX_RectF rt(*pRect);
+ mt.TransformRect(rt);
+ pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt);
}
-void CFWL_Edit::ShowCaret(bool bVisible, CFX_RectF* pRect) {
+void CFWL_Edit::HideCaret(CFX_RectF* pRect) {
if (m_pCaret) {
- m_pCaret->ShowCaret(bVisible);
- if (bVisible && !pRect->IsEmpty())
- m_pCaret->SetWidgetRect(*pRect);
+ m_pCaret->HideCaret();
Repaint(&m_rtEngine);
return;
}
CFWL_Widget* pOuter = this;
- if (bVisible) {
- pRect->Offset(m_pProperties->m_rtWidget.left,
- m_pProperties->m_rtWidget.top);
- }
- while (pOuter->GetOuter()) {
+ while (pOuter->GetOuter())
pOuter = pOuter->GetOuter();
- if (bVisible) {
- CFX_RectF rtOuter;
- pOuter->GetWidgetRect(rtOuter);
- pRect->Offset(rtOuter.left, rtOuter.top);
- }
- }
- FWL_ShowCaret(pOuter, bVisible, pRect);
+
+ CXFA_FFWidget* pXFAWidget =
+ static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem());
+ if (!pXFAWidget)
+ return;
+
+ IXFA_DocEnvironment* pDocEnvironment =
+ pXFAWidget->GetDoc()->GetDocEnvironment();
+ if (!pDocEnvironment)
+ return;
+
+ pDocEnvironment->DisplayCaret(pXFAWidget, false, pRect);
}
bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) {
@@ -1250,8 +1261,8 @@ bool CFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) {
void CFWL_Edit::InitCaret() {
if (!m_pCaret) {
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) {
- m_pCaret.reset(new CFWL_Caret(
- m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this));
+ m_pCaret = pdfium::MakeUnique<CFWL_Caret>(
+ m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this);
m_pCaret->SetParent(this);
m_pCaret->SetStates(m_pProperties->m_dwStates);
}
@@ -1371,7 +1382,7 @@ void CFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
UpdateCaret();
} else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
- ShowCaret(false);
+ HideCaret(nullptr);
if ((dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) {
int32_t nSel = CountSelRanges();
if (nSel > 0) {
diff --git a/xfa/fwl/core/cfwl_edit.h b/xfa/fwl/core/cfwl_edit.h
index d560bc5d8d..b8b3b143a3 100644
--- a/xfa/fwl/core/cfwl_edit.h
+++ b/xfa/fwl/core/cfwl_edit.h
@@ -119,7 +119,8 @@ class CFWL_Edit : public CFWL_Widget {
void SetScrollOffset(FX_FLOAT fScrollOffset);
protected:
- void ShowCaret(bool bVisible, CFX_RectF* pRect = nullptr);
+ void ShowCaret(CFX_RectF* pRect);
+ void HideCaret(CFX_RectF* pRect);
const CFX_RectF& GetRTClient() const { return m_rtClient; }
CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; }