Chromium Code Reviews| 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 #include "base/mac/foundation_util.h" | |
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 9 #import "chrome/browser/ui/cocoa/browser_window_controller.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_cell.h" |
| 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 11 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 12 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 13 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/url_drop_target.h" | 14 #import "chrome/browser/ui/cocoa/url_drop_target.h" |
| 14 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 16 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 [editor selectAll:nil]; | 144 [editor selectAll:nil]; |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 return; | 148 return; |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Give the cell a chance to intercept clicks in page-actions and | 151 // Give the cell a chance to intercept clicks in page-actions and |
| 151 // other decorative items. | 152 // other decorative items. |
| 152 if ([cell mouseDown:theEvent inRect:bounds ofView:self]) { | 153 if ([cell mouseDown:theEvent inRect:bounds ofView:self]) { |
| 154 // If a decoration intercepted the click, then the text field should resign | |
| 155 // first responder. | |
|
Scott Hess - ex-Googler
2015/05/08 19:38:28
This doesn't seem right for the case where the fie
erikchen
2015/05/08 20:02:20
Why not? That's the behavior on Windows. Try this
Scott Hess - ex-Googler
2015/05/08 20:34:28
You didn't mention platform. On OSX with the late
erikchen
2015/05/09 01:09:37
Hm, you're right. I've removed this logic.
| |
| 156 NSView* firstResponder = | |
| 157 base::mac::ObjCCast<NSView>([[self window] firstResponder]); | |
| 158 if ([firstResponder isDescendantOf:self]) | |
| 159 [[self window] makeFirstResponder:nil]; | |
| 153 return; | 160 return; |
| 154 } | 161 } |
| 155 | 162 |
| 156 NSText* editor = [self currentEditor]; | 163 NSText* editor = [self currentEditor]; |
| 157 | 164 |
| 158 // We should only be here if we accepted first-responder status and | 165 // We should only be here if we accepted first-responder status and |
| 159 // have a field editor. If one of these fires, it means some | 166 // have a field editor. If one of these fires, it means some |
| 160 // assumptions are being broken. | 167 // assumptions are being broken. |
| 161 DCHECK(editor != nil); | 168 DCHECK(editor != nil); |
| 162 DCHECK([editor isDescendantOf:self]); | 169 DCHECK([editor isDescendantOf:self]); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 // causes a select-all, even if the decoration handles the click. If | 392 // 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 | 393 // 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 | 394 // again. This allows the selection to be unmodified if the click is |
| 388 // handled by a decoration or context menu (|-mouseDown:| will still | 395 // handled by a decoration or context menu (|-mouseDown:| will still |
| 389 // change it if appropriate). | 396 // change it if appropriate). |
| 390 - (BOOL)acceptsFirstResponder { | 397 - (BOOL)acceptsFirstResponder { |
| 391 if ([self currentEditor]) { | 398 if ([self currentEditor]) { |
| 392 DCHECK_EQ([self currentEditor], [[self window] firstResponder]); | 399 DCHECK_EQ([self currentEditor], [[self window] firstResponder]); |
| 393 return NO; | 400 return NO; |
| 394 } | 401 } |
| 402 | |
| 403 // If the event is a left-mouse click, and it lands on a decoration, then the | |
| 404 // event should not cause the text field to become first responder. | |
| 405 NSEvent* event = [NSApp currentEvent]; | |
| 406 if ([event type] == NSLeftMouseDown) { | |
| 407 LocationBarDecoration* decoration = | |
| 408 [[self cell] decorationForEvent:event inRect:[self bounds] ofView:self]; | |
| 409 if (decoration and decoration->AcceptsMousePress()) | |
|
Scott Hess - ex-Googler
2015/05/08 19:38:28
gah! "and"?
erikchen
2015/05/08 20:02:20
I don't even. Fixed.
| |
| 410 return NO; | |
| 411 } | |
| 412 | |
| 395 return [super acceptsFirstResponder]; | 413 return [super acceptsFirstResponder]; |
| 396 } | 414 } |
| 397 | 415 |
| 398 // (Overridden from NSResponder) | 416 // (Overridden from NSResponder) |
| 399 - (BOOL)becomeFirstResponder { | 417 - (BOOL)becomeFirstResponder { |
| 400 BOOL doAccept = [super becomeFirstResponder]; | 418 BOOL doAccept = [super becomeFirstResponder]; |
| 401 if (doAccept) { | 419 if (doAccept) { |
| 402 [[BrowserWindowController browserWindowControllerForView:self] | 420 [[BrowserWindowController browserWindowControllerForView:self] |
| 403 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 421 lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
| 404 | 422 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 NSMinY(frame), | 524 NSMinY(frame), |
| 507 suggestWidth, | 525 suggestWidth, |
| 508 NSHeight(frame)); | 526 NSHeight(frame)); |
| 509 | 527 |
| 510 gfx::ScopedNSGraphicsContextSaveGState saveGState; | 528 gfx::ScopedNSGraphicsContextSaveGState saveGState; |
| 511 NSRectClip(suggestRect); | 529 NSRectClip(suggestRect); |
| 512 [cell drawInteriorWithFrame:frame inView:controlView]; | 530 [cell drawInteriorWithFrame:frame inView:controlView]; |
| 513 } | 531 } |
| 514 | 532 |
| 515 } // namespace autocomplete_text_field | 533 } // namespace autocomplete_text_field |
| OLD | NEW |