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

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

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 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 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 #include <vector>
11 11
12 #include "ui/gfx/render_text.h" 12 #include "ui/gfx/render_text.h"
13 13
14 namespace gfx { 14 namespace gfx {
15 15
16 // RenderTextLinux is the Linux implementation of RenderText using Pango. 16 // RenderTextLinux is the Linux implementation of RenderText using Pango.
17 class RenderTextLinux : public RenderText { 17 class RenderTextLinux : public RenderText {
18 public: 18 public:
19 RenderTextLinux(); 19 RenderTextLinux();
20 virtual ~RenderTextLinux(); 20 virtual ~RenderTextLinux();
21 21
22 // Overridden from RenderText: 22 // Overridden from RenderText:
23 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE; 23 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE;
24 virtual int GetStringWidth() OVERRIDE; 24 virtual Size GetStringSize() OVERRIDE;
25 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; 25 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
26 virtual Rect GetCursorBounds(const SelectionModel& position,
27 bool insert_mode) OVERRIDE;
28 26
29 protected: 27 protected:
30 // Overridden from RenderText: 28 // Overridden from RenderText:
31 virtual SelectionModel AdjacentCharSelectionModel( 29 virtual SelectionModel AdjacentCharSelectionModel(
32 const SelectionModel& selection, 30 const SelectionModel& selection,
33 VisualCursorDirection direction) OVERRIDE; 31 VisualCursorDirection direction) OVERRIDE;
34 virtual SelectionModel AdjacentWordSelectionModel( 32 virtual SelectionModel AdjacentWordSelectionModel(
35 const SelectionModel& selection, 33 const SelectionModel& selection,
36 VisualCursorDirection direction) OVERRIDE; 34 VisualCursorDirection direction) OVERRIDE;
37 virtual SelectionModel EdgeSelectionModel( 35 virtual void GetGlyphBounds(size_t index,
38 VisualCursorDirection direction) OVERRIDE; 36 ui::Range* xspan,
39 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to) OVERRIDE; 37 int* height) OVERRIDE;
38 virtual std::vector<Rect> GetSubstringBounds(ui::Range range) OVERRIDE;
40 virtual void SetSelectionModel(const SelectionModel& model) OVERRIDE; 39 virtual void SetSelectionModel(const SelectionModel& model) OVERRIDE;
41 virtual bool IsCursorablePosition(size_t position) OVERRIDE; 40 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
42 virtual void UpdateLayout() OVERRIDE; 41 virtual void UpdateLayout() OVERRIDE;
43 virtual void EnsureLayout() OVERRIDE; 42 virtual void EnsureLayout() OVERRIDE;
44 virtual void DrawVisualText(Canvas* canvas) OVERRIDE; 43 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
45 44
46 private: 45 private:
47 virtual size_t IndexOfAdjacentGrapheme( 46 virtual size_t IndexOfAdjacentGrapheme(
48 size_t index, 47 size_t index,
49 LogicalCursorDirection direction) OVERRIDE; 48 LogicalCursorDirection direction) OVERRIDE;
50 49
51 // Returns the run that contains |position|. Return NULL if not found. 50 // Returns the run that contains the character attached to the caret in the
52 GSList* GetRunContainingPosition(size_t position) const; 51 // given selection model. Return NULL if not found.
52 GSList* GetRunContainingCaret(const SelectionModel& caret) const;
53 53
54 // Given |layout_index_of_current_grapheme|, returns the layout (UTF-8) index 54 // Given |layout_index_of_current_grapheme|, returns the layout (UTF-8) index
55 // of the |next| or previous grapheme in logical order. Returns 0 if there is 55 // of the |next| or previous grapheme in logical order. Returns 0 if there is
56 // no previous grapheme, or the |text_| length if there is no next grapheme. 56 // no previous grapheme, or the |text_| length if there is no next grapheme.
57 size_t LayoutIndexOfAdjacentGrapheme(size_t layout_index_of_current_grapheme, 57 size_t LayoutIndexOfAdjacentGrapheme(size_t layout_index_of_current_grapheme,
58 LogicalCursorDirection direction) const; 58 LogicalCursorDirection direction) const;
59 59
60 // Given a |run|, returns the SelectionModel that contains the logical first 60 // Given a |run|, returns the SelectionModel that contains the logical first
61 // or last caret position inside (not at a boundary of) the run. 61 // or last caret position inside (not at a boundary of) the run.
62 // The returned value represents a cursor/caret position without a selection. 62 // The returned value represents a cursor/caret position without a selection.
63 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const; 63 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const;
64 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const; 64 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const;
65 65
66 // Unref |layout_| and |pango_line_|. Set them to NULL. 66 // Unref |layout_| and |pango_line_|. Set them to NULL.
67 void ResetLayout(); 67 void ResetLayout();
68 68
69 // Setup pango attribute: foreground, background, font, strike. 69 // Setup pango attribute: foreground, background, font, strike.
70 void SetupPangoAttributes(PangoLayout* layout); 70 void SetupPangoAttributes(PangoLayout* layout);
71 71
72 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. 72 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
73 void AppendPangoAttribute(size_t start, 73 void AppendPangoAttribute(size_t start,
74 size_t end, 74 size_t end,
75 PangoAttribute* pango_attr, 75 PangoAttribute* pango_attr,
76 PangoAttrList* attrs); 76 PangoAttrList* attrs);
77 77
78 // Convert between indices into text() and indices into |layout_text_|. 78 // Convert between indices into text() and indices into |layout_text_|.
79 size_t TextIndexToLayoutIndex(size_t index) const; 79 size_t TextIndexToLayoutIndex(size_t index) const;
80 size_t LayoutIndexToTextIndex(size_t index) const; 80 size_t LayoutIndexToTextIndex(size_t index) const;
81 81
82 // Calculate the visual bounds containing the logical substring within |from| 82 // Calculate the visual bounds containing the logical substring within the
83 // to |to|. 83 // given range.
84 std::vector<Rect> CalculateSubstringBounds(size_t from, size_t to); 84 std::vector<Rect> CalculateSubstringBounds(ui::Range range);
85 85
86 // Get the visual bounds of the logical selection. 86 // Get the visual bounds of the logical selection.
87 std::vector<Rect> GetSelectionBounds(); 87 std::vector<Rect> GetSelectionBounds();
88 88
89 // Pango Layout. 89 // Pango Layout.
90 PangoLayout* layout_; 90 PangoLayout* layout_;
91 // A single line layout resulting from laying out via |layout_|. 91 // A single line layout resulting from laying out via |layout_|.
92 PangoLayoutLine* current_line_; 92 PangoLayoutLine* current_line_;
93 93
94 // Information about character attributes. 94 // Information about character attributes.
95 PangoLogAttr* log_attrs_; 95 PangoLogAttr* log_attrs_;
96 // Number of attributes in |log_attrs_|. 96 // Number of attributes in |log_attrs_|.
97 int num_log_attrs_; 97 int num_log_attrs_;
98 98
99 // Vector of the visual bounds containing the logical substring of selection. 99 // Vector of the visual bounds containing the logical substring of selection.
100 std::vector<Rect> selection_visual_bounds_; 100 std::vector<Rect> selection_visual_bounds_;
101 101
102 // The text in the |layout_|. 102 // The text in the |layout_|.
103 const char* layout_text_; 103 const char* layout_text_;
104 // The text length. 104 // The text length.
105 size_t layout_text_len_; 105 size_t layout_text_len_;
106 106
107 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); 107 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
108 }; 108 };
109 109
110 } // namespace gfx 110 } // namespace gfx
111 111
112 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ 112 #endif // UI_GFX_RENDER_TEXT_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698