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

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

Issue 779793006: MacViews: Use RenderTextHarfBuzz only for Textfields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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 <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
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)
Alexei Svitkine (slow) 2014/12/08 15:53:10 Is this change needed anymore?
Andre 2014/12/08 18:33:45 I think so. TOOLKIT_VIEWS will be turned on soon f
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 return new RenderTextHarfBuzz;
msw 2014/12/08 19:27:50 Shouldn't this respect kDisableHarfBuzzRenderText?
Andre 2014/12/08 19:51:32 Done.
413 }
414
411 void RenderText::SetText(const base::string16& text) { 415 void RenderText::SetText(const base::string16& text) {
412 DCHECK(!composition_range_.IsValid()); 416 DCHECK(!composition_range_.IsValid());
413 if (text_ == text) 417 if (text_ == text)
414 return; 418 return;
415 text_ = text; 419 text_ = text;
416 420
417 // Adjust ranged styles and colors to accommodate a new text length. 421 // Adjust ranged styles and colors to accommodate a new text length.
418 // Clear style ranges as they might break new text graphemes and apply 422 // Clear style ranges as they might break new text graphemes and apply
419 // the first style to the whole text instead. 423 // the first style to the whole text instead.
420 const size_t text_length = text_.length(); 424 const size_t text_length = text_.length();
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1230
1227 base::string16 RenderText::Elide(const base::string16& text, 1231 base::string16 RenderText::Elide(const base::string16& text,
1228 float available_width, 1232 float available_width,
1229 ElideBehavior behavior) { 1233 ElideBehavior behavior) {
1230 if (available_width <= 0 || text.empty()) 1234 if (available_width <= 0 || text.empty())
1231 return base::string16(); 1235 return base::string16();
1232 if (behavior == ELIDE_EMAIL) 1236 if (behavior == ELIDE_EMAIL)
1233 return ElideEmail(text, available_width); 1237 return ElideEmail(text, available_width);
1234 1238
1235 // Create a RenderText copy with attributes that affect the rendering width. 1239 // Create a RenderText copy with attributes that affect the rendering width.
1236 scoped_ptr<RenderText> render_text(CreateInstance()); 1240 scoped_ptr<RenderText> render_text = NewInstance();
1237 render_text->SetFontList(font_list_); 1241 render_text->SetFontList(font_list_);
1238 render_text->SetDirectionalityMode(directionality_mode_); 1242 render_text->SetDirectionalityMode(directionality_mode_);
1239 render_text->SetCursorEnabled(cursor_enabled_); 1243 render_text->SetCursorEnabled(cursor_enabled_);
1240 render_text->set_truncate_length(truncate_length_); 1244 render_text->set_truncate_length(truncate_length_);
1241 render_text->styles_ = styles_; 1245 render_text->styles_ = styles_;
1242 render_text->colors_ = colors_; 1246 render_text->colors_ = colors_;
1243 render_text->SetText(text); 1247 render_text->SetText(text);
1244 if (render_text->GetContentWidth() <= available_width) 1248 if (render_text->GetContentWidth() <= available_width)
1245 return text; 1249 return text;
1246 1250
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 SetDisplayOffset(display_offset_.x() + delta_x); 1409 SetDisplayOffset(display_offset_.x() + delta_x);
1406 } 1410 }
1407 1411
1408 void RenderText::DrawSelection(Canvas* canvas) { 1412 void RenderText::DrawSelection(Canvas* canvas) {
1409 const std::vector<Rect> sel = GetSubstringBounds(selection()); 1413 const std::vector<Rect> sel = GetSubstringBounds(selection());
1410 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) 1414 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i)
1411 canvas->FillRect(*i, selection_background_focused_color_); 1415 canvas->FillRect(*i, selection_background_focused_color_);
1412 } 1416 }
1413 1417
1414 } // namespace gfx 1418 } // namespace gfx
OLDNEW
« ui/gfx/render_text.h ('K') | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698