Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: xfa/fwl/theme/pushbuttontp.cpp

Issue 1834323003: Move xfa/include/fwl/{theme,lightwidget} to xfa/fwl (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/include/fwl/theme/pushbuttontp.h"
8
9 #include "xfa/fwl/basewidget/ifwl_pushbutton.h"
10 #include "xfa/fwl/core/cfwl_themebackground.h"
11 #include "xfa/fwl/core/ifwl_themeprovider.h"
12 #include "xfa/fwl/core/ifwl_widget.h"
13 #include "xfa/fxgraphics/cfx_color.h"
14 #include "xfa/fxgraphics/cfx_path.h"
15
16 #define PUSHBUTTON_SIZE_Corner 2
17
18 CFWL_PushButtonTP::CFWL_PushButtonTP() {
19 m_pThemeData = new PBThemeData;
20 SetThemeData(0);
21 }
22 CFWL_PushButtonTP::~CFWL_PushButtonTP() {
23 if (m_pThemeData) {
24 delete m_pThemeData;
25 }
26 }
27 FX_BOOL CFWL_PushButtonTP::IsValidWidget(IFWL_Widget* pWidget) {
28 return pWidget->GetClassID() == FWL_CLASSHASH_PushButton;
29 }
30 uint32_t CFWL_PushButtonTP::SetThemeID(IFWL_Widget* pWidget,
31 uint32_t dwThemeID,
32 FX_BOOL bChildren) {
33 SetThemeData(FWL_GetThemeColor(dwThemeID));
34 return CFWL_WidgetTP::SetThemeID(pWidget, dwThemeID, bChildren);
35 }
36 FX_BOOL CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) {
37 switch (pParams->m_iPart) {
38 case FWL_PART_PSB_Border: {
39 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
40 break;
41 }
42 case FWL_PART_PSB_Edge: {
43 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(),
44 &pParams->m_rtPart, &pParams->m_matrix);
45 break;
46 }
47 case FWL_PART_PSB_Background: {
48 CFX_RectF& rect = pParams->m_rtPart;
49 FX_FLOAT fRight = rect.right();
50 FX_FLOAT fBottom = rect.bottom();
51 CFX_Path strokePath;
52 strokePath.Create();
53 strokePath.MoveTo(rect.left + PUSHBUTTON_SIZE_Corner, rect.top);
54 strokePath.LineTo(fRight - PUSHBUTTON_SIZE_Corner, rect.top);
55 strokePath.LineTo(fRight, rect.top + PUSHBUTTON_SIZE_Corner);
56 strokePath.LineTo(fRight, fBottom - PUSHBUTTON_SIZE_Corner);
57 strokePath.LineTo(fRight - PUSHBUTTON_SIZE_Corner, fBottom);
58 strokePath.LineTo(rect.left + PUSHBUTTON_SIZE_Corner, fBottom);
59 strokePath.LineTo(rect.left, fBottom - PUSHBUTTON_SIZE_Corner);
60 strokePath.LineTo(rect.left, rect.top + PUSHBUTTON_SIZE_Corner);
61 strokePath.LineTo(rect.left + PUSHBUTTON_SIZE_Corner, rect.top);
62 CFX_Path fillPath;
63 fillPath.Create();
64 fillPath.AddSubpath(&strokePath);
65 CFX_Graphics* pGraphics = pParams->m_pGraphics;
66 pGraphics->SaveGraphState();
67 CFX_RectF rtInner(rect);
68 rtInner.Deflate(PUSHBUTTON_SIZE_Corner + 1, PUSHBUTTON_SIZE_Corner + 1,
69 PUSHBUTTON_SIZE_Corner, PUSHBUTTON_SIZE_Corner);
70 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
71 rtInner.height);
72 int32_t iColor = GetColorID(pParams->m_dwStates);
73 DrawAxialShading(pGraphics, rect.left + PUSHBUTTON_SIZE_Corner, rect.top,
74 rect.left + PUSHBUTTON_SIZE_Corner, rect.bottom(),
75 m_pThemeData->clrStart[iColor],
76 m_pThemeData->clrEnd[iColor], &fillPath,
77 FXFILL_ALTERNATE, &pParams->m_matrix);
78 CFX_Color crStroke(m_pThemeData->clrBorder[iColor]);
79 pGraphics->SetStrokeColor(&crStroke);
80 pGraphics->StrokePath(&strokePath, &pParams->m_matrix);
81 fillPath.Clear();
82 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
83 rtInner.height);
84 CFX_Color crFill(m_pThemeData->clrFill[iColor]);
85 pGraphics->SetFillColor(&crFill);
86 pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams->m_matrix);
87 if (pParams->m_dwStates & FWL_PARTSTATE_PSB_Focused) {
88 rtInner.Inflate(1, 1, 0, 0);
89 DrawFocus(pGraphics, &rtInner, &pParams->m_matrix);
90 }
91 pGraphics->RestoreGraphState();
92 break;
93 }
94 default: {}
95 }
96 return TRUE;
97 }
98 void* CFWL_PushButtonTP::GetCapacity(CFWL_ThemePart* pThemePart,
99 uint32_t dwCapacity) {
100 if (dwCapacity == FWL_WGTCAPACITY_PSB_Margin) {
101 m_fValue = 0;
102 return &m_fValue;
103 }
104 return CFWL_WidgetTP::GetCapacity(pThemePart, dwCapacity);
105 }
106 FWL_ERR CFWL_PushButtonTP::Initialize() {
107 InitTTO();
108 return CFWL_WidgetTP::Initialize();
109 }
110 FWL_ERR CFWL_PushButtonTP::Finalize() {
111 FinalizeTTO();
112 return CFWL_WidgetTP::Finalize();
113 }
114 void CFWL_PushButtonTP::SetThemeData(uint32_t dwID) {
115 if (dwID) {
116 m_pThemeData->clrBorder[0] = ArgbEncode(255, 55, 98, 6);
117 m_pThemeData->clrBorder[1] = ArgbEncode(255, 55, 98, 6);
118 m_pThemeData->clrBorder[2] = ArgbEncode(255, 55, 98, 6);
119 m_pThemeData->clrBorder[3] = ArgbEncode(255, 55, 98, 6);
120 m_pThemeData->clrBorder[4] = ArgbEncode(255, 172, 168, 153);
121 m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 246);
122 m_pThemeData->clrStart[1] = ArgbEncode(255, 223, 205, 180);
123 m_pThemeData->clrStart[2] = ArgbEncode(255, 252, 197, 149);
124 m_pThemeData->clrStart[3] = ArgbEncode(255, 194, 209, 143);
125 m_pThemeData->clrStart[4] = ArgbEncode(255, 216, 216, 216);
126 m_pThemeData->clrEnd[0] = ArgbEncode(255, 227, 209, 184);
127 m_pThemeData->clrEnd[1] = ArgbEncode(255, 248, 244, 228);
128 m_pThemeData->clrEnd[2] = ArgbEncode(255, 207, 114, 37);
129 m_pThemeData->clrEnd[3] = ArgbEncode(255, 144, 193, 84);
130 m_pThemeData->clrEnd[4] = ArgbEncode(255, 172, 168, 153);
131 m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);
132 m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);
133 m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);
134 m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);
135 m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
136 } else {
137 m_pThemeData->clrBorder[0] = ArgbEncode(255, 0, 60, 116);
138 m_pThemeData->clrBorder[1] = ArgbEncode(255, 0, 60, 116);
139 m_pThemeData->clrBorder[2] = ArgbEncode(255, 0, 60, 116);
140 m_pThemeData->clrBorder[3] = ArgbEncode(255, 0, 60, 116);
141 m_pThemeData->clrBorder[4] = ArgbEncode(255, 201, 199, 186);
142 m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 255);
143 m_pThemeData->clrStart[1] = ArgbEncode(255, 209, 204, 193);
144 m_pThemeData->clrStart[2] = ArgbEncode(255, 255, 240, 207);
145 m_pThemeData->clrStart[3] = ArgbEncode(255, 206, 231, 255);
146 m_pThemeData->clrStart[4] = ArgbEncode(255, 245, 244, 234);
147 m_pThemeData->clrEnd[0] = ArgbEncode(255, 214, 208, 197);
148 m_pThemeData->clrEnd[1] = ArgbEncode(255, 242, 241, 238);
149 m_pThemeData->clrEnd[2] = ArgbEncode(255, 229, 151, 0);
150 m_pThemeData->clrEnd[3] = ArgbEncode(255, 105, 130, 238);
151 m_pThemeData->clrEnd[4] = ArgbEncode(255, 245, 244, 234);
152 m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);
153 m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);
154 m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);
155 m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);
156 m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
157 }
158 }
159 int32_t CFWL_PushButtonTP::GetColorID(uint32_t dwStates) {
160 return dwStates &= FWL_PARTSTATE_PSB_Mask;
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698