OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_RENDER_TEXT_LINUX_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_LINUX_H_ |
6 #define UI_GFX_RENDER_TEXT_LINUX_H_ | 6 #define UI_GFX_RENDER_TEXT_LINUX_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <pango/pango.h> | |
10 | |
9 #include "ui/gfx/render_text.h" | 11 #include "ui/gfx/render_text.h" |
10 | 12 |
11 namespace gfx { | 13 namespace gfx { |
12 | 14 |
13 // RenderTextLinux is the Linux implementation of RenderText using Pango. | 15 // RenderTextLinux is the Linux implementation of RenderText using Pango. |
14 class RenderTextLinux : public RenderText { | 16 class RenderTextLinux : public RenderText { |
15 public: | 17 public: |
16 RenderTextLinux(); | 18 RenderTextLinux(); |
17 virtual ~RenderTextLinux(); | 19 virtual ~RenderTextLinux(); |
18 | 20 |
19 private: | 21 // Overridden from RenderText: |
22 virtual void SetText(const string16& text) OVERRIDE; | |
23 virtual void SetDisplayRect(const Rect&r) OVERRIDE; | |
24 virtual void ApplyStyleRange(StyleRange style_range) OVERRIDE; | |
25 virtual void ApplyDefaultStyle() OVERRIDE; | |
26 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE; | |
27 virtual int GetStringWidth() OVERRIDE; | |
28 virtual void Draw(Canvas* canvas) OVERRIDE; | |
29 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; | |
30 virtual Rect GetCursorBounds(const SelectionModel& position, | |
31 bool insert_mode) OVERRIDE; | |
32 | |
33 protected: | |
34 // Overridden from RenderText: | |
35 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | |
36 BreakType break_type) OVERRIDE; | |
37 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | |
38 BreakType break_type) OVERRIDE; | |
39 virtual size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE; | |
40 | |
41 private: | |
42 enum RelativeLogicalPosition { | |
43 PREVIOUS, | |
44 NEXT | |
45 }; | |
46 | |
47 // Get the SelectionModels corresponding to the left or right text ends. | |
48 // The returned value represents a cursor/caret position without a selection. | |
49 SelectionModel LeftEndSelectionModel(); | |
50 SelectionModel RightEndSelectionModel(); | |
51 | |
52 // Returns the run that contains |position|. Return NULL if not found. | |
53 GSList* GetRunContainingPosition(size_t position) const; | |
54 | |
55 // Given |utf16_index_of_current_grapheme|, returns the UTF8 or UTF16 index of | |
56 // next graphame in the text if |pos| is NEXT, otherwise, returns the index of | |
57 // previous grapheme. | |
58 size_t Utf8IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme, | |
msw
2011/08/23 08:01:01
Can you comment on (and ensure you're properly han
| |
59 RelativeLogicalPosition pos) const; | |
60 size_t Utf16IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme, | |
61 RelativeLogicalPosition pos) const; | |
62 | |
63 // Given a |run|, returns the SelectionModel that contains the logical first | |
64 // or last caret position inside (not at a boundary of) the run. | |
65 // The returned value represents a cursor/caret position without a selection. | |
66 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const; | |
67 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const; | |
68 | |
69 // Get the selection model that visually left or right of |current| by one | |
70 // grapheme. | |
71 // The returned value represents a cursor/caret position without a selection. | |
72 SelectionModel LeftSelectionModel(const SelectionModel& current); | |
73 SelectionModel RightSelectionModel(const SelectionModel& current); | |
74 | |
75 // Create, setup, and return pango layout and pango layout line if |layout_| | |
76 // is NULL. Otherwise, return the cached |layout_|. | |
77 PangoLayout* EnsureLayout(); | |
78 | |
79 // Unref |layout_| and |pango_line_|. Set them to NULL. | |
80 void ResetLayout(); | |
81 | |
82 // Setup pango attribute: foreground, background, font, strike. | |
83 void SetupPangoAttributes(PangoLayout* layout); | |
84 | |
85 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. | |
86 void AppendPangoAttribute(size_t start, | |
87 size_t end, | |
88 PangoAttribute* pango_attr, | |
89 PangoAttrList* attrs); | |
90 | |
91 // Returns |run|'s visually previous run. | |
92 GSList* GetPreviousRun(GSList* run) const; | |
93 | |
94 // Returns the last run in |layout_line_|. | |
95 GSList* GetLastRun() const; | |
96 | |
97 size_t Utf16IndexToUtf8Index(size_t index) const; | |
98 size_t Utf8IndexToUtf16Index(size_t index) const; | |
99 | |
100 PangoLayout* layout_; | |
101 | |
102 PangoLayoutLine* layout_line_; | |
103 | |
20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); | 104 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); |
21 }; | 105 }; |
22 | 106 |
23 } // namespace gfx; | 107 } // namespace gfx; |
24 | 108 |
25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ | 109 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ |
OLD | NEW |