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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if (model_->popup_model()->IsOpen()) | 257 if (model_->popup_model()->IsOpen()) |
258 model_->popup_model()->TryDeletingCurrentItem(); | 258 model_->popup_model()->TryDeletingCurrentItem(); |
259 } else if (!handled && event.key_code() == ui::VKEY_UP) { | 259 } else if (!handled && event.key_code() == ui::VKEY_UP) { |
260 model_->OnUpOrDownKeyPressed(-1); | 260 model_->OnUpOrDownKeyPressed(-1); |
261 handled = true; | 261 handled = true; |
262 } else if (!handled && event.key_code() == ui::VKEY_DOWN) { | 262 } else if (!handled && event.key_code() == ui::VKEY_DOWN) { |
263 model_->OnUpOrDownKeyPressed(1); | 263 model_->OnUpOrDownKeyPressed(1); |
264 handled = true; | 264 handled = true; |
265 } else if (!handled && | 265 } else if (!handled && |
266 event.key_code() == ui::VKEY_TAB && | 266 event.key_code() == ui::VKEY_TAB && |
267 !event.IsShiftDown() && | |
268 !event.IsControlDown()) { | 267 !event.IsControlDown()) { |
269 if (model_->is_keyword_hint()) { | 268 if (model_->is_keyword_hint() && !event.IsShiftDown()) { |
270 handled = model_->AcceptKeyword(); | 269 handled = model_->AcceptKeyword(); |
| 270 } else if (model_->popup_model()->IsOpen()) { |
| 271 if (event.IsShiftDown() && |
| 272 model_->popup_model()->selected_line_state() == |
| 273 AutocompletePopupModel::KEYWORD) { |
| 274 model_->ClearKeyword(GetText()); |
| 275 } else { |
| 276 model_->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); |
| 277 } |
| 278 handled = true; |
271 } else { | 279 } else { |
272 string16::size_type start = 0; | 280 string16::size_type start = 0; |
273 string16::size_type end = 0; | 281 string16::size_type end = 0; |
274 size_t length = GetTextLength(); | 282 size_t length = GetTextLength(); |
275 GetSelectionBounds(&start, &end); | 283 GetSelectionBounds(&start, &end); |
276 if (start != end || start < length) { | 284 if (start != end || start < length) { |
277 OnBeforePossibleChange(); | 285 OnBeforePossibleChange(); |
278 textfield_->SelectRange(ui::Range(length, length)); | 286 textfield_->SelectRange(ui::Range(length, length)); |
279 OnAfterPossibleChange(); | 287 OnAfterPossibleChange(); |
280 handled = true; | 288 handled = true; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 462 } |
455 | 463 |
456 void OmniboxViewViews::SetUserText(const string16& text) { | 464 void OmniboxViewViews::SetUserText(const string16& text) { |
457 SetUserText(text, text, true); | 465 SetUserText(text, text, true); |
458 } | 466 } |
459 | 467 |
460 void OmniboxViewViews::SetUserText(const string16& text, | 468 void OmniboxViewViews::SetUserText(const string16& text, |
461 const string16& display_text, | 469 const string16& display_text, |
462 bool update_popup) { | 470 bool update_popup) { |
463 model_->SetUserText(text); | 471 model_->SetUserText(text); |
464 SetWindowTextAndCaretPos(display_text, display_text.length()); | 472 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, |
465 if (update_popup) | 473 true); |
466 UpdatePopup(); | |
467 TextChanged(); | |
468 } | 474 } |
469 | 475 |
470 void OmniboxViewViews::SetWindowTextAndCaretPos(const string16& text, | 476 void OmniboxViewViews::SetWindowTextAndCaretPos(const string16& text, |
471 size_t caret_pos) { | 477 size_t caret_pos, |
| 478 bool update_popup, |
| 479 bool notify_text_changed) { |
472 const ui::Range range(caret_pos, caret_pos); | 480 const ui::Range range(caret_pos, caret_pos); |
473 SetTextAndSelectedRange(text, range); | 481 SetTextAndSelectedRange(text, range); |
474 } | 482 } |
475 | 483 |
476 void OmniboxViewViews::SetForcedQuery() { | 484 void OmniboxViewViews::SetForcedQuery() { |
477 const string16 current_text(GetText()); | 485 const string16 current_text(GetText()); |
478 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); | 486 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); |
479 if (start == string16::npos || (current_text[start] != '?')) | 487 if (start == string16::npos || (current_text[start] != '?')) |
480 SetUserText(ASCIIToUTF16("?")); | 488 SetUserText(ASCIIToUTF16("?")); |
481 else | 489 else |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 // In views-implementation, the focus is on textfield rather than OmniboxView. | 545 // In views-implementation, the focus is on textfield rather than OmniboxView. |
538 textfield_->RequestFocus(); | 546 textfield_->RequestFocus(); |
539 } | 547 } |
540 | 548 |
541 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 549 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
542 const string16& display_text, | 550 const string16& display_text, |
543 bool save_original_selection) { | 551 bool save_original_selection) { |
544 if (save_original_selection) | 552 if (save_original_selection) |
545 textfield_->GetSelectedRange(&saved_temporary_selection_); | 553 textfield_->GetSelectedRange(&saved_temporary_selection_); |
546 | 554 |
547 SetWindowTextAndCaretPos(display_text, display_text.length()); | 555 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
548 TextChanged(); | |
549 } | 556 } |
550 | 557 |
551 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 558 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
552 const string16& display_text, | 559 const string16& display_text, |
553 size_t user_text_length) { | 560 size_t user_text_length) { |
554 if (display_text == GetText()) | 561 if (display_text == GetText()) |
555 return false; | 562 return false; |
556 ui::Range range(display_text.size(), user_text_length); | 563 ui::Range range(display_text.size(), user_text_length); |
557 SetTextAndSelectedRange(display_text, range); | 564 SetTextAndSelectedRange(display_text, range); |
558 TextChanged(); | 565 TextChanged(); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 860 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
854 toolbar_model, | 861 toolbar_model, |
855 profile, | 862 profile, |
856 command_updater, | 863 command_updater, |
857 popup_window_mode, | 864 popup_window_mode, |
858 location_bar); | 865 location_bar); |
859 omnibox_view->Init(); | 866 omnibox_view->Init(); |
860 return omnibox_view; | 867 return omnibox_view; |
861 } | 868 } |
862 #endif | 869 #endif |
OLD | NEW |