| 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 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" | 5 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" |
| 6 #include "base/mac_util.h" | 6 #include "base/mac_util.h" |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_utils.h" | 9 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 10 #import "chrome/browser/browser_theme_provider.h" | 10 #import "chrome/browser/browser_theme_provider.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // Frequency of the scrolling timer in seconds. | 23 // Frequency of the scrolling timer in seconds. |
| 24 const NSTimeInterval kBookmarkBarFolderScrollInterval = 0.2; | 24 const NSTimeInterval kBookmarkBarFolderScrollInterval = 0.2; |
| 25 | 25 |
| 26 // Amount to scroll by per timer fire. We scroll rather slowly; to | 26 // Amount to scroll by per timer fire. We scroll rather slowly; to |
| 27 // accomodate we do 2 at a time. | 27 // accomodate we do 2 at a time. |
| 28 const CGFloat kBookmarkBarFolderScrollAmount = | 28 const CGFloat kBookmarkBarFolderScrollAmount = |
| 29 2 * (bookmarks::kBookmarkButtonHeight + | 29 2 * (bookmarks::kBookmarkButtonHeight + |
| 30 bookmarks::kBookmarkVerticalPadding); | 30 bookmarks::kBookmarkVerticalPadding); |
| 31 | 31 |
| 32 // Amount to scroll for each scroll wheel delta. |
| 33 const CGFloat kBookmarkBarFolderScrollWheelAmount = |
| 34 1 * (bookmarks::kBookmarkButtonHeight + |
| 35 bookmarks::kBookmarkVerticalPadding); |
| 36 |
| 32 // When constraining a scrolling bookmark bar folder window to the | 37 // When constraining a scrolling bookmark bar folder window to the |
| 33 // screen, shrink the "constrain" by this much vertically. Currently | 38 // screen, shrink the "constrain" by this much vertically. Currently |
| 34 // this is 0.0 to avoid a problem with tracking areas leaving the | 39 // this is 0.0 to avoid a problem with tracking areas leaving the |
| 35 // window, but should probably be 8.0 or something. | 40 // window, but should probably be 8.0 or something. |
| 36 // TODO(jrg): http://crbug.com/36225 | 41 // TODO(jrg): http://crbug.com/36225 |
| 37 const CGFloat kScrollWindowVerticalMargin = 0.0; | 42 const CGFloat kScrollWindowVerticalMargin = 0.0; |
| 38 | 43 |
| 39 } // namespace | 44 } // namespace |
| 40 | 45 |
| 41 @interface BookmarkBarFolderController(Private) | 46 @interface BookmarkBarFolderController(Private) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 [super dealloc]; | 83 [super dealloc]; |
| 79 } | 84 } |
| 80 | 85 |
| 81 // Overriden from NSWindowController to call childFolderWillShow: before showing | 86 // Overriden from NSWindowController to call childFolderWillShow: before showing |
| 82 // the window. | 87 // the window. |
| 83 - (void)showWindow:(id)sender { | 88 - (void)showWindow:(id)sender { |
| 84 [parentController_ childFolderWillShow:self]; | 89 [parentController_ childFolderWillShow:self]; |
| 85 [super showWindow:sender]; | 90 [super showWindow:sender]; |
| 86 } | 91 } |
| 87 | 92 |
| 88 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)child { | 93 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)child { |
| 89 NSImage* image = child ? [barController_ favIconForNode:child] : nil; | 94 NSImage* image = child ? [barController_ favIconForNode:child] : nil; |
| 90 NSMenu* menu = child ? child->is_folder() ? folderMenu_ : buttonMenu_ : nil; | 95 NSMenu* menu = child ? child->is_folder() ? folderMenu_ : buttonMenu_ : nil; |
| 91 BookmarkBarFolderButtonCell* cell = | 96 BookmarkBarFolderButtonCell* cell = |
| 92 [BookmarkBarFolderButtonCell buttonCellForNode:child | 97 [BookmarkBarFolderButtonCell buttonCellForNode:child |
| 93 contextMenu:menu | 98 contextMenu:menu |
| 94 cellText:nil | 99 cellText:nil |
| 95 cellImage:image]; | 100 cellImage:image]; |
| 96 return cell; | 101 return cell; |
| 97 } | 102 } |
| 98 | 103 |
| 99 // Redirect to our logic shared with BookmarkBarController. | 104 // Redirect to our logic shared with BookmarkBarController. |
| 100 - (IBAction)openBookmarkFolderFromButton:(id)sender { | 105 - (IBAction)openBookmarkFolderFromButton:(id)sender { |
| 101 [folderTarget_ openBookmarkFolderFromButton:sender]; | 106 [folderTarget_ openBookmarkFolderFromButton:sender]; |
| 102 } | 107 } |
| 103 | 108 |
| 104 // Create a bookmark button for the given node using frame. | 109 // Create a bookmark button for the given node using frame. |
| 105 // | 110 // |
| 106 // If |node| is NULL this is an "(empty)" button. | 111 // If |node| is NULL this is an "(empty)" button. |
| 107 // Does NOT add this button to our button list. | 112 // Does NOT add this button to our button list. |
| 108 // Returns an autoreleased button. | 113 // Returns an autoreleased button. |
| 109 // Adjusts the input frame width as appropriate. | 114 // Adjusts the input frame width as appropriate. |
| 110 // | 115 // |
| 111 // TODO(jrg): combine with addNodesToButtonList: code from | 116 // TODO(jrg): combine with addNodesToButtonList: code from |
| 112 // bookmark_bar_controller.mm, and generalize that to use both x and y | 117 // bookmark_bar_controller.mm, and generalize that to use both x and y |
| 113 // offsets. | 118 // offsets. |
| 114 // http://crbug.com/35966 | 119 // http://crbug.com/35966 |
| 115 - (BookmarkButton*)makeButtonForNode:(const BookmarkNode*)node | 120 - (BookmarkButton*)makeButtonForNode:(const BookmarkNode*)node |
| 116 frame:(NSRect)frame { | 121 frame:(NSRect)frame { |
| 117 NSCell* cell = [self cellForBookmarkNode:node]; | 122 BookmarkButtonCell* cell = [self cellForBookmarkNode:node]; |
| 118 DCHECK(cell); | 123 DCHECK(cell); |
| 119 | 124 |
| 125 // We must decide if we draw the folder arrow before we ask the cell |
| 126 // how big it needs to be. |
| 127 if (node && node->is_folder()) { |
| 128 // Warning when combining code with bookmark_bar_controller.mm: |
| 129 // this call should NOT be made for the bar buttons; only for the |
| 130 // subfolder buttons. |
| 131 [cell setDrawFolderArrow:YES]; |
| 132 } |
| 133 |
| 120 // The "+2" is needed because, sometimes, Cocoa is off by a tad when | 134 // The "+2" is needed because, sometimes, Cocoa is off by a tad when |
| 121 // returning the value it thinks it needs. | 135 // returning the value it thinks it needs. |
| 122 CGFloat desired = [cell cellSize].width + 2; | 136 CGFloat desired = [cell cellSize].width + 2; |
| 123 frame.size.width = std::min( | 137 frame.size.width = std::min( |
| 124 std::max(bookmarks::kBookmarkMenuButtonMinimumWidth, desired), | 138 std::max(bookmarks::kBookmarkMenuButtonMinimumWidth, desired), |
| 125 bookmarks::kBookmarkMenuButtonMaximumWidth); | 139 bookmarks::kBookmarkMenuButtonMaximumWidth); |
| 126 | 140 |
| 127 BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame] | 141 BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame] |
| 128 autorelease]; | 142 autorelease]; |
| 129 DCHECK(button); | 143 DCHECK(button); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 [button setAction:@selector(openBookmark:)]; | 154 [button setAction:@selector(openBookmark:)]; |
| 141 // Add a tooltip. | 155 // Add a tooltip. |
| 142 NSString* title = base::SysWideToNSString(node->GetTitle()); | 156 NSString* title = base::SysWideToNSString(node->GetTitle()); |
| 143 std::string urlString = node->GetURL().possibly_invalid_spec(); | 157 std::string urlString = node->GetURL().possibly_invalid_spec(); |
| 144 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, | 158 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title, |
| 145 urlString.c_str()]; | 159 urlString.c_str()]; |
| 146 [button setToolTip:tooltip]; | 160 [button setToolTip:tooltip]; |
| 147 } | 161 } |
| 148 } else { | 162 } else { |
| 149 [button setEnabled:NO]; | 163 [button setEnabled:NO]; |
| 164 [button setBordered:NO]; |
| 150 } | 165 } |
| 151 return button; | 166 return button; |
| 152 } | 167 } |
| 153 | 168 |
| 154 // Exposed for testing. | 169 // Exposed for testing. |
| 155 - (NSView*)mainView { | 170 - (NSView*)mainView { |
| 156 return mainView_; | 171 return mainView_; |
| 157 } | 172 } |
| 158 | 173 |
| 159 - (BookmarkBarFolderController*)folderController { | 174 - (BookmarkBarFolderController*)folderController { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (delta) { | 382 if (delta) { |
| 368 // If we can, grow the window (up). | 383 // If we can, grow the window (up). |
| 369 if (NSHeight(windowFrame) < screenHeightMinusMargin) { | 384 if (NSHeight(windowFrame) < screenHeightMinusMargin) { |
| 370 CGFloat growAmount = delta; | 385 CGFloat growAmount = delta; |
| 371 // Don't scroll more than enough to "finish". | 386 // Don't scroll more than enough to "finish". |
| 372 if (scrollPosition.y < 0) | 387 if (scrollPosition.y < 0) |
| 373 growAmount += scrollPosition.y; | 388 growAmount += scrollPosition.y; |
| 374 windowFrame.size.height += growAmount; | 389 windowFrame.size.height += growAmount; |
| 375 windowFrame.size.height = std::min(NSHeight(windowFrame), | 390 windowFrame.size.height = std::min(NSHeight(windowFrame), |
| 376 screenHeightMinusMargin); | 391 screenHeightMinusMargin); |
| 377 [[self window] setFrame:windowFrame display:YES]; | 392 // Don't allow scrolling to make the window smaller, ever. This |
| 378 [self addOrUpdateScrollTracking]; | 393 // conditional is important when processing scrollWheel events. |
| 394 if (windowFrame.size.height > [[self window] frame].size.height) { |
| 395 [[self window] setFrame:windowFrame display:YES]; |
| 396 [self addOrUpdateScrollTracking]; |
| 397 } |
| 379 } | 398 } |
| 380 } | 399 } |
| 381 | 400 |
| 382 // If we're at either end, happiness. | 401 // If we're at either end, happiness. |
| 383 if ((scrollPosition.y <= 0) || | 402 if ((scrollPosition.y <= 0) || |
| 384 ((scrollPosition.y + NSHeight(windowFrame) >= | 403 ((scrollPosition.y + NSHeight(windowFrame) >= |
| 385 NSHeight([mainView_ frame])) && | 404 NSHeight([mainView_ frame])) && |
| 386 (windowFrame.size.height == screenHeightMinusMargin))) { | 405 (windowFrame.size.height == screenHeightMinusMargin))) { |
| 387 [self endScroll]; | 406 [self endScroll]; |
| 388 | 407 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 819 |
| 801 - (NSArray*)buttons { | 820 - (NSArray*)buttons { |
| 802 return buttons_.get(); | 821 return buttons_.get(); |
| 803 } | 822 } |
| 804 | 823 |
| 805 - (void)close { | 824 - (void)close { |
| 806 [folderController_ close]; | 825 [folderController_ close]; |
| 807 [super close]; | 826 [super close]; |
| 808 } | 827 } |
| 809 | 828 |
| 829 - (void)scrollWheel:(NSEvent *)theEvent { |
| 830 if (scrollable_) { |
| 831 // We go negative since an NSScrollView has a flipped coordinate frame. |
| 832 CGFloat amt = kBookmarkBarFolderScrollWheelAmount * -[theEvent deltaY]; |
| 833 [self performOneScroll:amt]; |
| 834 } |
| 835 } |
| 836 |
| 810 #pragma mark Methods Forwarded to BookmarkBarController | 837 #pragma mark Methods Forwarded to BookmarkBarController |
| 811 | 838 |
| 812 - (IBAction)cutBookmark:(id)sender { | 839 - (IBAction)cutBookmark:(id)sender { |
| 813 [barController_ cutBookmark:sender]; | 840 [barController_ cutBookmark:sender]; |
| 814 } | 841 } |
| 815 | 842 |
| 816 - (IBAction)copyBookmark:(id)sender { | 843 - (IBAction)copyBookmark:(id)sender { |
| 817 [barController_ cutBookmark:sender]; | 844 [barController_ cutBookmark:sender]; |
| 818 } | 845 } |
| 819 | 846 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 } | 885 } |
| 859 | 886 |
| 860 - (IBAction)openBookmarkInNewForegroundTab:(id)sender { | 887 - (IBAction)openBookmarkInNewForegroundTab:(id)sender { |
| 861 [barController_ openBookmarkInNewForegroundTab:sender]; | 888 [barController_ openBookmarkInNewForegroundTab:sender]; |
| 862 } | 889 } |
| 863 | 890 |
| 864 - (IBAction)openBookmarkInNewWindow:(id)sender { | 891 - (IBAction)openBookmarkInNewWindow:(id)sender { |
| 865 [barController_ openBookmarkInNewWindow:sender]; | 892 [barController_ openBookmarkInNewWindow:sender]; |
| 866 } | 893 } |
| 867 | 894 |
| 895 |
| 868 @end // BookmarkBarFolderController | 896 @end // BookmarkBarFolderController |
| OLD | NEW |