summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-03-17 15:14:19 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-17 22:54:26 +0000
commit85f019a8e7d33cbba368a6c6b75fd091269e14a1 (patch)
tree8dcf6fcd98309a48ebbd9e46cc8c0d23a57c0965 /xfa
parent240fe6d79f234896a966ddce0b9a125776dc9171 (diff)
downloadpdfium-85f019a8e7d33cbba368a6c6b75fd091269e14a1.tar.xz
Add pdfium::clamp() as a placeholder for std::clamp().chromium/3046
Ue it to fix a typo as well. BUG=pdfium:634 Change-Id: I2d686242ffb841aedc2fae6a3cf7a00bea667404 Reviewed-on: https://pdfium-review.googlesource.com/3113 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fde/css/cfde_csstextbuf.cpp4
-rw-r--r--xfa/fwl/cfwl_edit.cpp15
-rw-r--r--xfa/fwl/cfwl_listbox.cpp4
-rw-r--r--xfa/fwl/cfwl_scrollbar.cpp5
-rw-r--r--xfa/fxfa/fm2js/xfa_fm2jscontext.cpp14
-rw-r--r--xfa/fxfa/parser/cxfa_widetextread.cpp3
6 files changed, 23 insertions, 22 deletions
diff --git a/xfa/fde/css/cfde_csstextbuf.cpp b/xfa/fde/css/cfde_csstextbuf.cpp
index 5df09f0936..6f74db2a78 100644
--- a/xfa/fde/css/cfde_csstextbuf.cpp
+++ b/xfa/fde/css/cfde_csstextbuf.cpp
@@ -6,7 +6,7 @@
#include "xfa/fde/css/cfde_csstextbuf.h"
-#include <algorithm>
+#include "third_party/base/stl_util.h"
CFDE_CSSTextBuf::CFDE_CSSTextBuf()
: m_bExtBuf(false),
@@ -80,7 +80,7 @@ bool CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) {
void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) {
ASSERT(iStart >= 0 && iLength >= 0);
- iLength = std::max(std::min(iLength, m_iDatLen - iStart), 0);
+ iLength = pdfium::clamp(iLength, 0, m_iDatLen - iStart);
FXSYS_memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(wchar_t));
m_iDatLen = iLength;
}
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index a17d5fec3d..58f8affb66 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -840,7 +840,7 @@ CFWL_ScrollBar* CFWL_Edit::UpdateScroll() {
float fRange = rtFDE.width - rtScroll.width;
m_pHorzScrollBar->SetRange(0.0f, fRange);
- float fPos = std::min(std::max(m_fScrollOffsetX, 0.0f), fRange);
+ float fPos = pdfium::clamp(m_fScrollOffsetX, 0.0f, fRange);
m_pHorzScrollBar->SetPos(fPos);
m_pHorzScrollBar->SetTrackPos(fPos);
m_pHorzScrollBar->SetPageSize(rtScroll.width);
@@ -867,7 +867,7 @@ CFWL_ScrollBar* CFWL_Edit::UpdateScroll() {
float fRange = std::max(rtFDE.height - m_rtEngine.height, fStep);
m_pVertScrollBar->SetRange(0.0f, fRange);
- float fPos = std::min(std::max(m_fScrollOffsetY, 0.0f), fRange);
+ float fPos = pdfium::clamp(m_fScrollOffsetY, 0.0f, fRange);
m_pVertScrollBar->SetPos(fPos);
m_pVertScrollBar->SetTrackPos(fPos);
m_pVertScrollBar->SetPageSize(rtScroll.height);
@@ -889,17 +889,16 @@ CFWL_ScrollBar* CFWL_Edit::UpdateScroll() {
}
bool CFWL_Edit::IsShowScrollBar(bool bVert) {
+ if (!bVert)
+ return false;
bool bShow =
(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus)
? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) ==
FWL_WGTSTATE_Focused
: true;
- if (bVert) {
- return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) &&
- (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) &&
- IsContentHeightOverflow();
- }
- return false;
+ return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) &&
+ (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) &&
+ IsContentHeightOverflow();
}
bool CFWL_Edit::IsContentHeightOverflow() {
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index 925c6f1f72..c858063d07 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -527,7 +527,7 @@ CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) {
m_pVertScrollBar->SetStepSize(m_fItemHeight);
float fPos =
- std::min(std::max(m_pVertScrollBar->GetPos(), 0.f), szRange.height);
+ pdfium::clamp(m_pVertScrollBar->GetPos(), 0.0f, szRange.height);
m_pVertScrollBar->SetPos(fPos);
m_pVertScrollBar->SetTrackPos(fPos);
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ==
@@ -559,7 +559,7 @@ CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) {
m_pHorzScrollBar->SetStepSize(fWidth / 10);
float fPos =
- std::min(std::max(m_pHorzScrollBar->GetPos(), 0.f), szRange.height);
+ pdfium::clamp(m_pHorzScrollBar->GetPos(), 0.0f, szRange.height);
m_pHorzScrollBar->SetPos(fPos);
m_pHorzScrollBar->SetTrackPos(fPos);
if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ==
diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp
index abe99dacce..72797ed315 100644
--- a/xfa/fwl/cfwl_scrollbar.cpp
+++ b/xfa/fwl/cfwl_scrollbar.cpp
@@ -11,6 +11,7 @@
#include <utility>
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fwl/cfwl_messagemouse.h"
#include "xfa/fwl/cfwl_messagemousewheel.h"
#include "xfa/fwl/cfwl_notedriver.h"
@@ -219,7 +220,7 @@ CFX_RectF CFWL_ScrollBar::CalcThumbButtonRect(const CFX_RectF& rtThumb) {
fThumbSize = std::max(fThumbSize, kMinThumbSize);
float fDiff = std::max(fLength - fThumbSize, 0.0f);
- float fTrackPos = std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin);
+ float fTrackPos = pdfium::clamp(m_fTrackPos, m_fRangeMin, m_fRangeMax);
if (!fRange)
return rect;
@@ -287,7 +288,7 @@ float CFWL_ScrollBar::GetTrackPointPos(const CFX_PointF& point) {
}
fPos += m_fLastTrackPos;
- return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax);
+ return pdfium::clamp(fPos, m_fRangeMin, m_fRangeMax);
}
bool CFWL_ScrollBar::SendEvent() {
diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp
index 21d91395c2..e951716802 100644
--- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp
+++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp
@@ -15,6 +15,7 @@
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fgas/localization/fgas_locale.h"
#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/fm2js/xfa_program.h"
@@ -910,8 +911,7 @@ void CXFA_FM2JSContext::Round(CFXJSE_Value* pThis,
return;
}
- uPrecision =
- static_cast<uint8_t>(std::min(std::max(dPrecision, 0.0), 12.0));
+ uPrecision = static_cast<uint8_t>(pdfium::clamp(dPrecision, 0.0, 12.0));
}
CFX_Decimal decimalValue((float)dValue, uPrecision);
@@ -4494,8 +4494,9 @@ void CXFA_FM2JSContext::Stuff(CFXJSE_Value* pThis,
!deleteValue->IsNull()) {
ValueToUTF8String(sourceValue.get(), sourceString);
iLength = sourceString.GetLength();
- iStart = std::min(iLength, std::max(1, static_cast<int32_t>(ValueToFloat(
- pThis, startValue.get()))));
+ iStart = pdfium::clamp(
+ static_cast<int32_t>(ValueToFloat(pThis, startValue.get())), 1,
+ iLength);
iDelete = std::max(
0, static_cast<int32_t>(ValueToFloat(pThis, deleteValue.get())));
}
@@ -4551,9 +4552,8 @@ void CXFA_FM2JSContext::Substr(CFXJSE_Value* pThis,
return;
}
- iStart = std::min(
- iLength,
- std::max(1, static_cast<int32_t>(ValueToFloat(pThis, startValue.get()))));
+ iStart = pdfium::clamp(
+ iLength, 1, static_cast<int32_t>(ValueToFloat(pThis, startValue.get())));
iCount =
std::max(0, static_cast<int32_t>(ValueToFloat(pThis, endValue.get())));
diff --git a/xfa/fxfa/parser/cxfa_widetextread.cpp b/xfa/fxfa/parser/cxfa_widetextread.cpp
index bba7cbdaa1..73da5c670b 100644
--- a/xfa/fxfa/parser/cxfa_widetextread.cpp
+++ b/xfa/fxfa/parser/cxfa_widetextread.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include "core/fxcrt/fx_ext.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fgas/crt/fgas_codepage.h"
CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer)
@@ -36,7 +37,7 @@ int32_t CXFA_WideTextRead::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
m_iPosition = m_wsBuffer.GetLength() + iOffset;
break;
}
- m_iPosition = std::min(std::max(0, m_iPosition), m_wsBuffer.GetLength());
+ m_iPosition = pdfium::clamp(0, m_iPosition, m_wsBuffer.GetLength());
return GetPosition();
}