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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 std::string OmniboxViewViews::GetClassName() const { | 437 std::string OmniboxViewViews::GetClassName() const { |
| 438 return kViewClassName; | 438 return kViewClassName; |
| 439 } | 439 } |
| 440 | 440 |
| 441 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 441 void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 442 if (popup_view_->IsOpen()) | 442 if (popup_view_->IsOpen()) |
| 443 popup_view_->UpdatePopupAppearance(); | 443 popup_view_->UpdatePopupAppearance(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 //////////////////////////////////////////////////////////////////////////////// | 446 //////////////////////////////////////////////////////////////////////////////// |
| 447 // OmniboxViewViews, AutocopmleteEditView implementation: | 447 // OmniboxViewViews, AutocompleteEditView implementation: |
| 448 | 448 |
| 449 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { | 449 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { |
| 450 DCHECK(tab); | 450 DCHECK(tab); |
| 451 | 451 |
| 452 // We don't want to keep the IME status, so force quit the current | 452 // We don't want to keep the IME status, so force quit the current |
| 453 // session here. It may affect the selection status, so order is | 453 // session here. It may affect the selection status, so order is |
| 454 // also important. | 454 // also important. |
| 455 if (textfield_->IsIMEComposing()) { | 455 if (textfield_->IsIMEComposing()) { |
| 456 textfield_->GetTextInputClient()->ConfirmCompositionText(); | 456 textfield_->GetTextInputClient()->ConfirmCompositionText(); |
| 457 textfield_->GetInputMethod()->CancelComposition(textfield_); | 457 textfield_->GetInputMethod()->CancelComposition(textfield_); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 477 | 477 |
| 478 // TODO(oshima): Copied from gtk implementation which is | 478 // TODO(oshima): Copied from gtk implementation which is |
| 479 // slightly different from WIN impl. Find out the correct implementation | 479 // slightly different from WIN impl. Find out the correct implementation |
| 480 // for views-implementation. | 480 // for views-implementation. |
| 481 if (contents) { | 481 if (contents) { |
| 482 RevertAll(); | 482 RevertAll(); |
| 483 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>( | 483 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>( |
| 484 contents->GetUserData(&kAutocompleteEditStateKey)); | 484 contents->GetUserData(&kAutocompleteEditStateKey)); |
| 485 if (state) { | 485 if (state) { |
| 486 model()->RestoreState(state->model_state); | 486 model()->RestoreState(state->model_state); |
| 487 ApplyFocusVisibility(); | |
| 487 | 488 |
| 488 // Move the marks for the cursor and the other end of the selection to | 489 // Move the marks for the cursor and the other end of the selection to |
| 489 // the previously-saved offsets (but preserve PRIMARY). | 490 // the previously-saved offsets (but preserve PRIMARY). |
| 490 textfield_->SelectSelectionModel(state->view_state.selection_model); | 491 textfield_->SelectSelectionModel(state->view_state.selection_model); |
| 491 // We do not carry over the current edit history to another tab. | 492 // We do not carry over the current edit history to another tab. |
| 492 // TODO(oshima): consider saving/restoring edit history. | 493 // TODO(oshima): consider saving/restoring edit history. |
| 493 textfield_->ClearEditHistory(); | 494 textfield_->ClearEditHistory(); |
| 494 } | 495 } |
| 495 } else if (visibly_changed_permanent_text) { | 496 } else if (visibly_changed_permanent_text) { |
| 496 RevertAll(); | 497 RevertAll(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 // the text, or in the middle of composition. | 567 // the text, or in the middle of composition. |
| 567 ui::Range sel; | 568 ui::Range sel; |
| 568 textfield_->GetSelectedRange(&sel); | 569 textfield_->GetSelectedRange(&sel); |
| 569 bool no_inline_autocomplete = | 570 bool no_inline_autocomplete = |
| 570 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); | 571 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); |
| 571 | 572 |
| 572 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); | 573 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); |
| 573 } | 574 } |
| 574 | 575 |
| 575 void OmniboxViewViews::SetFocus() { | 576 void OmniboxViewViews::SetFocus() { |
| 577 model()->set_is_focus_visible(true); | |
| 578 ApplyFocusVisibility(); | |
| 576 // In views-implementation, the focus is on textfield rather than OmniboxView. | 579 // In views-implementation, the focus is on textfield rather than OmniboxView. |
| 577 textfield_->RequestFocus(); | 580 textfield_->RequestFocus(); |
| 578 } | 581 } |
| 582 | |
| 583 void OmniboxViewViews::SetInvisibleFocus() { | |
| 584 DLOG(0) << "SetInvisibleFocus"; | |
| 585 model()->set_is_focus_visible(false); | |
| 586 ApplyFocusVisibility(); | |
| 587 // In views-implementation, the focus is on textfield rather than OmniboxView. | |
| 588 textfield_->RequestFocus(); | |
| 589 } | |
| 579 | 590 |
| 580 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 591 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
| 581 const string16& display_text, | 592 const string16& display_text, |
| 582 bool save_original_selection) { | 593 bool save_original_selection) { |
| 583 if (save_original_selection) | 594 if (save_original_selection) |
| 584 textfield_->GetSelectedRange(&saved_temporary_selection_); | 595 textfield_->GetSelectedRange(&saved_temporary_selection_); |
| 585 | 596 |
| 586 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 597 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
| 587 } | 598 } |
| 588 | 599 |
| 589 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 600 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
| 590 const string16& display_text, | 601 const string16& display_text, |
| 591 size_t user_text_length) { | 602 size_t user_text_length) { |
| 592 if (display_text == GetText()) | 603 if (display_text == GetText()) |
| 593 return false; | 604 return false; |
| 594 ui::Range range(display_text.size(), user_text_length); | 605 ui::Range range(display_text.size(), user_text_length); |
| 595 SetTextAndSelectedRange(display_text, range); | 606 SetTextAndSelectedRange(display_text, range); |
| 596 TextChanged(); | 607 TextChanged(); |
| 597 return true; | 608 return true; |
| 598 } | 609 } |
| 599 | 610 |
| 600 void OmniboxViewViews::OnRevertTemporaryText() { | 611 void OmniboxViewViews::OnRevertTemporaryText() { |
| 601 textfield_->SelectRange(saved_temporary_selection_); | 612 textfield_->SelectRange(saved_temporary_selection_); |
| 602 TextChanged(); | 613 TextChanged(); |
| 603 } | 614 } |
| 604 | 615 |
| 605 void OmniboxViewViews::OnBeforePossibleChange() { | 616 void OmniboxViewViews::OnBeforePossibleChange() { |
| 617 // Since this is called when the user directly clicks on the omnibox | |
| 618 // regardless of its focus state, we reset the focus to visible. | |
| 619 model()->set_is_focus_visible(true); | |
| 620 ApplyFocusVisibility(); | |
| 606 // Record our state. | 621 // Record our state. |
| 607 text_before_change_ = GetText(); | 622 text_before_change_ = GetText(); |
| 608 textfield_->GetSelectedRange(&sel_before_change_); | 623 textfield_->GetSelectedRange(&sel_before_change_); |
| 609 ime_composing_before_change_ = textfield_->IsIMEComposing(); | 624 ime_composing_before_change_ = textfield_->IsIMEComposing(); |
| 610 } | 625 } |
| 611 | 626 |
| 612 bool OmniboxViewViews::OnAfterPossibleChange() { | 627 bool OmniboxViewViews::OnAfterPossibleChange() { |
| 613 ui::Range new_sel; | 628 ui::Range new_sel; |
| 614 textfield_->GetSelectedRange(&new_sel); | 629 textfield_->GetSelectedRange(&new_sel); |
| 615 | 630 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 if (!text.empty()) { | 948 if (!text.empty()) { |
| 934 // Record this paste, so we can do different behavior. | 949 // Record this paste, so we can do different behavior. |
| 935 model()->on_paste(); | 950 model()->on_paste(); |
| 936 // Force a Paste operation to trigger the text_changed code in | 951 // Force a Paste operation to trigger the text_changed code in |
| 937 // OnAfterPossibleChange(), even if identical contents are pasted into the | 952 // OnAfterPossibleChange(), even if identical contents are pasted into the |
| 938 // text box. | 953 // text box. |
| 939 text_before_change_.clear(); | 954 text_before_change_.clear(); |
| 940 textfield_->ReplaceSelection(text); | 955 textfield_->ReplaceSelection(text); |
| 941 } | 956 } |
| 942 } | 957 } |
| 958 | |
| 959 void OmniboxViewViews::ApplyFocusVisibility() { | |
| 960 textfield_->SetCursorColor(model()->is_focus_visible() ? | |
| 961 SK_ColorBLACK : textfield_->background_color()); | |
|
samarth
2012/11/28 17:43:54
Is BLACK always correct? If not, we may need to s
Mathieu
2012/11/28 21:03:06
Thanks for the comment. I've changed the logic so
| |
| 962 } | |
| 963 | |
| OLD | NEW |