Chromium Code Reviews| Index: chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm |
| diff --git a/chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm b/chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm |
| index 45e2349c2afd93d282a7fc2ded7e62bf0084abd6..86aacb9be2593e46e667d4b088e9767ae9f8a577 100644 |
| --- a/chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm |
| +++ b/chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm |
| @@ -24,8 +24,11 @@ |
| #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" |
| +#include "chrome/common/url_constants.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "content/public/browser/native_web_keyboard_event.h" |
| +#include "skia/ext/skia_utils_mac.h" |
| +#include "ui/base/cocoa/controls/hyperlink_text_view.h" |
| #include "ui/base/cocoa/window_size_constants.h" |
| #include "ui/base/l10n/l10n_util_mac.h" |
| @@ -35,7 +38,7 @@ namespace { |
| const CGFloat kChooserBubbleWidth = 320.0f; |
| // Chooser bubble height. |
| -const CGFloat kChooserBubbleHeight = 220.0f; |
| +const CGFloat kChooserBubbleHeight = 280.0f; |
| // Distance between the bubble border and the view that is closest to the |
| // border. |
| @@ -46,8 +49,7 @@ const CGFloat kMarginY = 20.0f; |
| const CGFloat kHorizontalPadding = 10.0f; |
| const CGFloat kVerticalPadding = 10.0f; |
| -const CGFloat kTitlePaddingX = 50.0f; |
| -} |
| +} // namespace |
| scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| return make_scoped_ptr(new ChooserBubbleUiCocoa(browser_, this)); |
| @@ -65,6 +67,8 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| base::scoped_nsobject<NSTableView> tableView_; |
| base::scoped_nsobject<NSButton> connectButton_; |
| base::scoped_nsobject<NSButton> cancelButton_; |
| + base::scoped_nsobject<NSTextField> message_; |
| + base::scoped_nsobject<HyperlinkTextView> helpLink_; |
| bool buttonPressed_; |
| Browser* browser_; // Weak. |
| @@ -121,6 +125,12 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| // Creates the "Cancel" button. |
| - (base::scoped_nsobject<NSButton>)cancelButton; |
| +// Creates the message. |
| +- (base::scoped_nsobject<NSTextField>)message; |
| + |
| +// Creates the help link. |
| +- (base::scoped_nsobject<HyperlinkTextView>)helpLink; |
| + |
| // Called when the "Connect" button is pressed. |
| - (void)onConnect:(id)sender; |
| @@ -202,6 +212,8 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| // | | | | |
| // | -------------------------------- | |
| // | [ Connect] [ Cancel ] | |
| + // |----------------------------------| |
| + // | Not seeing your device? Get help | |
| // ------------------------------------ |
| // Determine the dimensions of the bubble. |
| @@ -213,28 +225,42 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| // Create the views. |
| // Title. |
| titleView_ = [self bubbleTitle]; |
| - CGFloat titleOriginX = kMarginX; |
| CGFloat titleHeight = NSHeight([titleView_ frame]); |
| - CGFloat titleOriginY = kChooserBubbleHeight - kMarginY - titleHeight; |
| - [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; |
| - [view addSubview:titleView_]; |
| // Connect button. |
| connectButton_ = [self connectButton]; |
| - // Cancel button. |
| - cancelButton_ = [self cancelButton]; |
| CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); |
| CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); |
| + |
| + // Cancel button. |
| + cancelButton_ = [self cancelButton]; |
| CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); |
| + // Message. |
| + message_ = [self message]; |
| + CGFloat messageWidth = NSWidth([message_ frame]); |
| + CGFloat messageHeight = NSHeight([message_ frame]); |
| + |
| + // Help link. |
| + helpLink_ = [self helpLink]; |
| + |
| + // Separator. |
| + CGFloat separatorOriginX = 0.0f; |
| + CGFloat separatorOriginY = kMarginY + messageHeight + kVerticalPadding; |
| + NSBox* separator = |
| + [self horizontalSeparatorWithFrame:NSMakeRect(separatorOriginX, |
| + separatorOriginY, |
| + kChooserBubbleWidth, 0.0f)]; |
| + |
| // ScollView embedding with TableView. |
| CGFloat scrollViewWidth = kChooserBubbleWidth - 2 * kMarginX; |
| CGFloat scrollViewHeight = kChooserBubbleHeight - 2 * kMarginY - |
| - 2 * kVerticalPadding - titleHeight - |
| - connectButtonHeight; |
| - NSRect scrollFrame = |
| - NSMakeRect(kMarginX, kMarginY + connectButtonHeight + kVerticalPadding, |
| - scrollViewWidth, scrollViewHeight); |
| + 4 * kVerticalPadding - titleHeight - |
| + connectButtonHeight - messageHeight; |
| + NSRect scrollFrame = NSMakeRect( |
| + kMarginX, |
| + kMarginY + messageHeight + 3 * kVerticalPadding + connectButtonHeight, |
| + scrollViewWidth, scrollViewHeight); |
| scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); |
| [scrollView_ setBorderType:NSBezelBorder]; |
| [scrollView_ setHasVerticalScroller:YES]; |
| @@ -252,26 +278,51 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| [tableView_ setHeaderView:nil]; |
| [tableView_ setFocusRingType:NSFocusRingTypeNone]; |
| + // Lay out the views. |
| + // Title. |
| + CGFloat titleOriginX = kMarginX; |
| + CGFloat titleOriginY = kChooserBubbleHeight - kMarginY - titleHeight; |
| + [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; |
| + [view addSubview:titleView_]; |
| + |
| + // ScollView. |
| [scrollView_ setDocumentView:tableView_]; |
| [view addSubview:scrollView_]; |
| - // Set connect button and cancel button to the right place. |
| + // Connect button. |
| CGFloat connectButtonOriginX = kChooserBubbleWidth - kMarginX - |
| kHorizontalPadding - connectButtonWidth - |
| cancelButtonWidth; |
| - CGFloat connectButtonOriginY = kMarginY; |
| + CGFloat connectButtonOriginY = |
| + kMarginY + messageHeight + 2 * kVerticalPadding; |
| [connectButton_ |
| setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; |
| [connectButton_ setEnabled:NO]; |
| [view addSubview:connectButton_]; |
| + // Cancel button. |
| CGFloat cancelButtonOriginX = |
| kChooserBubbleWidth - kMarginX - cancelButtonWidth; |
| - CGFloat cancelButtonOriginY = kMarginY; |
| + CGFloat cancelButtonOriginY = connectButtonOriginY; |
| [cancelButton_ |
| setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; |
| [view addSubview:cancelButton_]; |
| + // Separator. |
| + [view addSubview:separator]; |
| + |
| + // Message. |
| + CGFloat messageOriginX = kMarginX; |
| + CGFloat messageOriginY = kMarginY; |
| + [message_ setFrameOrigin:NSMakePoint(messageOriginX, messageOriginY)]; |
| + [view addSubview:message_]; |
| + |
| + // Help link. |
| + CGFloat helpLinkOriginX = kMarginX + messageWidth; |
| + CGFloat helpLinkOriginY = kMarginY; |
| + [helpLink_ setFrameOrigin:NSMakePoint(helpLinkOriginX, helpLinkOriginY)]; |
| + [view addSubview:helpLink_]; |
| + |
| bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; |
| if ([[self window] isVisible]) { |
| // Unfortunately, calling -setFrame followed by -setFrameOrigin (called |
| @@ -392,9 +443,6 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| [titleView setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_PROMPT)]; |
| [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| [titleView sizeToFit]; |
| - NSRect titleFrame = [titleView frame]; |
| - [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, |
| - NSHeight(titleFrame))]; |
| return titleView; |
| } |
| @@ -422,6 +470,48 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)]; |
| } |
| +- (base::scoped_nsobject<NSTextField>)message { |
| + base::scoped_nsobject<NSTextField> messageView( |
| + [[NSTextField alloc] initWithFrame:NSZeroRect]); |
| + [messageView setDrawsBackground:NO]; |
| + [messageView setBezeled:NO]; |
| + [messageView setEditable:NO]; |
| + [messageView setSelectable:NO]; |
| + [messageView |
| + setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICE_TEXT)]; |
| + [messageView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| + [messageView sizeToFit]; |
| + return messageView; |
| +} |
| + |
| +- (base::scoped_nsobject<HyperlinkTextView>)helpLink { |
| + base::scoped_nsobject<HyperlinkTextView> helpTextView( |
| + [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); |
| + NSString* getHelpText = |
| + l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT); |
| + |
| + NSColor* linkColor = |
| + skia::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| + [helpTextView setMessage:getHelpText |
| + withFont:[NSFont systemFontOfSize:[NSFont systemFontSize]] |
| + messageColor:linkColor]; |
| + |
| + NSUInteger getHelpOffset = 0; |
| + [helpTextView addLinkRange:NSMakeRange(getHelpOffset, [getHelpText length]) |
|
Robert Sesek
2016/02/16 21:26:40
Since you're linkifying the entire text content, d
juncai
2016/02/17 01:06:42
Done.
|
| + withURL:@(chrome::kChooserUIGetHelpURL) |
| + linkColor:linkColor]; |
| + |
| + // Removes the underlining from the link. |
| + NSTextStorage* textStorage = [helpTextView textStorage]; |
| + [textStorage addAttribute:NSUnderlineStyleAttributeName |
| + value:@(NSUnderlineStyleNone) |
| + range:NSMakeRange(getHelpOffset, [getHelpText length])]; |
| + |
| + [helpTextView setFrameSize:NSMakeSize(70, 17)]; |
| + |
| + return helpTextView; |
| +} |
| + |
| + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { |
| NSRect frameA = [viewA frame]; |
| NSRect frameB = [viewB frame]; |