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

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

Issue 8725002: Draw text via Skia in RenderTextLinux. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years 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) 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 #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 <vector>
9 10
10 #include "base/i18n/break_iterator.h" 11 #include "base/i18n/break_iterator.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "ui/gfx/canvas_skia.h" 13 #include "ui/gfx/canvas_skia.h"
14 #include "ui/gfx/font.h"
13 #include "ui/gfx/pango_util.h" 15 #include "ui/gfx/pango_util.h"
14 #include "unicode/uchar.h" 16 #include "unicode/uchar.h"
15 #include "unicode/ustring.h" 17 #include "unicode/ustring.h"
16 18
17 namespace { 19 namespace {
18 20
19 // TODO(xji): instead of converting each R or G or B from 8-bit to 16-bit, 21 // TODO(xji): instead of converting each R or G or B from 8-bit to 16-bit,
20 // it should also massage A in the conversion. 22 // it should also massage A in the conversion.
21 int ConvertColorFrom8BitTo16Bit(int c) { 23 int ConvertColorFrom8BitTo16Bit(int c) {
22 return (c << 8) + c; 24 return (c << 8) + c;
23 } 25 }
24 26
27 // Returns whether the given Pango item is Left to Right.
28 bool IsRunLTR(const PangoItem* item) {
29 return (item->analysis.level & 1) == 0;
30 }
31
32 // Checks whether |range| contains |index|. This is not the same as calling
33 // |range.Contains(ui::Range(index))| - as that would return true when
34 // |index| == |range.end()|.
35 bool IndexInRange(const ui::Range& range, size_t index) {
36 return index >= range.start() && index < range.end();
37 }
38
25 } // namespace 39 } // namespace
26 40
27 // TODO(xji): index saved in upper layer is utf16 index. Pango uses utf8 index. 41 // TODO(xji): index saved in upper layer is utf16 index. Pango uses utf8 index.
28 // Since caret_pos is used internally, we could save utf8 index for caret_pos 42 // Since caret_pos is used internally, we could save utf8 index for caret_pos
29 // to avoid conversion. 43 // to avoid conversion.
30 44
31 namespace gfx { 45 namespace gfx {
32 46
33 RenderTextLinux::RenderTextLinux() 47 RenderTextLinux::RenderTextLinux()
34 : layout_(NULL), 48 : layout_(NULL),
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DCHECK(break_type == WORD_BREAK); 161 DCHECK(break_type == WORD_BREAK);
148 return RightSelectionModelByWord(current); 162 return RightSelectionModelByWord(current);
149 } 163 }
150 164
151 SelectionModel RenderTextLinux::LeftEndSelectionModel() { 165 SelectionModel RenderTextLinux::LeftEndSelectionModel() {
152 if (GetTextDirection() == base::i18n::RIGHT_TO_LEFT) { 166 if (GetTextDirection() == base::i18n::RIGHT_TO_LEFT) {
153 if (current_line_->runs) { 167 if (current_line_->runs) {
154 PangoLayoutRun* first_visual_run = 168 PangoLayoutRun* first_visual_run =
155 reinterpret_cast<PangoLayoutRun*>(current_line_->runs->data); 169 reinterpret_cast<PangoLayoutRun*>(current_line_->runs->data);
156 PangoItem* item = first_visual_run->item; 170 PangoItem* item = first_visual_run->item;
157 if (item->analysis.level % 2 == 0) { // LTR. 171 if (IsRunLTR(item)) {
158 size_t caret = Utf8IndexToUtf16Index(item->offset); 172 size_t caret = Utf8IndexToUtf16Index(item->offset);
159 return SelectionModel(text().length(), caret, SelectionModel::LEADING); 173 return SelectionModel(text().length(), caret, SelectionModel::LEADING);
160 } else { // RTL. 174 } else { // RTL.
161 size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length, 175 size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length,
162 false); 176 false);
163 return SelectionModel(text().length(), caret, SelectionModel::TRAILING); 177 return SelectionModel(text().length(), caret, SelectionModel::TRAILING);
164 } 178 }
165 } 179 }
166 } 180 }
167 return SelectionModel(0, 0, SelectionModel::LEADING); 181 return SelectionModel(0, 0, SelectionModel::LEADING);
168 } 182 }
169 183
170 SelectionModel RenderTextLinux::RightEndSelectionModel() { 184 SelectionModel RenderTextLinux::RightEndSelectionModel() {
171 if (GetTextDirection() == base::i18n::LEFT_TO_RIGHT) { 185 if (GetTextDirection() == base::i18n::LEFT_TO_RIGHT) {
172 PangoLayoutRun* last_visual_run = GetLastRun(); 186 PangoLayoutRun* last_visual_run = GetLastRun();
173 if (last_visual_run) { 187 if (last_visual_run) {
174 PangoItem* item = last_visual_run->item; 188 PangoItem* item = last_visual_run->item;
175 if (item->analysis.level % 2 == 0) { // LTR. 189 if (IsRunLTR(item)) {
176 size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length, 190 size_t caret = Utf16IndexOfAdjacentGrapheme(item->offset + item->length,
177 false); 191 false);
178 return SelectionModel(text().length(), caret, SelectionModel::TRAILING); 192 return SelectionModel(text().length(), caret, SelectionModel::TRAILING);
179 } else { // RTL. 193 } else { // RTL.
180 size_t caret = Utf8IndexToUtf16Index(item->offset); 194 size_t caret = Utf8IndexToUtf16Index(item->offset);
181 return SelectionModel(text().length(), caret, SelectionModel::LEADING); 195 return SelectionModel(text().length(), caret, SelectionModel::LEADING);
182 } 196 }
183 } 197 }
184 } 198 }
185 return SelectionModel(0, 0, SelectionModel::LEADING); 199 return SelectionModel(0, 0, SelectionModel::LEADING);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 pango_layout_line_ref(current_line_); 267 pango_layout_line_ref(current_line_);
254 268
255 pango_layout_get_log_attrs(layout_, &log_attrs_, &num_log_attrs_); 269 pango_layout_get_log_attrs(layout_, &log_attrs_, &num_log_attrs_);
256 270
257 layout_text_ = pango_layout_get_text(layout_); 271 layout_text_ = pango_layout_get_text(layout_);
258 layout_text_len_ = strlen(layout_text_); 272 layout_text_len_ = strlen(layout_text_);
259 } 273 }
260 } 274 }
261 275
262 void RenderTextLinux::DrawVisualText(Canvas* canvas) { 276 void RenderTextLinux::DrawVisualText(Canvas* canvas) {
263 Rect bounds(display_rect()); 277 DCHECK(layout_);
264 278
265 // Clip the canvas to the text display area. 279 Point offset(GetOriginForSkiaDrawing());
266 SkCanvas* canvas_skia = canvas->GetSkCanvas(); 280 SkScalar x = SkIntToScalar(offset.x());
281 SkScalar y = SkIntToScalar(offset.y());
267 282
268 skia::ScopedPlatformPaint scoped_platform_paint(canvas_skia); 283 std::vector<SkPoint> pos;
269 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); 284 std::vector<uint16> glyphs;
270 cairo_save(cr);
271 cairo_rectangle(cr, bounds.x(), bounds.y(), bounds.width(), bounds.height());
272 cairo_clip(cr);
273 285
274 int text_width, text_height; 286 StyleRanges styles(style_ranges());
275 pango_layout_get_pixel_size(layout_, &text_width, &text_height); 287 ApplyCompositionAndSelectionStyles(&styles);
276 Point offset(ToViewPoint(Point()));
277 // Vertically centered.
278 int text_y = offset.y() + ((bounds.height() - text_height) / 2);
279 // TODO(xji): need to use SkCanvas->drawPosText() for gpu acceleration.
280 cairo_move_to(cr, offset.x(), text_y);
281 pango_cairo_show_layout(cr, layout_);
282 288
283 cairo_restore(cr); 289 // Pre-calculate UTF8 indices from UTF16 indices.
290 // TODO(asvitkine): Can we cache these?
291 std::vector<ui::Range> style_ranges_utf8;
292 style_ranges_utf8.reserve(styles.size());
293 size_t start_index = 0;
294 for (size_t i = 0; i < styles.size(); ++i) {
295 size_t end_index = Utf16IndexToUtf8Index(styles[i].range.end());
296 style_ranges_utf8.push_back(ui::Range(start_index, end_index));
297 start_index = end_index;
298 }
299
300 internal::SkiaTextRenderer renderer(canvas);
301 for (GSList* it = current_line_->runs; it; it = it->next) {
302 PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data);
303 int glyph_count = run->glyphs->num_glyphs;
304 if (glyph_count == 0)
305 continue;
306
307 size_t run_start = run->item->offset;
308 size_t first_glyph_byte_index = run_start + run->glyphs->log_clusters[0];
309 size_t style_increment = IsRunLTR(run->item) ? 1 : -1;
310
311 // Find the initial style for this run.
312 // TODO(asvitkine): Can we avoid looping here, e.g. by caching this per run?
313 int style = -1;
314 for (size_t i = 0; i < style_ranges_utf8.size(); ++i) {
315 if (IndexInRange(style_ranges_utf8[i], first_glyph_byte_index)) {
316 style = i;
317 break;
318 }
319 }
320 DCHECK_GE(style, 0);
321
322 PangoFontDescription* native_font =
323 pango_font_describe(run->item->analysis.font);
324 renderer.SetFont(gfx::Font(native_font));
325 pango_font_description_free(native_font);
326
327 SkScalar glyph_x = x;
328 SkScalar start_x = x;
329 int start = 0;
330
331 glyphs.resize(glyph_count);
332 pos.resize(glyph_count);
333
334 for (int i = 0; i < glyph_count; ++i) {
335 const PangoGlyphInfo& glyph = run->glyphs->glyphs[i];
336 glyphs[i] = static_cast<uint16>(glyph.glyph);
337 pos[i].set(glyph_x + PANGO_PIXELS(glyph.geometry.x_offset),
338 y + PANGO_PIXELS(glyph.geometry.y_offset));
339 glyph_x += PANGO_PIXELS(glyph.geometry.width);
340
341 // If this glyph is beyond the current style, draw the glyphs so far and
342 // advance to the next style.
343 size_t glyph_byte_index = run_start + run->glyphs->log_clusters[i];
344 DCHECK_GE(style, 0);
345 DCHECK_LT(style, static_cast<int>(styles.size()));
346 if (!IndexInRange(style_ranges_utf8[style], glyph_byte_index)) {
347 // TODO(asvitkine): For cases like "fi", where "fi" is a single glyph
348 // but can span multiple styles, Pango splits the
349 // styles evenly over the glyph. We can do this too by
350 // clipping and drawing the glyph several times.
351 renderer.SetForegroundColor(styles[style].foreground);
352 renderer.DrawPosText(&pos[start], &glyphs[start], i - start);
353 if (styles[style].underline || styles[style].strike) {
354 renderer.DrawDecorations(start_x, y, glyph_x - start_x,
355 styles[style].underline,
356 styles[style].strike);
357 }
358
359 start = i;
360 start_x = glyph_x;
361 // Loop to find the next style, in case the glyph spans multiple styles.
362 do {
363 style += style_increment;
364 } while (style >= 0 && style < static_cast<int>(styles.size()) &&
365 !IndexInRange(style_ranges_utf8[style], glyph_byte_index));
366 }
367 }
368
369 // Draw the remaining glyphs.
370 renderer.SetForegroundColor(styles[style].foreground);
371 renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start);
372 if (styles[style].underline || styles[style].strike) {
373 renderer.DrawDecorations(start_x, y, glyph_x - start_x,
374 styles[style].underline,
375 styles[style].strike);
376 }
377
378 x = glyph_x;
379 }
284 } 380 }
285 381
286 size_t RenderTextLinux::IndexOfAdjacentGrapheme(size_t index, bool next) { 382 size_t RenderTextLinux::IndexOfAdjacentGrapheme(size_t index, bool next) {
287 EnsureLayout(); 383 EnsureLayout();
288 return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next); 384 return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next);
289 } 385 }
290 386
291 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { 387 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const {
292 GSList* run = current_line_->runs; 388 GSList* run = current_line_->runs;
293 while (run) { 389 while (run) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 size_t caret = selection.caret_pos(); 469 size_t caret = selection.caret_pos();
374 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); 470 SelectionModel::CaretPlacement caret_placement = selection.caret_placement();
375 GSList* run = GetRunContainingPosition(caret); 471 GSList* run = GetRunContainingPosition(caret);
376 DCHECK(run); 472 DCHECK(run);
377 473
378 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data); 474 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data);
379 PangoItem* item = layout_run->item; 475 PangoItem* item = layout_run->item;
380 size_t run_start = Utf8IndexToUtf16Index(item->offset); 476 size_t run_start = Utf8IndexToUtf16Index(item->offset);
381 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); 477 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length);
382 478
383 if (item->analysis.level % 2 == 0) { // LTR run. 479 if (IsRunLTR(item)) {
384 if (caret_placement == SelectionModel::TRAILING) 480 if (caret_placement == SelectionModel::TRAILING)
385 return SelectionModel(caret, caret, SelectionModel::LEADING); 481 return SelectionModel(caret, caret, SelectionModel::LEADING);
386 else if (caret > run_start) { 482 else if (caret > run_start) {
387 caret = GetIndexOfPreviousGrapheme(caret); 483 caret = GetIndexOfPreviousGrapheme(caret);
388 return SelectionModel(caret, caret, SelectionModel::LEADING); 484 return SelectionModel(caret, caret, SelectionModel::LEADING);
389 } 485 }
390 } else { // RTL run. 486 } else { // RTL run.
391 if (caret_placement == SelectionModel::LEADING) { 487 if (caret_placement == SelectionModel::LEADING) {
392 size_t cursor = GetIndexOfNextGrapheme(caret); 488 size_t cursor = GetIndexOfNextGrapheme(caret);
393 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 489 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
394 } else if (selection.selection_end() < run_end) { 490 } else if (selection.selection_end() < run_end) {
395 caret = GetIndexOfNextGrapheme(caret); 491 caret = GetIndexOfNextGrapheme(caret);
396 size_t cursor = GetIndexOfNextGrapheme(caret); 492 size_t cursor = GetIndexOfNextGrapheme(caret);
397 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 493 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
398 } 494 }
399 } 495 }
400 496
401 // The character is at the begin of its run; advance to the previous visual 497 // The character is at the begin of its run; advance to the previous visual
402 // run. 498 // run.
403 PangoLayoutRun* prev_run = GetPreviousRun(layout_run); 499 PangoLayoutRun* prev_run = GetPreviousRun(layout_run);
404 if (!prev_run) 500 if (!prev_run)
405 return LeftEndSelectionModel(); 501 return LeftEndSelectionModel();
406 502
407 item = prev_run->item; 503 item = prev_run->item;
408 return (item->analysis.level % 2) ? FirstSelectionModelInsideRun(item) : 504 return IsRunLTR(item) ? LastSelectionModelInsideRun(item) :
409 LastSelectionModelInsideRun(item); 505 FirstSelectionModelInsideRun(item);
410 } 506 }
411 507
412 // Assume caret_pos in |current| is n, 'l' represents leading in 508 // Assume caret_pos in |current| is n, 'l' represents leading in
413 // caret_placement and 't' represents trailing in caret_placement. Following 509 // caret_placement and 't' represents trailing in caret_placement. Following
414 // is the calculation from (caret_pos, caret_placement) in |current| to 510 // is the calculation from (caret_pos, caret_placement) in |current| to
415 // (selection_end, caret_pos, caret_placement) when moving cursor right by 511 // (selection_end, caret_pos, caret_placement) when moving cursor right by
416 // one grapheme (for simplicity, assume each grapheme is one character). 512 // one grapheme (for simplicity, assume each grapheme is one character).
417 // If n is in LTR run, 513 // If n is in LTR run,
418 // (n, l) ---> (n+1, n, t). 514 // (n, l) ---> (n+1, n, t).
419 // (n, t) ---> (n+2, n+1, t) if n is inside run (not at boundary). 515 // (n, t) ---> (n+2, n+1, t) if n is inside run (not at boundary).
(...skipping 11 matching lines...) Expand all
431 const SelectionModel& selection) { 527 const SelectionModel& selection) {
432 size_t caret = selection.caret_pos(); 528 size_t caret = selection.caret_pos();
433 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); 529 SelectionModel::CaretPlacement caret_placement = selection.caret_placement();
434 GSList* run = GetRunContainingPosition(caret); 530 GSList* run = GetRunContainingPosition(caret);
435 DCHECK(run); 531 DCHECK(run);
436 532
437 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; 533 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item;
438 size_t run_start = Utf8IndexToUtf16Index(item->offset); 534 size_t run_start = Utf8IndexToUtf16Index(item->offset);
439 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); 535 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length);
440 536
441 if (item->analysis.level % 2 == 0) { // LTR run. 537 if (IsRunLTR(item)) {
442 if (caret_placement == SelectionModel::LEADING) { 538 if (caret_placement == SelectionModel::LEADING) {
443 size_t cursor = GetIndexOfNextGrapheme(caret); 539 size_t cursor = GetIndexOfNextGrapheme(caret);
444 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 540 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
445 } else if (selection.selection_end() < run_end) { 541 } else if (selection.selection_end() < run_end) {
446 caret = GetIndexOfNextGrapheme(caret); 542 caret = GetIndexOfNextGrapheme(caret);
447 size_t cursor = GetIndexOfNextGrapheme(caret); 543 size_t cursor = GetIndexOfNextGrapheme(caret);
448 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 544 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
449 } 545 }
450 } else { // RTL run. 546 } else { // RTL run.
451 if (caret_placement == SelectionModel::TRAILING) 547 if (caret_placement == SelectionModel::TRAILING)
452 return SelectionModel(caret, caret, SelectionModel::LEADING); 548 return SelectionModel(caret, caret, SelectionModel::LEADING);
453 else if (caret > run_start) { 549 else if (caret > run_start) {
454 caret = GetIndexOfPreviousGrapheme(caret); 550 caret = GetIndexOfPreviousGrapheme(caret);
455 return SelectionModel(caret, caret, SelectionModel::LEADING); 551 return SelectionModel(caret, caret, SelectionModel::LEADING);
456 } 552 }
457 } 553 }
458 554
459 // The character is at the end of its run; advance to the next visual run. 555 // The character is at the end of its run; advance to the next visual run.
460 GSList* next_run = run->next; 556 GSList* next_run = run->next;
461 if (!next_run) 557 if (!next_run)
462 return RightEndSelectionModel(); 558 return RightEndSelectionModel();
463 559
464 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item; 560 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item;
465 return (item->analysis.level % 2) ? LastSelectionModelInsideRun(item) : 561 return IsRunLTR(item) ? FirstSelectionModelInsideRun(item) :
466 FirstSelectionModelInsideRun(item); 562 LastSelectionModelInsideRun(item);
467 } 563 }
468 564
469 SelectionModel RenderTextLinux::LeftSelectionModelByWord( 565 SelectionModel RenderTextLinux::LeftSelectionModelByWord(
470 const SelectionModel& selection) { 566 const SelectionModel& selection) {
471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 567 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
472 bool success = iter.Init(); 568 bool success = iter.Init();
473 DCHECK(success); 569 DCHECK(success);
474 if (!success) 570 if (!success)
475 return selection; 571 return selection;
476 572
477 SelectionModel left_end = LeftEndSelectionModel(); 573 SelectionModel left_end = LeftEndSelectionModel();
478 SelectionModel left(selection); 574 SelectionModel left(selection);
479 while (!left.Equals(left_end)) { 575 while (!left.Equals(left_end)) {
480 left = LeftSelectionModel(left); 576 left = LeftSelectionModel(left);
481 size_t caret = left.caret_pos(); 577 size_t caret = left.caret_pos();
482 GSList* run = GetRunContainingPosition(caret); 578 GSList* run = GetRunContainingPosition(caret);
483 DCHECK(run); 579 DCHECK(run);
484 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; 580 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item;
485 size_t cursor = left.selection_end(); 581 size_t cursor = left.selection_end();
486 if (item->analysis.level % 2 == 0) { // LTR run. 582 if (IsRunLTR(item)) {
487 if (iter.IsStartOfWord(cursor)) 583 if (iter.IsStartOfWord(cursor))
488 return left; 584 return left;
489 } else { // RTL run. 585 } else { // RTL run.
490 if (iter.IsEndOfWord(cursor)) 586 if (iter.IsEndOfWord(cursor))
491 return left; 587 return left;
492 } 588 }
493 } 589 }
494 590
495 return left_end; 591 return left_end;
496 } 592 }
497 593
498 SelectionModel RenderTextLinux::RightSelectionModelByWord( 594 SelectionModel RenderTextLinux::RightSelectionModelByWord(
499 const SelectionModel& selection) { 595 const SelectionModel& selection) {
500 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 596 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
501 bool success = iter.Init(); 597 bool success = iter.Init();
502 DCHECK(success); 598 DCHECK(success);
503 if (!success) 599 if (!success)
504 return selection; 600 return selection;
505 601
506 SelectionModel right_end = RightEndSelectionModel(); 602 SelectionModel right_end = RightEndSelectionModel();
507 SelectionModel right(selection); 603 SelectionModel right(selection);
508 while (!right.Equals(right_end)) { 604 while (!right.Equals(right_end)) {
509 right = RightSelectionModel(right); 605 right = RightSelectionModel(right);
510 size_t caret = right.caret_pos(); 606 size_t caret = right.caret_pos();
511 GSList* run = GetRunContainingPosition(caret); 607 GSList* run = GetRunContainingPosition(caret);
512 DCHECK(run); 608 DCHECK(run);
513 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; 609 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item;
514 size_t cursor = right.selection_end(); 610 size_t cursor = right.selection_end();
515 if (item->analysis.level % 2 == 0) { // LTR run. 611 if (IsRunLTR(item)) {
516 if (iter.IsEndOfWord(cursor)) 612 if (iter.IsEndOfWord(cursor))
517 return right; 613 return right;
518 } else { // RTL run. 614 } else { // RTL run.
519 if (iter.IsStartOfWord(cursor)) 615 if (iter.IsStartOfWord(cursor))
520 return right; 616 return right;
521 } 617 }
522 } 618 }
523 619
524 return right_end; 620 return right_end;
525 } 621 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 779 }
684 780
685 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) { 781 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) {
686 if (selection_visual_bounds_.empty()) 782 if (selection_visual_bounds_.empty())
687 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(), 783 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(),
688 &selection_visual_bounds_); 784 &selection_visual_bounds_);
689 *bounds = selection_visual_bounds_; 785 *bounds = selection_visual_bounds_;
690 } 786 }
691 787
692 } // namespace gfx 788 } // namespace gfx
OLDNEW
« ui/gfx/render_text.cc ('K') | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698