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 grapheme in the text if |pos| is NEXT, otherwise, returns the index of | |
57 // previous grapheme. Returns 0 if there is no previous grapheme, and returns | |
58 // the |text_| length if there is no next grapheme. | |
msw
2011/08/24 08:55:30
See my other comment about handling this behavior
| |
59 size_t Utf8IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme, | |
60 RelativeLogicalPosition pos) const; | |
61 size_t Utf16IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme, | |
62 RelativeLogicalPosition pos) const; | |
63 | |
64 // Given a |run|, returns the SelectionModel that contains the logical first | |
65 // or last caret position inside (not at a boundary of) the run. | |
66 // The returned value represents a cursor/caret position without a selection. | |
67 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const; | |
68 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const; | |
69 | |
70 // Get the selection model that visually left or right of |current| by one | |
71 // grapheme. | |
72 // The returned value represents a cursor/caret position without a selection. | |
73 SelectionModel LeftSelectionModel(const SelectionModel& current); | |
74 SelectionModel RightSelectionModel(const SelectionModel& current); | |
75 | |
76 // Create, setup, and return pango layout and pango layout line if |layout_| | |
77 // is NULL. Otherwise, return the cached |layout_|. | |
78 PangoLayout* EnsureLayout(); | |
79 | |
80 // Unref |layout_| and |pango_line_|. Set them to NULL. | |
81 void ResetLayout(); | |
82 | |
83 // Setup pango attribute: foreground, background, font, strike. | |
84 void SetupPangoAttributes(PangoLayout* layout); | |
85 | |
86 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. | |
87 void AppendPangoAttribute(size_t start, | |
88 size_t end, | |
89 PangoAttribute* pango_attr, | |
90 PangoAttrList* attrs); | |
91 | |
92 // Returns |run|'s visually previous run. | |
93 GSList* GetPreviousRun(GSList* run) const; | |
94 | |
95 // Returns the last run in |layout_line_|. | |
96 GSList* GetLastRun() const; | |
97 | |
98 size_t Utf16IndexToUtf8Index(size_t index) const; | |
99 size_t Utf8IndexToUtf16Index(size_t index) const; | |
100 | |
101 PangoLayout* layout_; | |
102 | |
103 PangoLayoutLine* layout_line_; | |
104 | |
20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); | 105 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); |
21 }; | 106 }; |
22 | 107 |
23 } // namespace gfx; | 108 } // namespace gfx; |
24 | 109 |
25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ | 110 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ |
OLD | NEW |