OLD | NEW |
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_sheet_controller.h" | 5 #import "chrome/browser/ui/cocoa/web_intent_sheet_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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "ui/base/l10n/l10n_util_mac.h" | 28 #include "ui/base/l10n/l10n_util_mac.h" |
29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
30 #include "ui/base/text/text_elider.h" | 30 #include "ui/base/text/text_elider.h" |
31 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
32 | 32 |
33 using content::OpenURLParams; | 33 using content::OpenURLParams; |
34 using content::Referrer; | 34 using content::Referrer; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // The width of the window, in view coordinates. The height will be | |
39 // determined by the content. | |
40 const CGFloat kWindowWidth = 400; | |
41 | |
42 // The maximum width in view units of a suggested extension's title link. | |
43 const int kTitleLinkMaxWidth = 130; | |
44 | |
45 // The width of a service button, in view coordinates. | 38 // The width of a service button, in view coordinates. |
46 const CGFloat kServiceButtonWidth = 300; | 39 const CGFloat kServiceButtonWidth = 300; |
47 | 40 |
48 // Padding along on the X-axis between the window frame and content. | |
49 const CGFloat kFramePadding = 10; | |
50 | |
51 // Spacing in between sections. | 41 // Spacing in between sections. |
52 const CGFloat kVerticalSpacing = 10; | 42 const CGFloat kVerticalSpacing = 10; |
53 | 43 |
54 // Square size of the close button. | 44 // Square size of the close button. |
55 const CGFloat kCloseButtonSize = 16; | 45 const CGFloat kCloseButtonSize = 16; |
56 | 46 |
57 // Font size for picker header. | 47 // Font size for picker header. |
58 const CGFloat kHeaderFontSize = 14.5; | 48 const CGFloat kHeaderFontSize = 14.5; |
59 | 49 |
60 // Width of the text fields. | 50 // Width of the text fields. |
61 const CGFloat kTextWidth = kWindowWidth - | 51 const CGFloat kTextWidth = WebIntentPicker::kWindowWidth - |
62 (kFramePadding * 2 + kCloseButtonSize); | 52 (WebIntentPicker::kContentAreaBorder * 2.0 + kCloseButtonSize); |
63 | 53 |
64 // Sets properties on the given |field| to act as title or description labels. | 54 // Sets properties on the given |field| to act as title or description labels. |
65 void ConfigureTextFieldAsLabel(NSTextField* field) { | 55 void ConfigureTextFieldAsLabel(NSTextField* field) { |
66 [field setEditable:NO]; | 56 [field setEditable:NO]; |
67 [field setSelectable:YES]; | 57 [field setSelectable:YES]; |
68 [field setDrawsBackground:NO]; | 58 [field setDrawsBackground:NO]; |
69 [field setBezeled:NO]; | 59 [field setBezeled:NO]; |
70 } | 60 } |
71 | 61 |
72 NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) { | 62 NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 (const WebIntentPickerModel::SuggestedExtension*)extension | 179 (const WebIntentPickerModel::SuggestedExtension*)extension |
190 withIndex:(size_t)index | 180 withIndex:(size_t)index |
191 forController:(WebIntentPickerSheetController*)controller { | 181 forController:(WebIntentPickerSheetController*)controller { |
192 const CGFloat kMaxHeight = 34.0; | 182 const CGFloat kMaxHeight = 34.0; |
193 const CGFloat kTitleX = 20.0; | 183 const CGFloat kTitleX = 20.0; |
194 const CGFloat kMinAddButtonHeight = 24.0; | 184 const CGFloat kMinAddButtonHeight = 24.0; |
195 const CGFloat kAddButtonX = 245; | 185 const CGFloat kAddButtonX = 245; |
196 const CGFloat kAddButtonWidth = 128.0; | 186 const CGFloat kAddButtonWidth = 128.0; |
197 | 187 |
198 // Build the main view | 188 // Build the main view |
199 NSRect contentFrame = NSMakeRect(0, 0, kWindowWidth, kMaxHeight); | 189 NSRect contentFrame = NSMakeRect( |
| 190 0, 0, WebIntentPicker::kWindowWidth, kMaxHeight); |
200 if (self = [super initWithFrame:contentFrame]) { | 191 if (self = [super initWithFrame:contentFrame]) { |
201 NSMutableArray* subviews = [NSMutableArray array]; | 192 NSMutableArray* subviews = [NSMutableArray array]; |
202 | 193 |
203 // Add the extension icon. | 194 // Add the extension icon. |
204 NSImage* icon = extension->icon.ToNSImage(); | 195 NSImage* icon = extension->icon.ToNSImage(); |
205 NSRect imageFrame = NSZeroRect; | 196 NSRect imageFrame = NSZeroRect; |
206 | 197 |
207 iconView_.reset( | 198 iconView_.reset( |
208 [[DimmableImageView alloc] initWithFrame:imageFrame]); | 199 [[DimmableImageView alloc] initWithFrame:imageFrame]); |
209 [iconView_ setImage:icon]; | 200 [iconView_ setImage:icon]; |
210 [iconView_ setImageFrameStyle:NSImageFrameNone]; | 201 [iconView_ setImageFrameStyle:NSImageFrameNone]; |
211 [iconView_ setEnabled:YES]; | 202 [iconView_ setEnabled:YES]; |
212 | 203 |
213 imageFrame.size = [icon size]; | 204 imageFrame.size = [icon size]; |
214 imageFrame.size.height = std::min(NSHeight(imageFrame), kMaxHeight); | 205 imageFrame.size.height = std::min(NSHeight(imageFrame), kMaxHeight); |
215 imageFrame.origin.y += (kMaxHeight - NSHeight(imageFrame)) / 2.0; | 206 imageFrame.origin.y += (kMaxHeight - NSHeight(imageFrame)) / 2.0; |
216 [iconView_ setFrame:imageFrame]; | 207 [iconView_ setFrame:imageFrame]; |
217 [subviews addObject:iconView_]; | 208 [subviews addObject:iconView_]; |
218 | 209 |
219 // Add the extension title. | 210 // Add the extension title. |
220 NSRect frame = NSMakeRect(kTitleX, 0, 0, 0); | 211 NSRect frame = NSMakeRect(kTitleX, 0, 0, 0); |
221 | 212 |
222 const string16 elidedTitle = ui::ElideText( | 213 const string16 elidedTitle = ui::ElideText( |
223 extension->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END); | 214 extension->title, gfx::Font(), WebIntentPicker::kTitleLinkMaxWidth, |
| 215 ui::ELIDE_AT_END); |
224 NSString* string = base::SysUTF16ToNSString(elidedTitle); | 216 NSString* string = base::SysUTF16ToNSString(elidedTitle); |
225 cwsButton_.reset(CreateHyperlinkButton(string, frame)); | 217 cwsButton_.reset(CreateHyperlinkButton(string, frame)); |
226 [cwsButton_ setAlignment:NSLeftTextAlignment]; | 218 [cwsButton_ setAlignment:NSLeftTextAlignment]; |
227 [cwsButton_ setTarget:controller]; | 219 [cwsButton_ setTarget:controller]; |
228 [cwsButton_ setAction:@selector(openExtensionLink:)]; | 220 [cwsButton_ setAction:@selector(openExtensionLink:)]; |
229 [cwsButton_ setTag:index]; | 221 [cwsButton_ setTag:index]; |
230 [cwsButton_ sizeToFit]; | 222 [cwsButton_ sizeToFit]; |
231 | 223 |
232 frame = [cwsButton_ frame]; | 224 frame = [cwsButton_ frame]; |
233 frame.size.height = std::min([[cwsButton_ cell] cellSize].height, | 225 frame.size.height = std::min([[cwsButton_ cell] cellSize].height, |
234 kMaxHeight); | 226 kMaxHeight); |
235 frame.origin.y = (kMaxHeight - NSHeight(frame)) / 2.0; | 227 frame.origin.y = (kMaxHeight - NSHeight(frame)) / 2.0; |
236 [cwsButton_ setFrame:frame]; | 228 [cwsButton_ setFrame:frame]; |
237 [subviews addObject:cwsButton_]; | 229 [subviews addObject:cwsButton_]; |
238 | 230 |
239 // Add the star rating | 231 // Add the star rating |
240 CGFloat offsetX = frame.origin.x + NSWidth(frame) + kFramePadding; | 232 CGFloat offsetX = frame.origin.x + NSWidth(frame) + |
| 233 WebIntentPicker::kContentAreaBorder; |
241 ratingsWidget_.reset( | 234 ratingsWidget_.reset( |
242 [SingleSuggestionView | 235 [SingleSuggestionView |
243 createStarWidgetWithRating:extension->average_rating]); | 236 createStarWidgetWithRating:extension->average_rating]); |
244 frame = [ratingsWidget_ frame]; | 237 frame = [ratingsWidget_ frame]; |
245 frame.origin.y += (kMaxHeight - NSHeight(frame)) / 2.0; | 238 frame.origin.y += (kMaxHeight - NSHeight(frame)) / 2.0; |
246 frame.origin.x = offsetX; | 239 frame.origin.x = offsetX; |
247 [ratingsWidget_ setFrame: frame]; | 240 [ratingsWidget_ setFrame: frame]; |
248 [subviews addObject:ratingsWidget_]; | 241 [subviews addObject:ratingsWidget_]; |
249 | 242 |
250 // Add an "add to chromium" button. | 243 // Add an "add to chromium" button. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 atOffset:offset]; | 370 atOffset:offset]; |
378 } | 371 } |
379 | 372 |
380 [self updateSuggestionLabelForModel:model]; | 373 [self updateSuggestionLabelForModel:model]; |
381 offset += [self addStackedView:suggestionLabel_ | 374 offset += [self addStackedView:suggestionLabel_ |
382 toSubviews:subviews | 375 toSubviews:subviews |
383 atOffset:offset]; | 376 atOffset:offset]; |
384 | 377 |
385 offset += kYMargin; | 378 offset += kYMargin; |
386 | 379 |
387 NSRect contentFrame = NSMakeRect(kFramePadding, 0, kWindowWidth, offset); | 380 NSRect contentFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, 0, |
| 381 WebIntentPicker::kWindowWidth, offset); |
388 if(self = [super initWithFrame:contentFrame]) | 382 if(self = [super initWithFrame:contentFrame]) |
389 [self setSubviews: subviews]; | 383 [self setSubviews: subviews]; |
390 | 384 |
391 controller_ = controller; | 385 controller_ = controller; |
392 return self; | 386 return self; |
393 } | 387 } |
394 | 388 |
395 - (void)updateSuggestionLabelForModel:(WebIntentPickerModel*)model { | 389 - (void)updateSuggestionLabelForModel:(WebIntentPickerModel*)model { |
396 DCHECK(suggestionLabel_.get()); | 390 DCHECK(suggestionLabel_.get()); |
397 string16 labelText = model->GetSuggestionsLinkText(); | 391 string16 labelText = model->GetSuggestionsLinkText(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 [subviews addObject:view]; | 441 [subviews addObject:view]; |
448 | 442 |
449 return NSHeight([view frame]); | 443 return NSHeight([view frame]); |
450 } | 444 } |
451 @end | 445 @end |
452 | 446 |
453 @implementation WebIntentPickerSheetController; | 447 @implementation WebIntentPickerSheetController; |
454 | 448 |
455 - (id)initWithPicker:(WebIntentPickerCocoa*)picker { | 449 - (id)initWithPicker:(WebIntentPickerCocoa*)picker { |
456 // Use an arbitrary height because it will reflect the size of the content. | 450 // Use an arbitrary height because it will reflect the size of the content. |
457 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, kVerticalSpacing); | 451 NSRect contentRect = NSMakeRect( |
| 452 0, 0, WebIntentPicker::kWindowWidth, kVerticalSpacing); |
458 | 453 |
459 // |window| is retained by the ConstrainedWindowMacDelegateCustomSheet when | 454 // |window| is retained by the ConstrainedWindowMacDelegateCustomSheet when |
460 // the sheet is initialized. | 455 // the sheet is initialized. |
461 scoped_nsobject<NSWindow> window( | 456 scoped_nsobject<NSWindow> window( |
462 [[NSWindow alloc] initWithContentRect:contentRect | 457 [[NSWindow alloc] initWithContentRect:contentRect |
463 styleMask:NSTitledWindowMask | 458 styleMask:NSTitledWindowMask |
464 backing:NSBackingStoreBuffered | 459 backing:NSBackingStoreBuffered |
465 defer:YES]); | 460 defer:YES]); |
466 if ((self = [super initWithWindow:window.get()])) { | 461 if ((self = [super initWithWindow:window.get()])) { |
467 picker_ = picker; | 462 picker_ = picker; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 contents_ = tabContents; | 510 contents_ = tabContents; |
516 } | 511 } |
517 | 512 |
518 - (void)setInlineDispositionFrameSize:(NSSize)inlineContentSize { | 513 - (void)setInlineDispositionFrameSize:(NSSize)inlineContentSize { |
519 DCHECK(contents_); | 514 DCHECK(contents_); |
520 | 515 |
521 NSView* webContentView = contents_->web_contents()->GetNativeView(); | 516 NSView* webContentView = contents_->web_contents()->GetNativeView(); |
522 | 517 |
523 // Compute container size to fit all elements, including padding. | 518 // Compute container size to fit all elements, including padding. |
524 NSSize containerSize = inlineContentSize; | 519 NSSize containerSize = inlineContentSize; |
525 containerSize.height += [webContentView frame].origin.y + kFramePadding; | 520 containerSize.height += |
526 containerSize.width += 2 * kFramePadding; | 521 [webContentView frame].origin.y + WebIntentPicker::kContentAreaBorder; |
| 522 containerSize.width += 2 * WebIntentPicker::kContentAreaBorder; |
527 | 523 |
528 // Ensure minimum container width. | 524 // Ensure minimum container width. |
529 containerSize.width = std::max(kWindowWidth, containerSize.width); | 525 containerSize.width = |
| 526 std::max(CGFloat(WebIntentPicker::kWindowWidth), containerSize.width); |
530 | 527 |
531 // Resize web contents. | 528 // Resize web contents. |
532 [webContentView setFrameSize:inlineContentSize]; | 529 [webContentView setFrameSize:inlineContentSize]; |
533 | 530 |
534 // Position close button. | 531 // Position close button. |
535 NSRect buttonFrame = [closeButton_ frame]; | 532 NSRect buttonFrame = [closeButton_ frame]; |
536 buttonFrame.origin.x = containerSize.width - kFramePadding - kCloseButtonSize; | 533 buttonFrame.origin.x = containerSize.width - |
| 534 WebIntentPicker::kContentAreaBorder - kCloseButtonSize; |
537 [closeButton_ setFrame:buttonFrame]; | 535 [closeButton_ setFrame:buttonFrame]; |
538 | 536 |
539 [self setContainerSize:containerSize]; | 537 [self setContainerSize:containerSize]; |
540 } | 538 } |
541 | 539 |
542 - (void)setContainerSize:(NSSize)containerSize { | 540 - (void)setContainerSize:(NSSize)containerSize { |
543 // Resize container views | 541 // Resize container views |
544 NSRect frame = NSMakeRect(0, 0, 0, 0); | 542 NSRect frame = NSMakeRect(0, 0, 0, 0); |
545 frame.size = containerSize; | 543 frame.size = containerSize; |
546 [[[self window] contentView] setFrame:frame]; | 544 [[[self window] contentView] setFrame:frame]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 [view setFrameOrigin:frameOrigin]; | 608 [view setFrameOrigin:frameOrigin]; |
611 [subviews addObject:view]; | 609 [subviews addObject:view]; |
612 | 610 |
613 return NSHeight([view frame]); | 611 return NSHeight([view frame]); |
614 } | 612 } |
615 | 613 |
616 // Adds a link to the Chrome Web Store, to obtain further intent handlers. | 614 // Adds a link to the Chrome Web Store, to obtain further intent handlers. |
617 // Returns the y position delta for the next offset. | 615 // Returns the y position delta for the next offset. |
618 - (CGFloat)addCwsButtonToSubviews:(NSMutableArray*)subviews | 616 - (CGFloat)addCwsButtonToSubviews:(NSMutableArray*)subviews |
619 atOffset:(CGFloat)offset { | 617 atOffset:(CGFloat)offset { |
620 NSRect frame = NSMakeRect(kFramePadding, offset, 100, 10); | 618 NSRect frame = |
| 619 NSMakeRect(WebIntentPicker::kContentAreaBorder, offset, 100, 10); |
621 NSString* string = | 620 NSString* string = |
622 l10n_util::GetNSStringWithFixup(IDS_FIND_MORE_INTENT_HANDLER_MESSAGE); | 621 l10n_util::GetNSStringWithFixup(IDS_FIND_MORE_INTENT_HANDLER_MESSAGE); |
623 scoped_nsobject<NSButton> button(CreateHyperlinkButton(string,frame)); | 622 scoped_nsobject<NSButton> button(CreateHyperlinkButton(string,frame)); |
624 [button setTarget:self]; | 623 [button setTarget:self]; |
625 [button setAction:@selector(showChromeWebStore:)]; | 624 [button setAction:@selector(showChromeWebStore:)]; |
626 [subviews addObject:button.get()]; | 625 [subviews addObject:button.get()]; |
627 | 626 |
628 // Call size-to-fit to fixup for the localized string. | 627 // Call size-to-fit to fixup for the localized string. |
629 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; | 628 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; |
630 | 629 |
631 return NSHeight([button frame]); | 630 return NSHeight([button frame]); |
632 } | 631 } |
633 | 632 |
634 - (void)addCloseButtonToSubviews:(NSMutableArray*)subviews { | 633 - (void)addCloseButtonToSubviews:(NSMutableArray*)subviews { |
635 if (!closeButton_.get()) { | 634 if (!closeButton_.get()) { |
636 NSRect buttonFrame = NSMakeRect( | 635 NSRect buttonFrame = NSMakeRect( |
637 kFramePadding + kTextWidth, kFramePadding, | 636 WebIntentPicker::kContentAreaBorder + kTextWidth, |
| 637 WebIntentPicker::kContentAreaBorder, |
638 kCloseButtonSize, kCloseButtonSize); | 638 kCloseButtonSize, kCloseButtonSize); |
639 closeButton_.reset( | 639 closeButton_.reset( |
640 [[HoverCloseButton alloc] initWithFrame:buttonFrame]); | 640 [[HoverCloseButton alloc] initWithFrame:buttonFrame]); |
641 [closeButton_ setTarget:self]; | 641 [closeButton_ setTarget:self]; |
642 [closeButton_ setAction:@selector(cancelOperation:)]; | 642 [closeButton_ setAction:@selector(cancelOperation:)]; |
643 } | 643 } |
644 [subviews addObject:closeButton_]; | 644 [subviews addObject:closeButton_]; |
645 } | 645 } |
646 | 646 |
647 // Adds a header (icon and explanatory text) to picker bubble. | 647 // Adds a header (icon and explanatory text) to picker bubble. |
(...skipping 18 matching lines...) Expand all Loading... |
666 return NSHeight([actionTextField_ frame]); | 666 return NSHeight([actionTextField_ frame]); |
667 } | 667 } |
668 | 668 |
669 - (CGFloat)addInlineHtmlToSubviews:(NSMutableArray*)subviews | 669 - (CGFloat)addInlineHtmlToSubviews:(NSMutableArray*)subviews |
670 atOffset:(CGFloat)offset { | 670 atOffset:(CGFloat)offset { |
671 if (!contents_) | 671 if (!contents_) |
672 return 0; | 672 return 0; |
673 | 673 |
674 // Determine a good size for the inline disposition window. | 674 // Determine a good size for the inline disposition window. |
675 gfx::Size size = WebIntentPicker::GetMinInlineDispositionSize(); | 675 gfx::Size size = WebIntentPicker::GetMinInlineDispositionSize(); |
676 NSRect frame = NSMakeRect(kFramePadding, offset, size.width(), size.height()); | 676 NSRect frame = NSMakeRect( |
| 677 WebIntentPicker::kContentAreaBorder, offset, size.width(), size.height()); |
677 | 678 |
678 [contents_->web_contents()->GetNativeView() setFrame:frame]; | 679 [contents_->web_contents()->GetNativeView() setFrame:frame]; |
679 [subviews addObject:contents_->web_contents()->GetNativeView()]; | 680 [subviews addObject:contents_->web_contents()->GetNativeView()]; |
680 | 681 |
681 return NSHeight(frame); | 682 return NSHeight(frame); |
682 } | 683 } |
683 | 684 |
684 - (CGFloat)addAnotherServiceLinkToSubviews:(NSMutableArray*)subviews | 685 - (CGFloat)addAnotherServiceLinkToSubviews:(NSMutableArray*)subviews |
685 atOffset:(CGFloat)offset { | 686 atOffset:(CGFloat)offset { |
686 | 687 |
687 NSRect textFrame = NSMakeRect(kFramePadding, offset, kTextWidth, 1); | 688 NSRect textFrame = |
| 689 NSMakeRect(WebIntentPicker::kContentAreaBorder, offset, kTextWidth, 1); |
688 [inlineDispositionTitleField_ setFrame:textFrame]; | 690 [inlineDispositionTitleField_ setFrame:textFrame]; |
689 [subviews addObject:inlineDispositionTitleField_]; | 691 [subviews addObject:inlineDispositionTitleField_]; |
690 [GTMUILocalizerAndLayoutTweaker sizeToFitView:inlineDispositionTitleField_]; | 692 [GTMUILocalizerAndLayoutTweaker sizeToFitView:inlineDispositionTitleField_]; |
691 textFrame = [inlineDispositionTitleField_ frame]; | 693 textFrame = [inlineDispositionTitleField_ frame]; |
692 | 694 |
693 // Add link for "choose another service" if other suggestions are available | 695 // Add link for "choose another service" if other suggestions are available |
694 // or if more than one (the current) service is installed. | 696 // or if more than one (the current) service is installed. |
695 if (model_->GetInstalledServiceCount() > 1 || | 697 if (model_->GetInstalledServiceCount() > 1 || |
696 model_->GetSuggestedExtensionCount()) { | 698 model_->GetSuggestedExtensionCount()) { |
697 NSRect frame = NSMakeRect( | 699 NSRect frame = NSMakeRect( |
698 NSMaxX(textFrame) + kFramePadding, offset, | 700 NSMaxX(textFrame) + WebIntentPicker::kContentAreaBorder, offset, |
699 kTitleLinkMaxWidth, 1); | 701 WebIntentPicker::kTitleLinkMaxWidth, 1); |
700 NSString* string = l10n_util::GetNSStringWithFixup( | 702 NSString* string = l10n_util::GetNSStringWithFixup( |
701 IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE); | 703 IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE); |
702 scoped_nsobject<NSButton> button(CreateHyperlinkButton(string, frame)); | 704 scoped_nsobject<NSButton> button(CreateHyperlinkButton(string, frame)); |
703 [[button cell] setControlSize:NSRegularControlSize]; | 705 [[button cell] setControlSize:NSRegularControlSize]; |
704 [button setTarget:self]; | 706 [button setTarget:self]; |
705 [button setAction:@selector(chooseAnotherService:)]; | 707 [button setAction:@selector(chooseAnotherService:)]; |
706 [subviews addObject:button]; | 708 [subviews addObject:button]; |
707 | 709 |
708 // Call size-to-fit to fixup for the localized string. | 710 // Call size-to-fit to fixup for the localized string. |
709 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button]; | 711 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button]; |
(...skipping 12 matching lines...) Expand all Loading... |
722 return NSHeight(textFrame); | 724 return NSHeight(textFrame); |
723 } | 725 } |
724 | 726 |
725 // Add a single button for a specific service | 727 // Add a single button for a specific service |
726 - (CGFloat)addServiceButton:(NSString*)title | 728 - (CGFloat)addServiceButton:(NSString*)title |
727 withImage:(NSImage*)image | 729 withImage:(NSImage*)image |
728 index:(NSUInteger)index | 730 index:(NSUInteger)index |
729 toSubviews:(NSMutableArray*)subviews | 731 toSubviews:(NSMutableArray*)subviews |
730 atOffset:(CGFloat)offset { | 732 atOffset:(CGFloat)offset { |
731 // Buttons are displayed centered. | 733 // Buttons are displayed centered. |
732 CGFloat offsetX = (kWindowWidth - kServiceButtonWidth) / 2.0; | 734 CGFloat offsetX = (WebIntentPicker::kWindowWidth - kServiceButtonWidth) / 2.0; |
733 NSRect frame = NSMakeRect(offsetX, offset, kServiceButtonWidth, 45); | 735 NSRect frame = NSMakeRect(offsetX, offset, kServiceButtonWidth, 45); |
734 scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:frame]); | 736 scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:frame]); |
735 | 737 |
736 if (image) { | 738 if (image) { |
737 [button setImage:image]; | 739 [button setImage:image]; |
738 [button setImagePosition:NSImageLeft]; | 740 [button setImagePosition:NSImageLeft]; |
739 } | 741 } |
740 [button setAlignment:NSLeftTextAlignment]; | 742 [button setAlignment:NSLeftTextAlignment]; |
741 [button setButtonType:NSMomentaryPushInButton]; | 743 [button setButtonType:NSMomentaryPushInButton]; |
742 [button setBezelStyle:NSRegularSquareBezelStyle]; | 744 [button setBezelStyle:NSRegularSquareBezelStyle]; |
(...skipping 11 matching lines...) Expand all Loading... |
754 frame = [button frame]; | 756 frame = [button frame]; |
755 frame.size.width = kServiceButtonWidth; | 757 frame.size.width = kServiceButtonWidth; |
756 [button setFrame:frame]; | 758 [button setFrame:frame]; |
757 | 759 |
758 return NSHeight([button frame]); | 760 return NSHeight([button frame]); |
759 } | 761 } |
760 | 762 |
761 - (NSView*)createEmptyView { | 763 - (NSView*)createEmptyView { |
762 NSMutableArray* subviews = [NSMutableArray array]; | 764 NSMutableArray* subviews = [NSMutableArray array]; |
763 | 765 |
764 NSRect titleFrame = NSMakeRect(kFramePadding, kFramePadding, | 766 NSRect titleFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, |
| 767 WebIntentPicker::kContentAreaBorder, |
765 kTextWidth, 1); | 768 kTextWidth, 1); |
766 scoped_nsobject<NSTextField> title( | 769 scoped_nsobject<NSTextField> title( |
767 [[NSTextField alloc] initWithFrame:titleFrame]); | 770 [[NSTextField alloc] initWithFrame:titleFrame]); |
768 ConfigureTextFieldAsLabel(title); | 771 ConfigureTextFieldAsLabel(title); |
769 [title setFont:[NSFont systemFontOfSize:kHeaderFontSize]]; | 772 [title setFont:[NSFont systemFontOfSize:kHeaderFontSize]]; |
770 [title setStringValue: | 773 [title setStringValue: |
771 l10n_util::GetNSStringWithFixup(IDS_INTENT_PICKER_NO_SERVICES_TITLE)]; | 774 l10n_util::GetNSStringWithFixup(IDS_INTENT_PICKER_NO_SERVICES_TITLE)]; |
772 titleFrame.size.height += | 775 titleFrame.size.height += |
773 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title]; | 776 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title]; |
774 | 777 |
775 NSRect bodyFrame = titleFrame; | 778 NSRect bodyFrame = titleFrame; |
776 bodyFrame.origin.y += NSHeight(titleFrame) + kFramePadding; | 779 bodyFrame.origin.y += |
| 780 NSHeight(titleFrame) + WebIntentPicker::kContentAreaBorder; |
777 | 781 |
778 scoped_nsobject<NSTextField> body( | 782 scoped_nsobject<NSTextField> body( |
779 [[NSTextField alloc] initWithFrame:bodyFrame]); | 783 [[NSTextField alloc] initWithFrame:bodyFrame]); |
780 ConfigureTextFieldAsLabel(body); | 784 ConfigureTextFieldAsLabel(body); |
781 [body setStringValue: | 785 [body setStringValue: |
782 l10n_util::GetNSStringWithFixup(IDS_INTENT_PICKER_NO_SERVICES)]; | 786 l10n_util::GetNSStringWithFixup(IDS_INTENT_PICKER_NO_SERVICES)]; |
783 bodyFrame.size.height += | 787 bodyFrame.size.height += |
784 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:body]; | 788 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:body]; |
785 NSRect viewFrame = NSMakeRect( | 789 NSRect viewFrame = NSMakeRect( |
786 0, | 790 0, |
787 kFramePadding, | 791 WebIntentPicker::kContentAreaBorder, |
788 std::max(NSWidth(bodyFrame), NSWidth(titleFrame)) + 2 * kFramePadding, | 792 std::max(NSWidth(bodyFrame), NSWidth(titleFrame)) + |
| 793 2 * WebIntentPicker::kContentAreaBorder, |
789 NSHeight(titleFrame) + NSHeight(bodyFrame) + kVerticalSpacing); | 794 NSHeight(titleFrame) + NSHeight(bodyFrame) + kVerticalSpacing); |
790 | 795 |
791 titleFrame.origin.y = NSHeight(viewFrame) - NSHeight(titleFrame); | 796 titleFrame.origin.y = NSHeight(viewFrame) - NSHeight(titleFrame); |
792 bodyFrame.origin.y = 0; | 797 bodyFrame.origin.y = 0; |
793 | 798 |
794 [title setFrame:titleFrame]; | 799 [title setFrame:titleFrame]; |
795 [body setFrame: bodyFrame]; | 800 [body setFrame: bodyFrame]; |
796 | 801 |
797 [subviews addObject:title]; | 802 [subviews addObject:title]; |
798 [subviews addObject:body]; | 803 [subviews addObject:body]; |
799 | 804 |
800 NSView* view = [[NSView alloc] initWithFrame:viewFrame]; | 805 NSView* view = [[NSView alloc] initWithFrame:viewFrame]; |
801 [view setAutoresizingMask:NSViewMinYMargin ]; | 806 [view setAutoresizingMask:NSViewMinYMargin ]; |
802 [view setSubviews:subviews]; | 807 [view setSubviews:subviews]; |
803 | 808 |
804 return view; | 809 return view; |
805 } | 810 } |
806 | 811 |
807 - (void)performLayoutWithModel:(WebIntentPickerModel*)model { | 812 - (void)performLayoutWithModel:(WebIntentPickerModel*)model { |
808 model_ = model; | 813 model_ = model; |
809 | 814 |
810 // |offset| is the Y position that should be drawn at next. | 815 // |offset| is the Y position that should be drawn at next. |
811 CGFloat offset = kFramePadding; | 816 CGFloat offset = WebIntentPicker::kContentAreaBorder; |
812 | 817 |
813 // Keep the new subviews in an array that gets replaced at the end. | 818 // Keep the new subviews in an array that gets replaced at the end. |
814 NSMutableArray* subviews = [NSMutableArray array]; | 819 NSMutableArray* subviews = [NSMutableArray array]; |
815 | 820 |
816 if (isEmpty_) { | 821 if (isEmpty_) { |
817 scoped_nsobject<NSView> emptyView([self createEmptyView]); | 822 scoped_nsobject<NSView> emptyView([self createEmptyView]); |
818 [subviews addObject:emptyView]; | 823 [subviews addObject:emptyView]; |
819 offset += NSHeight([emptyView frame]); | 824 offset += NSHeight([emptyView frame]); |
820 } else if (contents_) { | 825 } else if (contents_) { |
821 offset += [self addAnotherServiceLinkToSubviews:subviews | 826 offset += [self addAnotherServiceLinkToSubviews:subviews |
822 atOffset:offset]; | 827 atOffset:offset]; |
823 offset += kFramePadding; | 828 offset += WebIntentPicker::kContentAreaBorder; |
824 offset += [self addInlineHtmlToSubviews:subviews atOffset:offset]; | 829 offset += [self addInlineHtmlToSubviews:subviews atOffset:offset]; |
825 } else { | 830 } else { |
826 offset += [self addHeaderToSubviews:subviews atOffset:offset]; | 831 offset += [self addHeaderToSubviews:subviews atOffset:offset]; |
827 | 832 |
828 offset += kVerticalSpacing; | 833 offset += kVerticalSpacing; |
829 | 834 |
830 if (model) { | 835 if (model) { |
831 [intentButtons_ removeAllObjects]; | 836 [intentButtons_ removeAllObjects]; |
832 | 837 |
833 for (NSUInteger i = 0; i < model->GetInstalledServiceCount(); ++i) { | 838 for (NSUInteger i = 0; i < model->GetInstalledServiceCount(); ++i) { |
(...skipping 19 matching lines...) Expand all Loading... |
853 } | 858 } |
854 [self addCloseButtonToSubviews:subviews]; | 859 [self addCloseButtonToSubviews:subviews]; |
855 | 860 |
856 // Add the bottom padding. | 861 // Add the bottom padding. |
857 offset += kVerticalSpacing; | 862 offset += kVerticalSpacing; |
858 | 863 |
859 // Replace the window's content. | 864 // Replace the window's content. |
860 [flipView_ setSubviews:subviews]; | 865 [flipView_ setSubviews:subviews]; |
861 | 866 |
862 // And resize to fit. | 867 // And resize to fit. |
863 [self setContainerSize:NSMakeSize(kWindowWidth, offset)]; | 868 [self setContainerSize:NSMakeSize(WebIntentPicker::kWindowWidth, offset)]; |
864 } | 869 } |
865 | 870 |
866 - (void)setActionString:(NSString*)actionString { | 871 - (void)setActionString:(NSString*)actionString { |
867 NSRect textFrame; | 872 NSRect textFrame; |
868 if (!actionTextField_.get()) { | 873 if (!actionTextField_.get()) { |
869 textFrame = NSMakeRect(kFramePadding, 0, | 874 textFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, 0, |
870 kTextWidth, 1); | 875 kTextWidth, 1); |
871 | 876 |
872 actionTextField_.reset([[NSTextField alloc] initWithFrame:textFrame]); | 877 actionTextField_.reset([[NSTextField alloc] initWithFrame:textFrame]); |
873 ConfigureTextFieldAsLabel(actionTextField_); | 878 ConfigureTextFieldAsLabel(actionTextField_); |
874 [actionTextField_ setFont:[NSFont systemFontOfSize:kHeaderFontSize]]; | 879 [actionTextField_ setFont:[NSFont systemFontOfSize:kHeaderFontSize]]; |
875 } else { | 880 } else { |
876 textFrame = [actionTextField_ frame]; | 881 textFrame = [actionTextField_ frame]; |
877 } | 882 } |
878 | 883 |
879 [actionTextField_ setStringValue:actionString]; | 884 [actionTextField_ setStringValue:actionString]; |
880 textFrame.size.height += | 885 textFrame.size.height += |
881 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: | 886 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: |
882 actionTextField_]; | 887 actionTextField_]; |
883 [actionTextField_ setFrame: textFrame]; | 888 [actionTextField_ setFrame: textFrame]; |
884 } | 889 } |
885 | 890 |
886 - (void)setInlineDispositionTitle:(NSString*)title { | 891 - (void)setInlineDispositionTitle:(NSString*)title { |
887 NSFont* nsfont = [inlineDispositionTitleField_ font]; | 892 NSFont* nsfont = [inlineDispositionTitleField_ font]; |
888 gfx::Font font( | 893 gfx::Font font( |
889 base::SysNSStringToUTF8([nsfont fontName]), [nsfont pointSize]); | 894 base::SysNSStringToUTF8([nsfont fontName]), [nsfont pointSize]); |
890 NSString* elidedTitle = base::SysUTF16ToNSString(ui::ElideText( | 895 NSString* elidedTitle = base::SysUTF16ToNSString(ui::ElideText( |
891 base::SysNSStringToUTF16(title), | 896 base::SysNSStringToUTF16(title), |
892 font, kTitleLinkMaxWidth, ui::ELIDE_AT_END)); | 897 font, WebIntentPicker::kTitleLinkMaxWidth, ui::ELIDE_AT_END)); |
893 [inlineDispositionTitleField_ setStringValue:elidedTitle]; | 898 [inlineDispositionTitleField_ setStringValue:elidedTitle]; |
894 } | 899 } |
895 | 900 |
896 - (void)stopThrobber { | 901 - (void)stopThrobber { |
897 [closeButton_ setEnabled:YES]; | 902 [closeButton_ setEnabled:YES]; |
898 [self setIntentButtonsEnabled:YES]; | 903 [self setIntentButtonsEnabled:YES]; |
899 [suggestionView_ stopThrobber]; | 904 [suggestionView_ stopThrobber]; |
900 } | 905 } |
901 | 906 |
902 - (void)closeSheet { | 907 - (void)closeSheet { |
903 [NSApp endSheet:[self window]]; | 908 [NSApp endSheet:[self window]]; |
904 } | 909 } |
905 | 910 |
906 - (void)pendingAsyncCompleted { | 911 - (void)pendingAsyncCompleted { |
907 // Requests to both the WebIntentService and the Chrome Web Store have | 912 // Requests to both the WebIntentService and the Chrome Web Store have |
908 // completed. If there are any services, installed or suggested, there's | 913 // completed. If there are any services, installed or suggested, there's |
909 // nothing to do. | 914 // nothing to do. |
910 DCHECK(model_); | 915 DCHECK(model_); |
911 isEmpty_ = !model_->GetInstalledServiceCount() && | 916 isEmpty_ = !model_->GetInstalledServiceCount() && |
912 !model_->GetSuggestedExtensionCount(); | 917 !model_->GetSuggestedExtensionCount(); |
913 [self performLayoutWithModel:model_]; | 918 [self performLayoutWithModel:model_]; |
914 } | 919 } |
915 | 920 |
916 @end // WebIntentPickerSheetController | 921 @end // WebIntentPickerSheetController |
OLD | NEW |