| 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/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #import "base/mac/sdk_forward_declarations.h" |
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "chrome/browser/search/search.h" | 13 #include "chrome/browser/search/search.h" |
| 13 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" | 15 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
| 15 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_separator_view.h" | 16 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_separator_view.h" |
| 16 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 17 #include "components/omnibox/browser/autocomplete_match.h" | 18 #include "components/omnibox/browser/autocomplete_match.h" |
| 18 #include "components/omnibox/browser/autocomplete_match_type.h" | 19 #include "components/omnibox/browser/autocomplete_match_type.h" |
| 19 #include "components/omnibox/browser/omnibox_edit_model.h" | 20 #include "components/omnibox/browser/omnibox_edit_model.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // running animations and set the new frame value immediately. In practice, | 268 // running animations and set the new frame value immediately. In practice, |
| 268 // zero-length animations are ignored entirely. Work around this AppKit bug | 269 // zero-length animations are ignored entirely. Work around this AppKit bug |
| 269 // by explicitly setting an NSNull animation for the "frame" key and then | 270 // by explicitly setting an NSNull animation for the "frame" key and then |
| 270 // running the animation with a non-zero(!!) duration. This somehow | 271 // running the animation with a non-zero(!!) duration. This somehow |
| 271 // convinces AppKit to do the right thing. Save off the current animations | 272 // convinces AppKit to do the right thing. Save off the current animations |
| 272 // dictionary so it can be restored later. | 273 // dictionary so it can be restored later. |
| 273 savedAnimations.reset([[popup_ animations] copy]); | 274 savedAnimations.reset([[popup_ animations] copy]); |
| 274 [popup_ setAnimations:@{@"frame" : [NSNull null]}]; | 275 [popup_ setAnimations:@{@"frame" : [NSNull null]}]; |
| 275 } | 276 } |
| 276 | 277 |
| 277 if (!animate && base::mac::IsOSElCapitanOrLater()) { | 278 [NSAnimationContext beginGrouping]; |
| 278 // When using the animator to make |popup_| larger on El Capitan, for some | 279 // Don't use the GTM addition for the "Steve" slowdown because this can |
| 279 // reason the window does not get redrawn. There's no animation in this case | 280 // happen async from user actions and the effects could be a surprise. |
| 280 // anyway, so just force the frame change. See http://crbug.com/538590 . | 281 [[NSAnimationContext currentContext] setDuration:kShrinkAnimationDuration]; |
| 281 [popup_ setFrame:popup_frame display:YES]; | 282 // When using the animator to update |popup_| on El Capitan, for some reason |
| 282 } else { | 283 // the window does not get redrawn. Use a completion handler to make sure |
| 283 [NSAnimationContext beginGrouping]; | 284 // |popup_| gets redrawn once the animation completes. See |
| 284 // Don't use the GTM addition for the "Steve" slowdown because this can | 285 // http://crbug.com/538590 and http://crbug.com/551007 . |
| 285 // happen async from user actions and the effects could be a surprise. | 286 if (base::mac::IsOSElCapitanOrLater()) { |
| 286 [[NSAnimationContext currentContext] setDuration:kShrinkAnimationDuration]; | 287 [[NSAnimationContext currentContext] setCompletionHandler:^{ |
| 287 [[popup_ animator] setFrame:popup_frame display:YES]; | 288 [popup_ display]; |
| 288 [NSAnimationContext endGrouping]; | 289 }]; |
| 289 } | 290 } |
| 291 [[popup_ animator] setFrame:popup_frame display:YES]; |
| 292 [NSAnimationContext endGrouping]; |
| 290 | 293 |
| 291 if (!animate) { | 294 if (!animate) { |
| 292 // Restore the original animations dictionary. This does not reinstate any | 295 // Restore the original animations dictionary. This does not reinstate any |
| 293 // previously running animations. | 296 // previously running animations. |
| 294 [popup_ setAnimations:savedAnimations]; | 297 [popup_ setAnimations:savedAnimations]; |
| 295 } | 298 } |
| 296 } | 299 } |
| 297 | 300 |
| 298 NSImage* OmniboxPopupViewMac::ImageForMatch( | 301 NSImage* OmniboxPopupViewMac::ImageForMatch( |
| 299 const AutocompleteMatch& match) const { | 302 const AutocompleteMatch& match) const { |
| 300 gfx::Image image = model_->GetIconIfExtensionMatch(match); | 303 gfx::Image image = model_->GetIconIfExtensionMatch(match); |
| 301 if (!image.IsEmpty()) | 304 if (!image.IsEmpty()) |
| 302 return image.AsNSImage(); | 305 return image.AsNSImage(); |
| 303 | 306 |
| 304 const int resource_id = model_->IsStarredMatch(match) ? | 307 const int resource_id = model_->IsStarredMatch(match) ? |
| 305 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match.type); | 308 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match.type); |
| 306 return OmniboxViewMac::ImageForResource(resource_id); | 309 return OmniboxViewMac::ImageForResource(resource_id); |
| 307 } | 310 } |
| 308 | 311 |
| 309 void OmniboxPopupViewMac::OpenURLForRow(size_t row, | 312 void OmniboxPopupViewMac::OpenURLForRow(size_t row, |
| 310 WindowOpenDisposition disposition) { | 313 WindowOpenDisposition disposition) { |
| 311 DCHECK_LT(row, GetResult().size()); | 314 DCHECK_LT(row, GetResult().size()); |
| 312 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), | 315 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), |
| 313 base::string16(), row); | 316 base::string16(), row); |
| 314 } | 317 } |
| OLD | NEW |