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 "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 Loading... | |
| 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 bool clear_first) { |
| 419 base::string16 new_string = new_value; | |
| 420 if (!clear_first) { | |
| 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 new_string = current_text.substr(0, selection_range.GetMin()) + new_value + | |
| 426 current_text.substr(selection_range.GetMax()); | |
| 427 } | |
| 428 SetUserText(new_string, true); | |
|
dmazzoni
2016/10/26 04:26:02
Could you use InsertOrReplaceText() when clear_fir
Patti Lor
2016/10/27 00:38:48
Thanks for trying to dig deeper on this - I did or
| |
| 419 } | 429 } |
| 420 | 430 |
| 421 void OmniboxViewViews::UpdateSecurityLevel() { | 431 void OmniboxViewViews::UpdateSecurityLevel() { |
| 422 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false); | 432 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false); |
| 423 } | 433 } |
| 424 | 434 |
| 425 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, | 435 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, |
| 426 size_t caret_pos, | 436 size_t caret_pos, |
| 427 bool update_popup, | 437 bool update_popup, |
| 428 bool notify_text_changed) { | 438 bool notify_text_changed) { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 return Textfield::SkipDefaultKeyEventProcessing(event); | 742 return Textfield::SkipDefaultKeyEventProcessing(event); |
| 733 } | 743 } |
| 734 | 744 |
| 735 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { | 745 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { |
| 736 state->role = ui::AX_ROLE_TEXT_FIELD; | 746 state->role = ui::AX_ROLE_TEXT_FIELD; |
| 737 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | 747 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); |
| 738 state->value = GetText(); | 748 state->value = GetText(); |
| 739 | 749 |
| 740 base::string16::size_type entry_start; | 750 base::string16::size_type entry_start; |
| 741 base::string16::size_type entry_end; | 751 base::string16::size_type entry_end; |
| 742 GetSelectionBounds(&entry_start, &entry_end); | 752 // Selection information is saved separately when focus is moved off the |
| 753 // current window - use that when there is no focus and it's valid. | |
| 754 if (saved_selection_for_focus_change_.IsValid()) { | |
| 755 entry_start = saved_selection_for_focus_change_.start(); | |
| 756 entry_end = saved_selection_for_focus_change_.end(); | |
| 757 } else { | |
| 758 GetSelectionBounds(&entry_start, &entry_end); | |
| 759 } | |
| 743 state->selection_start = entry_start; | 760 state->selection_start = entry_start; |
| 744 state->selection_end = entry_end; | 761 state->selection_end = entry_end; |
| 745 | 762 |
| 746 if (popup_window_mode_) { | 763 if (popup_window_mode_) { |
| 747 state->AddStateFlag(ui::AX_STATE_READ_ONLY); | 764 state->AddStateFlag(ui::AX_STATE_READ_ONLY); |
| 748 } else { | 765 } else { |
| 749 state->AddStateFlag(ui::AX_STATE_EDITABLE); | 766 state->AddStateFlag(ui::AX_STATE_EDITABLE); |
| 750 state->set_value_callback = | 767 state->set_value_callback = |
| 751 base::Bind(&OmniboxViewViews::AccessibilitySetValue, | 768 base::Bind(&OmniboxViewViews::AccessibilitySetValue, |
| 752 weak_ptr_factory_.GetWeakPtr()); | 769 weak_ptr_factory_.GetWeakPtr()); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1074 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1091 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 1075 | 1092 |
| 1076 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1093 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1077 | 1094 |
| 1078 // Minor note: We use IDC_ for command id here while the underlying textfield | 1095 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 1079 // is using IDS_ for all its command ids. This is because views cannot depend | 1096 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1080 // on IDC_ for now. | 1097 // on IDC_ for now. |
| 1081 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1098 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1082 IDS_EDIT_SEARCH_ENGINES); | 1099 IDS_EDIT_SEARCH_ENGINES); |
| 1083 } | 1100 } |
| OLD | NEW |