| 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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 OnCaretBoundsChanged(); | 848 OnCaretBoundsChanged(); |
| 849 } | 849 } |
| 850 | 850 |
| 851 void Textfield::OnEnabledChanged() { | 851 void Textfield::OnEnabledChanged() { |
| 852 View::OnEnabledChanged(); | 852 View::OnEnabledChanged(); |
| 853 if (GetInputMethod()) | 853 if (GetInputMethod()) |
| 854 GetInputMethod()->OnTextInputTypeChanged(this); | 854 GetInputMethod()->OnTextInputTypeChanged(this); |
| 855 SchedulePaint(); | 855 SchedulePaint(); |
| 856 } | 856 } |
| 857 | 857 |
| 858 void Textfield::ViewHierarchyChanged( | |
| 859 const ViewHierarchyChangedDetails& details) { | |
| 860 if (details.is_add && details.child == this) | |
| 861 UpdateColorsFromTheme(GetNativeTheme()); | |
| 862 } | |
| 863 | |
| 864 void Textfield::OnPaint(gfx::Canvas* canvas) { | 858 void Textfield::OnPaint(gfx::Canvas* canvas) { |
| 865 OnPaintBackground(canvas); | 859 OnPaintBackground(canvas); |
| 866 PaintTextAndCursor(canvas); | 860 PaintTextAndCursor(canvas); |
| 867 OnPaintBorder(canvas); | 861 OnPaintBorder(canvas); |
| 868 } | 862 } |
| 869 | 863 |
| 870 void Textfield::OnFocus() { | 864 void Textfield::OnFocus() { |
| 871 GetRenderText()->set_focused(true); | 865 GetRenderText()->set_focused(true); |
| 872 cursor_visible_ = true; | 866 cursor_visible_ = true; |
| 873 SchedulePaint(); | 867 SchedulePaint(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 898 | 892 |
| 899 // Border typically draws focus indicator. | 893 // Border typically draws focus indicator. |
| 900 SchedulePaint(); | 894 SchedulePaint(); |
| 901 } | 895 } |
| 902 | 896 |
| 903 gfx::Point Textfield::GetKeyboardContextMenuLocation() { | 897 gfx::Point Textfield::GetKeyboardContextMenuLocation() { |
| 904 return GetCaretBounds().bottom_right(); | 898 return GetCaretBounds().bottom_right(); |
| 905 } | 899 } |
| 906 | 900 |
| 907 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 901 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 908 UpdateColorsFromTheme(theme); | 902 gfx::RenderText* render_text = GetRenderText(); |
| 903 render_text->SetColor(GetTextColor()); |
| 904 UpdateBackgroundColor(); |
| 905 render_text->set_cursor_color(GetTextColor()); |
| 906 render_text->set_selection_color(theme->GetSystemColor( |
| 907 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 908 render_text->set_selection_background_focused_color(theme->GetSystemColor( |
| 909 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); |
| 910 |
| 909 } | 911 } |
| 910 | 912 |
| 911 //////////////////////////////////////////////////////////////////////////////// | 913 //////////////////////////////////////////////////////////////////////////////// |
| 912 // Textfield, TextfieldModel::Delegate overrides: | 914 // Textfield, TextfieldModel::Delegate overrides: |
| 913 | 915 |
| 914 void Textfield::OnCompositionTextConfirmedOrCleared() { | 916 void Textfield::OnCompositionTextConfirmedOrCleared() { |
| 915 if (!skip_input_method_cancel_composition_) | 917 if (!skip_input_method_cancel_composition_) |
| 916 GetInputMethod()->CancelComposition(this); | 918 GetInputMethod()->CancelComposition(this); |
| 917 } | 919 } |
| 918 | 920 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 } | 1466 } |
| 1465 } | 1467 } |
| 1466 | 1468 |
| 1467 void Textfield::UpdateBackgroundColor() { | 1469 void Textfield::UpdateBackgroundColor() { |
| 1468 const SkColor color = GetBackgroundColor(); | 1470 const SkColor color = GetBackgroundColor(); |
| 1469 set_background(Background::CreateSolidBackground(color)); | 1471 set_background(Background::CreateSolidBackground(color)); |
| 1470 GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); | 1472 GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); |
| 1471 SchedulePaint(); | 1473 SchedulePaint(); |
| 1472 } | 1474 } |
| 1473 | 1475 |
| 1474 void Textfield::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | |
| 1475 gfx::RenderText* render_text = GetRenderText(); | |
| 1476 render_text->SetColor(GetTextColor()); | |
| 1477 UpdateBackgroundColor(); | |
| 1478 render_text->set_cursor_color(GetTextColor()); | |
| 1479 render_text->set_selection_color(theme->GetSystemColor( | |
| 1480 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | |
| 1481 render_text->set_selection_background_focused_color(theme->GetSystemColor( | |
| 1482 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); | |
| 1483 } | |
| 1484 | |
| 1485 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { | 1476 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { |
| 1486 if (text_changed) { | 1477 if (text_changed) { |
| 1487 if (controller_) | 1478 if (controller_) |
| 1488 controller_->ContentsChanged(this, text()); | 1479 controller_->ContentsChanged(this, text()); |
| 1489 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); | 1480 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| 1490 } | 1481 } |
| 1491 if (cursor_changed) { | 1482 if (cursor_changed) { |
| 1492 cursor_visible_ = true; | 1483 cursor_visible_ = true; |
| 1493 RepaintCursor(); | 1484 RepaintCursor(); |
| 1494 if (cursor_repaint_timer_.IsRunning()) | 1485 if (cursor_repaint_timer_.IsRunning()) |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 const size_t length = selection_clipboard_text.length(); | 1675 const size_t length = selection_clipboard_text.length(); |
| 1685 range = gfx::Range(range.start() + length, range.end() + length); | 1676 range = gfx::Range(range.start() + length, range.end() + length); |
| 1686 } | 1677 } |
| 1687 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1678 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
| 1688 UpdateAfterChange(true, true); | 1679 UpdateAfterChange(true, true); |
| 1689 OnAfterUserAction(); | 1680 OnAfterUserAction(); |
| 1690 } | 1681 } |
| 1691 } | 1682 } |
| 1692 | 1683 |
| 1693 } // namespace views | 1684 } // namespace views |
| OLD | NEW |