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