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

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

Issue 6258015: Remove wstring from autocomplete.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 DWORD EditDropTarget::OnDrop(IDataObject* data_object, 178 DWORD EditDropTarget::OnDrop(IDataObject* data_object,
179 DWORD key_state, 179 DWORD key_state,
180 POINT cursor_position, 180 POINT cursor_position,
181 DWORD effect) { 181 DWORD effect) {
182 ui::OSExchangeData os_data(new ui::OSExchangeDataProviderWin(data_object)); 182 ui::OSExchangeData os_data(new ui::OSExchangeDataProviderWin(data_object));
183 183
184 if (drag_has_url_) { 184 if (drag_has_url_) {
185 GURL url; 185 GURL url;
186 std::wstring title; 186 string16 title;
187 if (os_data.GetURLAndTitle(&url, &title)) { 187 if (os_data.GetURLAndTitle(&url, &title)) {
188 edit_->SetUserText(UTF8ToWide(url.spec())); 188 edit_->SetUserText(UTF8ToWide(url.spec()));
189 edit_->model()->AcceptInput(CURRENT_TAB, true); 189 edit_->model()->AcceptInput(CURRENT_TAB, true);
190 return CopyOrLinkDropEffect(effect); 190 return CopyOrLinkDropEffect(effect);
191 } 191 }
192 } else if (drag_has_string_) { 192 } else if (drag_has_string_) {
193 int string_drop_position = edit_->drop_highlight_position(); 193 int string_drop_position = edit_->drop_highlight_position();
194 std::wstring text; 194 string16 text;
195 if ((string_drop_position != -1 || !edit_->in_drag()) && 195 if ((string_drop_position != -1 || !edit_->in_drag()) &&
196 os_data.GetString(&text)) { 196 os_data.GetString(&text)) {
197 DCHECK(string_drop_position == -1 || 197 DCHECK(string_drop_position == -1 ||
198 ((string_drop_position >= 0) && 198 ((string_drop_position >= 0) &&
199 (string_drop_position <= edit_->GetTextLength()))); 199 (string_drop_position <= edit_->GetTextLength())));
200 const DWORD drop_operation = 200 const DWORD drop_operation =
201 OnDragOver(data_object, key_state, cursor_position, effect); 201 OnDragOver(data_object, key_state, cursor_position, effect);
202 if (edit_->in_drag()) { 202 if (edit_->in_drag()) {
203 if (drop_operation == DROPEFFECT_MOVE) 203 if (drop_operation == DROPEFFECT_MOVE)
204 edit_->MoveSelectedText(string_drop_position); 204 edit_->MoveSelectedText(string_drop_position);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // Only the security style changed, nothing else. Redraw our text using it. 590 // Only the security style changed, nothing else. Redraw our text using it.
591 EmphasizeURLComponents(); 591 EmphasizeURLComponents();
592 } 592 }
593 } 593 }
594 594
595 void AutocompleteEditViewWin::OpenURL(const GURL& url, 595 void AutocompleteEditViewWin::OpenURL(const GURL& url,
596 WindowOpenDisposition disposition, 596 WindowOpenDisposition disposition,
597 PageTransition::Type transition, 597 PageTransition::Type transition,
598 const GURL& alternate_nav_url, 598 const GURL& alternate_nav_url,
599 size_t selected_line, 599 size_t selected_line,
600 const std::wstring& keyword) { 600 const string16& keyword) {
601 if (!url.is_valid()) 601 if (!url.is_valid())
602 return; 602 return;
603 603
604 // When we navigate, we first revert to the unedited state, then if necessary 604 // When we navigate, we first revert to the unedited state, then if necessary
605 // synchronously change the permanent text to the new URL. If we don't freeze 605 // synchronously change the permanent text to the new URL. If we don't freeze
606 // here, the user could potentially see a flicker of the current URL before 606 // here, the user could potentially see a flicker of the current URL before
607 // the new one reappears, which would look glitchy. 607 // the new one reappears, which would look glitchy.
608 ScopedFreeze freeze(this, GetTextObjectModel()); 608 ScopedFreeze freeze(this, GetTextObjectModel());
609 model_->OpenURL(url, disposition, transition, alternate_nav_url, 609 model_->OpenURL(url, disposition, transition, alternate_nav_url,
610 selected_line, keyword); 610 selected_line, keyword);
611 } 611 }
612 612
613 std::wstring AutocompleteEditViewWin::GetText() const { 613 string16 AutocompleteEditViewWin::GetText() const {
614 const int len = GetTextLength() + 1; 614 const int len = GetTextLength() + 1;
615 std::wstring str; 615 string16 str;
616 GetWindowText(WriteInto(&str, len), len); 616 GetWindowText(WriteInto(&str, len), len);
617 return str; 617 return str;
618 } 618 }
619 619
620 bool AutocompleteEditViewWin::IsEditingOrEmpty() const { 620 bool AutocompleteEditViewWin::IsEditingOrEmpty() const {
621 return model_->user_input_in_progress() || (GetTextLength() == 0); 621 return model_->user_input_in_progress() || (GetTextLength() == 0);
622 } 622 }
623 623
624 int AutocompleteEditViewWin::GetIcon() const { 624 int AutocompleteEditViewWin::GetIcon() const {
625 return IsEditingOrEmpty() ? 625 return IsEditingOrEmpty() ?
626 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : 626 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
627 toolbar_model_->GetIcon(); 627 toolbar_model_->GetIcon();
628 } 628 }
629 629
630 void AutocompleteEditViewWin::SetUserText(const std::wstring& text) { 630 void AutocompleteEditViewWin::SetUserText(const string16& text) {
631 SetUserText(text, text, true); 631 SetUserText(text, text, true);
632 } 632 }
633 633
634 void AutocompleteEditViewWin::SetUserText(const std::wstring& text, 634 void AutocompleteEditViewWin::SetUserText(const string16& text,
635 const std::wstring& display_text, 635 const string16& display_text,
636 bool update_popup) { 636 bool update_popup) {
637 ScopedFreeze freeze(this, GetTextObjectModel()); 637 ScopedFreeze freeze(this, GetTextObjectModel());
638 model_->SetUserText(text); 638 model_->SetUserText(text);
639 saved_selection_for_focus_change_.cpMin = -1; 639 saved_selection_for_focus_change_.cpMin = -1;
640 SetWindowTextAndCaretPos(display_text, display_text.length()); 640 SetWindowTextAndCaretPos(display_text, display_text.length());
641 if (update_popup) 641 if (update_popup)
642 UpdatePopup(); 642 UpdatePopup();
643 TextChanged(); 643 TextChanged();
644 } 644 }
645 645
646 void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text, 646 void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const string16& text,
647 size_t caret_pos) { 647 size_t caret_pos) {
648 SetWindowText(text.c_str()); 648 SetWindowText(text.c_str());
649 PlaceCaretAt(caret_pos); 649 PlaceCaretAt(caret_pos);
650 } 650 }
651 651
652 void AutocompleteEditViewWin::SetForcedQuery() { 652 void AutocompleteEditViewWin::SetForcedQuery() {
653 const std::wstring current_text(GetText()); 653 const string16 current_text(GetText());
654 const size_t start = current_text.find_first_not_of(kWhitespaceWide); 654 const size_t start = current_text.find_first_not_of(kWhitespaceWide);
655 if (start == std::wstring::npos || (current_text[start] != '?')) 655 if (start == string16::npos || (current_text[start] != '?'))
656 SetUserText(L"?"); 656 SetUserText(L"?");
657 else 657 else
658 SetSelection(current_text.length(), start + 1); 658 SetSelection(current_text.length(), start + 1);
659 } 659 }
660 660
661 bool AutocompleteEditViewWin::IsSelectAll() { 661 bool AutocompleteEditViewWin::IsSelectAll() {
662 CHARRANGE selection; 662 CHARRANGE selection;
663 GetSel(selection); 663 GetSel(selection);
664 return IsSelectAllForRange(selection); 664 return IsSelectAllForRange(selection);
665 } 665 }
666 666
667 bool AutocompleteEditViewWin::DeleteAtEndPressed() { 667 bool AutocompleteEditViewWin::DeleteAtEndPressed() {
668 return delete_at_end_pressed_; 668 return delete_at_end_pressed_;
669 } 669 }
670 670
671 void AutocompleteEditViewWin::GetSelectionBounds(std::wstring::size_type* start, 671 void AutocompleteEditViewWin::GetSelectionBounds(string16::size_type* start,
672 std::wstring::size_type* end) { 672 string16::size_type* end) {
673 CHARRANGE selection; 673 CHARRANGE selection;
674 GetSel(selection); 674 GetSel(selection);
675 *start = static_cast<size_t>(selection.cpMin); 675 *start = static_cast<size_t>(selection.cpMin);
676 *end = static_cast<size_t>(selection.cpMax); 676 *end = static_cast<size_t>(selection.cpMax);
677 } 677 }
678 678
679 void AutocompleteEditViewWin::SelectAll(bool reversed) { 679 void AutocompleteEditViewWin::SelectAll(bool reversed) {
680 if (reversed) 680 if (reversed)
681 SetSelection(GetTextLength(), 0); 681 SetSelection(GetTextLength(), 0);
682 else 682 else
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 754
755 void AutocompleteEditViewWin::SetDropHighlightPosition(int position) { 755 void AutocompleteEditViewWin::SetDropHighlightPosition(int position) {
756 if (drop_highlight_position_ != position) { 756 if (drop_highlight_position_ != position) {
757 RepaintDropHighlight(drop_highlight_position_); 757 RepaintDropHighlight(drop_highlight_position_);
758 drop_highlight_position_ = position; 758 drop_highlight_position_ = position;
759 RepaintDropHighlight(drop_highlight_position_); 759 RepaintDropHighlight(drop_highlight_position_);
760 } 760 }
761 } 761 }
762 762
763 void AutocompleteEditViewWin::MoveSelectedText(int new_position) { 763 void AutocompleteEditViewWin::MoveSelectedText(int new_position) {
764 const std::wstring selected_text(GetSelectedText()); 764 const string16 selected_text(GetSelectedText());
765 CHARRANGE sel; 765 CHARRANGE sel;
766 GetSel(sel); 766 GetSel(sel);
767 DCHECK((sel.cpMax != sel.cpMin) && (new_position >= 0) && 767 DCHECK((sel.cpMax != sel.cpMin) && (new_position >= 0) &&
768 (new_position <= GetTextLength())); 768 (new_position <= GetTextLength()));
769 769
770 ScopedFreeze freeze(this, GetTextObjectModel()); 770 ScopedFreeze freeze(this, GetTextObjectModel());
771 OnBeforePossibleChange(); 771 OnBeforePossibleChange();
772 772
773 // Nuke the selected text. 773 // Nuke the selected text.
774 ReplaceSel(L"", TRUE); 774 ReplaceSel(L"", TRUE);
775 775
776 // And insert it into the new location. 776 // And insert it into the new location.
777 if (new_position >= sel.cpMin) 777 if (new_position >= sel.cpMin)
778 new_position -= (sel.cpMax - sel.cpMin); 778 new_position -= (sel.cpMax - sel.cpMin);
779 PlaceCaretAt(new_position); 779 PlaceCaretAt(new_position);
780 ReplaceSel(selected_text.c_str(), TRUE); 780 ReplaceSel(selected_text.c_str(), TRUE);
781 781
782 OnAfterPossibleChange(); 782 OnAfterPossibleChange();
783 } 783 }
784 784
785 void AutocompleteEditViewWin::InsertText(int position, 785 void AutocompleteEditViewWin::InsertText(int position,
786 const std::wstring& text) { 786 const string16& text) {
787 DCHECK((position >= 0) && (position <= GetTextLength())); 787 DCHECK((position >= 0) && (position <= GetTextLength()));
788 ScopedFreeze freeze(this, GetTextObjectModel()); 788 ScopedFreeze freeze(this, GetTextObjectModel());
789 OnBeforePossibleChange(); 789 OnBeforePossibleChange();
790 SetSelection(position, position); 790 SetSelection(position, position);
791 ReplaceSel(text.c_str()); 791 ReplaceSel(text.c_str());
792 OnAfterPossibleChange(); 792 OnAfterPossibleChange();
793 } 793 }
794 794
795 void AutocompleteEditViewWin::OnTemporaryTextMaybeChanged( 795 void AutocompleteEditViewWin::OnTemporaryTextMaybeChanged(
796 const std::wstring& display_text, 796 const string16& display_text,
797 bool save_original_selection) { 797 bool save_original_selection) {
798 if (save_original_selection) 798 if (save_original_selection)
799 GetSelection(original_selection_); 799 GetSelection(original_selection_);
800 800
801 // Set new text and cursor position. Sometimes this does extra work (e.g. 801 // Set new text and cursor position. Sometimes this does extra work (e.g.
802 // when the new text and the old text are identical), but it's only called 802 // when the new text and the old text are identical), but it's only called
803 // when the user manually changes the selected line in the popup, so that's 803 // when the user manually changes the selected line in the popup, so that's
804 // not really a problem. Also, even when the text hasn't changed we'd want to 804 // not really a problem. Also, even when the text hasn't changed we'd want to
805 // update the caret, because if the user had the cursor in the middle of the 805 // update the caret, because if the user had the cursor in the middle of the
806 // text and then arrowed to another entry with the same text, we'd still want 806 // text and then arrowed to another entry with the same text, we'd still want
807 // to move the caret. 807 // to move the caret.
808 ScopedFreeze freeze(this, GetTextObjectModel()); 808 ScopedFreeze freeze(this, GetTextObjectModel());
809 SetWindowTextAndCaretPos(display_text, display_text.length()); 809 SetWindowTextAndCaretPos(display_text, display_text.length());
810 TextChanged(); 810 TextChanged();
811 } 811 }
812 812
813 bool AutocompleteEditViewWin::OnInlineAutocompleteTextMaybeChanged( 813 bool AutocompleteEditViewWin::OnInlineAutocompleteTextMaybeChanged(
814 const std::wstring& display_text, 814 const string16& display_text,
815 size_t user_text_length) { 815 size_t user_text_length) {
816 // Update the text and selection. Because this can be called repeatedly while 816 // Update the text and selection. Because this can be called repeatedly while
817 // typing, we've careful not to freeze the edit unless we really need to. 817 // typing, we've careful not to freeze the edit unless we really need to.
818 // Also, unlike in the temporary text case above, here we don't want to update 818 // Also, unlike in the temporary text case above, here we don't want to update
819 // the caret/selection unless we have to, since this might make the user's 819 // the caret/selection unless we have to, since this might make the user's
820 // caret position change without warning during typing. 820 // caret position change without warning during typing.
821 if (display_text == GetText()) 821 if (display_text == GetText())
822 return false; 822 return false;
823 823
824 ScopedFreeze freeze(this, GetTextObjectModel()); 824 ScopedFreeze freeze(this, GetTextObjectModel());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 } 863 }
864 const bool selection_differs = 864 const bool selection_differs =
865 ((new_sel.cpMin != new_sel.cpMax) || 865 ((new_sel.cpMin != new_sel.cpMax) ||
866 (sel_before_change_.cpMin != sel_before_change_.cpMax)) && 866 (sel_before_change_.cpMin != sel_before_change_.cpMax)) &&
867 ((new_sel.cpMin != sel_before_change_.cpMin) || 867 ((new_sel.cpMin != sel_before_change_.cpMin) ||
868 (new_sel.cpMax != sel_before_change_.cpMax)); 868 (new_sel.cpMax != sel_before_change_.cpMax));
869 const bool at_end_of_edit = 869 const bool at_end_of_edit =
870 (new_sel.cpMin == length) && (new_sel.cpMax == length); 870 (new_sel.cpMin == length) && (new_sel.cpMax == length);
871 871
872 // See if the text or selection have changed since OnBeforePossibleChange(). 872 // See if the text or selection have changed since OnBeforePossibleChange().
873 const std::wstring new_text(GetText()); 873 const string16 new_text(GetText());
874 const bool text_differs = (new_text != text_before_change_) || 874 const bool text_differs = (new_text != text_before_change_) ||
875 force_text_changed; 875 force_text_changed;
876 876
877 // 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
878 // 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
879 // (or typing) the prefix of that selection. (We detect these by making 879 // (or typing) the prefix of that selection. (We detect these by making
880 // sure the caret, which should be after any insertion, hasn't moved 880 // sure the caret, which should be after any insertion, hasn't moved
881 // forward of the old selection start.) 881 // forward of the old selection start.)
882 const bool just_deleted_text = 882 const bool just_deleted_text =
883 (text_before_change_.length() > new_text.length()) && 883 (text_before_change_.length() > new_text.length()) &&
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 940
941 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) { 941 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) {
942 views::NativeViewHost* host = new views::NativeViewHost; 942 views::NativeViewHost* host = new views::NativeViewHost;
943 parent->AddChildView(host); 943 parent->AddChildView(host);
944 host->set_focus_view(parent); 944 host->set_focus_view(parent);
945 host->Attach(GetNativeView()); 945 host->Attach(GetNativeView());
946 return host; 946 return host;
947 } 947 }
948 948
949 bool AutocompleteEditViewWin::CommitInstantSuggestion( 949 bool AutocompleteEditViewWin::CommitInstantSuggestion(
950 const std::wstring& typed_text, 950 const string16& typed_text,
951 const std::wstring& suggested_text) { 951 const string16& suggested_text) {
952 model_->FinalizeInstantQuery(typed_text, suggested_text); 952 model_->FinalizeInstantQuery(typed_text, suggested_text);
953 return true; 953 return true;
954 } 954 }
955 955
956 void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) { 956 void AutocompleteEditViewWin::PasteAndGo(const string16& text) {
957 if (CanPasteAndGo(text)) 957 if (CanPasteAndGo(text))
958 model_->PasteAndGo(); 958 model_->PasteAndGo();
959 } 959 }
960 960
961 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( 961 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing(
962 const views::KeyEvent& e) { 962 const views::KeyEvent& e) {
963 ui::KeyboardCode key = e.GetKeyCode(); 963 ui::KeyboardCode key = e.GetKeyCode();
964 // We don't process ALT + numpad digit as accelerators, they are used for 964 // We don't process ALT + numpad digit as accelerators, they are used for
965 // entering special characters. We do translate alt-home. 965 // entering special characters. We do translate alt-home.
966 if (e.IsAltDown() && (key != ui::VKEY_HOME) && 966 if (e.IsAltDown() && (key != ui::VKEY_HOME) &&
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 ui::Accelerator* accelerator) { 1042 ui::Accelerator* accelerator) {
1043 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator); 1043 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator);
1044 } 1044 }
1045 1045
1046 bool AutocompleteEditViewWin::IsItemForCommandIdDynamic(int command_id) const { 1046 bool AutocompleteEditViewWin::IsItemForCommandIdDynamic(int command_id) const {
1047 // No need to change the default IDS_PASTE_AND_GO label unless this is a 1047 // No need to change the default IDS_PASTE_AND_GO label unless this is a
1048 // search. 1048 // search.
1049 return command_id == IDS_PASTE_AND_GO; 1049 return command_id == IDS_PASTE_AND_GO;
1050 } 1050 }
1051 1051
1052 std::wstring AutocompleteEditViewWin::GetLabelForCommandId( 1052 string16 AutocompleteEditViewWin::GetLabelForCommandId(
1053 int command_id) const { 1053 int command_id) const {
1054 DCHECK(command_id == IDS_PASTE_AND_GO); 1054 DCHECK(command_id == IDS_PASTE_AND_GO);
1055 return l10n_util::GetStringUTF16(model_->is_paste_and_search() ? 1055 return l10n_util::GetStringUTF16(model_->is_paste_and_search() ?
1056 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); 1056 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
1057 } 1057 }
1058 1058
1059 void AutocompleteEditViewWin::ExecuteCommand(int command_id) { 1059 void AutocompleteEditViewWin::ExecuteCommand(int command_id) {
1060 ScopedFreeze freeze(this, GetTextObjectModel()); 1060 ScopedFreeze freeze(this, GetTextObjectModel());
1061 if (command_id == IDS_PASTE_AND_GO) { 1061 if (command_id == IDS_PASTE_AND_GO) {
1062 // This case is separate from the switch() below since we don't want to wrap 1062 // This case is separate from the switch() below since we don't want to wrap
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 POINT p; 1254 POINT p;
1255 GetCaretPos(&p); 1255 GetCaretPos(&p);
1256 MapWindowPoints(HWND_DESKTOP, &p, 1); 1256 MapWindowPoints(HWND_DESKTOP, &p, 1);
1257 context_menu_->RunContextMenuAt(gfx::Point(p)); 1257 context_menu_->RunContextMenuAt(gfx::Point(p));
1258 } else { 1258 } else {
1259 context_menu_->RunContextMenuAt(gfx::Point(point)); 1259 context_menu_->RunContextMenuAt(gfx::Point(point));
1260 } 1260 }
1261 } 1261 }
1262 1262
1263 void AutocompleteEditViewWin::OnCopy() { 1263 void AutocompleteEditViewWin::OnCopy() {
1264 std::wstring text(GetSelectedText()); 1264 string16 text(GetSelectedText());
1265 if (text.empty()) 1265 if (text.empty())
1266 return; 1266 return;
1267 1267
1268 CHARRANGE sel; 1268 CHARRANGE sel;
1269 GURL url; 1269 GURL url;
1270 bool write_url = false; 1270 bool write_url = false;
1271 GetSel(sel); 1271 GetSel(sel);
1272 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be 1272 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be
1273 // the smaller value. 1273 // the smaller value.
1274 model_->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); 1274 model_->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 // only changes the current reading order, and as soon as the user deletes all 1362 // only changes the current reading order, and as soon as the user deletes all
1363 // the text, or we call SetWindowText(), it reverts to the "default" order. 1363 // the text, or we call SetWindowText(), it reverts to the "default" order.
1364 // To work around this, if the user hits ctrl+shift, we pass it to 1364 // To work around this, if the user hits ctrl+shift, we pass it to
1365 // DefWindowProc() while the edit is empty, which toggles the default reading 1365 // DefWindowProc() while the edit is empty, which toggles the default reading
1366 // order; then we restore the user's input. 1366 // order; then we restore the user's input.
1367 if (!(flags & KF_ALTDOWN) && 1367 if (!(flags & KF_ALTDOWN) &&
1368 (((key == VK_CONTROL) && (GetKeyState(VK_SHIFT) < 0)) || 1368 (((key == VK_CONTROL) && (GetKeyState(VK_SHIFT) < 0)) ||
1369 ((key == VK_SHIFT) && (GetKeyState(VK_CONTROL) < 0)))) { 1369 ((key == VK_SHIFT) && (GetKeyState(VK_CONTROL) < 0)))) {
1370 ScopedFreeze freeze(this, GetTextObjectModel()); 1370 ScopedFreeze freeze(this, GetTextObjectModel());
1371 1371
1372 std::wstring saved_text(GetText()); 1372 string16 saved_text(GetText());
1373 CHARRANGE saved_sel; 1373 CHARRANGE saved_sel;
1374 GetSelection(saved_sel); 1374 GetSelection(saved_sel);
1375 1375
1376 SetWindowText(L""); 1376 SetWindowText(L"");
1377 1377
1378 DefWindowProc(WM_KEYUP, key, MAKELPARAM(repeat_count, flags)); 1378 DefWindowProc(WM_KEYUP, key, MAKELPARAM(repeat_count, flags));
1379 1379
1380 SetWindowText(saved_text.c_str()); 1380 SetWindowText(saved_text.c_str());
1381 SetSelectionRange(saved_sel); 1381 SetSelectionRange(saved_sel);
1382 return; 1382 return;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 1684
1685 // Blit the memory DC to the actual paint DC and clean up. 1685 // Blit the memory DC to the actual paint DC and clean up.
1686 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,
1687 rect.left, rect.top, SRCCOPY); 1687 rect.left, rect.top, SRCCOPY);
1688 memory_dc.SelectBitmap(old_bitmap); 1688 memory_dc.SelectBitmap(old_bitmap);
1689 edit_hwnd = old_edit_hwnd; 1689 edit_hwnd = old_edit_hwnd;
1690 } 1690 }
1691 1691
1692 void AutocompleteEditViewWin::OnPaste() { 1692 void AutocompleteEditViewWin::OnPaste() {
1693 // Replace the selection if we have something to paste. 1693 // Replace the selection if we have something to paste.
1694 const std::wstring text(GetClipboardText()); 1694 const string16 text(GetClipboardText());
1695 if (!text.empty()) { 1695 if (!text.empty()) {
1696 // Record this paste, so we can do different behavior. 1696 // Record this paste, so we can do different behavior.
1697 model_->on_paste(); 1697 model_->on_paste();
1698 // Force a Paste operation to trigger the text_changed code in 1698 // Force a Paste operation to trigger the text_changed code in
1699 // OnAfterPossibleChange(), even if identical contents are pasted into the 1699 // OnAfterPossibleChange(), even if identical contents are pasted into the
1700 // text box. 1700 // text box.
1701 text_before_change_.clear(); 1701 text_before_change_.clear();
1702 ReplaceSel(text.c_str(), true); 1702 ReplaceSel(text.c_str(), true);
1703 } 1703 }
1704 } 1704 }
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 return; 2026 return;
2027 ScopedComPtr<ITextSelection> selection; 2027 ScopedComPtr<ITextSelection> selection;
2028 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); 2028 const HRESULT hr = text_object_model->GetSelection(selection.Receive());
2029 DCHECK(hr == S_OK); 2029 DCHECK(hr == S_OK);
2030 long flags; 2030 long flags;
2031 selection->GetFlags(&flags); 2031 selection->GetFlags(&flags);
2032 if (flags & tomSelStartActive) 2032 if (flags & tomSelStartActive)
2033 std::swap(sel.cpMin, sel.cpMax); 2033 std::swap(sel.cpMin, sel.cpMax);
2034 } 2034 }
2035 2035
2036 std::wstring AutocompleteEditViewWin::GetSelectedText() const { 2036 string16 AutocompleteEditViewWin::GetSelectedText() const {
2037 // Figure out the length of the selection. 2037 // Figure out the length of the selection.
2038 CHARRANGE sel; 2038 CHARRANGE sel;
2039 GetSel(sel); 2039 GetSel(sel);
2040 2040
2041 // Grab the selected text. 2041 // Grab the selected text.
2042 std::wstring str; 2042 string16 str;
2043 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); 2043 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
2044 return str; 2044 return str;
2045 } 2045 }
2046 2046
2047 void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) { 2047 void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) {
2048 SetSel(start, end); 2048 SetSel(start, end);
2049 2049
2050 if (start <= end) 2050 if (start <= end)
2051 return; 2051 return;
2052 2052
2053 // We need to reverse the direction of the selection. 2053 // We need to reverse the direction of the selection.
2054 ITextDocument* const text_object_model = GetTextObjectModel(); 2054 ITextDocument* const text_object_model = GetTextObjectModel();
2055 if (!text_object_model) 2055 if (!text_object_model)
2056 return; 2056 return;
2057 ScopedComPtr<ITextSelection> selection; 2057 ScopedComPtr<ITextSelection> selection;
2058 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); 2058 const HRESULT hr = text_object_model->GetSelection(selection.Receive());
2059 DCHECK(hr == S_OK); 2059 DCHECK(hr == S_OK);
2060 selection->SetFlags(tomSelStartActive); 2060 selection->SetFlags(tomSelStartActive);
2061 } 2061 }
2062 2062
2063 void AutocompleteEditViewWin::PlaceCaretAt(std::wstring::size_type pos) { 2063 void AutocompleteEditViewWin::PlaceCaretAt(string16::size_type pos) {
2064 SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos)); 2064 SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos));
2065 } 2065 }
2066 2066
2067 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { 2067 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const {
2068 const int text_length = GetTextLength(); 2068 const int text_length = GetTextLength();
2069 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) || 2069 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) ||
2070 ((sel.cpMax == 0) && (sel.cpMin >= text_length)); 2070 ((sel.cpMax == 0) && (sel.cpMin >= text_length));
2071 } 2071 }
2072 2072
2073 LONG AutocompleteEditViewWin::ClipXCoordToVisibleText( 2073 LONG AutocompleteEditViewWin::ClipXCoordToVisibleText(
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2312 LineTo(hdc, clip_rect.left, clip_rect.bottom); 2312 LineTo(hdc, clip_rect.left, clip_rect.bottom);
2313 DeleteObject(SelectObject(hdc, last_pen)); 2313 DeleteObject(SelectObject(hdc, last_pen));
2314 } 2314 }
2315 2315
2316 void AutocompleteEditViewWin::TextChanged() { 2316 void AutocompleteEditViewWin::TextChanged() {
2317 ScopedFreeze freeze(this, GetTextObjectModel()); 2317 ScopedFreeze freeze(this, GetTextObjectModel());
2318 EmphasizeURLComponents(); 2318 EmphasizeURLComponents();
2319 controller_->OnChanged(); 2319 controller_->OnChanged();
2320 } 2320 }
2321 2321
2322 std::wstring AutocompleteEditViewWin::GetClipboardText() const { 2322 string16 AutocompleteEditViewWin::GetClipboardText() const {
2323 // Try text format. 2323 // Try text format.
2324 ui::Clipboard* clipboard = g_browser_process->clipboard(); 2324 ui::Clipboard* clipboard = g_browser_process->clipboard();
2325 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), 2325 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
2326 ui::Clipboard::BUFFER_STANDARD)) { 2326 ui::Clipboard::BUFFER_STANDARD)) {
2327 std::wstring text; 2327 string16 text;
2328 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); 2328 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
2329 2329
2330 // Note: Unlike in the find popup and textfield view, here we completely 2330 // Note: Unlike in the find popup and textfield view, here we completely
2331 // remove whitespace strings containing newlines. We assume users are 2331 // remove whitespace strings containing newlines. We assume users are
2332 // most likely pasting in URLs that may have been split into multiple 2332 // most likely pasting in URLs that may have been split into multiple
2333 // lines in terminals, email programs, etc., and so linebreaks indicate 2333 // lines in terminals, email programs, etc., and so linebreaks indicate
2334 // completely bogus whitespace that would just cause the input to be 2334 // completely bogus whitespace that would just cause the input to be
2335 // invalid. 2335 // invalid.
2336 return CollapseWhitespace(text, true); 2336 return CollapseWhitespace(text, true);
2337 } 2337 }
2338 2338
2339 // Try bookmark format. 2339 // Try bookmark format.
2340 // 2340 //
2341 // It is tempting to try bookmark format first, but the URL we get out of a 2341 // It is tempting to try bookmark format first, but the URL we get out of a
2342 // bookmark has been cannonicalized via GURL. This means if a user copies 2342 // bookmark has been cannonicalized via GURL. This means if a user copies
2343 // and pastes from the URL bar to itself, the text will get fixed up and 2343 // and pastes from the URL bar to itself, the text will get fixed up and
2344 // cannonicalized, which is not what the user expects. By pasting in this 2344 // cannonicalized, which is not what the user expects. By pasting in this
2345 // order, we are sure to paste what the user copied. 2345 // order, we are sure to paste what the user copied.
2346 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(), 2346 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
2347 ui::Clipboard::BUFFER_STANDARD)) { 2347 ui::Clipboard::BUFFER_STANDARD)) {
2348 std::string url_str; 2348 std::string url_str;
2349 clipboard->ReadBookmark(NULL, &url_str); 2349 clipboard->ReadBookmark(NULL, &url_str);
2350 // pass resulting url string through GURL to normalize 2350 // pass resulting url string through GURL to normalize
2351 GURL url(url_str); 2351 GURL url(url_str);
2352 if (url.is_valid()) 2352 if (url.is_valid())
2353 return UTF8ToWide(url.spec()); 2353 return UTF8ToWide(url.spec());
2354 } 2354 }
2355 2355
2356 return std::wstring(); 2356 return string16();
2357 } 2357 }
2358 2358
2359 bool AutocompleteEditViewWin::CanPasteAndGo(const std::wstring& text) const { 2359 bool AutocompleteEditViewWin::CanPasteAndGo(const string16& text) const {
2360 return !popup_window_mode_ && model_->CanPasteAndGo(text); 2360 return !popup_window_mode_ && model_->CanPasteAndGo(text);
2361 } 2361 }
2362 2362
2363 ITextDocument* AutocompleteEditViewWin::GetTextObjectModel() const { 2363 ITextDocument* AutocompleteEditViewWin::GetTextObjectModel() const {
2364 if (!text_object_model_) { 2364 if (!text_object_model_) {
2365 // This is lazily initialized, instead of being initialized in the 2365 // This is lazily initialized, instead of being initialized in the
2366 // constructor, in order to avoid hurting startup performance. 2366 // constructor, in order to avoid hurting startup performance.
2367 ScopedComPtr<IRichEditOle, NULL> ole_interface; 2367 ScopedComPtr<IRichEditOle, NULL> ole_interface;
2368 ole_interface.Attach(GetOleInterface()); 2368 ole_interface.Attach(GetOleInterface());
2369 if (ole_interface) { 2369 if (ole_interface) {
(...skipping 23 matching lines...) Expand all
2393 // selection and start the drag. We always send lbuttonup as otherwise we 2393 // selection and start the drag. We always send lbuttonup as otherwise we
2394 // might trigger a context menu (right up). This seems scary, but doesn't 2394 // might trigger a context menu (right up). This seems scary, but doesn't
2395 // seem to cause problems. 2395 // seem to cause problems.
2396 { 2396 {
2397 ScopedFreeze freeze(this, GetTextObjectModel()); 2397 ScopedFreeze freeze(this, GetTextObjectModel());
2398 DefWindowProc(WM_LBUTTONUP, 0, 2398 DefWindowProc(WM_LBUTTONUP, 0,
2399 MAKELPARAM(click_point_[kLeft].x, click_point_[kLeft].y)); 2399 MAKELPARAM(click_point_[kLeft].x, click_point_[kLeft].y));
2400 SetSelectionRange(sel); 2400 SetSelectionRange(sel);
2401 } 2401 }
2402 2402
2403 const std::wstring start_text(GetText()); 2403 const string16 start_text(GetText());
2404 std::wstring text_to_write(GetSelectedText()); 2404 string16 text_to_write(GetSelectedText());
2405 GURL url; 2405 GURL url;
2406 bool write_url; 2406 bool write_url;
2407 const bool is_all_selected = IsSelectAllForRange(sel); 2407 const bool is_all_selected = IsSelectAllForRange(sel);
2408 2408
2409 // |sel| was set by GetSelection(), which preserves selection direction, so 2409 // |sel| was set by GetSelection(), which preserves selection direction, so
2410 // sel.cpMin may not be the smaller value. 2410 // sel.cpMin may not be the smaller value.
2411 model()->AdjustTextForCopy(std::min(sel.cpMin, sel.cpMax), is_all_selected, 2411 model()->AdjustTextForCopy(std::min(sel.cpMin, sel.cpMax), is_all_selected,
2412 &text_to_write, &url, &write_url); 2412 &text_to_write, &url, &write_url);
2413 2413
2414 if (write_url) { 2414 if (write_url) {
2415 std::wstring title; 2415 string16 title;
2416 SkBitmap favicon; 2416 SkBitmap favicon;
2417 if (is_all_selected) 2417 if (is_all_selected)
2418 model_->GetDataForURLExport(&url, &title, &favicon); 2418 model_->GetDataForURLExport(&url, &title, &favicon);
2419 drag_utils::SetURLAndDragImage(url, title, favicon, &data); 2419 drag_utils::SetURLAndDragImage(url, title, favicon, &data);
2420 supported_modes |= DROPEFFECT_LINK; 2420 supported_modes |= DROPEFFECT_LINK;
2421 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragURL"), 2421 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragURL"),
2422 model_->profile()); 2422 model_->profile());
2423 } else { 2423 } else {
2424 supported_modes |= DROPEFFECT_MOVE; 2424 supported_modes |= DROPEFFECT_MOVE;
2425 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragString"), 2425 UserMetrics::RecordAction(UserMetricsAction("Omnibox_DragString"),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2554 2554
2555 int AutocompleteEditViewWin::GetHorizontalMargin() const { 2555 int AutocompleteEditViewWin::GetHorizontalMargin() const {
2556 RECT rect; 2556 RECT rect;
2557 GetRect(&rect); 2557 GetRect(&rect);
2558 RECT client_rect; 2558 RECT client_rect;
2559 GetClientRect(&client_rect); 2559 GetClientRect(&client_rect);
2560 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2560 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2561 } 2561 }
2562 2562
2563 int AutocompleteEditViewWin::WidthNeededToDisplay( 2563 int AutocompleteEditViewWin::WidthNeededToDisplay(
2564 const std::wstring& text) const { 2564 const string16& text) const {
2565 // Use font_.GetStringWidth() instead of 2565 // Use font_.GetStringWidth() instead of
2566 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2566 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2567 // 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,
2568 // PosFromChar(i) might return 0 when i is greater than 1. 2568 // PosFromChar(i) might return 0 when i is greater than 1.
2569 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2569 return font_.GetStringWidth(text) + GetHorizontalMargin();
2570 } 2570 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_win.h ('k') | chrome/browser/autocomplete/autocomplete_match.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698