Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / render_text_pango.h
1 // Copyright (c) 2012 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 UI_GFX_RENDER_TEXT_PANGO_H_
6 #define UI_GFX_RENDER_TEXT_PANGO_H_
7
8 #include <pango/pango.h>
9 #include <vector>
10
11 #include "ui/gfx/render_text.h"
12
13 namespace gfx {
14
15 // RenderTextPango is the Linux implementation of RenderText using Pango.
16 class RenderTextPango : public RenderText {
17  public:
18   RenderTextPango();
19   ~RenderTextPango() override;
20
21   // Overridden from RenderText:
22   Size GetStringSize() override;
23   SelectionModel FindCursorPosition(const Point& point) override;
24   std::vector<FontSpan> GetFontSpansForTesting() override;
25
26  protected:
27   // Overridden from RenderText:
28   int GetLayoutTextBaseline() override;
29   SelectionModel AdjacentCharSelectionModel(
30       const SelectionModel& selection,
31       VisualCursorDirection direction) override;
32   SelectionModel AdjacentWordSelectionModel(
33       const SelectionModel& selection,
34       VisualCursorDirection direction) override;
35   Range GetGlyphBounds(size_t index) override;
36   std::vector<Rect> GetSubstringBounds(const Range& range) override;
37   size_t TextIndexToLayoutIndex(size_t index) const override;
38   size_t LayoutIndexToTextIndex(size_t index) const override;
39   bool IsValidCursorIndex(size_t index) override;
40   void ResetLayout() override;
41   void EnsureLayout() override;
42   void DrawVisualText(Canvas* canvas) override;
43
44  private:
45   friend class RenderTextTest;
46   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes);
47
48   // Returns the run that contains the character attached to the caret in the
49   // given selection model. Return NULL if not found.
50   GSList* GetRunContainingCaret(const SelectionModel& caret) const;
51
52   // Given a |run|, returns the SelectionModel that contains the logical first
53   // or last caret position inside (not at a boundary of) the run.
54   // The returned value represents a cursor/caret position without a selection.
55   SelectionModel FirstSelectionModelInsideRun(const PangoItem* run);
56   SelectionModel LastSelectionModelInsideRun(const PangoItem* run);
57
58   // Setup pango attribute: foreground, background, font, strike.
59   void SetupPangoAttributes(PangoLayout* layout);
60
61   // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
62   void AppendPangoAttribute(size_t start,
63                             size_t end,
64                             PangoAttribute* pango_attr,
65                             PangoAttrList* attrs);
66
67   // Get the text index corresponding to the |run|'s |glyph_index|.
68   size_t GetGlyphTextIndex(PangoLayoutRun* run, int glyph_index) const;
69
70   // Pango Layout.
71   PangoLayout* layout_;
72   // A single line layout resulting from laying out via |layout_|.
73   PangoLayoutLine* current_line_;
74
75   // Information about character attributes.
76   PangoLogAttr* log_attrs_;
77   // Number of attributes in |log_attrs_|.
78   int num_log_attrs_;
79
80   // The text in the |layout_|.
81   const char* layout_text_;
82
83   DISALLOW_COPY_AND_ASSIGN(RenderTextPango);
84 };
85
86 }  // namespace gfx
87
88 #endif  // UI_GFX_RENDER_TEXT_PANGO_H_