• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
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 "core/fxge/render_defines.h"
10 #include "xfa/fwl/cfwl_pushbutton.h"
11 #include "xfa/fwl/cfwl_themebackground.h"
12 #include "xfa/fwl/cfwl_widget.h"
13 #include "xfa/fwl/ifwl_themeprovider.h"
14 #include "xfa/fxgraphics/cxfa_gecolor.h"
15 #include "xfa/fxgraphics/cxfa_gepath.h"
16 
17 #define PUSHBUTTON_SIZE_Corner 2
18 
CFWL_PushButtonTP()19 CFWL_PushButtonTP::CFWL_PushButtonTP() : m_pThemeData(new PBThemeData) {
20   SetThemeData();
21 }
22 
~CFWL_PushButtonTP()23 CFWL_PushButtonTP::~CFWL_PushButtonTP() {}
24 
DrawBackground(const CFWL_ThemeBackground & pParams)25 void CFWL_PushButtonTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
26   switch (pParams.m_iPart) {
27     case CFWL_Part::Border: {
28       DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
29       break;
30     }
31     case CFWL_Part::Background: {
32       const CFX_RectF& rect = pParams.m_rtPart;
33       float fRight = rect.right();
34       float fBottom = rect.bottom();
35 
36       CXFA_GEPath strokePath;
37       strokePath.MoveTo(
38           CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top));
39       strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, rect.top));
40       strokePath.LineTo(CFX_PointF(fRight, rect.top + PUSHBUTTON_SIZE_Corner));
41       strokePath.LineTo(CFX_PointF(fRight, fBottom - PUSHBUTTON_SIZE_Corner));
42       strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, fBottom));
43       strokePath.LineTo(
44           CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, fBottom));
45       strokePath.LineTo(
46           CFX_PointF(rect.left, fBottom - PUSHBUTTON_SIZE_Corner));
47       strokePath.LineTo(
48           CFX_PointF(rect.left, rect.top + PUSHBUTTON_SIZE_Corner));
49       strokePath.LineTo(
50           CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top));
51 
52       CXFA_GEPath fillPath;
53       fillPath.AddSubpath(&strokePath);
54 
55       CXFA_Graphics* pGraphics = pParams.m_pGraphics.Get();
56       pGraphics->SaveGraphState();
57 
58       CFX_RectF rtInner(rect);
59       rtInner.Deflate(PUSHBUTTON_SIZE_Corner + 1, PUSHBUTTON_SIZE_Corner + 1,
60                       PUSHBUTTON_SIZE_Corner, PUSHBUTTON_SIZE_Corner);
61       fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
62                             rtInner.height);
63 
64       int32_t iColor = GetColorID(pParams.m_dwStates);
65       FillSolidRect(pGraphics, m_pThemeData->clrEnd[iColor], rect,
66                     pParams.m_matrix);
67 
68       pGraphics->SetStrokeColor(CXFA_GEColor(m_pThemeData->clrBorder[iColor]));
69       pGraphics->StrokePath(&strokePath, &pParams.m_matrix);
70 
71       fillPath.Clear();
72       fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
73                             rtInner.height);
74 
75       pGraphics->SetFillColor(CXFA_GEColor(m_pThemeData->clrFill[iColor]));
76       pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams.m_matrix);
77       if (pParams.m_dwStates & CFWL_PartState_Focused) {
78         rtInner.Inflate(1, 1, 0, 0);
79         DrawFocus(pGraphics, rtInner, pParams.m_matrix);
80       }
81       pGraphics->RestoreGraphState();
82       break;
83     }
84     default:
85       break;
86   }
87 }
88 
SetThemeData()89 void CFWL_PushButtonTP::SetThemeData() {
90   m_pThemeData->clrBorder[0] = ArgbEncode(255, 0, 60, 116);
91   m_pThemeData->clrBorder[1] = ArgbEncode(255, 0, 60, 116);
92   m_pThemeData->clrBorder[2] = ArgbEncode(255, 0, 60, 116);
93   m_pThemeData->clrBorder[3] = ArgbEncode(255, 0, 60, 116);
94   m_pThemeData->clrBorder[4] = ArgbEncode(255, 201, 199, 186);
95   m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 255);
96   m_pThemeData->clrStart[1] = ArgbEncode(255, 209, 204, 193);
97   m_pThemeData->clrStart[2] = ArgbEncode(255, 255, 240, 207);
98   m_pThemeData->clrStart[3] = ArgbEncode(255, 206, 231, 255);
99   m_pThemeData->clrStart[4] = ArgbEncode(255, 245, 244, 234);
100   m_pThemeData->clrEnd[0] = ArgbEncode(255, 214, 208, 197);
101   m_pThemeData->clrEnd[1] = ArgbEncode(255, 242, 241, 238);
102   m_pThemeData->clrEnd[2] = ArgbEncode(255, 229, 151, 0);
103   m_pThemeData->clrEnd[3] = ArgbEncode(255, 105, 130, 238);
104   m_pThemeData->clrEnd[4] = ArgbEncode(255, 245, 244, 234);
105   m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);
106   m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);
107   m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);
108   m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);
109   m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
110 }
111 
GetColorID(uint32_t dwStates) const112 int32_t CFWL_PushButtonTP::GetColorID(uint32_t dwStates) const {
113   int32_t color = 0;
114   if (dwStates & CFWL_PartState_Disabled)
115     color += 4;
116   if (dwStates & CFWL_PartState_Default) {
117     color += 3;
118   } else {
119     if (dwStates & CFWL_PartState_Hovered)
120       color += 2;
121     if (dwStates & CFWL_PartState_Pressed)
122       color += 1;
123   }
124   return color;
125 }
126