| 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/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 OnCaretBoundsChanged(); | 839 OnCaretBoundsChanged(); |
| 840 } | 840 } |
| 841 | 841 |
| 842 void Textfield::OnEnabledChanged() { | 842 void Textfield::OnEnabledChanged() { |
| 843 View::OnEnabledChanged(); | 843 View::OnEnabledChanged(); |
| 844 if (GetInputMethod()) | 844 if (GetInputMethod()) |
| 845 GetInputMethod()->OnTextInputTypeChanged(this); | 845 GetInputMethod()->OnTextInputTypeChanged(this); |
| 846 SchedulePaint(); | 846 SchedulePaint(); |
| 847 } | 847 } |
| 848 | 848 |
| 849 void Textfield::ViewHierarchyChanged( | |
| 850 const ViewHierarchyChangedDetails& details) { | |
| 851 if (details.is_add && details.child == this) | |
| 852 UpdateColorsFromTheme(GetNativeTheme()); | |
| 853 } | |
| 854 | |
| 855 void Textfield::OnPaint(gfx::Canvas* canvas) { | 849 void Textfield::OnPaint(gfx::Canvas* canvas) { |
| 856 OnPaintBackground(canvas); | 850 OnPaintBackground(canvas); |
| 857 PaintTextAndCursor(canvas); | 851 PaintTextAndCursor(canvas); |
| 858 OnPaintBorder(canvas); | 852 OnPaintBorder(canvas); |
| 859 } | 853 } |
| 860 | 854 |
| 861 void Textfield::OnFocus() { | 855 void Textfield::OnFocus() { |
| 862 GetRenderText()->set_focused(true); | 856 GetRenderText()->set_focused(true); |
| 863 cursor_visible_ = true; | 857 cursor_visible_ = true; |
| 864 SchedulePaint(); | 858 SchedulePaint(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 889 | 883 |
| 890 // Border typically draws focus indicator. | 884 // Border typically draws focus indicator. |
| 891 SchedulePaint(); | 885 SchedulePaint(); |
| 892 } | 886 } |
| 893 | 887 |
| 894 gfx::Point Textfield::GetKeyboardContextMenuLocation() { | 888 gfx::Point Textfield::GetKeyboardContextMenuLocation() { |
| 895 return GetCaretBounds().bottom_right(); | 889 return GetCaretBounds().bottom_right(); |
| 896 } | 890 } |
| 897 | 891 |
| 898 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 892 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 899 UpdateColorsFromTheme(theme); | 893 gfx::RenderText* render_text = GetRenderText(); |
| 894 render_text->SetColor(GetTextColor()); |
| 895 UpdateBackgroundColor(); |
| 896 render_text->set_cursor_color(GetTextColor()); |
| 897 render_text->set_selection_color(theme->GetSystemColor( |
| 898 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 899 render_text->set_selection_background_focused_color(theme->GetSystemColor( |
| 900 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); |
| 901 |
| 900 } | 902 } |
| 901 | 903 |
| 902 //////////////////////////////////////////////////////////////////////////////// | 904 //////////////////////////////////////////////////////////////////////////////// |
| 903 // Textfield, TextfieldModel::Delegate overrides: | 905 // Textfield, TextfieldModel::Delegate overrides: |
| 904 | 906 |
| 905 void Textfield::OnCompositionTextConfirmedOrCleared() { | 907 void Textfield::OnCompositionTextConfirmedOrCleared() { |
| 906 if (!skip_input_method_cancel_composition_) | 908 if (!skip_input_method_cancel_composition_) |
| 907 GetInputMethod()->CancelComposition(this); | 909 GetInputMethod()->CancelComposition(this); |
| 908 } | 910 } |
| 909 | 911 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 } | 1457 } |
| 1456 } | 1458 } |
| 1457 | 1459 |
| 1458 void Textfield::UpdateBackgroundColor() { | 1460 void Textfield::UpdateBackgroundColor() { |
| 1459 const SkColor color = GetBackgroundColor(); | 1461 const SkColor color = GetBackgroundColor(); |
| 1460 set_background(Background::CreateSolidBackground(color)); | 1462 set_background(Background::CreateSolidBackground(color)); |
| 1461 GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); | 1463 GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); |
| 1462 SchedulePaint(); | 1464 SchedulePaint(); |
| 1463 } | 1465 } |
| 1464 | 1466 |
| 1465 void Textfield::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | |
| 1466 gfx::RenderText* render_text = GetRenderText(); | |
| 1467 render_text->SetColor(GetTextColor()); | |
| 1468 UpdateBackgroundColor(); | |
| 1469 render_text->set_cursor_color(GetTextColor()); | |
| 1470 render_text->set_selection_color(theme->GetSystemColor( | |
| 1471 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | |
| 1472 render_text->set_selection_background_focused_color(theme->GetSystemColor( | |
| 1473 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); | |
| 1474 } | |
| 1475 | |
| 1476 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { | 1467 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| 1477 if (text_changed) { | 1468 if (text_changed) { |
| 1478 if (controller_) | 1469 if (controller_) |
| 1479 controller_->ContentsChanged(this, text()); | 1470 controller_->ContentsChanged(this, text()); |
| 1480 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); | 1471 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| 1481 } | 1472 } |
| 1482 if (cursor_changed) { | 1473 if (cursor_changed) { |
| 1483 cursor_visible_ = true; | 1474 cursor_visible_ = true; |
| 1484 RepaintCursor(); | 1475 RepaintCursor(); |
| 1485 if (cursor_repaint_timer_.IsRunning()) | 1476 if (cursor_repaint_timer_.IsRunning()) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 const size_t length = selection_clipboard_text.length(); | 1666 const size_t length = selection_clipboard_text.length(); |
| 1676 range = gfx::Range(range.start() + length, range.end() + length); | 1667 range = gfx::Range(range.start() + length, range.end() + length); |
| 1677 } | 1668 } |
| 1678 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1669 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
| 1679 UpdateAfterChange(true, true); | 1670 UpdateAfterChange(true, true); |
| 1680 OnAfterUserAction(); | 1671 OnAfterUserAction(); |
| 1681 } | 1672 } |
| 1682 } | 1673 } |
| 1683 | 1674 |
| 1684 } // namespace views | 1675 } // namespace views |
| OLD | NEW |