Chromium Code Reviews| 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 "ui/gfx/render_text.h" | 9 #include "ui/gfx/render_text.h" |
| 10 | 10 |
| 11 #include <pango/pango.h> | |
| 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 virtual void SetText(const string16& text) OVERRIDE { |
| 22 RenderText::SetText(text); | |
|
msw
2011/08/19 23:16:59
All of these definitions are simple, but non-trivi
xji
2011/08/22 23:57:28
Done.
| |
| 23 ResetLayout(); | |
| 24 } | |
| 25 | |
| 26 virtual void SetDisplayRect(const Rect&r) OVERRIDE { | |
| 27 RenderText::SetDisplayRect(r); | |
| 28 ResetLayout(); | |
| 29 } | |
| 30 | |
| 31 virtual void ApplyStyleRange(StyleRange style_range) OVERRIDE { | |
| 32 RenderText::ApplyStyleRange(style_range); | |
| 33 ResetLayout(); | |
| 34 } | |
| 35 | |
| 36 virtual void ApplyDefaultStyle() OVERRIDE { | |
| 37 RenderText::ApplyDefaultStyle(); | |
| 38 ResetLayout(); | |
| 39 } | |
| 40 | |
| 41 virtual int GetStringWidth() OVERRIDE; | |
| 42 | |
| 43 virtual void Draw(Canvas* canvas) OVERRIDE; | |
| 44 | |
| 45 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE; | |
| 46 | |
| 47 virtual Rect GetCursorBounds(const SelectionModel& position, | |
| 48 bool insert_mode) OVERRIDE; | |
| 49 | |
| 50 private: | |
| 51 enum CursorMovementDirection { | |
| 52 LEFT, | |
| 53 RIGHT | |
| 54 }; | |
| 55 | |
| 56 enum RelativeLogicalPosition { | |
| 57 PREVIOUS, | |
| 58 NEXT | |
| 59 }; | |
| 60 | |
| 61 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, | |
|
msw
2011/08/19 23:16:59
Also add "// Overridden from RenderText:" here and
xji
2011/08/22 23:57:28
Done.
| |
| 62 BreakType break_type) OVERRIDE; | |
| 63 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, | |
| 64 BreakType break_type) OVERRIDE; | |
| 65 | |
| 66 virtual size_t GetIndexOfPreviousGrapheme(size_t position) OVERRIDE; | |
| 67 | |
| 68 // Returns the SelectionModel for visual leftmost position in the line. | |
|
msw
2011/08/19 23:16:59
There are going to be lots of opportunities for us
xji
2011/08/22 23:57:28
Changed to the same names. But I can not declare t
msw
2011/08/23 08:01:01
Sounds good.
| |
| 69 // The returned value represents a cursor/caret position without a selection. | |
| 70 SelectionModel GetSelectionModelForVisualLeftmost() const; | |
| 71 | |
| 72 // Returns the run that contains the caret_pos in |current|. Based on moving | |
| 73 // direction, set whether the (caret_pos, caret_placement) is at the boundary | |
| 74 // of the run. If moving right, the trailing edge of LTR run or the leading | |
| 75 // edge of RTL run is at boundary of run. If moving left, the leading edge of | |
| 76 // LTR run or the trailing edge of RTL run is at the boundary of run. | |
| 77 // | |
| 78 // This does not work if |current| is the visually rightmost END position, | |
| 79 // which is SelectionModel(text().length(), text().length(), LEADING). | |
| 80 // This END position does not belong to any run. | |
|
msw
2011/08/19 23:16:59
Interesting, instead of using a caret at (text().l
xji
2011/08/22 23:57:28
I think you are right. I changed it to your way.
msw
2011/08/23 08:01:01
:)
| |
| 81 GSList* GetRunContainsCaretPos(const SelectionModel& current, | |
|
msw
2011/08/19 23:16:59
Hopefully we'll be able to merge the signatures an
xji
2011/08/22 23:57:28
I changed the implementation as yours. But I am re
msw
2011/08/23 08:01:01
:) I'm so sorry about the GList, it's a tragedy.
| |
| 82 CursorMovementDirection dir, | |
| 83 bool* at_boundary) const; | |
| 84 | |
| 85 // Given |utf16_index_of_current_grapheme|, returns the UTF8 index of next | |
| 86 // graphame in the text if |pos| is NEXT, otherwise, returns the UTF8 index of | |
| 87 // previous grapheme. | |
| 88 size_t Utf8IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme, | |
| 89 RelativeLogicalPosition pos) const; | |
| 90 | |
| 91 // Given |utf16_index_of_current_grapheme|, returns the UTF16 index of next | |
| 92 // graphame in the text if |pos| is NEXT, otherwise, returns the UTF16 index | |
| 93 // of previous grapheme. | |
| 94 size_t Utf16IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme, | |
| 95 RelativeLogicalPosition pos) const; | |
| 96 | |
| 97 // Given a |run|, returns the SelectionModel that contains the logical first | |
| 98 // caret position inside (not at bounary of) the run. | |
|
msw
2011/08/19 23:16:59
"not at *a* boundary" here and elsewhere
xji
2011/08/22 23:57:28
Done.
| |
| 99 // The returned value represents a cursor/caret position without a selection. | |
| 100 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const; | |
| 101 | |
| 102 // Given a |run|, returns the SelectionModel that contains the logical last | |
| 103 // caret position inside (not at bounary of) the run. | |
| 104 // The returned value represents a cursor/caret position without a selection. | |
| 105 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const; | |
| 106 | |
| 107 // Given a |run|, returns the SelectionModel that contains the leftmost caret | |
| 108 // position inside (not at bounary of) the run. | |
| 109 // The returned value represents a cursor/caret position without a selection. | |
| 110 SelectionModel LeftmostSelectionModelInsideRun(const PangoItem* run) const; | |
| 111 | |
| 112 // Given a |run|, returns the SelectionModel that contains the rightmost caret | |
| 113 // position inside (not at bounary of) the run. | |
| 114 // The returned value represents a cursor/caret position without a selection. | |
| 115 SelectionModel RightmostSelectionModelInsideRun(const PangoItem* run) const; | |
| 116 | |
| 117 // when |sel| is the visually rightmost END position of line, set |adjacent| | |
|
msw
2011/08/19 23:16:59
Wouldn't it be left-most for RTL text/UI?
xji
2011/08/22 23:57:28
this handles the right (visual) end (NOT the logic
| |
| 118 // as the left or right (depends on |dir|) of |sel| and return true. | |
| 119 // Otherwise, return false. | |
| 120 // The value set in |adjacent| represnts a cursor/caret positin without a | |
|
msw
2011/08/19 23:16:59
positi*o*n
xji
2011/08/22 23:57:28
Done.
| |
| 121 // selection. | |
| 122 bool GetVisuallyAdjacentCursorPositionForEnd(const SelectionModel& current, | |
| 123 CursorMovementDirection dir, | |
| 124 SelectionModel* adjacent) const; | |
| 125 | |
| 126 // Get the selection model that visually left of |current| by one grapheme. | |
| 127 // The returned value represents a cursor/caret position without a selection. | |
| 128 SelectionModel GetLeftSelectionModelByGrapheme( | |
| 129 const SelectionModel& current) const; | |
| 130 | |
| 131 // Get the selection model that visually right of |current| by one grapheme. | |
| 132 // The returned value represents a cursor/caret position without a selection. | |
| 133 SelectionModel GetRightSelectionModelByGrapheme( | |
| 134 const SelectionModel& current) const; | |
| 135 | |
| 136 // Creates, setup, and returns pango layout and pango layout line if layout_ | |
|
msw
2011/08/19 23:16:59
"Create*, setup, and return*" to match the tense o
xji
2011/08/22 23:57:28
Done.
| |
| 137 // is NULL. Otherwise, return the cached layout_. | |
| 138 PangoLayout* EnsureLayout(); | |
| 139 | |
| 140 // Unref pango layout (layout_) and pango layout line (pango_line_). Set them | |
|
msw
2011/08/19 23:16:59
Use vertical bars to indicate members, and you can
xji
2011/08/22 23:57:28
Done.
I thought we only use vertical bar for funct
msw
2011/08/23 08:01:01
Hmm, you might be right; I'm still learning chromi
xji
2011/08/23 23:52:52
I checked with my co-worker, and seems there is no
| |
| 141 // to NULL. nds_. | |
|
msw
2011/08/19 23:16:59
what is " nds_."?
xji
2011/08/22 23:57:28
must have done extra editing accidently. removed.
| |
| 142 void ResetLayout(); | |
| 143 | |
| 144 // Setup pango attribute: foreground, background, font, strike. | |
| 145 void SetupPangoAttributes(PangoLayout* layout); | |
| 146 | |
| 147 // Append one pango attribute |pango_attr| into pango attribute list |attrs|. | |
| 148 void AppendPangoAttribute(size_t start, | |
| 149 size_t end, | |
| 150 PangoAttribute* pango_attr, | |
| 151 PangoAttrList* attrs); | |
| 152 | |
| 153 // Returns |run|'s visually previous run. | |
| 154 GSList* GetPreviousRun(GSList* run) const; | |
| 155 | |
| 156 // Returns last run in Layout_line_. | |
|
msw
2011/08/19 23:16:59
"*the* last run" and use bars and un-capitalize "|
xji
2011/08/22 23:57:28
Done.
| |
| 157 GSList* GetLastRun() const; | |
| 158 | |
| 159 size_t Utf16IndexToUtf8Index(const string16& text, size_t index) const; | |
|
msw
2011/08/19 23:16:59
These two functions don't use any class members, a
xji
2011/08/22 23:57:28
Done.
| |
| 160 size_t Utf8IndexToUtf16Index(const string16& text, size_t index) const; | |
| 161 | |
| 162 // Adjust |bounds| for non insert mode. | |
| 163 void AdjustBoundsForNonInsertMode(const SelectionModel& selection, | |
| 164 const PangoRectangle& pos, | |
| 165 Rect* bounds) const; | |
| 166 | |
| 167 PangoLayout* layout_; | |
| 168 | |
| 169 PangoLayoutLine* layout_line_; | |
| 170 | |
| 20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); | 171 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); |
| 21 }; | 172 }; |
| 22 | 173 |
| 23 } // namespace gfx; | 174 } // namespace gfx; |
| 24 | 175 |
| 25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ | 176 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ |
| OLD | NEW |