1/*
2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#pragma once
24
25#include "Color.h"
26#include "FloatPoint.h"
27#include "RenderStyleConstants.h"
28#include <wtf/OptionSet.h>
29
30namespace WebCore {
31
32class FilterOperations;
33class FontCascade;
34class FloatRect;
35class GraphicsContext;
36class InlineTextBox;
37class RenderObject;
38class RenderStyle;
39class RenderText;
40class ShadowData;
41class TextRun;
42
43class TextDecorationPainter {
44public:
45 struct Styles;
46 TextDecorationPainter(GraphicsContext&, OptionSet<TextDecoration> decorations, const RenderText&, bool isFirstLine, const FontCascade&, Optional<Styles> = WTF::nullopt);
47
48 void setInlineTextBox(const InlineTextBox* inlineTextBox) { m_inlineTextBox = inlineTextBox; }
49 void setIsHorizontal(bool isHorizontal) { m_isHorizontal = isHorizontal; }
50 void setWidth(float width) { m_width = width; }
51 void setTextShadow(const ShadowData* textShadow) { m_shadow = textShadow; }
52 void setShadowColorFilter(const FilterOperations* colorFilter) { m_shadowColorFilter = colorFilter; }
53
54 void paintTextDecoration(const TextRun&, const FloatPoint& textOrigin, const FloatPoint& boxOrigin);
55
56 struct Styles {
57 bool operator==(const Styles&) const;
58 bool operator!=(const Styles& other) const { return !(*this == other); }
59
60 Color underlineColor;
61 Color overlineColor;
62 Color linethroughColor;
63 TextDecorationStyle underlineStyle;
64 TextDecorationStyle overlineStyle;
65 TextDecorationStyle linethroughStyle;
66 };
67 static Styles stylesForRenderer(const RenderObject&, OptionSet<TextDecoration> requestedDecorations, bool firstLineStyle = false, PseudoId = PseudoId::None);
68
69private:
70 GraphicsContext& m_context;
71 OptionSet<TextDecoration> m_decorations;
72 float m_wavyOffset;
73 float m_width { 0 };
74 FloatPoint m_boxOrigin;
75 bool m_isPrinting;
76 bool m_isHorizontal { true };
77 const ShadowData* m_shadow { nullptr };
78 const FilterOperations* m_shadowColorFilter { nullptr };
79 const InlineTextBox* m_inlineTextBox { nullptr };
80 const FontCascade& m_font;
81
82 Styles m_styles;
83 const RenderStyle& m_lineStyle;
84};
85
86} // namespace WebCore
87