Chromium Code Reviews| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 model()->OnControlKeyChanged(false); | 362 model()->OnControlKeyChanged(false); |
| 362 return true; | 363 return true; |
| 363 } | 364 } |
| 364 return false; | 365 return false; |
| 365 } | 366 } |
| 366 | 367 |
| 367 void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) { | 368 void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) { |
| 368 select_all_on_mouse_release_ = | 369 select_all_on_mouse_release_ = |
| 369 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && | 370 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
| 370 !textfield_->HasFocus(); | 371 !textfield_->HasFocus(); |
| 372 // Restore caret visibility whenever the user clicks in the the omnibox. This | |
| 373 // is not always covered by OnSetFocus() because when clicking while the | |
| 374 // omnibox has invisible focus does not trigger a new OnSetFocus() call. | |
| 375 model()->SetCaretVisibility(true); | |
| 371 } | 376 } |
| 372 | 377 |
| 373 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { | 378 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { |
| 374 select_all_on_mouse_release_ = false; | 379 select_all_on_mouse_release_ = false; |
| 375 } | 380 } |
| 376 | 381 |
| 377 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) { | 382 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) { |
| 378 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && | 383 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
| 379 select_all_on_mouse_release_) { | 384 select_all_on_mouse_release_) { |
| 380 // Select all in the reverse direction so as not to scroll the caret | 385 // Select all in the reverse direction so as not to scroll the caret |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 std::string OmniboxViewViews::GetClassName() const { | 443 std::string OmniboxViewViews::GetClassName() const { |
| 439 return kViewClassName; | 444 return kViewClassName; |
| 440 } | 445 } |
| 441 | 446 |
| 442 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 447 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 443 if (popup_view_->IsOpen()) | 448 if (popup_view_->IsOpen()) |
| 444 popup_view_->UpdatePopupAppearance(); | 449 popup_view_->UpdatePopupAppearance(); |
| 445 } | 450 } |
| 446 | 451 |
| 447 //////////////////////////////////////////////////////////////////////////////// | 452 //////////////////////////////////////////////////////////////////////////////// |
| 448 // OmniboxViewViews, AutocopmleteEditView implementation: | 453 // OmniboxViewViews, OmniboxView implementation: |
| 449 | 454 |
| 450 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { | 455 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { |
| 451 DCHECK(tab); | 456 DCHECK(tab); |
| 452 | 457 |
| 453 // We don't want to keep the IME status, so force quit the current | 458 // 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 | 459 // session here. It may affect the selection status, so order is |
| 455 // also important. | 460 // also important. |
| 456 if (textfield_->IsIMEComposing()) { | 461 if (textfield_->IsIMEComposing()) { |
| 457 textfield_->GetTextInputClient()->ConfirmCompositionText(); | 462 textfield_->GetTextInputClient()->ConfirmCompositionText(); |
| 458 textfield_->GetInputMethod()->CancelComposition(textfield_); | 463 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. | 572 // the text, or in the middle of composition. |
| 568 ui::Range sel; | 573 ui::Range sel; |
| 569 textfield_->GetSelectedRange(&sel); | 574 textfield_->GetSelectedRange(&sel); |
| 570 bool no_inline_autocomplete = | 575 bool no_inline_autocomplete = |
| 571 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); | 576 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); |
| 572 | 577 |
| 573 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); | 578 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); |
| 574 } | 579 } |
| 575 | 580 |
| 576 void OmniboxViewViews::SetFocus() { | 581 void OmniboxViewViews::SetFocus() { |
| 582 // Restore caret visibility if focused explicitly. | |
|
Peter Kasting
2012/12/05 00:52:53
Nit: Add: "We need to do this here because if we a
samarth
2012/12/05 01:15:51
Yes, exactly; updated comment.
| |
| 583 model()->SetCaretVisibility(true); | |
| 577 // In views-implementation, the focus is on textfield rather than OmniboxView. | 584 // In views-implementation, the focus is on textfield rather than OmniboxView. |
| 578 textfield_->RequestFocus(); | 585 textfield_->RequestFocus(); |
| 579 } | 586 } |
| 580 | 587 |
| 588 void OmniboxViewViews::ApplyCaretVisibility() { | |
| 589 if (textfield_->cursor_color() != textfield_->background_color()) | |
| 590 visible_caret_color_ = textfield_->cursor_color(); | |
| 591 // Setting the color of the text cursor (caret) to the background color | |
| 592 // effectively hides it. | |
| 593 textfield_->SetCursorColor(model()->is_caret_visible() ? | |
| 594 visible_caret_color_ : textfield_->background_color()); | |
| 595 } | |
| 596 | |
| 581 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 597 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
| 582 const string16& display_text, | 598 const string16& display_text, |
| 583 bool save_original_selection) { | 599 bool save_original_selection) { |
| 584 if (save_original_selection) | 600 if (save_original_selection) |
| 585 textfield_->GetSelectedRange(&saved_temporary_selection_); | 601 textfield_->GetSelectedRange(&saved_temporary_selection_); |
| 586 | 602 |
| 587 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 603 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
| 588 } | 604 } |
| 589 | 605 |
| 590 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 606 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
| (...skipping 343 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 |