| 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); |
| 470 |
| 471 if (update_popup) |
| 472 UpdatePopup(); |
| 473 |
| 474 if (notify_text_changed) |
| 475 TextChanged(); |
| 462 } | 476 } |
| 463 | 477 |
| 464 void OmniboxViewViews::SetForcedQuery() { | 478 void OmniboxViewViews::SetForcedQuery() { |
| 465 const string16 current_text(GetText()); | 479 const string16 current_text(GetText()); |
| 466 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); | 480 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); |
| 467 if (start == string16::npos || (current_text[start] != '?')) | 481 if (start == string16::npos || (current_text[start] != '?')) |
| 468 SetUserText(ASCIIToUTF16("?")); | 482 SetUserText(ASCIIToUTF16("?")); |
| 469 else | 483 else |
| 470 textfield_->SelectRange(ui::Range(current_text.size(), start + 1)); | 484 textfield_->SelectRange(ui::Range(current_text.size(), start + 1)); |
| 471 } | 485 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 // In views-implementation, the focus is on textfield rather than OmniboxView. | 539 // In views-implementation, the focus is on textfield rather than OmniboxView. |
| 526 textfield_->RequestFocus(); | 540 textfield_->RequestFocus(); |
| 527 } | 541 } |
| 528 | 542 |
| 529 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 543 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
| 530 const string16& display_text, | 544 const string16& display_text, |
| 531 bool save_original_selection) { | 545 bool save_original_selection) { |
| 532 if (save_original_selection) | 546 if (save_original_selection) |
| 533 textfield_->GetSelectedRange(&saved_temporary_selection_); | 547 textfield_->GetSelectedRange(&saved_temporary_selection_); |
| 534 | 548 |
| 535 SetWindowTextAndCaretPos(display_text, display_text.length()); | 549 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
| 536 TextChanged(); | |
| 537 } | 550 } |
| 538 | 551 |
| 539 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 552 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
| 540 const string16& display_text, | 553 const string16& display_text, |
| 541 size_t user_text_length) { | 554 size_t user_text_length) { |
| 542 if (display_text == GetText()) | 555 if (display_text == GetText()) |
| 543 return false; | 556 return false; |
| 544 ui::Range range(display_text.size(), user_text_length); | 557 ui::Range range(display_text.size(), user_text_length); |
| 545 SetTextAndSelectedRange(display_text, range); | 558 SetTextAndSelectedRange(display_text, range); |
| 546 TextChanged(); | 559 TextChanged(); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 844 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
| 832 toolbar_model, | 845 toolbar_model, |
| 833 profile, | 846 profile, |
| 834 command_updater, | 847 command_updater, |
| 835 popup_window_mode, | 848 popup_window_mode, |
| 836 location_bar); | 849 location_bar); |
| 837 omnibox_view->Init(); | 850 omnibox_view->Init(); |
| 838 return omnibox_view; | 851 return omnibox_view; |
| 839 } | 852 } |
| 840 #endif | 853 #endif |
| OLD | NEW |