Commit a42db114 authored by melandory's avatar melandory Committed by Commit bot

[Smart Lock] Branding string (Google Smart Lock) in Mac save password infobar should be a link.

R=vabr@chromium.org
BUG=486739

Review URL: https://codereview.chromium.org/1139913004

Cr-Commit-Position: refs/heads/master@{#329766}
parent bb77c868
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_content_view_controller.h" #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_content_view_controller.h"
@class HyperlinkTextView;
namespace ui { namespace ui {
class ComboboxModel; class ComboboxModel;
} // namespace ui } // namespace ui
...@@ -30,11 +32,12 @@ class ManagePasswordsBubbleModel; ...@@ -30,11 +32,12 @@ class ManagePasswordsBubbleModel;
// Manages the view that offers to save the user's password. // Manages the view that offers to save the user's password.
@interface ManagePasswordsBubblePendingViewController @interface ManagePasswordsBubblePendingViewController
: ManagePasswordsBubbleContentViewController { : ManagePasswordsBubbleContentViewController<NSTextViewDelegate> {
@private @private
ManagePasswordsBubbleModel* model_; // weak ManagePasswordsBubbleModel* model_; // weak
base::scoped_nsobject<NSButton> saveButton_; base::scoped_nsobject<NSButton> saveButton_;
base::scoped_nsobject<BubbleCombobox> nopeButton_; base::scoped_nsobject<BubbleCombobox> nopeButton_;
base::scoped_nsobject<HyperlinkTextView> titleView_;
base::scoped_nsobject<ManagePasswordItemViewController> passwordItem_; base::scoped_nsobject<ManagePasswordItemViewController> passwordItem_;
} }
- (id)initWithModel:(ManagePasswordsBubbleModel*)model - (id)initWithModel:(ManagePasswordsBubbleModel*)model
......
...@@ -9,10 +9,13 @@ ...@@ -9,10 +9,13 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/bubble_combobox.h" #import "chrome/browser/ui/cocoa/bubble_combobox.h"
#import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h" #import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h"
#include "chrome/browser/ui/chrome_style.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h" #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "skia/ext/skia_utils_mac.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h" #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#import "ui/base/cocoa/controls/hyperlink_text_view.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/combobox_model.h" #include "ui/base/models/combobox_model.h"
...@@ -64,6 +67,14 @@ using namespace password_manager::mac::ui; ...@@ -64,6 +67,14 @@ using namespace password_manager::mac::ui;
} }
} }
- (BOOL)textView:(NSTextView*)textView
clickedOnLink:(id)link
atIndex:(NSUInteger)charIndex {
model_->OnBrandLinkClicked();
[delegate_ viewShouldDismiss];
return YES;
}
- (void)loadView { - (void)loadView {
base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
...@@ -75,6 +86,11 @@ using namespace password_manager::mac::ui; ...@@ -75,6 +86,11 @@ using namespace password_manager::mac::ui;
// | [Save] [Nope v] | // | [Save] [Nope v] |
// ----------------------------------- // -----------------------------------
// The title text depends on whether the user is signed in and therefore syncs
// their password
// Do you want [Google Smart Lock]/Chrome/Chromium to save password
// for this site.
// The bubble should be wide enough to fit the title row, the username and // The bubble should be wide enough to fit the title row, the username and
// password row, and the buttons row on one line each, but not smaller than // password row, and the buttons row on one line each, but not smaller than
// kDesiredBubbleWidth. // kDesiredBubbleWidth.
...@@ -82,9 +98,39 @@ using namespace password_manager::mac::ui; ...@@ -82,9 +98,39 @@ using namespace password_manager::mac::ui;
// Create the elements and add them to the view. // Create the elements and add them to the view.
// Title. // Title.
NSTextField* titleLabel = titleView_.reset([[HyperlinkTextView alloc] initWithFrame:NSZeroRect]);
[self addTitleLabel:base::SysUTF16ToNSString(model_->title()) NSColor* textColor = [NSColor blackColor];
toView:view]; NSFont* font = ResourceBundle::GetSharedInstance()
.GetFontList(ResourceBundle::SmallFont)
.GetPrimaryFont()
.GetNativeFont();
[titleView_ setMessage:base::SysUTF16ToNSString(model_->title())
withFont:font
messageColor:textColor];
NSRange titleBrandLinkRange = model_->title_brand_link_range().ToNSRange();
if (titleBrandLinkRange.length) {
NSColor* linkColor =
gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor());
[titleView_ addLinkRange:titleBrandLinkRange
withName:@""
linkColor:linkColor];
[titleView_.get() setDelegate:self];
// Create the link with no underlining.
[titleView_ setLinkTextAttributes:nil];
NSTextStorage* text = [titleView_ textStorage];
[text addAttribute:NSUnderlineStyleAttributeName
value:@(NSUnderlineStyleNone)
range:titleBrandLinkRange];
}
// Force the text to wrap to fit in the bubble size.
[titleView_ setVerticallyResizable:YES];
[titleView_ setFrameSize:NSMakeSize(kDesiredBubbleWidth - 2 * kFramePadding,
MAXFLOAT)];
[titleView_ sizeToFit];
[view addSubview:titleView_];
// Password item. // Password item.
// It should be at least as wide as the box without the padding. // It should be at least as wide as the box without the padding.
...@@ -125,7 +171,7 @@ using namespace password_manager::mac::ui; ...@@ -125,7 +171,7 @@ using namespace password_manager::mac::ui;
// Compute the bubble width using the password item. // Compute the bubble width using the password item.
const CGFloat contentWidth = const CGFloat contentWidth =
kFramePadding + NSWidth([password frame]) + kFramePadding; kFramePadding + NSWidth([titleView_ frame]) + kFramePadding;
const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth); const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth);
// Layout the elements, starting at the bottom and moving up. // Layout the elements, starting at the bottom and moving up.
...@@ -149,10 +195,10 @@ using namespace password_manager::mac::ui; ...@@ -149,10 +195,10 @@ using namespace password_manager::mac::ui;
// Title goes at the top after some padding. // Title goes at the top after some padding.
curY = NSMaxY([password frame]) + kUnrelatedControlVerticalPadding; curY = NSMaxY([password frame]) + kUnrelatedControlVerticalPadding;
[titleLabel setFrameOrigin:NSMakePoint(curX, curY)]; [titleView_ setFrameOrigin:NSMakePoint(curX, curY)];
// Update the bubble size. // Update the bubble size.
const CGFloat height = NSMaxY([titleLabel frame]) + kFramePadding; const CGFloat height = NSMaxY([titleView_ frame]) + kFramePadding;
[view setFrame:NSMakeRect(0, 0, width, height)]; [view setFrame:NSMakeRect(0, 0, width, height)];
[self setView:view]; [self setView:view];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment