1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fwl/theme/cfwl_pushbuttontp.h"
8
9 #include "xfa/fgas/graphics/cfgas_gecolor.h"
10 #include "xfa/fgas/graphics/cfgas_gegraphics.h"
11 #include "xfa/fgas/graphics/cfgas_gepath.h"
12 #include "xfa/fwl/cfwl_pushbutton.h"
13 #include "xfa/fwl/cfwl_themebackground.h"
14 #include "xfa/fwl/cfwl_widget.h"
15 #include "xfa/fwl/ifwl_themeprovider.h"
16
17 namespace pdfium {
18
19 namespace {
20
21 constexpr float kPushbuttonSizeCorner = 2.0f;
22
23 } // namespace
24
CFWL_PushButtonTP()25 CFWL_PushButtonTP::CFWL_PushButtonTP() : m_pThemeData(new PBThemeData) {
26 SetThemeData();
27 }
28
29 CFWL_PushButtonTP::~CFWL_PushButtonTP() = default;
30
DrawBackground(const CFWL_ThemeBackground & pParams)31 void CFWL_PushButtonTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
32 switch (pParams.GetPart()) {
33 case CFWL_ThemePart::Part::kBorder: {
34 DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
35 break;
36 }
37 case CFWL_ThemePart::Part::kBackground: {
38 const CFX_RectF& rect = pParams.m_PartRect;
39 float fRight = rect.right();
40 float fBottom = rect.bottom();
41
42 CFGAS_GEPath strokePath;
43 strokePath.MoveTo(
44 CFX_PointF(rect.left + kPushbuttonSizeCorner, rect.top));
45 strokePath.LineTo(CFX_PointF(fRight - kPushbuttonSizeCorner, rect.top));
46 strokePath.LineTo(CFX_PointF(fRight, rect.top + kPushbuttonSizeCorner));
47 strokePath.LineTo(CFX_PointF(fRight, fBottom - kPushbuttonSizeCorner));
48 strokePath.LineTo(CFX_PointF(fRight - kPushbuttonSizeCorner, fBottom));
49 strokePath.LineTo(CFX_PointF(rect.left + kPushbuttonSizeCorner, fBottom));
50 strokePath.LineTo(CFX_PointF(rect.left, fBottom - kPushbuttonSizeCorner));
51 strokePath.LineTo(
52 CFX_PointF(rect.left, rect.top + kPushbuttonSizeCorner));
53 strokePath.LineTo(
54 CFX_PointF(rect.left + kPushbuttonSizeCorner, rect.top));
55
56 CFGAS_GEPath fillPath;
57 fillPath.AddSubpath(strokePath);
58
59 CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
60 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
61 CFX_RectF rtInner(rect);
62 rtInner.Deflate(kPushbuttonSizeCorner + 1, kPushbuttonSizeCorner + 1,
63 kPushbuttonSizeCorner, kPushbuttonSizeCorner);
64 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
65 rtInner.height);
66
67 int32_t iColor = GetColorID(pParams.m_dwStates);
68 FillSolidRect(pGraphics, m_pThemeData->clrEnd[iColor], rect,
69 pParams.m_matrix);
70
71 pGraphics->SetStrokeColor(CFGAS_GEColor(m_pThemeData->clrBorder[iColor]));
72 pGraphics->StrokePath(strokePath, pParams.m_matrix);
73
74 fillPath.Clear();
75 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
76 rtInner.height);
77
78 pGraphics->SetFillColor(CFGAS_GEColor(m_pThemeData->clrFill[iColor]));
79 pGraphics->FillPath(fillPath, CFX_FillRenderOptions::FillType::kWinding,
80 pParams.m_matrix);
81 if (pParams.m_dwStates & CFWL_PartState::kFocused) {
82 rtInner.Inflate(1, 1, 0, 0);
83 DrawFocus(pGraphics, rtInner, pParams.m_matrix);
84 }
85 break;
86 }
87 default:
88 break;
89 }
90 }
91
SetThemeData()92 void CFWL_PushButtonTP::SetThemeData() {
93 m_pThemeData->clrBorder[0] = ArgbEncode(255, 0, 60, 116);
94 m_pThemeData->clrBorder[1] = ArgbEncode(255, 0, 60, 116);
95 m_pThemeData->clrBorder[2] = ArgbEncode(255, 0, 60, 116);
96 m_pThemeData->clrBorder[3] = ArgbEncode(255, 0, 60, 116);
97 m_pThemeData->clrBorder[4] = ArgbEncode(255, 201, 199, 186);
98 m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 255);
99 m_pThemeData->clrStart[1] = ArgbEncode(255, 209, 204, 193);
100 m_pThemeData->clrStart[2] = ArgbEncode(255, 255, 240, 207);
101 m_pThemeData->clrStart[3] = ArgbEncode(255, 206, 231, 255);
102 m_pThemeData->clrStart[4] = ArgbEncode(255, 245, 244, 234);
103 m_pThemeData->clrEnd[0] = ArgbEncode(255, 214, 208, 197);
104 m_pThemeData->clrEnd[1] = ArgbEncode(255, 242, 241, 238);
105 m_pThemeData->clrEnd[2] = ArgbEncode(255, 229, 151, 0);
106 m_pThemeData->clrEnd[3] = ArgbEncode(255, 105, 130, 238);
107 m_pThemeData->clrEnd[4] = ArgbEncode(255, 245, 244, 234);
108 m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);
109 m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);
110 m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);
111 m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);
112 m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
113 }
114
GetColorID(Mask<CFWL_PartState> dwStates) const115 int32_t CFWL_PushButtonTP::GetColorID(Mask<CFWL_PartState> dwStates) const {
116 int32_t color = 0;
117 if (dwStates & CFWL_PartState::kDisabled)
118 color += 4;
119 if (dwStates & CFWL_PartState::kDefault) {
120 color += 3;
121 } else {
122 if (dwStates & CFWL_PartState::kHovered)
123 color += 2;
124 if (dwStates & CFWL_PartState::kPressed)
125 color += 1;
126 }
127 return color;
128 }
129
130 } // namespace pdfium
131