| 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" |
| 11 #include "chrome/browser/cocoa/autocomplete_text_field.h" |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 | 13 |
| 13 // Focus-handling between |field_| and |model_| is a bit subtle. | 14 // Focus-handling between |field_| and |model_| is a bit subtle. |
| 14 // Other platforms detect change of focus, which is inconvenient | 15 // Other platforms detect change of focus, which is inconvenient |
| 15 // without subclassing NSTextField (even with a subclass, the use of a | 16 // without subclassing NSTextField (even with a subclass, the use of a |
| 16 // field editor may complicate things). | 17 // field editor may complicate things). |
| 17 // | 18 // |
| 18 // |model_| doesn't actually do anything when it gains focus, it just | 19 // |model_| doesn't actually do anything when it gains focus, it just |
| 19 // initializes. Visible activity happens only after the user edits. | 20 // initializes. Visible activity happens only after the user edits. |
| 20 // NSTextField delegate receives messages around starting and ending | 21 // NSTextField delegate receives messages around starting and ending |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // the edit view. | 119 // the edit view. |
| 119 | 120 |
| 120 @interface AutocompleteFieldDelegate : NSObject { | 121 @interface AutocompleteFieldDelegate : NSObject { |
| 121 @private | 122 @private |
| 122 AutocompleteEditViewMac* edit_view_; // weak, owns us. | 123 AutocompleteEditViewMac* edit_view_; // weak, owns us. |
| 123 } | 124 } |
| 124 - initWithEditView:(AutocompleteEditViewMac*)view; | 125 - initWithEditView:(AutocompleteEditViewMac*)view; |
| 125 - (void)windowDidResignKey:(NSNotification*)notification; | 126 - (void)windowDidResignKey:(NSNotification*)notification; |
| 126 @end | 127 @end |
| 127 | 128 |
| 129 // TODO(shess): AutocompletePopupViewMac doesn't really need an |
| 130 // NSTextField. It wants to know where the position the popup, what |
| 131 // font to use, and it also needs to be able to attach the popup to |
| 132 // the window |field_| is in. |
| 128 AutocompleteEditViewMac::AutocompleteEditViewMac( | 133 AutocompleteEditViewMac::AutocompleteEditViewMac( |
| 129 AutocompleteEditController* controller, | 134 AutocompleteEditController* controller, |
| 130 ToolbarModel* toolbar_model, | 135 ToolbarModel* toolbar_model, |
| 131 Profile* profile, | 136 Profile* profile, |
| 132 CommandUpdater* command_updater, | 137 CommandUpdater* command_updater, |
| 133 NSTextField* field) | 138 AutocompleteTextField* field) |
| 134 : model_(new AutocompleteEditModel(this, controller, profile)), | 139 : model_(new AutocompleteEditModel(this, controller, profile)), |
| 135 popup_view_(new AutocompletePopupViewMac(this, model_.get(), profile, | 140 popup_view_(new AutocompletePopupViewMac(this, model_.get(), profile, |
| 136 field)), | 141 field)), |
| 137 controller_(controller), | 142 controller_(controller), |
| 138 toolbar_model_(toolbar_model), | 143 toolbar_model_(toolbar_model), |
| 139 command_updater_(command_updater), | 144 command_updater_(command_updater), |
| 140 field_(field), | 145 field_(field), |
| 141 edit_helper_([[AutocompleteFieldDelegate alloc] initWithEditView:this]) { | 146 edit_helper_([[AutocompleteFieldDelegate alloc] initWithEditView:this]) { |
| 142 DCHECK(controller); | 147 DCHECK(controller); |
| 143 DCHECK(toolbar_model); | 148 DCHECK(toolbar_model); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 // We should only arrive here when the field is focussed. | 520 // We should only arrive here when the field is focussed. |
| 516 DCHECK(IsFirstResponder()); | 521 DCHECK(IsFirstResponder()); |
| 517 | 522 |
| 518 model_->OnEscapeKeyPressed(); | 523 model_->OnEscapeKeyPressed(); |
| 519 } | 524 } |
| 520 | 525 |
| 521 void AutocompleteEditViewMac::OnWillBeginEditing() { | 526 void AutocompleteEditViewMac::OnWillBeginEditing() { |
| 522 // We should only arrive here when the field is focussed. | 527 // We should only arrive here when the field is focussed. |
| 523 DCHECK([field_ currentEditor]); | 528 DCHECK([field_ currentEditor]); |
| 524 | 529 |
| 525 // TODO(shess): Having the control key depressed changes the desired | 530 // TODO(shess): Detect control-key situation. Since this code is |
| 526 // TLD for autocomplete, which changes the results. Not sure if we | 531 // called on first edit, not on receipt of focus, it may be that we |
| 527 // can detect that without subclassing NSTextField. | 532 // cannot correctly handle this without refactoring. |
| 528 const bool controlDown = false; | 533 const bool controlDown = false; |
| 529 model_->OnSetFocus(controlDown); | 534 model_->OnSetFocus(controlDown); |
| 530 | 535 |
| 531 // Capture the current state. | 536 // Capture the current state. |
| 532 OnBeforePossibleChange(); | 537 OnBeforePossibleChange(); |
| 533 } | 538 } |
| 534 | 539 |
| 535 void AutocompleteEditViewMac::OnDidEndEditing() { | 540 void AutocompleteEditViewMac::OnDidEndEditing() { |
| 536 ClosePopup(); | 541 ClosePopup(); |
| 537 | 542 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 // TODO(shess): Figure out where the selection belongs. On GTK, | 627 // TODO(shess): Figure out where the selection belongs. On GTK, |
| 623 // it's set to the start of the text. | 628 // it's set to the start of the text. |
| 624 } | 629 } |
| 625 | 630 |
| 626 // Signal that we've lost focus when the window resigns key. | 631 // Signal that we've lost focus when the window resigns key. |
| 627 - (void)windowDidResignKey:(NSNotification*)notification { | 632 - (void)windowDidResignKey:(NSNotification*)notification { |
| 628 edit_view_->OnDidResignKey(); | 633 edit_view_->OnDidResignKey(); |
| 629 } | 634 } |
| 630 | 635 |
| 631 @end | 636 @end |
| OLD | NEW |