| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/gfx/geometry/insets.h" | 21 #include "ui/gfx/geometry/insets.h" |
| 22 #include "ui/gfx/geometry/safe_integer_conversions.h" | 22 #include "ui/gfx/geometry/safe_integer_conversions.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_MACOSX) |
| 32 #include "ui/gfx/render_text_mac.h" |
| 33 #endif // defined(OS_MACOSX) |
| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); | 397 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); |
| 394 } | 398 } |
| 395 | 399 |
| 396 } // namespace internal | 400 } // namespace internal |
| 397 | 401 |
| 398 RenderText::~RenderText() { | 402 RenderText::~RenderText() { |
| 399 } | 403 } |
| 400 | 404 |
| 401 RenderText* RenderText::CreateInstance() { | 405 RenderText* RenderText::CreateInstance() { |
| 402 #if defined(OS_MACOSX) | 406 #if defined(OS_MACOSX) |
| 403 static const bool use_harfbuzz = | 407 static const bool use_native = |
| 404 base::CommandLine::ForCurrentProcess()->HasSwitch( | 408 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 405 switches::kEnableHarfBuzzRenderText); | 409 switches::kEnableHarfBuzzRenderText); |
| 406 #else | 410 if (use_native) |
| 407 static const bool use_harfbuzz = | 411 return new RenderTextMac; |
| 408 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 412 #endif // defined(OS_MACOSX) |
| 409 switches::kDisableHarfBuzzRenderText); | 413 return new RenderTextHarfBuzz; |
| 410 #endif | |
| 411 return use_harfbuzz ? new RenderTextHarfBuzz : CreateNativeInstance(); | |
| 412 } | 414 } |
| 413 | 415 |
| 414 RenderText* RenderText::CreateInstanceForEditing() { | 416 RenderText* RenderText::CreateInstanceForEditing() { |
| 415 static const bool use_harfbuzz = | 417 return new RenderTextHarfBuzz; |
| 416 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 417 switches::kDisableHarfBuzzRenderText); | |
| 418 return use_harfbuzz ? new RenderTextHarfBuzz : CreateNativeInstance(); | |
| 419 } | 418 } |
| 420 | 419 |
| 421 void RenderText::SetText(const base::string16& text) { | 420 void RenderText::SetText(const base::string16& text) { |
| 422 DCHECK(!composition_range_.IsValid()); | 421 DCHECK(!composition_range_.IsValid()); |
| 423 if (text_ == text) | 422 if (text_ == text) |
| 424 return; | 423 return; |
| 425 text_ = text; | 424 text_ = text; |
| 426 | 425 |
| 427 // Adjust ranged styles and colors to accommodate a new text length. | 426 // Adjust ranged styles and colors to accommodate a new text length. |
| 428 // Clear style ranges as they might break new text graphemes and apply | 427 // Clear style ranges as they might break new text graphemes and apply |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 SetDisplayOffset(display_offset_.x() + delta_x); | 1416 SetDisplayOffset(display_offset_.x() + delta_x); |
| 1418 } | 1417 } |
| 1419 | 1418 |
| 1420 void RenderText::DrawSelection(Canvas* canvas) { | 1419 void RenderText::DrawSelection(Canvas* canvas) { |
| 1421 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1420 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1422 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1421 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1423 canvas->FillRect(*i, selection_background_focused_color_); | 1422 canvas->FillRect(*i, selection_background_focused_color_); |
| 1424 } | 1423 } |
| 1425 | 1424 |
| 1426 } // namespace gfx | 1425 } // namespace gfx |
| OLD | NEW |