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

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

Issue 2418413005: Remove FWL theme subclasses (Closed)
Patch Set: Review fixes Created 4 years, 2 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
« no previous file with comments | « xfa/fwl/theme/cfwl_checkboxtp.h ('k') | xfa/fwl/theme/cfwl_edittp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/theme/cfwl_checkboxtp.h" 7 #include "xfa/fwl/theme/cfwl_checkboxtp.h"
8 8
9 #include "core/fxge/cfx_pathdata.h" 9 #include "core/fxge/cfx_pathdata.h"
10 #include "xfa/fde/tto/fde_textout.h" 10 #include "xfa/fde/tto/fde_textout.h"
11 #include "xfa/fwl/basewidget/ifwl_checkbox.h" 11 #include "xfa/fwl/basewidget/ifwl_checkbox.h"
12 #include "xfa/fwl/core/cfwl_themebackground.h" 12 #include "xfa/fwl/core/cfwl_themebackground.h"
13 #include "xfa/fwl/core/cfwl_themetext.h" 13 #include "xfa/fwl/core/cfwl_themetext.h"
14 #include "xfa/fwl/core/ifwl_widget.h" 14 #include "xfa/fwl/core/ifwl_widget.h"
15 #include "xfa/fxgraphics/cfx_color.h" 15 #include "xfa/fxgraphics/cfx_color.h"
16 #include "xfa/fxgraphics/cfx_path.h" 16 #include "xfa/fxgraphics/cfx_path.h"
17 17
18 namespace { 18 namespace {
19 19
20 const int kSignMargin = 3;
21 const int kSignBorder = 2;
22 const int kSignPath = 100; 20 const int kSignPath = 100;
23 21
24 } // namespace 22 } // namespace
25 23
26 #define CHECKBOX_COLOR_BOXLT1 (ArgbEncode(255, 172, 168, 153)) 24 #define CHECKBOX_COLOR_BOXLT1 (ArgbEncode(255, 172, 168, 153))
27 #define CHECKBOX_COLOR_BOXLT2 (ArgbEncode(255, 113, 111, 100)) 25 #define CHECKBOX_COLOR_BOXLT2 (ArgbEncode(255, 113, 111, 100))
28 #define CHECKBOX_COLOR_BOXRB1 (ArgbEncode(255, 241, 239, 226)) 26 #define CHECKBOX_COLOR_BOXRB1 (ArgbEncode(255, 241, 239, 226))
29 #define CHECKBOX_COLOR_BOXRB2 (ArgbEncode(255, 255, 255, 255)) 27 #define CHECKBOX_COLOR_BOXRB2 (ArgbEncode(255, 255, 255, 255))
30 28
31 CFWL_CheckBoxTP::CFWL_CheckBoxTP() : m_pThemeData(new CKBThemeData) { 29 CFWL_CheckBoxTP::CFWL_CheckBoxTP() : m_pThemeData(new CKBThemeData) {
(...skipping 17 matching lines...) Expand all
49 47
50 FX_BOOL CFWL_CheckBoxTP::DrawText(CFWL_ThemeText* pParams) { 48 FX_BOOL CFWL_CheckBoxTP::DrawText(CFWL_ThemeText* pParams) {
51 if (!m_pTextOut) 49 if (!m_pTextOut)
52 return FALSE; 50 return FALSE;
53 m_pTextOut->SetTextColor(pParams->m_dwStates & CFWL_PartState_Disabled 51 m_pTextOut->SetTextColor(pParams->m_dwStates & CFWL_PartState_Disabled
54 ? FWLTHEME_CAPACITY_TextDisColor 52 ? FWLTHEME_CAPACITY_TextDisColor
55 : FWLTHEME_CAPACITY_TextColor); 53 : FWLTHEME_CAPACITY_TextColor);
56 return CFWL_WidgetTP::DrawText(pParams); 54 return CFWL_WidgetTP::DrawText(pParams);
57 } 55 }
58 56
59 FX_BOOL CFWL_CheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) {
60 if (!pParams)
61 return FALSE;
62 switch (pParams->m_iPart) {
63 case CFWL_Part::Border: {
64 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
65 break;
66 }
67 case CFWL_Part::Edge: {
68 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(),
69 &pParams->m_rtPart, &pParams->m_matrix);
70 break;
71 }
72 case CFWL_Part::Background: {
73 FillBackground(pParams->m_pGraphics, &pParams->m_rtPart,
74 &pParams->m_matrix);
75 if (pParams->m_dwStates & CFWL_PartState_Focused) {
76 pParams->m_rtPart = *(CFX_RectF*)pParams->m_pData;
77 DrawFocus(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
78 }
79 break;
80 }
81 case CFWL_Part::CheckBox: {
82 DrawBoxBk(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart,
83 pParams->m_dwStates, &pParams->m_matrix);
84 if ((pParams->m_dwStates & CFWL_PartState_Checked) |
85 (pParams->m_dwStates & CFWL_PartState_Neutral)) {
86 DrawSign(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart,
87 pParams->m_dwStates, &pParams->m_matrix);
88 }
89 DrawSignBorder(
90 pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart,
91 pParams->m_dwStates & CFWL_PartState_Disabled, &pParams->m_matrix);
92 break;
93 }
94 default: { return FALSE; }
95 }
96 return TRUE;
97 }
98
99 FWL_Error CFWL_CheckBoxTP::Initialize() { 57 FWL_Error CFWL_CheckBoxTP::Initialize() {
100 InitTTO(); 58 InitTTO();
101 return CFWL_WidgetTP::Initialize(); 59 return CFWL_WidgetTP::Initialize();
102 } 60 }
103 61
104 FWL_Error CFWL_CheckBoxTP::Finalize() { 62 FWL_Error CFWL_CheckBoxTP::Finalize() {
105 FinalizeTTO(); 63 FinalizeTTO();
106 return CFWL_WidgetTP::Finalize(); 64 return CFWL_WidgetTP::Finalize();
107 } 65 }
108 66
109 void CFWL_CheckBoxTP::DrawBoxBk(IFWL_Widget* pWidget,
110 CFX_Graphics* pGraphics,
111 const CFX_RectF* pRect,
112 uint32_t dwStates,
113 CFX_Matrix* pMatrix) {
114 dwStates &= 0x03;
115 int32_t fillMode = FXFILL_WINDING;
116 uint32_t dwStyleEx = pWidget->GetStylesEx();
117 dwStyleEx &= FWL_STYLEEXT_CKB_ShapeMask;
118 CFX_Path path;
119 path.Create();
120 FX_FLOAT fRight = pRect->right();
121 FX_FLOAT fBottom = pRect->bottom();
122 bool bClipSign = !!(dwStates & CFWL_PartState_Hovered);
123 if ((dwStyleEx == FWL_STYLEEXT_CKB_ShapeSolidSquare) ||
124 (dwStyleEx == FWL_STYLEEXT_CKB_ShapeSunkenSquare)) {
125 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height);
126 if (bClipSign) {
127 fillMode = FXFILL_ALTERNATE;
128 path.AddRectangle(pRect->left + kSignMargin, pRect->top + kSignMargin,
129 pRect->width - kSignMargin * 2,
130 pRect->height - kSignMargin * 2);
131 }
132 } else {
133 CFX_RectF rect(*pRect);
134 rect.Deflate(0, 0, 1, 1);
135 path.AddEllipse(rect);
136 if (bClipSign) {
137 fillMode = FXFILL_ALTERNATE;
138 CFX_RectF rtClip(rect);
139 rtClip.Deflate(kSignMargin - 1, kSignMargin - 1);
140 path.AddEllipse(rtClip);
141 }
142 }
143 int32_t iTheme = 1;
144 if (dwStates & CFWL_PartState_Hovered) {
145 iTheme = 2;
146 } else if (dwStates & CFWL_PartState_Pressed) {
147 iTheme = 3;
148 } else if (dwStates & CFWL_PartState_Disabled) {
149 iTheme = 4;
150 }
151 if (dwStates & CFWL_PartState_Checked) {
152 iTheme += 4;
153 } else if (dwStates & CFWL_PartState_Neutral) {
154 iTheme += 8;
155 }
156 DrawAxialShading(pGraphics, pRect->left - 1, pRect->top - 1, fRight, fBottom,
157 m_pThemeData->clrBoxBk[iTheme][0],
158 m_pThemeData->clrBoxBk[iTheme][1], &path, fillMode, pMatrix);
159 }
160
161 void CFWL_CheckBoxTP::DrawSign(IFWL_Widget* pWidget,
162 CFX_Graphics* pGraphics,
163 const CFX_RectF* pRtBox,
164 uint32_t dwStates,
165 CFX_Matrix* pMatrix) {
166 CFX_RectF rtSign(*pRtBox);
167 rtSign.Deflate(kSignMargin, kSignMargin);
168 uint32_t dwColor = m_pThemeData->clrSignCheck;
169 bool bCheck = true;
170 if ((dwStates & CFWL_PartState_Disabled) &&
171 (dwStates & CFWL_PartState_Checked)) {
172 dwColor = m_pThemeData->clrSignBorderDisable;
173 } else if (dwStates & CFWL_PartState_Neutral) {
174 if (dwStates & CFWL_PartState_Hovered) {
175 dwColor = m_pThemeData->clrSignNeutralHover;
176 } else if (dwStates & CFWL_PartState_Pressed) {
177 dwColor = m_pThemeData->clrSignNeutralPressed;
178 } else if (dwStates & CFWL_PartState_Disabled) {
179 dwColor = m_pThemeData->clrSignBorderDisable;
180 } else {
181 dwColor = m_pThemeData->clrSignNeutralNormal;
182 }
183 bCheck = false;
184 }
185 if (bCheck) {
186 uint32_t dwStyle = pWidget->GetStylesEx();
187 switch (dwStyle & FWL_STYLEEXT_CKB_SignShapeMask) {
188 case FWL_STYLEEXT_CKB_SignShapeCheck: {
189 DrawSignCheck(pGraphics, &rtSign, dwColor, pMatrix);
190 break;
191 }
192 case FWL_STYLEEXT_CKB_SignShapeCircle: {
193 rtSign.Deflate(1, 1);
194 DrawSignCircle(pGraphics, &rtSign, dwColor, pMatrix);
195 break;
196 }
197 case FWL_STYLEEXT_CKB_SignShapeCross: {
198 DrawSignCross(pGraphics, &rtSign, dwColor, pMatrix);
199 break;
200 }
201 case FWL_STYLEEXT_CKB_SignShapeDiamond: {
202 DrawSignDiamond(pGraphics, &rtSign, dwColor, pMatrix);
203 break;
204 }
205 case FWL_STYLEEXT_CKB_SignShapeSquare: {
206 DrawSignSquare(pGraphics, &rtSign, dwColor, pMatrix);
207 break;
208 }
209 case FWL_STYLEEXT_CKB_SignShapeStar: {
210 DrawSignStar(pGraphics, &rtSign, dwColor, pMatrix);
211 break;
212 }
213 }
214 } else {
215 FillSoildRect(pGraphics, ArgbEncode(255, 33, 161, 33), &rtSign, pMatrix);
216 }
217 }
218
219 void CFWL_CheckBoxTP::DrawSignNeutral(CFX_Graphics* pGraphics,
220 const CFX_RectF* pRtSign,
221 CFX_Matrix* pMatrix) {
222 ((CFX_RectF*)pRtSign)->Inflate(-3, -3);
223 FillSoildRect(pGraphics, m_pThemeData->clrSignNeutral, pRtSign, pMatrix);
224 }
225
226 void CFWL_CheckBoxTP::DrawSignCheck(CFX_Graphics* pGraphics, 67 void CFWL_CheckBoxTP::DrawSignCheck(CFX_Graphics* pGraphics,
227 const CFX_RectF* pRtSign, 68 const CFX_RectF* pRtSign,
228 FX_ARGB argbFill, 69 FX_ARGB argbFill,
229 CFX_Matrix* pMatrix) { 70 CFX_Matrix* pMatrix) {
230 if (!m_pCheckPath) 71 if (!m_pCheckPath)
231 InitCheckPath(pRtSign->width); 72 InitCheckPath(pRtSign->width);
232 73
233 CFX_Matrix mt; 74 CFX_Matrix mt;
234 mt.SetIdentity(); 75 mt.SetIdentity();
235 mt.Translate(pRtSign->left, pRtSign->top); 76 mt.Translate(pRtSign->left, pRtSign->top);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 177 }
337 path.LineTo(px[nNext], py[nNext]); 178 path.LineTo(px[nNext], py[nNext]);
338 } 179 }
339 CFX_Color crFill(argbFill); 180 CFX_Color crFill(argbFill);
340 pGraphics->SaveGraphState(); 181 pGraphics->SaveGraphState();
341 pGraphics->SetFillColor(&crFill); 182 pGraphics->SetFillColor(&crFill);
342 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); 183 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
343 pGraphics->RestoreGraphState(); 184 pGraphics->RestoreGraphState();
344 } 185 }
345 186
346 void CFWL_CheckBoxTP::DrawSignBorder(IFWL_Widget* pWidget,
347 CFX_Graphics* pGraphics,
348 const CFX_RectF* pRtBox,
349 FX_BOOL bDisable,
350 CFX_Matrix* pMatrix) {
351 switch (pWidget->GetStylesEx() & FWL_STYLEEXT_CKB_ShapeMask) {
352 case FWL_STYLEEXT_CKB_ShapeSolidSquare: {
353 DrawAnnulusRect(pGraphics, bDisable ? m_pThemeData->clrSignBorderDisable
354 : m_pThemeData->clrSignBorderNormal,
355 pRtBox, 1, pMatrix);
356 break;
357 }
358 case FWL_STYLEEXT_CKB_ShapeSunkenSquare: {
359 Draw3DRect(pGraphics, FWLTHEME_EDGE_Sunken, kSignBorder, pRtBox,
360 CHECKBOX_COLOR_BOXLT1, CHECKBOX_COLOR_BOXLT2,
361 CHECKBOX_COLOR_BOXRB1, CHECKBOX_COLOR_BOXRB2, pMatrix);
362 break;
363 }
364 case FWL_STYLEEXT_CKB_ShapeSolidCircle: {
365 DrawAnnulusCircle(pGraphics, bDisable ? m_pThemeData->clrSignBorderDisable
366 : m_pThemeData->clrSignBorderNormal,
367 pRtBox, 1, pMatrix);
368 break;
369 }
370 case FWL_STYLEEXT_CKB_ShapeSunkenCircle: {
371 Draw3DCircle(pGraphics, FWLTHEME_EDGE_Sunken, kSignBorder, pRtBox,
372 CHECKBOX_COLOR_BOXLT1, CHECKBOX_COLOR_BOXLT2,
373 CHECKBOX_COLOR_BOXRB1, CHECKBOX_COLOR_BOXRB2, pMatrix);
374 break;
375 }
376 }
377 }
378
379 void CFWL_CheckBoxTP::SetThemeData(uint32_t dwID) { 187 void CFWL_CheckBoxTP::SetThemeData(uint32_t dwID) {
380 uint32_t* pData = (uint32_t*)&m_pThemeData->clrBoxBk; 188 uint32_t* pData = (uint32_t*)&m_pThemeData->clrBoxBk;
381 if (dwID) { 189 if (dwID) {
382 *pData++ = 0, *pData++ = 0, *pData++ = ArgbEncode(255, 220, 220, 215), 190 *pData++ = 0, *pData++ = 0, *pData++ = ArgbEncode(255, 220, 220, 215),
383 *pData++ = ArgbEncode(255, 255, 255, 255), 191 *pData++ = ArgbEncode(255, 255, 255, 255),
384 *pData++ = ArgbEncode(255, 255, 240, 207), 192 *pData++ = ArgbEncode(255, 255, 240, 207),
385 *pData++ = ArgbEncode(255, 248, 179, 48), 193 *pData++ = ArgbEncode(255, 248, 179, 48),
386 *pData++ = ArgbEncode(255, 176, 176, 167), 194 *pData++ = ArgbEncode(255, 176, 176, 167),
387 *pData++ = ArgbEncode(255, 241, 239, 239), 195 *pData++ = ArgbEncode(255, 241, 239, 239),
388 *pData++ = ArgbEncode(255, 255, 255, 255), 196 *pData++ = ArgbEncode(255, 255, 255, 255),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 pt1.x + px2 * FX_BEZIER, pt1.y + py2 * FX_BEZIER, 314 pt1.x + px2 * FX_BEZIER, pt1.y + py2 * FX_BEZIER,
507 pt1.x, pt1.y); 315 pt1.x, pt1.y);
508 FX_FLOAT fScale = fCheckLen / kSignPath; 316 FX_FLOAT fScale = fCheckLen / kSignPath;
509 CFX_Matrix mt; 317 CFX_Matrix mt;
510 mt.Set(1, 0, 0, 1, 0, 0); 318 mt.Set(1, 0, 0, 1, 0, 0);
511 mt.Scale(fScale, fScale); 319 mt.Scale(fScale, fScale);
512 CFX_PathData* pData = m_pCheckPath->GetPathData(); 320 CFX_PathData* pData = m_pCheckPath->GetPathData();
513 pData->Transform(&mt); 321 pData->Transform(&mt);
514 } 322 }
515 } 323 }
324
325 FX_BOOL CFWL_CheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) {
326 if (pParams->m_iPart != CFWL_Part::CheckBox) {
327 return FALSE;
328 }
329 if ((pParams->m_dwStates & CFWL_PartState_Checked) ||
330 (pParams->m_dwStates & CFWL_PartState_Neutral)) {
331 DrawCheckSign(pParams->m_pWidget, pParams->m_pGraphics, pParams->m_rtPart,
332 pParams->m_dwStates, &pParams->m_matrix);
333 }
334 return FALSE;
335 }
336
337 void CFWL_CheckBoxTP::DrawCheckSign(IFWL_Widget* pWidget,
338 CFX_Graphics* pGraphics,
339 const CFX_RectF& pRtBox,
340 int32_t iState,
341 CFX_Matrix* pMatrix) {
342 CFX_RectF rtSign(pRtBox);
343 uint32_t dwColor = iState & CFWL_PartState_Neutral ? 0xFFA9A9A9 : 0xFF000000;
344
345 uint32_t dwStyle = pWidget->GetStylesEx();
346 rtSign.Deflate(rtSign.width / 4, rtSign.height / 4);
347 switch (dwStyle & FWL_STYLEEXT_CKB_SignShapeMask) {
348 case FWL_STYLEEXT_CKB_SignShapeCheck:
349 DrawSignCheck(pGraphics, &rtSign, dwColor, pMatrix);
350 break;
351 case FWL_STYLEEXT_CKB_SignShapeCircle:
352 DrawSignCircle(pGraphics, &rtSign, dwColor, pMatrix);
353 break;
354 case FWL_STYLEEXT_CKB_SignShapeCross:
355 DrawSignCross(pGraphics, &rtSign, dwColor, pMatrix);
356 break;
357 case FWL_STYLEEXT_CKB_SignShapeDiamond:
358 DrawSignDiamond(pGraphics, &rtSign, dwColor, pMatrix);
359 break;
360 case FWL_STYLEEXT_CKB_SignShapeSquare:
361 DrawSignSquare(pGraphics, &rtSign, dwColor, pMatrix);
362 break;
363 case FWL_STYLEEXT_CKB_SignShapeStar:
364 DrawSignStar(pGraphics, &rtSign, dwColor, pMatrix);
365 break;
366 default:
367 break;
368 }
369 }
OLDNEW
« no previous file with comments | « xfa/fwl/theme/cfwl_checkboxtp.h ('k') | xfa/fwl/theme/cfwl_edittp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698