| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/text_elider.h" | 5 #include "app/gfx/text_elider.h" |
| 6 #include "base/sys_string_conversions.h" | 6 #include "base/sys_string_conversions.h" |
| 7 #include "chrome/browser/bookmarks/bookmark_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
| 9 #import "chrome/browser/cocoa/bookmark_menu_bridge.h" | 9 #import "chrome/browser/cocoa/bookmark_menu_bridge.h" |
| 10 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h" | 10 #import "chrome/browser/cocoa/bookmark_menu_cocoa_controller.h" |
| 11 #include "chrome/browser/cocoa/event_utils.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #import "chrome/common/cocoa_utils.h" | |
| 14 #include "webkit/glue/window_open_disposition.h" | 14 #include "webkit/glue/window_open_disposition.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Menus more than this many pixels wide will get trimmed | 18 // Menus more than this many pixels wide will get trimmed |
| 19 // TODO(jrg): ask UI dudes what a good value is. | 19 // TODO(jrg): ask UI dudes what a good value is. |
| 20 const NSUInteger kMaximumMenuPixelsWide = 300; | 20 const NSUInteger kMaximumMenuPixelsWide = 300; |
| 21 | 21 |
| 22 } | 22 } |
| 23 | 23 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Return the a BookmarkNode that has the given id (called | 45 // Return the a BookmarkNode that has the given id (called |
| 46 // "identifier" here to avoid conflict with objc's concept of "id"). | 46 // "identifier" here to avoid conflict with objc's concept of "id"). |
| 47 - (const BookmarkNode*)nodeForIdentifier:(int)identifier { | 47 - (const BookmarkNode*)nodeForIdentifier:(int)identifier { |
| 48 return bridge_->GetBookmarkModel()->GetNodeByID(identifier); | 48 return bridge_->GetBookmarkModel()->GetNodeByID(identifier); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Open the URL of the given BookmarkNode in the current tab. | 51 // Open the URL of the given BookmarkNode in the current tab. |
| 52 - (void)openURLForNode:(const BookmarkNode*)node { | 52 - (void)openURLForNode:(const BookmarkNode*)node { |
| 53 Browser* browser = BrowserList::GetLastActive(); | 53 Browser* browser = |
| 54 | 54 Browser::GetOrCreateTabbedBrowser(bridge_->GetDefaultProfile()); |
| 55 if (!browser) { // No windows open? | 55 WindowOpenDisposition disposition = |
| 56 Browser::OpenEmptyWindow(bridge_->GetDefaultProfile()); | 56 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 57 browser = BrowserList::GetLastActive(); | 57 browser->OpenURL(node->GetURL(), GURL(), disposition, |
| 58 } | 58 PageTransition::AUTO_BOOKMARK); |
| 59 DCHECK(browser); | |
| 60 TabContents* tab_contents = browser->GetSelectedTabContents(); | |
| 61 DCHECK(tab_contents); | |
| 62 | |
| 63 // A TabContents is a PageNavigator, so we can OpenURL() on it. | |
| 64 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( | |
| 65 [[NSApp currentEvent] modifierFlags]); | |
| 66 tab_contents->OpenURL(node->GetURL(), GURL(), disposition, | |
| 67 PageTransition::AUTO_BOOKMARK); | |
| 68 } | 59 } |
| 69 | 60 |
| 70 - (IBAction)openBookmarkMenuItem:(id)sender { | 61 - (IBAction)openBookmarkMenuItem:(id)sender { |
| 71 NSInteger tag = [sender tag]; | 62 NSInteger tag = [sender tag]; |
| 72 int identifier = tag; | 63 int identifier = tag; |
| 73 const BookmarkNode* node = [self nodeForIdentifier:identifier]; | 64 const BookmarkNode* node = [self nodeForIdentifier:identifier]; |
| 74 DCHECK(node); | 65 DCHECK(node); |
| 75 if (!node) | 66 if (!node) |
| 76 return; // shouldn't be reached | 67 return; // shouldn't be reached |
| 77 | 68 |
| 78 [self openURLForNode:node]; | 69 [self openURLForNode:node]; |
| 79 } | 70 } |
| 80 | 71 |
| 81 @end // BookmarkMenuCocoaController | 72 @end // BookmarkMenuCocoaController |
| 82 | 73 |
| OLD | NEW |