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

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: makes trybots green. 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())
yukawa 2015/06/11 21:48:42 Why do we test GetTextInputClient() in Combobox::~
Shu Chen 2015/06/12 03:34:38 You're right. I've updated the code to check GetTe
yukawa 2015/06/12 05:20:45 Hmm, if the derived class of TextField calls |GetI
Shu Chen 2015/06/12 05:32:54 I think the derived class of TextField overrides G
296 GetInputMethod()->DetachTextInputClient(GetTextInputClient());
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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 void Textfield::OnPaint(gfx::Canvas* canvas) { 990 void Textfield::OnPaint(gfx::Canvas* canvas) {
988 OnPaintBackground(canvas); 991 OnPaintBackground(canvas);
989 PaintTextAndCursor(canvas); 992 PaintTextAndCursor(canvas);
990 OnPaintBorder(canvas); 993 OnPaintBorder(canvas);
991 } 994 }
992 995
993 void Textfield::OnFocus() { 996 void Textfield::OnFocus() {
994 GetRenderText()->set_focused(true); 997 GetRenderText()->set_focused(true);
995 cursor_visible_ = true; 998 cursor_visible_ = true;
996 SchedulePaint(); 999 SchedulePaint();
997 GetInputMethod()->OnFocus(); 1000 if (GetInputMethod())
yukawa 2015/06/11 21:48:42 ditto.
Shu Chen 2015/06/12 03:34:38 Done.
1001 GetInputMethod()->SetFocusedTextInputClient(this);
998 OnCaretBoundsChanged(); 1002 OnCaretBoundsChanged();
999 1003
1000 const size_t caret_blink_ms = Textfield::GetCaretBlinkMs(); 1004 const size_t caret_blink_ms = Textfield::GetCaretBlinkMs();
1001 if (caret_blink_ms != 0) { 1005 if (caret_blink_ms != 0) {
1002 cursor_repaint_timer_.Start(FROM_HERE, 1006 cursor_repaint_timer_.Start(FROM_HERE,
1003 base::TimeDelta::FromMilliseconds(caret_blink_ms), this, 1007 base::TimeDelta::FromMilliseconds(caret_blink_ms), this,
1004 &Textfield::UpdateCursor); 1008 &Textfield::UpdateCursor);
1005 } 1009 }
1006 1010
1007 View::OnFocus(); 1011 View::OnFocus();
1008 SchedulePaint(); 1012 SchedulePaint();
1009 } 1013 }
1010 1014
1011 void Textfield::OnBlur() { 1015 void Textfield::OnBlur() {
1012 GetRenderText()->set_focused(false); 1016 GetRenderText()->set_focused(false);
1013 GetInputMethod()->OnBlur(); 1017 if (GetInputMethod())
yukawa 2015/06/11 21:48:42 ditto.
Shu Chen 2015/06/12 03:34:38 Done.
1018 GetInputMethod()->DetachTextInputClient(this);
1014 cursor_repaint_timer_.Stop(); 1019 cursor_repaint_timer_.Stop();
1015 if (cursor_visible_) { 1020 if (cursor_visible_) {
1016 cursor_visible_ = false; 1021 cursor_visible_ = false;
1017 RepaintCursor(); 1022 RepaintCursor();
1018 } 1023 }
1019 1024
1020 DestroyTouchSelection(); 1025 DestroyTouchSelection();
1021 1026
1022 // Border typically draws focus indicator. 1027 // Border typically draws focus indicator.
1023 SchedulePaint(); 1028 SchedulePaint();
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 DoInsertChar(ch); 1457 DoInsertChar(ch);
1453 1458
1454 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD && 1459 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD &&
1455 password_reveal_duration_ != base::TimeDelta()) { 1460 password_reveal_duration_ != base::TimeDelta()) {
1456 const size_t change_offset = model_->GetCursorPosition(); 1461 const size_t change_offset = model_->GetCursorPosition();
1457 DCHECK_GT(change_offset, 0u); 1462 DCHECK_GT(change_offset, 0u);
1458 RevealPasswordChar(change_offset - 1); 1463 RevealPasswordChar(change_offset - 1);
1459 } 1464 }
1460 } 1465 }
1461 1466
1462 gfx::NativeWindow Textfield::GetAttachedWindow() const {
1463 // Imagine the following hierarchy.
1464 // [NativeWidget A] - FocusManager
1465 // [View]
1466 // [NativeWidget B]
1467 // [View]
1468 // [View X]
1469 // An important thing is that [NativeWidget A] owns Win32 input focus even
1470 // when [View X] is logically focused by FocusManager. As a result, an Win32
1471 // IME may want to interact with the native view of [NativeWidget A] rather
1472 // than that of [NativeWidget B]. This is why we need to call
1473 // GetTopLevelWidget() here.
1474 return GetWidget()->GetTopLevelWidget()->GetNativeWindow();
1475 }
1476
1477 ui::TextInputType Textfield::GetTextInputType() const { 1467 ui::TextInputType Textfield::GetTextInputType() const {
1478 if (read_only() || !enabled()) 1468 if (read_only() || !enabled())
1479 return ui::TEXT_INPUT_TYPE_NONE; 1469 return ui::TEXT_INPUT_TYPE_NONE;
1480 return text_input_type_; 1470 return text_input_type_;
1481 } 1471 }
1482 1472
1483 ui::TextInputMode Textfield::GetTextInputMode() const { 1473 ui::TextInputMode Textfield::GetTextInputMode() const {
1484 return ui::TEXT_INPUT_MODE_DEFAULT; 1474 return ui::TEXT_INPUT_MODE_DEFAULT;
1485 } 1475 }
1486 1476
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 RequestFocus(); 1883 RequestFocus();
1894 model_->MoveCursorTo(mouse); 1884 model_->MoveCursorTo(mouse);
1895 if (!selection_clipboard_text.empty()) { 1885 if (!selection_clipboard_text.empty()) {
1896 model_->InsertText(selection_clipboard_text); 1886 model_->InsertText(selection_clipboard_text);
1897 UpdateAfterChange(true, true); 1887 UpdateAfterChange(true, true);
1898 } 1888 }
1899 OnAfterUserAction(); 1889 OnAfterUserAction();
1900 } 1890 }
1901 1891
1902 } // namespace views 1892 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698