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 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 void RenderText::SetVerticalAlignment(VerticalAlignment alignment) { | 341 void RenderText::SetVerticalAlignment(VerticalAlignment alignment) { |
342 if (vertical_alignment_ != alignment) { | 342 if (vertical_alignment_ != alignment) { |
343 vertical_alignment_ = alignment; | 343 vertical_alignment_ = alignment; |
344 display_offset_ = Vector2d(); | 344 display_offset_ = Vector2d(); |
345 cached_bounds_and_offset_valid_ = false; | 345 cached_bounds_and_offset_valid_ = false; |
346 } | 346 } |
347 } | 347 } |
348 | 348 |
349 void RenderText::SetFontList(const FontList& font_list) { | 349 void RenderText::SetFontList(const FontList& font_list) { |
350 font_list_ = font_list; | 350 font_list_ = font_list; |
351 // Cache the height and baseline of the font list. | |
352 font_list_height_ = font_list_.GetHeight(); | |
msw
2013/07/11 22:47:29
Init these values to 0 in the ctor.
Yuki
2013/07/12 08:25:53
Done.
| |
353 font_list_baseline_ = font_list_.GetBaseline(); | |
351 cached_bounds_and_offset_valid_ = false; | 354 cached_bounds_and_offset_valid_ = false; |
352 ResetLayout(); | 355 ResetLayout(); |
353 } | 356 } |
354 | 357 |
355 void RenderText::SetFont(const Font& font) { | 358 void RenderText::SetFont(const Font& font) { |
356 SetFontList(FontList(font)); | 359 SetFontList(FontList(font)); |
357 } | 360 } |
358 | 361 |
359 void RenderText::SetFontSize(int size) { | 362 void RenderText::SetFontSize(int size) { |
360 font_list_ = font_list_.DeriveFontListWithSize(size); | 363 SetFontList(font_list_.DeriveFontListWithSize(size)); |
361 cached_bounds_and_offset_valid_ = false; | |
362 ResetLayout(); | |
363 } | 364 } |
364 | 365 |
365 void RenderText::SetCursorEnabled(bool cursor_enabled) { | 366 void RenderText::SetCursorEnabled(bool cursor_enabled) { |
366 cursor_enabled_ = cursor_enabled; | 367 cursor_enabled_ = cursor_enabled; |
367 cached_bounds_and_offset_valid_ = false; | 368 cached_bounds_and_offset_valid_ = false; |
368 } | 369 } |
369 | 370 |
370 const Font& RenderText::GetFont() const { | 371 const Font& RenderText::GetFont() const { |
371 return font_list_.GetFonts()[0]; | 372 return font_list_.GetFonts()[0]; |
372 } | 373 } |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 cursor_bounds_ += delta_offset; | 1017 cursor_bounds_ += delta_offset; |
1017 } | 1018 } |
1018 | 1019 |
1019 void RenderText::DrawSelection(Canvas* canvas) { | 1020 void RenderText::DrawSelection(Canvas* canvas) { |
1020 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1021 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1021 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1022 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1022 canvas->FillRect(*i, selection_background_focused_color_); | 1023 canvas->FillRect(*i, selection_background_focused_color_); |
1023 } | 1024 } |
1024 | 1025 |
1025 } // namespace gfx | 1026 } // namespace gfx |
OLD | NEW |