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

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

Issue 8536047: Separate selection highlight from pango layout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: address comments Created 9 years 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
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 9 #include <pango/pango.h>
10 #include <vector>
10 11
11 #include "ui/gfx/render_text.h" 12 #include "ui/gfx/render_text.h"
12 13
13 namespace gfx { 14 namespace gfx {
14 15
15 // RenderTextLinux is the Linux implementation of RenderText using Pango. 16 // RenderTextLinux is the Linux implementation of RenderText using Pango.
16 class RenderTextLinux : public RenderText { 17 class RenderTextLinux : public RenderText {
17 public: 18 public:
18 RenderTextLinux(); 19 RenderTextLinux();
19 virtual ~RenderTextLinux(); 20 virtual ~RenderTextLinux();
20 21
21 // Overridden from RenderText: 22 // Overridden from RenderText:
22 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE; 23 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE;
23 virtual int GetStringWidth() OVERRIDE; 24 virtual int GetStringWidth() OVERRIDE;
24 virtual void Draw(Canvas* canvas) OVERRIDE;
25 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; 25 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
26 virtual Rect GetCursorBounds(const SelectionModel& position, 26 virtual Rect GetCursorBounds(const SelectionModel& position,
27 bool insert_mode) OVERRIDE; 27 bool insert_mode) OVERRIDE;
28 28
29 protected: 29 protected:
30 // Overridden from RenderText: 30 // Overridden from RenderText:
31 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, 31 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
32 BreakType break_type) OVERRIDE; 32 BreakType break_type) OVERRIDE;
33 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, 33 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
34 BreakType break_type) OVERRIDE; 34 BreakType break_type) OVERRIDE;
35 virtual SelectionModel LeftEndSelectionModel() OVERRIDE; 35 virtual SelectionModel LeftEndSelectionModel() OVERRIDE;
36 virtual SelectionModel RightEndSelectionModel() OVERRIDE; 36 virtual SelectionModel RightEndSelectionModel() OVERRIDE;
37 virtual void GetSubstringBounds(size_t from,
38 size_t to,
39 std::vector<Rect>* bounds) OVERRIDE;
40 virtual void SetSelectionModel(const SelectionModel& model) OVERRIDE;
37 virtual bool IsCursorablePosition(size_t position) OVERRIDE; 41 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
38 virtual void UpdateLayout() OVERRIDE; 42 virtual void UpdateLayout() OVERRIDE;
43 virtual void EnsureLayout() OVERRIDE;
44 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
39 45
40 private: 46 private:
41 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) OVERRIDE; 47 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) OVERRIDE;
42 48
43 // Returns the run that contains |position|. Return NULL if not found. 49 // Returns the run that contains |position|. Return NULL if not found.
44 GSList* GetRunContainingPosition(size_t position) const; 50 GSList* GetRunContainingPosition(size_t position) const;
45 51
46 // Given |utf8_index_of_current_grapheme|, returns the UTF8 or UTF16 index of 52 // Given |utf8_index_of_current_grapheme|, returns the UTF8 or UTF16 index of
47 // next grapheme in the text if |next| is true, otherwise, returns the index 53 // next grapheme in the text if |next| is true, otherwise, returns the index
48 // of previous grapheme. Returns 0 if there is no previous grapheme, and 54 // of previous grapheme. Returns 0 if there is no previous grapheme, and
(...skipping 13 matching lines...) Expand all
62 // grapheme. 68 // grapheme.
63 // The returned value represents a cursor/caret position without a selection. 69 // The returned value represents a cursor/caret position without a selection.
64 SelectionModel LeftSelectionModel(const SelectionModel& current); 70 SelectionModel LeftSelectionModel(const SelectionModel& current);
65 SelectionModel RightSelectionModel(const SelectionModel& current); 71 SelectionModel RightSelectionModel(const SelectionModel& current);
66 72
67 // Get the selection model visually left or right of |current| by one word. 73 // Get the selection model visually left or right of |current| by one word.
68 // The returned value represents a cursor/caret position without a selection. 74 // The returned value represents a cursor/caret position without a selection.
69 SelectionModel LeftSelectionModelByWord(const SelectionModel& current); 75 SelectionModel LeftSelectionModelByWord(const SelectionModel& current);
70 SelectionModel RightSelectionModelByWord(const SelectionModel& current); 76 SelectionModel RightSelectionModelByWord(const SelectionModel& current);
71 77
72 // If |layout_| is NULL, create and setup |layout_|, retain and ref
73 // |current_line_|. Return |layout_|.
74 PangoLayout* EnsureLayout();
75
76 // Unref |layout_| and |pango_line_|. Set them to NULL. 78 // Unref |layout_| and |pango_line_|. Set them to NULL.
77 void ResetLayout(); 79 void ResetLayout();
78 80
79 // Setup pango attribute: foreground, background, font, strike. 81 // Setup pango attribute: foreground, background, font, strike.
80 void SetupPangoAttributes(PangoLayout* layout); 82 void SetupPangoAttributes(PangoLayout* layout);
81 83
82 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. 84 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
83 void AppendPangoAttribute(size_t start, 85 void AppendPangoAttribute(size_t start,
84 size_t end, 86 size_t end,
85 PangoAttribute* pango_attr, 87 PangoAttribute* pango_attr,
86 PangoAttrList* attrs); 88 PangoAttrList* attrs);
87 89
88 // Returns |run|'s visually previous run. 90 // Returns |run|'s visually previous run.
89 // The complexity is O(n) since it is a single-linked list. 91 // The complexity is O(n) since it is a single-linked list.
90 PangoLayoutRun* GetPreviousRun(PangoLayoutRun* run) const; 92 PangoLayoutRun* GetPreviousRun(PangoLayoutRun* run) const;
91 93
92 // Returns the last run in |current_line_|. 94 // Returns the last run in |current_line_|.
93 // The complexity is O(n) since it is a single-linked list. 95 // The complexity is O(n) since it is a single-linked list.
94 PangoLayoutRun* GetLastRun() const; 96 PangoLayoutRun* GetLastRun() const;
95 97
96 size_t Utf16IndexToUtf8Index(size_t index) const; 98 size_t Utf16IndexToUtf8Index(size_t index) const;
97 size_t Utf8IndexToUtf16Index(size_t index) const; 99 size_t Utf8IndexToUtf16Index(size_t index) const;
98 100
101 // Calculate the visual bounds containing the logical substring within |from|
102 // to |to| into |bounds|.
103 void CalculateSubstringBounds(size_t from,
104 size_t to,
105 std::vector<Rect>* bounds);
106
107 // Save the visual bounds of logical selection into |bounds|.
108 void GetSelectionBounds(std::vector<Rect>* bounds);
109
99 // Pango Layout. 110 // Pango Layout.
100 PangoLayout* layout_; 111 PangoLayout* layout_;
101 // A single line layout resulting from laying out via |layout_|. 112 // A single line layout resulting from laying out via |layout_|.
102 PangoLayoutLine* current_line_; 113 PangoLayoutLine* current_line_;
103 114
104 // Information about character attributes. 115 // Information about character attributes.
105 PangoLogAttr* log_attrs_; 116 PangoLogAttr* log_attrs_;
106 // Number of attributes in |log_attrs_|. 117 // Number of attributes in |log_attrs_|.
107 int num_log_attrs_; 118 int num_log_attrs_;
108 119
120 // Vector of the visual bounds containing the logical substring of selection.
121 std::vector<Rect> selection_visual_bounds_;
122
109 // The text in the |layout_|. 123 // The text in the |layout_|.
110 const char* layout_text_; 124 const char* layout_text_;
111 // The text length. 125 // The text length.
112 size_t layout_text_len_; 126 size_t layout_text_len_;
113 127
114 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); 128 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
115 }; 129 };
116 130
117 } // namespace gfx 131 } // namespace gfx
118 132
119 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ 133 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698