| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/drag_util.h" | 5 #import "chrome/browser/ui/cocoa/drag_util.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 144 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 145 favicon = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); | 145 favicon = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // If no title, just use icon. | 148 // If no title, just use icon. |
| 149 if (title.empty()) | 149 if (title.empty()) |
| 150 return favicon; | 150 return favicon; |
| 151 NSString* ns_title = base::SysUTF16ToNSString(title); | 151 NSString* ns_title = base::SysUTF16ToNSString(title); |
| 152 | 152 |
| 153 // Set the look of the title. | 153 // Set the look of the title. |
| 154 NSDictionary* attrs = | 154 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( |
| 155 [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize: | 155 [[NSMutableParagraphStyle alloc] init]); |
| 156 [NSFont smallSystemFontSize]] | 156 [paragraph_style setLineBreakMode:NSLineBreakByClipping]; |
| 157 forKey:NSFontAttributeName]; | 157 NSDictionary* attrs = @{ |
| 158 NSFontAttributeName : |
| 159 [NSFont systemFontOfSize:[NSFont smallSystemFontSize]], |
| 160 NSParagraphStyleAttributeName : paragraph_style |
| 161 }; |
| 158 base::scoped_nsobject<NSAttributedString> rich_title( | 162 base::scoped_nsobject<NSAttributedString> rich_title( |
| 159 [[NSAttributedString alloc] initWithString:ns_title attributes:attrs]); | 163 [[NSAttributedString alloc] initWithString:ns_title attributes:attrs]); |
| 160 | 164 |
| 161 // Set up sizes and locations for rendering. | 165 // Set up sizes and locations for rendering. |
| 162 const CGFloat kIconPadding = 2.0; // Gap between icon and text. | 166 const CGFloat kIconPadding = 2.0; // Gap between icon and text. |
| 163 NSRect favicon_rect = {NSZeroPoint, [favicon size]}; | 167 NSRect favicon_rect = {NSZeroPoint, [favicon size]}; |
| 164 CGFloat icon_plus_padding_width = NSWidth(favicon_rect) + kIconPadding; | 168 CGFloat icon_plus_padding_width = NSWidth(favicon_rect) + kIconPadding; |
| 165 CGFloat full_text_width = [rich_title size].width; | 169 CGFloat full_text_width = [rich_title size].width; |
| 166 CGFloat allowed_text_width = drag_image_width - icon_plus_padding_width; | 170 CGFloat allowed_text_width = drag_image_width - icon_plus_padding_width; |
| 167 CGFloat used_text_width = std::min(full_text_width, allowed_text_width); | 171 CGFloat used_text_width = std::min(full_text_width, allowed_text_width); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 198 | 202 |
| 199 bool is_title_rtl = base::i18n::GetFirstStrongCharacterDirection(title) == | 203 bool is_title_rtl = base::i18n::GetFirstStrongCharacterDirection(title) == |
| 200 base::i18n::RIGHT_TO_LEFT; | 204 base::i18n::RIGHT_TO_LEFT; |
| 201 DrawTruncatedTitle(rich_title, text_rect, is_title_rtl); | 205 DrawTruncatedTitle(rich_title, text_rect, is_title_rtl); |
| 202 [drag_image unlockFocus]; | 206 [drag_image unlockFocus]; |
| 203 | 207 |
| 204 return drag_image; | 208 return drag_image; |
| 205 } | 209 } |
| 206 | 210 |
| 207 } // namespace drag_util | 211 } // namespace drag_util |
| OLD | NEW |