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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 run = (direction == CURSOR_RIGHT) ? | 175 run = (direction == CURSOR_RIGHT) ? |
176 run->next : GSListPrevious(current_line_->runs, run); | 176 run->next : GSListPrevious(current_line_->runs, run); |
177 if (!run) | 177 if (!run) |
178 return EdgeSelectionModel(direction); | 178 return EdgeSelectionModel(direction); |
179 } | 179 } |
180 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 180 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
181 return IsForwardMotion(direction, item) ? | 181 return IsForwardMotion(direction, item) ? |
182 FirstSelectionModelInsideRun(item) : LastSelectionModelInsideRun(item); | 182 FirstSelectionModelInsideRun(item) : LastSelectionModelInsideRun(item); |
183 } | 183 } |
184 | 184 |
185 SelectionModel RenderTextLinux::AdjacentWordSelectionModel( | |
186 const SelectionModel& selection, | |
187 VisualCursorDirection direction) { | |
188 if (obscured()) | |
189 return EdgeSelectionModel(direction); | |
190 | |
191 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | |
192 bool success = iter.Init(); | |
193 DCHECK(success); | |
194 if (!success) | |
195 return selection; | |
196 | |
197 SelectionModel cur(selection); | |
198 for (;;) { | |
199 cur = AdjacentCharSelectionModel(cur, direction); | |
200 GSList* run = GetRunContainingCaret(cur); | |
201 if (!run) | |
202 break; | |
203 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | |
204 size_t cursor = cur.caret_pos(); | |
205 if (IsForwardMotion(direction, item) ? | |
206 iter.IsEndOfWord(cursor) : iter.IsStartOfWord(cursor)) | |
207 break; | |
208 } | |
209 | |
210 return cur; | |
211 } | |
212 | |
213 ui::Range RenderTextLinux::GetGlyphBounds(size_t index) { | 185 ui::Range RenderTextLinux::GetGlyphBounds(size_t index) { |
214 PangoRectangle pos; | 186 PangoRectangle pos; |
215 pango_layout_index_to_pos(layout_, TextIndexToLayoutIndex(index), &pos); | 187 pango_layout_index_to_pos(layout_, TextIndexToLayoutIndex(index), &pos); |
216 // TODO(derat): Support fractional ranges for subpixel positioning? | 188 // TODO(derat): Support fractional ranges for subpixel positioning? |
217 return ui::Range(PANGO_PIXELS(pos.x), PANGO_PIXELS(pos.x + pos.width)); | 189 return ui::Range(PANGO_PIXELS(pos.x), PANGO_PIXELS(pos.x + pos.width)); |
218 } | 190 } |
219 | 191 |
220 std::vector<Rect> RenderTextLinux::GetSubstringBounds(const ui::Range& range) { | 192 std::vector<Rect> RenderTextLinux::GetSubstringBounds(const ui::Range& range) { |
221 DCHECK_LE(range.GetMax(), text().length()); | 193 DCHECK_LE(range.GetMax(), text().length()); |
222 if (range.is_empty()) | 194 if (range.is_empty()) |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 int glyph_index) const { | 473 int glyph_index) const { |
502 return LayoutIndexToTextIndex(run->item->offset + | 474 return LayoutIndexToTextIndex(run->item->offset + |
503 run->glyphs->log_clusters[glyph_index]); | 475 run->glyphs->log_clusters[glyph_index]); |
504 } | 476 } |
505 | 477 |
506 RenderText* RenderText::CreateInstance() { | 478 RenderText* RenderText::CreateInstance() { |
507 return new RenderTextLinux; | 479 return new RenderTextLinux; |
508 } | 480 } |
509 | 481 |
510 } // namespace gfx | 482 } // namespace gfx |
OLD | NEW |