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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 baseline_ = DetermineBaselineCenteringText(display_rect(), font_list()); | 755 baseline_ = DetermineBaselineCenteringText(display_rect(), font_list()); |
756 DCHECK_NE(kInvalidBaseline, baseline_); | 756 DCHECK_NE(kInvalidBaseline, baseline_); |
757 return baseline_; | 757 return baseline_; |
758 } | 758 } |
759 | 759 |
760 void RenderText::Draw(Canvas* canvas) { | 760 void RenderText::Draw(Canvas* canvas) { |
761 EnsureLayout(); | 761 EnsureLayout(); |
762 | 762 |
763 if (clip_to_display_rect()) { | 763 if (clip_to_display_rect()) { |
764 Rect clip_rect(display_rect()); | 764 Rect clip_rect(display_rect()); |
765 clip_rect.Inset(ShadowValue::GetMargin(text_shadows_)); | 765 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); |
766 | 766 |
767 canvas->Save(); | 767 canvas->Save(); |
768 canvas->ClipRect(clip_rect); | 768 canvas->ClipRect(clip_rect); |
769 } | 769 } |
770 | 770 |
771 if (!text().empty() && focused()) | 771 if (!text().empty() && focused()) |
772 DrawSelection(canvas); | 772 DrawSelection(canvas); |
773 | 773 |
774 if (cursor_enabled() && cursor_visible() && focused()) | 774 if (cursor_enabled() && cursor_visible() && focused()) |
775 DrawCursor(canvas, selection_model_); | 775 DrawCursor(canvas, selection_model_); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 866 } |
867 | 867 |
868 SelectionModel RenderText::GetSelectionModelForSelectionStart() { | 868 SelectionModel RenderText::GetSelectionModelForSelectionStart() { |
869 const Range& sel = selection(); | 869 const Range& sel = selection(); |
870 if (sel.is_empty()) | 870 if (sel.is_empty()) |
871 return selection_model_; | 871 return selection_model_; |
872 return SelectionModel(sel.start(), | 872 return SelectionModel(sel.start(), |
873 sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD); | 873 sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD); |
874 } | 874 } |
875 | 875 |
876 void RenderText::SetTextShadows(const ShadowValues& shadows) { | |
877 text_shadows_ = shadows; | |
878 } | |
879 | |
880 RenderText::RenderText() | 876 RenderText::RenderText() |
881 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), | 877 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), |
882 directionality_mode_(DIRECTIONALITY_FROM_TEXT), | 878 directionality_mode_(DIRECTIONALITY_FROM_TEXT), |
883 text_direction_(base::i18n::UNKNOWN_DIRECTION), | 879 text_direction_(base::i18n::UNKNOWN_DIRECTION), |
884 cursor_enabled_(true), | 880 cursor_enabled_(true), |
885 cursor_visible_(false), | 881 cursor_visible_(false), |
886 insert_mode_(true), | 882 insert_mode_(true), |
887 cursor_color_(kDefaultColor), | 883 cursor_color_(kDefaultColor), |
888 selection_color_(kDefaultColor), | 884 selection_color_(kDefaultColor), |
889 selection_background_focused_color_(kDefaultSelectionBackgroundColor), | 885 selection_background_focused_color_(kDefaultSelectionBackgroundColor), |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 text_rect.Inset(GetAlignmentOffset(0).x(), 0, 0, 0); | 1099 text_rect.Inset(GetAlignmentOffset(0).x(), 0, 0, 0); |
1104 | 1100 |
1105 // TODO(msw): Use the actual text colors corresponding to each faded part. | 1101 // TODO(msw): Use the actual text colors corresponding to each faded part. |
1106 skia::RefPtr<SkShader> shader = CreateFadeShader( | 1102 skia::RefPtr<SkShader> shader = CreateFadeShader( |
1107 text_rect, left_part, right_part, colors_.breaks().front().second); | 1103 text_rect, left_part, right_part, colors_.breaks().front().second); |
1108 if (shader) | 1104 if (shader) |
1109 renderer->SetShader(shader.get(), display_rect()); | 1105 renderer->SetShader(shader.get(), display_rect()); |
1110 } | 1106 } |
1111 | 1107 |
1112 void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) { | 1108 void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) { |
1113 skia::RefPtr<SkDrawLooper> looper = CreateShadowDrawLooper(text_shadows_); | 1109 skia::RefPtr<SkDrawLooper> looper = CreateShadowDrawLooper(shadows_); |
1114 renderer->SetDrawLooper(looper.get()); | 1110 renderer->SetDrawLooper(looper.get()); |
1115 } | 1111 } |
1116 | 1112 |
1117 // static | 1113 // static |
1118 bool RenderText::RangeContainsCaret(const Range& range, | 1114 bool RenderText::RangeContainsCaret(const Range& range, |
1119 size_t caret_pos, | 1115 size_t caret_pos, |
1120 LogicalCursorDirection caret_affinity) { | 1116 LogicalCursorDirection caret_affinity) { |
1121 // NB: exploits unsigned wraparound (WG14/N1124 section 6.2.5 paragraph 9). | 1117 // NB: exploits unsigned wraparound (WG14/N1124 section 6.2.5 paragraph 9). |
1122 size_t adjacent = (caret_affinity == CURSOR_BACKWARD) ? | 1118 size_t adjacent = (caret_affinity == CURSOR_BACKWARD) ? |
1123 caret_pos - 1 : caret_pos + 1; | 1119 caret_pos - 1 : caret_pos + 1; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 cursor_bounds_ += delta_offset; | 1316 cursor_bounds_ += delta_offset; |
1321 } | 1317 } |
1322 | 1318 |
1323 void RenderText::DrawSelection(Canvas* canvas) { | 1319 void RenderText::DrawSelection(Canvas* canvas) { |
1324 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1320 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1325 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1321 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1326 canvas->FillRect(*i, selection_background_focused_color_); | 1322 canvas->FillRect(*i, selection_background_focused_color_); |
1327 } | 1323 } |
1328 | 1324 |
1329 } // namespace gfx | 1325 } // namespace gfx |
OLD | NEW |