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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // the text, or in the middle of composition. | 562 // the text, or in the middle of composition. |
563 ui::Range sel; | 563 ui::Range sel; |
564 textfield_->GetSelectedRange(&sel); | 564 textfield_->GetSelectedRange(&sel); |
565 bool no_inline_autocomplete = | 565 bool no_inline_autocomplete = |
566 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); | 566 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); |
567 | 567 |
568 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); | 568 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); |
569 } | 569 } |
570 | 570 |
571 void OmniboxViewViews::SetFocus() { | 571 void OmniboxViewViews::SetFocus() { |
| 572 SetFocusVisibility(true); |
572 // In views-implementation, the focus is on textfield rather than OmniboxView. | 573 // In views-implementation, the focus is on textfield rather than OmniboxView. |
573 textfield_->RequestFocus(); | 574 textfield_->RequestFocus(); |
574 } | 575 } |
| 576 |
| 577 void OmniboxViewViews::SetInvisibleFocus() { |
| 578 SetFocusVisibility(false); |
| 579 // In views-implementation, the focus is on textfield rather than OmniboxView. |
| 580 textfield_->RequestFocus(); |
| 581 } |
575 | 582 |
576 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 583 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
577 const string16& display_text, | 584 const string16& display_text, |
578 bool save_original_selection) { | 585 bool save_original_selection) { |
579 if (save_original_selection) | 586 if (save_original_selection) |
580 textfield_->GetSelectedRange(&saved_temporary_selection_); | 587 textfield_->GetSelectedRange(&saved_temporary_selection_); |
581 | 588 |
582 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 589 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); |
583 } | 590 } |
584 | 591 |
585 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( | 592 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( |
586 const string16& display_text, | 593 const string16& display_text, |
587 size_t user_text_length) { | 594 size_t user_text_length) { |
588 if (display_text == GetText()) | 595 if (display_text == GetText()) |
589 return false; | 596 return false; |
590 ui::Range range(display_text.size(), user_text_length); | 597 ui::Range range(display_text.size(), user_text_length); |
591 SetTextAndSelectedRange(display_text, range); | 598 SetTextAndSelectedRange(display_text, range); |
592 TextChanged(); | 599 TextChanged(); |
593 return true; | 600 return true; |
594 } | 601 } |
595 | 602 |
596 void OmniboxViewViews::OnRevertTemporaryText() { | 603 void OmniboxViewViews::OnRevertTemporaryText() { |
597 textfield_->SelectRange(saved_temporary_selection_); | 604 textfield_->SelectRange(saved_temporary_selection_); |
598 TextChanged(); | 605 TextChanged(); |
599 } | 606 } |
600 | 607 |
601 void OmniboxViewViews::OnBeforePossibleChange() { | 608 void OmniboxViewViews::OnBeforePossibleChange() { |
| 609 SetFocusVisibility(true); |
602 // Record our state. | 610 // Record our state. |
603 text_before_change_ = GetText(); | 611 text_before_change_ = GetText(); |
604 textfield_->GetSelectedRange(&sel_before_change_); | 612 textfield_->GetSelectedRange(&sel_before_change_); |
605 ime_composing_before_change_ = textfield_->IsIMEComposing(); | 613 ime_composing_before_change_ = textfield_->IsIMEComposing(); |
606 } | 614 } |
607 | 615 |
608 bool OmniboxViewViews::OnAfterPossibleChange() { | 616 bool OmniboxViewViews::OnAfterPossibleChange() { |
609 ui::Range new_sel; | 617 ui::Range new_sel; |
610 textfield_->GetSelectedRange(&new_sel); | 618 textfield_->GetSelectedRange(&new_sel); |
611 | 619 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 if (!text.empty()) { | 937 if (!text.empty()) { |
930 // Record this paste, so we can do different behavior. | 938 // Record this paste, so we can do different behavior. |
931 model()->on_paste(); | 939 model()->on_paste(); |
932 // Force a Paste operation to trigger the text_changed code in | 940 // Force a Paste operation to trigger the text_changed code in |
933 // OnAfterPossibleChange(), even if identical contents are pasted into the | 941 // OnAfterPossibleChange(), even if identical contents are pasted into the |
934 // text box. | 942 // text box. |
935 text_before_change_.clear(); | 943 text_before_change_.clear(); |
936 textfield_->ReplaceSelection(text); | 944 textfield_->ReplaceSelection(text); |
937 } | 945 } |
938 } | 946 } |
| 947 |
| 948 void OmniboxViewViews::SetFocusVisibility(bool focus_is_visible) { |
| 949 model()->OnFocusVisibilityChange(focus_is_visible); |
| 950 // TODO(mathp): actually make focus invisible |
| 951 } |
OLD | NEW |