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

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

Issue 384953003: RenderText: handle center-aligned text in UpdateCachedBoundsAndOffset() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Used SetDisplayOffset() in UpdateChachedBoundsAndOffset() Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 to move
msw 2014/07/16 01:41:43 nit: fix "to to"
mohsen 2014/07/16 20:48:10 Done.
1318 // the 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 if (cursor_bounds_.right() > display_rect_.right()) {
1320 const int display_width = display_rect_.width(); 1323 // TODO(xji): when the character overflow is a RTL character, currently,
msw 2014/07/16 01:41:43 nit: consolidate these two as TODO(bidi) above the
mohsen 2014/07/16 20:48:10 Done. Please check if the result is satisfactory.
1321 const int content_width = GetContentWidth(); 1324 // if we pan cursor at the rightmost position, the entered RTL character
1322 1325 // is not displayed. Should pan cursor to show the last logical
1323 int delta_x = 0; 1326 // characters.
1324 if (content_width <= display_width || !cursor_enabled()) { 1327 //
1325 // Don't pan if the text fits in the display width or when the cursor is 1328 // Pan to show the cursor when it overflows to the right.
msw 2014/07/16 01:41:43 nit: remove the "pan to show" comments, the top co
mohsen 2014/07/16 20:48:10 Done.
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 // TODO(xji): have similar problem as above when overflow character is a
1329 // TODO(xji): when the character overflow is a RTL character, currently, if 1332 // LTR character.
1330 // we pan cursor at the rightmost position, the entered RTL character is not 1333 //
1331 // displayed. Should pan cursor to show the last logical characters. 1334 // Pan to show the cursor when it overflows to the left.
1332 // 1335 delta_x = display_rect_.x() - cursor_bounds_.x();
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
msw 2014/07/16 01:41:43 Does the new code still do this via min/max clampi
mohsen 2014/07/16 20:48:10 Yes.
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 } 1336 }
1349 } 1337 }
1350 1338
1351 Vector2d delta_offset(delta_x, 0); 1339 SetDisplayOffset(display_offset_.x() + delta_x);
1352 display_offset_ += delta_offset;
1353 cursor_bounds_ += delta_offset;
1354 } 1340 }
1355 1341
1356 void RenderText::DrawSelection(Canvas* canvas) { 1342 void RenderText::DrawSelection(Canvas* canvas) {
1357 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1343 const std::vector<Rect> sel = GetSubstringBounds(selection());
1358 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1344 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1359 canvas->FillRect(*i, selection_background_focused_color_); 1345 canvas->FillRect(*i, selection_background_focused_color_);
1360 } 1346 }
1361 1347
1362 } // namespace gfx 1348 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698