| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <locale> | 8 #include <locale> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 void OmniboxViewWin::InsertText(int position, const string16& text) { | 853 void OmniboxViewWin::InsertText(int position, const string16& text) { |
| 854 DCHECK((position >= 0) && (position <= GetTextLength())); | 854 DCHECK((position >= 0) && (position <= GetTextLength())); |
| 855 ScopedFreeze freeze(this, GetTextObjectModel()); | 855 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 856 OnBeforePossibleChange(); | 856 OnBeforePossibleChange(); |
| 857 SetSelection(position, position); | 857 SetSelection(position, position); |
| 858 ReplaceSel(text.c_str()); | 858 ReplaceSel(text.c_str()); |
| 859 OnAfterPossibleChange(); | 859 OnAfterPossibleChange(); |
| 860 } | 860 } |
| 861 | 861 |
| 862 void OmniboxViewWin::OnTemporaryTextMaybeChanged(const string16& display_text, | 862 void OmniboxViewWin::OnTemporaryTextMaybeChanged(const string16& display_text, |
| 863 bool save_original_selection) { | 863 bool save_original_selection, |
| 864 bool notify_text_changed) { |
| 864 if (save_original_selection) | 865 if (save_original_selection) |
| 865 GetSelection(original_selection_); | 866 GetSelection(original_selection_); |
| 866 | 867 |
| 867 // Set new text and cursor position. Sometimes this does extra work (e.g. | 868 // Set new text and cursor position. Sometimes this does extra work (e.g. |
| 868 // when the new text and the old text are identical), but it's only called | 869 // when the new text and the old text are identical), but it's only called |
| 869 // when the user manually changes the selected line in the popup, so that's | 870 // when the user manually changes the selected line in the popup, so that's |
| 870 // not really a problem. Also, even when the text hasn't changed we'd want to | 871 // not really a problem. Also, even when the text hasn't changed we'd want to |
| 871 // update the caret, because if the user had the cursor in the middle of the | 872 // update the caret, because if the user had the cursor in the middle of the |
| 872 // text and then arrowed to another entry with the same text, we'd still want | 873 // text and then arrowed to another entry with the same text, we'd still want |
| 873 // to move the caret. | 874 // to move the caret. |
| 874 ScopedFreeze freeze(this, GetTextObjectModel()); | 875 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 875 SetWindowTextAndCaretPos(display_text, display_text.length(), false, true); | 876 SetWindowTextAndCaretPos(display_text, display_text.length(), false, |
| 877 notify_text_changed); |
| 876 } | 878 } |
| 877 | 879 |
| 878 bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( | 880 bool OmniboxViewWin::OnInlineAutocompleteTextMaybeChanged( |
| 879 const string16& display_text, | 881 const string16& display_text, |
| 880 size_t user_text_length) { | 882 size_t user_text_length) { |
| 881 // Update the text and selection. Because this can be called repeatedly while | 883 // Update the text and selection. Because this can be called repeatedly while |
| 882 // typing, we've careful not to freeze the edit unless we really need to. | 884 // typing, we've careful not to freeze the edit unless we really need to. |
| 883 // Also, unlike in the temporary text case above, here we don't want to update | 885 // Also, unlike in the temporary text case above, here we don't want to update |
| 884 // the caret/selection unless we have to, since this might make the user's | 886 // the caret/selection unless we have to, since this might make the user's |
| 885 // caret position change without warning during typing. | 887 // caret position change without warning during typing. |
| 886 if (display_text == GetText()) | 888 if (display_text == GetText()) |
| 887 return false; | 889 return false; |
| 888 | 890 |
| 889 ScopedFreeze freeze(this, GetTextObjectModel()); | 891 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 890 SetWindowText(display_text.c_str()); | 892 SetWindowText(display_text.c_str()); |
| 891 // Set a reversed selection to keep the caret in the same position, which | 893 // Set a reversed selection to keep the caret in the same position, which |
| 892 // avoids scrolling the user's text. | 894 // avoids scrolling the user's text. |
| 893 SetSelection(static_cast<LONG>(display_text.length()), | 895 SetSelection(static_cast<LONG>(display_text.length()), |
| 894 static_cast<LONG>(user_text_length)); | 896 static_cast<LONG>(user_text_length)); |
| 895 TextChanged(); | 897 TextChanged(); |
| 896 return true; | 898 return true; |
| 897 } | 899 } |
| 898 | 900 |
| 899 void OmniboxViewWin::OnRevertTemporaryText() { | 901 void OmniboxViewWin::OnRevertTemporaryText() { |
| 900 SetSelectionRange(original_selection_); | 902 SetSelectionRange(original_selection_); |
| 901 TextChanged(); | |
| 902 } | 903 } |
| 903 | 904 |
| 904 void OmniboxViewWin::OnBeforePossibleChange() { | 905 void OmniboxViewWin::OnBeforePossibleChange() { |
| 905 // Record our state. | 906 // Record our state. |
| 906 text_before_change_ = GetText(); | 907 text_before_change_ = GetText(); |
| 907 GetSelection(sel_before_change_); | 908 GetSelection(sel_before_change_); |
| 908 } | 909 } |
| 909 | 910 |
| 910 bool OmniboxViewWin::OnAfterPossibleChange() { | 911 bool OmniboxViewWin::OnAfterPossibleChange() { |
| 911 return OnAfterPossibleChangeInternal(false); | 912 return OnAfterPossibleChangeInternal(false); |
| (...skipping 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2829 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2830 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2830 } | 2831 } |
| 2831 | 2832 |
| 2832 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2833 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2833 // Use font_.GetStringWidth() instead of | 2834 // Use font_.GetStringWidth() instead of |
| 2834 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2835 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
| 2835 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2836 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
| 2836 // PosFromChar(i) might return 0 when i is greater than 1. | 2837 // PosFromChar(i) might return 0 when i is greater than 1. |
| 2837 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2838 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2838 } | 2839 } |
| OLD | NEW |