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 #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 Loading... | |
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)) { |
xji
2011/12/07 19:52:26
thanks for making those changes.
| |
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 Loading... | |
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)) { | |
xji
2011/12/07 19:52:26
Ah, sorry that I just realized does this (using gl
Alexei Svitkine (slow)
2011/12/07 19:59:25
I am not sure how its possible to render a single
xji
2011/12/07 23:17:42
I am not sure about this part.
I remember that you
behdad_google
2011/12/07 23:35:05
Yeah, this is broken. That's why I suggested that
xji
2011/12/08 00:27:56
Does pango handle using 2 different foregrounds (n
xji
2011/12/08 00:27:56
'fi' ligature is different. it is one glyph, but 2
behdad_google
2011/12/14 06:29:11
No. Pango doesn't by itself. But if you try sele
| |
316 style = i; | |
317 break; | |
318 } | |
319 } | |
320 DCHECK_GE(style, 0); | |
xji
2011/12/07 19:52:26
nit: do you want to dcheck "style < style_ranges.u
Alexei Svitkine (slow)
2011/12/07 19:59:25
It's not possible given the above loop.
xji
2011/12/07 23:17:42
Ah, you right.
| |
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 if (!IndexInRange(style_ranges_utf8[style], glyph_byte_index)) { | |
xji
2011/12/07 19:52:26
same question for whether glyph's style set works
| |
345 renderer.SetForegroundColor(styles[style].foreground); | |
346 renderer.DrawPosText(&pos[start], &glyphs[start], i - start); | |
347 if (styles[style].underline || styles[style].strike) { | |
348 renderer.DrawDecorations(start_x, y, glyph_x - start_x, | |
349 styles[style].underline, | |
350 styles[style].strike); | |
351 } | |
352 | |
353 style += style_increment; | |
354 start = i; | |
355 start_x = glyph_x; | |
356 } | |
357 } | |
358 | |
359 // Draw the remaining glyphs. | |
360 renderer.SetForegroundColor(styles[style].foreground); | |
361 renderer.DrawPosText(&pos[start], &glyphs[start], glyph_count - start); | |
362 if (styles[style].underline || styles[style].strike) { | |
363 renderer.DrawDecorations(start_x, y, glyph_x - start_x, | |
364 styles[style].underline, | |
365 styles[style].strike); | |
366 } | |
367 | |
368 x = glyph_x; | |
369 } | |
284 } | 370 } |
285 | 371 |
286 size_t RenderTextLinux::IndexOfAdjacentGrapheme(size_t index, bool next) { | 372 size_t RenderTextLinux::IndexOfAdjacentGrapheme(size_t index, bool next) { |
287 EnsureLayout(); | 373 EnsureLayout(); |
288 return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next); | 374 return Utf16IndexOfAdjacentGrapheme(Utf16IndexToUtf8Index(index), next); |
289 } | 375 } |
290 | 376 |
291 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { | 377 GSList* RenderTextLinux::GetRunContainingPosition(size_t position) const { |
292 GSList* run = current_line_->runs; | 378 GSList* run = current_line_->runs; |
293 while (run) { | 379 while (run) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 size_t caret = selection.caret_pos(); | 459 size_t caret = selection.caret_pos(); |
374 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); | 460 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); |
375 GSList* run = GetRunContainingPosition(caret); | 461 GSList* run = GetRunContainingPosition(caret); |
376 DCHECK(run); | 462 DCHECK(run); |
377 | 463 |
378 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data); | 464 PangoLayoutRun* layout_run = reinterpret_cast<PangoLayoutRun*>(run->data); |
379 PangoItem* item = layout_run->item; | 465 PangoItem* item = layout_run->item; |
380 size_t run_start = Utf8IndexToUtf16Index(item->offset); | 466 size_t run_start = Utf8IndexToUtf16Index(item->offset); |
381 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); | 467 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); |
382 | 468 |
383 if (item->analysis.level % 2 == 0) { // LTR run. | 469 if (IsRunLTR(item)) { |
384 if (caret_placement == SelectionModel::TRAILING) | 470 if (caret_placement == SelectionModel::TRAILING) |
385 return SelectionModel(caret, caret, SelectionModel::LEADING); | 471 return SelectionModel(caret, caret, SelectionModel::LEADING); |
386 else if (caret > run_start) { | 472 else if (caret > run_start) { |
387 caret = GetIndexOfPreviousGrapheme(caret); | 473 caret = GetIndexOfPreviousGrapheme(caret); |
388 return SelectionModel(caret, caret, SelectionModel::LEADING); | 474 return SelectionModel(caret, caret, SelectionModel::LEADING); |
389 } | 475 } |
390 } else { // RTL run. | 476 } else { // RTL run. |
391 if (caret_placement == SelectionModel::LEADING) { | 477 if (caret_placement == SelectionModel::LEADING) { |
392 size_t cursor = GetIndexOfNextGrapheme(caret); | 478 size_t cursor = GetIndexOfNextGrapheme(caret); |
393 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | 479 return SelectionModel(cursor, caret, SelectionModel::TRAILING); |
394 } else if (selection.selection_end() < run_end) { | 480 } else if (selection.selection_end() < run_end) { |
395 caret = GetIndexOfNextGrapheme(caret); | 481 caret = GetIndexOfNextGrapheme(caret); |
396 size_t cursor = GetIndexOfNextGrapheme(caret); | 482 size_t cursor = GetIndexOfNextGrapheme(caret); |
397 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | 483 return SelectionModel(cursor, caret, SelectionModel::TRAILING); |
398 } | 484 } |
399 } | 485 } |
400 | 486 |
401 // The character is at the begin of its run; advance to the previous visual | 487 // The character is at the begin of its run; advance to the previous visual |
402 // run. | 488 // run. |
403 PangoLayoutRun* prev_run = GetPreviousRun(layout_run); | 489 PangoLayoutRun* prev_run = GetPreviousRun(layout_run); |
404 if (!prev_run) | 490 if (!prev_run) |
405 return LeftEndSelectionModel(); | 491 return LeftEndSelectionModel(); |
406 | 492 |
407 item = prev_run->item; | 493 item = prev_run->item; |
408 return (item->analysis.level % 2) ? FirstSelectionModelInsideRun(item) : | 494 return IsRunLTR(item) ? LastSelectionModelInsideRun(item) : |
409 LastSelectionModelInsideRun(item); | 495 FirstSelectionModelInsideRun(item); |
410 } | 496 } |
411 | 497 |
412 // Assume caret_pos in |current| is n, 'l' represents leading in | 498 // Assume caret_pos in |current| is n, 'l' represents leading in |
413 // caret_placement and 't' represents trailing in caret_placement. Following | 499 // caret_placement and 't' represents trailing in caret_placement. Following |
414 // is the calculation from (caret_pos, caret_placement) in |current| to | 500 // is the calculation from (caret_pos, caret_placement) in |current| to |
415 // (selection_end, caret_pos, caret_placement) when moving cursor right by | 501 // (selection_end, caret_pos, caret_placement) when moving cursor right by |
416 // one grapheme (for simplicity, assume each grapheme is one character). | 502 // one grapheme (for simplicity, assume each grapheme is one character). |
417 // If n is in LTR run, | 503 // If n is in LTR run, |
418 // (n, l) ---> (n+1, n, t). | 504 // (n, l) ---> (n+1, n, t). |
419 // (n, t) ---> (n+2, n+1, t) if n is inside run (not at boundary). | 505 // (n, t) ---> (n+2, n+1, t) if n is inside run (not at boundary). |
(...skipping 11 matching lines...) Expand all Loading... | |
431 const SelectionModel& selection) { | 517 const SelectionModel& selection) { |
432 size_t caret = selection.caret_pos(); | 518 size_t caret = selection.caret_pos(); |
433 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); | 519 SelectionModel::CaretPlacement caret_placement = selection.caret_placement(); |
434 GSList* run = GetRunContainingPosition(caret); | 520 GSList* run = GetRunContainingPosition(caret); |
435 DCHECK(run); | 521 DCHECK(run); |
436 | 522 |
437 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 523 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
438 size_t run_start = Utf8IndexToUtf16Index(item->offset); | 524 size_t run_start = Utf8IndexToUtf16Index(item->offset); |
439 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); | 525 size_t run_end = Utf8IndexToUtf16Index(item->offset + item->length); |
440 | 526 |
441 if (item->analysis.level % 2 == 0) { // LTR run. | 527 if (IsRunLTR(item)) { |
442 if (caret_placement == SelectionModel::LEADING) { | 528 if (caret_placement == SelectionModel::LEADING) { |
443 size_t cursor = GetIndexOfNextGrapheme(caret); | 529 size_t cursor = GetIndexOfNextGrapheme(caret); |
444 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | 530 return SelectionModel(cursor, caret, SelectionModel::TRAILING); |
445 } else if (selection.selection_end() < run_end) { | 531 } else if (selection.selection_end() < run_end) { |
446 caret = GetIndexOfNextGrapheme(caret); | 532 caret = GetIndexOfNextGrapheme(caret); |
447 size_t cursor = GetIndexOfNextGrapheme(caret); | 533 size_t cursor = GetIndexOfNextGrapheme(caret); |
448 return SelectionModel(cursor, caret, SelectionModel::TRAILING); | 534 return SelectionModel(cursor, caret, SelectionModel::TRAILING); |
449 } | 535 } |
450 } else { // RTL run. | 536 } else { // RTL run. |
451 if (caret_placement == SelectionModel::TRAILING) | 537 if (caret_placement == SelectionModel::TRAILING) |
452 return SelectionModel(caret, caret, SelectionModel::LEADING); | 538 return SelectionModel(caret, caret, SelectionModel::LEADING); |
453 else if (caret > run_start) { | 539 else if (caret > run_start) { |
454 caret = GetIndexOfPreviousGrapheme(caret); | 540 caret = GetIndexOfPreviousGrapheme(caret); |
455 return SelectionModel(caret, caret, SelectionModel::LEADING); | 541 return SelectionModel(caret, caret, SelectionModel::LEADING); |
456 } | 542 } |
457 } | 543 } |
458 | 544 |
459 // The character is at the end of its run; advance to the next visual run. | 545 // The character is at the end of its run; advance to the next visual run. |
460 GSList* next_run = run->next; | 546 GSList* next_run = run->next; |
461 if (!next_run) | 547 if (!next_run) |
462 return RightEndSelectionModel(); | 548 return RightEndSelectionModel(); |
463 | 549 |
464 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item; | 550 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item; |
465 return (item->analysis.level % 2) ? LastSelectionModelInsideRun(item) : | 551 return IsRunLTR(item) ? FirstSelectionModelInsideRun(item) : |
466 FirstSelectionModelInsideRun(item); | 552 LastSelectionModelInsideRun(item); |
467 } | 553 } |
468 | 554 |
469 SelectionModel RenderTextLinux::LeftSelectionModelByWord( | 555 SelectionModel RenderTextLinux::LeftSelectionModelByWord( |
470 const SelectionModel& selection) { | 556 const SelectionModel& selection) { |
471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 557 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
472 bool success = iter.Init(); | 558 bool success = iter.Init(); |
473 DCHECK(success); | 559 DCHECK(success); |
474 if (!success) | 560 if (!success) |
475 return selection; | 561 return selection; |
476 | 562 |
477 SelectionModel left_end = LeftEndSelectionModel(); | 563 SelectionModel left_end = LeftEndSelectionModel(); |
478 SelectionModel left(selection); | 564 SelectionModel left(selection); |
479 while (!left.Equals(left_end)) { | 565 while (!left.Equals(left_end)) { |
480 left = LeftSelectionModel(left); | 566 left = LeftSelectionModel(left); |
481 size_t caret = left.caret_pos(); | 567 size_t caret = left.caret_pos(); |
482 GSList* run = GetRunContainingPosition(caret); | 568 GSList* run = GetRunContainingPosition(caret); |
483 DCHECK(run); | 569 DCHECK(run); |
484 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 570 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
485 size_t cursor = left.selection_end(); | 571 size_t cursor = left.selection_end(); |
486 if (item->analysis.level % 2 == 0) { // LTR run. | 572 if (IsRunLTR(item)) { |
487 if (iter.IsStartOfWord(cursor)) | 573 if (iter.IsStartOfWord(cursor)) |
488 return left; | 574 return left; |
489 } else { // RTL run. | 575 } else { // RTL run. |
490 if (iter.IsEndOfWord(cursor)) | 576 if (iter.IsEndOfWord(cursor)) |
491 return left; | 577 return left; |
492 } | 578 } |
493 } | 579 } |
494 | 580 |
495 return left_end; | 581 return left_end; |
496 } | 582 } |
497 | 583 |
498 SelectionModel RenderTextLinux::RightSelectionModelByWord( | 584 SelectionModel RenderTextLinux::RightSelectionModelByWord( |
499 const SelectionModel& selection) { | 585 const SelectionModel& selection) { |
500 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 586 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
501 bool success = iter.Init(); | 587 bool success = iter.Init(); |
502 DCHECK(success); | 588 DCHECK(success); |
503 if (!success) | 589 if (!success) |
504 return selection; | 590 return selection; |
505 | 591 |
506 SelectionModel right_end = RightEndSelectionModel(); | 592 SelectionModel right_end = RightEndSelectionModel(); |
507 SelectionModel right(selection); | 593 SelectionModel right(selection); |
508 while (!right.Equals(right_end)) { | 594 while (!right.Equals(right_end)) { |
509 right = RightSelectionModel(right); | 595 right = RightSelectionModel(right); |
510 size_t caret = right.caret_pos(); | 596 size_t caret = right.caret_pos(); |
511 GSList* run = GetRunContainingPosition(caret); | 597 GSList* run = GetRunContainingPosition(caret); |
512 DCHECK(run); | 598 DCHECK(run); |
513 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 599 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
514 size_t cursor = right.selection_end(); | 600 size_t cursor = right.selection_end(); |
515 if (item->analysis.level % 2 == 0) { // LTR run. | 601 if (IsRunLTR(item)) { |
516 if (iter.IsEndOfWord(cursor)) | 602 if (iter.IsEndOfWord(cursor)) |
517 return right; | 603 return right; |
518 } else { // RTL run. | 604 } else { // RTL run. |
519 if (iter.IsStartOfWord(cursor)) | 605 if (iter.IsStartOfWord(cursor)) |
520 return right; | 606 return right; |
521 } | 607 } |
522 } | 608 } |
523 | 609 |
524 return right_end; | 610 return right_end; |
525 } | 611 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 } | 769 } |
684 | 770 |
685 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) { | 771 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) { |
686 if (selection_visual_bounds_.empty()) | 772 if (selection_visual_bounds_.empty()) |
687 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(), | 773 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(), |
688 &selection_visual_bounds_); | 774 &selection_visual_bounds_); |
689 *bounds = selection_visual_bounds_; | 775 *bounds = selection_visual_bounds_; |
690 } | 776 } |
691 | 777 |
692 } // namespace gfx | 778 } // namespace gfx |
OLD | NEW |