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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 - (BOOL)acceptsFirstResponder { | 390 - (BOOL)acceptsFirstResponder { |
391 if ([self currentEditor]) { | 391 if ([self currentEditor]) { |
392 DCHECK_EQ([self currentEditor], [[self window] firstResponder]); | 392 DCHECK_EQ([self currentEditor], [[self window] firstResponder]); |
393 return NO; | 393 return NO; |
394 } | 394 } |
395 return [super acceptsFirstResponder]; | 395 return [super acceptsFirstResponder]; |
396 } | 396 } |
397 | 397 |
398 // (Overridden from NSResponder) | 398 // (Overridden from NSResponder) |
399 - (BOOL)becomeFirstResponder { | 399 - (BOOL)becomeFirstResponder { |
| 400 // If the event is a left-mouse click, and it lands on a decoration, then the |
| 401 // event should not cause the text field to become first responder. |
| 402 NSEvent* event = [NSApp currentEvent]; |
| 403 if ([event type] == NSLeftMouseDown) { |
| 404 LocationBarDecoration* decoration = |
| 405 [[self cell] decorationForEvent:event inRect:[self bounds] ofView:self]; |
| 406 if (decoration) |
| 407 return NO; |
| 408 } |
| 409 |
400 BOOL doAccept = [super becomeFirstResponder]; | 410 BOOL doAccept = [super becomeFirstResponder]; |
401 if (doAccept) { | 411 if (doAccept) { |
402 [[BrowserWindowController browserWindowControllerForView:self] | 412 [[BrowserWindowController browserWindowControllerForView:self] |
403 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 413 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
404 | 414 |
405 // Tells the observer that we get the focus. | 415 // Tells the observer that we get the focus. |
406 // But we can't call observer_->OnKillFocus() in resignFirstResponder:, | 416 // But we can't call observer_->OnKillFocus() in resignFirstResponder:, |
407 // because the first responder will be immediately set to the field editor | 417 // because the first responder will be immediately set to the field editor |
408 // when calling [super becomeFirstResponder], thus we won't receive | 418 // when calling [super becomeFirstResponder], thus we won't receive |
409 // resignFirstResponder: anymore when losing focus. | 419 // resignFirstResponder: anymore when losing focus. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 NSMinY(frame), | 516 NSMinY(frame), |
507 suggestWidth, | 517 suggestWidth, |
508 NSHeight(frame)); | 518 NSHeight(frame)); |
509 | 519 |
510 gfx::ScopedNSGraphicsContextSaveGState saveGState; | 520 gfx::ScopedNSGraphicsContextSaveGState saveGState; |
511 NSRectClip(suggestRect); | 521 NSRectClip(suggestRect); |
512 [cell drawInteriorWithFrame:frame inView:controlView]; | 522 [cell drawInteriorWithFrame:frame inView:controlView]; |
513 } | 523 } |
514 | 524 |
515 } // namespace autocomplete_text_field | 525 } // namespace autocomplete_text_field |
OLD | NEW |