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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 198 } |
199 | 199 |
200 SkiaTextRenderer::~SkiaTextRenderer() { | 200 SkiaTextRenderer::~SkiaTextRenderer() { |
201 } | 201 } |
202 | 202 |
203 void SkiaTextRenderer::SetDrawLooper(SkDrawLooper* draw_looper) { | 203 void SkiaTextRenderer::SetDrawLooper(SkDrawLooper* draw_looper) { |
204 paint_.setLooper(draw_looper); | 204 paint_.setLooper(draw_looper); |
205 } | 205 } |
206 | 206 |
207 void SkiaTextRenderer::SetFontRenderParams(const FontRenderParams& params, | 207 void SkiaTextRenderer::SetFontRenderParams(const FontRenderParams& params, |
208 bool background_is_transparent) { | 208 bool subpixel_rendering_enabled) { |
209 ApplyRenderParams(params, background_is_transparent, &paint_); | 209 ApplyRenderParams(params, subpixel_rendering_enabled, &paint_); |
210 } | 210 } |
211 | 211 |
212 void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) { | 212 void SkiaTextRenderer::SetTypeface(SkTypeface* typeface) { |
213 paint_.setTypeface(typeface); | 213 paint_.setTypeface(typeface); |
214 } | 214 } |
215 | 215 |
216 void SkiaTextRenderer::SetTextSize(SkScalar size) { | 216 void SkiaTextRenderer::SetTextSize(SkScalar size) { |
217 paint_.setTextSize(size); | 217 paint_.setTextSize(size); |
218 } | 218 } |
219 | 219 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 381 |
382 Line::~Line() {} | 382 Line::~Line() {} |
383 | 383 |
384 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family, | 384 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family, |
385 int style) { | 385 int style) { |
386 SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style); | 386 SkTypeface::Style skia_style = ConvertFontStyleToSkiaTypefaceStyle(style); |
387 return skia::AdoptRef(SkTypeface::CreateFromName(family.c_str(), skia_style)); | 387 return skia::AdoptRef(SkTypeface::CreateFromName(family.c_str(), skia_style)); |
388 } | 388 } |
389 | 389 |
390 void ApplyRenderParams(const FontRenderParams& params, | 390 void ApplyRenderParams(const FontRenderParams& params, |
391 bool background_is_transparent, | 391 bool subpixel_rendering_enabled, |
392 SkPaint* paint) { | 392 SkPaint* paint) { |
393 paint->setAntiAlias(params.antialiasing); | 393 paint->setAntiAlias(params.antialiasing); |
394 paint->setLCDRenderText(!background_is_transparent && | 394 paint->setLCDRenderText(subpixel_rendering_enabled && |
395 params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE); | 395 params.subpixel_rendering != FontRenderParams::SUBPIXEL_RENDERING_NONE); |
396 paint->setSubpixelText(params.subpixel_positioning); | 396 paint->setSubpixelText(params.subpixel_positioning); |
397 paint->setAutohinted(params.autohinter); | 397 paint->setAutohinted(params.autohinter); |
398 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); | 398 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); |
399 } | 399 } |
400 | 400 |
401 } // namespace internal | 401 } // namespace internal |
402 | 402 |
403 RenderText::~RenderText() { | 403 RenderText::~RenderText() { |
404 } | 404 } |
405 | 405 |
| 406 // static |
406 RenderText* RenderText::CreateInstance() { | 407 RenderText* RenderText::CreateInstance() { |
407 #if defined(OS_MACOSX) | 408 #if defined(OS_MACOSX) |
408 static const bool use_native = | 409 static const bool use_native = |
409 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 410 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
410 switches::kEnableHarfBuzzRenderText); | 411 switches::kEnableHarfBuzzRenderText); |
411 if (use_native) | 412 if (use_native) |
412 return new RenderTextMac; | 413 return new RenderTextMac; |
413 #endif // defined(OS_MACOSX) | 414 #endif // defined(OS_MACOSX) |
414 return new RenderTextHarfBuzz; | 415 return new RenderTextHarfBuzz; |
415 } | 416 } |
416 | 417 |
| 418 // static |
417 RenderText* RenderText::CreateInstanceForEditing() { | 419 RenderText* RenderText::CreateInstanceForEditing() { |
418 return new RenderTextHarfBuzz; | 420 return new RenderTextHarfBuzz; |
419 } | 421 } |
420 | 422 |
421 void RenderText::SetText(const base::string16& text) { | 423 void RenderText::SetText(const base::string16& text) { |
422 DCHECK(!composition_range_.IsValid()); | 424 DCHECK(!composition_range_.IsValid()); |
423 if (text_ == text) | 425 if (text_ == text) |
424 return; | 426 return; |
425 text_ = text; | 427 text_ = text; |
426 | 428 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 colors_(kDefaultColor), | 915 colors_(kDefaultColor), |
914 styles_(NUM_TEXT_STYLES), | 916 styles_(NUM_TEXT_STYLES), |
915 composition_and_selection_styles_applied_(false), | 917 composition_and_selection_styles_applied_(false), |
916 obscured_(false), | 918 obscured_(false), |
917 obscured_reveal_index_(-1), | 919 obscured_reveal_index_(-1), |
918 truncate_length_(0), | 920 truncate_length_(0), |
919 elide_behavior_(NO_ELIDE), | 921 elide_behavior_(NO_ELIDE), |
920 text_elided_(false), | 922 text_elided_(false), |
921 min_line_height_(0), | 923 min_line_height_(0), |
922 multiline_(false), | 924 multiline_(false), |
923 background_is_transparent_(false), | 925 subpixel_rendering_enabled_(true), |
924 clip_to_display_rect_(true), | 926 clip_to_display_rect_(true), |
925 baseline_(kInvalidBaseline), | 927 baseline_(kInvalidBaseline), |
926 cached_bounds_and_offset_valid_(false) { | 928 cached_bounds_and_offset_valid_(false) { |
927 } | 929 } |
928 | 930 |
929 SelectionModel RenderText::GetAdjacentSelectionModel( | 931 SelectionModel RenderText::GetAdjacentSelectionModel( |
930 const SelectionModel& current, | 932 const SelectionModel& current, |
931 BreakType break_type, | 933 BreakType break_type, |
932 VisualCursorDirection direction) { | 934 VisualCursorDirection direction) { |
933 EnsureLayout(); | 935 EnsureLayout(); |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1459 |
1458 SetDisplayOffset(display_offset_.x() + delta_x); | 1460 SetDisplayOffset(display_offset_.x() + delta_x); |
1459 } | 1461 } |
1460 | 1462 |
1461 void RenderText::DrawSelection(Canvas* canvas) { | 1463 void RenderText::DrawSelection(Canvas* canvas) { |
1462 for (const Rect& s : GetSubstringBounds(selection())) | 1464 for (const Rect& s : GetSubstringBounds(selection())) |
1463 canvas->FillRect(s, selection_background_focused_color_); | 1465 canvas->FillRect(s, selection_background_focused_color_); |
1464 } | 1466 } |
1465 | 1467 |
1466 } // namespace gfx | 1468 } // namespace gfx |
OLD | NEW |