| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/passwords/signin_promo_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/passwords/signin_promo_view_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/ui/chrome_style.h" |
| 9 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
| 8 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" | 10 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" |
| 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 10 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 11 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 13 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 12 #include "ui/base/l10n/l10n_util_mac.h" | 14 #include "ui/base/l10n/l10n_util_mac.h" |
| 13 | 15 |
| 14 @interface SignInPromoViewController () { | 16 @interface SignInPromoViewController () { |
| 15 base::scoped_nsobject<NSButton> _signInButton; | 17 base::scoped_nsobject<NSButton> _signInButton; |
| 16 base::scoped_nsobject<NSButton> _noButton; | 18 base::scoped_nsobject<NSButton> _noButton; |
| 19 base::scoped_nsobject<NSButton> _closeButton; |
| 17 } | 20 } |
| 18 | 21 |
| 19 // "Sign In" and "No thanks" button handlers. | 22 // "Sign In" and "No thanks" button handlers. |
| 20 - (void)onSignInClicked:(id)sender; | 23 - (void)onSignInClicked:(id)sender; |
| 21 - (void)onNoClicked:(id)sender; | 24 - (void)onNoClicked:(id)sender; |
| 25 - (void)onCloseClicked:(id)sender; |
| 22 @end | 26 @end |
| 23 | 27 |
| 24 @implementation SignInPromoViewController | 28 @implementation SignInPromoViewController |
| 25 | 29 |
| 26 - (instancetype)initWithDelegate: | 30 - (instancetype)initWithDelegate: |
| 27 (id<BasePasswordsContentViewDelegate>)delegate { | 31 (id<BasePasswordsContentViewDelegate>)delegate { |
| 28 return [super initWithDelegate:delegate]; | 32 return [super initWithDelegate:delegate]; |
| 29 } | 33 } |
| 30 | 34 |
| 31 - (NSButton*)defaultButton { | 35 - (NSButton*)defaultButton { |
| 32 return _signInButton; | 36 return _signInButton; |
| 33 } | 37 } |
| 34 | 38 |
| 35 // ------------------------------------ | 39 // ------------------------------------ |
| 36 // | Sign in to Chrome! | | 40 // | Sign in to Chrome! | |
| 37 // | | | 41 // | | |
| 38 // | [ No ] [ Sign In ] | | 42 // | [ No ] [ Sign In ] | |
| 39 // ------------------------------------ | 43 // ------------------------------------ |
| 40 - (void)loadView { | 44 - (void)loadView { |
| 41 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 45 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 46 // Close button. |
| 47 const int dimension = chrome_style::GetCloseButtonSize(); |
| 48 NSRect frame = NSMakeRect(0, 0, dimension, dimension); |
| 49 _closeButton.reset( |
| 50 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); |
| 51 [_closeButton setAction:@selector(onCloseClicked:)]; |
| 52 [_closeButton setTarget:self]; |
| 53 [view addSubview:_closeButton]; |
| 42 // Title. | 54 // Title. |
| 43 HyperlinkTextView* titleView = TitleBubbleLabelWithLink( | 55 HyperlinkTextView* titleView = TitleBubbleLabelWithLink( |
| 44 [self.delegate model]->title(), gfx::Range(), nil); | 56 [self.delegate model]->title(), gfx::Range(), nil); |
| 45 // Force the text to wrap to fit in the bubble size. | 57 // Force the text to wrap to fit in the bubble size. |
| 46 int titleWidth = kDesiredBubbleWidth - 2*kFramePadding; | 58 int titleRightPadding = |
| 59 2 * chrome_style::kCloseButtonPadding + NSWidth([_closeButton frame]); |
| 60 int titleWidth = kDesiredBubbleWidth - kFramePadding - titleRightPadding; |
| 47 [titleView setVerticallyResizable:YES]; | 61 [titleView setVerticallyResizable:YES]; |
| 48 [titleView setFrameSize:NSMakeSize(titleWidth, MAXFLOAT)]; | 62 [titleView setFrameSize:NSMakeSize(titleWidth, MAXFLOAT)]; |
| 49 [titleView sizeToFit]; | 63 [titleView sizeToFit]; |
| 50 [view addSubview:titleView]; | 64 [view addSubview:titleView]; |
| 51 | 65 |
| 52 NSString* signInText = | 66 NSString* signInText = |
| 53 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SIGNIN_PROMO_SIGN_IN); | 67 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SIGNIN_PROMO_SIGN_IN); |
| 54 _signInButton.reset([[self addButton:signInText | 68 _signInButton.reset([[self addButton:signInText |
| 55 toView:view | 69 toView:view |
| 56 target:self | 70 target:self |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 kDesiredBubbleWidth - kFramePadding - NSWidth([_signInButton frame]); | 81 kDesiredBubbleWidth - kFramePadding - NSWidth([_signInButton frame]); |
| 68 CGFloat curY = kFramePadding; | 82 CGFloat curY = kFramePadding; |
| 69 [_signInButton setFrameOrigin:NSMakePoint(curX, curY)]; | 83 [_signInButton setFrameOrigin:NSMakePoint(curX, curY)]; |
| 70 | 84 |
| 71 curX -= kRelatedControlHorizontalPadding; | 85 curX -= kRelatedControlHorizontalPadding; |
| 72 curX -= NSWidth([_noButton frame]); | 86 curX -= NSWidth([_noButton frame]); |
| 73 [_noButton setFrameOrigin:NSMakePoint(curX, curY)]; | 87 [_noButton setFrameOrigin:NSMakePoint(curX, curY)]; |
| 74 | 88 |
| 75 curY = NSMaxY([_noButton frame]) + kUnrelatedControlVerticalPadding; | 89 curY = NSMaxY([_noButton frame]) + kUnrelatedControlVerticalPadding; |
| 76 [titleView setFrameOrigin:NSMakePoint(kFramePadding, curY)]; | 90 [titleView setFrameOrigin:NSMakePoint(kFramePadding, curY)]; |
| 77 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, | 91 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding; |
| 78 NSMaxY([titleView frame]) + kFramePadding)]; | 92 // The close button is in the corner. |
| 93 NSPoint closeButtonOrigin = NSMakePoint( |
| 94 NSMaxX([titleView frame]) + chrome_style::kCloseButtonPadding, |
| 95 height - NSHeight([_closeButton frame]) - |
| 96 chrome_style::kCloseButtonPadding); |
| 97 [_closeButton setFrameOrigin:closeButtonOrigin]; |
| 98 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, height)]; |
| 79 [self setView:view]; | 99 [self setView:view]; |
| 80 } | 100 } |
| 81 | 101 |
| 82 - (void)onSignInClicked:(id)sender { | 102 - (void)onSignInClicked:(id)sender { |
| 83 ManagePasswordsBubbleModel* model = [self.delegate model]; | 103 ManagePasswordsBubbleModel* model = [self.delegate model]; |
| 84 if (model) | 104 if (model) |
| 85 model->OnSignInToChromeClicked(); | 105 model->OnSignInToChromeClicked(); |
| 86 [self.delegate viewShouldDismiss]; | 106 [self.delegate viewShouldDismiss]; |
| 87 } | 107 } |
| 88 | 108 |
| 89 - (void)onNoClicked:(id)sender { | 109 - (void)onNoClicked:(id)sender { |
| 90 ManagePasswordsBubbleModel* model = [self.delegate model]; | 110 ManagePasswordsBubbleModel* model = [self.delegate model]; |
| 91 if (model) | 111 if (model) |
| 92 model->OnSkipSignInClicked(); | 112 model->OnSkipSignInClicked(); |
| 93 [self.delegate viewShouldDismiss]; | 113 [self.delegate viewShouldDismiss]; |
| 94 } | 114 } |
| 95 | 115 |
| 116 - (void)onCloseClicked:(id)sender { |
| 117 [self.delegate viewShouldDismiss]; |
| 118 } |
| 119 |
| 96 @end | 120 @end |
| 97 | 121 |
| 98 @implementation SignInPromoViewController (Testing) | 122 @implementation SignInPromoViewController (Testing) |
| 99 | 123 |
| 100 - (NSButton*)signInButton { | 124 - (NSButton*)signInButton { |
| 101 return _signInButton.get(); | 125 return _signInButton.get(); |
| 102 } | 126 } |
| 103 | 127 |
| 104 - (NSButton*)noButton { | 128 - (NSButton*)noButton { |
| 105 return _noButton.get(); | 129 return _noButton.get(); |
| 106 } | 130 } |
| 107 | 131 |
| 132 - (NSButton*)closeButton { |
| 133 return _closeButton.get(); |
| 134 } |
| 135 |
| 108 @end | 136 @end |
| OLD | NEW |