xref: /aosp_15_r20/external/pdfium/xfa/fwl/theme/cfwl_edittp.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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_edittp.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_edit.h"
13 #include "xfa/fwl/cfwl_themebackground.h"
14 #include "xfa/fwl/cfwl_widget.h"
15 
16 CFWL_EditTP::CFWL_EditTP() = default;
17 
18 CFWL_EditTP::~CFWL_EditTP() = default;
19 
DrawBackground(const CFWL_ThemeBackground & pParams)20 void CFWL_EditTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
21   switch (pParams.GetPart()) {
22     case CFWL_ThemePart::Part::kBorder: {
23       DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
24       break;
25     }
26     case CFWL_ThemePart::Part::kBackground: {
27       CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
28       CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
29       const CFGAS_GEPath* pParamsPath = pParams.GetPath();
30       if (pParamsPath) {
31         pGraphics->SetFillColor(CFGAS_GEColor(FWLTHEME_COLOR_BKSelected));
32         pGraphics->FillPath(*pParamsPath,
33                             CFX_FillRenderOptions::FillType::kWinding,
34                             pParams.m_matrix);
35       } else {
36         CFGAS_GEPath path;
37         path.AddRectangle(pParams.m_PartRect.left, pParams.m_PartRect.top,
38                           pParams.m_PartRect.width, pParams.m_PartRect.height);
39         CFGAS_GEColor cr(FWLTHEME_COLOR_Background);
40         if (!pParams.m_bStaticBackground) {
41           if (pParams.m_dwStates & CFWL_PartState::kDisabled)
42             cr = CFGAS_GEColor(FWLTHEME_COLOR_EDGERB1);
43           else if (pParams.m_dwStates & CFWL_PartState::kReadOnly)
44             cr = CFGAS_GEColor(ArgbEncode(255, 236, 233, 216));
45           else
46             cr = CFGAS_GEColor(0xFFFFFFFF);
47         }
48         pGraphics->SetFillColor(cr);
49         pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding,
50                             pParams.m_matrix);
51       }
52       break;
53     }
54     case CFWL_ThemePart::Part::kCombTextLine: {
55       CFWL_Widget::AdapterIface* pWidget =
56           pParams.GetWidget()->GetOutmost()->GetAdapterIface();
57       FX_ARGB cr = 0xFF000000;
58       float fWidth = 1.0f;
59       pWidget->GetBorderColorAndThickness(&cr, &fWidth);
60       pParams.GetGraphics()->SetStrokeColor(CFGAS_GEColor(cr));
61       pParams.GetGraphics()->SetLineWidth(fWidth);
62       const CFGAS_GEPath* pParamsPath = pParams.GetPath();
63       if (pParamsPath)
64         pParams.GetGraphics()->StrokePath(*pParamsPath, pParams.m_matrix);
65       break;
66     }
67     default:
68       break;
69   }
70 }
71