Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_folder_controller.mm

Issue 3150039: Merge 57399 - Try to fix top crasher.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/nsimage_cache_mac.h" 7 #include "base/nsimage_cache_mac.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h" 9 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/bookmarks/bookmark_utils.h" 10 #include "chrome/browser/bookmarks/bookmark_utils.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 - (void)dealloc { 140 - (void)dealloc {
141 // The button is no longer part of the menu path. 141 // The button is no longer part of the menu path.
142 [parentButton_ forceButtonBorderToStayOnAlways:NO]; 142 [parentButton_ forceButtonBorderToStayOnAlways:NO];
143 [parentButton_ setNeedsDisplay]; 143 [parentButton_ setNeedsDisplay];
144 144
145 [self removeScrollTracking]; 145 [self removeScrollTracking];
146 [self endScroll]; 146 [self endScroll];
147 [hoverState_ draggingExited]; 147 [hoverState_ draggingExited];
148
149 // Delegate pattern does not retain; make sure pointers to us are removed.
150 for (BookmarkButton* button in buttons_.get()) {
151 [button setDelegate:nil];
152 [button setTarget:nil];
153 [button setAction:nil];
154 }
155
148 // Note: we don't need to 156 // Note: we don't need to
149 // [NSObject cancelPreviousPerformRequestsWithTarget:self]; 157 // [NSObject cancelPreviousPerformRequestsWithTarget:self];
150 // Because all of our performSelector: calls use withDelay: which 158 // Because all of our performSelector: calls use withDelay: which
151 // retains us. 159 // retains us.
152 [super dealloc]; 160 [super dealloc];
153 } 161 }
154 162
155 // Overriden from NSWindowController to call childFolderWillShow: before showing 163 // Overriden from NSWindowController to call childFolderWillShow: before showing
156 // the window. 164 // the window.
157 - (void)showWindow:(id)sender { 165 - (void)showWindow:(id)sender {
158 [barController_ childFolderWillShow:self]; 166 [barController_ childFolderWillShow:self];
159 [super showWindow:sender]; 167 [super showWindow:sender];
160 } 168 }
161 169
162 - (BookmarkButton*)parentButton { 170 - (BookmarkButton*)parentButton {
163 return parentButton_.get(); 171 return parentButton_.get();
164 } 172 }
165 173
166 - (void)offsetFolderMenuWindow:(NSSize)offset { 174 - (void)offsetFolderMenuWindow:(NSSize)offset {
167 NSWindow* window = [self window]; 175 NSWindow* window = [self window];
168 NSRect windowFrame = [window frame]; 176 NSRect windowFrame = [window frame];
169 windowFrame.origin.x -= offset.width; 177 windowFrame.origin.x -= offset.width;
170 windowFrame.origin.y += offset.height; // Yes, in the opposite direction! 178 windowFrame.origin.y += offset.height; // Yes, in the opposite direction!
171 [window setFrame:windowFrame display:YES]; 179 [window setFrame:windowFrame display:YES];
172 [folderController_ offsetFolderMenuWindow:offset]; 180 [folderController_ offsetFolderMenuWindow:offset];
173 } 181 }
174 182
175 - (void)reconfigureMenu { 183 - (void)reconfigureMenu {
176 [NSObject cancelPreviousPerformRequestsWithTarget:self]; 184 [NSObject cancelPreviousPerformRequestsWithTarget:self];
177 for (BookmarkButton* button in buttons_.get()) 185 for (BookmarkButton* button in buttons_.get()) {
186 [button setDelegate:nil];
178 [button removeFromSuperview]; 187 [button removeFromSuperview];
188 }
179 [buttons_ removeAllObjects]; 189 [buttons_ removeAllObjects];
180 [self configureWindow]; 190 [self configureWindow];
181 } 191 }
182 192
183 #pragma mark Private Methods 193 #pragma mark Private Methods
184 194
185 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)child { 195 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)child {
186 NSImage* image = child ? [barController_ favIconForNode:child] : nil; 196 NSImage* image = child ? [barController_ favIconForNode:child] : nil;
187 NSMenu* menu = child ? child->is_folder() ? folderMenu_ : buttonMenu_ : nil; 197 NSMenu* menu = child ? child->is_folder() ? folderMenu_ : buttonMenu_ : nil;
188 BookmarkBarFolderButtonCell* cell = 198 BookmarkBarFolderButtonCell* cell =
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 NSWidth([mainView_ frame]) - 2 * bookmarks::kBookmarkHorizontalPadding - 1227 NSWidth([mainView_ frame]) - 2 * bookmarks::kBookmarkHorizontalPadding -
1218 bookmarks::kScrollViewContentWidthMargin, 1228 bookmarks::kScrollViewContentWidthMargin,
1219 bookmarks::kBookmarkBarHeight - 2 * 1229 bookmarks::kBookmarkBarHeight - 2 *
1220 bookmarks::kBookmarkVerticalPadding); 1230 bookmarks::kBookmarkVerticalPadding);
1221 // When adding a button to an empty folder we must remove the 'empty' 1231 // When adding a button to an empty folder we must remove the 'empty'
1222 // placeholder button. This can be detected by checking for a parent 1232 // placeholder button. This can be detected by checking for a parent
1223 // child count of 1. 1233 // child count of 1.
1224 const BookmarkNode* parentNode = node->GetParent(); 1234 const BookmarkNode* parentNode = node->GetParent();
1225 if (parentNode->GetChildCount() == 1) { 1235 if (parentNode->GetChildCount() == 1) {
1226 BookmarkButton* emptyButton = [buttons_ lastObject]; 1236 BookmarkButton* emptyButton = [buttons_ lastObject];
1237 [emptyButton setDelegate:nil];
1227 [emptyButton removeFromSuperview]; 1238 [emptyButton removeFromSuperview];
1228 [buttons_ removeLastObject]; 1239 [buttons_ removeLastObject];
1229 } else { 1240 } else {
1230 // Set us up to remember the last moved button's frame. 1241 // Set us up to remember the last moved button's frame.
1231 buttonFrame.origin.y += NSHeight([mainView_ frame]) + 1242 buttonFrame.origin.y += NSHeight([mainView_ frame]) +
1232 bookmarks::kBookmarkBarHeight; 1243 bookmarks::kBookmarkBarHeight;
1233 } 1244 }
1234 1245
1235 if (buttonIndex == -1) 1246 if (buttonIndex == -1)
1236 buttonIndex = [buttons_ count]; 1247 buttonIndex = [buttons_ count];
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 NSPoint poofPoint = NSMakePoint(NSMidX(poofFrame), NSMidY(poofFrame)); 1354 NSPoint poofPoint = NSMakePoint(NSMidX(poofFrame), NSMidY(poofFrame));
1344 poofPoint = [oldButton convertPoint:poofPoint toView:nil]; 1355 poofPoint = [oldButton convertPoint:poofPoint toView:nil];
1345 poofPoint = [[oldButton window] convertBaseToScreen:poofPoint]; 1356 poofPoint = [[oldButton window] convertBaseToScreen:poofPoint];
1346 1357
1347 // If a hover-open is pending, cancel it. 1358 // If a hover-open is pending, cancel it.
1348 if (oldButton == buttonThatMouseIsIn_) { 1359 if (oldButton == buttonThatMouseIsIn_) {
1349 [NSObject cancelPreviousPerformRequestsWithTarget:self]; 1360 [NSObject cancelPreviousPerformRequestsWithTarget:self];
1350 buttonThatMouseIsIn_ = nil; 1361 buttonThatMouseIsIn_ = nil;
1351 } 1362 }
1352 1363
1364 [oldButton setDelegate:nil];
1353 [oldButton removeFromSuperview]; 1365 [oldButton removeFromSuperview];
1354 if (animate && !ignoreAnimations_) 1366 if (animate && !ignoreAnimations_)
1355 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint, 1367 NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault, poofPoint,
1356 NSZeroSize, nil, nil, nil); 1368 NSZeroSize, nil, nil, nil);
1357 [buttons_ removeObjectAtIndex:buttonIndex]; 1369 [buttons_ removeObjectAtIndex:buttonIndex];
1358 for (NSInteger i = 0; i < buttonIndex; ++i) { 1370 for (NSInteger i = 0; i < buttonIndex; ++i) {
1359 BookmarkButton* button = [buttons_ objectAtIndex:i]; 1371 BookmarkButton* button = [buttons_ objectAtIndex:i];
1360 NSRect buttonFrame = [button frame]; 1372 NSRect buttonFrame = [button frame];
1361 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight; 1373 buttonFrame.origin.y -= bookmarks::kBookmarkBarHeight;
1362 [button setFrame:buttonFrame]; 1374 [button setFrame:buttonFrame];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 1420
1409 - (void)setIgnoreAnimations:(BOOL)ignore { 1421 - (void)setIgnoreAnimations:(BOOL)ignore {
1410 ignoreAnimations_ = ignore; 1422 ignoreAnimations_ = ignore;
1411 } 1423 }
1412 1424
1413 - (BookmarkButton*)buttonThatMouseIsIn { 1425 - (BookmarkButton*)buttonThatMouseIsIn {
1414 return buttonThatMouseIsIn_; 1426 return buttonThatMouseIsIn_;
1415 } 1427 }
1416 1428
1417 @end // BookmarkBarFolderController 1429 @end // BookmarkBarFolderController
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.mm ('k') | chrome/browser/cocoa/bookmark_button_cell.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698