| 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 248fa37ff3da814f9781cbd09b5ec7b06e430ea5..27602d31fc7a3444756d186eb1d071d3fb987816 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
|
| @@ -18,7 +18,7 @@
|
| #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
|
| #import "chrome/browser/ui/cocoa/browser_window_controller.h"
|
| #import "chrome/browser/ui/cocoa/browser_window_utils.h"
|
| -#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
|
| +#import "chrome/browser/ui/cocoa/chooser_content_view.h"
|
| #import "chrome/browser/ui/cocoa/info_bubble_view.h"
|
| #import "chrome/browser/ui/cocoa/info_bubble_window.h"
|
| #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
|
| @@ -27,34 +27,13 @@
|
| #include "components/bubble/bubble_controller.h"
|
| #include "components/url_formatter/elide_url.h"
|
| #include "content/public/browser/native_web_keyboard_event.h"
|
| -#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
|
| #include "ui/base/cocoa/cocoa_base_utils.h"
|
| -#import "ui/base/cocoa/controls/hyperlink_button_cell.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"
|
| #include "url/origin.h"
|
|
|
| -namespace {
|
| -
|
| -// Chooser bubble width.
|
| -const CGFloat kChooserBubbleWidth = 320.0f;
|
| -
|
| -// Chooser bubble height.
|
| -const CGFloat kChooserBubbleHeight = 280.0f;
|
| -
|
| -// Distance between the bubble border and the view that is closest to the
|
| -// border.
|
| -const CGFloat kMarginX = 20.0f;
|
| -const CGFloat kMarginY = 20.0f;
|
| -
|
| -// Distance between two views inside the bubble.
|
| -const CGFloat kHorizontalPadding = 10.0f;
|
| -const CGFloat kVerticalPadding = 10.0f;
|
| -
|
| -} // namespace
|
| -
|
| std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| return base::WrapUnique(
|
| new ChooserBubbleUiCocoa(browser_, chooser_controller()));
|
| @@ -64,18 +43,15 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> {
|
| @private
|
| // Bridge to the C++ class that created this object.
|
| - ChooserBubbleUiCocoa* bridge_;
|
| -
|
| - base::scoped_nsobject<NSTextField> titleView_;
|
| - base::scoped_nsobject<NSScrollView> scrollView_;
|
| - base::scoped_nsobject<NSTableColumn> tableColumn_;
|
| - base::scoped_nsobject<NSTableView> tableView_;
|
| - base::scoped_nsobject<NSButton> connectButton_;
|
| - base::scoped_nsobject<NSButton> cancelButton_;
|
| - base::scoped_nsobject<NSTextField> message_;
|
| - base::scoped_nsobject<NSButton> getHelpButton_;
|
| + ChooserBubbleUiCocoa* bridge_; // Weak.
|
| bool buttonPressed_;
|
|
|
| + base::scoped_nsobject<ChooserContentView> chooserContentView_;
|
| + NSTableView* tableView_; // Weak.
|
| + NSButton* connectButton_; // Weak.
|
| + NSButton* cancelButton_; // Weak.
|
| + NSButton* helpButton_; // Weak.
|
| +
|
| Browser* browser_; // Weak.
|
| ChooserController* chooserController_; // Weak.
|
| }
|
| @@ -118,25 +94,6 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| // Returns the expected parent for this bubble.
|
| - (NSWindow*)getExpectedParentWindow;
|
|
|
| -// Creates the title for the bubble.
|
| -- (base::scoped_nsobject<NSTextField>)bubbleTitle;
|
| -
|
| -// Creates a button with |title| and |action|.
|
| -- (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title
|
| - action:(SEL)action;
|
| -
|
| -// Creates the "Connect" button.
|
| -- (base::scoped_nsobject<NSButton>)connectButton;
|
| -
|
| -// Creates the "Cancel" button.
|
| -- (base::scoped_nsobject<NSButton>)cancelButton;
|
| -
|
| -// Creates the message.
|
| -- (base::scoped_nsobject<NSTextField>)message;
|
| -
|
| -// Creates the "Get help" button.
|
| -- (base::scoped_nsobject<NSButton>)getHelpButton;
|
| -
|
| // Called when the "Connect" button is pressed.
|
| - (void)onConnect:(id)sender;
|
|
|
| @@ -144,7 +101,7 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| - (void)onCancel:(id)sender;
|
|
|
| // Called when the "Get help" button is pressed.
|
| -- (void)onGetHelpPressed:(id)sender;
|
| +- (void)onHelpPressed:(id)sender;
|
|
|
| @end
|
|
|
| @@ -211,134 +168,32 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| }
|
|
|
| - (void)show {
|
| - NSView* view = [[self window] contentView];
|
| -
|
| - // ------------------------------------
|
| - // | Chooser bubble title |
|
| - // | -------------------------------- |
|
| - // | | option 0 | |
|
| - // | | option 1 | |
|
| - // | | option 2 | |
|
| - // | | | |
|
| - // | | | |
|
| - // | | | |
|
| - // | -------------------------------- |
|
| - // | [ Connect ] [ Cancel ] |
|
| - // |----------------------------------|
|
| - // | Not seeing your device? Get help |
|
| - // ------------------------------------
|
| -
|
| - // Determine the dimensions of the bubble.
|
| - // Once the height and width are set, the buttons and permission menus can
|
| - // be laid out correctly.
|
| - NSRect bubbleFrame =
|
| - NSMakeRect(0, 0, kChooserBubbleWidth, kChooserBubbleHeight);
|
| -
|
| - // Create the views.
|
| - // Title.
|
| - titleView_ = [self bubbleTitle];
|
| - CGFloat titleHeight = NSHeight([titleView_ frame]);
|
| -
|
| - // Connect button.
|
| - connectButton_ = [self connectButton];
|
| - 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]);
|
| -
|
| - // Get help button.
|
| - getHelpButton_ = [self getHelpButton];
|
| -
|
| - // 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 -
|
| - 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];
|
| - [scrollView_ setHasHorizontalScroller:YES];
|
| - [scrollView_ setAutohidesScrollers:YES];
|
| -
|
| - // TableView.
|
| - tableView_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]);
|
| - tableColumn_.reset([[NSTableColumn alloc] initWithIdentifier:@""]);
|
| - [tableColumn_ setWidth:(scrollViewWidth - kMarginX)];
|
| - [tableView_ addTableColumn:tableColumn_];
|
| + chooserContentView_.reset([[ChooserContentView alloc]
|
| + initWithChooserTitle:
|
| + l10n_util::GetNSStringF(
|
| + IDS_CHOOSER_BUBBLE_PROMPT,
|
| + url_formatter::FormatOriginForSecurityDisplay(
|
| + chooserController_->GetOrigin(),
|
| + url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]);
|
| +
|
| + tableView_ = [chooserContentView_ tableView];
|
| + connectButton_ = [chooserContentView_ connectButton];
|
| + cancelButton_ = [chooserContentView_ cancelButton];
|
| + helpButton_ = [chooserContentView_ helpButton];
|
| +
|
| + [connectButton_ setTarget:self];
|
| + [connectButton_ setAction:@selector(onConnect:)];
|
| + [cancelButton_ setTarget:self];
|
| + [cancelButton_ setAction:@selector(onCancel:)];
|
| [tableView_ setDelegate:self];
|
| [tableView_ setDataSource:self];
|
| - // Make the column title invisible.
|
| - [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_];
|
| -
|
| - // Connect button.
|
| - CGFloat connectButtonOriginX = kChooserBubbleWidth - kMarginX -
|
| - kHorizontalPadding - connectButtonWidth -
|
| - cancelButtonWidth;
|
| - 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 = 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_];
|
| -
|
| - // Get help button.
|
| - getHelpButton_ = [self getHelpButton];
|
| - CGFloat getHelpButtonOriginX =
|
| - kMarginX + messageWidth - kHorizontalPadding / 2;
|
| - CGFloat getHelpButtonOriginY = kMarginY;
|
| - [getHelpButton_
|
| - setFrameOrigin:NSMakePoint(getHelpButtonOriginX, getHelpButtonOriginY)];
|
| - [view addSubview:getHelpButton_];
|
| -
|
| - bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame];
|
| + [helpButton_ setTarget:self];
|
| + [helpButton_ setAction:@selector(onHelpPressed:)];
|
| +
|
| + [[[self window] contentView] addSubview:chooserContentView_.get()];
|
| +
|
| + NSRect bubbleFrame =
|
| + [[self window] frameRectForContentRect:[chooserContentView_ frame]];
|
| if ([[self window] isVisible]) {
|
| // Unfortunately, calling -setFrame followed by -setFrameOrigin (called
|
| // within -setAnchorPoint) causes flickering. Avoid the flickering by
|
| @@ -355,7 +210,7 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| [self setAnchorPoint:[self getExpectedAnchorPoint]];
|
| [self showWindow:nil];
|
| [[self window] makeFirstResponder:nil];
|
| - [[self window] setInitialFirstResponder:tableView_.get()];
|
| + [[self window] setInitialFirstResponder:tableView_];
|
| }
|
| }
|
|
|
| @@ -449,78 +304,6 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| return browser_->window()->GetNativeWindow();
|
| }
|
|
|
| -- (base::scoped_nsobject<NSTextField>)bubbleTitle {
|
| - base::scoped_nsobject<NSTextField> titleView(
|
| - [[NSTextField alloc] initWithFrame:NSZeroRect]);
|
| - [titleView setDrawsBackground:NO];
|
| - [titleView setBezeled:NO];
|
| - [titleView setEditable:NO];
|
| - [titleView setSelectable:NO];
|
| - [titleView setStringValue:
|
| - l10n_util::GetNSStringF(
|
| - IDS_CHOOSER_BUBBLE_PROMPT,
|
| - url_formatter::FormatOriginForSecurityDisplay(
|
| - chooserController_->GetOrigin(),
|
| - url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))];
|
| - [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
|
| - // The height is arbitrary as it will be adjusted later.
|
| - [titleView setFrameSize:NSMakeSize(kChooserBubbleWidth - 2 * kMarginX, 0.0f)];
|
| - [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView];
|
| - return titleView;
|
| -}
|
| -
|
| -- (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title
|
| - action:(SEL)action {
|
| - base::scoped_nsobject<NSButton> button(
|
| - [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]);
|
| - [button setButtonType:NSMomentaryPushInButton];
|
| - [button setTitle:title];
|
| - [button setTarget:self];
|
| - [button setAction:action];
|
| - [button sizeToFit];
|
| - return button;
|
| -}
|
| -
|
| -- (base::scoped_nsobject<NSButton>)connectButton {
|
| - NSString* connectTitle =
|
| - l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT);
|
| - return [self buttonWithTitle:connectTitle action:@selector(onConnect:)];
|
| -}
|
| -
|
| -- (base::scoped_nsobject<NSButton>)cancelButton {
|
| - NSString* cancelTitle =
|
| - l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT);
|
| - 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::GetNSStringF(IDS_CHOOSER_BUBBLE_FOOTNOTE_TEXT,
|
| - base::string16())];
|
| - [messageView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
|
| - [messageView sizeToFit];
|
| - return messageView;
|
| -}
|
| -
|
| -- (base::scoped_nsobject<NSButton>)getHelpButton {
|
| - base::scoped_nsobject<NSButton> button(
|
| - [[NSButton alloc] initWithFrame:NSZeroRect]);
|
| - base::scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc]
|
| - initTextCell:l10n_util::GetNSString(
|
| - IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT)]);
|
| - [button setCell:cell.get()];
|
| - [button sizeToFit];
|
| - [button setTarget:self];
|
| - [button setAction:@selector(onGetHelpPressed:)];
|
| - return button;
|
| -}
|
| -
|
| + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB {
|
| NSRect frameA = [viewA frame];
|
| NSRect frameB = [viewB frame];
|
| @@ -553,7 +336,7 @@ std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
|
| [self close];
|
| }
|
|
|
| -- (void)onGetHelpPressed:(id)sender {
|
| +- (void)onHelpPressed:(id)sender {
|
| chooserController_->OpenHelpCenterUrl();
|
| }
|
|
|
|
|