| 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/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 const gfx::RenderText* render_text = GetRenderTextForSelectionController(); | 614 const gfx::RenderText* render_text = GetRenderTextForSelectionController(); |
| 615 DCHECK(render_text); | 615 DCHECK(render_text); |
| 616 const base::string16 selected_text = | 616 const base::string16 selected_text = |
| 617 render_text->GetTextFromRange(render_text->selection()); | 617 render_text->GetTextFromRange(render_text->selection()); |
| 618 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_SELECTION) | 618 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_SELECTION) |
| 619 .WriteText(selected_text); | 619 .WriteText(selected_text); |
| 620 } | 620 } |
| 621 #endif | 621 #endif |
| 622 } | 622 } |
| 623 | 623 |
| 624 SkColor Label::GetSelectionTextColor() const { |
| 625 return actual_selection_text_color_; |
| 626 } |
| 627 |
| 628 SkColor Label::GetSelectionBackgroundColor() const { |
| 629 return selection_background_color_; |
| 630 } |
| 631 |
| 632 SkColor Label::GetSelectionBackgroundUnfocusedColor() const { |
| 633 // TODO(patricialor): Put a proper colour here. |
| 634 return SK_ColorBLUE; |
| 635 } |
| 636 |
| 637 void Label::OnWillChangeFocus(View* focused_before, View* focused_now) { |
| 638 // TODO(patricialor): Test labels! |
| 639 UpdateTextSelectionDrawState(this, focused_before, focused_now); |
| 640 SchedulePaint(); |
| 641 } |
| 642 |
| 624 const gfx::RenderText* Label::GetRenderTextForSelectionController() const { | 643 const gfx::RenderText* Label::GetRenderTextForSelectionController() const { |
| 625 if (!selectable()) | 644 if (!selectable()) |
| 626 return nullptr; | 645 return nullptr; |
| 627 MaybeBuildRenderTextLines(); | 646 MaybeBuildRenderTextLines(); |
| 628 | 647 |
| 629 // This may happen when the content bounds of the view are empty. | 648 // This may happen when the content bounds of the view are empty. |
| 630 if (lines_.empty()) | 649 if (lines_.empty()) |
| 631 return nullptr; | 650 return nullptr; |
| 632 | 651 |
| 633 DCHECK_EQ(1u, lines_.size()); | 652 DCHECK_EQ(1u, lines_.size()); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 SchedulePaint(); | 836 SchedulePaint(); |
| 818 } | 837 } |
| 819 | 838 |
| 820 void Label::ApplyTextColors() const { | 839 void Label::ApplyTextColors() const { |
| 821 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; | 840 SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_; |
| 822 bool subpixel_rendering_suppressed = | 841 bool subpixel_rendering_suppressed = |
| 823 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; | 842 SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_; |
| 824 for (size_t i = 0; i < lines_.size(); ++i) { | 843 for (size_t i = 0; i < lines_.size(); ++i) { |
| 825 lines_[i]->SetColor(color); | 844 lines_[i]->SetColor(color); |
| 826 lines_[i]->set_selection_color(actual_selection_text_color_); | 845 lines_[i]->set_selection_color(actual_selection_text_color_); |
| 827 lines_[i]->set_selection_background_focused_color( | 846 lines_[i]->set_selection_background_color(selection_background_color_); |
| 828 selection_background_color_); | |
| 829 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); | 847 lines_[i]->set_subpixel_rendering_suppressed(subpixel_rendering_suppressed); |
| 830 } | 848 } |
| 831 } | 849 } |
| 832 | 850 |
| 833 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | 851 void Label::UpdateColorsFromTheme(const ui::NativeTheme* theme) { |
| 834 if (!enabled_color_set_) { | 852 if (!enabled_color_set_) { |
| 835 requested_enabled_color_ = theme->GetSystemColor( | 853 requested_enabled_color_ = theme->GetSystemColor( |
| 836 ui::NativeTheme::kColorId_LabelEnabledColor); | 854 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 837 } | 855 } |
| 838 if (!disabled_color_set_) { | 856 if (!disabled_color_set_) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 864 void Label::ClearRenderTextLines() const { | 882 void Label::ClearRenderTextLines() const { |
| 865 // Persist the selection range if there is an active selection. | 883 // Persist the selection range if there is an active selection. |
| 866 if (HasSelection()) { | 884 if (HasSelection()) { |
| 867 stored_selection_range_ = | 885 stored_selection_range_ = |
| 868 GetRenderTextForSelectionController()->selection(); | 886 GetRenderTextForSelectionController()->selection(); |
| 869 } | 887 } |
| 870 lines_.clear(); | 888 lines_.clear(); |
| 871 } | 889 } |
| 872 | 890 |
| 873 } // namespace views | 891 } // namespace views |
| OLD | NEW |