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

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

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 6 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 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
11 #include "ui/base/clipboard/scoped_clipboard_writer.h" 11 #include "ui/base/clipboard/scoped_clipboard_writer.h"
12 #include "ui/base/cursor/cursor.h" 12 #include "ui/base/cursor/cursor.h"
13 #include "ui/base/dragdrop/drag_drop_types.h" 13 #include "ui/base/dragdrop/drag_drop_types.h"
14 #include "ui/base/dragdrop/drag_utils.h" 14 #include "ui/base/dragdrop/drag_utils.h"
15 #include "ui/base/ime/input_method.h"
15 #include "ui/base/touch/selection_bound.h" 16 #include "ui/base/touch/selection_bound.h"
16 #include "ui/base/ui_base_switches_util.h" 17 #include "ui/base/ui_base_switches_util.h"
17 #include "ui/compositor/canvas_painter.h" 18 #include "ui/compositor/canvas_painter.h"
18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
19 #include "ui/events/event.h" 20 #include "ui/events/event.h"
20 #include "ui/events/keycodes/keyboard_codes.h" 21 #include "ui/events/keycodes/keyboard_codes.h"
21 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/display.h" 23 #include "ui/gfx/display.h"
23 #include "ui/gfx/geometry/insets.h" 24 #include "ui/gfx/geometry/insets.h"
24 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
25 #include "ui/native_theme/native_theme.h" 26 #include "ui/native_theme/native_theme.h"
26 #include "ui/strings/grit/ui_strings.h" 27 #include "ui/strings/grit/ui_strings.h"
27 #include "ui/views/background.h" 28 #include "ui/views/background.h"
28 #include "ui/views/controls/focusable_border.h" 29 #include "ui/views/controls/focusable_border.h"
29 #include "ui/views/controls/label.h" 30 #include "ui/views/controls/label.h"
30 #include "ui/views/controls/menu/menu_runner.h" 31 #include "ui/views/controls/menu/menu_runner.h"
31 #include "ui/views/controls/native/native_view_host.h" 32 #include "ui/views/controls/native/native_view_host.h"
32 #include "ui/views/controls/textfield/textfield_controller.h" 33 #include "ui/views/controls/textfield/textfield_controller.h"
33 #include "ui/views/drag_utils.h" 34 #include "ui/views/drag_utils.h"
34 #include "ui/views/ime/input_method.h"
35 #include "ui/views/metrics.h" 35 #include "ui/views/metrics.h"
36 #include "ui/views/native_cursor.h" 36 #include "ui/views/native_cursor.h"
37 #include "ui/views/painter.h" 37 #include "ui/views/painter.h"
38 #include "ui/views/views_delegate.h" 38 #include "ui/views/views_delegate.h"
39 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
40 40
41 #if defined(OS_WIN) 41 #if defined(OS_WIN)
42 #include "base/win/win_util.h" 42 #include "base/win/win_util.h"
43 #endif 43 #endif
44 44
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 SetBorder(scoped_ptr<Border>(new FocusableBorder())); 284 SetBorder(scoped_ptr<Border>(new FocusableBorder()));
285 SetFocusable(true); 285 SetFocusable(true);
286 286
287 if (ViewsDelegate::GetInstance()) { 287 if (ViewsDelegate::GetInstance()) {
288 password_reveal_duration_ = 288 password_reveal_duration_ =
289 ViewsDelegate::GetInstance() 289 ViewsDelegate::GetInstance()
290 ->GetDefaultTextfieldObscuredRevealDuration(); 290 ->GetDefaultTextfieldObscuredRevealDuration();
291 } 291 }
292 } 292 }
293 293
294 Textfield::~Textfield() {} 294 Textfield::~Textfield() {
295 if (GetInputMethod())
sky 2015/06/29 02:17:41 Is it really possible to hit this? I would have as
Shu Chen 2015/06/29 02:56:34 You're right. The FocusManager should make sure th
sky 2015/06/29 17:03:49 DCHECK.
Shu Chen 2015/06/30 00:54:06 Done.
296 GetInputMethod()->DetachTextInputClient(this);
297 }
295 298
296 void Textfield::SetReadOnly(bool read_only) { 299 void Textfield::SetReadOnly(bool read_only) {
297 // Update read-only without changing the focusable state (or active, etc.). 300 // Update read-only without changing the focusable state (or active, etc.).
298 read_only_ = read_only; 301 read_only_ = read_only;
299 if (GetInputMethod()) 302 if (GetInputMethod())
300 GetInputMethod()->OnTextInputTypeChanged(this); 303 GetInputMethod()->OnTextInputTypeChanged(this);
301 SetColor(GetTextColor()); 304 SetColor(GetTextColor());
302 UpdateBackgroundColor(); 305 UpdateBackgroundColor();
303 } 306 }
304 307
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 if (edit_command == kNoCommand) 711 if (edit_command == kNoCommand)
709 edit_command = GetCommandForKeyEvent(event, HasSelection()); 712 edit_command = GetCommandForKeyEvent(event, HasSelection());
710 713
711 if (!handled && IsCommandIdEnabled(edit_command)) { 714 if (!handled && IsCommandIdEnabled(edit_command)) {
712 ExecuteCommand(edit_command); 715 ExecuteCommand(edit_command);
713 handled = true; 716 handled = true;
714 } 717 }
715 return handled; 718 return handled;
716 } 719 }
717 720
718 ui::TextInputClient* Textfield::GetTextInputClient() {
719 return this;
720 }
721
722 void Textfield::OnGestureEvent(ui::GestureEvent* event) { 721 void Textfield::OnGestureEvent(ui::GestureEvent* event) {
723 switch (event->type()) { 722 switch (event->type()) {
724 case ui::ET_GESTURE_TAP_DOWN: 723 case ui::ET_GESTURE_TAP_DOWN:
725 RequestFocus(); 724 RequestFocus();
726 ShowImeIfNeeded(); 725 ShowImeIfNeeded();
727 event->SetHandled(); 726 event->SetHandled();
728 break; 727 break;
729 case ui::ET_GESTURE_TAP: 728 case ui::ET_GESTURE_TAP:
730 if (event->details().tap_count() == 1) { 729 if (event->details().tap_count() == 1) {
731 // If tap is on the selection and touch handles are not present, handles 730 // If tap is on the selection and touch handles are not present, handles
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 void Textfield::OnPaint(gfx::Canvas* canvas) { 986 void Textfield::OnPaint(gfx::Canvas* canvas) {
988 OnPaintBackground(canvas); 987 OnPaintBackground(canvas);
989 PaintTextAndCursor(canvas); 988 PaintTextAndCursor(canvas);
990 OnPaintBorder(canvas); 989 OnPaintBorder(canvas);
991 } 990 }
992 991
993 void Textfield::OnFocus() { 992 void Textfield::OnFocus() {
994 GetRenderText()->set_focused(true); 993 GetRenderText()->set_focused(true);
995 cursor_visible_ = true; 994 cursor_visible_ = true;
996 SchedulePaint(); 995 SchedulePaint();
997 GetInputMethod()->OnFocus(); 996 if (GetInputMethod())
997 GetInputMethod()->SetFocusedTextInputClient(this);
998 OnCaretBoundsChanged(); 998 OnCaretBoundsChanged();
999 999
1000 const size_t caret_blink_ms = Textfield::GetCaretBlinkMs(); 1000 const size_t caret_blink_ms = Textfield::GetCaretBlinkMs();
1001 if (caret_blink_ms != 0) { 1001 if (caret_blink_ms != 0) {
1002 cursor_repaint_timer_.Start(FROM_HERE, 1002 cursor_repaint_timer_.Start(FROM_HERE,
1003 base::TimeDelta::FromMilliseconds(caret_blink_ms), this, 1003 base::TimeDelta::FromMilliseconds(caret_blink_ms), this,
1004 &Textfield::UpdateCursor); 1004 &Textfield::UpdateCursor);
1005 } 1005 }
1006 1006
1007 View::OnFocus(); 1007 View::OnFocus();
1008 SchedulePaint(); 1008 SchedulePaint();
1009 } 1009 }
1010 1010
1011 void Textfield::OnBlur() { 1011 void Textfield::OnBlur() {
1012 GetRenderText()->set_focused(false); 1012 GetRenderText()->set_focused(false);
1013 GetInputMethod()->OnBlur(); 1013 if (GetInputMethod())
1014 GetInputMethod()->DetachTextInputClient(this);
1014 cursor_repaint_timer_.Stop(); 1015 cursor_repaint_timer_.Stop();
1015 if (cursor_visible_) { 1016 if (cursor_visible_) {
1016 cursor_visible_ = false; 1017 cursor_visible_ = false;
1017 RepaintCursor(); 1018 RepaintCursor();
1018 } 1019 }
1019 1020
1020 DestroyTouchSelection(); 1021 DestroyTouchSelection();
1021 1022
1022 // Border typically draws focus indicator. 1023 // Border typically draws focus indicator.
1023 SchedulePaint(); 1024 SchedulePaint();
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 RequestFocus(); 1894 RequestFocus();
1894 model_->MoveCursorTo(mouse); 1895 model_->MoveCursorTo(mouse);
1895 if (!selection_clipboard_text.empty()) { 1896 if (!selection_clipboard_text.empty()) {
1896 model_->InsertText(selection_clipboard_text); 1897 model_->InsertText(selection_clipboard_text);
1897 UpdateAfterChange(true, true); 1898 UpdateAfterChange(true, true);
1898 } 1899 }
1899 OnAfterUserAction(); 1900 OnAfterUserAction();
1900 } 1901 }
1901 1902
1902 } // namespace views 1903 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698