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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "ui/display/screen.h" | 26 #include "ui/display/screen.h" |
27 #include "ui/events/base_event_utils.h" | 27 #include "ui/events/base_event_utils.h" |
28 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
29 #include "ui/events/keycodes/keyboard_codes.h" | 29 #include "ui/events/keycodes/keyboard_codes.h" |
30 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/geometry/insets.h" | 31 #include "ui/gfx/geometry/insets.h" |
32 #include "ui/gfx/selection_bound.h" | 32 #include "ui/gfx/selection_bound.h" |
33 #include "ui/native_theme/native_theme.h" | 33 #include "ui/native_theme/native_theme.h" |
34 #include "ui/strings/grit/ui_strings.h" | 34 #include "ui/strings/grit/ui_strings.h" |
35 #include "ui/views/background.h" | 35 #include "ui/views/background.h" |
36 #include "ui/views/controls/focus_ring.h" | |
36 #include "ui/views/controls/focusable_border.h" | 37 #include "ui/views/controls/focusable_border.h" |
37 #include "ui/views/controls/label.h" | 38 #include "ui/views/controls/label.h" |
38 #include "ui/views/controls/menu/menu_runner.h" | 39 #include "ui/views/controls/menu/menu_runner.h" |
39 #include "ui/views/controls/native/native_view_host.h" | 40 #include "ui/views/controls/native/native_view_host.h" |
40 #include "ui/views/controls/textfield/textfield_controller.h" | 41 #include "ui/views/controls/textfield/textfield_controller.h" |
41 #include "ui/views/drag_utils.h" | 42 #include "ui/views/drag_utils.h" |
42 #include "ui/views/metrics.h" | 43 #include "ui/views/metrics.h" |
43 #include "ui/views/native_cursor.h" | 44 #include "ui/views/native_cursor.h" |
44 #include "ui/views/painter.h" | 45 #include "ui/views/painter.h" |
45 #include "ui/views/style/platform_style.h" | 46 #include "ui/views/style/platform_style.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 placeholder_text_color_(kDefaultPlaceholderTextColor), | 254 placeholder_text_color_(kDefaultPlaceholderTextColor), |
254 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
255 text_input_flags_(0), | 256 text_input_flags_(0), |
256 performing_user_action_(false), | 257 performing_user_action_(false), |
257 skip_input_method_cancel_composition_(false), | 258 skip_input_method_cancel_composition_(false), |
258 drop_cursor_visible_(false), | 259 drop_cursor_visible_(false), |
259 initiating_drag_(false), | 260 initiating_drag_(false), |
260 aggregated_clicks_(0), | 261 aggregated_clicks_(0), |
261 drag_start_display_offset_(0), | 262 drag_start_display_offset_(0), |
262 touch_handles_hidden_due_to_scroll_(false), | 263 touch_handles_hidden_due_to_scroll_(false), |
264 focus_ring_(nullptr), | |
263 weak_ptr_factory_(this) { | 265 weak_ptr_factory_(this) { |
264 set_context_menu_controller(this); | 266 set_context_menu_controller(this); |
265 set_drag_controller(this); | 267 set_drag_controller(this); |
266 GetRenderText()->SetFontList(GetDefaultFontList()); | 268 GetRenderText()->SetFontList(GetDefaultFontList()); |
267 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); | 269 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
268 SetFocusBehavior(FocusBehavior::ALWAYS); | 270 SetFocusBehavior(FocusBehavior::ALWAYS); |
271 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | |
272 focus_ring_ = new FocusRing(); | |
273 AddChildView(focus_ring_); | |
274 } | |
269 | 275 |
270 // These allow BrowserView to pass edit commands from the Chrome menu to us | 276 // These allow BrowserView to pass edit commands from the Chrome menu to us |
271 // when we're focused by simply asking the FocusManager to | 277 // when we're focused by simply asking the FocusManager to |
272 // ProcessAccelerator() with the relevant accelerators. | 278 // ProcessAccelerator() with the relevant accelerators. |
273 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); | 279 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); |
274 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); | 280 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); |
275 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 281 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
276 } | 282 } |
277 | 283 |
278 Textfield::~Textfield() { | 284 Textfield::~Textfield() { |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 if (ShouldShowCursor()) | 989 if (ShouldShowCursor()) |
984 GetRenderText()->set_cursor_visible(true); | 990 GetRenderText()->set_cursor_visible(true); |
985 SchedulePaint(); | 991 SchedulePaint(); |
986 if (GetInputMethod()) | 992 if (GetInputMethod()) |
987 GetInputMethod()->SetFocusedTextInputClient(this); | 993 GetInputMethod()->SetFocusedTextInputClient(this); |
988 OnCaretBoundsChanged(); | 994 OnCaretBoundsChanged(); |
989 if (ShouldBlinkCursor()) | 995 if (ShouldBlinkCursor()) |
990 StartBlinkingCursor(); | 996 StartBlinkingCursor(); |
991 View::OnFocus(); | 997 View::OnFocus(); |
992 SchedulePaint(); | 998 SchedulePaint(); |
999 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | |
1000 focus_ring_->SetVisible(true); | |
993 } | 1001 } |
994 | 1002 |
995 void Textfield::OnBlur() { | 1003 void Textfield::OnBlur() { |
996 gfx::RenderText* render_text = GetRenderText(); | 1004 gfx::RenderText* render_text = GetRenderText(); |
997 render_text->set_focused(false); | 1005 render_text->set_focused(false); |
998 if (GetInputMethod()) | 1006 if (GetInputMethod()) |
999 GetInputMethod()->DetachTextInputClient(this); | 1007 GetInputMethod()->DetachTextInputClient(this); |
1000 StopBlinkingCursor(); | 1008 StopBlinkingCursor(); |
1001 if (render_text->cursor_visible()) { | 1009 if (render_text->cursor_visible()) { |
1002 render_text->set_cursor_visible(false); | 1010 render_text->set_cursor_visible(false); |
1003 RepaintCursor(); | 1011 RepaintCursor(); |
1004 } | 1012 } |
1005 | 1013 |
1006 DestroyTouchSelection(); | 1014 DestroyTouchSelection(); |
1007 | 1015 |
1008 // Border typically draws focus indicator. | 1016 // Border typically draws focus indicator. |
1009 SchedulePaint(); | 1017 SchedulePaint(); |
1018 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | |
1019 focus_ring_->SetVisible(false); | |
sky
2016/10/03 23:53:15
Similar comment about deleting here.
| |
1010 } | 1020 } |
1011 | 1021 |
1012 gfx::Point Textfield::GetKeyboardContextMenuLocation() { | 1022 gfx::Point Textfield::GetKeyboardContextMenuLocation() { |
1013 return GetCaretBounds().bottom_right(); | 1023 return GetCaretBounds().bottom_right(); |
1014 } | 1024 } |
1015 | 1025 |
1016 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 1026 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
1017 gfx::RenderText* render_text = GetRenderText(); | 1027 gfx::RenderText* render_text = GetRenderText(); |
1018 render_text->SetColor(GetTextColor()); | 1028 render_text->SetColor(GetTextColor()); |
1019 UpdateBackgroundColor(); | 1029 UpdateBackgroundColor(); |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2059 } | 2069 } |
2060 | 2070 |
2061 void Textfield::OnCursorBlinkTimerFired() { | 2071 void Textfield::OnCursorBlinkTimerFired() { |
2062 DCHECK(ShouldBlinkCursor()); | 2072 DCHECK(ShouldBlinkCursor()); |
2063 gfx::RenderText* render_text = GetRenderText(); | 2073 gfx::RenderText* render_text = GetRenderText(); |
2064 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2074 render_text->set_cursor_visible(!render_text->cursor_visible()); |
2065 RepaintCursor(); | 2075 RepaintCursor(); |
2066 } | 2076 } |
2067 | 2077 |
2068 } // namespace views | 2078 } // namespace views |
OLD | NEW |