Chromium Code Reviews| 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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 | 494 |
| 495 bool handled; | 495 bool handled; |
| 496 if (decoration->AsButtonDecoration()) { | 496 if (decoration->AsButtonDecoration()) { |
| 497 ButtonDecoration* button = decoration->AsButtonDecoration(); | 497 ButtonDecoration* button = decoration->AsButtonDecoration(); |
| 498 | 498 |
| 499 button->SetButtonState(ButtonDecoration::kButtonStatePressed); | 499 button->SetButtonState(ButtonDecoration::kButtonStatePressed); |
| 500 [controlView setNeedsDisplay:YES]; | 500 [controlView setNeedsDisplay:YES]; |
| 501 | 501 |
| 502 // Track the mouse until the user releases the button. | 502 // Track the mouse until the user releases the button. |
| 503 [self trackMouse:theEvent | 503 [self trackMouse:theEvent |
| 504 inRect:cellFrame | 504 inRect:decorationRect |
| 505 ofView:controlView | 505 ofView:controlView |
| 506 untilMouseUp:YES]; | 506 untilMouseUp:YES]; |
| 507 | 507 |
| 508 const NSPoint mouseLocation = [[NSApp currentEvent] locationInWindow]; | |
| 509 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; | |
| 510 | |
| 508 // Post delayed focus notification, if necessary. | 511 // Post delayed focus notification, if necessary. |
| 509 if (focusEvent.get()) | 512 if (focusEvent.get() && !button->PreventFocus(point)) |
| 510 [self focusNotificationFor:focusEvent ofView:controlView]; | 513 [self focusNotificationFor:focusEvent ofView:controlView]; |
|
Scott Hess - ex-Googler
2014/05/08 23:00:47
I don't recall who originally wrote this code, but
groby-ooo-7-16
2014/05/08 23:14:07
The original writer would be me :)
focusEvent is
Scott Hess - ex-Googler
2014/05/08 23:21:36
Apologies, did not notice the missing _. In that
macourteau
2014/05/09 14:00:27
Done.
| |
| 511 | 514 |
| 512 // Set the proper state (hover or normal) once the mouse has been released, | 515 // Set the proper state (hover or normal) once the mouse has been released, |
| 513 // and call |OnMousePressed| if the button was released while the mouse was | 516 // and call |OnMousePressed| if the button was released while the mouse was |
| 514 // within the bounds of the button. | 517 // within the bounds of the button. |
| 515 const NSPoint mouseLocation = [[NSApp currentEvent] locationInWindow]; | |
| 516 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; | |
| 517 if (NSMouseInRect(point, decorationRect, [controlView isFlipped])) { | 518 if (NSMouseInRect(point, decorationRect, [controlView isFlipped])) { |
| 518 button->SetButtonState(ButtonDecoration::kButtonStateHover); | 519 button->SetButtonState(ButtonDecoration::kButtonStateHover); |
| 519 [controlView setNeedsDisplay:YES]; | 520 [controlView setNeedsDisplay:YES]; |
| 520 handled = decoration->AsButtonDecoration()->OnMousePressed( | 521 handled = decoration->OnMousePressed( |
| 521 [self frameForDecoration:decoration inFrame:cellFrame]); | 522 [self frameForDecoration:decoration inFrame:cellFrame], |
| 523 NSMakePoint(point.x - decorationRect.origin.x, | |
| 524 point.y - decorationRect.origin.y)); | |
| 522 } else { | 525 } else { |
| 523 button->SetButtonState(ButtonDecoration::kButtonStateNormal); | 526 button->SetButtonState(ButtonDecoration::kButtonStateNormal); |
| 524 [controlView setNeedsDisplay:YES]; | 527 [controlView setNeedsDisplay:YES]; |
| 525 handled = true; | 528 handled = true; |
| 526 } | 529 } |
| 527 } else { | 530 } else { |
| 528 handled = decoration->OnMousePressed(decorationRect); | 531 const NSPoint mouseLocation = [theEvent locationInWindow]; |
| 532 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; | |
| 533 handled = decoration->OnMousePressed( | |
| 534 decorationRect, | |
| 535 NSMakePoint(point.x - decorationRect.origin.x, | |
| 536 point.y - decorationRect.origin.y)); | |
| 529 } | 537 } |
| 530 | 538 |
| 531 return handled ? YES : NO; | 539 return handled ? YES : NO; |
| 532 } | 540 } |
| 533 | 541 |
| 534 // Helper method for the |mouseEntered:inView:| and |mouseExited:inView:| | 542 // Helper method for the |mouseEntered:inView:| and |mouseExited:inView:| |
| 535 // messages. Retrieves the |ButtonDecoration| for the specified event (received | 543 // messages. Retrieves the |ButtonDecoration| for the specified event (received |
| 536 // from a tracking area), and returns |NULL| if no decoration matches. | 544 // from a tracking area), and returns |NULL| if no decoration matches. |
| 537 - (ButtonDecoration*)getButtonDecorationForEvent:(NSEvent*)theEvent { | 545 - (ButtonDecoration*)getButtonDecorationForEvent:(NSEvent*)theEvent { |
| 538 ButtonDecoration* bd = static_cast<ButtonDecoration*>( | 546 ButtonDecoration* bd = static_cast<ButtonDecoration*>( |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 focusEvent_.reset([event retain]); | 863 focusEvent_.reset([event retain]); |
| 856 return; | 864 return; |
| 857 } | 865 } |
| 858 } | 866 } |
| 859 | 867 |
| 860 // Handle event immediately. | 868 // Handle event immediately. |
| 861 [self focusNotificationFor:event ofView:controlView]; | 869 [self focusNotificationFor:event ofView:controlView]; |
| 862 } | 870 } |
| 863 | 871 |
| 864 @end | 872 @end |
| OLD | NEW |