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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.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 "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 16 matching lines...) Expand all
27 #include "components/omnibox/browser/omnibox_edit_controller.h" 27 #include "components/omnibox/browser/omnibox_edit_controller.h"
28 #include "components/omnibox/browser/omnibox_edit_model.h" 28 #include "components/omnibox/browser/omnibox_edit_model.h"
29 #include "components/omnibox/browser/omnibox_field_trial.h" 29 #include "components/omnibox/browser/omnibox_field_trial.h"
30 #include "components/omnibox/browser/omnibox_popup_model.h" 30 #include "components/omnibox/browser/omnibox_popup_model.h"
31 #include "components/strings/grit/components_strings.h" 31 #include "components/strings/grit/components_strings.h"
32 #include "components/toolbar/toolbar_model.h" 32 #include "components/toolbar/toolbar_model.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "extensions/common/constants.h" 34 #include "extensions/common/constants.h"
35 #include "net/base/escape.h" 35 #include "net/base/escape.h"
36 #include "third_party/skia/include/core/SkColor.h" 36 #include "third_party/skia/include/core/SkColor.h"
37 #include "ui/accessibility/ax_view_state.h" 37 #include "ui/accessibility/ax_action_data.h"
38 #include "ui/accessibility/ax_node_data.h"
38 #include "ui/base/clipboard/scoped_clipboard_writer.h" 39 #include "ui/base/clipboard/scoped_clipboard_writer.h"
39 #include "ui/base/dragdrop/drag_drop_types.h" 40 #include "ui/base/dragdrop/drag_drop_types.h"
40 #include "ui/base/dragdrop/os_exchange_data.h" 41 #include "ui/base/dragdrop/os_exchange_data.h"
41 #include "ui/base/ime/input_method.h" 42 #include "ui/base/ime/input_method.h"
42 #include "ui/base/ime/text_edit_commands.h" 43 #include "ui/base/ime/text_edit_commands.h"
43 #include "ui/base/ime/text_input_client.h" 44 #include "ui/base/ime/text_input_client.h"
44 #include "ui/base/ime/text_input_type.h" 45 #include "ui/base/ime/text_input_type.h"
45 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/base/models/simple_menu_model.h" 47 #include "ui/base/models/simple_menu_model.h"
47 #include "ui/compositor/layer.h" 48 #include "ui/compositor/layer.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), 117 base::WrapUnique(new ChromeOmniboxClient(controller, profile))),
117 profile_(profile), 118 profile_(profile),
118 popup_window_mode_(popup_window_mode), 119 popup_window_mode_(popup_window_mode),
119 security_level_(security_state::SecurityStateModel::NONE), 120 security_level_(security_state::SecurityStateModel::NONE),
120 saved_selection_for_focus_change_(gfx::Range::InvalidRange()), 121 saved_selection_for_focus_change_(gfx::Range::InvalidRange()),
121 ime_composing_before_change_(false), 122 ime_composing_before_change_(false),
122 delete_at_end_pressed_(false), 123 delete_at_end_pressed_(false),
123 location_bar_view_(location_bar), 124 location_bar_view_(location_bar),
124 ime_candidate_window_open_(false), 125 ime_candidate_window_open_(false),
125 select_all_on_mouse_release_(false), 126 select_all_on_mouse_release_(false),
126 select_all_on_gesture_tap_(false), 127 select_all_on_gesture_tap_(false) {
127 weak_ptr_factory_(this) {
128 set_id(VIEW_ID_OMNIBOX); 128 set_id(VIEW_ID_OMNIBOX);
129 SetFontList(font_list); 129 SetFontList(font_list);
130 } 130 }
131 131
132 OmniboxViewViews::~OmniboxViewViews() { 132 OmniboxViewViews::~OmniboxViewViews() {
133 #if defined(OS_CHROMEOS) 133 #if defined(OS_CHROMEOS)
134 chromeos::input_method::InputMethodManager::Get()-> 134 chromeos::input_method::InputMethodManager::Get()->
135 RemoveCandidateWindowObserver(this); 135 RemoveCandidateWindowObserver(this);
136 #endif 136 #endif
137 137
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (event.IsShiftDown() && 401 if (event.IsShiftDown() &&
402 (model()->popup_model()->selected_line_state() == 402 (model()->popup_model()->selected_line_state() ==
403 OmniboxPopupModel::KEYWORD)) 403 OmniboxPopupModel::KEYWORD))
404 model()->ClearKeyword(); 404 model()->ClearKeyword();
405 else 405 else
406 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); 406 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1);
407 407
408 return true; 408 return true;
409 } 409 }
410 410
411 void OmniboxViewViews::AccessibilitySetValue(const base::string16& new_value,
412 bool clear_first) {
413 if (read_only())
414 return;
415 if (clear_first) {
416 SetUserText(new_value, true);
417 } else {
418 model()->SetInputInProgress(true);
419 if (saved_selection_for_focus_change_.IsValid()) {
420 SelectRange(saved_selection_for_focus_change_);
421 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
422 }
423 InsertOrReplaceText(new_value);
424 TextChanged();
425 }
426 }
427
428 void OmniboxViewViews::UpdateSecurityLevel() { 411 void OmniboxViewViews::UpdateSecurityLevel() {
429 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false); 412 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
430 } 413 }
431 414
432 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, 415 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
433 size_t caret_pos, 416 size_t caret_pos,
434 bool update_popup, 417 bool update_popup,
435 bool notify_text_changed) { 418 bool notify_text_changed) {
436 const gfx::Range range(caret_pos, caret_pos); 419 const gfx::Range range(caret_pos, caret_pos);
437 SetTextAndSelectedRange(text, range); 420 SetTextAndSelectedRange(text, range);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 if (views::FocusManager::IsTabTraversalKeyEvent(event) && 715 if (views::FocusManager::IsTabTraversalKeyEvent(event) &&
733 ((model()->is_keyword_hint() && !event.IsShiftDown()) || 716 ((model()->is_keyword_hint() && !event.IsShiftDown()) ||
734 model()->popup_model()->IsOpen())) { 717 model()->popup_model()->IsOpen())) {
735 return true; 718 return true;
736 } 719 }
737 if (event.key_code() == ui::VKEY_ESCAPE) 720 if (event.key_code() == ui::VKEY_ESCAPE)
738 return model()->WillHandleEscapeKey(); 721 return model()->WillHandleEscapeKey();
739 return Textfield::SkipDefaultKeyEventProcessing(event); 722 return Textfield::SkipDefaultKeyEventProcessing(event);
740 } 723 }
741 724
742 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { 725 void OmniboxViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) {
743 state->role = ui::AX_ROLE_TEXT_FIELD; 726 node_data->role = ui::AX_ROLE_TEXT_FIELD;
744 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); 727 node_data->SetName(l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION));
745 state->value = GetText(); 728 node_data->SetValue(GetText());
746 729
747 base::string16::size_type entry_start; 730 base::string16::size_type entry_start;
748 base::string16::size_type entry_end; 731 base::string16::size_type entry_end;
749 // Selection information is saved separately when focus is moved off the 732 // Selection information is saved separately when focus is moved off the
750 // current window - use that when there is no focus and it's valid. 733 // current window - use that when there is no focus and it's valid.
751 if (saved_selection_for_focus_change_.IsValid()) { 734 if (saved_selection_for_focus_change_.IsValid()) {
752 entry_start = saved_selection_for_focus_change_.start(); 735 entry_start = saved_selection_for_focus_change_.start();
753 entry_end = saved_selection_for_focus_change_.end(); 736 entry_end = saved_selection_for_focus_change_.end();
754 } else { 737 } else {
755 GetSelectionBounds(&entry_start, &entry_end); 738 GetSelectionBounds(&entry_start, &entry_end);
756 } 739 }
757 state->selection_start = entry_start; 740 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, entry_start);
758 state->selection_end = entry_end; 741 node_data->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, entry_end);
759 742
760 if (popup_window_mode_) { 743 if (popup_window_mode_) {
761 state->AddStateFlag(ui::AX_STATE_READ_ONLY); 744 node_data->AddStateFlag(ui::AX_STATE_READ_ONLY);
762 } else { 745 } else {
763 state->AddStateFlag(ui::AX_STATE_EDITABLE); 746 node_data->AddStateFlag(ui::AX_STATE_EDITABLE);
764 state->set_value_callback =
765 base::Bind(&OmniboxViewViews::AccessibilitySetValue,
766 weak_ptr_factory_.GetWeakPtr());
767 } 747 }
768 } 748 }
769 749
750 bool OmniboxViewViews::HandleAccessibleAction(
751 const ui::AXActionData& action_data) {
752 if (read_only())
753 return Textfield::HandleAccessibleAction(action_data);
754
755 if (action_data.action == ui::AX_ACTION_SET_VALUE) {
756 SetUserText(action_data.value, true);
757 return true;
758 } else if (action_data.action == ui::AX_ACTION_REPLACE_SELECTED_TEXT) {
759 model()->SetInputInProgress(true);
760 if (saved_selection_for_focus_change_.IsValid()) {
761 SelectRange(saved_selection_for_focus_change_);
762 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
763 }
764 InsertOrReplaceText(action_data.value);
765 TextChanged();
766 return true;
767 }
768
769 return Textfield::HandleAccessibleAction(action_data);
770 }
771
770 void OmniboxViewViews::OnFocus() { 772 void OmniboxViewViews::OnFocus() {
771 views::Textfield::OnFocus(); 773 views::Textfield::OnFocus();
772 // TODO(oshima): Get control key state. 774 // TODO(oshima): Get control key state.
773 model()->OnSetFocus(false); 775 model()->OnSetFocus(false);
774 // Don't call controller()->OnSetFocus, this view has already acquired focus. 776 // Don't call controller()->OnSetFocus, this view has already acquired focus.
775 777
776 // Restore the selection we saved in OnBlur() if it's still valid. 778 // Restore the selection we saved in OnBlur() if it's still valid.
777 if (saved_selection_for_focus_change_.IsValid()) { 779 if (saved_selection_for_focus_change_.IsValid()) {
778 SelectRange(saved_selection_for_focus_change_); 780 SelectRange(saved_selection_for_focus_change_);
779 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); 781 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1086 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1085 1087
1086 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1088 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1087 1089
1088 // Minor note: We use IDC_ for command id here while the underlying textfield 1090 // Minor note: We use IDC_ for command id here while the underlying textfield
1089 // is using IDS_ for all its command ids. This is because views cannot depend 1091 // is using IDS_ for all its command ids. This is because views cannot depend
1090 // on IDC_ for now. 1092 // on IDC_ for now.
1091 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1093 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1092 IDS_EDIT_SEARCH_ENGINES); 1094 IDS_EDIT_SEARCH_ENGINES);
1093 } 1095 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | chrome/browser/ui/views/tabs/tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698