Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 6252003: Accept keyword by pressing space. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only allow 0x0020 and 0x3000 for now. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 CHARRANGE new_sel; 854 CHARRANGE new_sel;
855 GetSelection(new_sel); 855 GetSelection(new_sel);
856 const int length = GetTextLength(); 856 const int length = GetTextLength();
857 if ((new_sel.cpMin > length) || (new_sel.cpMax > length)) { 857 if ((new_sel.cpMin > length) || (new_sel.cpMax > length)) {
858 if (new_sel.cpMin > length) 858 if (new_sel.cpMin > length)
859 new_sel.cpMin = length; 859 new_sel.cpMin = length;
860 if (new_sel.cpMax > length) 860 if (new_sel.cpMax > length)
861 new_sel.cpMax = length; 861 new_sel.cpMax = length;
862 SetSelectionRange(new_sel); 862 SetSelectionRange(new_sel);
863 } 863 }
864 const bool selection_differs = (new_sel.cpMin != sel_before_change_.cpMin) || 864 const bool selection_differs =
865 (new_sel.cpMax != sel_before_change_.cpMax); 865 ((new_sel.cpMin != new_sel.cpMax) ||
866 (sel_before_change_.cpMin != sel_before_change_.cpMax)) &&
867 ((new_sel.cpMin != sel_before_change_.cpMin) ||
868 (new_sel.cpMax != sel_before_change_.cpMax));
866 const bool at_end_of_edit = 869 const bool at_end_of_edit =
867 (new_sel.cpMin == length) && (new_sel.cpMax == length); 870 (new_sel.cpMin == length) && (new_sel.cpMax == length);
868 871
869 // See if the text or selection have changed since OnBeforePossibleChange(). 872 // See if the text or selection have changed since OnBeforePossibleChange().
870 const std::wstring new_text(GetText()); 873 const std::wstring new_text(GetText());
871 const bool text_differs = (new_text != text_before_change_) || 874 const bool text_differs = (new_text != text_before_change_) ||
872 force_text_changed; 875 force_text_changed;
873 876
874 // When the user has deleted text, we don't allow inline autocomplete. Make 877 // When the user has deleted text, we don't allow inline autocomplete. Make
875 // sure to not flag cases like selecting part of the text and then pasting 878 // sure to not flag cases like selecting part of the text and then pasting
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc, 1686 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc,
1684 rect.left, rect.top, SRCCOPY); 1687 rect.left, rect.top, SRCCOPY);
1685 memory_dc.SelectBitmap(old_bitmap); 1688 memory_dc.SelectBitmap(old_bitmap);
1686 edit_hwnd = old_edit_hwnd; 1689 edit_hwnd = old_edit_hwnd;
1687 } 1690 }
1688 1691
1689 void AutocompleteEditViewWin::OnPaste() { 1692 void AutocompleteEditViewWin::OnPaste() {
1690 // Replace the selection if we have something to paste. 1693 // Replace the selection if we have something to paste.
1691 const std::wstring text(GetClipboardText()); 1694 const std::wstring text(GetClipboardText());
1692 if (!text.empty()) { 1695 if (!text.empty()) {
1693 // If this paste will be replacing all the text, record that, so we can do 1696 // Record this paste, so we can do different behavior.
1694 // different behaviors in such a case. 1697 model_->on_paste();
1695 if (IsSelectAll())
1696 model_->on_paste_replacing_all();
1697 // Force a Paste operation to trigger the text_changed code in 1698 // Force a Paste operation to trigger the text_changed code in
1698 // OnAfterPossibleChange(), even if identical contents are pasted into the 1699 // OnAfterPossibleChange(), even if identical contents are pasted into the
1699 // text box. 1700 // text box.
1700 text_before_change_.clear(); 1701 text_before_change_.clear();
1701 ReplaceSel(text.c_str(), true); 1702 ReplaceSel(text.c_str(), true);
1702 } 1703 }
1703 } 1704 }
1704 1705
1705 void AutocompleteEditViewWin::OnRButtonDblClk(UINT /*keys*/, 1706 void AutocompleteEditViewWin::OnRButtonDblClk(UINT /*keys*/,
1706 const CPoint& /*point*/) { 1707 const CPoint& /*point*/) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 } 1966 }
1966 1967
1967 // We're showing a keyword and the user pressed backspace at the beginning 1968 // We're showing a keyword and the user pressed backspace at the beginning
1968 // of the text. Delete the selected keyword. 1969 // of the text. Delete the selected keyword.
1969 ScopedFreeze freeze(this, GetTextObjectModel()); 1970 ScopedFreeze freeze(this, GetTextObjectModel());
1970 model_->ClearKeyword(GetText()); 1971 model_->ClearKeyword(GetText());
1971 return true; 1972 return true;
1972 } 1973 }
1973 1974
1974 case VK_TAB: { 1975 case VK_TAB: {
1975 if (model_->is_keyword_hint() && !model_->keyword().empty()) { 1976 if (model_->is_keyword_hint()) {
1976 // Accept the keyword. 1977 // Accept the keyword.
1977 ScopedFreeze freeze(this, GetTextObjectModel()); 1978 ScopedFreeze freeze(this, GetTextObjectModel());
1978 model_->AcceptKeyword(); 1979 model_->AcceptKeyword();
1979 } else { 1980 } else {
1980 controller_->OnCommitSuggestedText(GetText()); 1981 controller_->OnCommitSuggestedText(GetText());
1981 } 1982 }
1982 return true; 1983 return true;
1983 } 1984 }
1984 1985
1985 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). 1986 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode).
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 } 2561 }
2561 2562
2562 int AutocompleteEditViewWin::WidthNeededToDisplay( 2563 int AutocompleteEditViewWin::WidthNeededToDisplay(
2563 const std::wstring& text) const { 2564 const std::wstring& text) const {
2564 // Use font_.GetStringWidth() instead of 2565 // Use font_.GetStringWidth() instead of
2565 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2566 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2566 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2567 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
2567 // PosFromChar(i) might return 0 when i is greater than 1. 2568 // PosFromChar(i) might return 0 when i is greater than 1.
2568 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2569 return font_.GetStringWidth(text) + GetHorizontalMargin();
2569 } 2570 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_mac.mm ('k') | chrome/browser/ui/gtk/location_bar_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698