| 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 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 defer:YES]); | 310 defer:YES]); |
| 311 [popup_ setMovableByWindowBackground:NO]; | 311 [popup_ setMovableByWindowBackground:NO]; |
| 312 // The window shape is determined by the content view. | 312 // The window shape is determined by the content view. |
| 313 [popup_ setAlphaValue:1.0]; | 313 [popup_ setAlphaValue:1.0]; |
| 314 [popup_ setOpaque:YES]; | 314 [popup_ setOpaque:YES]; |
| 315 [popup_ setBackgroundColor:BackgroundColor()]; | 315 [popup_ setBackgroundColor:BackgroundColor()]; |
| 316 [popup_ setHasShadow:YES]; | 316 [popup_ setHasShadow:YES]; |
| 317 [popup_ setLevel:NSNormalWindowLevel]; | 317 [popup_ setLevel:NSNormalWindowLevel]; |
| 318 // Use a flipped view to pin the matrix top the top left. This is needed | 318 // Use a flipped view to pin the matrix top the top left. This is needed |
| 319 // for animated resize. | 319 // for animated resize. |
| 320 scoped_nsobject<FlippedView> contentView( | 320 base::scoped_nsobject<FlippedView> contentView( |
| 321 [[FlippedView alloc] initWithFrame:NSZeroRect]); | 321 [[FlippedView alloc] initWithFrame:NSZeroRect]); |
| 322 [popup_ setContentView:contentView]; | 322 [popup_ setContentView:contentView]; |
| 323 | 323 |
| 324 autocomplete_matrix_.reset( | 324 autocomplete_matrix_.reset( |
| 325 [[AutocompleteMatrix alloc] initWithPopupView:this]); | 325 [[AutocompleteMatrix alloc] initWithPopupView:this]); |
| 326 [contentView addSubview:autocomplete_matrix_]; | 326 [contentView addSubview:autocomplete_matrix_]; |
| 327 | 327 |
| 328 // TODO(dtseng): Ignore until we provide NSAccessibility support. | 328 // TODO(dtseng): Ignore until we provide NSAccessibility support. |
| 329 [popup_ accessibilitySetOverrideValue:NSAccessibilityUnknownRole | 329 [popup_ accessibilitySetOverrideValue:NSAccessibilityUnknownRole |
| 330 forAttribute:NSAccessibilityRoleAttribute]; | 330 forAttribute:NSAccessibilityRoleAttribute]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 359 [autocomplete_matrix_ setFrame:matrixFrame]; | 359 [autocomplete_matrix_ setFrame:matrixFrame]; |
| 360 | 360 |
| 361 NSRect currentPopupFrame = [popup_ frame]; | 361 NSRect currentPopupFrame = [popup_ frame]; |
| 362 targetPopupFrame_ = popupFrame; | 362 targetPopupFrame_ = popupFrame; |
| 363 | 363 |
| 364 // Animate the frame change if the only change is that the height got smaller. | 364 // Animate the frame change if the only change is that the height got smaller. |
| 365 // Otherwise, resize immediately. | 365 // Otherwise, resize immediately. |
| 366 bool animate = (NSHeight(popupFrame) < NSHeight(currentPopupFrame) && | 366 bool animate = (NSHeight(popupFrame) < NSHeight(currentPopupFrame) && |
| 367 NSWidth(popupFrame) == NSWidth(currentPopupFrame)); | 367 NSWidth(popupFrame) == NSWidth(currentPopupFrame)); |
| 368 | 368 |
| 369 scoped_nsobject<NSDictionary> savedAnimations; | 369 base::scoped_nsobject<NSDictionary> savedAnimations; |
| 370 if (!animate) { | 370 if (!animate) { |
| 371 // In an ideal world, running a zero-length animation would cancel any | 371 // In an ideal world, running a zero-length animation would cancel any |
| 372 // running animations and set the new frame value immediately. In practice, | 372 // running animations and set the new frame value immediately. In practice, |
| 373 // zero-length animations are ignored entirely. Work around this AppKit bug | 373 // zero-length animations are ignored entirely. Work around this AppKit bug |
| 374 // by explicitly setting an NSNull animation for the "frame" key and then | 374 // by explicitly setting an NSNull animation for the "frame" key and then |
| 375 // running the animation with a non-zero(!!) duration. This somehow | 375 // running the animation with a non-zero(!!) duration. This somehow |
| 376 // convinces AppKit to do the right thing. Save off the current animations | 376 // convinces AppKit to do the right thing. Save off the current animations |
| 377 // dictionary so it can be restored later. | 377 // dictionary so it can be restored later. |
| 378 savedAnimations.reset([[popup_ animations] copy]); | 378 savedAnimations.reset([[popup_ animations] copy]); |
| 379 [popup_ setAnimations: | 379 [popup_ setAnimations: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 [self removeTrackingArea:trackingArea]; | 576 [self removeTrackingArea:trackingArea]; |
| 577 } | 577 } |
| 578 | 578 |
| 579 // TODO(shess): Consider overriding -acceptsFirstMouse: and changing | 579 // TODO(shess): Consider overriding -acceptsFirstMouse: and changing |
| 580 // NSTrackingActiveInActiveApp to NSTrackingActiveAlways. | 580 // NSTrackingActiveInActiveApp to NSTrackingActiveAlways. |
| 581 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited; | 581 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited; |
| 582 options |= NSTrackingMouseMoved; | 582 options |= NSTrackingMouseMoved; |
| 583 options |= NSTrackingActiveInActiveApp; | 583 options |= NSTrackingActiveInActiveApp; |
| 584 options |= NSTrackingInVisibleRect; | 584 options |= NSTrackingInVisibleRect; |
| 585 | 585 |
| 586 scoped_nsobject<NSTrackingArea> trackingArea( | 586 base::scoped_nsobject<NSTrackingArea> trackingArea( |
| 587 [[NSTrackingArea alloc] initWithRect:[self frame] | 587 [[NSTrackingArea alloc] initWithRect:[self frame] |
| 588 options:options | 588 options:options |
| 589 owner:self | 589 owner:self |
| 590 userInfo:nil]); | 590 userInfo:nil]); |
| 591 [self addTrackingArea:trackingArea]; | 591 [self addTrackingArea:trackingArea]; |
| 592 } | 592 } |
| 593 | 593 |
| 594 - (void)updateTrackingAreas { | 594 - (void)updateTrackingAreas { |
| 595 [self resetTrackingArea]; | 595 [self resetTrackingArea]; |
| 596 [super updateTrackingAreas]; | 596 [super updateTrackingAreas]; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 const NSUInteger count = [cells count]; | 736 const NSUInteger count = [cells count]; |
| 737 for(NSUInteger i = 0; i < count; ++i) { | 737 for(NSUInteger i = 0; i < count; ++i) { |
| 738 if ([[cells objectAtIndex:i] isHighlighted]) { | 738 if ([[cells objectAtIndex:i] isHighlighted]) { |
| 739 return i; | 739 return i; |
| 740 } | 740 } |
| 741 } | 741 } |
| 742 return -1; | 742 return -1; |
| 743 } | 743 } |
| 744 | 744 |
| 745 @end | 745 @end |
| OLD | NEW |