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

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: comments Created 8 years, 10 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 void GetGlyphBounds(size_t index,
26 ui::Range* xspan,
27 int* height) OVERRIDE;
25 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; 28 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
26 virtual Rect GetCursorBounds(const SelectionModel& position,
27 bool insert_mode) OVERRIDE;
28 29
29 protected: 30 protected:
30 // Overridden from RenderText: 31 // Overridden from RenderText:
31 virtual SelectionModel AdjacentCharSelectionModel( 32 virtual SelectionModel AdjacentCharSelectionModel(
32 const SelectionModel& selection, 33 const SelectionModel& selection,
33 VisualCursorDirection direction) OVERRIDE; 34 VisualCursorDirection direction) OVERRIDE;
34 virtual SelectionModel AdjacentWordSelectionModel( 35 virtual SelectionModel AdjacentWordSelectionModel(
35 const SelectionModel& selection, 36 const SelectionModel& selection,
36 VisualCursorDirection direction) OVERRIDE; 37 VisualCursorDirection direction) OVERRIDE;
37 virtual SelectionModel EdgeSelectionModel( 38 virtual std::vector<Rect> GetSubstringBounds(ui::Range range) OVERRIDE;
38 VisualCursorDirection direction) OVERRIDE;
39 virtual std::vector<Rect> GetSubstringBounds(size_t from, size_t to) 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 |utf8_index_of_current_grapheme|, returns the UTF-8 index of the 54 // Given |utf8_index_of_current_grapheme|, returns the UTF-8 index of the
55 // |next| or previous grapheme in logical order. Returns 0 if there is no 55 // |next| or previous grapheme in logical order. Returns 0 if there is no
56 // previous grapheme, or the |text_| length if there is no next grapheme. 56 // previous grapheme, or the |text_| length if there is no next grapheme.
57 size_t Utf8IndexOfAdjacentGrapheme(size_t utf8_index_of_current_grapheme, 57 size_t Utf8IndexOfAdjacentGrapheme(size_t utf8_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 size_t Utf16IndexToUtf8Index(size_t index) const; 78 size_t Utf16IndexToUtf8Index(size_t index) const;
79 size_t Utf8IndexToUtf16Index(size_t index) const; 79 size_t Utf8IndexToUtf16Index(size_t index) const;
80 80
81 // Calculate the visual bounds containing the logical substring within |from| 81 // Calculate the visual bounds containing the logical substring within the
82 // to |to|. 82 // given range.
83 std::vector<Rect> CalculateSubstringBounds(size_t from, size_t to); 83 std::vector<Rect> CalculateSubstringBounds(ui::Range range);
84 84
85 // Get the visual bounds of the logical selection. 85 // Get the visual bounds of the logical selection.
86 std::vector<Rect> GetSelectionBounds(); 86 std::vector<Rect> GetSelectionBounds();
87 87
88 // Pango Layout. 88 // Pango Layout.
89 PangoLayout* layout_; 89 PangoLayout* layout_;
90 // A single line layout resulting from laying out via |layout_|. 90 // A single line layout resulting from laying out via |layout_|.
91 PangoLayoutLine* current_line_; 91 PangoLayoutLine* current_line_;
92 92
93 // Information about character attributes. 93 // Information about character attributes.
94 PangoLogAttr* log_attrs_; 94 PangoLogAttr* log_attrs_;
95 // Number of attributes in |log_attrs_|. 95 // Number of attributes in |log_attrs_|.
96 int num_log_attrs_; 96 int num_log_attrs_;
97 97
98 // Vector of the visual bounds containing the logical substring of selection. 98 // Vector of the visual bounds containing the logical substring of selection.
99 std::vector<Rect> selection_visual_bounds_; 99 std::vector<Rect> selection_visual_bounds_;
100 100
101 // The text in the |layout_|. 101 // The text in the |layout_|.
102 const char* layout_text_; 102 const char* layout_text_;
103 // The text length. 103 // The text length.
104 size_t layout_text_len_; 104 size_t layout_text_len_;
105 105
106 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); 106 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
107 }; 107 };
108 108
109 } // namespace gfx 109 } // namespace gfx
110 110
111 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ 111 #endif // UI_GFX_RENDER_TEXT_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698