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

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

Issue 707013004: Fix clipping RenderTextHarfBuzz text on Windows 8. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring. Created 6 years, 1 month 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 | « 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 10 matching lines...) Expand all
21 #include "ui/gfx/geometry/safe_integer_conversions.h" 21 #include "ui/gfx/geometry/safe_integer_conversions.h"
22 #include "ui/gfx/insets.h" 22 #include "ui/gfx/insets.h"
23 #include "ui/gfx/render_text_harfbuzz.h" 23 #include "ui/gfx/render_text_harfbuzz.h"
24 #include "ui/gfx/scoped_canvas.h" 24 #include "ui/gfx/scoped_canvas.h"
25 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
26 #include "ui/gfx/switches.h" 26 #include "ui/gfx/switches.h"
27 #include "ui/gfx/text_elider.h" 27 #include "ui/gfx/text_elider.h"
28 #include "ui/gfx/text_utils.h" 28 #include "ui/gfx/text_utils.h"
29 #include "ui/gfx/utf16_indexing.h" 29 #include "ui/gfx/utf16_indexing.h"
30 30
31 #if defined(OS_WIN)
32 #include "base/win/windows_version.h"
33 #endif
34
31 namespace gfx { 35 namespace gfx {
32 36
33 namespace { 37 namespace {
34 38
35 // All chars are replaced by this char when the password style is set. 39 // All chars are replaced by this char when the password style is set.
36 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' 40 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*'
37 // that's available in the font (find_invisible_char() in gtkentry.c). 41 // that's available in the font (find_invisible_char() in gtkentry.c).
38 const base::char16 kPasswordReplacementChar = '*'; 42 const base::char16 kPasswordReplacementChar = '*';
39 43
40 // Default color used for the text and cursor. 44 // Default color used for the text and cursor.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 FontRenderParams::Hinting params_hinting) { 166 FontRenderParams::Hinting params_hinting) {
163 switch (params_hinting) { 167 switch (params_hinting) {
164 case FontRenderParams::HINTING_NONE: return SkPaint::kNo_Hinting; 168 case FontRenderParams::HINTING_NONE: return SkPaint::kNo_Hinting;
165 case FontRenderParams::HINTING_SLIGHT: return SkPaint::kSlight_Hinting; 169 case FontRenderParams::HINTING_SLIGHT: return SkPaint::kSlight_Hinting;
166 case FontRenderParams::HINTING_MEDIUM: return SkPaint::kNormal_Hinting; 170 case FontRenderParams::HINTING_MEDIUM: return SkPaint::kNormal_Hinting;
167 case FontRenderParams::HINTING_FULL: return SkPaint::kFull_Hinting; 171 case FontRenderParams::HINTING_FULL: return SkPaint::kFull_Hinting;
168 } 172 }
169 return SkPaint::kNo_Hinting; 173 return SkPaint::kNo_Hinting;
170 } 174 }
171 175
176 // Returns true if the RenderTextHarfBuzz implementation should be used.
177 bool UseHarfBuzz() {
178 static const bool kUseHarfBuzz =
179 !CommandLine::ForCurrentProcess()->HasSwitch(
180 switches::kDisableHarfBuzzRenderText);
181 return kUseHarfBuzz;
182 }
183
184 // Returns the padding left of centered text used to match legacy behavior.
185 // TODO(msw|ckocagil): This may not be needed at all for RenderTextHarfBuzz.
186 int GetLeftOfCenterPadding() {
187 #if defined(OS_WIN)
188 if (UseHarfBuzz() && base::win::GetVersion() > base::win::VERSION_WIN7)
189 return 0;
190 #endif
191 return 1;
192 }
193
172 } // namespace 194 } // namespace
173 195
174 namespace internal { 196 namespace internal {
175 197
176 // Value of |underline_thickness_| that indicates that underline metrics have 198 // Value of |underline_thickness_| that indicates that underline metrics have
177 // not been set explicitly. 199 // not been set explicitly.
178 const SkScalar kUnderlineMetricsNotSet = -1.0f; 200 const SkScalar kUnderlineMetricsNotSet = -1.0f;
179 201
180 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) 202 SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas)
181 : canvas_(canvas), 203 : canvas_(canvas),
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 paint->setAutohinted(params.autohinter); 413 paint->setAutohinted(params.autohinter);
392 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); 414 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting));
393 } 415 }
394 416
395 } // namespace internal 417 } // namespace internal
396 418
397 RenderText::~RenderText() { 419 RenderText::~RenderText() {
398 } 420 }
399 421
400 RenderText* RenderText::CreateInstance() { 422 RenderText* RenderText::CreateInstance() {
401 return CommandLine::ForCurrentProcess()->HasSwitch( 423 return UseHarfBuzz() ? new RenderTextHarfBuzz() : CreateNativeInstance();
402 switches::kDisableHarfBuzzRenderText) ? CreateNativeInstance() :
403 new RenderTextHarfBuzz;
404 } 424 }
405 425
406 void RenderText::SetText(const base::string16& text) { 426 void RenderText::SetText(const base::string16& text) {
407 DCHECK(!composition_range_.IsValid()); 427 DCHECK(!composition_range_.IsValid());
408 if (text_ == text) 428 if (text_ == text)
409 return; 429 return;
410 text_ = text; 430 text_ = text;
411 431
412 // Adjust ranged styles and colors to accommodate a new text length. 432 // Adjust ranged styles and colors to accommodate a new text length.
413 // Clear style ranges as they might break new text graphemes and apply 433 // Clear style ranges as they might break new text graphemes and apply
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 Vector2d offset; 1085 Vector2d offset;
1066 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); 1086 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment();
1067 if (horizontal_alignment != ALIGN_LEFT) { 1087 if (horizontal_alignment != ALIGN_LEFT) {
1068 #if defined(OS_WIN) 1088 #if defined(OS_WIN)
1069 const int width = lines_[line_number].size.width() + 1089 const int width = lines_[line_number].size.width() +
1070 (cursor_enabled_ ? 1 : 0); 1090 (cursor_enabled_ ? 1 : 0);
1071 #else 1091 #else
1072 const int width = GetContentWidth(); 1092 const int width = GetContentWidth();
1073 #endif 1093 #endif
1074 offset.set_x(display_rect().width() - width); 1094 offset.set_x(display_rect().width() - width);
1075 // Put any extra margin pixel on the left to match legacy behavior. 1095 // Put any extra margin pixel on the left to match some legacy behaviors.
1096 static const int kLeftOfCenterPadding = GetLeftOfCenterPadding();
1076 if (horizontal_alignment == ALIGN_CENTER) 1097 if (horizontal_alignment == ALIGN_CENTER)
1077 offset.set_x((offset.x() + 1) / 2); 1098 offset.set_x((offset.x() + kLeftOfCenterPadding) / 2);
Peter Kasting 2014/11/06 23:14:47 I don't understand why the previous code was causi
msw 2014/11/06 23:48:44 You're right, width+1 in RenderTextHarfBuzz::GetSt
1078 } 1099 }
1079 1100
1080 // Vertically center the text. 1101 // Vertically center the text.
1081 if (multiline_) { 1102 if (multiline_) {
1082 const int text_height = lines_.back().preceding_heights + 1103 const int text_height = lines_.back().preceding_heights +
1083 lines_.back().size.height(); 1104 lines_.back().size.height();
1084 offset.set_y((display_rect_.height() - text_height) / 2); 1105 offset.set_y((display_rect_.height() - text_height) / 2);
1085 } else { 1106 } else {
1086 offset.set_y(GetBaseline() - GetLayoutTextBaseline()); 1107 offset.set_y(GetBaseline() - GetLayoutTextBaseline());
1087 } 1108 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 SetDisplayOffset(display_offset_.x() + delta_x); 1419 SetDisplayOffset(display_offset_.x() + delta_x);
1399 } 1420 }
1400 1421
1401 void RenderText::DrawSelection(Canvas* canvas) { 1422 void RenderText::DrawSelection(Canvas* canvas) {
1402 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1423 const std::vector<Rect> sel = GetSubstringBounds(selection());
1403 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1424 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1404 canvas->FillRect(*i, selection_background_focused_color_); 1425 canvas->FillRect(*i, selection_background_focused_color_);
1405 } 1426 }
1406 1427
1407 } // namespace gfx 1428 } // 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