From c635c93c974db1c55032c36e81e98f3d214a249f Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 3 Jan 2017 15:46:55 -0500 Subject: Remove the ::GetCapacity methods. The GetCapacity methods return a void* because they return different types of internal class memory based on what the calling parameter was. This is confusing and makes it difficult to tell when then enum values can be removed. This CL removes GetCapacity and adds methods as needed to get the real values. Change-Id: I64c2edc858220624880e27f4ed49c2dae080f462 Reviewed-on: https://pdfium-review.googlesource.com/2137 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- xfa/fxfa/app/xfa_ffcheckbutton.cpp | 3 +- xfa/fxfa/app/xfa_fffield.cpp | 9 +-- xfa/fxfa/app/xfa_ffimageedit.cpp | 3 +- xfa/fxfa/app/xfa_ffwidgetacc.cpp | 9 +-- xfa/fxfa/app/xfa_fwltheme.cpp | 154 ++++++++++++++++++------------------- xfa/fxfa/app/xfa_fwltheme.h | 17 ++-- 6 files changed, 94 insertions(+), 101 deletions(-) (limited to 'xfa/fxfa/app') diff --git a/xfa/fxfa/app/xfa_ffcheckbutton.cpp b/xfa/fxfa/app/xfa_ffcheckbutton.cpp index 30ea09ff4d..e8a422ebd6 100644 --- a/xfa/fxfa/app/xfa_ffcheckbutton.cpp +++ b/xfa/fxfa/app/xfa_ffcheckbutton.cpp @@ -192,8 +192,7 @@ void CXFA_FFCheckButton::CapLeftRightPlacement(CXFA_Margin mgCap) { } } void CXFA_FFCheckButton::AddUIMargin(int32_t iCapPlacement) { - CFX_RectF rtUIMargin; - m_pDataAcc->GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); m_rtUI.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2; FX_FLOAT fLeftAddRight = rtUIMargin.left + rtUIMargin.width; FX_FLOAT fTopAddBottom = rtUIMargin.top + rtUIMargin.height; diff --git a/xfa/fxfa/app/xfa_fffield.cpp b/xfa/fxfa/app/xfa_fffield.cpp index 2e15696ab7..0bd6160944 100644 --- a/xfa/fxfa/app/xfa_fffield.cpp +++ b/xfa/fxfa/app/xfa_fffield.cpp @@ -135,8 +135,7 @@ void CXFA_FFField::SetEditScrollOffset() { FX_FLOAT fScrollOffset = 0; CXFA_FFField* pPrev = static_cast(GetPrev()); if (pPrev) { - CFX_RectF rtMargin; - m_pDataAcc->GetUIMargin(rtMargin); + CFX_RectF rtMargin = m_pDataAcc->GetUIMargin(); fScrollOffset = -rtMargin.top; } while (pPrev) { @@ -265,8 +264,7 @@ void CXFA_FFField::CapPlacement() { void CXFA_FFField::CapTopBottomPlacement(CXFA_Caption caption, const CFX_RectF& rtWidget, int32_t iCapPlacement) { - CFX_RectF rtUIMargin; - m_pDataAcc->GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); m_rtCaption.left += rtUIMargin.left; if (CXFA_Margin mgCap = caption.GetMargin()) { XFA_RectWidthoutMargin(m_rtCaption, mgCap); @@ -292,8 +290,7 @@ void CXFA_FFField::CapTopBottomPlacement(CXFA_Caption caption, void CXFA_FFField::CapLeftRightPlacement(CXFA_Caption caption, const CFX_RectF& rtWidget, int32_t iCapPlacement) { - CFX_RectF rtUIMargin; - m_pDataAcc->GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); m_rtCaption.top += rtUIMargin.top; m_rtCaption.height -= rtUIMargin.top; if (CXFA_Margin mgCap = caption.GetMargin()) { diff --git a/xfa/fxfa/app/xfa_ffimageedit.cpp b/xfa/fxfa/app/xfa_ffimageedit.cpp index 04ad313a27..3b063d6e98 100644 --- a/xfa/fxfa/app/xfa_ffimageedit.cpp +++ b/xfa/fxfa/app/xfa_ffimageedit.cpp @@ -107,8 +107,7 @@ void CXFA_FFImageEdit::SetFWLRect() { if (!m_pNormalWidget) { return; } - CFX_RectF rtUIMargin; - m_pDataAcc->GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); CFX_RectF rtImage(m_rtUI); rtImage.Deflate(rtUIMargin.left, rtUIMargin.top, rtUIMargin.width, rtUIMargin.height); diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index 3ff159aa41..13145e6448 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -768,8 +768,7 @@ void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { bool CXFA_WidgetAcc::CalculateFieldAutoSize(CFX_SizeF& size) { CFX_SizeF szCap; CalcCaptionSize(szCap); - CFX_RectF rtUIMargin; - GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = GetUIMargin(); size.x += rtUIMargin.left + rtUIMargin.width; size.y += rtUIMargin.top + rtUIMargin.height; if (szCap.x > 0 && szCap.y > 0) { @@ -883,8 +882,7 @@ bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) { break; } } - CFX_RectF rtUIMargin; - GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = GetUIMargin(); size.x -= rtUIMargin.left + rtUIMargin.width; CXFA_Margin mgWidget = GetMargin(); if (mgWidget) { @@ -1168,8 +1166,7 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { mgWidget.GetTopInset(fTopInset); mgWidget.GetBottomInset(fBottomInset); } - CFX_RectF rtUIMargin; - GetUIMargin(rtUIMargin); + CFX_RectF rtUIMargin = GetUIMargin(); fTopInset += rtUIMargin.top; fBottomInset += rtUIMargin.width; } diff --git a/xfa/fxfa/app/xfa_fwltheme.cpp b/xfa/fxfa/app/xfa_fwltheme.cpp index c08e51f807..d12678e51b 100644 --- a/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/xfa/fxfa/app/xfa_fwltheme.cpp @@ -32,6 +32,8 @@ const FX_WCHAR* const g_FWLTheme_CalFonts[] = { L"Arial", L"Courier New", L"DejaVu Sans", }; +const float kLineHeight = 12.0f; + } // namespace CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget) { @@ -54,8 +56,6 @@ CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) m_pCaretTP(new CFWL_CaretTP), m_pBarcodeTP(new CFWL_BarcodeTP), m_pTextOut(new CFDE_TextOut), - m_fCapacity(0.0f), - m_dwCapacity(0), m_pCalendarFont(nullptr), m_pApp(pApp) { m_Rect.Reset(); @@ -151,84 +151,80 @@ void CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) { pParams->m_wsText.GetLength(), pParams->m_rtPart); } -void* CXFA_FWLTheme::GetCapacity(CFWL_ThemePart* pThemePart, - CFWL_WidgetCapacity dwCapacity) { - switch (dwCapacity) { - case CFWL_WidgetCapacity::Font: { - if (CXFA_FFWidget* pWidget = - XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { - return pWidget->GetDataAcc()->GetFDEFont(); - } - break; - } - case CFWL_WidgetCapacity::FontSize: { - if (CXFA_FFWidget* pWidget = - XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { - m_fCapacity = pWidget->GetDataAcc()->GetFontSize(); - return &m_fCapacity; - } - break; - } - case CFWL_WidgetCapacity::TextColor: { - if (CXFA_FFWidget* pWidget = - XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { - m_dwCapacity = pWidget->GetDataAcc()->GetTextColor(); - return &m_dwCapacity; - } - break; - } - case CFWL_WidgetCapacity::LineHeight: { - if (CXFA_FFWidget* pWidget = - XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { - m_fCapacity = pWidget->GetDataAcc()->GetLineHeight(); - return &m_fCapacity; - } - break; - } - case CFWL_WidgetCapacity::ScrollBarWidth: { - m_fCapacity = 9; - return &m_fCapacity; - } - case CFWL_WidgetCapacity::UIMargin: { - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget); - if (pWidget) { - CXFA_LayoutItem* pItem = pWidget; - CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); - pWidgetAcc->GetUIMargin(m_Rect); - if (CXFA_Para para = pWidgetAcc->GetPara()) { - m_Rect.left += para.GetMarginLeft(); - if (pWidgetAcc->IsMultiLine()) { - m_Rect.width += para.GetMarginRight(); - } - } - if (!pItem->GetPrev()) { - if (pItem->GetNext()) { - m_Rect.height = 0; - } - } else if (!pItem->GetNext()) { - m_Rect.top = 0; - } else { - m_Rect.top = 0; - m_Rect.height = 0; - } - } - return &m_Rect; - } - case CFWL_WidgetCapacity::SpaceAboveBelow: { - CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget); - if (pWidget) { - CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); - if (CXFA_Para para = pWidgetAcc->GetPara()) { - m_SizeAboveBelow.x = para.GetSpaceAbove(); - m_SizeAboveBelow.y = para.GetSpaceBelow(); - } - } - return &m_SizeAboveBelow; +CFX_RectF CXFA_FWLTheme::GetUIMargin(CFWL_ThemePart* pThemePart) const { + CFX_RectF rect; + rect.Reset(); + + CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget); + if (!pWidget) + return rect; + + CXFA_LayoutItem* pItem = pWidget; + CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); + rect = pWidgetAcc->GetUIMargin(); + if (CXFA_Para para = pWidgetAcc->GetPara()) { + rect.left += para.GetMarginLeft(); + if (pWidgetAcc->IsMultiLine()) + rect.width += para.GetMarginRight(); + } + if (!pItem->GetPrev()) { + if (pItem->GetNext()) + rect.height = 0; + } else if (!pItem->GetNext()) { + rect.top = 0; + } else { + rect.top = 0; + rect.height = 0; + } + return rect; +} + +float CXFA_FWLTheme::GetCXBorderSize() const { + return 1.0f; +} + +float CXFA_FWLTheme::GetCYBorderSize() const { + return 1.0f; +} + +float CXFA_FWLTheme::GetFontSize(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetFontSize(); + return FWLTHEME_CAPACITY_FontSize; +} + +CFGAS_GEFont* CXFA_FWLTheme::GetFont(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetFDEFont(); + return GetTheme(pThemePart->m_pWidget)->GetFont(); +} + +float CXFA_FWLTheme::GetLineHeight(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetLineHeight(); + return kLineHeight; +} + +float CXFA_FWLTheme::GetScrollBarWidth() const { + return 9.0f; +} + +FX_COLORREF CXFA_FWLTheme::GetTextColor(CFWL_ThemePart* pThemePart) const { + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) + return pWidget->GetDataAcc()->GetTextColor(); + return FWLTHEME_CAPACITY_TextColor; +} + +CFX_SizeF CXFA_FWLTheme::GetSpaceAboveBelow(CFWL_ThemePart* pThemePart) const { + CFX_SizeF sizeAboveBelow; + if (CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) { + CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc(); + if (CXFA_Para para = pWidgetAcc->GetPara()) { + sizeAboveBelow.x = para.GetSpaceAbove(); + sizeAboveBelow.y = para.GetSpaceBelow(); } - default: - break; } - return GetTheme(pThemePart->m_pWidget)->GetCapacity(pThemePart, dwCapacity); + return sizeAboveBelow; } void CXFA_FWLTheme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) { @@ -263,7 +259,7 @@ void CXFA_FWLTheme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) { pParams->m_wsText.GetLength(), rect); } -CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(CFWL_Widget* pWidget) { +CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(CFWL_Widget* pWidget) const { switch (pWidget->GetClassID()) { case FWL_Type::CheckBox: return m_pCheckBoxTP.get(); diff --git a/xfa/fxfa/app/xfa_fwltheme.h b/xfa/fxfa/app/xfa_fwltheme.h index 98fd74c315..f8b804893a 100644 --- a/xfa/fxfa/app/xfa_fwltheme.h +++ b/xfa/fxfa/app/xfa_fwltheme.h @@ -32,12 +32,20 @@ class CXFA_FWLTheme final : public IFWL_ThemeProvider { // IFWL_ThemeProvider: void DrawBackground(CFWL_ThemeBackground* pParams) override; void DrawText(CFWL_ThemeText* pParams) override; - void* GetCapacity(CFWL_ThemePart* pThemePart, - CFWL_WidgetCapacity dwCapacity) override; void CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) override; + float GetCXBorderSize() const override; + float GetCYBorderSize() const override; + CFX_RectF GetUIMargin(CFWL_ThemePart* pThemePart) const override; + float GetFontSize(CFWL_ThemePart* pThemePart) const override; + CFGAS_GEFont* GetFont(CFWL_ThemePart* pThemePart) const override; + float GetLineHeight(CFWL_ThemePart* pThemePart) const override; + float GetScrollBarWidth() const override; + FX_COLORREF GetTextColor(CFWL_ThemePart* pThemePart) const override; + CFX_SizeF GetSpaceAboveBelow(CFWL_ThemePart* pThemePart) const override; private: - CFWL_WidgetTP* GetTheme(CFWL_Widget* pWidget); + CFWL_WidgetTP* GetTheme(CFWL_Widget* pWidget) const; + std::unique_ptr m_pCheckBoxTP; std::unique_ptr m_pListBoxTP; std::unique_ptr m_pPictureBoxTP; @@ -50,13 +58,10 @@ class CXFA_FWLTheme final : public IFWL_ThemeProvider { std::unique_ptr m_pCaretTP; std::unique_ptr m_pBarcodeTP; std::unique_ptr m_pTextOut; - FX_FLOAT m_fCapacity; - uint32_t m_dwCapacity; CFGAS_GEFont* m_pCalendarFont; CFX_WideString m_wsResource; CXFA_FFApp* const m_pApp; CFX_RectF m_Rect; - CFX_SizeF m_SizeAboveBelow; }; CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget); -- cgit v1.2.3