Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / gfx / render_text_linux.h
blob2abdf2b07488bffd356533b7a5c2a3dd06305b94
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.
5 #ifndef UI_GFX_RENDER_TEXT_LINUX_H_
6 #define UI_GFX_RENDER_TEXT_LINUX_H_
8 #include <pango/pango.h>
9 #include <vector>
11 #include "ui/gfx/render_text.h"
13 namespace gfx {
15 // RenderTextLinux is the Linux implementation of RenderText using Pango.
16 class RenderTextLinux : public RenderText {
17 public:
18 RenderTextLinux();
19 virtual ~RenderTextLinux();
21 // Overridden from RenderText:
22 virtual Size GetStringSize() OVERRIDE;
23 virtual int GetBaseline() OVERRIDE;
24 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
25 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE;
27 protected:
28 // Overridden from RenderText:
29 virtual SelectionModel AdjacentCharSelectionModel(
30 const SelectionModel& selection,
31 VisualCursorDirection direction) OVERRIDE;
32 virtual SelectionModel AdjacentWordSelectionModel(
33 const SelectionModel& selection,
34 VisualCursorDirection direction) OVERRIDE;
35 virtual void SetSelectionModel(const SelectionModel& model) OVERRIDE;
36 virtual void GetGlyphBounds(size_t index,
37 ui::Range* xspan,
38 int* height) OVERRIDE;
39 virtual std::vector<Rect> GetSubstringBounds(const ui::Range& range) OVERRIDE;
40 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE;
41 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE;
42 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
43 virtual void ResetLayout() OVERRIDE;
44 virtual void EnsureLayout() OVERRIDE;
45 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
47 private:
48 friend class RenderTextTest;
49 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes);
51 // Returns the run that contains the character attached to the caret in the
52 // given selection model. Return NULL if not found.
53 GSList* GetRunContainingCaret(const SelectionModel& caret) const;
55 // Given a |run|, returns the SelectionModel that contains the logical first
56 // or last caret position inside (not at a boundary of) the run.
57 // The returned value represents a cursor/caret position without a selection.
58 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run);
59 SelectionModel LastSelectionModelInsideRun(const PangoItem* run);
61 // Setup pango attribute: foreground, background, font, strike.
62 void SetupPangoAttributes(PangoLayout* layout);
64 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
65 void AppendPangoAttribute(size_t start,
66 size_t end,
67 PangoAttribute* pango_attr,
68 PangoAttrList* attrs);
70 // Calculate the visual bounds containing the logical substring within the
71 // given range.
72 std::vector<Rect> CalculateSubstringBounds(ui::Range range);
74 // Get the visual bounds of the logical selection.
75 std::vector<Rect> GetSelectionBounds();
77 // Get the text index corresponding to the |run|'s |glyph_index|.
78 size_t GetGlyphTextIndex(PangoLayoutRun* run, int glyph_index) const;
80 // Pango Layout.
81 PangoLayout* layout_;
82 // A single line layout resulting from laying out via |layout_|.
83 PangoLayoutLine* current_line_;
85 // Information about character attributes.
86 PangoLogAttr* log_attrs_;
87 // Number of attributes in |log_attrs_|.
88 int num_log_attrs_;
90 // Vector of the visual bounds containing the logical substring of selection.
91 std::vector<Rect> selection_visual_bounds_;
93 // The text in the |layout_|.
94 const char* layout_text_;
95 // The text length.
96 size_t layout_text_len_;
98 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
101 } // namespace gfx
103 #endif // UI_GFX_RENDER_TEXT_LINUX_H_