OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 FocusLocation(false); | 362 FocusLocation(false); |
363 model()->SetCaretVisibility(true); | 363 model()->SetCaretVisibility(true); |
364 } | 364 } |
365 | 365 |
366 void OmniboxViewMac::ApplyCaretVisibility() { | 366 void OmniboxViewMac::ApplyCaretVisibility() { |
367 [[field_ cell] setHideFocusState:!model()->is_caret_visible() | 367 [[field_ cell] setHideFocusState:!model()->is_caret_visible() |
368 ofView:field_]; | 368 ofView:field_]; |
369 } | 369 } |
370 | 370 |
371 void OmniboxViewMac::SetText(const string16& display_text) { | 371 void OmniboxViewMac::SetText(const string16& display_text) { |
372 // If we are setting the text directly, there cannot be any suggest text. | |
373 SetInstantSuggestion(string16()); | |
374 SetTextInternal(display_text); | 372 SetTextInternal(display_text); |
375 } | 373 } |
376 | 374 |
377 void OmniboxViewMac::SetTextInternal(const string16& display_text) { | 375 void OmniboxViewMac::SetTextInternal(const string16& display_text) { |
378 NSString* ss = base::SysUTF16ToNSString(display_text); | 376 NSString* ss = base::SysUTF16ToNSString(display_text); |
379 NSMutableAttributedString* as = | 377 NSMutableAttributedString* as = |
380 [[[NSMutableAttributedString alloc] initWithString:ss] autorelease]; | 378 [[[NSMutableAttributedString alloc] initWithString:ss] autorelease]; |
381 | 379 |
382 ApplyTextAttributes(display_text, as); | 380 ApplyTextAttributes(display_text, as); |
383 [field_ setAttributedStringValue:as]; | 381 [field_ setAttributedStringValue:as]; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 range:ComponentToNSRange(scheme)]; | 486 range:ComponentToNSRange(scheme)]; |
489 } | 487 } |
490 } | 488 } |
491 | 489 |
492 void OmniboxViewMac::OnTemporaryTextMaybeChanged(const string16& display_text, | 490 void OmniboxViewMac::OnTemporaryTextMaybeChanged(const string16& display_text, |
493 bool save_original_selection, | 491 bool save_original_selection, |
494 bool notify_text_changed) { | 492 bool notify_text_changed) { |
495 if (save_original_selection) | 493 if (save_original_selection) |
496 saved_temporary_selection_ = GetSelectedRange(); | 494 saved_temporary_selection_ = GetSelectedRange(); |
497 | 495 |
498 SetInstantSuggestion(string16()); | |
499 SetWindowTextAndCaretPos(display_text, display_text.size(), false, false); | 496 SetWindowTextAndCaretPos(display_text, display_text.size(), false, false); |
500 if (notify_text_changed) | 497 if (notify_text_changed) |
501 model()->OnChanged(); | 498 model()->OnChanged(); |
502 [field_ clearUndoChain]; | 499 [field_ clearUndoChain]; |
503 } | 500 } |
504 | 501 |
505 void OmniboxViewMac::OnStartingIME() { | 502 void OmniboxViewMac::OnStartingIME() { |
Peter Kasting
2013/04/03 00:35:35
Can this function be eliminated entirely?
sail
2013/04/03 19:34:11
Done.
Good idea.
| |
506 // Reset the suggest text just before starting an IME composition session, | |
507 // otherwise the IME composition may be interrupted when the suggest text | |
508 // gets reset by the IME composition change. | |
509 SetInstantSuggestion(string16()); | |
510 } | 503 } |
511 | 504 |
512 bool OmniboxViewMac::OnInlineAutocompleteTextMaybeChanged( | 505 bool OmniboxViewMac::OnInlineAutocompleteTextMaybeChanged( |
513 const string16& display_text, | 506 const string16& display_text, |
514 size_t user_text_length) { | 507 size_t user_text_length) { |
515 // TODO(shess): Make sure that this actually works. The round trip | 508 // TODO(shess): Make sure that this actually works. The round trip |
516 // to native form and back may mean that it's the same but not the | 509 // to native form and back may mean that it's the same but not the |
517 // same. | 510 // same. |
518 if (display_text == GetText()) | 511 if (display_text == GetText()) |
519 return false; | 512 return false; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 void OmniboxViewMac::OnDidChange() { | 634 void OmniboxViewMac::OnDidChange() { |
642 // Figure out what changed and notify the model. | 635 // Figure out what changed and notify the model. |
643 OnAfterPossibleChange(); | 636 OnAfterPossibleChange(); |
644 } | 637 } |
645 | 638 |
646 void OmniboxViewMac::OnDidEndEditing() { | 639 void OmniboxViewMac::OnDidEndEditing() { |
647 ClosePopup(); | 640 ClosePopup(); |
648 } | 641 } |
649 | 642 |
650 bool OmniboxViewMac::OnDoCommandBySelector(SEL cmd) { | 643 bool OmniboxViewMac::OnDoCommandBySelector(SEL cmd) { |
651 if (cmd != @selector(moveRight:) && | |
652 cmd != @selector(insertTab:) && | |
653 cmd != @selector(insertTabIgnoringFieldEditor:)) { | |
654 // Reset the suggest text for any change other than key right or tab. | |
655 // TODO(rohitrao): This is here to prevent complications when editing text. | |
656 // See if this can be removed. | |
657 SetInstantSuggestion(string16()); | |
658 } | |
659 | |
660 if (cmd == @selector(deleteForward:)) | 644 if (cmd == @selector(deleteForward:)) |
661 delete_was_pressed_ = true; | 645 delete_was_pressed_ = true; |
662 | 646 |
663 if (cmd == @selector(moveDown:)) { | 647 if (cmd == @selector(moveDown:)) { |
664 model()->OnUpOrDownKeyPressed(1); | 648 model()->OnUpOrDownKeyPressed(1); |
665 return true; | 649 return true; |
666 } | 650 } |
667 | 651 |
668 if (cmd == @selector(moveUp:)) { | 652 if (cmd == @selector(moveUp:)) { |
669 model()->OnUpOrDownKeyPressed(-1); | 653 model()->OnUpOrDownKeyPressed(-1); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 | 960 |
977 NSUInteger OmniboxViewMac::GetTextLength() const { | 961 NSUInteger OmniboxViewMac::GetTextLength() const { |
978 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 962 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
979 [[field_ stringValue] length]; | 963 [[field_ stringValue] length]; |
980 } | 964 } |
981 | 965 |
982 bool OmniboxViewMac::IsCaretAtEnd() const { | 966 bool OmniboxViewMac::IsCaretAtEnd() const { |
983 const NSRange selection = GetSelectedRange(); | 967 const NSRange selection = GetSelectedRange(); |
984 return NSMaxRange(selection) == GetTextLength(); | 968 return NSMaxRange(selection) == GetTextLength(); |
985 } | 969 } |
OLD | NEW |