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

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

Issue 391057: Fix multi-window bookmark bubble problem.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 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/l10n_util_mac.h" 5 #include "app/l10n_util_mac.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 #import "chrome/browser/cocoa/bookmark_bubble_controller.h" 9 #import "chrome/browser/cocoa/bookmark_bubble_controller.h"
10 #include "chrome/browser/metrics/user_metrics.h" 10 #include "chrome/browser/metrics/user_metrics.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 node_ = node; 51 node_ = node;
52 alreadyBookmarked_ = alreadyBookmarked; 52 alreadyBookmarked_ = alreadyBookmarked;
53 } 53 }
54 return self; 54 return self;
55 } 55 }
56 56
57 - (void)windowWillClose:(NSNotification *)notification { 57 - (void)windowWillClose:(NSNotification *)notification {
58 [self autorelease]; 58 [self autorelease];
59 } 59 }
60 60
61 - (void)windowDidLoad { 61
62 NSWindow* window = [self window]; 62 // We want this to be a child of a browser window. addChildWindow:
63 // (called from this function) will bring the window on-screen;
64 // unfortunately, [NSWindowController showWindow:] will also bring it
65 // on-screen (but will cause unexpected changes to the window's
66 // position). We cannot have an addChildWindow: and a subsequent
67 // showWindow:. Thus, we have our own version.
68 - (void)showWindow:(id)sender {
69 NSWindow* window = [self window]; // completes nib load
63 NSPoint origin = [parentWindow_ convertBaseToScreen:topLeftForBubble_]; 70 NSPoint origin = [parentWindow_ convertBaseToScreen:topLeftForBubble_];
64 origin.y -= NSHeight([window frame]); 71 origin.y -= NSHeight([window frame]);
65 [window setFrameOrigin:origin]; 72 [window setFrameOrigin:origin];
66 [parentWindow_ addChildWindow:window ordered:NSWindowAbove]; 73 [parentWindow_ addChildWindow:window ordered:NSWindowAbove];
67 // Default is IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK; "Bookmark". 74 // Default is IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK; "Bookmark".
68 // If adding for the 1st time the string becomes "Bookmark Added!" 75 // If adding for the 1st time the string becomes "Bookmark Added!"
69 if (!alreadyBookmarked_) { 76 if (!alreadyBookmarked_) {
70 NSString* title = 77 NSString* title =
71 l10n_util::GetNSString(IDS_BOOMARK_BUBBLE_PAGE_BOOKMARKED); 78 l10n_util::GetNSString(IDS_BOOMARK_BUBBLE_PAGE_BOOKMARKED);
72 [bigTitle_ setStringValue:title]; 79 [bigTitle_ setStringValue:title];
73 } 80 }
74 81
75 [self fillInFolderList]; 82 [self fillInFolderList];
83
84 [[self window] makeKeyAndOrderFront:self];
76 } 85 }
77 86
78 - (void)close { 87 - (void)close {
79 [parentWindow_ removeChildWindow:[self window]]; 88 [parentWindow_ removeChildWindow:[self window]];
89 [delegate_ bubbleWindowWillClose:[self window]];
80 [super close]; 90 [super close];
81 } 91 }
82 92
83 // Shows the bookmark editor sheet for more advanced editing. 93 // Shows the bookmark editor sheet for more advanced editing.
84 - (void)showEditor { 94 - (void)showEditor {
85 [self ok:nil]; 95 [self ok:nil];
86 [delegate_ editBookmarkNode:node_]; 96 [delegate_ editBookmarkNode:node_];
87 } 97 }
88 98
89 - (IBAction)edit:(id)sender { 99 - (IBAction)edit:(id)sender {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 [self showEditor]; 137 [self showEditor];
128 } 138 }
129 } 139 }
130 140
131 // The controller is the delegate of the window so it receives did resign key 141 // The controller is the delegate of the window so it receives did resign key
132 // notifications. When key is resigned mirror Windows behavior and close the 142 // notifications. When key is resigned mirror Windows behavior and close the
133 // window. 143 // window.
134 - (void)windowDidResignKey:(NSNotification*)notification { 144 - (void)windowDidResignKey:(NSNotification*)notification {
135 DCHECK_EQ([notification object], [self window]); 145 DCHECK_EQ([notification object], [self window]);
136 146
147 // We must tell our delegate our window is gone RIGHT NOW. The
148 // performSelector: call below triggers a close but it might get
149 // processed after a request to show a new bubble (e.g. in another
150 // window).
151 [delegate_ bubbleWindowWillClose:[self window]];
152
137 // Can't call close from within a window delegate method. Call close for the 153 // Can't call close from within a window delegate method. Call close for the
138 // next time through the event loop. 154 // next time through the event loop.
139 [self performSelector:@selector(ok:) withObject:self afterDelay:0]; 155 [self performSelector:@selector(ok:) withObject:self afterDelay:0];
140 } 156 }
141 157
142 // Look at the dialog; if the user has changed anything, update the 158 // Look at the dialog; if the user has changed anything, update the
143 // bookmark node to reflect this. 159 // bookmark node to reflect this.
144 - (void)updateBookmarkNode { 160 - (void)updateBookmarkNode {
145 if (!node_) return; 161 if (!node_) return;
146 162
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 249 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
234 DCHECK(idx != -1); 250 DCHECK(idx != -1);
235 [folderPopUpButton_ selectItemAtIndex:idx]; 251 [folderPopUpButton_ selectItemAtIndex:idx];
236 } 252 }
237 253
238 - (NSPopUpButton*)folderPopUpButton { 254 - (NSPopUpButton*)folderPopUpButton {
239 return folderPopUpButton_; 255 return folderPopUpButton_;
240 } 256 }
241 257
242 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 258 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bubble_controller.h ('k') | chrome/browser/cocoa/bookmark_bubble_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698