| 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 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 return Textfield::SkipDefaultKeyEventProcessing(event); | 743 return Textfield::SkipDefaultKeyEventProcessing(event); |
| 733 } | 744 } |
| 734 | 745 |
| 735 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { | 746 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { |
| 736 state->role = ui::AX_ROLE_TEXT_FIELD; | 747 state->role = ui::AX_ROLE_TEXT_FIELD; |
| 737 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); | 748 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); |
| 738 state->value = GetText(); | 749 state->value = GetText(); |
| 739 | 750 |
| 740 base::string16::size_type entry_start; | 751 base::string16::size_type entry_start; |
| 741 base::string16::size_type entry_end; | 752 base::string16::size_type entry_end; |
| 742 GetSelectionBounds(&entry_start, &entry_end); | 753 // Selection information is saved separately when focus is moved off the |
| 754 // current window - use that when there is no focus and it's valid. |
| 755 if (saved_selection_for_focus_change_.IsValid()) { |
| 756 entry_start = saved_selection_for_focus_change_.start(); |
| 757 entry_end = saved_selection_for_focus_change_.end(); |
| 758 } else { |
| 759 GetSelectionBounds(&entry_start, &entry_end); |
| 760 } |
| 743 state->selection_start = entry_start; | 761 state->selection_start = entry_start; |
| 744 state->selection_end = entry_end; | 762 state->selection_end = entry_end; |
| 745 | 763 |
| 746 if (popup_window_mode_) { | 764 if (popup_window_mode_) { |
| 747 state->AddStateFlag(ui::AX_STATE_READ_ONLY); | 765 state->AddStateFlag(ui::AX_STATE_READ_ONLY); |
| 748 } else { | 766 } else { |
| 749 state->AddStateFlag(ui::AX_STATE_EDITABLE); | 767 state->AddStateFlag(ui::AX_STATE_EDITABLE); |
| 750 state->set_value_callback = | 768 state->set_value_callback = |
| 751 base::Bind(&OmniboxViewViews::AccessibilitySetValue, | 769 base::Bind(&OmniboxViewViews::AccessibilitySetValue, |
| 752 weak_ptr_factory_.GetWeakPtr()); | 770 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); | 1092 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 1075 | 1093 |
| 1076 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1094 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1077 | 1095 |
| 1078 // Minor note: We use IDC_ for command id here while the underlying textfield | 1096 // 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 | 1097 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1080 // on IDC_ for now. | 1098 // on IDC_ for now. |
| 1081 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1099 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1082 IDS_EDIT_SEARCH_ENGINES); | 1100 IDS_EDIT_SEARCH_ENGINES); |
| 1083 } | 1101 } |
| OLD | NEW |