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

Side by Side Diff: chrome/browser/ui/cocoa/web_intent_bubble_controller.mm

Issue 9581041: Make web intents picker work as constrained dialog instead of InfoBubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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) 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/web_intent_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h"
6 6
7 #include "base/memory/scoped_nsobject.h" 7 #include "base/memory/scoped_nsobject.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
10 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" 10 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 @interface WebIntentsContentView : NSView 66 @interface WebIntentsContentView : NSView
67 @end 67 @end
68 @implementation WebIntentsContentView 68 @implementation WebIntentsContentView
69 - (BOOL)isFlipped { 69 - (BOOL)isFlipped {
70 return YES; 70 return YES;
71 } 71 }
72 @end 72 @end
73 73
74 @implementation WebIntentBubbleController; 74 @implementation WebIntentBubbleController;
75 75
76 - (id)initWithPicker:(WebIntentPickerCocoa*)picker 76 - (id)initWithPicker:(WebIntentPickerCocoa*)picker {
77 parentWindow:(NSWindow*)parent
78 anchoredAt:(NSPoint)point {
79 // Use an arbitrary height because it will reflect the size of the content. 77 // Use an arbitrary height because it will reflect the size of the content.
80 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, kVerticalSpacing); 78 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, kVerticalSpacing);
81 // Create an empty window into which content is placed. 79
82 scoped_nsobject<InfoBubbleWindow> window( 80 // |window| is retained by the ConstrainedWindowMacDelegateCustomSheet when
83 [[InfoBubbleWindow alloc] initWithContentRect:contentRect 81 // the sheet is initialized.
84 styleMask:NSBorderlessWindowMask 82 scoped_nsobject<NSWindow> window;
85 backing:NSBackingStoreBuffered 83 window.reset(
Nico 2012/03/03 06:13:49 Use scoped_ptr's constructor to set the pointer in
groby-ooo-7-16 2012/03/03 23:41:49 Done.
86 defer:NO]); 84 [[NSWindow alloc] initWithContentRect:contentRect
87 if ((self = [super initWithWindow:window.get() 85 styleMask:NSTitledWindowMask
88 parentWindow:parent 86 backing:NSBackingStoreBuffered
89 anchoredAt:point])) { 87 defer:YES]);
88
89 if ((self = [super initWithWindow:window.get()])) {
90 picker_ = picker; 90 picker_ = picker;
91 [self performLayoutWithModel:NULL];
92 }
93 return self;
94 }
91 95
92 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; 96 - (void)sheetDidEnd:(NSWindow*)sheet
93 [self performLayoutWithModel:NULL]; 97 returnCode:(int)returnCode
94 [self showWindow:nil]; 98 contextInfo:(void *)contextInfo {
95 picker_->set_controller(self); 99 // Also called when user navigates to another page while the sheet is open.
Nico 2012/03/03 06:13:49 No space in front of *
groby-ooo-7-16 2012/03/03 23:41:49 Done.
96 } 100 if (picker_)
97 101 picker_->OnSheetDidEnd(sheet);
98 return self;
99 } 102 }
100 103
101 - (void)setInlineDispositionTabContents:(TabContentsWrapper*)wrapper { 104 - (void)setInlineDispositionTabContents:(TabContentsWrapper*)wrapper {
102 contents_ = wrapper; 105 contents_ = wrapper;
103 } 106 }
104 107
105 // We need to watch for window closing so we can notify up via |picker_|.
106 - (void)windowWillClose:(NSNotification*)notification {
107 if (picker_) {
108 WebIntentPickerCocoa* temp = picker_;
109 picker_ = NULL; // Abandon picker, we are done with it.
110 temp->OnCancelled();
111 }
112 [super windowWillClose:notification];
113 }
114
115 // Pop up a new tab with the Chrome Web Store. 108 // Pop up a new tab with the Chrome Web Store.
116 - (IBAction)showChromeWebStore:(id)sender { 109 - (IBAction)showChromeWebStore:(id)sender {
117 GURL url(l10n_util::GetStringUTF8(IDS_WEBSTORE_URL)); 110 GURL url(l10n_util::GetStringUTF8(IDS_WEBSTORE_URL));
118 Browser* browser = BrowserList::GetLastActive(); 111 Browser* browser = BrowserList::GetLastActive();
119 OpenURLParams params( 112 OpenURLParams params(
120 url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, 113 url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK,
121 false); 114 false);
122 browser->OpenURL(params); 115 browser->OpenURL(params);
123 } 116 }
124 117
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 contents_->web_contents()); 205 contents_->web_contents());
213 NSRect frame = NSMakeRect(kFramePadding, offset, size.width(), size.height()); 206 NSRect frame = NSMakeRect(kFramePadding, offset, size.width(), size.height());
214 207
215 [contents_->web_contents()->GetNativeView() setFrame:frame]; 208 [contents_->web_contents()->GetNativeView() setFrame:frame];
216 [subviews addObject:contents_->web_contents()->GetNativeView()]; 209 [subviews addObject:contents_->web_contents()->GetNativeView()];
217 210
218 return NSHeight(frame); 211 return NSHeight(frame);
219 } 212 }
220 213
221 // Add a single button for a specific service 214 // Add a single button for a specific service
222 -(CGFloat)addServiceButton:(NSString*)title 215 - (CGFloat)addServiceButton:(NSString*)title
223 withImage:(NSImage*)image 216 withImage:(NSImage*)image
224 index:(NSUInteger)index 217 index:(NSUInteger)index
225 toSubviews:(NSMutableArray*)subviews 218 toSubviews:(NSMutableArray*)subviews
226 atOffset:(CGFloat)offset { 219 atOffset:(CGFloat)offset {
227 NSRect frame = NSMakeRect(kFramePadding, offset, kServiceButtonWidth, 45); 220 NSRect frame = NSMakeRect(kFramePadding, offset, kServiceButtonWidth, 45);
228 scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:frame]); 221 scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:frame]);
229 222
230 if (image) { 223 if (image) {
231 [button setImage:image]; 224 [button setImage:image];
232 [button setImagePosition:NSImageLeft]; 225 [button setImagePosition:NSImageLeft];
(...skipping 13 matching lines...) Expand all
246 frame = [button frame]; 239 frame = [button frame];
247 frame.size.width = kServiceButtonWidth; 240 frame.size.width = kServiceButtonWidth;
248 [button setFrame:frame]; 241 [button setFrame:frame];
249 242
250 return NSHeight([button frame]); 243 return NSHeight([button frame]);
251 } 244 }
252 245
253 // Layout the contents of the picker bubble. 246 // Layout the contents of the picker bubble.
254 - (void)performLayoutWithModel:(WebIntentPickerModel*)model { 247 - (void)performLayoutWithModel:(WebIntentPickerModel*)model {
255 // |offset| is the Y position that should be drawn at next. 248 // |offset| is the Y position that should be drawn at next.
256 CGFloat offset = kFramePadding + info_bubble::kBubbleArrowHeight; 249 CGFloat offset = kFramePadding;
257 250
258 // Keep the new subviews in an array that gets replaced at the end. 251 // Keep the new subviews in an array that gets replaced at the end.
259 NSMutableArray* subviews = [NSMutableArray array]; 252 NSMutableArray* subviews = [NSMutableArray array];
260 253
261 if (contents_) { 254 if (contents_) {
262 offset += [self addInlineHtmlToSubviews:subviews atOffset:offset]; 255 offset += [self addInlineHtmlToSubviews:subviews atOffset:offset];
263 } else { 256 } else {
264 offset += [self addHeaderToSubviews:subviews atOffset:offset]; 257 offset += [self addHeaderToSubviews:subviews atOffset:offset];
265 if (model) { 258 if (model) {
266 for (NSUInteger i = 0; i < model->GetInstalledServiceCount(); ++i) { 259 for (NSUInteger i = 0; i < model->GetInstalledServiceCount(); ++i) {
(...skipping 16 matching lines...) Expand all
283 NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, offset); 276 NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, offset);
284 scoped_nsobject<WebIntentsContentView> contentView( 277 scoped_nsobject<WebIntentsContentView> contentView(
285 [[WebIntentsContentView alloc] initWithFrame:contentFrame]); 278 [[WebIntentsContentView alloc] initWithFrame:contentFrame]);
286 [contentView setSubviews:subviews]; 279 [contentView setSubviews:subviews];
287 [contentView setAutoresizingMask:NSViewMinYMargin]; 280 [contentView setAutoresizingMask:NSViewMinYMargin];
288 281
289 // Adjust frame to fit all elements. 282 // Adjust frame to fit all elements.
290 NSRect windowFrame = NSMakeRect(0, 0, kWindowWidth, offset); 283 NSRect windowFrame = NSMakeRect(0, 0, kWindowWidth, offset);
291 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size 284 windowFrame.size = [[[self window] contentView] convertSize:windowFrame.size
292 toView:nil]; 285 toView:nil];
293 // Adjust the origin by the difference in height.
294 windowFrame.origin = [[self window] frame].origin;
295 windowFrame.origin.y -= NSHeight(windowFrame) -
296 NSHeight([[self window] frame]);
297 286
287 // Adjust the window frame to accomodate the content.
288 windowFrame=[[self window] frameRectForContentRect:windowFrame];
Nico 2012/03/03 06:13:49 indent looks off
groby-ooo-7-16 2012/03/03 23:41:49 Done.
298 [[self window] setFrame:windowFrame display:YES animate:YES]; 289 [[self window] setFrame:windowFrame display:YES animate:YES];
299 290
300 // Replace the window's content. 291 // Replace the window's content.
301 [[[self window] contentView] setSubviews: 292 [[[self window] contentView] setSubviews:
302 [NSArray arrayWithObject:contentView]]; 293 [NSArray arrayWithObject:contentView]];
303 } 294 }
304 295
296 - (void)closeSheet {
297 [NSApp endSheet:[self window]];
298 }
305 @end // WebIntentBubbleController 299 @end // WebIntentBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698