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

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

Issue 1307533002: [Mac] Enable MacViews bookmark bubble behind --enable-mac-views-dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@modal
Patch Set: Rebase atop https://codereview.chromium.org/1309583002/ Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/cocoa/bookmarks/bookmark_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_dialogs.h"
10 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_sync_promo_controller.h" 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_sync_promo_controller.h"
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
14 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 16 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
15 #include "chrome/browser/ui/sync/sync_promo_ui.h" 17 #include "chrome/browser/ui/sync/sync_promo_ui.h"
16 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
17 #include "components/bookmarks/browser/bookmark_model.h" 19 #include "components/bookmarks/browser/bookmark_model.h"
18 #include "components/bookmarks/browser/bookmark_utils.h" 20 #include "components/bookmarks/browser/bookmark_utils.h"
19 #include "components/bookmarks/managed/managed_bookmark_service.h" 21 #include "components/bookmarks/managed/managed_bookmark_service.h"
20 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/user_metrics.h" 25 #include "content/public/browser/user_metrics.h"
24 #include "ui/base/l10n/l10n_util_mac.h" 26 #include "ui/base/l10n/l10n_util_mac.h"
27 #import "ui/gfx/mac/coordinate_conversion.h"
25 28
26 using base::UserMetricsAction; 29 using base::UserMetricsAction;
27 using bookmarks::BookmarkModel; 30 using bookmarks::BookmarkModel;
28 using bookmarks::BookmarkNode; 31 using bookmarks::BookmarkNode;
29 32
33 namespace {
34
35 // Closes the BookmarkBubbleController when the toolkit-views bubble closes.
36 class CocoaViewsBookmarkBubbleObserver
37 : public bookmarks::BookmarkBubbleObserver {
38 public:
39 explicit CocoaViewsBookmarkBubbleObserver(
40 BookmarkBubbleController* controller)
41 : controller_(controller) {}
42 ~CocoaViewsBookmarkBubbleObserver() override {}
43
44 // bookmarks::BookmarkBubbleObserver.
45 void OnBookmarkBubbleShown(const GURL& url) override {}
46 void OnBookmarkBubbleHidden() override { [controller_ close]; }
47
48 private:
49 BookmarkBubbleController* controller_; // Weak, owns us.
50
51 DISALLOW_COPY_AND_ASSIGN(CocoaViewsBookmarkBubbleObserver);
52 };
53
54 } // namespace
55
30 // An object to represent the ChooseAnotherFolder item in the pop up. 56 // An object to represent the ChooseAnotherFolder item in the pop up.
31 @interface ChooseAnotherFolder : NSObject 57 @interface ChooseAnotherFolder : NSObject
32 @end 58 @end
33 59
34 @implementation ChooseAnotherFolder 60 @implementation ChooseAnotherFolder
35 @end 61 @end
36 62
37 @interface BookmarkBubbleController (PrivateAPI) 63 @interface BookmarkBubbleController (PrivateAPI)
38 - (void)updateBookmarkNode; 64 - (void)updateBookmarkNode;
39 - (void)fillInFolderList; 65 - (void)fillInFolderList;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 InfoBubbleView* bubble = self.bubble; 203 InfoBubbleView* bubble = self.bubble;
178 [bubble setArrowLocation:info_bubble::kTopRight]; 204 [bubble setArrowLocation:info_bubble::kTopRight];
179 205
180 // Insure decent positioning even in the absence of a browser controller, 206 // Insure decent positioning even in the absence of a browser controller,
181 // which will occur for some unit tests. 207 // which will occur for some unit tests.
182 NSPoint arrowTip = bwc ? [bwc bookmarkBubblePoint] : 208 NSPoint arrowTip = bwc ? [bwc bookmarkBubblePoint] :
183 NSMakePoint([window frame].size.width, [window frame].size.height); 209 NSMakePoint([window frame].size.width, [window frame].size.height);
184 arrowTip = [parentWindow convertBaseToScreen:arrowTip]; 210 arrowTip = [parentWindow convertBaseToScreen:arrowTip];
185 NSPoint bubbleArrowTip = [bubble arrowTip]; 211 NSPoint bubbleArrowTip = [bubble arrowTip];
186 bubbleArrowTip = [bubble convertPoint:bubbleArrowTip toView:nil]; 212 bubbleArrowTip = [bubble convertPoint:bubbleArrowTip toView:nil];
187 arrowTip.y -= bubbleArrowTip.y; 213 [window setFrameOrigin:NSMakePoint(arrowTip.x - bubbleArrowTip.x,
188 arrowTip.x -= bubbleArrowTip.x; 214 arrowTip.y - bubbleArrowTip.y)];
189 [window setFrameOrigin:arrowTip];
190 215
191 // Default is IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK; "Bookmark". 216 // Default is IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK; "Bookmark".
192 // If adding for the 1st time the string becomes "Bookmark Added!" 217 // If adding for the 1st time the string becomes "Bookmark Added!"
193 if (!alreadyBookmarked_) { 218 if (!alreadyBookmarked_) {
194 NSString* title = 219 NSString* title =
195 l10n_util::GetNSString(IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED); 220 l10n_util::GetNSString(IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED);
196 [bigTitle_ setStringValue:title]; 221 [bigTitle_ setStringValue:title];
197 } 222 }
198 223
199 [self fillInFolderList]; 224 [self fillInFolderList];
200 225
201 // Ping me when things change out from under us. Unlike a normal 226 // Ping me when things change out from under us. Unlike a normal
202 // dialog, the bookmark bubble's cancel: means "don't add this as a 227 // dialog, the bookmark bubble's cancel: means "don't add this as a
203 // bookmark", not "cancel editing". We must take extra care to not 228 // bookmark", not "cancel editing". We must take extra care to not
204 // touch the bookmark in this selector. 229 // touch the bookmark in this selector.
205 bookmarkObserver_.reset( 230 bookmarkObserver_.reset(
206 new BookmarkModelObserverForCocoa(model_, ^(BOOL nodeWasDeleted) { 231 new BookmarkModelObserverForCocoa(model_, ^(BOOL nodeWasDeleted) {
207 // If a watched node was deleted, the pointer to the pulsing button 232 // If a watched node was deleted, the pointer to the pulsing button
208 // is likely stale. 233 // is likely stale.
209 if (nodeWasDeleted) 234 if (nodeWasDeleted)
210 pulsingBookmarkNode_ = NULL; 235 pulsingBookmarkNode_ = NULL;
211 [self dismissWithoutEditing:nil]; 236 [self dismissWithoutEditing:nil];
212 })); 237 }));
213 bookmarkObserver_->StartObservingNode(node_); 238 bookmarkObserver_->StartObservingNode(node_);
214 239
215 // Pulse something interesting on the bookmark bar. 240 // Pulse something interesting on the bookmark bar.
216 [self startPulsingBookmarkButton:node_]; 241 [self startPulsingBookmarkButton:node_];
217 242
243 if (chrome::ToolkitViewsDialogsEnabled()) {
244 if (!bookmarkBubbleObserver_.get())
245 bookmarkBubbleObserver_.reset(new CocoaViewsBookmarkBubbleObserver(self));
246 chrome::ShowBookmarkBubbleViewsAtPoint(
247 gfx::ScreenPointFromNSPoint(arrowTip), [parentWindow contentView],
248 bookmarkBubbleObserver_.get(),
249 chrome::FindBrowserWithWindow(parentWindow), node_->url(),
250 alreadyBookmarked_);
251 return;
252 }
253
218 [parentWindow addChildWindow:window ordered:NSWindowAbove]; 254 [parentWindow addChildWindow:window ordered:NSWindowAbove];
219 [window makeKeyAndOrderFront:self]; 255 [window makeKeyAndOrderFront:self];
220 [self registerKeyStateEventTap]; 256 [self registerKeyStateEventTap];
221 } 257 }
222 258
223 - (void)close { 259 - (void)close {
224 [[BrowserWindowController browserWindowControllerForWindow:self.parentWindow] 260 [[BrowserWindowController browserWindowControllerForWindow:self.parentWindow]
225 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; 261 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO];
226 262
227 [super close]; 263 [super close];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 440 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
405 DCHECK(idx != -1); 441 DCHECK(idx != -1);
406 [folderPopUpButton_ selectItemAtIndex:idx]; 442 [folderPopUpButton_ selectItemAtIndex:idx];
407 } 443 }
408 444
409 - (NSPopUpButton*)folderPopUpButton { 445 - (NSPopUpButton*)folderPopUpButton {
410 return folderPopUpButton_; 446 return folderPopUpButton_;
411 } 447 }
412 448
413 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 449 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698