From d6aff2f2e8469344becd6f73e443c31bca9baac0 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 13 Jul 2017 21:36:29 -0400 Subject: Add CFX_FloatRect::GetDeflated This CL adds a method to CFX_FloatRect to get a new deflated rectangle from a given rectangle. Change-Id: I781222257c82baf94d5f77deede52fbe4e97c701 Reviewed-on: https://pdfium-review.googlesource.com/7850 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- core/fxcrt/fx_coordinates.h | 10 +++++++++ fpdfsdk/cpdfsdk_widget.cpp | 36 +++++-------------------------- fpdfsdk/pdfwindow/cpwl_edit.cpp | 9 ++------ fpdfsdk/pdfwindow/cpwl_list_box.cpp | 9 ++------ fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp | 27 +++++++++-------------- fpdfsdk/pdfwindow/cpwl_special_button.cpp | 9 ++------ fpdfsdk/pdfwindow/cpwl_utils.cpp | 15 +++---------- fpdfsdk/pdfwindow/cpwl_wnd.cpp | 19 +++++----------- 8 files changed, 39 insertions(+), 95 deletions(-) diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index 79f7d4f29e..bcbdc0b804 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -543,6 +543,16 @@ class CFX_FloatRect { Deflate(rt.left, rt.bottom, rt.right, rt.top); } + CFX_FloatRect GetDeflated(float x, float y) const { + if (IsEmpty()) + return CFX_FloatRect(); + + CFX_FloatRect that = *this; + that.Deflate(x, y); + that.Normalize(); + return that; + } + void Translate(float e, float f) { left += e; right += e; diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index b0f3c3468b..80e7c8adb1 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -925,12 +925,7 @@ void CPDFSDK_Widget::ResetAppearance_PushButton() { break; } - CFX_FloatRect rcClient = rcWindow; - if (!rcClient.IsEmpty()) { - rcClient.Deflate(fBorderWidth, fBorderWidth); - rcClient.Normalize(); - } - + CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); CFX_Color crText(COLORTYPE_GRAY, 0); CFX_ByteString csNameTag; @@ -1107,12 +1102,7 @@ void CPDFSDK_Widget::ResetAppearance_CheckBox() { } CFX_FloatRect rcWindow = GetRotatedRect(); - CFX_FloatRect rcClient = rcWindow; - if (!rcClient.IsEmpty()) { - rcClient.Deflate(fBorderWidth, fBorderWidth); - rcClient.Normalize(); - } - + CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); if (da.HasColor()) { da.GetColor(iColorType, fc); @@ -1232,12 +1222,7 @@ void CPDFSDK_Widget::ResetAppearance_RadioButton() { } CFX_FloatRect rcWindow = GetRotatedRect(); - CFX_FloatRect rcClient = rcWindow; - if (!rcClient.IsEmpty()) { - rcClient.Deflate(fBorderWidth, fBorderWidth); - rcClient.Normalize(); - } - + CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); if (da.HasColor()) { da.GetColor(iColorType, fc); @@ -1272,13 +1257,7 @@ void CPDFSDK_Widget::ResetAppearance_RadioButton() { } CFX_ByteString csAP_N_ON; - - CFX_FloatRect rcCenter = rcWindow.GetCenterSquare(); - if (!rcCenter.IsEmpty()) { - rcCenter.Deflate(1.0f, 1.0f); - rcCenter.Normalize(); - } - + CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f); if (nStyle == PCS_CIRCLE) { if (nBorderStyle == BorderStyle::BEVELED) { crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); @@ -1664,12 +1643,7 @@ CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { default: break; } - - if (!rcWindow.IsEmpty()) { - rcWindow.Deflate(fBorderWidth, fBorderWidth); - rcWindow.Normalize(); - } - return rcWindow; + return rcWindow.GetDeflated(fBorderWidth, fBorderWidth); } CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { diff --git a/fpdfsdk/pdfwindow/cpwl_edit.cpp b/fpdfsdk/pdfwindow/cpwl_edit.cpp index 92b3f6498e..7d75bc693d 100644 --- a/fpdfsdk/pdfwindow/cpwl_edit.cpp +++ b/fpdfsdk/pdfwindow/cpwl_edit.cpp @@ -103,13 +103,8 @@ void CPWL_Edit::RePosChildWnd() { } CFX_FloatRect CPWL_Edit::GetClientRect() const { - CFX_FloatRect rcClient = GetWindowRect(); - if (!rcClient.IsEmpty()) { - float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); - rcClient.Deflate(width, width); - rcClient.Normalize(); - } - + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + CFX_FloatRect rcClient = GetWindowRect().GetDeflated(width, width); if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { if (pVSB->IsVisible()) { rcClient.right -= PWL_SCROLLBAR_WIDTH; diff --git a/fpdfsdk/pdfwindow/cpwl_list_box.cpp b/fpdfsdk/pdfwindow/cpwl_list_box.cpp index 4b4df33e39..96df02c642 100644 --- a/fpdfsdk/pdfwindow/cpwl_list_box.cpp +++ b/fpdfsdk/pdfwindow/cpwl_list_box.cpp @@ -405,13 +405,8 @@ float CPWL_ListBox::GetFirstHeight() const { } CFX_FloatRect CPWL_ListBox::GetListRect() const { - CFX_FloatRect rect = GetWindowRect(); - if (!rect.IsEmpty()) { - float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); - rect.Deflate(width, width); - rect.Normalize(); - } - return rect; + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + return GetWindowRect().GetDeflated(width, width); } bool CPWL_ListBox::OnMouseWheel(short zDelta, diff --git a/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp b/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp index 491d0b3876..dc153fda37 100644 --- a/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pdfwindow/cpwl_scroll_bar.cpp @@ -242,31 +242,23 @@ void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, } // draw border - CFX_FloatRect rcDraw = rectWnd; - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rectWnd, ArgbEncode(nTransparency, 100, 100, 100), 0.0f); // draw inner border - rcDraw = rectWnd; - if (!rcDraw.IsEmpty()) { - rcDraw.Deflate(0.5f, 0.5f); - rcDraw.Normalize(); - } - CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, rcDraw, + CPWL_Utils::DrawStrokeRect(pDevice, pUser2Device, + rectWnd.GetDeflated(0.5f, 0.5f), ArgbEncode(nTransparency, 255, 255, 255), 1.0f); if (m_eSBButtonType != PSBT_POS) { // draw background - 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); + CPWL_Utils::DrawShadow(pDevice, pUser2Device, true, false, + rectWnd.GetDeflated(1.0f, 1.0f), nTransparency, 80, + 220); } else { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, + rectWnd.GetDeflated(1.0f, 1.0f), ArgbEncode(255, 255, 255, 255)); } @@ -326,7 +318,8 @@ void CPWL_SBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, ptBottom.x += 1.0f; } } else { - CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcDraw, + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, + rectWnd.GetDeflated(0.5f, 0.5f), ArgbEncode(255, 255, 255, 255)); } diff --git a/fpdfsdk/pdfwindow/cpwl_special_button.cpp b/fpdfsdk/pdfwindow/cpwl_special_button.cpp index 743565f0dc..da91da3ecb 100644 --- a/fpdfsdk/pdfwindow/cpwl_special_button.cpp +++ b/fpdfsdk/pdfwindow/cpwl_special_button.cpp @@ -18,13 +18,8 @@ CFX_ByteString CPWL_PushButton::GetClassName() const { } CFX_FloatRect CPWL_PushButton::GetFocusRect() const { - CFX_FloatRect rect = GetWindowRect(); - if (!rect.IsEmpty()) { - rect.Deflate(static_cast(GetBorderWidth()), - static_cast(GetBorderWidth())); - rect.Normalize(); - } - return rect; + return GetWindowRect().GetDeflated(static_cast(GetBorderWidth()), + static_cast(GetBorderWidth())); } CPWL_CheckBox::CPWL_CheckBox() : m_bChecked(false) {} diff --git a/fpdfsdk/pdfwindow/cpwl_utils.cpp b/fpdfsdk/pdfwindow/cpwl_utils.cpp index c576044a69..af69174276 100644 --- a/fpdfsdk/pdfwindow/cpwl_utils.cpp +++ b/fpdfsdk/pdfwindow/cpwl_utils.cpp @@ -611,19 +611,10 @@ CFX_ByteString CPWL_Utils::GetCircleBorderAppStream( sAppStream << "q\n"; float fHalfWidth = fWidth / 2.0f; + CFX_FloatRect rect_by_2 = rect.GetDeflated(fHalfWidth, fHalfWidth); - 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(); - } - + float div = fHalfWidth * 0.75f; + CFX_FloatRect rect_by_75 = rect.GetDeflated(div, div); switch (nStyle) { default: case BorderStyle::SOLID: diff --git a/fpdfsdk/pdfwindow/cpwl_wnd.cpp b/fpdfsdk/pdfwindow/cpwl_wnd.cpp index 5aae2dfa92..863b9aab9a 100644 --- a/fpdfsdk/pdfwindow/cpwl_wnd.cpp +++ b/fpdfsdk/pdfwindow/cpwl_wnd.cpp @@ -292,14 +292,9 @@ void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, return; if (HasFlag(PWS_BACKGROUND)) { - 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, + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + CPWL_Utils::DrawFillRect(pDevice, pUser2Device, + rectWnd.GetDeflated(width, width), GetBackgroundColor(), GetTransparency()); } @@ -468,13 +463,9 @@ CFX_FloatRect CPWL_Wnd::GetWindowRect() const { CFX_FloatRect CPWL_Wnd::GetClientRect() const { CFX_FloatRect rcWindow = GetWindowRect(); - CFX_FloatRect rcClient = rcWindow; - if (!rcClient.IsEmpty()) { - float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); - rcClient.Deflate(width, width); - rcClient.Normalize(); - } + float width = static_cast(GetBorderWidth() + GetInnerBorderWidth()); + CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width); if (CPWL_ScrollBar* pVSB = GetVScrollBar()) rcClient.right -= pVSB->GetScrollBarWidth(); -- cgit v1.2.3