| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "ui/gfx/render_text.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <climits> | 8 #include <climits> |
| 9 | 9 |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 if (clip_to_display_rect()) | 711 if (clip_to_display_rect()) |
| 712 canvas->Restore(); | 712 canvas->Restore(); |
| 713 } | 713 } |
| 714 | 714 |
| 715 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { | 715 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { |
| 716 // Paint cursor. Replace cursor is drawn as rectangle for now. | 716 // Paint cursor. Replace cursor is drawn as rectangle for now. |
| 717 // TODO(msw): Draw a better cursor with a better indication of association. | 717 // TODO(msw): Draw a better cursor with a better indication of association. |
| 718 canvas->FillRect(GetCursorBounds(position, true), cursor_color_); | 718 canvas->FillRect(GetCursorBounds(position, true), cursor_color_); |
| 719 } | 719 } |
| 720 | 720 |
| 721 void RenderText::DrawSelectedTextForDrag(Canvas* canvas) { | |
| 722 EnsureLayout(); | |
| 723 const std::vector<Rect> sel = GetSubstringBounds(selection()); | |
| 724 | |
| 725 // Override the selection color with black, and force the background to be | |
| 726 // transparent so that it's rendered without subpixel antialiasing. | |
| 727 const bool saved_background_is_transparent = background_is_transparent(); | |
| 728 const SkColor saved_selection_color = selection_color(); | |
| 729 set_background_is_transparent(true); | |
| 730 set_selection_color(SK_ColorBLACK); | |
| 731 | |
| 732 for (size_t i = 0; i < sel.size(); ++i) { | |
| 733 canvas->Save(); | |
| 734 canvas->ClipRect(sel[i]); | |
| 735 DrawVisualText(canvas); | |
| 736 canvas->Restore(); | |
| 737 } | |
| 738 | |
| 739 // Restore saved transparency and selection color. | |
| 740 set_selection_color(saved_selection_color); | |
| 741 set_background_is_transparent(saved_background_is_transparent); | |
| 742 } | |
| 743 | |
| 744 Rect RenderText::GetCursorBounds(const SelectionModel& caret, | 721 Rect RenderText::GetCursorBounds(const SelectionModel& caret, |
| 745 bool insert_mode) { | 722 bool insert_mode) { |
| 746 // TODO(ckocagil): Support multiline. This function should return the height | 723 // TODO(ckocagil): Support multiline. This function should return the height |
| 747 // of the line the cursor is on. |GetStringSize()| now returns | 724 // of the line the cursor is on. |GetStringSize()| now returns |
| 748 // the multiline size, eliminate its use here. | 725 // the multiline size, eliminate its use here. |
| 749 | 726 |
| 750 EnsureLayout(); | 727 EnsureLayout(); |
| 751 | 728 |
| 752 size_t caret_pos = caret.caret_pos(); | 729 size_t caret_pos = caret.caret_pos(); |
| 753 DCHECK(IsCursorablePosition(caret_pos)); | 730 DCHECK(IsCursorablePosition(caret_pos)); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 cursor_bounds_ += delta_offset; | 1251 cursor_bounds_ += delta_offset; |
| 1275 } | 1252 } |
| 1276 | 1253 |
| 1277 void RenderText::DrawSelection(Canvas* canvas) { | 1254 void RenderText::DrawSelection(Canvas* canvas) { |
| 1278 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1255 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1279 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1256 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1280 canvas->FillRect(*i, selection_background_focused_color_); | 1257 canvas->FillRect(*i, selection_background_focused_color_); |
| 1281 } | 1258 } |
| 1282 | 1259 |
| 1283 } // namespace gfx | 1260 } // namespace gfx |
| OLD | NEW |