| 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 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // field editor area, and if so sets the selection to {0,0} to clear | 72 // field editor area, and if so sets the selection to {0,0} to clear |
| 73 // the selection before forwarding the event to the field editor for | 73 // the selection before forwarding the event to the field editor for |
| 74 // processing (it will set the cursor position). This also starts the | 74 // processing (it will set the cursor position). This also starts the |
| 75 // click-drag selection machinery. | 75 // click-drag selection machinery. |
| 76 // | 76 // |
| 77 // This code does the same thing for cases where the click was in the | 77 // This code does the same thing for cases where the click was in the |
| 78 // decoration area. This allows the user to click-drag starting from | 78 // decoration area. This allows the user to click-drag starting from |
| 79 // a decoration area and get the expected selection behaviour, | 79 // a decoration area and get the expected selection behaviour, |
| 80 // likewise for multiple clicks in those areas. | 80 // likewise for multiple clicks in those areas. |
| 81 - (void)mouseDown:(NSEvent*)theEvent { | 81 - (void)mouseDown:(NSEvent*)theEvent { |
| 82 // TODO(groby): Figure out if OnMouseDown needs to be postponed/skipped |
| 83 // for button decorations. |
| 82 if (observer_) | 84 if (observer_) |
| 83 observer_->OnMouseDown([theEvent buttonNumber]); | 85 observer_->OnMouseDown([theEvent buttonNumber]); |
| 84 | 86 |
| 85 // If the click was a Control-click, bring up the context menu. | 87 // If the click was a Control-click, bring up the context menu. |
| 86 // |NSTextField| handles these cases inconsistently if the field is | 88 // |NSTextField| handles these cases inconsistently if the field is |
| 87 // not already first responder. | 89 // not already first responder. |
| 88 if (([theEvent modifierFlags] & NSControlKeyMask) != 0) { | 90 if (([theEvent modifierFlags] & NSControlKeyMask) != 0) { |
| 89 NSText* editor = [self currentEditor]; | 91 NSText* editor = [self currentEditor]; |
| 90 NSMenu* menu = [editor menuForEvent:theEvent]; | 92 NSMenu* menu = [editor menuForEvent:theEvent]; |
| 91 [NSMenu popUpContextMenu:menu withEvent:theEvent forView:editor]; | 93 [NSMenu popUpContextMenu:menu withEvent:theEvent forView:editor]; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 BOOL doAccept = [super becomeFirstResponder]; | 363 BOOL doAccept = [super becomeFirstResponder]; |
| 362 if (doAccept) { | 364 if (doAccept) { |
| 363 [[BrowserWindowController browserWindowControllerForView:self] | 365 [[BrowserWindowController browserWindowControllerForView:self] |
| 364 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 366 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
| 365 | 367 |
| 366 // Tells the observer that we get the focus. | 368 // Tells the observer that we get the focus. |
| 367 // But we can't call observer_->OnKillFocus() in resignFirstResponder:, | 369 // But we can't call observer_->OnKillFocus() in resignFirstResponder:, |
| 368 // because the first responder will be immediately set to the field editor | 370 // because the first responder will be immediately set to the field editor |
| 369 // when calling [super becomeFirstResponder], thus we won't receive | 371 // when calling [super becomeFirstResponder], thus we won't receive |
| 370 // resignFirstResponder: anymore when losing focus. | 372 // resignFirstResponder: anymore when losing focus. |
| 371 if (observer_) { | 373 [[self cell] handleFocusEvent:[NSApp currentEvent] ofView:self]; |
| 372 NSEvent* theEvent = [NSApp currentEvent]; | |
| 373 const bool controlDown = ([theEvent modifierFlags]&NSControlKeyMask) != 0; | |
| 374 observer_->OnSetFocus(controlDown); | |
| 375 } | |
| 376 } | 374 } |
| 377 return doAccept; | 375 return doAccept; |
| 378 } | 376 } |
| 379 | 377 |
| 380 // (Overridden from NSResponder) | 378 // (Overridden from NSResponder) |
| 381 - (BOOL)resignFirstResponder { | 379 - (BOOL)resignFirstResponder { |
| 382 BOOL doResign = [super resignFirstResponder]; | 380 BOOL doResign = [super resignFirstResponder]; |
| 383 if (doResign) { | 381 if (doResign) { |
| 384 [[BrowserWindowController browserWindowControllerForView:self] | 382 [[BrowserWindowController browserWindowControllerForView:self] |
| 385 releaseBarVisibilityForOwner:self withAnimation:YES delay:YES]; | 383 releaseBarVisibilityForOwner:self withAnimation:YES delay:YES]; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 NSMinY(frame), | 469 NSMinY(frame), |
| 472 suggestWidth, | 470 suggestWidth, |
| 473 NSHeight(frame)); | 471 NSHeight(frame)); |
| 474 | 472 |
| 475 gfx::ScopedNSGraphicsContextSaveGState saveGState; | 473 gfx::ScopedNSGraphicsContextSaveGState saveGState; |
| 476 NSRectClip(suggestRect); | 474 NSRectClip(suggestRect); |
| 477 [cell drawInteriorWithFrame:frame inView:controlView]; | 475 [cell drawInteriorWithFrame:frame inView:controlView]; |
| 478 } | 476 } |
| 479 | 477 |
| 480 } // namespace autocomplete_text_field | 478 } // namespace autocomplete_text_field |
| OLD | NEW |