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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // causes a select-all, even if the decoration handles the click. If | 385 // causes a select-all, even if the decoration handles the click. If |
386 // the field editor is already in place, don't accept first responder | 386 // the field editor is already in place, don't accept first responder |
387 // again. This allows the selection to be unmodified if the click is | 387 // again. This allows the selection to be unmodified if the click is |
388 // handled by a decoration or context menu (|-mouseDown:| will still | 388 // handled by a decoration or context menu (|-mouseDown:| will still |
389 // change it if appropriate). | 389 // change it if appropriate). |
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 |
| 396 // If the event is a left-mouse click, and it lands on a decoration, then the |
| 397 // event should not cause the text field to become first responder. |
| 398 NSEvent* event = [NSApp currentEvent]; |
| 399 if ([event type] == NSLeftMouseDown) { |
| 400 LocationBarDecoration* decoration = |
| 401 [[self cell] decorationForEvent:event inRect:[self bounds] ofView:self]; |
| 402 if (decoration && decoration->AcceptsMousePress()) |
| 403 return NO; |
| 404 } |
| 405 |
395 return [super acceptsFirstResponder]; | 406 return [super acceptsFirstResponder]; |
396 } | 407 } |
397 | 408 |
398 // (Overridden from NSResponder) | 409 // (Overridden from NSResponder) |
399 - (BOOL)becomeFirstResponder { | 410 - (BOOL)becomeFirstResponder { |
400 BOOL doAccept = [super becomeFirstResponder]; | 411 BOOL doAccept = [super becomeFirstResponder]; |
401 if (doAccept) { | 412 if (doAccept) { |
402 [[BrowserWindowController browserWindowControllerForView:self] | 413 [[BrowserWindowController browserWindowControllerForView:self] |
403 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 414 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
404 | 415 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 NSMinY(frame), | 517 NSMinY(frame), |
507 suggestWidth, | 518 suggestWidth, |
508 NSHeight(frame)); | 519 NSHeight(frame)); |
509 | 520 |
510 gfx::ScopedNSGraphicsContextSaveGState saveGState; | 521 gfx::ScopedNSGraphicsContextSaveGState saveGState; |
511 NSRectClip(suggestRect); | 522 NSRectClip(suggestRect); |
512 [cell drawInteriorWithFrame:frame inView:controlView]; | 523 [cell drawInteriorWithFrame:frame inView:controlView]; |
513 } | 524 } |
514 | 525 |
515 } // namespace autocomplete_text_field | 526 } // namespace autocomplete_text_field |
OLD | NEW |