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/download/download_item_controller.h" | 5 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/mac/mac_util.h" | |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 14 #include "chrome/browser/download/download_item_model.h" | 15 #include "chrome/browser/download/download_item_model.h" |
| 15 #include "chrome/browser/download/download_shelf_context_menu.h" | 16 #include "chrome/browser/download/download_shelf_context_menu.h" |
| 16 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" | 17 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" |
| 17 #import "chrome/browser/themes/theme_properties.h" | 18 #import "chrome/browser/themes/theme_properties.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 [self updateExperienceSamplingEvent:ExperienceSamplingEvent::kIgnore]; | 123 [self updateExperienceSamplingEvent:ExperienceSamplingEvent::kIgnore]; |
| 123 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 124 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 124 [progressView_ setController:nil]; | 125 [progressView_ setController:nil]; |
| 125 [[self view] removeFromSuperview]; | 126 [[self view] removeFromSuperview]; |
| 126 [super dealloc]; | 127 [super dealloc]; |
| 127 } | 128 } |
| 128 | 129 |
| 129 - (void)awakeFromNib { | 130 - (void)awakeFromNib { |
| 130 [progressView_ setController:self]; | 131 [progressView_ setController:self]; |
| 131 | 132 |
| 133 // The new system font on Yosemite brings slightly different font metrics. | |
| 134 // The |dangerousDownloadLabel_| is 22 points high with two lines of text | |
| 135 // in the nib, but on Yosemite it needs 24 points to hold that same text. | |
| 136 // The best alternative to hard coding the 2.0pt delta is to have the | |
| 137 // textfield compute the height necessary to display two lines of text. | |
| 138 // In order to disturb as little as possible, the code below only runs on | |
| 139 // Yosemite, and restores the original state of |dangerousDownloadLabel_| | |
| 140 // after the computation (except for, of course, its height). | |
|
asanka
2015/02/21 02:14:53
Comment is out of date?
shrike
2015/02/23 20:12:14
It's not, but I rewrote it in the new cl.
| |
| 141 // http://crbug.com/454782 . | |
| 142 if (base::mac::IsOSYosemiteOrLater()) { | |
| 143 NSString* placeholderText = [dangerousDownloadLabel_ stringValue]; | |
|
asanka
2015/02/21 02:14:54
Let's move this height adjustment logic into -show
| |
| 144 NSRect labelFrame = [dangerousDownloadLabel_ frame]; | |
| 145 [dangerousDownloadLabel_ setStringValue:@"Two lines\nof text"]; | |
|
asanka
2015/02/21 02:14:54
Once this is moved to -showDangerousWarning:, we c
shrike
2015/02/23 20:12:14
The idea behind this change is just to quickly fix
asanka
2015/02/24 03:16:13
showDangerousWarning is called at most once per do
| |
| 146 [dangerousDownloadLabel_ sizeToFit]; | |
| 147 CGFloat heightDelta = [dangerousDownloadLabel_ frame].size.height - | |
| 148 labelFrame.size.height; | |
| 149 labelFrame.origin.y -= heightDelta / 2.0; | |
| 150 labelFrame.size.height += heightDelta; | |
| 151 [dangerousDownloadLabel_ setFrame:labelFrame]; | |
| 152 [dangerousDownloadLabel_ setStringValue:placeholderText]; | |
| 153 } | |
| 132 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = | 154 GTMUILocalizerAndLayoutTweaker* localizerAndLayoutTweaker = |
| 133 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; | 155 [[[GTMUILocalizerAndLayoutTweaker alloc] init] autorelease]; |
| 134 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; | 156 [localizerAndLayoutTweaker applyLocalizer:localizer_ tweakingUI:[self view]]; |
| 135 | 157 |
| 136 [self setStateFromDownload:bridge_->download_model()]; | 158 [self setStateFromDownload:bridge_->download_model()]; |
| 137 | 159 |
| 138 bridge_->LoadIcon(); | 160 bridge_->LoadIcon(); |
| 139 [self updateToolTip]; | 161 [self updateToolTip]; |
| 140 } | 162 } |
| 141 | 163 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 base::scoped_nsobject<DownloadShelfContextMenuController> menuController( | 395 base::scoped_nsobject<DownloadShelfContextMenuController> menuController( |
| 374 [[DownloadShelfContextMenuController alloc] | 396 [[DownloadShelfContextMenuController alloc] |
| 375 initWithItemController:self | 397 initWithItemController:self |
| 376 withDelegate:nil]); | 398 withDelegate:nil]); |
| 377 [NSMenu popUpContextMenu:[menuController menu] | 399 [NSMenu popUpContextMenu:[menuController menu] |
| 378 withEvent:[NSApp currentEvent] | 400 withEvent:[NSApp currentEvent] |
| 379 forView:[self view]]; | 401 forView:[self view]]; |
| 380 } | 402 } |
| 381 | 403 |
| 382 @end | 404 @end |
| OLD | NEW |