| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 bool popup_window_mode, | 217 bool popup_window_mode, |
| 218 LocationBarView* location_bar) | 218 LocationBarView* location_bar) |
| 219 : OmniboxView(profile, controller, toolbar_model, command_updater), | 219 : OmniboxView(profile, controller, toolbar_model, command_updater), |
| 220 textfield_(NULL), | 220 textfield_(NULL), |
| 221 popup_window_mode_(popup_window_mode), | 221 popup_window_mode_(popup_window_mode), |
| 222 security_level_(ToolbarModel::NONE), | 222 security_level_(ToolbarModel::NONE), |
| 223 ime_composing_before_change_(false), | 223 ime_composing_before_change_(false), |
| 224 delete_at_end_pressed_(false), | 224 delete_at_end_pressed_(false), |
| 225 location_bar_view_(location_bar), | 225 location_bar_view_(location_bar), |
| 226 ime_candidate_window_open_(false), | 226 ime_candidate_window_open_(false), |
| 227 select_all_on_mouse_release_(false) { | 227 select_all_on_mouse_release_(false), |
| 228 visible_caret_color_(SK_ColorBLACK) { |
| 228 } | 229 } |
| 229 | 230 |
| 230 OmniboxViewViews::~OmniboxViewViews() { | 231 OmniboxViewViews::~OmniboxViewViews() { |
| 231 #if defined(OS_CHROMEOS) | 232 #if defined(OS_CHROMEOS) |
| 232 chromeos::input_method::InputMethodManager::GetInstance()-> | 233 chromeos::input_method::InputMethodManager::GetInstance()-> |
| 233 RemoveCandidateWindowObserver(this); | 234 RemoveCandidateWindowObserver(this); |
| 234 #endif | 235 #endif |
| 235 | 236 |
| 236 // Explicitly teardown members which have a reference to us. Just to be safe | 237 // Explicitly teardown members which have a reference to us. Just to be safe |
| 237 // we want them to be destroyed before destroying any other internal state. | 238 // we want them to be destroyed before destroying any other internal state. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 aura::client::FocusClient* client = | 400 aura::client::FocusClient* client = |
| 400 aura::client::GetFocusClient(widget->GetNativeView()); | 401 aura::client::GetFocusClient(widget->GetNativeView()); |
| 401 if (client) | 402 if (client) |
| 402 native_view = client->GetFocusedWindow(); | 403 native_view = client->GetFocusedWindow(); |
| 403 } | 404 } |
| 404 #endif | 405 #endif |
| 405 model()->OnWillKillFocus(native_view); | 406 model()->OnWillKillFocus(native_view); |
| 406 // Close the popup. | 407 // Close the popup. |
| 407 CloseOmniboxPopup(); | 408 CloseOmniboxPopup(); |
| 408 // Tell the model to reset itself. | 409 // Tell the model to reset itself. |
| 410 model()->SetCaretVisibility(true); |
| 409 model()->OnKillFocus(); | 411 model()->OnKillFocus(); |
| 410 controller()->OnKillFocus(); | 412 controller()->OnKillFocus(); |
| 411 } | 413 } |
| 412 | 414 |
| 413 void OmniboxViewViews::SetLocationEntryFocusable(bool focusable) { | 415 void OmniboxViewViews::SetLocationEntryFocusable(bool focusable) { |
| 414 textfield_->set_focusable(focusable); | 416 textfield_->set_focusable(focusable); |
| 415 } | 417 } |
| 416 | 418 |
| 417 bool OmniboxViewViews::IsLocationEntryFocusableInRootView() const { | 419 bool OmniboxViewViews::IsLocationEntryFocusableInRootView() const { |
| 418 return textfield_->IsFocusable(); | 420 return textfield_->IsFocusable(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 438 std::string OmniboxViewViews::GetClassName() const { | 440 std::string OmniboxViewViews::GetClassName() const { |
| 439 return kViewClassName; | 441 return kViewClassName; |
| 440 } | 442 } |
| 441 | 443 |
| 442 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 444 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 443 if (popup_view_->IsOpen()) | 445 if (popup_view_->IsOpen()) |
| 444 popup_view_->UpdatePopupAppearance(); | 446 popup_view_->UpdatePopupAppearance(); |
| 445 } | 447 } |
| 446 | 448 |
| 447 //////////////////////////////////////////////////////////////////////////////// | 449 //////////////////////////////////////////////////////////////////////////////// |
| 448 // OmniboxViewViews, AutocopmleteEditView implementation: | 450 // OmniboxViewViews, OmniboxView implementation: |
| 449 | 451 |
| 450 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { | 452 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { |
| 451 DCHECK(tab); | 453 DCHECK(tab); |
| 452 | 454 |
| 453 // We don't want to keep the IME status, so force quit the current | 455 // We don't want to keep the IME status, so force quit the current |
| 454 // session here. It may affect the selection status, so order is | 456 // session here. It may affect the selection status, so order is |
| 455 // also important. | 457 // also important. |
| 456 if (textfield_->IsIMEComposing()) { | 458 if (textfield_->IsIMEComposing()) { |
| 457 textfield_->GetTextInputClient()->ConfirmCompositionText(); | 459 textfield_->GetTextInputClient()->ConfirmCompositionText(); |
| 458 textfield_->GetInputMethod()->CancelComposition(textfield_); | 460 textfield_->GetInputMethod()->CancelComposition(textfield_); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // the text, or in the middle of composition. | 569 // the text, or in the middle of composition. |
| 568 ui::Range sel; | 570 ui::Range sel; |
| 569 textfield_->GetSelectedRange(&sel); | 571 textfield_->GetSelectedRange(&sel); |
| 570 bool no_inline_autocomplete = | 572 bool no_inline_autocomplete = |
| 571 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); | 573 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); |
| 572 | 574 |
| 573 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); | 575 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); |
| 574 } | 576 } |
| 575 | 577 |
| 576 void OmniboxViewViews::SetFocus() { | 578 void OmniboxViewViews::SetFocus() { |
| 579 model()->SetCaretVisibility(true); |
| 577 // In views-implementation, the focus is on textfield rather than OmniboxView. | 580 // In views-implementation, the focus is on textfield rather than OmniboxView. |
| 578 textfield_->RequestFocus(); | 581 textfield_->RequestFocus(); |
| 579 } | 582 } |
| 580 | 583 |
| 584 void OmniboxViewViews::ApplyCaretVisibility() { |
| 585 if (textfield_->cursor_color() != textfield_->background_color()) |
| 586 visible_caret_color_ = textfield_->cursor_color(); |
| 587 // Setting the color of the text cursor (caret) to the background color |
| 588 // effectively hides it. |
| 589 textfield_->SetCursorColor(model()->is_caret_visible() ? |
| 590 visible_caret_color_ : textfield_->background_color()); |
| 591 } |
| 592 |
| 581 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 593 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
| 582 const string16& display_text, | 594 const string16& display_text, |
| 583 bool save_original_selection) { | 595 bool save_original_selection) { |
| 584 if (save_original_selection) | 596 if (save_original_selection) |
| 585 textfield_->GetSelectedRange(&saved_temporary_selection_); | 597 textfield_->GetSelectedRange(&saved_temporary_selection_); |
| 586 | 598 |
| 587 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 599 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
| 588 } | 600 } |
| 589 | 601 |
| 590 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 602 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
| 591 const string16& display_text, | 603 const string16& display_text, |
| 592 size_t user_text_length) { | 604 size_t user_text_length) { |
| 593 if (display_text == GetText()) | 605 if (display_text == GetText()) |
| 594 return false; | 606 return false; |
| 595 ui::Range range(display_text.size(), user_text_length); | 607 ui::Range range(display_text.size(), user_text_length); |
| 596 SetTextAndSelectedRange(display_text, range); | 608 SetTextAndSelectedRange(display_text, range); |
| 597 TextChanged(); | 609 TextChanged(); |
| 598 return true; | 610 return true; |
| 599 } | 611 } |
| 600 | 612 |
| 601 void OmniboxViewViews::OnRevertTemporaryText() { | 613 void OmniboxViewViews::OnRevertTemporaryText() { |
| 602 textfield_->SelectRange(saved_temporary_selection_); | 614 textfield_->SelectRange(saved_temporary_selection_); |
| 603 TextChanged(); | 615 TextChanged(); |
| 604 } | 616 } |
| 605 | 617 |
| 606 void OmniboxViewViews::OnBeforePossibleChange() { | 618 void OmniboxViewViews::OnBeforePossibleChange() { |
| 619 // We set the focus to visible here to cover two cases. This is called when |
| 620 // the user directly clicks on the omnibox as well as when a character is |
| 621 // about to be entered. |
| 622 model()->SetCaretVisibility(true); |
| 607 // Record our state. | 623 // Record our state. |
| 608 text_before_change_ = GetText(); | 624 text_before_change_ = GetText(); |
| 609 textfield_->GetSelectedRange(&sel_before_change_); | 625 textfield_->GetSelectedRange(&sel_before_change_); |
| 610 ime_composing_before_change_ = textfield_->IsIMEComposing(); | 626 ime_composing_before_change_ = textfield_->IsIMEComposing(); |
| 611 } | 627 } |
| 612 | 628 |
| 613 bool OmniboxViewViews::OnAfterPossibleChange() { | 629 bool OmniboxViewViews::OnAfterPossibleChange() { |
| 614 ui::Range new_sel; | 630 ui::Range new_sel; |
| 615 textfield_->GetSelectedRange(&new_sel); | 631 textfield_->GetSelectedRange(&new_sel); |
| 616 | 632 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 if (!text.empty()) { | 950 if (!text.empty()) { |
| 935 // Record this paste, so we can do different behavior. | 951 // Record this paste, so we can do different behavior. |
| 936 model()->on_paste(); | 952 model()->on_paste(); |
| 937 // Force a Paste operation to trigger the text_changed code in | 953 // Force a Paste operation to trigger the text_changed code in |
| 938 // OnAfterPossibleChange(), even if identical contents are pasted into the | 954 // OnAfterPossibleChange(), even if identical contents are pasted into the |
| 939 // text box. | 955 // text box. |
| 940 text_before_change_.clear(); | 956 text_before_change_.clear(); |
| 941 textfield_->ReplaceSelection(text); | 957 textfield_->ReplaceSelection(text); |
| 942 } | 958 } |
| 943 } | 959 } |
| OLD | NEW |