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

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

Issue 795933009: [AiS] for desktop, two lines and font sytles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using SK color macros Created 5 years, 9 months 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 438
439 // static 439 // static
440 RenderText* RenderText::CreateInstanceForEditing() { 440 RenderText* RenderText::CreateInstanceForEditing() {
441 return new RenderTextHarfBuzz; 441 return new RenderTextHarfBuzz;
442 } 442 }
443 443
444 void RenderText::SetText(const base::string16& text) { 444 void RenderText::SetText(const base::string16& text) {
445 DCHECK(!composition_range_.IsValid()); 445 DCHECK(!composition_range_.IsValid());
446 if (text_ == text) 446 if (text_ == text)
447 return; 447 return;
448 text_ = text; 448 text_.clear();
449 AppendText(text);
449 450
450 // Adjust ranged styles, baselines, and colors to accommodate a new text 451 // Clear style ranges as they might break new text graphemes and apply
451 // length. Clear style ranges as they might break new text graphemes and apply
452 // the first style to the whole text instead. 452 // the first style to the whole text instead.
453 const size_t text_length = text_.length(); 453 colors_.SetValue(colors_.breaks().begin()->second);
454 colors_.SetMax(text_length);
455 baselines_.SetValue(baselines_.breaks().begin()->second); 454 baselines_.SetValue(baselines_.breaks().begin()->second);
456 baselines_.SetMax(text_length);
457 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) { 455 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) {
458 BreakList<bool>& break_list = styles_[style]; 456 BreakList<bool>& break_list = styles_[style];
459 break_list.SetValue(break_list.breaks().begin()->second); 457 break_list.SetValue(break_list.breaks().begin()->second);
460 break_list.SetMax(text_length);
461 } 458 }
462 cached_bounds_and_offset_valid_ = false;
463 459
464 // Reset selection model. SetText should always followed by SetSelectionModel 460 // Reset selection model. SetText should always followed by SetSelectionModel
465 // or SetCursorPosition in upper layer. 461 // or SetCursorPosition in upper layer.
466 SetSelectionModel(SelectionModel()); 462 SetSelectionModel(SelectionModel());
467 463
468 // Invalidate the cached text direction if it depends on the text contents. 464 // Invalidate the cached text direction if it depends on the text contents.
469 if (directionality_mode_ == DIRECTIONALITY_FROM_TEXT) 465 if (directionality_mode_ == DIRECTIONALITY_FROM_TEXT)
470 text_direction_ = base::i18n::UNKNOWN_DIRECTION; 466 text_direction_ = base::i18n::UNKNOWN_DIRECTION;
467 }
471 468
469 void RenderText::AppendText(const base::string16& text) {
470 text_ += text;
471 // Adjust ranged styles and colors to accommodate a new text length.
472 const size_t text_length = text_.length();
473 colors_.SetMax(text_length);
474 baselines_.SetMax(text_length);
475 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) {
476 BreakList<bool>& break_list = styles_[style];
477 break_list.SetMax(text_length);
478 }
479 cached_bounds_and_offset_valid_ = false;
472 obscured_reveal_index_ = -1; 480 obscured_reveal_index_ = -1;
473 OnTextAttributeChanged(); 481 OnTextAttributeChanged();
474 } 482 }
475 483
476 void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) { 484 void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) {
477 if (horizontal_alignment_ != alignment) { 485 if (horizontal_alignment_ != alignment) {
478 horizontal_alignment_ = alignment; 486 horizontal_alignment_ = alignment;
479 display_offset_ = Vector2d(); 487 display_offset_ = Vector2d();
480 cached_bounds_and_offset_valid_ = false; 488 cached_bounds_and_offset_valid_ = false;
481 } 489 }
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 1504
1497 SetDisplayOffset(display_offset_.x() + delta_x); 1505 SetDisplayOffset(display_offset_.x() + delta_x);
1498 } 1506 }
1499 1507
1500 void RenderText::DrawSelection(Canvas* canvas) { 1508 void RenderText::DrawSelection(Canvas* canvas) {
1501 for (const Rect& s : GetSubstringBounds(selection())) 1509 for (const Rect& s : GetSubstringBounds(selection()))
1502 canvas->FillRect(s, selection_background_focused_color_); 1510 canvas->FillRect(s, selection_background_focused_color_);
1503 } 1511 }
1504 1512
1505 } // namespace gfx 1513 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698