Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2345183002: Views: Draw Textfield selected text in gray when top-level Widget loses focus.
Patch Set: Fix up diff & add colors to Windows/Mac. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 8 #include <utility>
9 9
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 } 960 }
961 961
962 void Textfield::OnEnabledChanged() { 962 void Textfield::OnEnabledChanged() {
963 View::OnEnabledChanged(); 963 View::OnEnabledChanged();
964 if (GetInputMethod()) 964 if (GetInputMethod())
965 GetInputMethod()->OnTextInputTypeChanged(this); 965 GetInputMethod()->OnTextInputTypeChanged(this);
966 SchedulePaint(); 966 SchedulePaint();
967 } 967 }
968 968
969 void Textfield::OnPaint(gfx::Canvas* canvas) { 969 void Textfield::OnPaint(gfx::Canvas* canvas) {
970 // If the textfield was the last focused view before switching windows, draw
971 // the text selection greyed out.
972 if (!HasFocus() &&
973 GetWidget()->GetFocusManager()->GetStoredFocusView() == this)
974 GetRenderText()->set_draw_unfocused_selection(true);
975
970 OnPaintBackground(canvas); 976 OnPaintBackground(canvas);
971 PaintTextAndCursor(canvas); 977 PaintTextAndCursor(canvas);
972 OnPaintBorder(canvas); 978 OnPaintBorder(canvas);
973 } 979 }
974 980
975 void Textfield::OnFocus() { 981 void Textfield::OnFocus() {
976 GetRenderText()->set_focused(true); 982 GetRenderText()->set_focused(true);
983 GetRenderText()->set_draw_unfocused_selection(false);
977 cursor_visible_ = true; 984 cursor_visible_ = true;
978 SchedulePaint(); 985 SchedulePaint();
979 if (GetInputMethod()) 986 if (GetInputMethod())
980 GetInputMethod()->SetFocusedTextInputClient(this); 987 GetInputMethod()->SetFocusedTextInputClient(this);
981 OnCaretBoundsChanged(); 988 OnCaretBoundsChanged();
982 989
983 const size_t caret_blink_ms = Textfield::GetCaretBlinkMs(); 990 const size_t caret_blink_ms = Textfield::GetCaretBlinkMs();
984 if (caret_blink_ms != 0) { 991 if (caret_blink_ms != 0) {
985 cursor_repaint_timer_.Start(FROM_HERE, 992 cursor_repaint_timer_.Start(FROM_HERE,
986 base::TimeDelta::FromMilliseconds(caret_blink_ms), this, 993 base::TimeDelta::FromMilliseconds(caret_blink_ms), this,
987 &Textfield::UpdateCursor); 994 &Textfield::UpdateCursor);
988 } 995 }
989 996
990 View::OnFocus(); 997 View::OnFocus();
991 SchedulePaint(); 998 SchedulePaint();
992 } 999 }
993 1000
994 void Textfield::OnBlur() { 1001 void Textfield::OnBlur() {
995 GetRenderText()->set_focused(false); 1002 GetRenderText()->set_focused(false);
996 if (GetInputMethod()) 1003 if (GetInputMethod())
997 GetInputMethod()->DetachTextInputClient(this); 1004 GetInputMethod()->DetachTextInputClient(this);
998 cursor_repaint_timer_.Stop(); 1005 cursor_repaint_timer_.Stop();
999 if (cursor_visible_) { 1006 if (cursor_visible_) {
1000 cursor_visible_ = false; 1007 cursor_visible_ = false;
1001 RepaintCursor(); 1008 RepaintCursor();
1002 } 1009 }
1010 // Another focused View in the same Widget means the user is interacting with
1011 // something else and the text selection is no longer needed.
1012 if (GetWidget()->GetFocusManager()->GetFocusedView())
1013 ClearSelection();
tapted 2016/09/20 06:57:55 There are some comments in http://crbug.com/331038
Patti Lor 2016/10/12 05:53:00 I don't think we need to change FocusChangeReason
1003 1014
1004 DestroyTouchSelection(); 1015 DestroyTouchSelection();
1005 1016
1006 // Border typically draws focus indicator. 1017 // Border typically draws focus indicator.
1007 SchedulePaint(); 1018 SchedulePaint();
1008 } 1019 }
1009 1020
1010 gfx::Point Textfield::GetKeyboardContextMenuLocation() { 1021 gfx::Point Textfield::GetKeyboardContextMenuLocation() {
1011 return GetCaretBounds().bottom_right(); 1022 return GetCaretBounds().bottom_right();
1012 } 1023 }
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 RequestFocus(); 2038 RequestFocus();
2028 model_->MoveCursorTo(mouse); 2039 model_->MoveCursorTo(mouse);
2029 if (!selection_clipboard_text.empty()) { 2040 if (!selection_clipboard_text.empty()) {
2030 model_->InsertText(selection_clipboard_text); 2041 model_->InsertText(selection_clipboard_text);
2031 UpdateAfterChange(true, true); 2042 UpdateAfterChange(true, true);
2032 } 2043 }
2033 OnAfterUserAction(); 2044 OnAfterUserAction();
2034 } 2045 }
2035 2046
2036 } // namespace views 2047 } // namespace views
OLDNEW
« ui/native_theme/native_theme_win.cc ('K') | « ui/native_theme/native_theme_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698