From adf922f278d23e7f955b89f48cc64b5de7925977 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Wed, 12 Jul 2017 21:56:27 -0400 Subject: Remove CPWL_Utils::{In,De}flateRect This CL removes the custom InflateRect and Deflate rect code in CPWL_Utils in favour of calling the CFX_FloatRect version. This required inlining some extra code at each callsite to check the rect size and normalize. Change-Id: I7f60e5de03fc1db0c1d8e51eaa1d0e0700ebf157 Reviewed-on: https://pdfium-review.googlesource.com/7710 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/cpdfsdk_widget.cpp | 32 ++++++++--- fpdfsdk/formfiller/cffl_formfiller.cpp | 6 ++- fpdfsdk/formfiller/cffl_interactiveformfiller.cpp | 6 ++- fpdfsdk/pdfwindow/cpwl_caret.cpp | 6 ++- fpdfsdk/pdfwindow/cpwl_edit.cpp | 29 +++++++--- fpdfsdk/pdfwindow/cpwl_list_box.cpp | 9 +++- fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp | 13 +++-- fpdfsdk/pdfwindow/cpwl_special_button.cpp | 8 ++- fpdfsdk/pdfwindow/cpwl_utils.cpp | 66 ++++++++--------------- fpdfsdk/pdfwindow/cpwl_utils.h | 3 -- fpdfsdk/pdfwindow/cpwl_wnd.cpp | 39 +++++++++++--- 11 files changed, 140 insertions(+), 77 deletions(-) diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 6670b29002..b7391e6ebc 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -925,7 +925,11 @@ void CPDFSDK_Widget::ResetAppearance_PushButton() { break; } - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); + CFX_FloatRect rcClient = rcWindow; + if (!rcClient.IsEmpty()) { + rcClient.Deflate(fBorderWidth, fBorderWidth); + rcClient.Normalize(); + } CPWL_Color crText(COLORTYPE_GRAY, 0); @@ -1103,7 +1107,12 @@ void CPDFSDK_Widget::ResetAppearance_CheckBox() { } CFX_FloatRect rcWindow = GetRotatedRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); + CFX_FloatRect rcClient = rcWindow; + if (!rcClient.IsEmpty()) { + rcClient.Deflate(fBorderWidth, fBorderWidth); + rcClient.Normalize(); + } + CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); if (da.HasColor()) { da.GetColor(iColorType, fc); @@ -1223,7 +1232,11 @@ void CPDFSDK_Widget::ResetAppearance_RadioButton() { } CFX_FloatRect rcWindow = GetRotatedRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); + CFX_FloatRect rcClient = rcWindow; + if (!rcClient.IsEmpty()) { + rcClient.Deflate(fBorderWidth, fBorderWidth); + rcClient.Normalize(); + } CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); if (da.HasColor()) { @@ -1260,8 +1273,11 @@ void CPDFSDK_Widget::ResetAppearance_RadioButton() { CFX_ByteString csAP_N_ON; - CFX_FloatRect rcCenter = - CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); + CFX_FloatRect rcCenter = CPWL_Utils::GetCenterSquare(rcWindow); + if (!rcCenter.IsEmpty()) { + rcCenter.Deflate(1.0f, 1.0f); + rcCenter.Normalize(); + } if (nStyle == PCS_CIRCLE) { if (nBorderStyle == BorderStyle::BEVELED) { @@ -1651,7 +1667,11 @@ CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { break; } - return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); + if (!rcWindow.IsEmpty()) { + rcWindow.Deflate(fBorderWidth, fBorderWidth); + rcWindow.Normalize(); + } + return rcWindow; } CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 31f6963348..6d71be5b6c 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -73,7 +73,11 @@ FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, if (!rcFocus.IsEmpty()) rcWin.Union(rcFocus); - return CPWL_Utils::InflateRect(rcWin, 1).GetOuterRect(); + if (!rcWin.IsEmpty()) { + rcWin.Inflate(1, 1); + rcWin.Normalize(); + } + return rcWin.GetOuterRect(); } void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp index d718e7ca40..5f5e21a274 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp @@ -45,7 +45,11 @@ FX_RECT CFFL_InteractiveFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, ASSERT(pPageView); CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); - CFX_FloatRect rcWin = CPWL_Utils::InflateRect(pPDFAnnot->GetRect(), 1); + CFX_FloatRect rcWin = pPDFAnnot->GetRect(); + if (!rcWin.IsEmpty()) { + rcWin.Inflate(1, 1); + rcWin.Normalize(); + } return rcWin.GetOuterRect(); } diff --git a/fpdfsdk/pdfwindow/cpwl_caret.cpp b/fpdfsdk/pdfwindow/cpwl_caret.cpp index 0d63622852..f49c77120c 100644 --- a/fpdfsdk/pdfwindow/cpwl_caret.cpp +++ b/fpdfsdk/pdfwindow/cpwl_caret.cpp @@ -135,7 +135,11 @@ void CPWL_Caret::SetCaret(bool bVisible, void CPWL_Caret::InvalidateRect(CFX_FloatRect* pRect) { if (pRect) { - CFX_FloatRect rcRefresh = CPWL_Utils::InflateRect(*pRect, 0.5f); + CFX_FloatRect rcRefresh = *pRect; + if (!rcRefresh.IsEmpty()) { + rcRefresh.Inflate(0.5f, 0.5f); + rcRefresh.Normalize(); + } rcRefresh.top += 1; rcRefresh.bottom -= 1; CPWL_Wnd::InvalidateRect(&rcRefresh); diff --git a/fpdfsdk/pdfwindow/cpwl_edit.cpp b/fpdfsdk/pdfwindow/cpwl_edit.cpp index a378156d41..2f9c5fbea5 100644 --- a/fpdfsdk/pdfwindow/cpwl_edit.cpp +++ b/fpdfsdk/pdfwindow/cpwl_edit.cpp @@ -89,16 +89,26 @@ void CPWL_Edit::RePosChildWnd() { pVSB->Move(rcVScroll, true, false); } - if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) - m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( - GetClientRect(), 1.0f)); // +1 for caret beside border + if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) { + CFX_FloatRect rect = GetClientRect(); + if (!rect.IsEmpty()) { + // +1 for caret beside border + rect.Inflate(1.0f, 1.0f); + rect.Normalize(); + } + m_pEditCaret->SetClipRect(rect); + } CPWL_EditCtrl::RePosChildWnd(); } CFX_FloatRect CPWL_Edit::GetClientRect() const { - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); + CFX_FloatRect rcClient = GetWindowRect(); + if (!rcClient.IsEmpty()) { + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + rcClient.Deflate(width, width); + rcClient.Normalize(); + } if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { if (pVSB->IsVisible()) { @@ -183,8 +193,13 @@ void CPWL_Edit::SetParamByFlag() { m_pEdit->SetTextOverflow(true, false); } else { if (m_pEditCaret) { - m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( - GetClientRect(), 1.0f)); // +1 for caret beside border + CFX_FloatRect rect = GetClientRect(); + if (!rect.IsEmpty()) { + // +1 for caret beside border + rect.Inflate(1.0f, 1.0f); + rect.Normalize(); + } + m_pEditCaret->SetClipRect(rect); } } } diff --git a/fpdfsdk/pdfwindow/cpwl_list_box.cpp b/fpdfsdk/pdfwindow/cpwl_list_box.cpp index 61f9aafa8f..79559d33f0 100644 --- a/fpdfsdk/pdfwindow/cpwl_list_box.cpp +++ b/fpdfsdk/pdfwindow/cpwl_list_box.cpp @@ -405,8 +405,13 @@ float CPWL_ListBox::GetFirstHeight() const { } CFX_FloatRect CPWL_ListBox::GetListRect() const { - return CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); + CFX_FloatRect rect = GetWindowRect(); + if (!rect.IsEmpty()) { + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + rect.Deflate(width, width); + rect.Normalize(); + } + return rect; } bool CPWL_ListBox::OnMouseWheel(short zDelta, diff --git a/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp b/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp index 01ce4e6f0a..cf5d42372a 100644 --- a/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp @@ -247,14 +247,21 @@ void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, ArgbEncode(nTransparency, 100, 100, 100), 0.0f); // draw inner border - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 0.5f); + rcDraw = rectWnd; + if (!rcDraw.IsEmpty()) { + rcDraw.Deflate(0.5f, 0.5f); + rcDraw.Normalize(); + } CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, ArgbEncode(nTransparency, 255, 255, 255), 1.0f); if (m_eSBButtonType != PSBT_POS) { // draw background - rcDraw = CPWL_Utils::DeflateRect(rectWnd, 1.0f); - + rcDraw = rectWnd; + if (!rcDraw.IsEmpty()) { + rcDraw.Deflate(1.0f, 1.0f); + rcDraw.Normalize(); + } if (IsEnabled()) { CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, rcDraw, nTransparency, 80, 220); diff --git a/fpdfsdk/pdfwindow/cpwl_special_button.cpp b/fpdfsdk/pdfwindow/cpwl_special_button.cpp index 56aa739545..743565f0dc 100644 --- a/fpdfsdk/pdfwindow/cpwl_special_button.cpp +++ b/fpdfsdk/pdfwindow/cpwl_special_button.cpp @@ -18,7 +18,13 @@ CFX_ByteString CPWL_PushButton::GetClassName() const { } CFX_FloatRect CPWL_PushButton::GetFocusRect() const { - return CPWL_Utils::DeflateRect(GetWindowRect(), (float)GetBorderWidth()); + CFX_FloatRect rect = GetWindowRect(); + if (!rect.IsEmpty()) { + rect.Deflate(static_cast(GetBorderWidth()), + static_cast(GetBorderWidth())); + rect.Normalize(); + } + return rect; } CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(false) {} diff --git a/fpdfsdk/pdfwindow/cpwl_utils.cpp b/fpdfsdk/pdfwindow/cpwl_utils.cpp index 4dd897d7d2..c31e092cd6 100644 --- a/fpdfsdk/pdfwindow/cpwl_utils.cpp +++ b/fpdfsdk/pdfwindow/cpwl_utils.cpp @@ -236,28 +236,6 @@ CFX_ByteString CPWL_Utils::GetAP_HalfCircle(const CFX_FloatRect& crBBox, return CFX_ByteString(csAP); } -CFX_FloatRect CPWL_Utils::InflateRect(const CFX_FloatRect& rcRect, - float fSize) { - if (rcRect.IsEmpty()) - return rcRect; - - CFX_FloatRect rcNew(rcRect.left - fSize, rcRect.bottom - fSize, - rcRect.right + fSize, rcRect.top + fSize); - rcNew.Normalize(); - return rcNew; -} - -CFX_FloatRect CPWL_Utils::DeflateRect(const CFX_FloatRect& rcRect, - float fSize) { - if (rcRect.IsEmpty()) - return rcRect; - - CFX_FloatRect rcNew(rcRect.left + fSize, rcRect.bottom + fSize, - rcRect.right - fSize, rcRect.top - fSize); - rcNew.Normalize(); - return rcNew; -} - CFX_FloatRect CPWL_Utils::ScaleRect(const CFX_FloatRect& rcRect, float fScale) { float fHalfWidth = (rcRect.right - rcRect.left) / 2.0f; float fHalfHeight = (rcRect.top - rcRect.bottom) / 2.0f; @@ -675,6 +653,20 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( if (fWidth > 0.0f) { sAppStream << "q\n"; + float fHalfWidth = fWidth / 2.0f; + + CFX_FloatRect rect_by_2 = rect; + CFX_FloatRect rect_by_75 = rect; + if (!rect.IsEmpty()) { + float div = fWidth / 2.0f; + rect_by_2.Deflate(div, div); + rect_by_2.Normalize(); + + div = fHalfWidth * 0.75f; + rect_by_75.Deflate(div, div); + rect_by_75.Normalize(); + } + switch (nStyle) { default: case BorderStyle::SOLID: @@ -683,9 +675,7 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( if (sColor.GetLength() > 0) { sAppStream << "q\n" << fWidth << " w\n" - << sColor - << CPWL_Utils::GetAP_Circle( - CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) + << sColor << CPWL_Utils::GetAP_Circle(rect_by_2) << " S\nQ\n"; } } break; @@ -696,15 +686,11 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( << fWidth << " w\n" << "[" << dash.nDash << " " << dash.nGap << "] " << dash.nPhase << " d\n" - << sColor - << CPWL_Utils::GetAP_Circle( - CPWL_Utils::DeflateRect(rect, fWidth / 2.0f)) + << sColor << CPWL_Utils::GetAP_Circle(rect_by_2) << " S\nQ\n"; } } break; case BorderStyle::BEVELED: { - float fHalfWidth = fWidth / 2.0f; - sColor = CPWL_Utils::GetColorAppStream(color, false); if (sColor.GetLength() > 0) { sAppStream << "q\n" @@ -717,9 +703,7 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI / 4.0f) + << CPWL_Utils::GetAP_HalfCircle(rect_by_75, FX_PI / 4.0f) << " S\nQ\n"; } @@ -728,15 +712,12 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI * 5 / 4.0f) + << CPWL_Utils::GetAP_HalfCircle(rect_by_75, + FX_PI * 5 / 4.0f) << " S\nQ\n"; } } break; case BorderStyle::INSET: { - float fHalfWidth = fWidth / 2.0f; - sColor = CPWL_Utils::GetColorAppStream(color, false); if (sColor.GetLength() > 0) { sAppStream << "q\n" @@ -749,9 +730,7 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI / 4.0f) + << CPWL_Utils::GetAP_HalfCircle(rect_by_75, FX_PI / 4.0f) << " S\nQ\n"; } @@ -760,9 +739,8 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( sAppStream << "q\n" << fHalfWidth << " w\n" << sColor - << CPWL_Utils::GetAP_HalfCircle( - CPWL_Utils::DeflateRect(rect, fHalfWidth * 0.75f), - FX_PI * 5 / 4.0f) + << CPWL_Utils::GetAP_HalfCircle(rect_by_75, + FX_PI * 5 / 4.0f) << " S\nQ\n"; } } break; diff --git a/fpdfsdk/pdfwindow/cpwl_utils.h b/fpdfsdk/pdfwindow/cpwl_utils.h index 5f039ad77c..ef06073d99 100644 --- a/fpdfsdk/pdfwindow/cpwl_utils.h +++ b/fpdfsdk/pdfwindow/cpwl_utils.h @@ -32,9 +32,6 @@ struct CPWL_Color; class CPWL_Utils { public: - static CFX_FloatRect InflateRect(const CFX_FloatRect& rcRect, float fSize); - static CFX_FloatRect DeflateRect(const CFX_FloatRect& rcRect, float fSize); - static CPVT_WordRange OverlapWordRange(const CPVT_WordRange& wr1, const CPVT_WordRange& wr2); static CFX_FloatRect GetCenterSquare(const CFX_FloatRect& rect); diff --git a/fpdfsdk/pdfwindow/cpwl_wnd.cpp b/fpdfsdk/pdfwindow/cpwl_wnd.cpp index 6e2e75c5a1..552c901f06 100644 --- a/fpdfsdk/pdfwindow/cpwl_wnd.cpp +++ b/fpdfsdk/pdfwindow/cpwl_wnd.cpp @@ -155,7 +155,11 @@ void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { m_sPrivateParam.rcRectWnd.Normalize(); m_rcWindow = m_sPrivateParam.rcRectWnd; - m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f); + m_rcClip = m_rcWindow; + if (!m_rcClip.IsEmpty()) { + m_rcClip.Inflate(1.0f, 1.0f); + m_rcClip.Normalize(); + } CreateMsgControl(); if (m_sPrivateParam.pParentWnd) @@ -288,8 +292,13 @@ void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, return; if (HasFlag(PWS_BACKGROUND)) { - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth())); + CFX_FloatRect rcClient = rectWnd; + if (!rcClient.IsEmpty()) { + float width = + static_cast(GetBorderWidth() + GetInnerBorderWidth()); + rcClient.Deflate(width, width); + rcClient.Normalize(); + } CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, GetBackgroundColor(), GetTransparency()); } @@ -459,8 +468,13 @@ CFX_FloatRect CPWL_Wnd::GetWindowRect() const { CFX_FloatRect CPWL_Wnd::GetClientRect() const { CFX_FloatRect rcWindow = GetWindowRect(); - CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( - rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth())); + CFX_FloatRect rcClient = rcWindow; + if (!rcClient.IsEmpty()) { + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + rcClient.Deflate(width, width); + rcClient.Normalize(); + } + if (CPWL_ScrollBar* pVSB = GetVScrollBar()) rcClient.right -= pVSB->GetScrollBarWidth(); @@ -633,8 +647,12 @@ void CPWL_Wnd::RePosChildWnd() { if (!pVSB) return; - CFX_FloatRect rcContent = CPWL_Utils::DeflateRect( - GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); + CFX_FloatRect rcContent = GetWindowRect(); + if (!rcContent.IsEmpty()) { + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + rcContent.Deflate(width, width); + rcContent.Normalize(); + } CFX_FloatRect rcVScroll = CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, rcContent.right - 1.0f, rcContent.top); @@ -687,7 +705,12 @@ bool CPWL_Wnd::IsFocused() const { } CFX_FloatRect CPWL_Wnd::GetFocusRect() const { - return CPWL_Utils::InflateRect(GetWindowRect(), 1); + CFX_FloatRect rect = GetWindowRect(); + if (!rect.IsEmpty()) { + rect.Inflate(1.0f, 1.0f); + rect.Normalize(); + } + return rect; } float CPWL_Wnd::GetFontSize() const { -- cgit v1.2.3