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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 353 } |
354 | 354 |
355 void RenderText::SetFont(const Font& font) { | 355 void RenderText::SetFont(const Font& font) { |
356 SetFontList(FontList(font)); | 356 SetFontList(FontList(font)); |
357 } | 357 } |
358 | 358 |
359 void RenderText::SetFontSize(int size) { | 359 void RenderText::SetFontSize(int size) { |
360 SetFontList(font_list_.DeriveFontListWithSize(size)); | 360 SetFontList(font_list_.DeriveFontListWithSize(size)); |
361 } | 361 } |
362 | 362 |
| 363 const Font& RenderText::GetPrimaryFont() const { |
| 364 return font_list_.GetPrimaryFont(); |
| 365 } |
| 366 |
363 void RenderText::SetCursorEnabled(bool cursor_enabled) { | 367 void RenderText::SetCursorEnabled(bool cursor_enabled) { |
364 cursor_enabled_ = cursor_enabled; | 368 cursor_enabled_ = cursor_enabled; |
365 cached_bounds_and_offset_valid_ = false; | 369 cached_bounds_and_offset_valid_ = false; |
366 } | 370 } |
367 | 371 |
368 const Font& RenderText::GetFont() const { | |
369 return font_list_.GetFonts()[0]; | |
370 } | |
371 | |
372 void RenderText::ToggleInsertMode() { | 372 void RenderText::ToggleInsertMode() { |
373 insert_mode_ = !insert_mode_; | 373 insert_mode_ = !insert_mode_; |
374 cached_bounds_and_offset_valid_ = false; | 374 cached_bounds_and_offset_valid_ = false; |
375 } | 375 } |
376 | 376 |
377 void RenderText::SetObscured(bool obscured) { | 377 void RenderText::SetObscured(bool obscured) { |
378 if (obscured != obscured_) { | 378 if (obscured != obscured_) { |
379 obscured_ = obscured; | 379 obscured_ = obscured; |
380 obscured_reveal_index_ = -1; | 380 obscured_reveal_index_ = -1; |
381 cached_bounds_and_offset_valid_ = false; | 381 cached_bounds_and_offset_valid_ = false; |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 if (!fade_head() && !fade_tail()) | 866 if (!fade_head() && !fade_tail()) |
867 return; | 867 return; |
868 | 868 |
869 const int text_width = GetStringSize().width(); | 869 const int text_width = GetStringSize().width(); |
870 const int display_width = display_rect().width(); | 870 const int display_width = display_rect().width(); |
871 | 871 |
872 // If the text fits as-is, no need to fade. | 872 // If the text fits as-is, no need to fade. |
873 if (text_width <= display_width) | 873 if (text_width <= display_width) |
874 return; | 874 return; |
875 | 875 |
876 int gradient_width = CalculateFadeGradientWidth(GetFont(), display_width); | 876 int gradient_width = CalculateFadeGradientWidth(GetPrimaryFont(), |
| 877 display_width); |
877 if (gradient_width == 0) | 878 if (gradient_width == 0) |
878 return; | 879 return; |
879 | 880 |
880 bool fade_left = fade_head(); | 881 bool fade_left = fade_head(); |
881 bool fade_right = fade_tail(); | 882 bool fade_right = fade_tail(); |
882 // Under RTL, |fade_right| == |fade_head|. | 883 // Under RTL, |fade_right| == |fade_head|. |
883 // TODO(asvitkine): This is currently not based on GetTextDirection() because | 884 // TODO(asvitkine): This is currently not based on GetTextDirection() because |
884 // RenderTextWin does not return a direction that's based on | 885 // RenderTextWin does not return a direction that's based on |
885 // the text content. | 886 // the text content. |
886 if (horizontal_alignment_ == ALIGN_RIGHT) | 887 if (horizontal_alignment_ == ALIGN_RIGHT) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 cursor_bounds_ += delta_offset; | 1015 cursor_bounds_ += delta_offset; |
1015 } | 1016 } |
1016 | 1017 |
1017 void RenderText::DrawSelection(Canvas* canvas) { | 1018 void RenderText::DrawSelection(Canvas* canvas) { |
1018 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1019 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1019 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1020 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1020 canvas->FillRect(*i, selection_background_focused_color_); | 1021 canvas->FillRect(*i, selection_background_focused_color_); |
1021 } | 1022 } |
1022 | 1023 |
1023 } // namespace gfx | 1024 } // namespace gfx |
OLD | NEW |