| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 if (directionality_mode_ == DIRECTIONALITY_FROM_TEXT) | 399 if (directionality_mode_ == DIRECTIONALITY_FROM_TEXT) |
| 400 text_direction_ = base::i18n::UNKNOWN_DIRECTION; | 400 text_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| 401 | 401 |
| 402 UpdateObscuredText(); | 402 UpdateObscuredText(); |
| 403 ResetLayout(); | 403 ResetLayout(); |
| 404 } | 404 } |
| 405 | 405 |
| 406 void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) { | 406 void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) { |
| 407 if (horizontal_alignment_ != alignment) { | 407 if (horizontal_alignment_ != alignment) { |
| 408 horizontal_alignment_ = alignment; | 408 horizontal_alignment_ = alignment; |
| 409 display_offset_ = Point(); | 409 display_offset_ = Vector2d(); |
| 410 cached_bounds_and_offset_valid_ = false; | 410 cached_bounds_and_offset_valid_ = false; |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 void RenderText::SetFontList(const FontList& font_list) { | 414 void RenderText::SetFontList(const FontList& font_list) { |
| 415 font_list_ = font_list; | 415 font_list_ = font_list; |
| 416 cached_bounds_and_offset_valid_ = false; | 416 cached_bounds_and_offset_valid_ = false; |
| 417 ResetLayout(); | 417 ResetLayout(); |
| 418 } | 418 } |
| 419 | 419 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 focused_(false), | 758 focused_(false), |
| 759 composition_range_(ui::Range::InvalidRange()), | 759 composition_range_(ui::Range::InvalidRange()), |
| 760 obscured_(false), | 760 obscured_(false), |
| 761 fade_head_(false), | 761 fade_head_(false), |
| 762 fade_tail_(false), | 762 fade_tail_(false), |
| 763 background_is_transparent_(false), | 763 background_is_transparent_(false), |
| 764 clip_to_display_rect_(true), | 764 clip_to_display_rect_(true), |
| 765 cached_bounds_and_offset_valid_(false) { | 765 cached_bounds_and_offset_valid_(false) { |
| 766 } | 766 } |
| 767 | 767 |
| 768 const Point& RenderText::GetUpdatedDisplayOffset() { | 768 const Vector2d& RenderText::GetUpdatedDisplayOffset() { |
| 769 UpdateCachedBoundsAndOffset(); | 769 UpdateCachedBoundsAndOffset(); |
| 770 return display_offset_; | 770 return display_offset_; |
| 771 } | 771 } |
| 772 | 772 |
| 773 SelectionModel RenderText::GetAdjacentSelectionModel( | 773 SelectionModel RenderText::GetAdjacentSelectionModel( |
| 774 const SelectionModel& current, | 774 const SelectionModel& current, |
| 775 BreakType break_type, | 775 BreakType break_type, |
| 776 VisualCursorDirection direction) { | 776 VisualCursorDirection direction) { |
| 777 EnsureLayout(); | 777 EnsureLayout(); |
| 778 | 778 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 } | 840 } |
| 841 | 841 |
| 842 Point RenderText::GetTextOrigin() { | 842 Point RenderText::GetTextOrigin() { |
| 843 Point origin = display_rect().origin(); | 843 Point origin = display_rect().origin(); |
| 844 origin = origin.Add(GetUpdatedDisplayOffset()); | 844 origin = origin.Add(GetUpdatedDisplayOffset()); |
| 845 origin = origin.Add(GetAlignmentOffset()); | 845 origin = origin.Add(GetAlignmentOffset()); |
| 846 return origin; | 846 return origin; |
| 847 } | 847 } |
| 848 | 848 |
| 849 Point RenderText::ToTextPoint(const Point& point) { | 849 Point RenderText::ToTextPoint(const Point& point) { |
| 850 return point.Subtract(GetTextOrigin()); | 850 return point.Subtract(GetTextOrigin().DistanceFromOrigin()); |
| 851 } | 851 } |
| 852 | 852 |
| 853 Point RenderText::ToViewPoint(const Point& point) { | 853 Point RenderText::ToViewPoint(const Point& point) { |
| 854 return point.Add(GetTextOrigin()); | 854 return point.Add(GetTextOrigin().DistanceFromOrigin()); |
| 855 } | 855 } |
| 856 | 856 |
| 857 int RenderText::GetContentWidth() { | 857 int RenderText::GetContentWidth() { |
| 858 return GetStringSize().width() + (cursor_enabled_ ? 1 : 0); | 858 return GetStringSize().width() + (cursor_enabled_ ? 1 : 0); |
| 859 } | 859 } |
| 860 | 860 |
| 861 Point RenderText::GetAlignmentOffset() { | 861 Vector2d RenderText::GetAlignmentOffset() { |
| 862 if (horizontal_alignment() != ALIGN_LEFT) { | 862 if (horizontal_alignment() != ALIGN_LEFT) { |
| 863 int x_offset = display_rect().width() - GetContentWidth(); | 863 int x_offset = display_rect().width() - GetContentWidth(); |
| 864 if (horizontal_alignment() == ALIGN_CENTER) | 864 if (horizontal_alignment() == ALIGN_CENTER) |
| 865 x_offset /= 2; | 865 x_offset /= 2; |
| 866 return Point(x_offset, 0); | 866 return Vector2d(x_offset, 0); |
| 867 } | 867 } |
| 868 return Point(); | 868 return Vector2d(); |
| 869 } | 869 } |
| 870 | 870 |
| 871 Point RenderText::GetOriginForDrawing() { | 871 Point RenderText::GetOriginForDrawing() { |
| 872 Point origin(GetTextOrigin()); | 872 Point origin(GetTextOrigin()); |
| 873 const int height = GetStringSize().height(); | 873 const int height = GetStringSize().height(); |
| 874 // Center the text vertically in the display area. | 874 // Center the text vertically in the display area. |
| 875 origin.Offset(0, (display_rect().height() - height) / 2); | 875 origin.Offset(0, (display_rect().height() - height) / 2); |
| 876 return origin; | 876 return origin; |
| 877 } | 877 } |
| 878 | 878 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 delta_offset = display_rect_.x() - cursor_bounds_.x(); | 994 delta_offset = display_rect_.x() - cursor_bounds_.x(); |
| 995 } else if (display_offset_.x() != 0) { | 995 } else if (display_offset_.x() != 0) { |
| 996 // Reduce the pan offset to show additional overflow text when the display | 996 // Reduce the pan offset to show additional overflow text when the display |
| 997 // width increases. | 997 // width increases. |
| 998 const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; | 998 const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; |
| 999 const int offset = negate_rtl * display_offset_.x(); | 999 const int offset = negate_rtl * display_offset_.x(); |
| 1000 if (display_width > (content_width + offset)) | 1000 if (display_width > (content_width + offset)) |
| 1001 delta_offset = negate_rtl * (display_width - (content_width + offset)); | 1001 delta_offset = negate_rtl * (display_width - (content_width + offset)); |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 display_offset_.Offset(delta_offset, 0); | 1004 display_offset_.Grow(delta_offset, 0); |
| 1005 cursor_bounds_.Offset(delta_offset, 0); | 1005 cursor_bounds_.Offset(delta_offset, 0); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 void RenderText::DrawSelection(Canvas* canvas) { | 1008 void RenderText::DrawSelection(Canvas* canvas) { |
| 1009 const SkColor color = focused() ? selection_background_focused_color_ : | 1009 const SkColor color = focused() ? selection_background_focused_color_ : |
| 1010 selection_background_unfocused_color_; | 1010 selection_background_unfocused_color_; |
| 1011 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1011 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1012 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1012 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1013 canvas->FillRect(*i, color); | 1013 canvas->FillRect(*i, color); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 void RenderText::DrawCursor(Canvas* canvas) { | 1016 void RenderText::DrawCursor(Canvas* canvas) { |
| 1017 // Paint cursor. Replace cursor is drawn as rectangle for now. | 1017 // Paint cursor. Replace cursor is drawn as rectangle for now. |
| 1018 // TODO(msw): Draw a better cursor with a better indication of association. | 1018 // TODO(msw): Draw a better cursor with a better indication of association. |
| 1019 if (cursor_enabled() && cursor_visible() && focused()) { | 1019 if (cursor_enabled() && cursor_visible() && focused()) { |
| 1020 const Rect& bounds = GetUpdatedCursorBounds(); | 1020 const Rect& bounds = GetUpdatedCursorBounds(); |
| 1021 if (bounds.width() != 0) | 1021 if (bounds.width() != 0) |
| 1022 canvas->FillRect(bounds, cursor_color_); | 1022 canvas->FillRect(bounds, cursor_color_); |
| 1023 else | 1023 else |
| 1024 canvas->DrawRect(bounds, cursor_color_); | 1024 canvas->DrawRect(bounds, cursor_color_); |
| 1025 } | 1025 } |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 } // namespace gfx | 1028 } // namespace gfx |
| OLD | NEW |