| 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/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/property_bag.h" | 9 #include "base/property_bag.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 357 |
| 358 // TODO(shess): What if it didn't get first responder, and there is | 358 // TODO(shess): What if it didn't get first responder, and there is |
| 359 // no field editor? This will do nothing. Well, at least it won't | 359 // no field editor? This will do nothing. Well, at least it won't |
| 360 // crash. Think of something more productive to do, or prove that | 360 // crash. Think of something more productive to do, or prove that |
| 361 // it cannot occur and DCHECK appropriately. | 361 // it cannot occur and DCHECK appropriately. |
| 362 [[field_ currentEditor] setSelectedRange:range]; | 362 [[field_ currentEditor] setSelectedRange:range]; |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 | 365 |
| 366 void OmniboxViewMac::SetWindowTextAndCaretPos(const string16& text, | 366 void OmniboxViewMac::SetWindowTextAndCaretPos(const string16& text, |
| 367 size_t caret_pos) { | 367 size_t caret_pos, |
| 368 bool update_popup, |
| 369 bool notify_text_changed) { |
| 368 DCHECK_LE(caret_pos, text.size()); | 370 DCHECK_LE(caret_pos, text.size()); |
| 369 SetTextAndSelectedRange(text, NSMakeRange(caret_pos, caret_pos)); | 371 SetTextAndSelectedRange(text, NSMakeRange(caret_pos, caret_pos)); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void OmniboxViewMac::SetForcedQuery() { | 374 void OmniboxViewMac::SetForcedQuery() { |
| 373 // We need to do this first, else |SetSelectedRange()| won't work. | 375 // We need to do this first, else |SetSelectedRange()| won't work. |
| 374 FocusLocation(true); | 376 FocusLocation(true); |
| 375 | 377 |
| 376 const string16 current_text(GetText()); | 378 const string16 current_text(GetText()); |
| 377 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); | 379 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 range:ComponentToNSRange(scheme)]; | 601 range:ComponentToNSRange(scheme)]; |
| 600 } | 602 } |
| 601 } | 603 } |
| 602 | 604 |
| 603 void OmniboxViewMac::OnTemporaryTextMaybeChanged(const string16& display_text, | 605 void OmniboxViewMac::OnTemporaryTextMaybeChanged(const string16& display_text, |
| 604 bool save_original_selection) { | 606 bool save_original_selection) { |
| 605 if (save_original_selection) | 607 if (save_original_selection) |
| 606 saved_temporary_selection_ = GetSelectedRange(); | 608 saved_temporary_selection_ = GetSelectedRange(); |
| 607 | 609 |
| 608 suggest_text_length_ = 0; | 610 suggest_text_length_ = 0; |
| 609 SetWindowTextAndCaretPos(display_text, display_text.size()); | 611 SetWindowTextAndCaretPos(display_text, display_text.size(), false, false); |
| 610 model_->OnChanged(); | 612 model_->OnChanged(); |
| 611 [field_ clearUndoChain]; | 613 [field_ clearUndoChain]; |
| 612 } | 614 } |
| 613 | 615 |
| 614 void OmniboxViewMac::OnStartingIME() { | 616 void OmniboxViewMac::OnStartingIME() { |
| 615 // Reset the suggest text just before starting an IME composition session, | 617 // Reset the suggest text just before starting an IME composition session, |
| 616 // otherwise the IME composition may be interrupted when the suggest text | 618 // otherwise the IME composition may be interrupted when the suggest text |
| 617 // gets reset by the IME composition change. | 619 // gets reset by the IME composition change. |
| 618 SetInstantSuggestion(string16(), false); | 620 SetInstantSuggestion(string16(), false); |
| 619 } | 621 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 | 1127 |
| 1126 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { | 1128 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { |
| 1127 DCHECK(pos <= GetTextLength()); | 1129 DCHECK(pos <= GetTextLength()); |
| 1128 SetSelectedRange(NSMakeRange(pos, pos)); | 1130 SetSelectedRange(NSMakeRange(pos, pos)); |
| 1129 } | 1131 } |
| 1130 | 1132 |
| 1131 bool OmniboxViewMac::IsCaretAtEnd() const { | 1133 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1132 const NSRange selection = GetSelectedRange(); | 1134 const NSRange selection = GetSelectedRange(); |
| 1133 return selection.length == 0 && selection.location == GetTextLength(); | 1135 return selection.length == 0 && selection.location == GetTextLength(); |
| 1134 } | 1136 } |
| OLD | NEW |