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

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

Issue 738363002: Enable subpixel positioning for UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-disable dwrite in tests, re-enable dwrite metrics Created 6 years 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
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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() { 715 VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() {
716 return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ? 716 return GetTextDirection() == base::i18n::LEFT_TO_RIGHT ?
717 CURSOR_RIGHT : CURSOR_LEFT; 717 CURSOR_RIGHT : CURSOR_LEFT;
718 } 718 }
719 719
720 SizeF RenderText::GetStringSizeF() { 720 SizeF RenderText::GetStringSizeF() {
721 return GetStringSize(); 721 return GetStringSize();
722 } 722 }
723 723
724 float RenderText::GetContentWidth() { 724 float RenderText::GetContentWidth() {
725 return GetStringSizeF().width() + (cursor_enabled_ ? 1 : 0); 725 return cursor_enabled_ ?
msw 2014/11/24 21:51:00 This change seems hinge on the cursor painting 1px
ckocagil 2014/11/25 01:39:47 Correct.
726 GetStringSize().width() + 1 : GetStringSizeF().width();
726 } 727 }
727 728
728 int RenderText::GetBaseline() { 729 int RenderText::GetBaseline() {
729 if (baseline_ == kInvalidBaseline) 730 if (baseline_ == kInvalidBaseline)
730 baseline_ = DetermineBaselineCenteringText(display_rect(), font_list()); 731 baseline_ = DetermineBaselineCenteringText(display_rect(), font_list());
731 DCHECK_NE(kInvalidBaseline, baseline_); 732 DCHECK_NE(kInvalidBaseline, baseline_);
732 return baseline_; 733 return baseline_;
733 } 734 }
734 735
735 void RenderText::Draw(Canvas* canvas) { 736 void RenderText::Draw(Canvas* canvas) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1065
1065 Vector2d RenderText::GetAlignmentOffset(size_t line_number) { 1066 Vector2d RenderText::GetAlignmentOffset(size_t line_number) {
1066 // TODO(ckocagil): Enable |lines_| usage in other platforms. 1067 // TODO(ckocagil): Enable |lines_| usage in other platforms.
1067 #if defined(OS_WIN) 1068 #if defined(OS_WIN)
1068 DCHECK_LT(line_number, lines_.size()); 1069 DCHECK_LT(line_number, lines_.size());
1069 #endif 1070 #endif
1070 Vector2d offset; 1071 Vector2d offset;
1071 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); 1072 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment();
1072 if (horizontal_alignment != ALIGN_LEFT) { 1073 if (horizontal_alignment != ALIGN_LEFT) {
1073 #if defined(OS_WIN) 1074 #if defined(OS_WIN)
1074 const int width = lines_[line_number].size.width() + 1075 const int width = std::ceil(lines_[line_number].size.width()) +
1075 (cursor_enabled_ ? 1 : 0); 1076 (cursor_enabled_ ? 1 : 0);
1076 #else 1077 #else
1077 const int width = GetContentWidth(); 1078 const int width = GetContentWidth();
1078 #endif 1079 #endif
1079 offset.set_x(display_rect().width() - width); 1080 offset.set_x(display_rect().width() - width);
1080 // Put any extra margin pixel on the left to match legacy behavior. 1081 // Put any extra margin pixel on the left to match legacy behavior.
1081 if (horizontal_alignment == ALIGN_CENTER) 1082 if (horizontal_alignment == ALIGN_CENTER)
1082 offset.set_x((offset.x() + 1) / 2); 1083 offset.set_x((offset.x() + 1) / 2);
1083 } 1084 }
1084 1085
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 SetDisplayOffset(display_offset_.x() + delta_x); 1404 SetDisplayOffset(display_offset_.x() + delta_x);
1404 } 1405 }
1405 1406
1406 void RenderText::DrawSelection(Canvas* canvas) { 1407 void RenderText::DrawSelection(Canvas* canvas) {
1407 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1408 const std::vector<Rect> sel = GetSubstringBounds(selection());
1408 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1409 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1409 canvas->FillRect(*i, selection_background_focused_color_); 1410 canvas->FillRect(*i, selection_background_focused_color_);
1410 } 1411 }
1411 1412
1412 } // namespace gfx 1413 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698