OLD | NEW |
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 #include "ui/gfx/render_text_linux.h" | 5 #include "ui/gfx/render_text_linux.h" |
6 | 6 |
7 #include <pango/pangocairo.h> | 7 #include <pango/pangocairo.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 base::i18n::TextDirection RenderTextLinux::GetTextDirection() { | 71 base::i18n::TextDirection RenderTextLinux::GetTextDirection() { |
72 EnsureLayout(); | 72 EnsureLayout(); |
73 | 73 |
74 PangoDirection base_dir = pango_find_base_dir(layout_text_, -1); | 74 PangoDirection base_dir = pango_find_base_dir(layout_text_, -1); |
75 if (base_dir == PANGO_DIRECTION_RTL || base_dir == PANGO_DIRECTION_WEAK_RTL) | 75 if (base_dir == PANGO_DIRECTION_RTL || base_dir == PANGO_DIRECTION_WEAK_RTL) |
76 return base::i18n::RIGHT_TO_LEFT; | 76 return base::i18n::RIGHT_TO_LEFT; |
77 return base::i18n::LEFT_TO_RIGHT; | 77 return base::i18n::LEFT_TO_RIGHT; |
78 } | 78 } |
79 | 79 |
80 int RenderTextLinux::GetStringWidth() { | 80 Size RenderTextLinux::GetStringSize() { |
81 EnsureLayout(); | 81 EnsureLayout(); |
82 int width; | 82 int width = 0, height = 0; |
83 pango_layout_get_pixel_size(layout_, &width, NULL); | 83 pango_layout_get_pixel_size(layout_, &width, &height); |
84 return width; | 84 return Size(width, height); |
85 } | 85 } |
86 | 86 |
87 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { | 87 SelectionModel RenderTextLinux::FindCursorPosition(const Point& point) { |
88 EnsureLayout(); | 88 EnsureLayout(); |
89 | 89 |
90 if (text().empty()) | 90 if (text().empty()) |
91 return SelectionModel(0, 0, SelectionModel::LEADING); | 91 return SelectionModel(0, CURSOR_FORWARD); |
92 | 92 |
93 Point p(ToTextPoint(point)); | 93 Point p(ToTextPoint(point)); |
94 | 94 |
95 // When the point is outside of text, return HOME/END position. | 95 // When the point is outside of text, return HOME/END position. |
96 if (p.x() < 0) | 96 if (p.x() < 0) |
97 return EdgeSelectionModel(CURSOR_LEFT); | 97 return EdgeSelectionModel(CURSOR_LEFT); |
98 else if (p.x() > GetStringWidth()) | 98 else if (p.x() > GetStringSize().width()) |
99 return EdgeSelectionModel(CURSOR_RIGHT); | 99 return EdgeSelectionModel(CURSOR_RIGHT); |
100 | 100 |
101 int caret_pos, trailing; | 101 int caret_pos = 0, trailing = 0; |
102 pango_layout_xy_to_index(layout_, p.x() * PANGO_SCALE, p.y() * PANGO_SCALE, | 102 pango_layout_xy_to_index(layout_, p.x() * PANGO_SCALE, p.y() * PANGO_SCALE, |
103 &caret_pos, &trailing); | 103 &caret_pos, &trailing); |
104 | 104 |
105 size_t selection_end = caret_pos; | 105 DCHECK_GE(trailing, 0); |
106 if (trailing > 0) { | 106 if (trailing > 0) { |
107 const char* ch = g_utf8_offset_to_pointer(layout_text_ + caret_pos, | 107 caret_pos = g_utf8_offset_to_pointer(layout_text_ + caret_pos, |
108 trailing); | 108 trailing) - layout_text_; |
109 DCHECK_GE(ch, layout_text_); | 109 DCHECK_LE(static_cast<size_t>(caret_pos), layout_text_len_); |
110 DCHECK_LE(ch, layout_text_ + layout_text_len_); | |
111 selection_end = ch - layout_text_; | |
112 } | 110 } |
113 | 111 |
114 return SelectionModel( | 112 return SelectionModel(LayoutIndexToTextIndex(caret_pos), |
115 LayoutIndexToTextIndex(selection_end), | 113 (trailing > 0) ? CURSOR_BACKWARD : CURSOR_FORWARD); |
116 LayoutIndexToTextIndex(caret_pos), | |
117 trailing > 0 ? SelectionModel::TRAILING : SelectionModel::LEADING); | |
118 } | 114 } |
119 | 115 |
120 Rect RenderTextLinux::GetCursorBounds(const SelectionModel& selection, | |
121 bool insert_mode) { | |
122 EnsureLayout(); | |
123 | |
124 size_t caret_pos = insert_mode ? selection.caret_pos() : | |
125 selection.selection_end(); | |
126 PangoRectangle pos; | |
127 pango_layout_index_to_pos(layout_, TextIndexToLayoutIndex(caret_pos), &pos); | |
128 | |
129 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); | |
130 int x = pos.x; | |
131 if ((insert_mode && caret_placement == SelectionModel::TRAILING) || | |
132 (!insert_mode && pos.width < 0)) | |
133 x += pos.width; | |
134 x = PANGO_PIXELS(x); | |
135 | |
136 int h = std::min(display_rect().height(), PANGO_PIXELS(pos.height)); | |
137 Rect bounds(x, (display_rect().height() - h) / 2, 0, h); | |
138 bounds.set_origin(ToViewPoint(bounds.origin())); | |
139 | |
140 if (!insert_mode) | |
141 bounds.set_width(PANGO_PIXELS(std::abs(pos.width))); | |
142 | |
143 return bounds; | |
144 } | |
145 | |
146 // Assume caret_pos in |current| is n, 'l' represents leading in | |
147 // caret_placement and 't' represents trailing in caret_placement. Following | |
148 // is the calculation from (caret_pos, caret_placement) in |current| to | |
149 // (selection_end, caret_pos, caret_placement) when moving cursor left/right by | |
150 // one grapheme (for simplicity, assume each grapheme is one character). | |
151 // If n is in LTR (if moving left) or RTL (if moving right) run, | |
152 // (n, t) --> (n, n, l). | |
153 // (n, l) --> (n-1, n-1, l) if n is inside run (not at boundary). | |
154 // (n, l) --> goto across run case if n is at run boundary. | |
155 // Otherwise, | |
156 // (n, l) --> (n+1, n, t). | |
157 // (n, t) --> (n+2, n+1, t) if n is inside run. | |
158 // (n, t) --> goto across run case if n is at run boundary. | |
159 // If n is at run boundary, get its visually left/right run, | |
160 // If left/right run is LTR/RTL run, | |
161 // (n, t) --> (left/right run's end, left/right run's end, l). | |
162 // Otherwise, | |
163 // (n, t) --> (left/right run's begin + 1, left/right run's begin, t). | |
164 SelectionModel RenderTextLinux::AdjacentCharSelectionModel( | 116 SelectionModel RenderTextLinux::AdjacentCharSelectionModel( |
165 const SelectionModel& selection, | 117 const SelectionModel& selection, |
166 VisualCursorDirection direction) { | 118 VisualCursorDirection direction) { |
167 size_t caret = selection.caret_pos(); | 119 GSList* run = GetRunContainingCaret(selection); |
168 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); | 120 if (!run) { |
169 GSList* run = GetRunContainingPosition(caret); | 121 // The cursor is not in any run: we're at the visual and logical edge. |
170 DCHECK(run); | 122 SelectionModel edge = EdgeSelectionModel(direction); |
171 | 123 if (edge.caret_pos() == selection.caret_pos()) |
172 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data); | 124 return edge; |
173 PangoItem* item = layout_run->item; | 125 else |
174 size_t run_start = LayoutIndexToTextIndex(item->offset); | 126 run = (direction == CURSOR_RIGHT) ? |
175 size_t run_end = LayoutIndexToTextIndex(item->offset + item->length); | 127 current_line_->runs : g_slist_last(current_line_->runs); |
176 if (!IsForwardMotion(direction, item)) { | 128 } else { |
177 if (caret_placement == SelectionModel::TRAILING) | 129 // If the cursor is moving within the current run, just move it by one |
178 return SelectionModel(caret, caret, SelectionModel::LEADING); | 130 // grapheme in the appropriate direction. |
179 else if (caret > run_start) { | 131 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
180 caret = IndexOfAdjacentGrapheme(caret, CURSOR_BACKWARD); | 132 size_t caret = selection.caret_pos(); |
181 return SelectionModel(caret, caret, SelectionModel::LEADING); | 133 if (IsForwardMotion(direction, item)) { |
| 134 if (caret < LayoutIndexToTextIndex(item->offset + item->length)) { |
| 135 caret = IndexOfAdjacentGrapheme(caret, CURSOR_FORWARD); |
| 136 return SelectionModel(caret, CURSOR_BACKWARD); |
| 137 } |
| 138 } else { |
| 139 if (caret > LayoutIndexToTextIndex(item->offset)) { |
| 140 caret = IndexOfAdjacentGrapheme(caret, CURSOR_BACKWARD); |
| 141 return SelectionModel(caret, CURSOR_FORWARD); |
| 142 } |
182 } | 143 } |
183 } else { | 144 // The cursor is at the edge of a run; move to the visually adjacent run. |
184 if (caret_placement == SelectionModel::LEADING) { | 145 // TODO(xji): Keep a vector of runs to avoid using a singly-linked list. |
185 size_t cursor = IndexOfAdjacentGrapheme(caret, CURSOR_FORWARD); | 146 run = (direction == CURSOR_RIGHT) ? |
186 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | 147 run->next : GSListPrevious(current_line_->runs, run); |
187 } else if (selection.selection_end() < run_end) { | 148 if (!run) |
188 caret = IndexOfAdjacentGrapheme(caret, CURSOR_FORWARD); | 149 return EdgeSelectionModel(direction); |
189 size_t cursor = IndexOfAdjacentGrapheme(caret, CURSOR_FORWARD); | |
190 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | |
191 } | |
192 } | 150 } |
193 | 151 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
194 // The character is at the edge of its run; advance to the adjacent visual | |
195 // run. | |
196 // TODO(xji): Keep a vector of runs to avoid using a singly-linked list. | |
197 GSList* adjacent_run = (direction == CURSOR_RIGHT) ? | |
198 run->next : GSListPrevious(current_line_->runs, run); | |
199 if (!adjacent_run) | |
200 return EdgeSelectionModel(direction); | |
201 | |
202 item = reinterpret_cast<PangoLayoutRun*>(adjacent_run->data)->item; | |
203 return IsForwardMotion(direction, item) ? | 152 return IsForwardMotion(direction, item) ? |
204 FirstSelectionModelInsideRun(item) : LastSelectionModelInsideRun(item); | 153 FirstSelectionModelInsideRun(item) : LastSelectionModelInsideRun(item); |
205 } | 154 } |
206 | 155 |
207 SelectionModel RenderTextLinux::AdjacentWordSelectionModel( | 156 SelectionModel RenderTextLinux::AdjacentWordSelectionModel( |
208 const SelectionModel& selection, | 157 const SelectionModel& selection, |
209 VisualCursorDirection direction) { | 158 VisualCursorDirection direction) { |
210 if (is_obscured()) | 159 if (is_obscured()) |
211 return EdgeSelectionModel(direction); | 160 return EdgeSelectionModel(direction); |
212 | 161 |
213 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 162 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
214 bool success = iter.Init(); | 163 bool success = iter.Init(); |
215 DCHECK(success); | 164 DCHECK(success); |
216 if (!success) | 165 if (!success) |
217 return selection; | 166 return selection; |
218 | 167 |
219 SelectionModel end = EdgeSelectionModel(direction); | |
220 SelectionModel cur(selection); | 168 SelectionModel cur(selection); |
221 while (!cur.Equals(end)) { | 169 for (;;) { |
222 cur = AdjacentCharSelectionModel(cur, direction); | 170 cur = AdjacentCharSelectionModel(cur, direction); |
223 size_t caret = cur.caret_pos(); | 171 GSList* run = GetRunContainingCaret(cur); |
224 GSList* run = GetRunContainingPosition(caret); | 172 if (!run) |
225 DCHECK(run); | 173 break; |
226 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 174 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
227 size_t cursor = cur.selection_end(); | 175 size_t cursor = cur.caret_pos(); |
228 if (IsForwardMotion(direction, item) ? | 176 if (IsForwardMotion(direction, item) ? |
229 iter.IsEndOfWord(cursor) : iter.IsStartOfWord(cursor)) | 177 iter.IsEndOfWord(cursor) : iter.IsStartOfWord(cursor)) |
230 return cur; | 178 break; |
231 } | 179 } |
232 | 180 |
233 return end; | 181 return cur; |
234 } | |
235 | |
236 SelectionModel RenderTextLinux::EdgeSelectionModel( | |
237 VisualCursorDirection direction) { | |
238 if (direction == GetVisualDirectionOfLogicalEnd()) { | |
239 // Advance to the logical end of the text. | |
240 GSList* run = current_line_->runs; | |
241 if (direction == CURSOR_RIGHT) | |
242 run = g_slist_last(run); | |
243 if (run) { | |
244 PangoLayoutRun* end_run = reinterpret_cast<PangoLayoutRun*>(run->data); | |
245 PangoItem* item = end_run->item; | |
246 if (IsForwardMotion(direction, item)) { | |
247 size_t caret = IndexOfAdjacentGrapheme( | |
248 LayoutIndexToTextIndex(item->offset + item->length), | |
249 CURSOR_BACKWARD); | |
250 return SelectionModel(text().length(), caret, SelectionModel::TRAILING); | |
251 } else { | |
252 size_t caret = LayoutIndexToTextIndex(item->offset); | |
253 return SelectionModel(text().length(), caret, SelectionModel::LEADING); | |
254 } | |
255 } | |
256 } | |
257 return SelectionModel(0, 0, SelectionModel::LEADING); | |
258 } | 182 } |
259 | 183 |
260 void RenderTextLinux::SetSelectionModel(const SelectionModel& model) { | 184 void RenderTextLinux::SetSelectionModel(const SelectionModel& model) { |
261 if (GetSelectionStart() != model.selection_start() || | 185 if (selection() != model.selection()) |
262 GetCursorPosition() != model.selection_end()) { | |
263 selection_visual_bounds_.clear(); | 186 selection_visual_bounds_.clear(); |
264 } | |
265 | 187 |
266 RenderText::SetSelectionModel(model); | 188 RenderText::SetSelectionModel(model); |
267 } | 189 } |
268 | 190 |
269 std::vector<Rect> RenderTextLinux::GetSubstringBounds(size_t from, size_t to) { | 191 void RenderTextLinux::GetGlyphBounds(size_t index, |
270 DCHECK(from <= text().length()); | 192 ui::Range* xspan, |
271 DCHECK(to <= text().length()); | 193 int* height) { |
| 194 PangoRectangle pos; |
| 195 pango_layout_index_to_pos(layout_, TextIndexToLayoutIndex(index), &pos); |
| 196 *xspan = ui::Range(PANGO_PIXELS(pos.x), PANGO_PIXELS(pos.x + pos.width)); |
| 197 *height = PANGO_PIXELS(pos.height); |
| 198 } |
272 | 199 |
273 if (from == to) | 200 std::vector<Rect> RenderTextLinux::GetSubstringBounds(ui::Range range) { |
| 201 DCHECK_LE(range.GetMax(), text().length()); |
| 202 |
| 203 if (range.is_empty()) |
274 return std::vector<Rect>(); | 204 return std::vector<Rect>(); |
275 | 205 |
276 EnsureLayout(); | 206 EnsureLayout(); |
277 | 207 if (range == selection()) |
278 if (from == GetSelectionStart() && to == GetCursorPosition()) | |
279 return GetSelectionBounds(); | 208 return GetSelectionBounds(); |
280 else | 209 return CalculateSubstringBounds(range); |
281 return CalculateSubstringBounds(from, to); | |
282 } | 210 } |
283 | 211 |
284 bool RenderTextLinux::IsCursorablePosition(size_t position) { | 212 bool RenderTextLinux::IsCursorablePosition(size_t position) { |
285 if (position == 0 && text().empty()) | 213 if (position == 0 && text().empty()) |
286 return true; | 214 return true; |
287 | 215 |
288 EnsureLayout(); | 216 EnsureLayout(); |
289 ptrdiff_t offset = ui::UTF16IndexToOffset(text(), 0, position); | 217 ptrdiff_t offset = ui::UTF16IndexToOffset(text(), 0, position); |
290 return (offset < num_log_attrs_ && log_attrs_[offset].is_cursor_position); | 218 return (offset < num_log_attrs_ && log_attrs_[offset].is_cursor_position); |
291 } | 219 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 if (char_offset < num_log_attrs_ - 1) { | 412 if (char_offset < num_log_attrs_ - 1) { |
485 do { | 413 do { |
486 ++char_offset; | 414 ++char_offset; |
487 } while (char_offset < num_log_attrs_ - 1 && | 415 } while (char_offset < num_log_attrs_ - 1 && |
488 !log_attrs_[char_offset].is_cursor_position); | 416 !log_attrs_[char_offset].is_cursor_position); |
489 } | 417 } |
490 } | 418 } |
491 return ui::UTF16OffsetToIndex(text(), 0, char_offset); | 419 return ui::UTF16OffsetToIndex(text(), 0, char_offset); |
492 } | 420 } |
493 | 421 |
494 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { | 422 GSList* RenderTextLinux::GetRunContainingCaret( |
495 position = TextIndexToLayoutIndex(position); | 423 const SelectionModel& caret) const { |
496 for (GSList* run = current_line_->runs; run; run = run->next) { | 424 size_t position = TextIndexToLayoutIndex(caret.caret_pos()); |
| 425 LogicalCursorDirection affinity = caret.caret_affinity(); |
| 426 GSList* run = current_line_->runs; |
| 427 while (run) { |
497 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 428 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
498 if (position >= static_cast<size_t>(item->offset) && | 429 ui::Range item_range(item->offset, item->offset + item->length); |
499 position < static_cast<size_t>(item->offset + item->length)) | 430 if (RangeContainsCaret(item_range, position, affinity)) |
500 return run; | 431 return run; |
| 432 run = run->next; |
501 } | 433 } |
502 return NULL; | 434 return NULL; |
503 } | 435 } |
504 | 436 |
505 SelectionModel RenderTextLinux::FirstSelectionModelInsideRun( | 437 SelectionModel RenderTextLinux::FirstSelectionModelInsideRun( |
506 const PangoItem* item) { | 438 const PangoItem* item) { |
507 size_t caret = LayoutIndexToTextIndex(item->offset); | 439 size_t caret = IndexOfAdjacentGrapheme( |
508 size_t cursor = IndexOfAdjacentGrapheme(caret, CURSOR_FORWARD); | 440 LayoutIndexToTextIndex(item->offset), CURSOR_FORWARD); |
509 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | 441 return SelectionModel(caret, CURSOR_BACKWARD); |
510 } | 442 } |
511 | 443 |
512 SelectionModel RenderTextLinux::LastSelectionModelInsideRun( | 444 SelectionModel RenderTextLinux::LastSelectionModelInsideRun( |
513 const PangoItem* item) { | 445 const PangoItem* item) { |
514 size_t caret = IndexOfAdjacentGrapheme( | 446 size_t caret = IndexOfAdjacentGrapheme( |
515 LayoutIndexToTextIndex(item->offset + item->length), CURSOR_BACKWARD); | 447 LayoutIndexToTextIndex(item->offset + item->length), CURSOR_BACKWARD); |
516 return SelectionModel(caret, caret, SelectionModel::LEADING); | 448 return SelectionModel(caret, CURSOR_FORWARD); |
517 } | 449 } |
518 | 450 |
519 void RenderTextLinux::ResetLayout() { | 451 void RenderTextLinux::ResetLayout() { |
520 // set_cached_bounds_and_offset_valid(false) is done in RenderText for every | 452 // set_cached_bounds_and_offset_valid(false) is done in RenderText for every |
521 // operation that triggers ResetLayout(). | 453 // operation that triggers ResetLayout(). |
522 if (layout_) { | 454 if (layout_) { |
523 g_object_unref(layout_); | 455 g_object_unref(layout_); |
524 layout_ = NULL; | 456 layout_ = NULL; |
525 } | 457 } |
526 if (current_line_) { | 458 if (current_line_) { |
(...skipping 22 matching lines...) Expand all Loading... |
549 } | 481 } |
550 | 482 |
551 size_t RenderTextLinux::LayoutIndexToTextIndex(size_t layout_index) const { | 483 size_t RenderTextLinux::LayoutIndexToTextIndex(size_t layout_index) const { |
552 // See |TextIndexToLayoutIndex()|. | 484 // See |TextIndexToLayoutIndex()|. |
553 DCHECK(layout_); | 485 DCHECK(layout_); |
554 const char* layout_pointer = layout_text_ + layout_index; | 486 const char* layout_pointer = layout_text_ + layout_index; |
555 long offset = g_utf8_pointer_to_offset(layout_text_, layout_pointer); | 487 long offset = g_utf8_pointer_to_offset(layout_text_, layout_pointer); |
556 return ui::UTF16OffsetToIndex(text(), 0, offset); | 488 return ui::UTF16OffsetToIndex(text(), 0, offset); |
557 } | 489 } |
558 | 490 |
559 std::vector<Rect> RenderTextLinux::CalculateSubstringBounds(size_t from, | 491 std::vector<Rect> RenderTextLinux::CalculateSubstringBounds(ui::Range range) { |
560 size_t to) { | |
561 int* ranges; | 492 int* ranges; |
562 int n_ranges; | 493 int n_ranges; |
563 size_t from_in_utf8 = TextIndexToLayoutIndex(from); | |
564 size_t to_in_utf8 = TextIndexToLayoutIndex(to); | |
565 pango_layout_line_get_x_ranges( | 494 pango_layout_line_get_x_ranges( |
566 current_line_, | 495 current_line_, |
567 std::min(from_in_utf8, to_in_utf8), | 496 TextIndexToLayoutIndex(range.GetMin()), |
568 std::max(from_in_utf8, to_in_utf8), | 497 TextIndexToLayoutIndex(range.GetMax()), |
569 &ranges, | 498 &ranges, |
570 &n_ranges); | 499 &n_ranges); |
571 | 500 |
572 int height; | 501 int height; |
573 pango_layout_get_pixel_size(layout_, NULL, &height); | 502 pango_layout_get_pixel_size(layout_, NULL, &height); |
574 | 503 |
575 int y = (display_rect().height() - height) / 2; | 504 int y = (display_rect().height() - height) / 2; |
576 | 505 |
577 std::vector<Rect> bounds; | 506 std::vector<Rect> bounds; |
578 for (int i = 0; i < n_ranges; ++i) { | 507 for (int i = 0; i < n_ranges; ++i) { |
579 int x = PANGO_PIXELS(ranges[2 * i]); | 508 int x = PANGO_PIXELS(ranges[2 * i]); |
580 int width = PANGO_PIXELS(ranges[2 * i + 1]) - x; | 509 int width = PANGO_PIXELS(ranges[2 * i + 1]) - x; |
581 Rect rect(x, y, width, height); | 510 Rect rect(x, y, width, height); |
582 rect.set_origin(ToViewPoint(rect.origin())); | 511 rect.set_origin(ToViewPoint(rect.origin())); |
583 bounds.push_back(rect); | 512 bounds.push_back(rect); |
584 } | 513 } |
585 g_free(ranges); | 514 g_free(ranges); |
586 return bounds; | 515 return bounds; |
587 } | 516 } |
588 | 517 |
589 std::vector<Rect> RenderTextLinux::GetSelectionBounds() { | 518 std::vector<Rect> RenderTextLinux::GetSelectionBounds() { |
590 if (selection_visual_bounds_.empty()) | 519 if (selection_visual_bounds_.empty()) |
591 selection_visual_bounds_ = | 520 selection_visual_bounds_ = CalculateSubstringBounds(selection()); |
592 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition()); | |
593 return selection_visual_bounds_; | 521 return selection_visual_bounds_; |
594 } | 522 } |
595 | 523 |
596 } // namespace gfx | 524 } // namespace gfx |
OLD | NEW |