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

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

Issue 2439693002: MacViews: Use bullets for displaying obscured text. (Closed)
Patch Set: Make kPasswordReplacementChar constexpr. Created 4 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 | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | 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 <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <climits> 10 #include <climits>
(...skipping 27 matching lines...) Expand all
38 38
39 #if defined(OS_MACOSX) 39 #if defined(OS_MACOSX)
40 #include "third_party/skia/include/ports/SkTypeface_mac.h" 40 #include "third_party/skia/include/ports/SkTypeface_mac.h"
41 #include "ui/gfx/render_text_mac.h" 41 #include "ui/gfx/render_text_mac.h"
42 #endif // defined(OS_MACOSX) 42 #endif // defined(OS_MACOSX)
43 43
44 namespace gfx { 44 namespace gfx {
45 45
46 namespace { 46 namespace {
47 47
48 // All chars are replaced by this char when the password style is set.
49 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*'
50 // that's available in the font (find_invisible_char() in gtkentry.c).
51 const base::char16 kPasswordReplacementChar = '*';
52
53 // Default color used for the text and cursor. 48 // Default color used for the text and cursor.
54 const SkColor kDefaultColor = SK_ColorBLACK; 49 const SkColor kDefaultColor = SK_ColorBLACK;
55 50
56 // Default color used for drawing selection background. 51 // Default color used for drawing selection background.
57 const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY; 52 const SkColor kDefaultSelectionBackgroundColor = SK_ColorGRAY;
58 53
59 // Fraction of the text size to lower a strike through below the baseline. 54 // Fraction of the text size to lower a strike through below the baseline.
60 const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21); 55 const SkScalar kStrikeThroughOffset = (-SK_Scalar1 * 6 / 21);
61 // Fraction of the text size to lower an underline below the baseline. 56 // Fraction of the text size to lower an underline below the baseline.
62 const SkScalar kUnderlineOffset = (SK_Scalar1 / 9); 57 const SkScalar kUnderlineOffset = (SK_Scalar1 / 9);
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 paint->setAntiAlias(params.antialiasing); 414 paint->setAntiAlias(params.antialiasing);
420 paint->setLCDRenderText(!subpixel_rendering_suppressed && 415 paint->setLCDRenderText(!subpixel_rendering_suppressed &&
421 params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE); 416 params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE);
422 paint->setSubpixelText(params.subpixel_positioning); 417 paint->setSubpixelText(params.subpixel_positioning);
423 paint->setAutohinted(params.autohinter); 418 paint->setAutohinted(params.autohinter);
424 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); 419 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting));
425 } 420 }
426 421
427 } // namespace internal 422 } // namespace internal
428 423
424 // static
425 constexpr base::char16 RenderText::kPasswordReplacementChar;
sky 2016/10/25 16:40:16 Are you sure this is still needed?
tapted 2016/10/25 23:09:39 drive-by: It's needed if the address is ever taken
karandeepb 2016/10/26 00:02:44 Yeah the standard calls these usages "odr-used".
426
429 RenderText::~RenderText() { 427 RenderText::~RenderText() {
430 } 428 }
431 429
432 // static 430 // static
433 RenderText* RenderText::CreateInstance() { 431 RenderText* RenderText::CreateInstance() {
434 #if defined(OS_MACOSX) 432 #if defined(OS_MACOSX)
435 static const bool use_native = 433 static const bool use_native =
436 !base::CommandLine::ForCurrentProcess()->HasSwitch( 434 !base::CommandLine::ForCurrentProcess()->HasSwitch(
437 switches::kEnableHarfBuzzRenderText); 435 switches::kEnableHarfBuzzRenderText);
438 if (use_native) 436 if (use_native)
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 1397
1400 void RenderText::OnTextAttributeChanged() { 1398 void RenderText::OnTextAttributeChanged() {
1401 layout_text_.clear(); 1399 layout_text_.clear();
1402 display_text_.clear(); 1400 display_text_.clear();
1403 text_elided_ = false; 1401 text_elided_ = false;
1404 line_breaks_.SetMax(0); 1402 line_breaks_.SetMax(0);
1405 1403
1406 if (obscured_) { 1404 if (obscured_) {
1407 size_t obscured_text_length = 1405 size_t obscured_text_length =
1408 static_cast<size_t>(UTF16IndexToOffset(text_, 0, text_.length())); 1406 static_cast<size_t>(UTF16IndexToOffset(text_, 0, text_.length()));
1409 layout_text_.assign(obscured_text_length, kPasswordReplacementChar); 1407 layout_text_.assign(obscured_text_length,
1408 RenderText::kPasswordReplacementChar);
1410 1409
1411 if (obscured_reveal_index_ >= 0 && 1410 if (obscured_reveal_index_ >= 0 &&
1412 obscured_reveal_index_ < static_cast<int>(text_.length())) { 1411 obscured_reveal_index_ < static_cast<int>(text_.length())) {
1413 // Gets the index range in |text_| to be revealed. 1412 // Gets the index range in |text_| to be revealed.
1414 size_t start = obscured_reveal_index_; 1413 size_t start = obscured_reveal_index_;
1415 U16_SET_CP_START(text_.data(), 0, start); 1414 U16_SET_CP_START(text_.data(), 0, start);
1416 size_t end = start; 1415 size_t end = start;
1417 UChar32 unused_char; 1416 UChar32 unused_char;
1418 U16_NEXT(text_.data(), end, text_.length(), unused_char); 1417 U16_NEXT(text_.data(), end, text_.length(), unused_char);
1419 1418
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 1683
1685 for (; range_max < length; ++range_max) 1684 for (; range_max < length; ++range_max)
1686 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1685 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1687 break; 1686 break;
1688 1687
1689 return range.is_reversed() ? Range(range_max, range_min) 1688 return range.is_reversed() ? Range(range_max, range_min)
1690 : Range(range_min, range_max); 1689 : Range(range_min, range_max);
1691 } 1690 }
1692 1691
1693 } // namespace gfx 1692 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698