Chromium Code Reviews| 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 int max_offset = 0; | 885 int max_offset = 0; |
| 886 if (extra_content > 0) { | 886 if (extra_content > 0) { |
| 887 switch (horizontal_alignment_) { | 887 switch (horizontal_alignment_) { |
| 888 case ALIGN_LEFT: | 888 case ALIGN_LEFT: |
| 889 min_offset = -extra_content; | 889 min_offset = -extra_content; |
| 890 break; | 890 break; |
| 891 case ALIGN_RIGHT: | 891 case ALIGN_RIGHT: |
| 892 max_offset = extra_content; | 892 max_offset = extra_content; |
| 893 break; | 893 break; |
| 894 case ALIGN_CENTER: | 894 case ALIGN_CENTER: |
| 895 min_offset = -extra_content / 2; | 895 min_offset = -(extra_content + 1) / 2; |
| 896 max_offset = extra_content / 2; | 896 max_offset = extra_content / 2; |
| 897 break; | 897 break; |
| 898 default: | 898 default: |
| 899 break; | 899 break; |
| 900 } | 900 } |
| 901 } | 901 } |
| 902 if (horizontal_offset < min_offset) | 902 if (horizontal_offset < min_offset) |
| 903 horizontal_offset = min_offset; | 903 horizontal_offset = min_offset; |
| 904 else if (horizontal_offset > max_offset) | 904 else if (horizontal_offset > max_offset) |
| 905 horizontal_offset = max_offset; | 905 horizontal_offset = max_offset; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1302 | 1302 |
| 1303 return render_text->text(); | 1303 return render_text->text(); |
| 1304 } | 1304 } |
| 1305 | 1305 |
| 1306 void RenderText::UpdateCachedBoundsAndOffset() { | 1306 void RenderText::UpdateCachedBoundsAndOffset() { |
| 1307 if (cached_bounds_and_offset_valid_) | 1307 if (cached_bounds_and_offset_valid_) |
| 1308 return; | 1308 return; |
| 1309 | 1309 |
| 1310 // TODO(ckocagil): Add support for scrolling multiline text. | 1310 // TODO(ckocagil): Add support for scrolling multiline text. |
| 1311 | 1311 |
| 1312 // First, set the valid flag true to calculate the current cursor bounds using | 1312 int delta_x = 0; |
| 1313 // the stale |display_offset_|. Applying |delta_offset| at the end of this | 1313 |
| 1314 // function will set |cursor_bounds_| and |display_offset_| to correct values. | 1314 if (cursor_enabled()) { |
| 1315 cached_bounds_and_offset_valid_ = true; | 1315 // When cursor is enabled, ensure it is visible. For this, set the valid |
| 1316 if (cursor_enabled()) | 1316 // flag true and calculate the current cursor bounds using the stale |
| 1317 // |display_offset_|. Then calculate the change in offset needed to move the | |
| 1318 // cursor into the visible area. | |
| 1319 cached_bounds_and_offset_valid_ = true; | |
| 1317 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); | 1320 cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); |
| 1318 | 1321 |
| 1319 // Update |display_offset_| to ensure the current cursor is visible. | 1322 // TODO(bidi): In left-aligned text, when overflow character is an RTL |
|
msw
2014/07/16 21:55:54
nit: use this one-liner: "// TODO(bidi): Show RTL
mohsen
2014/07/16 23:36:21
Done.
| |
| 1320 const int display_width = display_rect_.width(); | 1323 // character, panning cursor at the rightmost position would not show the |
| 1321 const int content_width = GetContentWidth(); | 1324 // entered character. The same happens in right-aligned text, when the |
| 1322 | 1325 // overflow character is an LTR character, if we pan cursor at the leftmost |
| 1323 int delta_x = 0; | 1326 // position. Ideally, we should pan cursor to show the last logical |
| 1324 if (content_width <= display_width || !cursor_enabled()) { | 1327 // characters. |
| 1325 // Don't pan if the text fits in the display width or when the cursor is | 1328 if (cursor_bounds_.right() > display_rect_.right()) |
| 1326 // disabled. | 1329 delta_x = display_rect_.right() - cursor_bounds_.right(); |
| 1327 delta_x = -display_offset_.x(); | 1330 else if (cursor_bounds_.x() < display_rect_.x()) |
| 1328 } else if (cursor_bounds_.right() > display_rect_.right()) { | 1331 delta_x = display_rect_.x() - cursor_bounds_.x(); |
| 1329 // TODO(xji): when the character overflow is a RTL character, currently, if | |
| 1330 // we pan cursor at the rightmost position, the entered RTL character is not | |
| 1331 // displayed. Should pan cursor to show the last logical characters. | |
| 1332 // | |
| 1333 // Pan to show the cursor when it overflows to the right. | |
| 1334 delta_x = display_rect_.right() - cursor_bounds_.right(); | |
| 1335 } else if (cursor_bounds_.x() < display_rect_.x()) { | |
| 1336 // TODO(xji): have similar problem as above when overflow character is a | |
| 1337 // LTR character. | |
| 1338 // | |
| 1339 // Pan to show the cursor when it overflows to the left. | |
| 1340 delta_x = display_rect_.x() - cursor_bounds_.x(); | |
| 1341 } else if (display_offset_.x() != 0) { | |
| 1342 // Reduce the pan offset to show additional overflow text when the display | |
| 1343 // width increases. | |
| 1344 const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; | |
| 1345 const int offset = negate_rtl * display_offset_.x(); | |
| 1346 if (display_width > (content_width + offset)) { | |
| 1347 delta_x = negate_rtl * (display_width - (content_width + offset)); | |
| 1348 } | |
| 1349 } | 1332 } |
| 1350 | 1333 |
| 1351 Vector2d delta_offset(delta_x, 0); | 1334 SetDisplayOffset(display_offset_.x() + delta_x); |
| 1352 display_offset_ += delta_offset; | |
| 1353 cursor_bounds_ += delta_offset; | |
| 1354 } | 1335 } |
| 1355 | 1336 |
| 1356 void RenderText::DrawSelection(Canvas* canvas) { | 1337 void RenderText::DrawSelection(Canvas* canvas) { |
| 1357 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1338 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1358 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1339 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1359 canvas->FillRect(*i, selection_background_focused_color_); | 1340 canvas->FillRect(*i, selection_background_focused_color_); |
| 1360 } | 1341 } |
| 1361 | 1342 |
| 1362 } // namespace gfx | 1343 } // namespace gfx |
| OLD | NEW |