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 HandleFocusIn() because when clicking while the | |
374 // omnibox has invisible focus does not trigger a new HandleFocusIn() 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 |
381 // into view and shift the contents jarringly. | 386 // into view and shift the contents jarringly. |
382 SelectAll(true); | 387 SelectAll(true); |
383 } | 388 } |
384 select_all_on_mouse_release_ = false; | 389 select_all_on_mouse_release_ = false; |
385 } | 390 } |
386 | 391 |
387 void OmniboxViewViews::HandleFocusIn() { | 392 void OmniboxViewViews::HandleFocusIn() { |
393 // Restore caret visibility whenever the user focuses back into the omnibox. | |
394 model()->SetCaretVisibility(true); | |
Peter Kasting
2012/12/04 22:55:49
Now that we've moved this to a function that uncon
samarth
2012/12/04 23:13:32
Done.
| |
388 // TODO(oshima): Get control key state. | 395 // TODO(oshima): Get control key state. |
389 model()->OnSetFocus(false); | 396 model()->OnSetFocus(false); |
390 // Don't call controller()->OnSetFocus as this view has already | 397 // Don't call controller()->OnSetFocus as this view has already |
391 // acquired the focus. | 398 // acquired the focus. |
392 } | 399 } |
393 | 400 |
394 void OmniboxViewViews::HandleFocusOut() { | 401 void OmniboxViewViews::HandleFocusOut() { |
395 gfx::NativeView native_view = NULL; | 402 gfx::NativeView native_view = NULL; |
396 #if defined(USE_AURA) | 403 #if defined(USE_AURA) |
397 views::Widget* widget = GetWidget(); | 404 views::Widget* widget = GetWidget(); |
398 if (widget) { | 405 if (widget) { |
399 aura::client::FocusClient* client = | 406 aura::client::FocusClient* client = |
400 aura::client::GetFocusClient(widget->GetNativeView()); | 407 aura::client::GetFocusClient(widget->GetNativeView()); |
401 if (client) | 408 if (client) |
402 native_view = client->GetFocusedWindow(); | 409 native_view = client->GetFocusedWindow(); |
403 } | 410 } |
404 #endif | 411 #endif |
405 model()->OnWillKillFocus(native_view); | 412 model()->OnWillKillFocus(native_view); |
406 // Close the popup. | 413 // Close the popup. |
407 CloseOmniboxPopup(); | 414 CloseOmniboxPopup(); |
408 // Tell the model to reset itself. | 415 // Tell the model to reset itself. |
416 model()->SetCaretVisibility(true); | |
Peter Kasting
2012/12/04 22:55:49
Why is this necessary if we set this on HandleFocu
samarth
2012/12/04 23:13:32
We'd added it out of paranoia before, but not nece
| |
409 model()->OnKillFocus(); | 417 model()->OnKillFocus(); |
410 controller()->OnKillFocus(); | 418 controller()->OnKillFocus(); |
411 } | 419 } |
412 | 420 |
413 void OmniboxViewViews::SetLocationEntryFocusable(bool focusable) { | 421 void OmniboxViewViews::SetLocationEntryFocusable(bool focusable) { |
414 textfield_->set_focusable(focusable); | 422 textfield_->set_focusable(focusable); |
415 } | 423 } |
416 | 424 |
417 bool OmniboxViewViews::IsLocationEntryFocusableInRootView() const { | 425 bool OmniboxViewViews::IsLocationEntryFocusableInRootView() const { |
418 return textfield_->IsFocusable(); | 426 return textfield_->IsFocusable(); |
(...skipping 19 matching lines...) Expand all Loading... | |
438 std::string OmniboxViewViews::GetClassName() const { | 446 std::string OmniboxViewViews::GetClassName() const { |
439 return kViewClassName; | 447 return kViewClassName; |
440 } | 448 } |
441 | 449 |
442 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 450 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
443 if (popup_view_->IsOpen()) | 451 if (popup_view_->IsOpen()) |
444 popup_view_->UpdatePopupAppearance(); | 452 popup_view_->UpdatePopupAppearance(); |
445 } | 453 } |
446 | 454 |
447 //////////////////////////////////////////////////////////////////////////////// | 455 //////////////////////////////////////////////////////////////////////////////// |
448 // OmniboxViewViews, AutocopmleteEditView implementation: | 456 // OmniboxViewViews, OmniboxView implementation: |
449 | 457 |
450 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { | 458 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { |
451 DCHECK(tab); | 459 DCHECK(tab); |
452 | 460 |
453 // We don't want to keep the IME status, so force quit the current | 461 // 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 | 462 // session here. It may affect the selection status, so order is |
455 // also important. | 463 // also important. |
456 if (textfield_->IsIMEComposing()) { | 464 if (textfield_->IsIMEComposing()) { |
457 textfield_->GetTextInputClient()->ConfirmCompositionText(); | 465 textfield_->GetTextInputClient()->ConfirmCompositionText(); |
458 textfield_->GetInputMethod()->CancelComposition(textfield_); | 466 textfield_->GetInputMethod()->CancelComposition(textfield_); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); | 579 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); |
572 | 580 |
573 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); | 581 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); |
574 } | 582 } |
575 | 583 |
576 void OmniboxViewViews::SetFocus() { | 584 void OmniboxViewViews::SetFocus() { |
577 // In views-implementation, the focus is on textfield rather than OmniboxView. | 585 // In views-implementation, the focus is on textfield rather than OmniboxView. |
578 textfield_->RequestFocus(); | 586 textfield_->RequestFocus(); |
579 } | 587 } |
580 | 588 |
589 void OmniboxViewViews::ApplyCaretVisibility() { | |
590 if (textfield_->cursor_color() != textfield_->background_color()) | |
591 visible_caret_color_ = textfield_->cursor_color(); | |
592 // Setting the color of the text cursor (caret) to the background color | |
593 // effectively hides it. | |
594 textfield_->SetCursorColor(model()->is_caret_visible() ? | |
595 visible_caret_color_ : textfield_->background_color()); | |
596 } | |
597 | |
581 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 598 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
582 const string16& display_text, | 599 const string16& display_text, |
583 bool save_original_selection) { | 600 bool save_original_selection) { |
584 if (save_original_selection) | 601 if (save_original_selection) |
585 textfield_->GetSelectedRange(&saved_temporary_selection_); | 602 textfield_->GetSelectedRange(&saved_temporary_selection_); |
586 | 603 |
587 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 604 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
588 } | 605 } |
589 | 606 |
590 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 607 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 | 641 |
625 // When the user has deleted text, we don't allow inline autocomplete. Make | 642 // When the user has deleted text, we don't allow inline autocomplete. Make |
626 // sure to not flag cases like selecting part of the text and then pasting | 643 // sure to not flag cases like selecting part of the text and then pasting |
627 // (or typing) the prefix of that selection. (We detect these by making | 644 // (or typing) the prefix of that selection. (We detect these by making |
628 // sure the caret, which should be after any insertion, hasn't moved | 645 // sure the caret, which should be after any insertion, hasn't moved |
629 // forward of the old selection start.) | 646 // forward of the old selection start.) |
630 const bool just_deleted_text = | 647 const bool just_deleted_text = |
631 (text_before_change_.length() > new_text.length()) && | 648 (text_before_change_.length() > new_text.length()) && |
632 (new_sel.start() <= sel_before_change_.GetMin()); | 649 (new_sel.start() <= sel_before_change_.GetMin()); |
633 | 650 |
651 // Restore caret visibility whenever the user enters text or changes selection | |
652 // in the omnibox. | |
Peter Kasting
2012/12/04 22:55:49
I was hoping to put this in the model's OnAfterPos
samarth
2012/12/04 23:13:32
Done.
| |
653 if (text_changed || selection_differs) | |
654 model()->SetCaretVisibility(true); | |
655 | |
634 const bool something_changed = model()->OnAfterPossibleChange( | 656 const bool something_changed = model()->OnAfterPossibleChange( |
635 text_before_change_, new_text, new_sel.start(), new_sel.end(), | 657 text_before_change_, new_text, new_sel.start(), new_sel.end(), |
636 selection_differs, text_changed, just_deleted_text, | 658 selection_differs, text_changed, just_deleted_text, |
637 !textfield_->IsIMEComposing()); | 659 !textfield_->IsIMEComposing()); |
638 | 660 |
639 // If only selection was changed, we don't need to call model()'s | 661 // If only selection was changed, we don't need to call model()'s |
640 // OnChanged() method, which is called in TextChanged(). | 662 // OnChanged() method, which is called in TextChanged(). |
641 // But we still need to call EmphasizeURLComponents() to make sure the text | 663 // But we still need to call EmphasizeURLComponents() to make sure the text |
642 // attributes are updated correctly. | 664 // attributes are updated correctly. |
643 if (something_changed && text_changed) | 665 if (something_changed && text_changed) |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 if (!text.empty()) { | 956 if (!text.empty()) { |
935 // Record this paste, so we can do different behavior. | 957 // Record this paste, so we can do different behavior. |
936 model()->on_paste(); | 958 model()->on_paste(); |
937 // Force a Paste operation to trigger the text_changed code in | 959 // Force a Paste operation to trigger the text_changed code in |
938 // OnAfterPossibleChange(), even if identical contents are pasted into the | 960 // OnAfterPossibleChange(), even if identical contents are pasted into the |
939 // text box. | 961 // text box. |
940 text_before_change_.clear(); | 962 text_before_change_.clear(); |
941 textfield_->ReplaceSelection(text); | 963 textfield_->ReplaceSelection(text); |
942 } | 964 } |
943 } | 965 } |
OLD | NEW |