OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/history_menu_bridge.h" | 5 #include "chrome/browser/cocoa/history_menu_bridge.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 title = base::SysUTF8ToNSString(url_string); | 291 title = base::SysUTF8ToNSString(url_string); |
292 NSString* full_title = title; | 292 NSString* full_title = title; |
293 if ([title length] > kMaximumMenuWidthInChars) { | 293 if ([title length] > kMaximumMenuWidthInChars) { |
294 // TODO(rsesek): use app/text_elider.h once it uses string16 and can | 294 // TODO(rsesek): use app/text_elider.h once it uses string16 and can |
295 // take out the middle of strings. | 295 // take out the middle of strings. |
296 title = [NSString stringWithFormat:@"%@…%@", | 296 title = [NSString stringWithFormat:@"%@…%@", |
297 [title substringToIndex:kMenuTrimSizeInChars], | 297 [title substringToIndex:kMenuTrimSizeInChars], |
298 [title substringFromIndex:([title length] - | 298 [title substringFromIndex:([title length] - |
299 kMenuTrimSizeInChars)]]; | 299 kMenuTrimSizeInChars)]]; |
300 } | 300 } |
301 scoped_nsobject<NSMenuItem> menu_item( | 301 item->menu_item.reset( |
John Grabowski
2010/06/17 18:53:55
Perhaps there is an easier solution?
If you just d
Robert Sesek
2010/06/17 19:05:44
I tried that as well as nil-ing the item in ClearM
| |
302 [[NSMenuItem alloc] initWithTitle:title | 302 [[NSMenuItem alloc] initWithTitle:title |
303 action:nil | 303 action:nil |
304 keyEquivalent:@""]); | 304 keyEquivalent:@""]); |
305 [menu_item setTarget:controller_]; | 305 [item->menu_item setTarget:controller_]; |
306 [menu_item setAction:@selector(openHistoryMenuItem:)]; | 306 [item->menu_item setAction:@selector(openHistoryMenuItem:)]; |
307 [menu_item setTag:tag]; | 307 [item->menu_item setTag:tag]; |
308 if (item->icon.get()) | 308 if (item->icon.get()) |
309 [menu_item setImage:item->icon.get()]; | 309 [item->menu_item setImage:item->icon.get()]; |
310 else if (!item->tabs.size()) | 310 else if (!item->tabs.size()) |
311 [menu_item setImage:default_favicon_.get()]; | 311 [item->menu_item setImage:default_favicon_.get()]; |
312 | 312 |
313 // Add a tooltip. | 313 // Add a tooltip. |
314 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", full_title, | 314 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", full_title, |
315 url_string.c_str()]; | 315 url_string.c_str()]; |
316 [menu_item setToolTip:tooltip]; | 316 [item->menu_item setToolTip:tooltip]; |
317 | 317 |
318 [menu insertItem:menu_item atIndex:index]; | 318 [menu insertItem:item->menu_item.get() atIndex:index]; |
319 item->menu_item = menu_item.get(); | 319 menu_item_map_.insert(std::make_pair(item->menu_item.get(), item)); |
320 menu_item_map_.insert(std::make_pair(menu_item.get(), item)); | |
321 | 320 |
322 return menu_item; | 321 return item->menu_item.get(); |
323 } | 322 } |
324 | 323 |
325 void HistoryMenuBridge::Init() { | 324 void HistoryMenuBridge::Init() { |
326 const NotificationSource& source = NotificationService::AllSources(); | 325 const NotificationSource& source = NotificationService::AllSources(); |
327 registrar_.Add(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, source); | 326 registrar_.Add(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, source); |
328 registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, source); | 327 registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, source); |
329 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, source); | 328 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, source); |
330 } | 329 } |
331 | 330 |
332 void HistoryMenuBridge::CreateMenu() { | 331 void HistoryMenuBridge::CreateMenu() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
438 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { | 437 void HistoryMenuBridge::CancelFaviconRequest(HistoryItem* item) { |
439 DCHECK(item); | 438 DCHECK(item); |
440 if (item->icon_requested) { | 439 if (item->icon_requested) { |
441 FaviconService* service = | 440 FaviconService* service = |
442 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 441 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
443 service->CancelRequest(item->icon_handle); | 442 service->CancelRequest(item->icon_handle); |
444 item->icon_requested = false; | 443 item->icon_requested = false; |
445 item->icon_handle = NULL; | 444 item->icon_handle = NULL; |
446 } | 445 } |
447 } | 446 } |
OLD | NEW |