summaryrefslogtreecommitdiff
path: root/xfa/fwl/cfwl_scrollbar.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-02 15:45:12 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-03 19:51:26 +0000
commitdb194cf018069b930d0e3d5fc0242e14f70e8620 (patch)
tree191fea4b4156e0f09f174466c8d9f5bd34932717 /xfa/fwl/cfwl_scrollbar.cpp
parent83c5eaca106f4afed6cceb1b3f336d0146cb10d7 (diff)
downloadpdfium-db194cf018069b930d0e3d5fc0242e14f70e8620.tar.xz
Use return values in CFWL_Scrollbar instead of out params
This CL updates CFWL_Scrollbar use return values instead of using out params. In some cases, the same values is assigned and passed in, but passing in the const ref is a lot clearer as to what is happening. Change-Id: Iff72a845e09ac73ff8eac938482547eaf251f835 Reviewed-on: https://pdfium-review.googlesource.com/2133 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fwl/cfwl_scrollbar.cpp')
-rw-r--r--xfa/fwl/cfwl_scrollbar.cpp129
1 files changed, 73 insertions, 56 deletions
diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp
index 60876e3135..016afd6d36 100644
--- a/xfa/fwl/cfwl_scrollbar.cpp
+++ b/xfa/fwl/cfwl_scrollbar.cpp
@@ -90,9 +90,9 @@ void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics,
void CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) {
m_fTrackPos = fTrackPos;
- CalcThumbButtonRect(m_rtThumb);
- CalcMinTrackRect(m_rtMinTrack);
- CalcMaxTrackRect(m_rtMaxTrack);
+ m_rtThumb = CalcThumbButtonRect(m_rtThumb);
+ m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack);
+ m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack);
}
bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, FX_FLOAT fPos) {
@@ -157,11 +157,11 @@ void CFWL_ScrollBar::Layout() {
pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size));
m_rtClient = GetClientRect();
CalcButtonLen();
- CalcMinButtonRect(m_rtMinBtn);
- CalcMaxButtonRect(m_rtMaxBtn);
- CalcThumbButtonRect(m_rtThumb);
- CalcMinTrackRect(m_rtMinTrack);
- CalcMaxTrackRect(m_rtMaxTrack);
+ m_rtMinBtn = CalcMinButtonRect();
+ m_rtMaxBtn = CalcMaxButtonRect();
+ m_rtThumb = CalcThumbButtonRect(m_rtThumb);
+ m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack);
+ m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack);
}
void CFWL_ScrollBar::CalcButtonLen() {
@@ -175,39 +175,47 @@ void CFWL_ScrollBar::CalcButtonLen() {
}
}
-void CFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) {
- rect.left = m_rtClient.left;
- rect.top = m_rtClient.top;
- rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen;
- rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height;
+CFX_RectF CFWL_ScrollBar::CalcMinButtonRect() {
+ CFX_RectF rect;
+ if (IsVertical())
+ rect.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width, m_fButtonLen);
+ else
+ rect.Set(m_rtClient.left, m_rtClient.top, m_fButtonLen, m_rtClient.height);
+ return rect;
}
-void CFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) {
- rect.left =
- IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen;
- rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top;
- rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen;
- rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height;
+CFX_RectF CFWL_ScrollBar::CalcMaxButtonRect() {
+ CFX_RectF rect;
+ if (IsVertical()) {
+ rect.Set(m_rtClient.left, m_rtClient.bottom() - m_fButtonLen,
+ m_rtClient.width, m_fButtonLen);
+ } else {
+ rect.Set(m_rtClient.right() - m_fButtonLen, m_rtClient.top, m_fButtonLen,
+ m_rtClient.height);
+ }
+ return rect;
}
-void CFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) {
- if (!IsEnabled()) {
- m_rtThumb.Reset();
- return;
- }
+CFX_RectF CFWL_ScrollBar::CalcThumbButtonRect(const CFX_RectF& rtThumb) {
+ CFX_RectF rect;
+ rect.Reset();
+
+ if (!IsEnabled())
+ return rect;
+
if (m_bMinSize) {
- m_rtThumb.Empty();
- return;
+ rect.left = rtThumb.left;
+ rect.top = rtThumb.top;
+ return rect;
}
FX_FLOAT fRange = m_fRangeMax - m_fRangeMin;
- memset(&rect, 0, sizeof(CFX_Rect));
if (fRange < 0) {
if (IsVertical())
rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0);
else
rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height);
- return;
+ return rect;
}
CFX_RectF rtClient = m_rtClient;
@@ -224,51 +232,60 @@ void CFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) {
FX_FLOAT fTrackPos =
std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin);
if (!fRange)
- return;
+ return rect;
FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange;
rect.left = rtClient.left;
- if (!IsVertical())
- rect.left += iPos;
-
rect.top = rtClient.top;
- if (IsVertical())
+ if (IsVertical()) {
rect.top += iPos;
-
- rect.width = IsVertical() ? rtClient.width : fThumbSize;
- rect.height = IsVertical() ? fThumbSize : rtClient.height;
+ rect.width = rtClient.width;
+ rect.height = fThumbSize;
+ } else {
+ rect.left += iPos;
+ rect.width = fThumbSize;
+ rect.height = rtClient.height;
+ }
+ return rect;
}
-void CFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) {
+CFX_RectF CFWL_ScrollBar::CalcMinTrackRect(const CFX_RectF& rtMinRect) {
+ CFX_RectF rect;
+ rect.Reset();
+
if (m_bMinSize) {
- rect.Empty();
- return;
+ rect.left = rtMinRect.left;
+ rect.top = rtMinRect.top;
+ return rect;
}
- FX_FLOAT fBottom = m_rtThumb.bottom();
- FX_FLOAT fRight = m_rtThumb.right();
- FX_FLOAT ix = (m_rtThumb.left + fRight) / 2;
- FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2;
rect.left = m_rtClient.left;
rect.top = m_rtClient.top;
- bool bVertical = IsVertical();
- rect.width = bVertical ? m_rtClient.width : ix;
- rect.height = bVertical ? iy : m_rtClient.height;
+ if (IsVertical()) {
+ rect.width = m_rtClient.width;
+ rect.height = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
+ } else {
+ rect.width = (m_rtThumb.left + m_rtThumb.right()) / 2;
+ rect.height = m_rtClient.height;
+ }
+ return rect;
}
-void CFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) {
+CFX_RectF CFWL_ScrollBar::CalcMaxTrackRect(const CFX_RectF& rtMaxRect) {
+ CFX_RectF rect;
if (m_bMinSize) {
- rect.Empty();
- return;
+ rect.Set(rtMaxRect.left, rtMaxRect.top, 0, 0);
+ return rect;
}
- FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2;
- FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
- bool bVertical = IsVertical();
- rect.left = bVertical ? m_rtClient.left : ix;
- rect.top = bVertical ? iy : m_rtClient.top;
- rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix;
- rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height;
+ if (IsVertical()) {
+ FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
+ rect.Set(m_rtClient.left, iy, m_rtClient.width, m_rtClient.bottom() - iy);
+ } else {
+ FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2;
+ rect.Set(ix, m_rtClient.top, m_rtClient.height - ix, m_rtClient.height);
+ }
+ return rect;
}
FX_FLOAT CFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) {