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 "base/property_bag.h" | 7 #include "base/property_bag.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 if (model_->popup_model()->IsOpen()) | 248 if (model_->popup_model()->IsOpen()) |
249 model_->popup_model()->TryDeletingCurrentItem(); | 249 model_->popup_model()->TryDeletingCurrentItem(); |
250 } else if (!handled && event.key_code() == ui::VKEY_UP) { | 250 } else if (!handled && event.key_code() == ui::VKEY_UP) { |
251 model_->OnUpOrDownKeyPressed(-1); | 251 model_->OnUpOrDownKeyPressed(-1); |
252 handled = true; | 252 handled = true; |
253 } else if (!handled && event.key_code() == ui::VKEY_DOWN) { | 253 } else if (!handled && event.key_code() == ui::VKEY_DOWN) { |
254 model_->OnUpOrDownKeyPressed(1); | 254 model_->OnUpOrDownKeyPressed(1); |
255 handled = true; | 255 handled = true; |
256 } else if (!handled && | 256 } else if (!handled && |
257 event.key_code() == ui::VKEY_TAB && | 257 event.key_code() == ui::VKEY_TAB && |
258 !event.IsShiftDown() && | |
259 !event.IsControlDown()) { | 258 !event.IsControlDown()) { |
260 if (model_->is_keyword_hint()) { | 259 if (model_->is_keyword_hint() && !event.IsShiftDown()) { |
261 handled = model_->AcceptKeyword(); | 260 handled = model_->AcceptKeyword(); |
| 261 } else if (model_->popup_model()->IsOpen()) { |
| 262 if (event.IsShiftDown() && |
| 263 model_->popup_model()->selected_line_state() == |
| 264 AutocompletePopupModel::KEYWORD) { |
| 265 model_->ClearKeyword(GetText()); |
| 266 } else { |
| 267 model_->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); |
| 268 } |
| 269 handled = true; |
262 } else { | 270 } else { |
263 string16::size_type start = 0; | 271 string16::size_type start = 0; |
264 string16::size_type end = 0; | 272 string16::size_type end = 0; |
265 size_t length = GetTextLength(); | 273 size_t length = GetTextLength(); |
266 GetSelectionBounds(&start, &end); | 274 GetSelectionBounds(&start, &end); |
267 if (start != end || start < length) { | 275 if (start != end || start < length) { |
268 OnBeforePossibleChange(); | 276 OnBeforePossibleChange(); |
269 textfield_->SelectRange(ui::Range(length, length)); | 277 textfield_->SelectRange(ui::Range(length, length)); |
270 OnAfterPossibleChange(); | 278 OnAfterPossibleChange(); |
271 handled = true; | 279 handled = true; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 } | 450 } |
443 | 451 |
444 void OmniboxViewViews::SetUserText(const string16& text) { | 452 void OmniboxViewViews::SetUserText(const string16& text) { |
445 SetUserText(text, text, true); | 453 SetUserText(text, text, true); |
446 } | 454 } |
447 | 455 |
448 void OmniboxViewViews::SetUserText(const string16& text, | 456 void OmniboxViewViews::SetUserText(const string16& text, |
449 const string16& display_text, | 457 const string16& display_text, |
450 bool update_popup) { | 458 bool update_popup) { |
451 model_->SetUserText(text); | 459 model_->SetUserText(text); |
452 SetWindowTextAndCaretPos(display_text, display_text.length()); | 460 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, |
453 if (update_popup) | 461 true); |
454 UpdatePopup(); | |
455 TextChanged(); | |
456 } | 462 } |
457 | 463 |
458 void OmniboxViewViews::SetWindowTextAndCaretPos(const string16& text, | 464 void OmniboxViewViews::SetWindowTextAndCaretPos(const string16& text, |
459 size_t caret_pos) { | 465 size_t caret_pos, |
| 466 bool update_popup, |
| 467 bool notify_text_changed) { |
460 const ui::Range range(caret_pos, caret_pos); | 468 const ui::Range range(caret_pos, caret_pos); |
461 SetTextAndSelectedRange(text, range); | 469 SetTextAndSelectedRange(text, range); |
462 } | 470 } |
463 | 471 |
464 void OmniboxViewViews::SetForcedQuery() { | 472 void OmniboxViewViews::SetForcedQuery() { |
465 const string16 current_text(GetText()); | 473 const string16 current_text(GetText()); |
466 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); | 474 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); |
467 if (start == string16::npos || (current_text[start] != '?')) | 475 if (start == string16::npos || (current_text[start] != '?')) |
468 SetUserText(ASCIIToUTF16("?")); | 476 SetUserText(ASCIIToUTF16("?")); |
469 else | 477 else |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // In views-implementation, the focus is on textfield rather than OmniboxView. | 533 // In views-implementation, the focus is on textfield rather than OmniboxView. |
526 textfield_->RequestFocus(); | 534 textfield_->RequestFocus(); |
527 } | 535 } |
528 | 536 |
529 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 537 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
530 const string16& display_text, | 538 const string16& display_text, |
531 bool save_original_selection) { | 539 bool save_original_selection) { |
532 if (save_original_selection) | 540 if (save_original_selection) |
533 textfield_->GetSelectedRange(&saved_temporary_selection_); | 541 textfield_->GetSelectedRange(&saved_temporary_selection_); |
534 | 542 |
535 SetWindowTextAndCaretPos(display_text, display_text.length()); | 543 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
536 TextChanged(); | |
537 } | 544 } |
538 | 545 |
539 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 546 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
540 const string16& display_text, | 547 const string16& display_text, |
541 size_t user_text_length) { | 548 size_t user_text_length) { |
542 if (display_text == GetText()) | 549 if (display_text == GetText()) |
543 return false; | 550 return false; |
544 ui::Range range(display_text.size(), user_text_length); | 551 ui::Range range(display_text.size(), user_text_length); |
545 SetTextAndSelectedRange(display_text, range); | 552 SetTextAndSelectedRange(display_text, range); |
546 TextChanged(); | 553 TextChanged(); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 838 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
832 toolbar_model, | 839 toolbar_model, |
833 profile, | 840 profile, |
834 command_updater, | 841 command_updater, |
835 popup_window_mode, | 842 popup_window_mode, |
836 location_bar); | 843 location_bar); |
837 omnibox_view->Init(); | 844 omnibox_view->Init(); |
838 return omnibox_view; | 845 return omnibox_view; |
839 } | 846 } |
840 #endif | 847 #endif |
OLD | NEW |