| 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 19 matching lines...) Expand all Loading... |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/l10n/l10n_util_mac.h" | 31 #include "ui/base/l10n/l10n_util_mac.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/base/text/text_elider.h" | 33 #include "ui/base/text/text_elider.h" |
| 34 #include "ui/gfx/font.h" | 34 #include "ui/gfx/font.h" |
| 35 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
| 36 | 36 |
| 37 using content::OpenURLParams; | 37 using content::OpenURLParams; |
| 38 using content::Referrer; | 38 using content::Referrer; |
| 39 | 39 |
| 40 @interface HyperlinkButtonCell (Private) |
| 41 - (void)customizeButtonCell; |
| 42 @end |
| 43 |
| 44 @interface CustomLinkButtonCell : HyperlinkButtonCell |
| 45 @end |
| 46 |
| 40 namespace { | 47 namespace { |
| 41 | 48 |
| 42 // The width of a service button, in view coordinates. | 49 // The width of a service button, in view coordinates. |
| 43 const CGFloat kServiceButtonWidth = 300; | 50 const CGFloat kServiceButtonWidth = 300; |
| 44 | 51 |
| 45 // Spacing in between sections. | 52 // Spacing in between sections. |
| 46 const CGFloat kVerticalSpacing = 18; | 53 const CGFloat kVerticalSpacing = 18; |
| 47 | 54 |
| 48 // Square size of the close button. | 55 // Square size of the close button. |
| 49 const CGFloat kCloseButtonSize = 16; | 56 const CGFloat kCloseButtonSize = 16; |
| 50 | 57 |
| 51 // Font size for picker header. | |
| 52 const CGFloat kHeaderFontSize = 14.5; | |
| 53 | |
| 54 // Width of the text fields. | 58 // Width of the text fields. |
| 55 const CGFloat kTextWidth = WebIntentPicker::kWindowWidth - | 59 const CGFloat kTextWidth = WebIntentPicker::kWindowWidth - |
| 56 (WebIntentPicker::kContentAreaBorder * 2.0 + kCloseButtonSize); | 60 (WebIntentPicker::kContentAreaBorder * 2.0 + kCloseButtonSize); |
| 57 | 61 |
| 58 // Maximum number of intents (suggested and installed) displayed. | 62 // Maximum number of intents (suggested and installed) displayed. |
| 59 const int kMaxIntentRows = 4; | 63 const int kMaxIntentRows = 4; |
| 60 | 64 |
| 61 // Sets properties on the given |field| to act as title or description labels. | 65 // Sets properties on the given |field| to act as title or description labels. |
| 62 void ConfigureTextFieldAsLabel(NSTextField* field) { | 66 void ConfigureTextFieldAsLabel(NSTextField* field) { |
| 63 [field setEditable:NO]; | 67 [field setEditable:NO]; |
| 64 [field setSelectable:YES]; | 68 [field setSelectable:YES]; |
| 65 [field setDrawsBackground:NO]; | 69 [field setDrawsBackground:NO]; |
| 66 [field setBezeled:NO]; | 70 [field setBezeled:NO]; |
| 67 } | 71 } |
| 68 | 72 |
| 69 NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) { | 73 NSButton* CreateHyperlinkButton(NSString* title, const NSRect& frame) { |
| 70 NSButton* button = [[NSButton alloc] initWithFrame:frame]; | 74 NSButton* button = [[NSButton alloc] initWithFrame:frame]; |
| 71 scoped_nsobject<HyperlinkButtonCell> cell( | 75 scoped_nsobject<CustomLinkButtonCell> cell( |
| 72 [[HyperlinkButtonCell alloc] initTextCell:title]); | 76 [[CustomLinkButtonCell alloc] initTextCell:title]); |
| 73 [cell setControlSize:NSSmallControlSize]; | 77 [cell setControlSize:NSSmallControlSize]; |
| 74 [button setCell:cell.get()]; | 78 [button setCell:cell.get()]; |
| 75 [button setButtonType:NSMomentaryPushInButton]; | 79 [button setButtonType:NSMomentaryPushInButton]; |
| 76 [button setBezelStyle:NSRegularSquareBezelStyle]; | 80 [button setBezelStyle:NSRegularSquareBezelStyle]; |
| 77 | 81 |
| 78 return button; | 82 return button; |
| 79 } | 83 } |
| 80 | 84 |
| 81 } // namespace | 85 } // namespace |
| 82 | 86 |
| 87 |
| 88 // Provide custom link format for intent picker. Removes underline attribute, |
| 89 // since UX direction is "look like WebUI". |
| 90 @implementation CustomLinkButtonCell |
| 91 - (void)customizeButtonCell { |
| 92 [super customizeButtonCell]; |
| 93 [self setTextColor:[NSColor colorWithDeviceRed:0xff/255.0 |
| 94 green:0x11/255.0 |
| 95 blue:0x55/255.0 |
| 96 alpha:0xcc/255.0]]; |
| 97 } |
| 98 |
| 99 - (NSDictionary*)linkAttributes { |
| 100 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
| 101 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); |
| 102 [paragraphStyle setAlignment:[self alignment]]; |
| 103 |
| 104 return @{ |
| 105 NSForegroundColorAttributeName: [self textColor], |
| 106 NSFontAttributeName: [self font], |
| 107 NSCursorAttributeName: [NSCursor pointingHandCursor], |
| 108 NSParagraphStyleAttributeName: paragraphStyle.get() |
| 109 }; |
| 110 } |
| 111 @end |
| 112 |
| 83 // This simple NSView subclass is used as the single subview of the page info | 113 // This simple NSView subclass is used as the single subview of the page info |
| 84 // bubble's window's contentView. Drawing is flipped so that layout of the | 114 // bubble's window's contentView. Drawing is flipped so that layout of the |
| 85 // sections is easier. Apple recommends flipping the coordinate origin when | 115 // sections is easier. Apple recommends flipping the coordinate origin when |
| 86 // doing a lot of text layout because it's more natural. | 116 // doing a lot of text layout because it's more natural. |
| 87 @interface WebIntentsContentView : NSView | 117 @interface WebIntentsContentView : NSView |
| 88 @end | 118 @end |
| 89 @implementation WebIntentsContentView | 119 @implementation WebIntentsContentView |
| 90 - (BOOL)isFlipped { | 120 - (BOOL)isFlipped { |
| 91 return YES; | 121 return YES; |
| 92 } | 122 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 kTextWidth, 1); | 276 kTextWidth, 1); |
| 247 subtitleField_.reset([[NSTextField alloc] initWithFrame:frame]); | 277 subtitleField_.reset([[NSTextField alloc] initWithFrame:frame]); |
| 248 ConfigureTextFieldAsLabel(subtitleField_); | 278 ConfigureTextFieldAsLabel(subtitleField_); |
| 249 gfx::Font textFont = rb.GetFont(ConstrainedWindow::kTextFontStyle); | 279 gfx::Font textFont = rb.GetFont(ConstrainedWindow::kTextFontStyle); |
| 250 [subtitleField_ setFont:textFont.GetNativeFont()]; | 280 [subtitleField_ setFont:textFont.GetNativeFont()]; |
| 251 | 281 |
| 252 frame = NSMakeRect(0, 0, WebIntentPicker::kWindowWidth, 1.0); | 282 frame = NSMakeRect(0, 0, WebIntentPicker::kWindowWidth, 1.0); |
| 253 spacer_.reset([[NSBox alloc] initWithFrame:frame]); | 283 spacer_.reset([[NSBox alloc] initWithFrame:frame]); |
| 254 [spacer_ setBoxType:NSBoxSeparator]; | 284 [spacer_ setBoxType:NSBoxSeparator]; |
| 255 [spacer_ setBorderColor:[NSColor blackColor]]; | 285 [spacer_ setBorderColor:[NSColor blackColor]]; |
| 286 [spacer_ setAlphaValue:0.2]; |
| 256 | 287 |
| 257 NSArray* subviews = @[titleField_, subtitleField_, spacer_]; | 288 NSArray* subviews = @[titleField_, subtitleField_, spacer_]; |
| 258 [self setSubviews:subviews]; | 289 [self setSubviews:subviews]; |
| 259 } | 290 } |
| 260 return self; | 291 return self; |
| 261 } | 292 } |
| 262 | 293 |
| 263 - (void)setTitle:(NSString*)title { | 294 - (void)setTitle:(NSString*)title { |
| 264 NSRect frame = [titleField_ frame]; | 295 NSRect frame = [titleField_ frame]; |
| 265 [titleField_ setStringValue:title]; | 296 [titleField_ setStringValue:title]; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 528 |
| 498 label_.reset([[NSTextField alloc] initWithFrame:frame]); | 529 label_.reset([[NSTextField alloc] initWithFrame:frame]); |
| 499 ConfigureTextFieldAsLabel(label_); | 530 ConfigureTextFieldAsLabel(label_); |
| 500 [label_ setStringValue:string]; | 531 [label_ setStringValue:string]; |
| 501 frame.size.height += | 532 frame.size.height += |
| 502 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: | 533 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: |
| 503 label_]; | 534 label_]; |
| 504 frame.origin.y = (kMaxHeight - NSHeight(frame)) / 2.0; | 535 frame.origin.y = (kMaxHeight - NSHeight(frame)) / 2.0; |
| 505 [label_ setFrame:frame]; | 536 [label_ setFrame:frame]; |
| 506 | 537 |
| 507 [self setActionButton:@"Select" | 538 string = l10n_util::GetNSStringWithFixup( |
| 539 IDS_INTENT_PICKER_SELECT_INTENT); |
| 540 [self setActionButton:string |
| 508 withSelector:@selector(invokeService:) | 541 withSelector:@selector(invokeService:) |
| 509 forController:controller]; | 542 forController:controller]; |
| 510 [installButton_ setTag:index]; | 543 [installButton_ setTag:index]; |
| 511 return [self init]; | 544 return [self init]; |
| 512 } | 545 } |
| 513 | 546 |
| 514 - (NSInteger)tag { | 547 - (NSInteger)tag { |
| 515 return [installButton_ tag]; | 548 return [installButton_ tag]; |
| 516 } | 549 } |
| 517 | 550 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 styleMask:NSTitledWindowMask | 720 styleMask:NSTitledWindowMask |
| 688 backing:NSBackingStoreBuffered | 721 backing:NSBackingStoreBuffered |
| 689 defer:YES]); | 722 defer:YES]); |
| 690 if ((self = [super initWithWindow:window.get()])) { | 723 if ((self = [super initWithWindow:window.get()])) { |
| 691 picker_ = picker; | 724 picker_ = picker; |
| 692 if (picker) | 725 if (picker) |
| 693 model_ = picker->model(); | 726 model_ = picker->model(); |
| 694 | 727 |
| 695 inlineDispositionTitleField_.reset([[NSTextField alloc] init]); | 728 inlineDispositionTitleField_.reset([[NSTextField alloc] init]); |
| 696 ConfigureTextFieldAsLabel(inlineDispositionTitleField_); | 729 ConfigureTextFieldAsLabel(inlineDispositionTitleField_); |
| 697 | 730 [inlineDispositionTitleField_ setFont: |
| 731 [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]]; |
| 698 flipView_.reset([[WebIntentsContentView alloc] init]); | 732 flipView_.reset([[WebIntentsContentView alloc] init]); |
| 699 [flipView_ setAutoresizingMask:NSViewMinYMargin]; | 733 [flipView_ setAutoresizingMask:NSViewMinYMargin]; |
| 700 [[[self window] contentView] setSubviews:@[flipView_]]; | 734 [[[self window] contentView] setSubviews:@[flipView_]]; |
| 701 | 735 |
| 702 [self performLayoutWithModel:model_]; | 736 [self performLayoutWithModel:model_]; |
| 703 } | 737 } |
| 704 return self; | 738 return self; |
| 705 } | 739 } |
| 706 | 740 |
| 707 // Handle default OSX dialog cancel mechanisms. (Cmd-.) | 741 // Handle default OSX dialog cancel mechanisms. (Cmd-.) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 737 containerSize.height += | 771 containerSize.height += |
| 738 [webContentView frame].origin.y + WebIntentPicker::kContentAreaBorder; | 772 [webContentView frame].origin.y + WebIntentPicker::kContentAreaBorder; |
| 739 containerSize.width += 2 * WebIntentPicker::kContentAreaBorder; | 773 containerSize.width += 2 * WebIntentPicker::kContentAreaBorder; |
| 740 | 774 |
| 741 // Ensure minimum container width. | 775 // Ensure minimum container width. |
| 742 containerSize.width = | 776 containerSize.width = |
| 743 std::max(CGFloat(WebIntentPicker::kWindowWidth), containerSize.width); | 777 std::max(CGFloat(WebIntentPicker::kWindowWidth), containerSize.width); |
| 744 | 778 |
| 745 // Resize web contents. | 779 // Resize web contents. |
| 746 [webContentView setFrameSize:inlineContentSize]; | 780 [webContentView setFrameSize:inlineContentSize]; |
| 747 | |
| 748 // Position close button. | |
| 749 NSRect buttonFrame = [closeButton_ frame]; | |
| 750 buttonFrame.origin.x = containerSize.width - | |
| 751 WebIntentPicker::kContentAreaBorder - kCloseButtonSize; | |
| 752 [closeButton_ setFrame:buttonFrame]; | |
| 753 | |
| 754 [self setContainerSize:containerSize]; | 781 [self setContainerSize:containerSize]; |
| 755 } | 782 } |
| 756 | 783 |
| 757 - (void)setContainerSize:(NSSize)containerSize { | 784 - (void)setContainerSize:(NSSize)containerSize { |
| 758 // Resize container views | 785 // Resize container views |
| 759 NSRect frame = NSMakeRect(0, 0, 0, 0); | 786 NSRect frame = NSMakeRect(0, 0, 0, 0); |
| 760 frame.size = containerSize; | 787 frame.size = containerSize; |
| 761 [[[self window] contentView] setFrame:frame]; | 788 [[[self window] contentView] setFrame:frame]; |
| 762 [flipView_ setFrame:frame]; | 789 [flipView_ setFrame:frame]; |
| 763 | 790 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 [button setAction:@selector(showChromeWebStore:)]; | 863 [button setAction:@selector(showChromeWebStore:)]; |
| 837 [subviews addObject:button.get()]; | 864 [subviews addObject:button.get()]; |
| 838 | 865 |
| 839 // Call size-to-fit to fixup for the localized string. | 866 // Call size-to-fit to fixup for the localized string. |
| 840 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; | 867 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button.get()]; |
| 841 | 868 |
| 842 return NSHeight([button frame]); | 869 return NSHeight([button frame]); |
| 843 } | 870 } |
| 844 | 871 |
| 845 - (void)addCloseButtonToSubviews:(NSMutableArray*)subviews { | 872 - (void)addCloseButtonToSubviews:(NSMutableArray*)subviews { |
| 873 const CGFloat kButtonPadding = 4.0; // whitespace inside button frame. |
| 846 if (!closeButton_.get()) { | 874 if (!closeButton_.get()) { |
| 847 NSRect buttonFrame = NSMakeRect( | 875 NSRect buttonFrame = NSMakeRect( |
| 848 WebIntentPicker::kContentAreaBorder + kTextWidth, | 876 WebIntentPicker::kContentAreaBorder + kTextWidth + kButtonPadding, |
| 849 WebIntentPicker::kContentAreaBorder, | 877 WebIntentPicker::kContentAreaBorder - kButtonPadding, |
| 850 kCloseButtonSize, kCloseButtonSize); | 878 kCloseButtonSize, kCloseButtonSize); |
| 851 closeButton_.reset( | 879 closeButton_.reset( |
| 852 [[HoverCloseButton alloc] initWithFrame:buttonFrame]); | 880 [[HoverCloseButton alloc] initWithFrame:buttonFrame]); |
| 881 // Anchor close button to upper right. |
| 882 // (NSViewMaxYMargin since parent view is flipped.) |
| 883 [closeButton_ setAutoresizingMask:NSViewMaxYMargin|NSViewMinXMargin]; |
| 853 [closeButton_ setTarget:self]; | 884 [closeButton_ setTarget:self]; |
| 854 [closeButton_ setAction:@selector(cancelOperation:)]; | 885 [closeButton_ setAction:@selector(cancelOperation:)]; |
| 855 [[closeButton_ cell] setKeyEquivalent:@"\e"]; | 886 [[closeButton_ cell] setKeyEquivalent:@"\e"]; |
| 856 } | 887 } |
| 857 [subviews addObject:closeButton_]; | 888 [subviews addObject:closeButton_]; |
| 858 } | 889 } |
| 859 | 890 |
| 860 // Adds a header (icon and explanatory text) to picker bubble. | 891 // Adds a header (icon and explanatory text) to picker bubble. |
| 861 // Returns the y position delta for the next offset. | 892 // Returns the y position delta for the next offset. |
| 862 - (CGFloat)addHeaderToSubviews:(NSMutableArray*)subviews | 893 - (CGFloat)addHeaderToSubviews:(NSMutableArray*)subviews |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 WebIntentPicker::kContentAreaBorder, offset, size.width(), size.height()); | 929 WebIntentPicker::kContentAreaBorder, offset, size.width(), size.height()); |
| 899 | 930 |
| 900 [contents_->web_contents()->GetNativeView() setFrame:frame]; | 931 [contents_->web_contents()->GetNativeView() setFrame:frame]; |
| 901 [subviews addObject:contents_->web_contents()->GetNativeView()]; | 932 [subviews addObject:contents_->web_contents()->GetNativeView()]; |
| 902 | 933 |
| 903 return NSHeight(frame); | 934 return NSHeight(frame); |
| 904 } | 935 } |
| 905 | 936 |
| 906 - (CGFloat)addAnotherServiceLinkToSubviews:(NSMutableArray*)subviews | 937 - (CGFloat)addAnotherServiceLinkToSubviews:(NSMutableArray*)subviews |
| 907 atOffset:(CGFloat)offset { | 938 atOffset:(CGFloat)offset { |
| 939 DCHECK(model_); |
| 940 DCHECK(model_->IsInlineDisposition()); |
| 941 GURL url = model_->inline_disposition_url(); |
| 908 | 942 |
| 943 const WebIntentPickerModel::InstalledService* service = |
| 944 model_->GetInstalledServiceWithURL(url); |
| 945 DCHECK(service); |
| 946 |
| 947 CGFloat originalOffset = offset; |
| 948 |
| 949 // Icon for current service. |
| 950 scoped_nsobject<NSImageView> icon; |
| 951 NSRect imageFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, offset, |
| 952 0, 0); |
| 953 icon.reset([[NSImageView alloc] initWithFrame:imageFrame]); |
| 954 [icon setImage:service->favicon.ToNSImage()]; |
| 955 [icon setImageFrameStyle:NSImageFrameNone]; |
| 956 [icon setEnabled:YES]; |
| 957 |
| 958 imageFrame.size = [service->favicon.ToNSImage() size]; |
| 959 [icon setFrame:imageFrame]; |
| 960 |
| 961 [subviews addObject:icon]; |
| 962 |
| 963 // Resize control to fit text |
| 909 NSRect textFrame = | 964 NSRect textFrame = |
| 910 NSMakeRect(WebIntentPicker::kContentAreaBorder, offset, kTextWidth, 1); | 965 NSMakeRect(NSMaxX(imageFrame) + 4, |
| 966 offset, |
| 967 WebIntentPicker::kTitleLinkMaxWidth, 1); |
| 911 [inlineDispositionTitleField_ setFrame:textFrame]; | 968 [inlineDispositionTitleField_ setFrame:textFrame]; |
| 912 [subviews addObject:inlineDispositionTitleField_]; | 969 [subviews addObject:inlineDispositionTitleField_]; |
| 913 [GTMUILocalizerAndLayoutTweaker sizeToFitView:inlineDispositionTitleField_]; | 970 [GTMUILocalizerAndLayoutTweaker sizeToFitView:inlineDispositionTitleField_]; |
| 914 textFrame = [inlineDispositionTitleField_ frame]; | 971 textFrame = [inlineDispositionTitleField_ frame]; |
| 915 | 972 |
| 916 // Add link for "choose another service" if other suggestions are available | 973 // Add link for "choose another service" if other suggestions are available |
| 917 // or if more than one (the current) service is installed. | 974 // or if more than one (the current) service is installed. |
| 918 if (model_->GetInstalledServiceCount() > 1 || | 975 if (model_->GetInstalledServiceCount() > 1 || |
| 919 model_->GetSuggestedExtensionCount()) { | 976 model_->GetSuggestedExtensionCount()) { |
| 920 NSRect frame = NSMakeRect( | 977 NSRect frame = NSMakeRect( |
| 921 NSMaxX(textFrame) + WebIntentPicker::kContentAreaBorder, offset, | 978 NSMaxX(textFrame) + WebIntentPicker::kContentAreaBorder, offset, |
| 922 WebIntentPicker::kTitleLinkMaxWidth, 1); | 979 1, 1); |
| 923 NSString* string = l10n_util::GetNSStringWithFixup( | 980 NSString* string = l10n_util::GetNSStringWithFixup( |
| 924 IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE); | 981 IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE); |
| 925 scoped_nsobject<NSButton> button(CreateHyperlinkButton(string, frame)); | 982 scoped_nsobject<NSButton> button(CreateHyperlinkButton(string, frame)); |
| 926 [[button cell] setControlSize:NSRegularControlSize]; | 983 [[button cell] setControlSize:NSRegularControlSize]; |
| 984 [[button cell] setFont: |
| 985 [NSFont controlContentFontOfSize:[NSFont systemFontSize]]]; |
| 927 [button setTarget:self]; | 986 [button setTarget:self]; |
| 928 [button setAction:@selector(chooseAnotherService:)]; | 987 [button setAction:@selector(chooseAnotherService:)]; |
| 929 [subviews addObject:button]; | 988 [subviews addObject:button]; |
| 930 | 989 |
| 931 // Call size-to-fit to fixup for the localized string. | 990 // Call size-to-fit to fixup for the localized string. |
| 932 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button]; | 991 [GTMUILocalizerAndLayoutTweaker sizeToFitView:button]; |
| 933 | 992 |
| 993 // Right-align the "use another service" button. |
| 994 frame = [button frame]; |
| 995 frame.origin.x = WebIntentPicker::kWindowWidth - NSWidth(frame) - |
| 996 2 * WebIntentPicker::kContentAreaBorder - kCloseButtonSize; |
| 997 [button setFrame:frame]; |
| 998 [button setAutoresizingMask:NSViewMinXMargin]; |
| 999 |
| 934 // And finally, make sure the link and the title are horizontally centered. | 1000 // And finally, make sure the link and the title are horizontally centered. |
| 935 frame = [button frame]; | 1001 frame = [button frame]; |
| 936 CGFloat height = std::max(NSHeight(textFrame), NSHeight(frame)); | 1002 CGFloat height = std::max(NSHeight(textFrame), NSHeight(frame)); |
| 937 frame.origin.y += (height - NSHeight(frame)) / 2.0; | 1003 frame.origin.y += (height - NSHeight(frame)) / 2.0; |
| 938 frame.size.height = height; | 1004 frame.size.height = height; |
| 939 textFrame.origin.y += (height - NSHeight(textFrame)) / 2.0; | 1005 textFrame.origin.y += (height - NSHeight(textFrame)) / 2.0; |
| 940 textFrame.size.height = height; | 1006 textFrame.size.height = height; |
| 941 [button setFrame:frame]; | 1007 [button setFrame:frame]; |
| 942 [inlineDispositionTitleField_ setFrame:textFrame]; | 1008 [inlineDispositionTitleField_ setFrame:textFrame]; |
| 943 } | 1009 } |
| 944 | 1010 |
| 945 return NSHeight(textFrame); | 1011 offset += NSHeight(textFrame) + kVerticalSpacing; |
| 1012 |
| 1013 scoped_nsobject<NSBox> spacer; |
| 1014 |
| 1015 NSRect frame = NSMakeRect(0, offset, WebIntentPicker::kWindowWidth, 1.0); |
| 1016 spacer.reset([[NSBox alloc] initWithFrame:frame]); |
| 1017 [spacer setBoxType:NSBoxSeparator]; |
| 1018 [spacer setAlphaValue:0.2]; |
| 1019 [spacer setAutoresizingMask:NSViewWidthSizable]; |
| 1020 [subviews addObject: spacer]; |
| 1021 |
| 1022 return offset + kVerticalSpacing - originalOffset; |
| 946 } | 1023 } |
| 947 | 1024 |
| 948 - (NSView*)createEmptyView { | 1025 - (NSView*)createEmptyView { |
| 949 NSRect titleFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, | 1026 NSRect titleFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, |
| 950 WebIntentPicker::kContentAreaBorder, | 1027 WebIntentPicker::kContentAreaBorder, |
| 951 kTextWidth, 1); | 1028 kTextWidth, 1); |
| 952 scoped_nsobject<NSTextField> title( | 1029 scoped_nsobject<NSTextField> title( |
| 953 [[NSTextField alloc] initWithFrame:titleFrame]); | 1030 [[NSTextField alloc] initWithFrame:titleFrame]); |
| 954 ConfigureTextFieldAsLabel(title); | 1031 ConfigureTextFieldAsLabel(title); |
| 955 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1032 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 waitingView_.reset([[WaitingView alloc] init]); | 1089 waitingView_.reset([[WaitingView alloc] init]); |
| 1013 [subviews addObject:waitingView_]; | 1090 [subviews addObject:waitingView_]; |
| 1014 offset += NSHeight([waitingView_ frame]); | 1091 offset += NSHeight([waitingView_ frame]); |
| 1015 } else if (isEmpty) { | 1092 } else if (isEmpty) { |
| 1016 scoped_nsobject<NSView> emptyView([self createEmptyView]); | 1093 scoped_nsobject<NSView> emptyView([self createEmptyView]); |
| 1017 [subviews addObject:emptyView]; | 1094 [subviews addObject:emptyView]; |
| 1018 offset += NSHeight([emptyView frame]); | 1095 offset += NSHeight([emptyView frame]); |
| 1019 } else if (contents_) { | 1096 } else if (contents_) { |
| 1020 offset += [self addAnotherServiceLinkToSubviews:subviews | 1097 offset += [self addAnotherServiceLinkToSubviews:subviews |
| 1021 atOffset:offset]; | 1098 atOffset:offset]; |
| 1022 offset += WebIntentPicker::kContentAreaBorder; | |
| 1023 offset += [self addInlineHtmlToSubviews:subviews atOffset:offset]; | 1099 offset += [self addInlineHtmlToSubviews:subviews atOffset:offset]; |
| 1024 } else { | 1100 } else { |
| 1025 offset += [self addHeaderToSubviews:subviews atOffset:offset]; | 1101 offset += [self addHeaderToSubviews:subviews atOffset:offset]; |
| 1026 | 1102 |
| 1027 if (model) { | 1103 if (model) { |
| 1028 intentView_.reset( | 1104 intentView_.reset( |
| 1029 [[IntentView alloc] initWithModel:model forController:self]); | 1105 [[IntentView alloc] initWithModel:model forController:self]); |
| 1030 offset += [self addStackedView:intentView_ | 1106 offset += [self addStackedView:intentView_ |
| 1031 toSubviews:subviews | 1107 toSubviews:subviews |
| 1032 atOffset:offset]; | 1108 atOffset:offset]; |
| 1033 } | 1109 } |
| 1034 offset += [self addCwsButtonToSubviews:subviews atOffset:offset]; | 1110 offset += [self addCwsButtonToSubviews:subviews atOffset:offset]; |
| 1035 } | 1111 } |
| 1036 [self addCloseButtonToSubviews:subviews]; | |
| 1037 | 1112 |
| 1038 // Add the bottom padding. | 1113 // Add the bottom padding. |
| 1039 offset += WebIntentPicker::kContentAreaBorder; | 1114 offset += WebIntentPicker::kContentAreaBorder; |
| 1040 | 1115 |
| 1116 // Resize to fit. |
| 1117 [self setContainerSize:NSMakeSize(WebIntentPicker::kWindowWidth, offset)]; |
| 1118 |
| 1119 [self addCloseButtonToSubviews:subviews]; |
| 1120 |
| 1041 // Replace the window's content. | 1121 // Replace the window's content. |
| 1042 [flipView_ setSubviews:subviews]; | 1122 [flipView_ setSubviews:subviews]; |
| 1043 | |
| 1044 // And resize to fit. | |
| 1045 [self setContainerSize:NSMakeSize(WebIntentPicker::kWindowWidth, offset)]; | |
| 1046 } | 1123 } |
| 1047 | 1124 |
| 1048 - (void)setActionString:(NSString*)actionString { | 1125 - (void)setActionString:(NSString*)actionString { |
| 1049 NSRect textFrame; | 1126 NSRect textFrame; |
| 1050 if (!actionTextField_.get()) { | 1127 if (!actionTextField_.get()) { |
| 1051 textFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, 0, | 1128 textFrame = NSMakeRect(WebIntentPicker::kContentAreaBorder, 0, |
| 1052 kTextWidth, 1); | 1129 kTextWidth, 1); |
| 1053 | 1130 |
| 1054 actionTextField_.reset([[NSTextField alloc] initWithFrame:textFrame]); | 1131 actionTextField_.reset([[NSTextField alloc] initWithFrame:textFrame]); |
| 1055 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1132 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1081 - (void)stopThrobber { | 1158 - (void)stopThrobber { |
| 1082 [closeButton_ setEnabled:YES]; | 1159 [closeButton_ setEnabled:YES]; |
| 1083 [intentView_ stopThrobber]; | 1160 [intentView_ stopThrobber]; |
| 1084 } | 1161 } |
| 1085 | 1162 |
| 1086 - (void)closeSheet { | 1163 - (void)closeSheet { |
| 1087 [NSApp endSheet:[self window]]; | 1164 [NSApp endSheet:[self window]]; |
| 1088 } | 1165 } |
| 1089 | 1166 |
| 1090 @end // WebIntentPickerSheetController | 1167 @end // WebIntentPickerSheetController |
| OLD | NEW |