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" |
11 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "third_party/icu/source/common/unicode/rbbi.h" | 16 #include "third_party/icu/source/common/unicode/rbbi.h" |
17 #include "third_party/icu/source/common/unicode/utf16.h" | 17 #include "third_party/icu/source/common/unicode/utf16.h" |
18 #include "third_party/skia/include/core/SkTypeface.h" | 18 #include "third_party/skia/include/core/SkTypeface.h" |
19 #include "third_party/skia/include/effects/SkGradientShader.h" | 19 #include "third_party/skia/include/effects/SkGradientShader.h" |
20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/insets.h" | 21 #include "ui/gfx/insets.h" |
22 #include "ui/gfx/render_text_harfbuzz.h" | 22 #include "ui/gfx/render_text_harfbuzz.h" |
23 #include "ui/gfx/scoped_canvas.h" | 23 #include "ui/gfx/scoped_canvas.h" |
24 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
25 #include "ui/gfx/switches.h" | 25 #include "ui/gfx/switches.h" |
26 #include "ui/gfx/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
27 #include "ui/gfx/text_utils.h" | 27 #include "ui/gfx/text_utils.h" |
28 #include "ui/gfx/utf16_indexing.h" | 28 #include "ui/gfx/utf16_indexing.h" |
29 | 29 |
30 #if defined(OS_WIN) | |
31 #include "base/win/windows_version.h" | |
32 #endif | |
33 | |
30 namespace gfx { | 34 namespace gfx { |
31 | 35 |
32 namespace { | 36 namespace { |
33 | 37 |
34 // All chars are replaced by this char when the password style is set. | 38 // All chars are replaced by this char when the password style is set. |
35 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' | 39 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' |
36 // that's available in the font (find_invisible_char() in gtkentry.c). | 40 // that's available in the font (find_invisible_char() in gtkentry.c). |
37 const base::char16 kPasswordReplacementChar = '*'; | 41 const base::char16 kPasswordReplacementChar = '*'; |
38 | 42 |
39 // Default color used for the text and cursor. | 43 // Default color used for the text and cursor. |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 paint->setAutohinted(params.autohinter); | 390 paint->setAutohinted(params.autohinter); |
387 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); | 391 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); |
388 } | 392 } |
389 | 393 |
390 } // namespace internal | 394 } // namespace internal |
391 | 395 |
392 RenderText::~RenderText() { | 396 RenderText::~RenderText() { |
393 } | 397 } |
394 | 398 |
395 RenderText* RenderText::CreateInstance() { | 399 RenderText* RenderText::CreateInstance() { |
396 #if defined(OS_MACOSX) && defined(TOOLKIT_VIEWS) | 400 #if defined(OS_WIN) |
397 // Use the more complete HarfBuzz implementation for Views controls on Mac. | 401 bool default_is_harfbuzz = base::win::OSInfo::GetInstance()->version() <= |
402 base::win::Version::VERSION_WIN8; | |
msw
2014/10/05 17:58:21
Are you sure the sizing problem only affects windo
ckocagil
2014/10/15 19:50:44
This should be fixed on both as of https://crrev.c
| |
403 #elif defined(OS_CHROMEOS) | |
404 bool default_is_harfbuzz = false; | |
msw
2014/10/05 17:58:21
What is the chrome os blocker(s)? Add a comment re
ckocagil
2014/10/15 19:50:44
Done.
| |
405 #else | |
406 bool default_is_harfbuzz = true; | |
407 #endif | |
408 | |
409 if (!default_is_harfbuzz || CommandLine::ForCurrentProcess()->HasSwitch( | |
410 switches::kDisableHarfBuzzRenderText)) { | |
411 return CreateNativeInstance(); | |
412 } | |
398 return new RenderTextHarfBuzz; | 413 return new RenderTextHarfBuzz; |
399 #else | |
400 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
401 switches::kEnableHarfBuzzRenderText)) { | |
402 return new RenderTextHarfBuzz; | |
403 } | |
404 return CreateNativeInstance(); | |
405 #endif | |
406 } | 414 } |
407 | 415 |
408 void RenderText::SetText(const base::string16& text) { | 416 void RenderText::SetText(const base::string16& text) { |
409 DCHECK(!composition_range_.IsValid()); | 417 DCHECK(!composition_range_.IsValid()); |
410 if (text_ == text) | 418 if (text_ == text) |
411 return; | 419 return; |
412 text_ = text; | 420 text_ = text; |
413 | 421 |
414 // Adjust ranged styles and colors to accommodate a new text length. | 422 // Adjust ranged styles and colors to accommodate a new text length. |
415 // Clear style ranges as they might break new text graphemes and apply | 423 // Clear style ranges as they might break new text graphemes and apply |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 SetDisplayOffset(display_offset_.x() + delta_x); | 1386 SetDisplayOffset(display_offset_.x() + delta_x); |
1379 } | 1387 } |
1380 | 1388 |
1381 void RenderText::DrawSelection(Canvas* canvas) { | 1389 void RenderText::DrawSelection(Canvas* canvas) { |
1382 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1390 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1383 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1391 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1384 canvas->FillRect(*i, selection_background_focused_color_); | 1392 canvas->FillRect(*i, selection_background_focused_color_); |
1385 } | 1393 } |
1386 | 1394 |
1387 } // namespace gfx | 1395 } // namespace gfx |
OLD | NEW |