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

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: Delete unused method declarations and revert redundant a11y notification. 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 if (event.IsShiftDown() && 407 if (event.IsShiftDown() &&
408 (model()->popup_model()->selected_line_state() == 408 (model()->popup_model()->selected_line_state() ==
409 OmniboxPopupModel::KEYWORD)) 409 OmniboxPopupModel::KEYWORD))
410 model()->ClearKeyword(); 410 model()->ClearKeyword();
411 else 411 else
412 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); 412 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1);
413 413
414 return true; 414 return true;
415 } 415 }
416 416
417 void OmniboxViewViews::AccessibilitySetValue(const base::string16& new_value) { 417 void OmniboxViewViews::AccessibilitySetValue(const base::string16& new_value,
418 SetUserText(new_value, true); 418 const bool& replace) {
419 base::string16 new_string = new_value;
420 if (replace) {
421 gfx::Range selection_range = saved_selection_for_focus_change_.IsValid()
422 ? saved_selection_for_focus_change_
423 : GetSelectedRange();
424 base::string16 current_text = GetText();
425 base::string16 new_string =
426 current_text.substr(0, selection_range.GetMin()) + new_value +
427 current_text.substr(selection_range.GetMax());
428 }
429 SetUserText(new_string, true);
419 } 430 }
420 431
421 void OmniboxViewViews::UpdateSecurityLevel() { 432 void OmniboxViewViews::UpdateSecurityLevel() {
422 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false); 433 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
423 } 434 }
424 435
425 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, 436 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
426 size_t caret_pos, 437 size_t caret_pos,
427 bool update_popup, 438 bool update_popup,
428 bool notify_text_changed) { 439 bool notify_text_changed) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 return Textfield::SkipDefaultKeyEventProcessing(event); 744 return Textfield::SkipDefaultKeyEventProcessing(event);
734 } 745 }
735 746
736 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { 747 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) {
737 state->role = ui::AX_ROLE_TEXT_FIELD; 748 state->role = ui::AX_ROLE_TEXT_FIELD;
738 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); 749 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION);
739 state->value = GetText(); 750 state->value = GetText();
740 751
741 base::string16::size_type entry_start; 752 base::string16::size_type entry_start;
742 base::string16::size_type entry_end; 753 base::string16::size_type entry_end;
743 GetSelectionBounds(&entry_start, &entry_end); 754 // Selection information is saved separately when focus is moved off the
755 // current window - use that when there is no focus and it's valid.
756 if (saved_selection_for_focus_change_.IsValid()) {
757 entry_start = saved_selection_for_focus_change_.start();
758 entry_end = saved_selection_for_focus_change_.end();
759 } else {
760 GetSelectionBounds(&entry_start, &entry_end);
761 }
744 state->selection_start = entry_start; 762 state->selection_start = entry_start;
745 state->selection_end = entry_end; 763 state->selection_end = entry_end;
746 764
747 if (popup_window_mode_) { 765 if (popup_window_mode_) {
748 state->AddStateFlag(ui::AX_STATE_READ_ONLY); 766 state->AddStateFlag(ui::AX_STATE_READ_ONLY);
749 } else { 767 } else {
750 state->AddStateFlag(ui::AX_STATE_EDITABLE); 768 state->AddStateFlag(ui::AX_STATE_EDITABLE);
751 state->set_value_callback = 769 state->set_value_callback =
752 base::Bind(&OmniboxViewViews::AccessibilitySetValue, 770 base::Bind(&OmniboxViewViews::AccessibilitySetValue,
753 weak_ptr_factory_.GetWeakPtr()); 771 weak_ptr_factory_.GetWeakPtr());
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1093 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1076 1094
1077 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1095 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1078 1096
1079 // Minor note: We use IDC_ for command id here while the underlying textfield 1097 // Minor note: We use IDC_ for command id here while the underlying textfield
1080 // is using IDS_ for all its command ids. This is because views cannot depend 1098 // is using IDS_ for all its command ids. This is because views cannot depend
1081 // on IDC_ for now. 1099 // on IDC_ for now.
1082 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1100 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1083 IDS_EDIT_SEARCH_ENGINES); 1101 IDS_EDIT_SEARCH_ENGINES);
1084 } 1102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698