| 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..7e09ca9de613f34f7b3ee5852a3df5230fcc08f4 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
|
| @@ -4,9 +4,10 @@
|
|
|
| #import "chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h"
|
|
|
| +#include <stddef.h>
|
| +
|
| #include <algorithm>
|
| #include <cmath>
|
| -#include <vector>
|
|
|
| #include "base/mac/scoped_nsobject.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| @@ -26,8 +27,12 @@
|
| #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.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.h"
|
| #include "ui/base/l10n/l10n_util_mac.h"
|
| +#include "url/gurl.h"
|
|
|
| namespace {
|
|
|
| @@ -35,7 +40,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 +51,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 +69,7 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| base::scoped_nsobject<NSTableView> tableView_;
|
| base::scoped_nsobject<NSButton> connectButton_;
|
| base::scoped_nsobject<NSButton> cancelButton_;
|
| + base::scoped_nsobject<HyperlinkTextView> message_;
|
| bool buttonPressed_;
|
|
|
| Browser* browser_; // Weak.
|
| @@ -121,6 +126,9 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| // Creates the "Cancel" button.
|
| - (base::scoped_nsobject<NSButton>)cancelButton;
|
|
|
| +// Creates the help link.
|
| +- (base::scoped_nsobject<HyperlinkTextView>)message;
|
| +
|
| // Called when the "Connect" button is pressed.
|
| - (void)onConnect:(id)sender;
|
|
|
| @@ -201,7 +209,9 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| // | | | |
|
| // | | | |
|
| // | -------------------------------- |
|
| - // | [ Connect] [ Cancel ] |
|
| + // | [ Connect ] [ Cancel ] |
|
| + // |----------------------------------|
|
| + // | Not seeing your device? Get help |
|
| // ------------------------------------
|
|
|
| // Determine the dimensions of the bubble.
|
| @@ -213,28 +223,38 @@ 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 messageHeight = NSHeight([message_ frame]);
|
| +
|
| + // 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 +272,45 @@ 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_];
|
| +
|
| bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame];
|
| if ([[self window] isVisible]) {
|
| // Unfortunately, calling -setFrame followed by -setFrameOrigin (called
|
| @@ -392,9 +431,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 +458,41 @@ scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)];
|
| }
|
|
|
| +- (base::scoped_nsobject<HyperlinkTextView>)message {
|
| + base::scoped_nsobject<HyperlinkTextView> textView(
|
| + [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]);
|
| +
|
| + base::string16 linkString =
|
| + l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT);
|
| +
|
| + NSString* text =
|
| + l10n_util::GetNSStringF(IDS_CHOOSER_BUBBLE_FOOTNOTE_TEXT, linkString);
|
| + [textView setMessage:text
|
| + withFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]
|
| + messageColor:[NSColor blackColor]];
|
| +
|
| + NSColor* linkColor =
|
| + skia::SkColorToCalibratedNSColor(chrome_style::GetLinkColor());
|
| + [textView addLinkRange:NSMakeRange([text length] - linkString.size(),
|
| + linkString.size())
|
| + withURL:base::SysUTF8ToNSString(
|
| + chooserBubbleDelegate_->GetHelpCenterUrl().spec())
|
| + linkColor:linkColor];
|
| +
|
| + // Removes the underlining from the link.
|
| + NSTextStorage* textStorage = [textView textStorage];
|
| + [textStorage addAttribute:NSUnderlineStyleAttributeName
|
| + value:@(NSUnderlineStyleNone)
|
| + range:NSMakeRange(0, [text length])];
|
| +
|
| + [textView setVerticallyResizable:YES];
|
| + [textView
|
| + setFrameSize:NSMakeSize(kChooserBubbleWidth - 2 * kMarginX, MAXFLOAT)];
|
| + [textView sizeToFit];
|
| +
|
| + return textView;
|
| +}
|
| +
|
| + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB {
|
| NSRect frameA = [viewA frame];
|
| NSRect frameB = [viewB frame];
|
|
|