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 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 763 |
764 // Apply an underline to the composition range in |underlines|. | 764 // Apply an underline to the composition range in |underlines|. |
765 if (composition_range_.IsValid() && !composition_range_.is_empty()) | 765 if (composition_range_.IsValid() && !composition_range_.is_empty()) |
766 styles_[UNDERLINE].ApplyValue(true, composition_range_); | 766 styles_[UNDERLINE].ApplyValue(true, composition_range_); |
767 | 767 |
768 // Apply the selected text color to the [un-reversed] selection range. | 768 // Apply the selected text color to the [un-reversed] selection range. |
769 if (!selection().is_empty()) { | 769 if (!selection().is_empty()) { |
770 const ui::Range range(selection().GetMin(), selection().GetMax()); | 770 const ui::Range range(selection().GetMin(), selection().GetMax()); |
771 colors_.ApplyValue(selection_color_, range); | 771 colors_.ApplyValue(selection_color_, range); |
772 } | 772 } |
773 // Apply the selected text color to the cursor range in overtype mode. | |
774 if (!insert_mode_ && cursor_visible() && focused()) { | |
775 const size_t cursor = cursor_position(); | |
776 const size_t next = IndexOfAdjacentGrapheme(cursor, CURSOR_FORWARD); | |
777 colors_.ApplyValue(selection_color_, ui::Range(cursor, next)); | |
778 } | |
779 composition_and_selection_styles_applied_ = true; | 773 composition_and_selection_styles_applied_ = true; |
780 } | 774 } |
781 | 775 |
782 void RenderText::UndoCompositionAndSelectionStyles() { | 776 void RenderText::UndoCompositionAndSelectionStyles() { |
783 // Restore the underline and color breaks to undo the temporary styles. | 777 // Restore the underline and color breaks to undo the temporary styles. |
784 DCHECK(composition_and_selection_styles_applied_); | 778 DCHECK(composition_and_selection_styles_applied_); |
785 colors_ = saved_colors_; | 779 colors_ = saved_colors_; |
786 styles_[UNDERLINE] = saved_underlines_; | 780 styles_[UNDERLINE] = saved_underlines_; |
787 composition_and_selection_styles_applied_ = false; | 781 composition_and_selection_styles_applied_ = false; |
788 } | 782 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 selection_background_unfocused_color_; | 949 selection_background_unfocused_color_; |
956 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 950 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
957 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 951 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
958 canvas->FillRect(*i, color); | 952 canvas->FillRect(*i, color); |
959 } | 953 } |
960 | 954 |
961 void RenderText::DrawCursor(Canvas* canvas) { | 955 void RenderText::DrawCursor(Canvas* canvas) { |
962 // Paint cursor. Replace cursor is drawn as rectangle for now. | 956 // Paint cursor. Replace cursor is drawn as rectangle for now. |
963 // TODO(msw): Draw a better cursor with a better indication of association. | 957 // TODO(msw): Draw a better cursor with a better indication of association. |
964 if (cursor_enabled() && cursor_visible() && focused()) { | 958 if (cursor_enabled() && cursor_visible() && focused()) { |
965 const Rect& bounds = GetUpdatedCursorBounds(); | 959 canvas->FillRect(GetUpdatedCursorBounds(), |
966 DCHECK(bounds.width()); | 960 insert_mode_ ? cursor_color_ : selection_background_unfocused_color_); |
967 canvas->FillRect(bounds, cursor_color_); | |
968 } | 961 } |
969 } | 962 } |
970 | 963 |
971 } // namespace gfx | 964 } // namespace gfx |
OLD | NEW |