OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autocomplete/autocomplete_edit_view_win.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 | 917 |
918 CommandUpdater* AutocompleteEditViewWin::GetCommandUpdater() { | 918 CommandUpdater* AutocompleteEditViewWin::GetCommandUpdater() { |
919 return command_updater_; | 919 return command_updater_; |
920 } | 920 } |
921 | 921 |
922 void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) { | 922 void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) { |
923 // On Windows, we shows the suggestion in LocationBarView. | 923 // On Windows, we shows the suggestion in LocationBarView. |
924 NOTREACHED(); | 924 NOTREACHED(); |
925 } | 925 } |
926 | 926 |
927 string16 AutocompleteEditViewWin::GetInstantSuggestion() const { | |
928 // On Windows, we shows the suggestion in LocationBarView. | |
929 NOTREACHED(); | |
930 return string16(); | |
931 } | |
932 | |
927 int AutocompleteEditViewWin::TextWidth() const { | 933 int AutocompleteEditViewWin::TextWidth() const { |
928 return WidthNeededToDisplay(GetText()); | 934 return WidthNeededToDisplay(GetText()); |
929 } | 935 } |
930 | 936 |
931 bool AutocompleteEditViewWin::IsImeComposing() const { | 937 bool AutocompleteEditViewWin::IsImeComposing() const { |
932 bool ime_composing = false; | 938 bool ime_composing = false; |
933 HIMC context = ImmGetContext(m_hWnd); | 939 HIMC context = ImmGetContext(m_hWnd); |
934 if (context) { | 940 if (context) { |
935 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); | 941 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); |
936 ImmReleaseContext(m_hWnd, context); | 942 ImmReleaseContext(m_hWnd, context); |
937 } | 943 } |
938 return ime_composing; | 944 return ime_composing; |
939 } | 945 } |
940 | 946 |
941 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) { | 947 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) { |
942 views::NativeViewHost* host = new views::NativeViewHost; | 948 views::NativeViewHost* host = new views::NativeViewHost; |
943 parent->AddChildView(host); | 949 parent->AddChildView(host); |
944 host->set_focus_view(parent); | 950 host->set_focus_view(parent); |
945 host->Attach(GetNativeView()); | 951 host->Attach(GetNativeView()); |
946 return host; | 952 return host; |
947 } | 953 } |
948 | 954 |
949 bool AutocompleteEditViewWin::CommitInstantSuggestion( | |
950 const string16& typed_text, | |
951 const string16& suggested_text) { | |
952 model_->FinalizeInstantQuery(typed_text, suggested_text); | |
953 return true; | |
954 } | |
955 | |
956 void AutocompleteEditViewWin::PasteAndGo(const string16& text) { | 955 void AutocompleteEditViewWin::PasteAndGo(const string16& text) { |
957 if (CanPasteAndGo(text)) | 956 if (CanPasteAndGo(text)) |
958 model_->PasteAndGo(); | 957 model_->PasteAndGo(); |
959 } | 958 } |
960 | 959 |
961 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( | 960 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( |
962 const views::KeyEvent& e) { | 961 const views::KeyEvent& e) { |
963 ui::KeyboardCode key = e.GetKeyCode(); | 962 ui::KeyboardCode key = e.GetKeyCode(); |
964 // We don't process ALT + numpad digit as accelerators, they are used for | 963 // We don't process ALT + numpad digit as accelerators, they are used for |
965 // entering special characters. We do translate alt-home. | 964 // entering special characters. We do translate alt-home. |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1841 switch (key) { | 1840 switch (key) { |
1842 case VK_RIGHT: | 1841 case VK_RIGHT: |
1843 // TODO(sky): figure out RTL. | 1842 // TODO(sky): figure out RTL. |
1844 if (base::i18n::IsRTL()) | 1843 if (base::i18n::IsRTL()) |
1845 return false; | 1844 return false; |
1846 { | 1845 { |
1847 CHARRANGE selection; | 1846 CHARRANGE selection; |
1848 GetSel(selection); | 1847 GetSel(selection); |
1849 return (selection.cpMin == selection.cpMax) && | 1848 return (selection.cpMin == selection.cpMax) && |
1850 (selection.cpMin == GetTextLength()) && | 1849 (selection.cpMin == GetTextLength()) && |
1851 controller_->OnCommitSuggestedText(GetText()); | 1850 controller_->OnCommitSuggestedText(true); |
1852 } | 1851 } |
1853 | 1852 |
1854 case VK_RETURN: | 1853 case VK_RETURN: |
1855 model_->AcceptInput((flags & KF_ALTDOWN) ? | 1854 model_->AcceptInput((flags & KF_ALTDOWN) ? |
1856 NEW_FOREGROUND_TAB : CURRENT_TAB, false); | 1855 NEW_FOREGROUND_TAB : CURRENT_TAB, false); |
1857 return true; | 1856 return true; |
1858 | 1857 |
1859 case VK_PRIOR: | 1858 case VK_PRIOR: |
1860 case VK_NEXT: | 1859 case VK_NEXT: |
1861 count = model_->result().size(); | 1860 count = model_->result().size(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1970 ScopedFreeze freeze(this, GetTextObjectModel()); | 1969 ScopedFreeze freeze(this, GetTextObjectModel()); |
1971 model_->ClearKeyword(GetText()); | 1970 model_->ClearKeyword(GetText()); |
1972 return true; | 1971 return true; |
1973 } | 1972 } |
1974 | 1973 |
1975 case VK_TAB: { | 1974 case VK_TAB: { |
1976 if (model_->is_keyword_hint()) { | 1975 if (model_->is_keyword_hint()) { |
1977 // Accept the keyword. | 1976 // Accept the keyword. |
1978 ScopedFreeze freeze(this, GetTextObjectModel()); | 1977 ScopedFreeze freeze(this, GetTextObjectModel()); |
1979 model_->AcceptKeyword(); | 1978 model_->AcceptKeyword(); |
1979 } else if (!IsCaretAtEnd()) { | |
1980 ScopedFreeze freeze(this, GetTextObjectModel()); | |
sky
2011/01/27 19:55:31
Again, do you need onbefore/after here?
| |
1981 OnBeforePossibleChange(); | |
1982 PlaceCaretAt(GetTextLength()); | |
1983 OnAfterPossibleChange(); | |
1980 } else { | 1984 } else { |
1981 controller_->OnCommitSuggestedText(GetText()); | 1985 controller_->OnCommitSuggestedText(true); |
1982 } | 1986 } |
1983 return true; | 1987 return true; |
1984 } | 1988 } |
1985 | 1989 |
1986 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). | 1990 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). |
1987 // We don't use VK_OEM_PLUS in case the macro isn't defined. | 1991 // We don't use VK_OEM_PLUS in case the macro isn't defined. |
1988 // (e.g., we don't have this symbol in embeded environment). | 1992 // (e.g., we don't have this symbol in embeded environment). |
1989 return true; | 1993 return true; |
1990 | 1994 |
1991 default: | 1995 default: |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2561 } | 2565 } |
2562 | 2566 |
2563 int AutocompleteEditViewWin::WidthNeededToDisplay( | 2567 int AutocompleteEditViewWin::WidthNeededToDisplay( |
2564 const string16& text) const { | 2568 const string16& text) const { |
2565 // Use font_.GetStringWidth() instead of | 2569 // Use font_.GetStringWidth() instead of |
2566 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2570 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2567 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2571 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2568 // PosFromChar(i) might return 0 when i is greater than 1. | 2572 // PosFromChar(i) might return 0 when i is greater than 1. |
2569 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2573 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2570 } | 2574 } |
2575 | |
2576 bool AutocompleteEditViewWin::IsCaretAtEnd() const { | |
2577 long length = GetTextLength(); | |
sky
2011/01/27 19:55:31
For consistency it would be nice if you had this o
James Su
2011/01/27 20:07:16
This is a method of CRichEditCtrl, we probably nee
sky
2011/01/27 21:47:20
I wasn't suggesting to make it part of the interfa
James Su
2011/01/27 22:04:59
Oh I see. How about add IsCaretAtEnd and PlaceCare
| |
2578 CHARRANGE sel; | |
2579 GetSelection(sel); | |
2580 return sel.cpMin == sel.cpMax && sel.cpMin == length; | |
2581 } | |
OLD | NEW |