| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 // Restore focus and selection if they were present when the tab | 217 // Restore focus and selection if they were present when the tab |
| 218 // was switched away. | 218 // was switched away. |
| 219 if (state->has_focus) { | 219 if (state->has_focus) { |
| 220 // TODO(shess): Unfortunately, there is no safe way to update | 220 // TODO(shess): Unfortunately, there is no safe way to update |
| 221 // this because TabStripController -selectTabWithContents:* is | 221 // this because TabStripController -selectTabWithContents:* is |
| 222 // also messing with focus. Both parties need to agree to | 222 // also messing with focus. Both parties need to agree to |
| 223 // store existing state before anyone tries to setup the new | 223 // store existing state before anyone tries to setup the new |
| 224 // state. Anyhow, it would look something like this. | 224 // state. Anyhow, it would look something like this. |
| 225 #if 0 | 225 #if 0 |
| 226 FocusLocation(); | 226 [[field_ window] makeFirstResponder:field_]; |
| 227 | |
| 228 // Must restore directly to evade model_->has_focus() guard. | |
| 229 [[field_ currentEditor] setSelectedRange:state->selection]; | 227 [[field_ currentEditor] setSelectedRange:state->selection]; |
| 230 #endif | 228 #endif |
| 231 } | 229 } |
| 232 } | 230 } |
| 233 } else if (user_visible) { | 231 } else if (user_visible) { |
| 234 // Restore everything to the baseline look. | 232 // Restore everything to the baseline look. |
| 235 RevertAll(); | 233 RevertAll(); |
| 236 // TODO(shess): Figure out how this case is used, to make sure | 234 // TODO(shess): Figure out how this case is used, to make sure |
| 237 // we're getting the selection and popup right. | 235 // we're getting the selection and popup right. |
| 238 | 236 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 DCHECK([field_ currentEditor]); | 286 DCHECK([field_ currentEditor]); |
| 289 return [[field_ currentEditor] selectedRange]; | 287 return [[field_ currentEditor] selectedRange]; |
| 290 } | 288 } |
| 291 | 289 |
| 292 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { | 290 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { |
| 293 // This can be called when we don't have focus. For instance, when | 291 // This can be called when we don't have focus. For instance, when |
| 294 // the user clicks the "Go" button. | 292 // the user clicks the "Go" button. |
| 295 if (model_->has_focus()) { | 293 if (model_->has_focus()) { |
| 296 // TODO(shess): If |model_| thinks we have focus, this should not | 294 // TODO(shess): If |model_| thinks we have focus, this should not |
| 297 // be necessary. Try to convert to DCHECK(IsFirstResponder()). | 295 // be necessary. Try to convert to DCHECK(IsFirstResponder()). |
| 298 FocusLocation(); | 296 if (![field_ currentEditor]) { |
| 297 [[field_ window] makeFirstResponder:field_]; |
| 298 } |
| 299 | 299 |
| 300 // 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 |
| 301 // 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 |
| 302 // crash. Think of something more productive to do, or prove that | 302 // crash. Think of something more productive to do, or prove that |
| 303 // it cannot occur and DCHECK appropriately. | 303 // it cannot occur and DCHECK appropriately. |
| 304 [[field_ currentEditor] setSelectedRange:range]; | 304 [[field_ currentEditor] setSelectedRange:range]; |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 void AutocompleteEditViewMac::SetWindowTextAndCaretPos(const std::wstring& text, | 308 void AutocompleteEditViewMac::SetWindowTextAndCaretPos(const std::wstring& text, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 void AutocompleteEditViewMac::OnDidResignKey() { | 542 void AutocompleteEditViewMac::OnDidResignKey() { |
| 543 ClosePopup(); | 543 ClosePopup(); |
| 544 } | 544 } |
| 545 | 545 |
| 546 void AutocompleteEditViewMac::AcceptInput( | 546 void AutocompleteEditViewMac::AcceptInput( |
| 547 WindowOpenDisposition disposition, bool for_drop) { | 547 WindowOpenDisposition disposition, bool for_drop) { |
| 548 model_->AcceptInput(disposition, for_drop); | 548 model_->AcceptInput(disposition, for_drop); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void AutocompleteEditViewMac::FocusLocation() { | 551 void AutocompleteEditViewMac::FocusLocation() { |
| 552 // -makeFirstResponder: will select the entire field_. If we're | 552 [[field_ window] makeFirstResponder:field_]; |
| 553 // already firstResponder, it's likely that we want to retain the | 553 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); |
| 554 // current selection. | |
| 555 if (![field_ currentEditor]) { | |
| 556 [[field_ window] makeFirstResponder:field_]; | |
| 557 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); | |
| 558 } | |
| 559 } | 554 } |
| 560 | 555 |
| 561 @implementation AutocompleteFieldDelegate | 556 @implementation AutocompleteFieldDelegate |
| 562 | 557 |
| 563 - initWithEditView:(AutocompleteEditViewMac*)view { | 558 - initWithEditView:(AutocompleteEditViewMac*)view { |
| 564 self = [super init]; | 559 self = [super init]; |
| 565 if (self) { | 560 if (self) { |
| 566 edit_view_ = view; | 561 edit_view_ = view; |
| 567 } | 562 } |
| 568 return self; | 563 return self; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 // TODO(shess): Figure out where the selection belongs. On GTK, | 622 // TODO(shess): Figure out where the selection belongs. On GTK, |
| 628 // it's set to the start of the text. | 623 // it's set to the start of the text. |
| 629 } | 624 } |
| 630 | 625 |
| 631 // Signal that we've lost focus when the window resigns key. | 626 // Signal that we've lost focus when the window resigns key. |
| 632 - (void)windowDidResignKey:(NSNotification*)notification { | 627 - (void)windowDidResignKey:(NSNotification*)notification { |
| 633 edit_view_->OnDidResignKey(); | 628 edit_view_->OnDidResignKey(); |
| 634 } | 629 } |
| 635 | 630 |
| 636 @end | 631 @end |
| OLD | NEW |