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 GetCensoredText(), |
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()), |
msw
2011/12/03 00:22:40
We should test this behavior with RTL passwords.
benrg
2011/12/08 21:40:55
What this is intended to do is display the whole *
| |
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 |
248 // label, we will need to remove the single-line-mode setting. | 248 // label, we will need to remove the single-line-mode setting. |
249 pango_layout_set_single_paragraph_mode(layout_, true); | 249 pango_layout_set_single_paragraph_mode(layout_, true); |
250 SetupPangoAttributes(layout_); | 250 SetupPangoAttributes(layout_); |
(...skipping 210 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 = GetCensoredText(); |
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 = GetCensoredText(); |
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 GSList* current = current_line_->runs; | 626 GSList* current = current_line_->runs; |
625 while (current && current->next) { | 627 while (current && current->next) { |
626 current = current->next; | 628 current = current->next; |
627 } | 629 } |
628 return current ? reinterpret_cast<PangoLayoutRun*>(current->data) : NULL; | 630 return current ? reinterpret_cast<PangoLayoutRun*>(current->data) : NULL; |
629 } | 631 } |
630 | 632 |
631 size_t RenderTextLinux::Utf16IndexToUtf8Index(size_t index) const { | 633 size_t RenderTextLinux::Utf16IndexToUtf8Index(size_t index) const { |
632 int32_t utf8_index = 0; | 634 int32_t utf8_index = 0; |
633 UErrorCode ec = U_ZERO_ERROR; | 635 UErrorCode ec = U_ZERO_ERROR; |
634 u_strToUTF8(NULL, 0, &utf8_index, text().data(), index, &ec); | 636 u_strToUTF8(NULL, 0, &utf8_index, text().data(), index, &ec); |
msw
2011/12/03 00:22:40
Should this use GetCensoredText()?
xji
2011/12/06 01:24:04
agree.
benrg
2011/12/08 21:40:55
See out-of-line comments.
| |
635 // Even given a destination buffer as NULL and destination capacity as 0, | 637 // Even given a destination buffer as NULL and destination capacity as 0, |
636 // if the output length is equal to or greater than the capacity, then the | 638 // if the output length is equal to or greater than the capacity, then the |
637 // UErrorCode is set to U_STRING_NOT_TERMINATED_WARNING or | 639 // UErrorCode is set to U_STRING_NOT_TERMINATED_WARNING or |
638 // U_BUFFER_OVERFLOW_ERROR respectively. | 640 // U_BUFFER_OVERFLOW_ERROR respectively. |
639 // Please refer to | 641 // Please refer to |
640 // http://userguide.icu-project.org/strings#TOC-Using-C-Strings:-NUL-Terminate d-vs | 642 // http://userguide.icu-project.org/strings#TOC-Using-C-Strings:-NUL-Terminate d-vs |
641 // for detail (search for "Note that" below "Preflighting"). | 643 // for detail (search for "Note that" below "Preflighting"). |
642 DCHECK(ec == U_BUFFER_OVERFLOW_ERROR || | 644 DCHECK(ec == U_BUFFER_OVERFLOW_ERROR || |
643 ec == U_STRING_NOT_TERMINATED_WARNING); | 645 ec == U_STRING_NOT_TERMINATED_WARNING); |
644 return utf8_index; | 646 return utf8_index; |
(...skipping 38 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 |