Fix build break
[chromium-blink-merge.git] / ui / gfx / render_text_linux.h
blobc7e01739467f00eb969944d206a68f074b7d6127
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 GetGlyphBounds(size_t index,
36 ui::Range* xspan,
37 int* height) OVERRIDE;
38 virtual std::vector<Rect> GetSubstringBounds(const ui::Range& range) OVERRIDE;
39 virtual size_t TextIndexToLayoutIndex(size_t index) const OVERRIDE;
40 virtual size_t LayoutIndexToTextIndex(size_t index) const OVERRIDE;
41 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
42 virtual void ResetLayout() OVERRIDE;
43 virtual void EnsureLayout() OVERRIDE;
44 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
46 private:
47 friend class RenderTextTest;
48 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes);
50 // Returns the run that contains the character attached to the caret in the
51 // given selection model. Return NULL if not found.
52 GSList* GetRunContainingCaret(const SelectionModel& caret) const;
54 // Given a |run|, returns the SelectionModel that contains the logical first
55 // or last caret position inside (not at a boundary of) the run.
56 // The returned value represents a cursor/caret position without a selection.
57 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run);
58 SelectionModel LastSelectionModelInsideRun(const PangoItem* run);
60 // Setup pango attribute: foreground, background, font, strike.
61 void SetupPangoAttributes(PangoLayout* layout);
63 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
64 void AppendPangoAttribute(size_t start,
65 size_t end,
66 PangoAttribute* pango_attr,
67 PangoAttrList* attrs);
69 // Get the text index corresponding to the |run|'s |glyph_index|.
70 size_t GetGlyphTextIndex(PangoLayoutRun* run, int glyph_index) const;
72 // Pango Layout.
73 PangoLayout* layout_;
74 // A single line layout resulting from laying out via |layout_|.
75 PangoLayoutLine* current_line_;
77 // Information about character attributes.
78 PangoLogAttr* log_attrs_;
79 // Number of attributes in |log_attrs_|.
80 int num_log_attrs_;
82 // The text in the |layout_|.
83 const char* layout_text_;
84 // The text length.
85 size_t layout_text_len_;
87 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
90 } // namespace gfx
92 #endif // UI_GFX_RENDER_TEXT_LINUX_H_