Chromium Code Reviews| 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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) || |
|
Peter Kasting
2011/01/20 00:04:22
Nit: I suggest using a similar addition to this in
James Su
2011/01/20 06:49:31
Done.
| |
| 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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // If this paste will be replacing all the text, record that, so we can do |
| 1694 // different behaviors in such a case. | 1697 // different behaviors in such a case. |
| 1695 if (IsSelectAll()) | 1698 model_->OnPaste(IsSelectAll()); |
| 1696 model_->on_paste_replacing_all(); | |
| 1697 // Force a Paste operation to trigger the text_changed code in | 1699 // Force a Paste operation to trigger the text_changed code in |
| 1698 // OnAfterPossibleChange(), even if identical contents are pasted into the | 1700 // OnAfterPossibleChange(), even if identical contents are pasted into the |
| 1699 // text box. | 1701 // text box. |
| 1700 text_before_change_.clear(); | 1702 text_before_change_.clear(); |
| 1701 ReplaceSel(text.c_str(), true); | 1703 ReplaceSel(text.c_str(), true); |
| 1702 } | 1704 } |
| 1703 } | 1705 } |
| 1704 | 1706 |
| 1705 void AutocompleteEditViewWin::OnRButtonDblClk(UINT /*keys*/, | 1707 void AutocompleteEditViewWin::OnRButtonDblClk(UINT /*keys*/, |
| 1706 const CPoint& /*point*/) { | 1708 const CPoint& /*point*/) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1965 } | 1967 } |
| 1966 | 1968 |
| 1967 // We're showing a keyword and the user pressed backspace at the beginning | 1969 // We're showing a keyword and the user pressed backspace at the beginning |
| 1968 // of the text. Delete the selected keyword. | 1970 // of the text. Delete the selected keyword. |
| 1969 ScopedFreeze freeze(this, GetTextObjectModel()); | 1971 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1970 model_->ClearKeyword(GetText()); | 1972 model_->ClearKeyword(GetText()); |
| 1971 return true; | 1973 return true; |
| 1972 } | 1974 } |
| 1973 | 1975 |
| 1974 case VK_TAB: { | 1976 case VK_TAB: { |
| 1975 if (model_->is_keyword_hint() && !model_->keyword().empty()) { | 1977 if (model_->is_keyword_hint()) { |
| 1976 // Accept the keyword. | 1978 // Accept the keyword. |
| 1977 ScopedFreeze freeze(this, GetTextObjectModel()); | 1979 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1978 model_->AcceptKeyword(); | 1980 model_->AcceptKeyword(); |
| 1979 } else { | 1981 } else { |
| 1980 controller_->OnCommitSuggestedText(GetText()); | 1982 controller_->OnCommitSuggestedText(GetText()); |
| 1981 } | 1983 } |
| 1982 return true; | 1984 return true; |
| 1983 } | 1985 } |
| 1984 | 1986 |
| 1985 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). | 1987 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2560 } | 2562 } |
| 2561 | 2563 |
| 2562 int AutocompleteEditViewWin::WidthNeededToDisplay( | 2564 int AutocompleteEditViewWin::WidthNeededToDisplay( |
| 2563 const std::wstring& text) const { | 2565 const std::wstring& text) const { |
| 2564 // Use font_.GetStringWidth() instead of | 2566 // Use font_.GetStringWidth() instead of |
| 2565 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2567 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
| 2566 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2568 // 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. | 2569 // PosFromChar(i) might return 0 when i is greater than 1. |
| 2568 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2570 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2569 } | 2571 } |
| OLD | NEW |