Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/gfx/render_text.cc

Issue 1018463004: Fix focus rectangle for label. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetFocusBounds Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 if (horizontal_offset < min_offset) 932 if (horizontal_offset < min_offset)
933 horizontal_offset = min_offset; 933 horizontal_offset = min_offset;
934 else if (horizontal_offset > max_offset) 934 else if (horizontal_offset > max_offset)
935 horizontal_offset = max_offset; 935 horizontal_offset = max_offset;
936 936
937 cached_bounds_and_offset_valid_ = true; 937 cached_bounds_and_offset_valid_ = true;
938 display_offset_.set_x(horizontal_offset); 938 display_offset_.set_x(horizontal_offset);
939 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); 939 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_);
940 } 940 }
941 941
942 Vector2d RenderText::GetLineOffset(size_t line_number) {
943 Vector2d offset = display_rect().OffsetFromOrigin();
944 // TODO(ckocagil): Apply the display offset for multiline scrolling.
945 if (!multiline())
946 offset.Add(GetUpdatedDisplayOffset());
947 else
948 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
949 offset.Add(GetAlignmentOffset(line_number));
950 return offset;
951 }
952
942 RenderText::RenderText() 953 RenderText::RenderText()
943 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), 954 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
944 directionality_mode_(DIRECTIONALITY_FROM_TEXT), 955 directionality_mode_(DIRECTIONALITY_FROM_TEXT),
945 text_direction_(base::i18n::UNKNOWN_DIRECTION), 956 text_direction_(base::i18n::UNKNOWN_DIRECTION),
946 cursor_enabled_(true), 957 cursor_enabled_(true),
947 cursor_visible_(false), 958 cursor_visible_(false),
948 insert_mode_(true), 959 insert_mode_(true),
949 cursor_color_(kDefaultColor), 960 cursor_color_(kDefaultColor),
950 selection_color_(kDefaultColor), 961 selection_color_(kDefaultColor),
951 selection_background_focused_color_(kDefaultSelectionBackgroundColor), 962 selection_background_focused_color_(kDefaultSelectionBackgroundColor),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 } 1071 }
1061 1072
1062 void RenderText::UndoCompositionAndSelectionStyles() { 1073 void RenderText::UndoCompositionAndSelectionStyles() {
1063 // Restore the underline and color breaks to undo the temporary styles. 1074 // Restore the underline and color breaks to undo the temporary styles.
1064 DCHECK(composition_and_selection_styles_applied_); 1075 DCHECK(composition_and_selection_styles_applied_);
1065 colors_ = saved_colors_; 1076 colors_ = saved_colors_;
1066 styles_[UNDERLINE] = saved_underlines_; 1077 styles_[UNDERLINE] = saved_underlines_;
1067 composition_and_selection_styles_applied_ = false; 1078 composition_and_selection_styles_applied_ = false;
1068 } 1079 }
1069 1080
1070 Vector2d RenderText::GetLineOffset(size_t line_number) {
1071 Vector2d offset = display_rect().OffsetFromOrigin();
1072 // TODO(ckocagil): Apply the display offset for multiline scrolling.
1073 if (!multiline())
1074 offset.Add(GetUpdatedDisplayOffset());
1075 else
1076 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
1077 offset.Add(GetAlignmentOffset(line_number));
1078 return offset;
1079 }
1080
1081 Point RenderText::ToTextPoint(const Point& point) { 1081 Point RenderText::ToTextPoint(const Point& point) {
1082 return point - GetLineOffset(0); 1082 return point - GetLineOffset(0);
1083 // TODO(ckocagil): Convert multiline view space points to text space. 1083 // TODO(ckocagil): Convert multiline view space points to text space.
1084 } 1084 }
1085 1085
1086 Point RenderText::ToViewPoint(const Point& point) { 1086 Point RenderText::ToViewPoint(const Point& point) {
1087 if (!multiline()) 1087 if (!multiline())
1088 return point + GetLineOffset(0); 1088 return point + GetLineOffset(0);
1089 1089
1090 // TODO(ckocagil): Traverse individual line segments for RTL support. 1090 // TODO(ckocagil): Traverse individual line segments for RTL support.
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 1496
1497 SetDisplayOffset(display_offset_.x() + delta_x); 1497 SetDisplayOffset(display_offset_.x() + delta_x);
1498 } 1498 }
1499 1499
1500 void RenderText::DrawSelection(Canvas* canvas) { 1500 void RenderText::DrawSelection(Canvas* canvas) {
1501 for (const Rect& s : GetSubstringBounds(selection())) 1501 for (const Rect& s : GetSubstringBounds(selection()))
1502 canvas->FillRect(s, selection_background_focused_color_); 1502 canvas->FillRect(s, selection_background_focused_color_);
1503 } 1503 }
1504 1504
1505 } // namespace gfx 1505 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698