OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_cell.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #include "base/mac/mac_logging.h" | 9 #include "base/mac/mac_logging.h" |
10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 std::reverse(decorations->begin() + left_count, decorations->end()); | 158 std::reverse(decorations->begin() + left_count, decorations->end()); |
159 std::reverse(decoration_frames->begin() + left_count, | 159 std::reverse(decoration_frames->begin() + left_count, |
160 decoration_frames->end()); | 160 decoration_frames->end()); |
161 | 161 |
162 *remaining_frame = frame; | 162 *remaining_frame = frame; |
163 return left_count; | 163 return left_count; |
164 } | 164 } |
165 | 165 |
166 } // namespace | 166 } // namespace |
167 | 167 |
168 @interface AutocompleteTextFieldCell () | |
169 // Post an OnSetFocus notification to the observer of |controlView|. | |
170 - (void)focusNotificationFor:(NSEvent*)event | |
171 ofView:(AutocompleteTextField*)controlView; | |
172 @end | |
173 | |
168 @implementation AutocompleteTextFieldCell | 174 @implementation AutocompleteTextFieldCell |
169 | 175 |
170 @synthesize isPopupMode = isPopupMode_; | 176 @synthesize isPopupMode = isPopupMode_; |
171 | 177 |
172 - (CGFloat)topTextFrameOffset { | 178 - (CGFloat)topTextFrameOffset { |
173 return 3.0; | 179 return 3.0; |
174 } | 180 } |
175 | 181 |
176 - (CGFloat)bottomTextFrameOffset { | 182 - (CGFloat)bottomTextFrameOffset { |
177 return 3.0; | 183 return 3.0; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 LocationBarDecoration* decoration = | 410 LocationBarDecoration* decoration = |
405 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView]; | 411 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView]; |
406 if (decoration) | 412 if (decoration) |
407 return decoration->GetMenu(); | 413 return decoration->GetMenu(); |
408 return nil; | 414 return nil; |
409 } | 415 } |
410 | 416 |
411 - (BOOL)mouseDown:(NSEvent*)theEvent | 417 - (BOOL)mouseDown:(NSEvent*)theEvent |
412 inRect:(NSRect)cellFrame | 418 inRect:(NSRect)cellFrame |
413 ofView:(AutocompleteTextField*)controlView { | 419 ofView:(AutocompleteTextField*)controlView { |
420 // Check if this mouseDown was the reason the control became firstResponder. | |
421 // If not, discard focus event. | |
422 base::scoped_nsobject<NSEvent> focusEvent(focusEvent_.release()); | |
423 if (![theEvent isEqual:focusEvent_]) | |
Scott Hess - ex-Googler
2014/02/27 21:09:36
focusEvent (no _), focusEvent_ is nil.
| |
424 focusEvent.reset(); | |
425 | |
414 LocationBarDecoration* decoration = | 426 LocationBarDecoration* decoration = |
415 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView]; | 427 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView]; |
416 if (!decoration || !decoration->AcceptsMousePress()) | 428 if (!decoration || !decoration->AcceptsMousePress()) |
417 return NO; | 429 return NO; |
418 | 430 |
419 NSRect decorationRect = | 431 NSRect decorationRect = |
420 [self frameForDecoration:decoration inFrame:cellFrame]; | 432 [self frameForDecoration:decoration inFrame:cellFrame]; |
421 | 433 |
422 // If the decoration is draggable, then initiate a drag if the user | 434 // If the decoration is draggable, then initiate a drag if the user |
423 // drags or holds the mouse down for awhile. | 435 // drags or holds the mouse down for awhile. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 | 486 |
475 button->SetButtonState(ButtonDecoration::kButtonStatePressed); | 487 button->SetButtonState(ButtonDecoration::kButtonStatePressed); |
476 [controlView setNeedsDisplay:YES]; | 488 [controlView setNeedsDisplay:YES]; |
477 | 489 |
478 // Track the mouse until the user releases the button. | 490 // Track the mouse until the user releases the button. |
479 [self trackMouse:theEvent | 491 [self trackMouse:theEvent |
480 inRect:cellFrame | 492 inRect:cellFrame |
481 ofView:controlView | 493 ofView:controlView |
482 untilMouseUp:YES]; | 494 untilMouseUp:YES]; |
483 | 495 |
496 // Post delayed focus notification, if necessary. | |
497 [self focusNotificationFor:focusEvent ofView:controlView]; | |
Scott Hess - ex-Googler
2014/02/27 21:09:36
Yeah, I think so. Nothing has occurred to me abou
groby-ooo-7-16
2014/02/27 23:15:27
Well, we need to accept firstResponder for the top
| |
498 | |
484 // Set the proper state (hover or normal) once the mouse has been released, | 499 // Set the proper state (hover or normal) once the mouse has been released, |
485 // and call |OnMousePressed| if the button was released while the mouse was | 500 // and call |OnMousePressed| if the button was released while the mouse was |
486 // within the bounds of the button. | 501 // within the bounds of the button. |
487 const NSPoint mouseLocation = | 502 const NSPoint mouseLocation = |
488 [[controlView window] mouseLocationOutsideOfEventStream]; | 503 [[controlView window] mouseLocationOutsideOfEventStream]; |
489 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; | 504 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; |
490 if (NSMouseInRect(point, cellFrame, [controlView isFlipped])) { | 505 if (NSMouseInRect(point, cellFrame, [controlView isFlipped])) { |
491 button->SetButtonState(ButtonDecoration::kButtonStateHover); | 506 button->SetButtonState(ButtonDecoration::kButtonStateHover); |
492 [controlView setNeedsDisplay:YES]; | 507 [controlView setNeedsDisplay:YES]; |
493 handled = decoration->AsButtonDecoration()->OnMousePressed( | 508 handled = decoration->AsButtonDecoration()->OnMousePressed( |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 [controlView setNeedsDisplay:YES]; | 815 [controlView setNeedsDisplay:YES]; |
801 NSTextView* fieldEditor = | 816 NSTextView* fieldEditor = |
802 base::mac::ObjCCastStrict<NSTextView>([controlView currentEditor]); | 817 base::mac::ObjCCastStrict<NSTextView>([controlView currentEditor]); |
803 [fieldEditor updateInsertionPointStateAndRestartTimer:YES]; | 818 [fieldEditor updateInsertionPointStateAndRestartTimer:YES]; |
804 } | 819 } |
805 | 820 |
806 - (BOOL)showsFirstResponder { | 821 - (BOOL)showsFirstResponder { |
807 return [super showsFirstResponder] && !hideFocusState_; | 822 return [super showsFirstResponder] && !hideFocusState_; |
808 } | 823 } |
809 | 824 |
825 - (void)focusNotificationFor:(NSEvent*)event | |
826 ofView:(AutocompleteTextField*)controlView { | |
827 if ([controlView observer] && event) { | |
828 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; | |
829 [controlView observer]->OnSetFocus(controlDown); | |
830 } | |
831 } | |
Scott Hess - ex-Googler
2014/02/27 21:09:36
I can't tell if the following is clearer or not, s
groby-ooo-7-16
2014/02/27 23:15:27
Except this is only called from button decorations
| |
832 | |
833 - (void)handleFocusEvent:(NSEvent*)event | |
834 ofView:(AutocompleteTextField*)controlView { | |
835 // Only intercept left button click. All other events cause immediate focus. | |
836 if ([event type] == NSLeftMouseDown) { | |
837 LocationBarDecoration* decoration = | |
838 [self decorationForEvent:event | |
839 inRect:[controlView bounds] | |
840 ofView:controlView]; | |
841 // Only ButtonDecorations need a delayed focus handling. | |
842 if (decoration && decoration->AsButtonDecoration()) { | |
843 focusEvent_.reset([event retain]); | |
844 return; | |
845 } | |
846 } | |
847 | |
848 // Handle event immediately. | |
849 [self focusNotificationFor:event ofView:controlView]; | |
850 } | |
851 | |
810 @end | 852 @end |
OLD | NEW |