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

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

Issue 2477463003: Replace ui::AXViewState with AXNodeData and AXActionData (Closed)
Patch Set: Fix test Created 4 years, 1 month 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/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "ui/accessibility/ax_view_state.h" 13 #include "ui/accessibility/ax_action_data.h"
14 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/base/clipboard/scoped_clipboard_writer.h" 15 #include "ui/base/clipboard/scoped_clipboard_writer.h"
14 #include "ui/base/cursor/cursor.h" 16 #include "ui/base/cursor/cursor.h"
15 #include "ui/base/default_style.h" 17 #include "ui/base/default_style.h"
16 #include "ui/base/dragdrop/drag_drop_types.h" 18 #include "ui/base/dragdrop/drag_drop_types.h"
17 #include "ui/base/dragdrop/drag_utils.h" 19 #include "ui/base/dragdrop/drag_utils.h"
18 #include "ui/base/ime/input_method.h" 20 #include "ui/base/ime/input_method.h"
19 #include "ui/base/ime/text_edit_commands.h" 21 #include "ui/base/ime/text_edit_commands.h"
20 #include "ui/base/material_design/material_design_controller.h" 22 #include "ui/base/material_design/material_design_controller.h"
21 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/ui_base_switches_util.h" 24 #include "ui/base/ui_base_switches_util.h"
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 UpdateAfterChange(true, true); 867 UpdateAfterChange(true, true);
866 OnAfterUserAction(); 868 OnAfterUserAction();
867 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; 869 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY;
868 } 870 }
869 871
870 void Textfield::OnDragDone() { 872 void Textfield::OnDragDone() {
871 initiating_drag_ = false; 873 initiating_drag_ = false;
872 drop_cursor_visible_ = false; 874 drop_cursor_visible_ = false;
873 } 875 }
874 876
875 void Textfield::GetAccessibleState(ui::AXViewState* state) { 877 void Textfield::GetAccessibleNodeData(ui::AXNodeData* node_data) {
876 state->role = ui::AX_ROLE_TEXT_FIELD; 878 node_data->role = ui::AX_ROLE_TEXT_FIELD;
877 state->name = accessible_name_; 879 node_data->SetName(accessible_name_);
878 if (read_only()) 880 if (read_only())
879 state->AddStateFlag(ui::AX_STATE_READ_ONLY); 881 node_data->AddStateFlag(ui::AX_STATE_READ_ONLY);
880 else 882 else
881 state->AddStateFlag(ui::AX_STATE_EDITABLE); 883 node_data->AddStateFlag(ui::AX_STATE_EDITABLE);
882 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) { 884 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) {
883 state->AddStateFlag(ui::AX_STATE_PROTECTED); 885 node_data->AddStateFlag(ui::AX_STATE_PROTECTED);
884 state->value = base::string16(text().size(), '*'); 886 node_data->SetValue(base::string16(text().size(), '*'));
885 } else { 887 } else {
886 state->value = text(); 888 node_data->SetValue(text());
887 } 889 }
888 state->placeholder = GetPlaceholderText(); 890 node_data->AddStringAttribute(ui::AX_ATTR_PLACEHOLDER,
891 base::UTF16ToUTF8(GetPlaceholderText()));
889 892
890 const gfx::Range range = GetSelectedRange(); 893 const gfx::Range range = GetSelectedRange();
891 state->selection_start = range.start(); 894 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, range.start());
892 state->selection_end = range.end(); 895 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, range.end());
896 }
893 897
894 if (!read_only()) { 898 bool Textfield::HandleAccessibleAction(const ui::AXActionData& action_data) {
895 state->set_value_callback = 899 if (read_only())
896 base::Bind(&Textfield::AccessibilitySetValue, 900 return View::HandleAccessibleAction(action_data);
897 weak_ptr_factory_.GetWeakPtr()); 901
902 if (action_data.action == ui::AX_ACTION_SET_VALUE) {
903 SetText(action_data.value);
904 ClearSelection();
905 return true;
906 } else if (action_data.action == ui::AX_ACTION_REPLACE_SELECTED_TEXT) {
907 InsertOrReplaceText(action_data.value);
908 ClearSelection();
909 return true;
898 } 910 }
911
912 return View::HandleAccessibleAction(action_data);
899 } 913 }
900 914
901 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) { 915 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) {
902 // Textfield insets include a reasonable amount of whitespace on all sides of 916 // Textfield insets include a reasonable amount of whitespace on all sides of
903 // the default font list. Fallback fonts with larger heights may paint over 917 // the default font list. Fallback fonts with larger heights may paint over
904 // the vertical whitespace as needed. Alternate solutions involve undesirable 918 // the vertical whitespace as needed. Alternate solutions involve undesirable
905 // behavior like changing the default font size, shrinking some fallback fonts 919 // behavior like changing the default font size, shrinking some fallback fonts
906 // beyond their legibility, or enlarging controls dynamically with content. 920 // beyond their legibility, or enlarging controls dynamically with content.
907 gfx::Rect bounds = GetContentsBounds(); 921 gfx::Rect bounds = GetContentsBounds();
908 // GetContentsBounds() does not actually use the local GetInsets() override. 922 // GetContentsBounds() does not actually use the local GetInsets() override.
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1831 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1818 if (text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD) { 1832 if (text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD) {
1819 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_SELECTION) 1833 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_SELECTION)
1820 .WriteText(GetSelectedText()); 1834 .WriteText(GetSelectedText());
1821 if (controller_) 1835 if (controller_)
1822 controller_->OnAfterCutOrCopy(ui::CLIPBOARD_TYPE_SELECTION); 1836 controller_->OnAfterCutOrCopy(ui::CLIPBOARD_TYPE_SELECTION);
1823 } 1837 }
1824 #endif 1838 #endif
1825 } 1839 }
1826 1840
1827 void Textfield::AccessibilitySetValue(const base::string16& new_value,
1828 bool clear_first) {
1829 if (read_only())
1830 return;
1831 if (!clear_first)
1832 InsertOrReplaceText(new_value);
1833 else
1834 SetText(new_value);
1835 ClearSelection();
1836 }
1837
1838 void Textfield::UpdateBackgroundColor() { 1841 void Textfield::UpdateBackgroundColor() {
1839 const SkColor color = GetBackgroundColor(); 1842 const SkColor color = GetBackgroundColor();
1840 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 1843 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
1841 set_background(Background::CreateBackgroundPainter( 1844 set_background(Background::CreateBackgroundPainter(
1842 true, Painter::CreateSolidRoundRectPainter( 1845 true, Painter::CreateSolidRoundRectPainter(
1843 color, FocusableBorder::kCornerRadiusDp))); 1846 color, FocusableBorder::kCornerRadiusDp)));
1844 } else { 1847 } else {
1845 set_background(Background::CreateSolidBackground(color)); 1848 set_background(Background::CreateSolidBackground(color));
1846 } 1849 }
1847 // Disable subpixel rendering when the background color is transparent 1850 // Disable subpixel rendering when the background color is transparent
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 } 2048 }
2046 2049
2047 void Textfield::OnCursorBlinkTimerFired() { 2050 void Textfield::OnCursorBlinkTimerFired() {
2048 DCHECK(ShouldBlinkCursor()); 2051 DCHECK(ShouldBlinkCursor());
2049 gfx::RenderText* render_text = GetRenderText(); 2052 gfx::RenderText* render_text = GetRenderText();
2050 render_text->set_cursor_visible(!render_text->cursor_visible()); 2053 render_text->set_cursor_visible(!render_text->cursor_visible());
2051 RepaintCursor(); 2054 RepaintCursor();
2052 } 2055 }
2053 2056
2054 } // namespace views 2057 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698