| 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 | 9 |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 227 |
| 228 void RenderTextLinux::EnsureLayout() { | 228 void RenderTextLinux::EnsureLayout() { |
| 229 if (layout_ == NULL) { | 229 if (layout_ == NULL) { |
| 230 CanvasSkia canvas(display_rect().width(), display_rect().height(), false); | 230 CanvasSkia canvas(display_rect().width(), display_rect().height(), false); |
| 231 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas()); | 231 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas()); |
| 232 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); | 232 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); |
| 233 | 233 |
| 234 layout_ = pango_cairo_create_layout(cr); | 234 layout_ = pango_cairo_create_layout(cr); |
| 235 SetupPangoLayout( | 235 SetupPangoLayout( |
| 236 layout_, | 236 layout_, |
| 237 text(), | 237 GetObscuredText(), |
| 238 default_style().font, | 238 default_style().font, |
| 239 display_rect().width(), | 239 display_rect().width(), |
| 240 base::i18n::GetFirstStrongCharacterDirection(text()), | 240 base::i18n::GetFirstStrongCharacterDirection(text()), |
| 241 CanvasSkia::DefaultCanvasTextAlignment()); | 241 CanvasSkia::DefaultCanvasTextAlignment()); |
| 242 | 242 |
| 243 // No width set so that the x-axis position is relative to the start of the | 243 // No width set so that the x-axis position is relative to the start of the |
| 244 // text. ToViewPoint and ToTextPoint take care of the position conversion | 244 // text. ToViewPoint and ToTextPoint take care of the position conversion |
| 245 // between text space and view spaces. | 245 // between text space and view spaces. |
| 246 pango_layout_set_width(layout_, -1); | 246 pango_layout_set_width(layout_, -1); |
| 247 // TODO(xji): If RenderText will be used for displaying purpose, such as | 247 // TODO(xji): If RenderText will be used for displaying purpose, such as |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 if (!next_run) | 461 if (!next_run) |
| 462 return RightEndSelectionModel(); | 462 return RightEndSelectionModel(); |
| 463 | 463 |
| 464 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item; | 464 item = reinterpret_cast<PangoLayoutRun*>(next_run->data)->item; |
| 465 return (item->analysis.level % 2) ? LastSelectionModelInsideRun(item) : | 465 return (item->analysis.level % 2) ? LastSelectionModelInsideRun(item) : |
| 466 FirstSelectionModelInsideRun(item); | 466 FirstSelectionModelInsideRun(item); |
| 467 } | 467 } |
| 468 | 468 |
| 469 SelectionModel RenderTextLinux::LeftSelectionModelByWord( | 469 SelectionModel RenderTextLinux::LeftSelectionModelByWord( |
| 470 const SelectionModel& selection) { | 470 const SelectionModel& selection) { |
| 471 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 471 string16 txt = GetObscuredText(); |
| 472 base::i18n::BreakIterator iter(txt, base::i18n::BreakIterator::BREAK_WORD); |
| 472 bool success = iter.Init(); | 473 bool success = iter.Init(); |
| 473 DCHECK(success); | 474 DCHECK(success); |
| 474 if (!success) | 475 if (!success) |
| 475 return selection; | 476 return selection; |
| 476 | 477 |
| 477 SelectionModel left_end = LeftEndSelectionModel(); | 478 SelectionModel left_end = LeftEndSelectionModel(); |
| 478 SelectionModel left(selection); | 479 SelectionModel left(selection); |
| 479 while (!left.Equals(left_end)) { | 480 while (!left.Equals(left_end)) { |
| 480 left = LeftSelectionModel(left); | 481 left = LeftSelectionModel(left); |
| 481 size_t caret = left.caret_pos(); | 482 size_t caret = left.caret_pos(); |
| 482 GSList* run = GetRunContainingPosition(caret); | 483 GSList* run = GetRunContainingPosition(caret); |
| 483 DCHECK(run); | 484 DCHECK(run); |
| 484 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; | 485 PangoItem* item = reinterpret_cast<PangoLayoutRun*>(run->data)->item; |
| 485 size_t cursor = left.selection_end(); | 486 size_t cursor = left.selection_end(); |
| 486 if (item->analysis.level % 2 == 0) { // LTR run. | 487 if (item->analysis.level % 2 == 0) { // LTR run. |
| 487 if (iter.IsStartOfWord(cursor)) | 488 if (iter.IsStartOfWord(cursor)) |
| 488 return left; | 489 return left; |
| 489 } else { // RTL run. | 490 } else { // RTL run. |
| 490 if (iter.IsEndOfWord(cursor)) | 491 if (iter.IsEndOfWord(cursor)) |
| 491 return left; | 492 return left; |
| 492 } | 493 } |
| 493 } | 494 } |
| 494 | 495 |
| 495 return left_end; | 496 return left_end; |
| 496 } | 497 } |
| 497 | 498 |
| 498 SelectionModel RenderTextLinux::RightSelectionModelByWord( | 499 SelectionModel RenderTextLinux::RightSelectionModelByWord( |
| 499 const SelectionModel& selection) { | 500 const SelectionModel& selection) { |
| 500 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 501 string16 txt = GetObscuredText(); |
| 502 base::i18n::BreakIterator iter(txt, base::i18n::BreakIterator::BREAK_WORD); |
| 501 bool success = iter.Init(); | 503 bool success = iter.Init(); |
| 502 DCHECK(success); | 504 DCHECK(success); |
| 503 if (!success) | 505 if (!success) |
| 504 return selection; | 506 return selection; |
| 505 | 507 |
| 506 SelectionModel right_end = RightEndSelectionModel(); | 508 SelectionModel right_end = RightEndSelectionModel(); |
| 507 SelectionModel right(selection); | 509 SelectionModel right(selection); |
| 508 while (!right.Equals(right_end)) { | 510 while (!right.Equals(right_end)) { |
| 509 right = RightSelectionModel(right); | 511 right = RightSelectionModel(right); |
| 510 size_t caret = right.caret_pos(); | 512 size_t caret = right.caret_pos(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 } | 685 } |
| 684 | 686 |
| 685 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) { | 687 void RenderTextLinux::GetSelectionBounds(std::vector<Rect>* bounds) { |
| 686 if (selection_visual_bounds_.empty()) | 688 if (selection_visual_bounds_.empty()) |
| 687 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(), | 689 CalculateSubstringBounds(GetSelectionStart(), GetCursorPosition(), |
| 688 &selection_visual_bounds_); | 690 &selection_visual_bounds_); |
| 689 *bounds = selection_visual_bounds_; | 691 *bounds = selection_visual_bounds_; |
| 690 } | 692 } |
| 691 | 693 |
| 692 } // namespace gfx | 694 } // namespace gfx |
| OLD | NEW |