Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_mac.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
| 8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/clipboard.h" | 10 #include "base/clipboard.h" |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 } | 579 } |
| 580 | 580 |
| 581 void AutocompleteEditViewMac::OnPaste() { | 581 void AutocompleteEditViewMac::OnPaste() { |
| 582 // This code currently expects |field_| to be focussed. | 582 // This code currently expects |field_| to be focussed. |
| 583 DCHECK([field_ currentEditor]); | 583 DCHECK([field_ currentEditor]); |
| 584 | 584 |
| 585 std::wstring text = GetClipboardText(g_browser_process->clipboard()); | 585 std::wstring text = GetClipboardText(g_browser_process->clipboard()); |
| 586 if (text.empty()) { | 586 if (text.empty()) { |
| 587 return; | 587 return; |
| 588 } | 588 } |
| 589 NSString* s = base::SysWideToNSString(text); | |
| 589 | 590 |
| 590 // If this paste will be replacing all the text, record that, so we | 591 // -shouldChangeTextInRange:* and -didChangeText are documented in |
| 591 // can do different behaviors in such a case. | 592 // NSTextView as things you need to do if you write additional |
| 592 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); | 593 // user-initiated editing functions. They cause the appropriate |
| 594 // delegate methods to be called. | |
| 595 // TODO(shess): It would be nice to separate the Cocoa-specific code | |
| 596 // from the Chrome-specific code. | |
| 597 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); | |
| 593 const NSRange selectedRange = GetSelectedRange(); | 598 const NSRange selectedRange = GetSelectedRange(); |
| 594 if (NSEqualRanges(allRange, selectedRange)) { | 599 if ([editor shouldChangeTextInRange:selectedRange replacementString:s]) { |
| 595 model_->on_paste_replacing_all(); | 600 // If this paste will be replacing all the text, record that, so |
| 601 // we can do different behaviors in such a case. | |
| 602 const NSRange allRange = NSMakeRange(0, [[field_ stringValue] length]); | |
| 603 if (NSEqualRanges(allRange, selectedRange)) { | |
| 604 model_->on_paste_replacing_all(); | |
| 605 } | |
| 606 | |
| 607 // Force a Paste operation to trigger the text_changed code in | |
| 608 // OnAfterPossibleChange(), even if identical contents are pasted | |
| 609 // into the text box. | |
| 610 text_before_change_.clear(); | |
| 611 | |
| 612 [editor replaceCharactersInRange:selectedRange withString:s]; | |
| 613 [editor didChangeText]; | |
|
rohitrao (ping after 24h)
2009/09/18 20:38:25
So this is what fires off controlTextDidChange?
Scott Hess - ex-Googler
2009/09/18 21:20:51
-didChangeText leads to -controlTextDidChange:, -s
| |
| 596 } | 614 } |
| 597 | |
| 598 // Force a Paste operation to trigger the text_changed code in | |
| 599 // OnAfterPossibleChange(), even if identical contents are pasted into the | |
| 600 // text box. | |
| 601 text_before_change_.clear(); | |
| 602 | |
| 603 NSString* s = base::SysWideToNSString(text); | |
| 604 [[field_ currentEditor] replaceCharactersInRange:selectedRange withString:s]; | |
| 605 | |
| 606 OnAfterPossibleChange(); | |
| 607 } | 615 } |
| 608 | 616 |
| 609 bool AutocompleteEditViewMac::OnTabPressed() { | 617 bool AutocompleteEditViewMac::OnTabPressed() { |
| 610 if (model_->is_keyword_hint() && !model_->keyword().empty()) { | 618 if (model_->is_keyword_hint() && !model_->keyword().empty()) { |
| 611 model_->AcceptKeyword(); | 619 model_->AcceptKeyword(); |
| 612 return true; | 620 return true; |
| 613 } | 621 } |
| 614 return false; | 622 return false; |
| 615 } | 623 } |
| 616 | 624 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 // prepended and ".com" appended. This calls down to | 856 // prepended and ".com" appended. This calls down to |
| 849 // AutocompleteEditModel::OnControlKeyChanged() so that it can change | 857 // AutocompleteEditModel::OnControlKeyChanged() so that it can change |
| 850 // the popup to reflect this. See autocomplete_edit.cc | 858 // the popup to reflect this. See autocomplete_edit.cc |
| 851 // OnControlKeyChanged() and OnAfterPossibleChange(). | 859 // OnControlKeyChanged() and OnAfterPossibleChange(). |
| 852 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { | 860 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { |
| 853 bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; | 861 bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; |
| 854 edit_view_->OnControlKeyChanged(controlFlag); | 862 edit_view_->OnControlKeyChanged(controlFlag); |
| 855 } | 863 } |
| 856 | 864 |
| 857 @end | 865 @end |
| OLD | NEW |