Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: ui/gfx/render_text_linux.h

Issue 7511029: Implement Pango RenderText for Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 SetCompositionRange(const ui::Range& composition_range) OVERRIDE;
25 virtual void ApplyStyleRange(StyleRange style_range) OVERRIDE;
26 virtual void ApplyDefaultStyle() OVERRIDE;
27 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE;
28 virtual int GetStringWidth() OVERRIDE;
29 virtual void Draw(Canvas* canvas) OVERRIDE;
30 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
31 virtual Rect GetCursorBounds(const SelectionModel& position,
32 bool insert_mode) OVERRIDE;
33
34 protected:
35 // Overridden from RenderText:
36 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
37 BreakType break_type) OVERRIDE;
38 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
39 BreakType break_type) OVERRIDE;
40 virtual SelectionModel LeftEndSelectionModel() OVERRIDE;
41 virtual SelectionModel RightEndSelectionModel() OVERRIDE;
42 virtual size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE;
43
44 private:
45 enum RelativeLogicalPosition {
46 PREVIOUS,
47 NEXT
48 };
49
50 // Get the logical start index of the next grapheme after |position|.
51 size_t GetIndexOfNextGrapheme(size_t position);
52
53 // Returns the run that contains |position|. Return NULL if not found.
54 GSList* GetRunContainingPosition(size_t position) const;
55
56 // Given |utf8_index_of_current_grapheme|, returns the UTF8 or UTF16 index of
57 // next grapheme in the text if |pos| is NEXT, otherwise, returns the index of
58 // previous grapheme. Returns 0 if there is no previous grapheme, and returns
59 // the |text_| length if there is no next grapheme.
60 size_t Utf8IndexOfAdjacentGrapheme(size_t utf8_index_of_current_grapheme,
61 RelativeLogicalPosition pos) const;
62 size_t Utf16IndexOfAdjacentGrapheme(size_t utf8_index_of_current_grapheme,
63 RelativeLogicalPosition pos) const;
64
65 // Given a |run|, returns the SelectionModel that contains the logical first
66 // or last caret position inside (not at a boundary of) the run.
67 // The returned value represents a cursor/caret position without a selection.
68 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const;
69 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const;
70
71 // Get the selection model visually left or right of |current| by one
72 // grapheme.
73 // The returned value represents a cursor/caret position without a selection.
74 SelectionModel LeftSelectionModel(const SelectionModel& current);
75 SelectionModel RightSelectionModel(const SelectionModel& current);
76
77 // If |layout_| is NULL, create and setup |layout_|, retain and ref
78 // |current_line_|. Return |layout_|.
79 PangoLayout* EnsureLayout();
80
81 // Unref |layout_| and |pango_line_|. Set them to NULL.
82 void ResetLayout();
83
84 // Setup pango attribute: foreground, background, font, strike.
85 void SetupPangoAttributes(PangoLayout* layout);
86
87 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
88 void AppendPangoAttribute(size_t start,
89 size_t end,
90 PangoAttribute* pango_attr,
91 PangoAttrList* attrs);
92
93 // Returns |run|'s visually previous run.
94 // The complexity is O(n) since it is a single-linked list.
95 PangoLayoutRun* GetPreviousRun(PangoLayoutRun* run) const;
96
97 // Returns the last run in |current_line_|.
98 // The complexity is O(n) since it is a single-linked list.
99 PangoLayoutRun* GetLastRun() const;
100
101 size_t Utf16IndexToUtf8Index(size_t index) const;
102 size_t Utf8IndexToUtf16Index(size_t index) const;
103
104 // Pango Layout.
105 PangoLayout* layout_;
106 // A single line layout resulting from laying out via |layout_|.
107 PangoLayoutLine* current_line_;
108
109 // Information about character attributes.
110 PangoLogAttr* log_attrs_;
111 // Number of attributes in |log_attrs_|.
112 int num_log_attrs_;
113
114 // The text in the |layout_|.
115 const char* layout_text_;
116 // The text length.
117 size_t layout_text_len_;
118
20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); 119 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
21 }; 120 };
22 121
23 } // namespace gfx; 122 } // namespace gfx;
24 123
25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ 124 #endif // UI_GFX_RENDER_TEXT_LINUX_H_
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_linux.cc » ('j') | ui/gfx/render_text_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698