| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 paint->setAutohinted(params.autohinter); | 391 paint->setAutohinted(params.autohinter); |
| 392 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); | 392 paint->setHinting(FontRenderParamsHintingToSkPaintHinting(params.hinting)); |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace internal | 395 } // namespace internal |
| 396 | 396 |
| 397 RenderText::~RenderText() { | 397 RenderText::~RenderText() { |
| 398 } | 398 } |
| 399 | 399 |
| 400 RenderText* RenderText::CreateInstance() { | 400 RenderText* RenderText::CreateInstance() { |
| 401 #if defined(OS_MACOSX) && !defined(TOOLKIT_VIEWS) | 401 #if defined(OS_MACOSX) |
| 402 static const bool use_harfbuzz = CommandLine::ForCurrentProcess()-> | 402 static const bool use_harfbuzz = CommandLine::ForCurrentProcess()-> |
| 403 HasSwitch(switches::kEnableHarfBuzzRenderText); | 403 HasSwitch(switches::kEnableHarfBuzzRenderText); |
| 404 #else | 404 #else |
| 405 static const bool use_harfbuzz = !CommandLine::ForCurrentProcess()-> | 405 static const bool use_harfbuzz = !CommandLine::ForCurrentProcess()-> |
| 406 HasSwitch(switches::kDisableHarfBuzzRenderText); | 406 HasSwitch(switches::kDisableHarfBuzzRenderText); |
| 407 #endif | 407 #endif |
| 408 return use_harfbuzz ? new RenderTextHarfBuzz : CreateNativeInstance(); | 408 return use_harfbuzz ? new RenderTextHarfBuzz : CreateNativeInstance(); |
| 409 } | 409 } |
| 410 | 410 |
| 411 RenderText* RenderText::CreateInstanceForEditing() { |
| 412 static const bool use_harfbuzz = !CommandLine::ForCurrentProcess()-> |
| 413 HasSwitch(switches::kDisableHarfBuzzRenderText); |
| 414 return use_harfbuzz ? new RenderTextHarfBuzz : CreateNativeInstance(); |
| 415 } |
| 416 |
| 411 void RenderText::SetText(const base::string16& text) { | 417 void RenderText::SetText(const base::string16& text) { |
| 412 DCHECK(!composition_range_.IsValid()); | 418 DCHECK(!composition_range_.IsValid()); |
| 413 if (text_ == text) | 419 if (text_ == text) |
| 414 return; | 420 return; |
| 415 text_ = text; | 421 text_ = text; |
| 416 | 422 |
| 417 // Adjust ranged styles and colors to accommodate a new text length. | 423 // Adjust ranged styles and colors to accommodate a new text length. |
| 418 // Clear style ranges as they might break new text graphemes and apply | 424 // Clear style ranges as they might break new text graphemes and apply |
| 419 // the first style to the whole text instead. | 425 // the first style to the whole text instead. |
| 420 const size_t text_length = text_.length(); | 426 const size_t text_length = text_.length(); |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 | 1232 |
| 1227 base::string16 RenderText::Elide(const base::string16& text, | 1233 base::string16 RenderText::Elide(const base::string16& text, |
| 1228 float available_width, | 1234 float available_width, |
| 1229 ElideBehavior behavior) { | 1235 ElideBehavior behavior) { |
| 1230 if (available_width <= 0 || text.empty()) | 1236 if (available_width <= 0 || text.empty()) |
| 1231 return base::string16(); | 1237 return base::string16(); |
| 1232 if (behavior == ELIDE_EMAIL) | 1238 if (behavior == ELIDE_EMAIL) |
| 1233 return ElideEmail(text, available_width); | 1239 return ElideEmail(text, available_width); |
| 1234 | 1240 |
| 1235 // Create a RenderText copy with attributes that affect the rendering width. | 1241 // Create a RenderText copy with attributes that affect the rendering width. |
| 1236 scoped_ptr<RenderText> render_text(CreateInstance()); | 1242 scoped_ptr<RenderText> render_text = CreateInstanceOfSameType(); |
| 1237 render_text->SetFontList(font_list_); | 1243 render_text->SetFontList(font_list_); |
| 1238 render_text->SetDirectionalityMode(directionality_mode_); | 1244 render_text->SetDirectionalityMode(directionality_mode_); |
| 1239 render_text->SetCursorEnabled(cursor_enabled_); | 1245 render_text->SetCursorEnabled(cursor_enabled_); |
| 1240 render_text->set_truncate_length(truncate_length_); | 1246 render_text->set_truncate_length(truncate_length_); |
| 1241 render_text->styles_ = styles_; | 1247 render_text->styles_ = styles_; |
| 1242 render_text->colors_ = colors_; | 1248 render_text->colors_ = colors_; |
| 1243 render_text->SetText(text); | 1249 render_text->SetText(text); |
| 1244 if (render_text->GetContentWidth() <= available_width) | 1250 if (render_text->GetContentWidth() <= available_width) |
| 1245 return text; | 1251 return text; |
| 1246 | 1252 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 SetDisplayOffset(display_offset_.x() + delta_x); | 1411 SetDisplayOffset(display_offset_.x() + delta_x); |
| 1406 } | 1412 } |
| 1407 | 1413 |
| 1408 void RenderText::DrawSelection(Canvas* canvas) { | 1414 void RenderText::DrawSelection(Canvas* canvas) { |
| 1409 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1415 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
| 1410 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1416 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
| 1411 canvas->FillRect(*i, selection_background_focused_color_); | 1417 canvas->FillRect(*i, selection_background_focused_color_); |
| 1412 } | 1418 } |
| 1413 | 1419 |
| 1414 } // namespace gfx | 1420 } // namespace gfx |
| OLD | NEW |