summaryrefslogtreecommitdiff
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
parent240fe6d79f234896a966ddce0b9a125776dc9171 (diff)
downloadpdfium-chromium/3046.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>
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_allstates.cpp15
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp12
-rw-r--r--core/fpdfapi/page/fpdf_page_colors.cpp3
-rw-r--r--core/fpdfapi/page/fpdf_page_func.cpp24
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp7
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp4
-rw-r--r--core/fpdfdoc/csection.cpp13
-rw-r--r--core/fxcodec/codec/fx_codec_fax.cpp3
-rw-r--r--core/fxcrt/fx_basic_bstring.cpp5
-rw-r--r--core/fxcrt/fx_basic_wstring.cpp5
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp5
-rw-r--r--core/fxge/dib/fx_dib_engine.cpp3
-rw-r--r--fpdfsdk/fpdfeditpage.cpp2
-rw-r--r--third_party/base/stl_util.h7
-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
21 files changed, 85 insertions, 77 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 4c378f7598..217a6eaf2e 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -21,6 +21,7 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -450,10 +451,10 @@ FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode) {
if (!err) {
FXFT_BBox cbox;
FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
- cbox.xMin = std::min(std::max(cbox.xMin, kMinCBox), kMaxCBox);
- cbox.xMax = std::min(std::max(cbox.xMax, kMinCBox), kMaxCBox);
- cbox.yMin = std::min(std::max(cbox.yMin, kMinCBox), kMaxCBox);
- cbox.yMax = std::min(std::max(cbox.yMax, kMinCBox), kMaxCBox);
+ cbox.xMin = pdfium::clamp(cbox.xMin, kMinCBox, kMaxCBox);
+ cbox.xMax = pdfium::clamp(cbox.xMax, kMinCBox, kMaxCBox);
+ cbox.yMin = pdfium::clamp(cbox.yMin, kMinCBox, kMaxCBox);
+ cbox.yMax = pdfium::clamp(cbox.yMax, kMinCBox, kMaxCBox);
int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem;
if (pixel_size_x == 0 || pixel_size_y == 0) {
diff --git a/core/fpdfapi/page/cpdf_allstates.cpp b/core/fpdfapi/page/cpdf_allstates.cpp
index a30696e8b7..c67d3152c0 100644
--- a/core/fpdfapi/page/cpdf_allstates.cpp
+++ b/core/fpdfapi/page/cpdf_allstates.cpp
@@ -14,14 +14,7 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fxge/cfx_graphstatedata.h"
-
-namespace {
-
-float ClipFloat(float f) {
- return std::max(0.0f, std::min(1.0f, f));
-}
-
-} // namespace
+#include "third_party/base/stl_util.h"
CPDF_AllStates::CPDF_AllStates()
: m_TextLeading(0), m_TextRise(0), m_TextHorzScale(1.0f) {}
@@ -117,10 +110,12 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
}
break;
case FXBSTR_ID('C', 'A', 0, 0):
- m_GeneralState.SetStrokeAlpha(ClipFloat(pObject->GetNumber()));
+ m_GeneralState.SetStrokeAlpha(
+ pdfium::clamp(pObject->GetNumber(), 0.0f, 1.0f));
break;
case FXBSTR_ID('c', 'a', 0, 0):
- m_GeneralState.SetFillAlpha(ClipFloat(pObject->GetNumber()));
+ m_GeneralState.SetFillAlpha(
+ pdfium::clamp(pObject->GetNumber(), 0.0f, 1.0f));
break;
case FXBSTR_ID('O', 'P', 0, 0):
m_GeneralState.SetStrokeOP(!!pObject->GetInteger());
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 1aaa1440a4..cc4afa55c9 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -24,6 +24,7 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxcrt/fx_memory.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -227,7 +228,7 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace {
};
float RGB_Conversion(float colorComponent) {
- colorComponent = std::min(std::max(colorComponent, 0.0f), 1.0f);
+ colorComponent = pdfium::clamp(colorComponent, 0.0f, 1.0f);
int scale = std::max(static_cast<int>(colorComponent * 1023), 0);
if (scale < 192)
return g_sRGBSamples1[scale] / 255.0f;
@@ -686,11 +687,12 @@ void CPDF_LabCS::GetDefaultValue(int iComponent,
*min = 0.0f;
*max = 100 * 1.0f;
*value = 0.0f;
- } else {
- *min = m_Ranges[iComponent * 2 - 2];
- *max = m_Ranges[iComponent * 2 - 1];
- *value = std::min(std::max(0.0f, *min), *max);
+ return;
}
+
+ *min = m_Ranges[iComponent * 2 - 2];
+ *max = m_Ranges[iComponent * 2 - 1];
+ *value = pdfium::clamp(0.0f, *min, *max);
}
bool CPDF_LabCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
diff --git a/core/fpdfapi/page/fpdf_page_colors.cpp b/core/fpdfapi/page/fpdf_page_colors.cpp
index e69620ea9a..adee5ff84b 100644
--- a/core/fpdfapi/page/fpdf_page_colors.cpp
+++ b/core/fpdfapi/page/fpdf_page_colors.cpp
@@ -18,11 +18,12 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fxcodec/fx_codec.h"
+#include "third_party/base/stl_util.h"
namespace {
float NormalizeChannel(float fVal) {
- return std::min(std::max(fVal, 0.0f), 1.0f);
+ return pdfium::clamp(fVal, 0.0f, 1.0f);
}
bool DetectSRGB(const uint8_t* pData, uint32_t dwSize) {
diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp
index 94695daca2..30f3b895d4 100644
--- a/core/fpdfapi/page/fpdf_page_func.cpp
+++ b/core/fpdfapi/page/fpdf_page_func.cpp
@@ -21,6 +21,7 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -541,8 +542,8 @@ bool CPDF_SampledFunc::v_Call(float* inputs, float* results) const {
encoded_input[i] =
PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1],
m_EncodeInfo[i].encode_min, m_EncodeInfo[i].encode_max);
- index[i] = std::min((uint32_t)std::max(0.f, encoded_input[i]),
- m_EncodeInfo[i].sizes - 1);
+ index[i] = pdfium::clamp(static_cast<uint32_t>(encoded_input[i]), 0U,
+ m_EncodeInfo[i].sizes - 1);
pos += index[i] * blocksize[i];
}
FX_SAFE_INT32 bits_to_output = m_nOutputs;
@@ -816,19 +817,16 @@ bool CPDF_Function::Call(float* inputs,
*nresults = m_nOutputs;
for (uint32_t i = 0; i < m_nInputs; i++) {
- if (inputs[i] < m_pDomains[i * 2])
- inputs[i] = m_pDomains[i * 2];
- else if (inputs[i] > m_pDomains[i * 2 + 1])
- inputs[i] = m_pDomains[i * 2] + 1;
+ inputs[i] =
+ pdfium::clamp(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1]);
}
v_Call(inputs, results);
- if (m_pRanges) {
- for (uint32_t i = 0; i < m_nOutputs; i++) {
- if (results[i] < m_pRanges[i * 2])
- results[i] = m_pRanges[i * 2];
- else if (results[i] > m_pRanges[i * 2 + 1])
- results[i] = m_pRanges[i * 2 + 1];
- }
+ if (!m_pRanges)
+ return true;
+
+ for (uint32_t i = 0; i < m_nOutputs; i++) {
+ results[i] =
+ pdfium::clamp(results[i], m_pRanges[i * 2], m_pRanges[i * 2 + 1]);
}
return true;
}
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 7903ad4a62..d3778452a3 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -30,6 +30,7 @@
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_pathdata.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#ifdef _SKIA_SUPPORT_
#include "core/fxge/skia/fx_skia_device.h"
@@ -273,11 +274,11 @@ void CPDF_ImageRenderer::CalculateDrawImage(CFX_FxgeDevice* pBitmapDevice1,
continue;
}
int orig = (*dest_scan - matte_b) * 255 / alpha + matte_b;
- *dest_scan++ = std::min(std::max(orig, 0), 255);
+ *dest_scan++ = pdfium::clamp(orig, 0, 255);
orig = (*dest_scan - matte_g) * 255 / alpha + matte_g;
- *dest_scan++ = std::min(std::max(orig, 0), 255);
+ *dest_scan++ = pdfium::clamp(orig, 0, 255);
orig = (*dest_scan - matte_r) * 255 / alpha + matte_r;
- *dest_scan++ = std::min(std::max(orig, 0), 255);
+ *dest_scan++ = pdfium::clamp(orig, 0, 255);
dest_scan++;
}
}
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index d5333192f5..dcd3a0785a 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -699,7 +699,7 @@ CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place,
return place;
int32_t nSecIndex =
- std::max(std::min(place.nSecIndex, m_SectionArray.GetSize()), 0);
+ pdfium::clamp(place.nSecIndex, 0, m_SectionArray.GetSize());
CSection* pSection = new CSection(this);
pSection->m_SecInfo = secinfo;
pSection->SecPlace.nSecIndex = nSecIndex;
@@ -727,7 +727,7 @@ CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place,
}
CPVT_WordPlace newplace = place;
newplace.nSecIndex =
- std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
+ pdfium::clamp(newplace.nSecIndex, 0, m_SectionArray.GetSize() - 1);
if (CSection* pSection = m_SectionArray.GetAt(newplace.nSecIndex))
return pSection->AddWord(newplace, wordinfo);
return place;
diff --git a/core/fpdfdoc/csection.cpp b/core/fpdfdoc/csection.cpp
index 981f6d0b54..0c7825585c 100644
--- a/core/fpdfdoc/csection.cpp
+++ b/core/fpdfdoc/csection.cpp
@@ -29,9 +29,8 @@ void CSection::ResetLineArray() {
}
void CSection::ResetWordArray() {
- for (int32_t i = 0, sz = m_WordArray.GetSize(); i < sz; i++) {
+ for (int32_t i = 0, sz = m_WordArray.GetSize(); i < sz; i++)
delete m_WordArray.GetAt(i);
- }
m_WordArray.RemoveAll();
}
@@ -47,12 +46,11 @@ CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place,
const CPVT_WordInfo& wordinfo) {
CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo);
int32_t nWordIndex =
- std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0);
- if (nWordIndex == m_WordArray.GetSize()) {
+ pdfium::clamp(place.nWordIndex, 0, m_WordArray.GetSize());
+ if (nWordIndex == m_WordArray.GetSize())
m_WordArray.Add(pWord);
- } else {
+ else
m_WordArray.InsertAt(nWordIndex, pWord);
- }
return place;
}
@@ -62,9 +60,8 @@ CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) {
}
CPVT_FloatRect CSection::Rearrange() {
- if (m_pVT->m_nCharArray > 0) {
+ if (m_pVT->m_nCharArray > 0)
return CTypeset(this).CharArray();
- }
return CTypeset(this).Typeset();
}
diff --git a/core/fxcodec/codec/fx_codec_fax.cpp b/core/fxcodec/codec/fx_codec_fax.cpp
index 46792a6003..7865da925e 100644
--- a/core/fxcodec/codec/fx_codec_fax.cpp
+++ b/core/fxcodec/codec/fx_codec_fax.cpp
@@ -12,6 +12,7 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_memory.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -104,7 +105,7 @@ void FaxG4FindB1B2(const std::vector<uint8_t>& ref_buf,
void FaxFillBits(uint8_t* dest_buf, int columns, int startpos, int endpos) {
startpos = std::max(startpos, 0);
- endpos = std::min(std::max(endpos, 0), columns);
+ endpos = pdfium::clamp(endpos, 0, columns);
if (startpos >= endpos)
return;
diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp
index b4eb4a75e0..f049b14c3a 100644
--- a/core/fxcrt/fx_basic_bstring.cpp
+++ b/core/fxcrt/fx_basic_bstring.cpp
@@ -12,6 +12,7 @@
#include "core/fxcrt/cfx_string_pool_template.h"
#include "core/fxcrt/fx_basic.h"
#include "third_party/base/numerics/safe_math.h"
+#include "third_party/base/stl_util.h"
template class CFX_StringDataTemplate<char>;
template class CFX_StringCTemplate<char>;
@@ -405,8 +406,8 @@ CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const {
if (!m_pData)
return CFX_ByteString();
- nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength);
- nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst);
+ nFirst = pdfium::clamp(nFirst, 0, m_pData->m_nDataLength);
+ nCount = pdfium::clamp(nCount, 0, m_pData->m_nDataLength - nFirst);
if (nCount == 0)
return CFX_ByteString();
diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp
index 8522d42a38..384b0b0086 100644
--- a/core/fxcrt/fx_basic_wstring.cpp
+++ b/core/fxcrt/fx_basic_wstring.cpp
@@ -13,6 +13,7 @@
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_ext.h"
#include "third_party/base/numerics/safe_math.h"
+#include "third_party/base/stl_util.h"
template class CFX_StringDataTemplate<wchar_t>;
template class CFX_StringCTemplate<wchar_t>;
@@ -375,8 +376,8 @@ CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const {
if (!m_pData)
return CFX_WideString();
- nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength);
- nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst);
+ nFirst = pdfium::clamp(nFirst, 0, m_pData->m_nDataLength);
+ nCount = pdfium::clamp(nCount, 0, m_pData->m_nDataLength - nFirst);
if (nCount == 0)
return CFX_WideString();
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 4534ee1425..b435c032bc 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -24,14 +24,15 @@
#include "third_party/agg23/agg_renderer_scanline.h"
#include "third_party/agg23/agg_scanline_u.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
const float kMaxPos = 32000.0f;
CFX_PointF HardClip(const CFX_PointF& pos) {
- return CFX_PointF(std::max(std::min(pos.x, kMaxPos), -kMaxPos),
- std::max(std::min(pos.y, kMaxPos), -kMaxPos));
+ return CFX_PointF(pdfium::clamp(pos.x, -kMaxPos, kMaxPos),
+ pdfium::clamp(pos.y, -kMaxPos, kMaxPos));
}
void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) {
diff --git a/core/fxge/dib/fx_dib_engine.cpp b/core/fxge/dib/fx_dib_engine.cpp
index 8d90a72401..5975a5e975 100644
--- a/core/fxge/dib/fx_dib_engine.cpp
+++ b/core/fxge/dib/fx_dib_engine.cpp
@@ -11,6 +11,7 @@
#include "core/fxge/dib/dib_int.h"
#include "core/fxge/fx_dib.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -984,7 +985,7 @@ bool CFX_ImageStretcher::ContinueQuickStretch(IFX_Pause* pPause) {
dest_y = m_LineIndex;
src_y = (dest_y + m_ClipRect.top) * src_height / m_DestHeight;
}
- src_y = std::max(std::min(src_y, src_height - 1), 0);
+ src_y = pdfium::clamp(src_y, 0, src_height - 1);
if (m_pSource->SkipToScanline(src_y, pPause))
return true;
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index cff339c8f8..7b55e4d99d 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -104,7 +104,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
if (!pDoc)
return nullptr;
- page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount());
+ page_index = pdfium::clamp(page_index, 0, pDoc->GetPageCount());
CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
if (!pPageDict)
return nullptr;
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h
index 96947f5e53..9c71530c12 100644
--- a/third_party/base/stl_util.h
+++ b/third_party/base/stl_util.h
@@ -10,6 +10,7 @@
#include <set>
#include "third_party/base/numerics/safe_conversions.h"
+#include "third_party/base/stl_util.h"
namespace pdfium {
@@ -67,6 +68,12 @@ class ScopedSetInsertion {
const T m_Entry;
};
+// std::clamp(), some day.
+template <class T>
+constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
+ return std::min(std::max(v, lo), hi);
+}
+
} // namespace pdfium
#endif // PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
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();
}