Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / TextPainter.h
1 // Copyright 2014 The Chromium 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 #ifndef TextPainter_h
6 #define TextPainter_h
7
8 #include "core/rendering/style/RenderStyleConstants.h"
9 #include "platform/fonts/TextBlob.h"
10 #include "platform/geometry/FloatPoint.h"
11 #include "platform/geometry/FloatRect.h"
12 #include "platform/graphics/Color.h"
13 #include "wtf/text/AtomicString.h"
14
15 namespace blink {
16
17 class Font;
18 class GraphicsContext;
19 class GraphicsContextStateSaver;
20 class RenderCombineText;
21 class RenderObject;
22 class RenderStyle;
23 class ShadowList;
24 class TextRun;
25 struct TextRunPaintInfo;
26
27 class TextPainter {
28 public:
29     struct Style;
30
31     TextPainter(GraphicsContext*, const Font&, const TextRun&, const FloatPoint& textOrigin, const FloatRect& textBounds, bool horizontal);
32     ~TextPainter();
33
34     void setEmphasisMark(const AtomicString&, TextEmphasisPosition);
35     void setCombinedText(RenderCombineText* combinedText) { m_combinedText = combinedText; }
36
37     static void updateGraphicsContext(GraphicsContext*, const Style&, bool horizontal, GraphicsContextStateSaver&);
38
39     void paint(int startOffset, int endOffset, int length, const Style&, TextBlobPtr* cachedTextBlob = 0);
40
41     struct Style {
42         Color fillColor;
43         Color strokeColor;
44         Color emphasisMarkColor;
45         float strokeWidth;
46         const ShadowList* shadow;
47
48         bool operator==(const Style& other)
49         {
50             return fillColor == other.fillColor
51                 && strokeColor == other.strokeColor
52                 && emphasisMarkColor == other.emphasisMarkColor
53                 && strokeWidth == other.strokeWidth
54                 && shadow == other.shadow;
55         }
56         bool operator!=(const Style& other) { return !(*this == other); }
57     };
58     static Style textPaintingStyle(RenderObject&, RenderStyle*, bool forceBlackText, bool isPrinting);
59     static Style selectionPaintingStyle(RenderObject&, bool haveSelection, bool forceBlackText, bool isPrinting, const Style& textStyle);
60
61 private:
62     void updateGraphicsContext(const Style& style, GraphicsContextStateSaver& saver)
63     {
64         updateGraphicsContext(m_graphicsContext, style, m_horizontal, saver);
65     }
66
67     enum PaintInternalStep { PaintText, PaintEmphasisMark };
68
69     template <PaintInternalStep step>
70     void paintInternalRun(TextRunPaintInfo&, int from, int to);
71
72     template <PaintInternalStep step>
73     void paintInternal(int startOffset, int endOffset, int truncationPoint, TextBlobPtr* cachedTextBlob = 0);
74
75     void paintEmphasisMarkForCombinedText();
76
77     GraphicsContext* m_graphicsContext;
78     const Font& m_font;
79     const TextRun& m_run;
80     FloatPoint m_textOrigin;
81     FloatRect m_textBounds;
82     bool m_horizontal;
83     AtomicString m_emphasisMark;
84     int m_emphasisMarkOffset;
85     RenderCombineText* m_combinedText;
86 };
87
88 } // namespace blink
89
90 #endif // TextPainter_h