Chromium Code Reviews| 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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 } | 890 } |
| 891 node_data->AddStringAttribute(ui::AX_ATTR_PLACEHOLDER, | 891 node_data->AddStringAttribute(ui::AX_ATTR_PLACEHOLDER, |
| 892 base::UTF16ToUTF8(GetPlaceholderText())); | 892 base::UTF16ToUTF8(GetPlaceholderText())); |
| 893 | 893 |
| 894 const gfx::Range range = GetSelectedRange(); | 894 const gfx::Range range = GetSelectedRange(); |
| 895 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, range.start()); | 895 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, range.start()); |
| 896 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, range.end()); | 896 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, range.end()); |
| 897 } | 897 } |
| 898 | 898 |
| 899 bool Textfield::HandleAccessibleAction(const ui::AXActionData& action_data) { | 899 bool Textfield::HandleAccessibleAction(const ui::AXActionData& action_data) { |
| 900 if (action_data.action == ui::AX_ACTION_SET_SELECTION) { | |
| 901 if (action_data.anchor_node_id != action_data.focus_node_id) | |
| 902 return false; | |
| 903 // TODO(nektar): Check that the focus_node_id matches the ID of this node. | |
|
msw
2017/02/08 22:11:40
q: can you address this now or file a bug and foll
| |
| 904 const gfx::Range range(action_data.anchor_offset, action_data.focus_offset); | |
| 905 return SetSelectionRange(range); | |
| 906 } | |
| 907 | |
| 908 // Remaining actions cannot be performed on readonly fields. | |
| 900 if (read_only()) | 909 if (read_only()) |
| 901 return View::HandleAccessibleAction(action_data); | 910 return View::HandleAccessibleAction(action_data); |
| 902 | 911 |
| 903 if (action_data.action == ui::AX_ACTION_SET_VALUE) { | 912 if (action_data.action == ui::AX_ACTION_SET_VALUE) { |
| 904 SetText(action_data.value); | 913 SetText(action_data.value); |
| 905 ClearSelection(); | 914 ClearSelection(); |
| 906 return true; | 915 return true; |
| 907 } else if (action_data.action == ui::AX_ACTION_REPLACE_SELECTED_TEXT) { | 916 } else if (action_data.action == ui::AX_ACTION_REPLACE_SELECTED_TEXT) { |
| 908 InsertOrReplaceText(action_data.value); | 917 InsertOrReplaceText(action_data.value); |
| 909 ClearSelection(); | 918 ClearSelection(); |
| (...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1873 controller_->ContentsChanged(this, text()); | 1882 controller_->ContentsChanged(this, text()); |
| 1874 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); | 1883 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); |
| 1875 } | 1884 } |
| 1876 if (cursor_changed) { | 1885 if (cursor_changed) { |
| 1877 GetRenderText()->set_cursor_visible(ShouldShowCursor()); | 1886 GetRenderText()->set_cursor_visible(ShouldShowCursor()); |
| 1878 RepaintCursor(); | 1887 RepaintCursor(); |
| 1879 if (ShouldBlinkCursor()) | 1888 if (ShouldBlinkCursor()) |
| 1880 StartBlinkingCursor(); | 1889 StartBlinkingCursor(); |
| 1881 else | 1890 else |
| 1882 StopBlinkingCursor(); | 1891 StopBlinkingCursor(); |
| 1883 if (!text_changed) { | 1892 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true); |
| 1884 // TEXT_CHANGED implies TEXT_SELECTION_CHANGED, so we only need to fire | |
| 1885 // this if only the selection changed. | |
| 1886 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true); | |
| 1887 } | |
| 1888 } | 1893 } |
| 1889 if (text_changed || cursor_changed) { | 1894 if (text_changed || cursor_changed) { |
| 1890 OnCaretBoundsChanged(); | 1895 OnCaretBoundsChanged(); |
| 1891 SchedulePaint(); | 1896 SchedulePaint(); |
| 1892 } | 1897 } |
| 1893 } | 1898 } |
| 1894 | 1899 |
| 1895 void Textfield::RepaintCursor() { | 1900 void Textfield::RepaintCursor() { |
| 1896 gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds()); | 1901 gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds()); |
| 1897 r.Inset(-1, -1, -1, -1); | 1902 r.Inset(-1, -1, -1, -1); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2053 } | 2058 } |
| 2054 | 2059 |
| 2055 void Textfield::OnCursorBlinkTimerFired() { | 2060 void Textfield::OnCursorBlinkTimerFired() { |
| 2056 DCHECK(ShouldBlinkCursor()); | 2061 DCHECK(ShouldBlinkCursor()); |
| 2057 gfx::RenderText* render_text = GetRenderText(); | 2062 gfx::RenderText* render_text = GetRenderText(); |
| 2058 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2063 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2059 RepaintCursor(); | 2064 RepaintCursor(); |
| 2060 } | 2065 } |
| 2061 | 2066 |
| 2062 } // namespace views | 2067 } // namespace views |
| OLD | NEW |