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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 color_ = colors_.GetBreak(position); | 297 color_ = colors_.GetBreak(position); |
298 for (size_t i = 0; i < NUM_TEXT_STYLES; ++i) | 298 for (size_t i = 0; i < NUM_TEXT_STYLES; ++i) |
299 style_[i] = styles_[i].GetBreak(position); | 299 style_[i] = styles_[i].GetBreak(position); |
300 } | 300 } |
301 | 301 |
302 } // namespace internal | 302 } // namespace internal |
303 | 303 |
304 RenderText::~RenderText() { | 304 RenderText::~RenderText() { |
305 } | 305 } |
306 | 306 |
307 void RenderText::SetText(const string16& text) { | 307 void RenderText::SetText(const base::string16& text) { |
308 DCHECK(!composition_range_.IsValid()); | 308 DCHECK(!composition_range_.IsValid()); |
309 text_ = text; | 309 text_ = text; |
310 | 310 |
311 // Adjust ranged styles and colors to accommodate a new text length. | 311 // Adjust ranged styles and colors to accommodate a new text length. |
312 const size_t text_length = text_.length(); | 312 const size_t text_length = text_.length(); |
313 colors_.SetMax(text_length); | 313 colors_.SetMax(text_length); |
314 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) | 314 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) |
315 styles_[style].SetMax(text_length); | 315 styles_[style].SetMax(text_length); |
316 cached_bounds_and_offset_valid_ = false; | 316 cached_bounds_and_offset_valid_ = false; |
317 | 317 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 return SelectionModel(text().length(), CURSOR_FORWARD); | 790 return SelectionModel(text().length(), CURSOR_FORWARD); |
791 return SelectionModel(0, CURSOR_BACKWARD); | 791 return SelectionModel(0, CURSOR_BACKWARD); |
792 } | 792 } |
793 | 793 |
794 void RenderText::SetSelectionModel(const SelectionModel& model) { | 794 void RenderText::SetSelectionModel(const SelectionModel& model) { |
795 DCHECK_LE(model.selection().GetMax(), text().length()); | 795 DCHECK_LE(model.selection().GetMax(), text().length()); |
796 selection_model_ = model; | 796 selection_model_ = model; |
797 cached_bounds_and_offset_valid_ = false; | 797 cached_bounds_and_offset_valid_ = false; |
798 } | 798 } |
799 | 799 |
800 const string16& RenderText::GetLayoutText() const { | 800 const base::string16& RenderText::GetLayoutText() const { |
801 return obscured() ? obscured_text_ : text(); | 801 return obscured() ? obscured_text_ : text(); |
802 } | 802 } |
803 | 803 |
804 void RenderText::ApplyCompositionAndSelectionStyles() { | 804 void RenderText::ApplyCompositionAndSelectionStyles() { |
805 // Save the underline and color breaks to undo the temporary styles later. | 805 // Save the underline and color breaks to undo the temporary styles later. |
806 DCHECK(!composition_and_selection_styles_applied_); | 806 DCHECK(!composition_and_selection_styles_applied_); |
807 saved_colors_ = colors_; | 807 saved_colors_ = colors_; |
808 saved_underlines_ = styles_[UNDERLINE]; | 808 saved_underlines_ = styles_[UNDERLINE]; |
809 | 809 |
810 // Apply an underline to the composition range in |underlines|. | 810 // Apply an underline to the composition range in |underlines|. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 void RenderText::DrawSelection(Canvas* canvas) { | 1002 void RenderText::DrawSelection(Canvas* canvas) { |
1003 const SkColor color = focused() ? | 1003 const SkColor color = focused() ? |
1004 selection_background_focused_color_ : | 1004 selection_background_focused_color_ : |
1005 selection_background_unfocused_color_; | 1005 selection_background_unfocused_color_; |
1006 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1006 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1007 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1007 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1008 canvas->FillRect(*i, color); | 1008 canvas->FillRect(*i, color); |
1009 } | 1009 } |
1010 | 1010 |
1011 } // namespace gfx | 1011 } // namespace gfx |
OLD | NEW |