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() { | |
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 } | |
511 | |
512 bool OmniboxViewMac::OnInlineAutocompleteTextMaybeChanged( | 502 bool OmniboxViewMac::OnInlineAutocompleteTextMaybeChanged( |
513 const string16& display_text, | 503 const string16& display_text, |
514 size_t user_text_length) { | 504 size_t user_text_length) { |
515 // TODO(shess): Make sure that this actually works. The round trip | 505 // 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 | 506 // to native form and back may mean that it's the same but not the |
517 // same. | 507 // same. |
518 if (display_text == GetText()) | 508 if (display_text == GetText()) |
519 return false; | 509 return false; |
520 | 510 |
521 DCHECK_LE(user_text_length, display_text.size()); | 511 DCHECK_LE(user_text_length, display_text.size()); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 void OmniboxViewMac::OnDidChange() { | 642 void OmniboxViewMac::OnDidChange() { |
653 // Figure out what changed and notify the model. | 643 // Figure out what changed and notify the model. |
654 OnAfterPossibleChange(); | 644 OnAfterPossibleChange(); |
655 } | 645 } |
656 | 646 |
657 void OmniboxViewMac::OnDidEndEditing() { | 647 void OmniboxViewMac::OnDidEndEditing() { |
658 ClosePopup(); | 648 ClosePopup(); |
659 } | 649 } |
660 | 650 |
661 bool OmniboxViewMac::OnDoCommandBySelector(SEL cmd) { | 651 bool OmniboxViewMac::OnDoCommandBySelector(SEL cmd) { |
662 if (cmd != @selector(moveRight:) && | |
663 cmd != @selector(insertTab:) && | |
664 cmd != @selector(insertTabIgnoringFieldEditor:)) { | |
665 // Reset the suggest text for any change other than key right or tab. | |
666 // TODO(rohitrao): This is here to prevent complications when editing text. | |
667 // See if this can be removed. | |
668 SetInstantSuggestion(string16()); | |
669 } | |
670 | |
671 if (cmd == @selector(deleteForward:)) | 652 if (cmd == @selector(deleteForward:)) |
672 delete_was_pressed_ = true; | 653 delete_was_pressed_ = true; |
673 | 654 |
674 if (cmd == @selector(moveDown:)) { | 655 if (cmd == @selector(moveDown:)) { |
675 model()->OnUpOrDownKeyPressed(1); | 656 model()->OnUpOrDownKeyPressed(1); |
676 return true; | 657 return true; |
677 } | 658 } |
678 | 659 |
679 if (cmd == @selector(moveUp:)) { | 660 if (cmd == @selector(moveUp:)) { |
680 model()->OnUpOrDownKeyPressed(-1); | 661 model()->OnUpOrDownKeyPressed(-1); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 968 |
988 NSUInteger OmniboxViewMac::GetTextLength() const { | 969 NSUInteger OmniboxViewMac::GetTextLength() const { |
989 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 970 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
990 [[field_ stringValue] length]; | 971 [[field_ stringValue] length]; |
991 } | 972 } |
992 | 973 |
993 bool OmniboxViewMac::IsCaretAtEnd() const { | 974 bool OmniboxViewMac::IsCaretAtEnd() const { |
994 const NSRange selection = GetSelectedRange(); | 975 const NSRange selection = GetSelectedRange(); |
995 return NSMaxRange(selection) == GetTextLength(); | 976 return NSMaxRange(selection) == GetTextLength(); |
996 } | 977 } |
OLD | NEW |