| 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/clipboard.h" | 7 #include "base/clipboard.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 DCHECK(field); | 154 DCHECK(field); |
| 155 [field_ setDelegate:edit_helper_]; | 155 [field_ setDelegate:edit_helper_]; |
| 156 | 156 |
| 157 // Needed so that editing doesn't lose the styling. | 157 // Needed so that editing doesn't lose the styling. |
| 158 [field_ setAllowsEditingTextAttributes:YES]; | 158 [field_ setAllowsEditingTextAttributes:YES]; |
| 159 | 159 |
| 160 // Track the window's key status for signalling focus changes to | 160 // Track the window's key status for signalling focus changes to |
| 161 // |model_|. | 161 // |model_|. |
| 162 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 162 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 163 [nc addObserver:edit_helper_ | 163 [nc addObserver:edit_helper_ |
| 164 selector:@selector(windowDidResignKey:) | 164 selector:@selector(windowDidResignKey:) |
| 165 name:NSWindowDidResignKeyNotification | 165 name:NSWindowDidResignKeyNotification |
| 166 object:[field_ window]]; | 166 object:[field_ window]]; |
| 167 } | 167 } |
| 168 | 168 |
| 169 AutocompleteEditViewMac::~AutocompleteEditViewMac() { | 169 AutocompleteEditViewMac::~AutocompleteEditViewMac() { |
| 170 // TODO(shess): Having to be aware of destructor ordering in this | 170 // TODO(shess): Having to be aware of destructor ordering in this |
| 171 // way seems brittle. There must be a better way. | 171 // way seems brittle. There must be a better way. |
| 172 | 172 |
| 173 // Destroy popup view before this object in case it tries to call us | 173 // Destroy popup view before this object in case it tries to call us |
| 174 // back in the destructor. Likewise for destroying the model before | 174 // back in the destructor. Likewise for destroying the model before |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // shouldn't need to be called at all. When coded that way, I find | 209 // shouldn't need to be called at all. When coded that way, I find |
| 210 // that the field isn't always updated correctly. Figure out why | 210 // that the field isn't always updated correctly. Figure out why |
| 211 // this is. Maybe this method should be refactored into more | 211 // this is. Maybe this method should be refactored into more |
| 212 // specific cases. | 212 // specific cases. |
| 213 const bool user_visible = | 213 const bool user_visible = |
| 214 model_->UpdatePermanentText(toolbar_model_->GetText()); | 214 model_->UpdatePermanentText(toolbar_model_->GetText()); |
| 215 | 215 |
| 216 if (tab_for_state_restoring) { | 216 if (tab_for_state_restoring) { |
| 217 RevertAll(); | 217 RevertAll(); |
| 218 | 218 |
| 219 const AutocompleteEditViewMacState* state = | 219 const AutocompleteEditViewMacState* state = |
| 220 GetStateFromTab(tab_for_state_restoring); | 220 GetStateFromTab(tab_for_state_restoring); |
| 221 if (state) { | 221 if (state) { |
| 222 // Should restore the user's text via SetUserText(). | 222 // Should restore the user's text via SetUserText(). |
| 223 model_->RestoreState(state->model_state); | 223 model_->RestoreState(state->model_state); |
| 224 | 224 |
| 225 // Restore focus and selection if they were present when the tab | 225 // Restore focus and selection if they were present when the tab |
| 226 // was switched away. | 226 // was switched away. |
| 227 if (state->has_focus) { | 227 if (state->has_focus) { |
| 228 // TODO(shess): Unfortunately, there is no safe way to update | 228 // TODO(shess): Unfortunately, there is no safe way to update |
| 229 // this because TabStripController -selectTabWithContents:* is | 229 // this because TabStripController -selectTabWithContents:* is |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // Restyle in case the user changed something. | 504 // Restyle in case the user changed something. |
| 505 // TODO(shess): I believe there are multiple-redraw cases, here. | 505 // TODO(shess): I believe there are multiple-redraw cases, here. |
| 506 // Linux watches for something_changed && text_differs, but that | 506 // Linux watches for something_changed && text_differs, but that |
| 507 // fails for us in case you copy the URL and paste the identical URL | 507 // fails for us in case you copy the URL and paste the identical URL |
| 508 // back (we'll lose the styling). | 508 // back (we'll lose the styling). |
| 509 EmphasizeURLComponents(); | 509 EmphasizeURLComponents(); |
| 510 | 510 |
| 511 return something_changed; | 511 return something_changed; |
| 512 } | 512 } |
| 513 | 513 |
| 514 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const { |
| 515 return field_; |
| 516 } |
| 517 |
| 514 void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) { | 518 void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) { |
| 515 // We should only arrive here when the field is focussed. | 519 // We should only arrive here when the field is focussed. |
| 516 DCHECK(IsFirstResponder()); | 520 DCHECK(IsFirstResponder()); |
| 517 | 521 |
| 518 const int count = by_page ? model_->result().size() : 1; | 522 const int count = by_page ? model_->result().size() : 1; |
| 519 model_->OnUpOrDownKeyPressed(up ? -count : count); | 523 model_->OnUpOrDownKeyPressed(up ? -count : count); |
| 520 } | 524 } |
| 521 | 525 |
| 522 void AutocompleteEditViewMac::OnEscapeKeyPressed() { | 526 void AutocompleteEditViewMac::OnEscapeKeyPressed() { |
| 523 // We should only arrive here when the field is focussed. | 527 // We should only arrive here when the field is focussed. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 if (cmd == @selector(moveDown:)) { | 658 if (cmd == @selector(moveDown:)) { |
| 655 edit_view_->OnUpOrDownKeyPressed(false, false); | 659 edit_view_->OnUpOrDownKeyPressed(false, false); |
| 656 return YES; | 660 return YES; |
| 657 } | 661 } |
| 658 | 662 |
| 659 if (cmd == @selector(moveUp:)) { | 663 if (cmd == @selector(moveUp:)) { |
| 660 edit_view_->OnUpOrDownKeyPressed(true, false); | 664 edit_view_->OnUpOrDownKeyPressed(true, false); |
| 661 return YES; | 665 return YES; |
| 662 } | 666 } |
| 663 } | 667 } |
| 664 | 668 |
| 665 if (cmd == @selector(scrollPageDown:)) { | 669 if (cmd == @selector(scrollPageDown:)) { |
| 666 edit_view_->OnUpOrDownKeyPressed(false, true); | 670 edit_view_->OnUpOrDownKeyPressed(false, true); |
| 667 return YES; | 671 return YES; |
| 668 } | 672 } |
| 669 | 673 |
| 670 if (cmd == @selector(scrollPageUp:)) { | 674 if (cmd == @selector(scrollPageUp:)) { |
| 671 edit_view_->OnUpOrDownKeyPressed(true, true); | 675 edit_view_->OnUpOrDownKeyPressed(true, true); |
| 672 return YES; | 676 return YES; |
| 673 } | 677 } |
| 674 | 678 |
| 675 if (cmd == @selector(cancelOperation:)) { | 679 if (cmd == @selector(cancelOperation:)) { |
| 676 edit_view_->OnEscapeKeyPressed(); | 680 edit_view_->OnEscapeKeyPressed(); |
| 677 return YES; | 681 return YES; |
| 678 } | 682 } |
| 679 | 683 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 // prepended and ".com" appended. This calls down to | 745 // prepended and ".com" appended. This calls down to |
| 742 // AutocompleteEditModel::OnControlKeyChanged() so that it can change | 746 // AutocompleteEditModel::OnControlKeyChanged() so that it can change |
| 743 // the popup to reflect this. See autocomplete_edit.cc | 747 // the popup to reflect this. See autocomplete_edit.cc |
| 744 // OnControlKeyChanged() and OnAfterPossibleChange(). | 748 // OnControlKeyChanged() and OnAfterPossibleChange(). |
| 745 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { | 749 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { |
| 746 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; | 750 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; |
| 747 edit_view_->OnControlKeyChanged(controlFlag); | 751 edit_view_->OnControlKeyChanged(controlFlag); |
| 748 } | 752 } |
| 749 | 753 |
| 750 @end | 754 @end |
| OLD | NEW |