| 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 "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" | 10 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 UpdatePopup(); | 283 UpdatePopup(); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 NSRange AutocompleteEditViewMac::GetSelectedRange() const { | 287 NSRange AutocompleteEditViewMac::GetSelectedRange() const { |
| 288 DCHECK([field_ currentEditor]); | 288 DCHECK([field_ currentEditor]); |
| 289 return [[field_ currentEditor] selectedRange]; | 289 return [[field_ currentEditor] selectedRange]; |
| 290 } | 290 } |
| 291 | 291 |
| 292 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { | 292 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { |
| 293 // This can be called when we don't have focus. For instance, when |
| 294 // the user clicks the "Go" button. |
| 293 if (model_->has_focus()) { | 295 if (model_->has_focus()) { |
| 294 // TODO(shess): This should not be necessary. Try to convert to | 296 // TODO(shess): If |model_| thinks we have focus, this should not |
| 295 // DCHECK(IsFirstResponder()). | 297 // be necessary. Try to convert to DCHECK(IsFirstResponder()). |
| 296 FocusLocation(); | 298 FocusLocation(); |
| 297 | 299 |
| 298 // TODO(shess): What if it didn't get first responder, and there is | 300 // TODO(shess): What if it didn't get first responder, and there is |
| 299 // no field editor? This will do nothing. Well, at least it won't | 301 // no field editor? This will do nothing. Well, at least it won't |
| 300 // crash. Think of something more productive to do, or prove that | 302 // crash. Think of something more productive to do, or prove that |
| 301 // it cannot occur and DCHECK appropriately. | 303 // it cannot occur and DCHECK appropriately. |
| 302 [[field_ currentEditor] setSelectedRange:range]; | 304 [[field_ currentEditor] setSelectedRange:range]; |
| 303 } | 305 } |
| 304 } | 306 } |
| 305 | 307 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 // Tell the model to reset itself. | 549 // Tell the model to reset itself. |
| 548 model_->OnKillFocus(); | 550 model_->OnKillFocus(); |
| 549 } | 551 } |
| 550 | 552 |
| 551 void AutocompleteEditViewMac::OnDidResignKey() { | 553 void AutocompleteEditViewMac::OnDidResignKey() { |
| 552 ClosePopup(); | 554 ClosePopup(); |
| 553 } | 555 } |
| 554 | 556 |
| 555 void AutocompleteEditViewMac::AcceptInput( | 557 void AutocompleteEditViewMac::AcceptInput( |
| 556 WindowOpenDisposition disposition, bool for_drop) { | 558 WindowOpenDisposition disposition, bool for_drop) { |
| 557 // We should only arrive here when the field is focussed. | |
| 558 DCHECK([field_ currentEditor]); | |
| 559 | |
| 560 model_->AcceptInput(disposition, for_drop); | 559 model_->AcceptInput(disposition, for_drop); |
| 561 } | 560 } |
| 562 | 561 |
| 563 void AutocompleteEditViewMac::FocusLocation() { | 562 void AutocompleteEditViewMac::FocusLocation() { |
| 564 // -makeFirstResponder: will select the entire field_. If we're | 563 // -makeFirstResponder: will select the entire field_. If we're |
| 565 // already firstResponder, it's likely that we want to retain the | 564 // already firstResponder, it's likely that we want to retain the |
| 566 // current selection. | 565 // current selection. |
| 567 if (![field_ currentEditor]) { | 566 if (![field_ currentEditor]) { |
| 568 [[field_ window] makeFirstResponder:field_]; | 567 [[field_ window] makeFirstResponder:field_]; |
| 569 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); | 568 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // TODO(shess): Figure out where the selection belongs. On GTK, | 638 // TODO(shess): Figure out where the selection belongs. On GTK, |
| 640 // it's set to the start of the text. | 639 // it's set to the start of the text. |
| 641 } | 640 } |
| 642 | 641 |
| 643 // Signal that we've lost focus when the window resigns key. | 642 // Signal that we've lost focus when the window resigns key. |
| 644 - (void)windowDidResignKey:(NSNotification*)notification { | 643 - (void)windowDidResignKey:(NSNotification*)notification { |
| 645 edit_view_->OnDidResignKey(); | 644 edit_view_->OnDidResignKey(); |
| 646 } | 645 } |
| 647 | 646 |
| 648 @end | 647 @end |
| OLD | NEW |