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

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
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (index > text().length()) 383 if (index > text().length())
288 return text().length(); 384 return text().length();
289 EnsureLayout(); 385 EnsureLayout();
290 return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next); 386 return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next);
291 } 387 }
292 388
293 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { 389 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 size_t caret = selection.caret_pos(); 471 size_t caret = selection.caret_pos();
376 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); 472 SelectionModel::CaretPlacement caret_placement = selection.caret_placement();
377 GSList* run = GetRunContainingPosition(caret); 473 GSList* run = GetRunContainingPosition(caret);
378 DCHECK(run); 474 DCHECK(run);
379 475
380 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data); 476 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data);
381 PangoItem* item = layout_run->item; 477 PangoItem* item = layout_run->item;
382 size_t run_start = Utf8IndexToUtf16Index(item->offset); 478 size_t run_start = Utf8IndexToUtf16Index(item->offset);
383 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); 479 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length);
384 480
385 if (item->analysis.level % 2 == 0) { // LTR run. 481 if (IsRunLTR(item)) {
386 if (caret_placement == SelectionModel::TRAILING) 482 if (caret_placement == SelectionModel::TRAILING)
387 return SelectionModel(caret, caret, SelectionModel::LEADING); 483 return SelectionModel(caret, caret, SelectionModel::LEADING);
388 else if (caret > run_start) { 484 else if (caret > run_start) {
389 caret = GetIndexOfPreviousGrapheme(caret); 485 caret = GetIndexOfPreviousGrapheme(caret);
390 return SelectionModel(caret, caret, SelectionModel::LEADING); 486 return SelectionModel(caret, caret, SelectionModel::LEADING);
391 } 487 }
392 } else { // RTL run. 488 } else { // RTL run.
393 if (caret_placement == SelectionModel::LEADING) { 489 if (caret_placement == SelectionModel::LEADING) {
394 size_t cursor = GetIndexOfNextGrapheme(caret); 490 size_t cursor = GetIndexOfNextGrapheme(caret);
395 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 491 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
396 } else if (selection.selection_end() < run_end) { 492 } else if (selection.selection_end() < run_end) {
397 caret = GetIndexOfNextGrapheme(caret); 493 caret = GetIndexOfNextGrapheme(caret);
398 size_t cursor = GetIndexOfNextGrapheme(caret); 494 size_t cursor = GetIndexOfNextGrapheme(caret);
399 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 495 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
400 } 496 }
401 } 497 }
402 498
403 // The character is at the begin of its run; advance to the previous visual 499 // The character is at the begin of its run; advance to the previous visual
404 // run. 500 // run.
405 PangoLayoutRun* prev_run = GetPreviousRun(layout_run); 501 PangoLayoutRun* prev_run = GetPreviousRun(layout_run);
406 if (!prev_run) 502 if (!prev_run)
407 return LeftEndSelectionModel(); 503 return LeftEndSelectionModel();
408 504
409 item = prev_run->item; 505 item = prev_run->item;
410 return (item->analysis.level % 2) ? FirstSelectionModelInsideRun(item) : 506 return IsRunLTR(item) ? LastSelectionModelInsideRun(item) :
411 LastSelectionModelInsideRun(item); 507 FirstSelectionModelInsideRun(item);
412 } 508 }
413 509
414 // Assume caret_pos in |current| is n, 'l' represents leading in 510 // Assume caret_pos in |current| is n, 'l' represents leading in
415 // caret_placement and 't' represents trailing in caret_placement. Following 511 // caret_placement and 't' represents trailing in caret_placement. Following
416 // is the calculation from (caret_pos, caret_placement) in |current| to 512 // is the calculation from (caret_pos, caret_placement) in |current| to
417 // (selection_end, caret_pos, caret_placement) when moving cursor right by 513 // (selection_end, caret_pos, caret_placement) when moving cursor right by
418 // one grapheme (for simplicity, assume each grapheme is one character). 514 // one grapheme (for simplicity, assume each grapheme is one character).
419 // If n is in LTR run, 515 // If n is in LTR run,
420 // (n, l) ---> (n+1, n, t). 516 // (n, l) ---> (n+1, n, t).
421 // (n, t) ---> (n+2, n+1, t) if n is inside run (not at boundary). 517 // (n, t) ---> (n+2, n+1, t) if n is inside run (not at boundary).
(...skipping 11 matching lines...) Expand all
433 const SelectionModel& selection) { 529 const SelectionModel& selection) {
434 size_t caret = selection.caret_pos(); 530 size_t caret = selection.caret_pos();
435 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); 531 SelectionModel::CaretPlacement caret_placement = selection.caret_placement();
436 GSList* run = GetRunContainingPosition(caret); 532 GSList* run = GetRunContainingPosition(caret);
437 DCHECK(run); 533 DCHECK(run);
438 534
439 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; 535 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item;
440 size_t run_start = Utf8IndexToUtf16Index(item->offset); 536 size_t run_start = Utf8IndexToUtf16Index(item->offset);
441 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); 537 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length);
442 538
443 if (item->analysis.level % 2 == 0) { // LTR run. 539 if (IsRunLTR(item)) {
444 if (caret_placement == SelectionModel::LEADING) { 540 if (caret_placement == SelectionModel::LEADING) {
445 size_t cursor = GetIndexOfNextGrapheme(caret); 541 size_t cursor = GetIndexOfNextGrapheme(caret);
446 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 542 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
447 } else if (selection.selection_end() < run_end) { 543 } else if (selection.selection_end() < run_end) {
448 caret = GetIndexOfNextGrapheme(caret); 544 caret = GetIndexOfNextGrapheme(caret);
449 size_t cursor = GetIndexOfNextGrapheme(caret); 545 size_t cursor = GetIndexOfNextGrapheme(caret);
450 return SelectionModel(cursor, caret, SelectionModel::TRAILING); 546 return SelectionModel(cursor, caret, SelectionModel::TRAILING);
451 } 547 }
452 } else { // RTL run. 548 } else { // RTL run.
453 if (caret_placement == SelectionModel::TRAILING) 549 if (caret_placement == SelectionModel::TRAILING)
454 return SelectionModel(caret, caret, SelectionModel::LEADING); 550 return SelectionModel(caret, caret, SelectionModel::LEADING);
455 else if (caret > run_start) { 551 else if (caret > run_start) {
456 caret = GetIndexOfPreviousGrapheme(caret); 552 caret = GetIndexOfPreviousGrapheme(caret);
457 return SelectionModel(caret, caret, SelectionModel::LEADING); 553 return SelectionModel(caret, caret, SelectionModel::LEADING);
458 } 554 }
459 } 555 }
460 556
461 // The character is at the end of its run; advance to the next visual run. 557 // The character is at the end of its run; advance to the next visual run.
462 GSList* next_run = run->next; 558 GSList* next_run = run->next;
463 if (!next_run) 559 if (!next_run)
464 return RightEndSelectionModel(); 560 return RightEndSelectionModel();
465 561
466 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item; 562 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item;
467 return (item->analysis.level % 2) ? LastSelectionModelInsideRun(item) : 563 return IsRunLTR(item) ? FirstSelectionModelInsideRun(item) :
468 FirstSelectionModelInsideRun(item); 564 LastSelectionModelInsideRun(item);
469 } 565 }
470 566
471 SelectionModel RenderTextLinux::LeftSelectionModelByWord( 567 SelectionModel RenderTextLinux::LeftSelectionModelByWord(
472 const SelectionModel& selection) { 568 const SelectionModel& selection) {
473 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 569 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
474 bool success = iter.Init(); 570 bool success = iter.Init();
475 DCHECK(success); 571 DCHECK(success);
476 if (!success) 572 if (!success)
477 return selection; 573 return selection;
478 574
479 SelectionModel left_end = LeftEndSelectionModel(); 575 SelectionModel left_end = LeftEndSelectionModel();
480 SelectionModel left(selection); 576 SelectionModel left(selection);
481 while (!left.Equals(left_end)) { 577 while (!left.Equals(left_end)) {
482 left = LeftSelectionModel(left); 578 left = LeftSelectionModel(left);
483 size_t caret = left.caret_pos(); 579 size_t caret = left.caret_pos();
484 GSList* run = GetRunContainingPosition(caret); 580 GSList* run = GetRunContainingPosition(caret);
485 DCHECK(run); 581 DCHECK(run);
486 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; 582 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item;
487 size_t cursor = left.selection_end(); 583 size_t cursor = left.selection_end();
488 if (item->analysis.level % 2 == 0) { // LTR run. 584 if (IsRunLTR(item)) {
489 if (iter.IsStartOfWord(cursor)) 585 if (iter.IsStartOfWord(cursor))
490 return left; 586 return left;
491 } else { // RTL run. 587 } else { // RTL run.
492 if (iter.IsEndOfWord(cursor)) 588 if (iter.IsEndOfWord(cursor))
493 return left; 589 return left;
494 } 590 }
495 } 591 }
496 592
497 return left_end; 593 return left_end;
498 } 594 }
499 595
500 SelectionModel RenderTextLinux::RightSelectionModelByWord( 596 SelectionModel RenderTextLinux::RightSelectionModelByWord(
501 const SelectionModel& selection) { 597 const SelectionModel& selection) {
502 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); 598 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD);
503 bool success = iter.Init(); 599 bool success = iter.Init();
504 DCHECK(success); 600 DCHECK(success);
505 if (!success) 601 if (!success)
506 return selection; 602 return selection;
507 603
508 SelectionModel right_end = RightEndSelectionModel(); 604 SelectionModel right_end = RightEndSelectionModel();
509 SelectionModel right(selection); 605 SelectionModel right(selection);
510 while (!right.Equals(right_end)) { 606 while (!right.Equals(right_end)) {
511 right = RightSelectionModel(right); 607 right = RightSelectionModel(right);
512 size_t caret = right.caret_pos(); 608 size_t caret = right.caret_pos();
513 GSList* run = GetRunContainingPosition(caret); 609 GSList* run = GetRunContainingPosition(caret);
514 DCHECK(run); 610 DCHECK(run);
515 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; 611 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item;
516 size_t cursor = right.selection_end(); 612 size_t cursor = right.selection_end();
517 if (item->analysis.level % 2 == 0) { // LTR run. 613 if (IsRunLTR(item)) {
518 if (iter.IsEndOfWord(cursor)) 614 if (iter.IsEndOfWord(cursor))
519 return right; 615 return right;
520 } else { // RTL run. 616 } else { // RTL run.
521 if (iter.IsStartOfWord(cursor)) 617 if (iter.IsStartOfWord(cursor))
522 return right; 618 return right;
523 } 619 }
524 } 620 }
525 621
526 return right_end; 622 return right_end;
527 } 623 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 781 }
686 782
687 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) { 783 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) {
688 if (selection_visual_bounds_.empty()) 784 if (selection_visual_bounds_.empty())
689 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(), 785 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(),
690 &selection_visual_bounds_); 786 &selection_visual_bounds_);
691 *bounds = selection_visual_bounds_; 787 *bounds = selection_visual_bounds_;
692 } 788 }
693 789
694 } // namespace gfx 790 } // namespace gfx
OLDNEW
« no previous file with comments | « 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