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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 2341633006: MacViews/a11y: Allow accessibility clients to update the selected text. (Closed)
Patch Set: Move accessibility notification for text selection being changed to SelectRange() instead. Created 4 years, 2 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 "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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 else 412 else
413 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); 413 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1);
414 414
415 return true; 415 return true;
416 } 416 }
417 417
418 void OmniboxViewViews::AccessibilitySetValue(const base::string16& new_value) { 418 void OmniboxViewViews::AccessibilitySetValue(const base::string16& new_value) {
419 SetUserText(new_value, true); 419 SetUserText(new_value, true);
420 } 420 }
421 421
422 void OmniboxViewViews::AccessibilityReplaceSelection(
423 const base::string16& new_value) {
424 // This should work even when focus is not on the omnibox, so restore the
425 // selection saved separately in OnBlur().
426 if (!HasFocus() && saved_selection_for_focus_change_.IsValid()) {
427 SelectRange(saved_selection_for_focus_change_);
tapted 2016/09/27 07:16:30 I don't think we need to select it (I'm actually n
Patti Lor 2016/10/20 04:19:34 Done.
428 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
429 }
430 gfx::Range selection_range = GetSelectedRange();
431 base::string16 current_text = GetText();
432 base::string16 new_string =
433 current_text.substr(0, selection_range.GetMin()) + new_value +
434 current_text.substr(selection_range.GetMax(), current_text.length());
tapted 2016/09/27 07:16:30 `current_text.length()` shouldn't be needed on the
Patti Lor 2016/10/20 04:19:34 Done.
435 SetUserText(new_string, true);
tapted 2016/09/27 07:16:30 Calling AccessibilitySetValue(new_string) is proba
Patti Lor 2016/10/20 04:19:34 No longer needed after your |replace| arg suggesti
436 SetSelectionRange(gfx::Range(selection_range.GetMin() + new_value.length()));
tapted 2016/09/27 07:16:30 Same here - I don't think we can set a selection w
Patti Lor 2016/10/20 04:19:34 Sorry - this is an inconsistency that I've now del
437 }
438
422 void OmniboxViewViews::UpdateSecurityLevel() { 439 void OmniboxViewViews::UpdateSecurityLevel() {
423 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false); 440 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
424 } 441 }
425 442
426 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, 443 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
427 size_t caret_pos, 444 size_t caret_pos,
428 bool update_popup, 445 bool update_popup,
429 bool notify_text_changed) { 446 bool notify_text_changed) {
430 const gfx::Range range(caret_pos, caret_pos); 447 const gfx::Range range(caret_pos, caret_pos);
431 SetTextAndSelectedRange(text, range); 448 SetTextAndSelectedRange(text, range);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 return Textfield::SkipDefaultKeyEventProcessing(event); 751 return Textfield::SkipDefaultKeyEventProcessing(event);
735 } 752 }
736 753
737 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { 754 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) {
738 state->role = ui::AX_ROLE_TEXT_FIELD; 755 state->role = ui::AX_ROLE_TEXT_FIELD;
739 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); 756 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION);
740 state->value = GetText(); 757 state->value = GetText();
741 758
742 base::string16::size_type entry_start; 759 base::string16::size_type entry_start;
743 base::string16::size_type entry_end; 760 base::string16::size_type entry_end;
744 GetSelectionBounds(&entry_start, &entry_end); 761 GetSelectionBounds(&entry_start, &entry_end);
tapted 2016/09/27 07:16:30 move to an `else`?
Patti Lor 2016/10/20 04:19:33 Done.
762 // Selection information is saved separately when focus is moved off the
763 // current window - use that when there is no focus and it's valid.
764 if (!HasFocus() && saved_selection_for_focus_change_.IsValid()) {
tapted 2016/09/27 07:16:30 `!HasFocus()` might not be required -- pretty sure
Patti Lor 2016/10/20 04:19:34 Done.
765 entry_start = saved_selection_for_focus_change_.start();
766 entry_end = saved_selection_for_focus_change_.end();
767 }
745 state->selection_start = entry_start; 768 state->selection_start = entry_start;
746 state->selection_end = entry_end; 769 state->selection_end = entry_end;
747 770
748 if (popup_window_mode_) { 771 if (popup_window_mode_) {
749 state->AddStateFlag(ui::AX_STATE_READ_ONLY); 772 state->AddStateFlag(ui::AX_STATE_READ_ONLY);
750 } else { 773 } else {
751 state->AddStateFlag(ui::AX_STATE_EDITABLE); 774 state->AddStateFlag(ui::AX_STATE_EDITABLE);
752 state->set_value_callback = 775 state->set_value_callback =
753 base::Bind(&OmniboxViewViews::AccessibilitySetValue, 776 base::Bind(&OmniboxViewViews::AccessibilitySetValue,
754 weak_ptr_factory_.GetWeakPtr()); 777 weak_ptr_factory_.GetWeakPtr());
778 state->replace_selection_callback =
779 base::Bind(&OmniboxViewViews::AccessibilityReplaceSelection,
780 weak_ptr_factory_.GetWeakPtr());
755 } 781 }
756 } 782 }
757 783
758 void OmniboxViewViews::OnFocus() { 784 void OmniboxViewViews::OnFocus() {
759 views::Textfield::OnFocus(); 785 views::Textfield::OnFocus();
760 // TODO(oshima): Get control key state. 786 // TODO(oshima): Get control key state.
761 model()->OnSetFocus(false); 787 model()->OnSetFocus(false);
762 // Don't call controller()->OnSetFocus, this view has already acquired focus. 788 // Don't call controller()->OnSetFocus, this view has already acquired focus.
763 789
764 // Restore the selection we saved in OnBlur() if it's still valid. 790 // Restore the selection we saved in OnBlur() if it's still valid.
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1102 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1077 1103
1078 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1104 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1079 1105
1080 // Minor note: We use IDC_ for command id here while the underlying textfield 1106 // Minor note: We use IDC_ for command id here while the underlying textfield
1081 // is using IDS_ for all its command ids. This is because views cannot depend 1107 // is using IDS_ for all its command ids. This is because views cannot depend
1082 // on IDC_ for now. 1108 // on IDC_ for now.
1083 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1109 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1084 IDS_EDIT_SEARCH_ENGINES); 1110 IDS_EDIT_SEARCH_ENGINES);
1085 } 1111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698