Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: chrome/browser/ui/cocoa/one_click_signin_bubble_controller.mm

Issue 9863032: [Sync] [Mac] Implement one-click signin bubble for OS X (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address sky's comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h"
6
7 #include "base/logging.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
10 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #import "ui/base/l10n/l10n_util_mac.h"
16
17 namespace {
18
19 // Shift the origin of |view|'s frame by the given amount in the
20 // positive y direction (up).
21 void ShiftOriginY(NSView* view, CGFloat amount) {
22 NSPoint origin = [view frame].origin;
23 origin.y += amount;
24 [view setFrameOrigin:origin];
25 }
26
27 } // namespace
28
29 @implementation OneClickSigninBubbleController
30
31 - (id)initWithBrowserWindowController:(BrowserWindowController*)controller
32 learnMoreCallback:(const base::Closure&)learnMoreCallback
33 advancedCallback:(const base::Closure&)advancedCallback {
34 NSWindow* parentWindow = [controller window];
35
36 // Set the anchor point to right below the wrench menu.
37 NSView* wrenchButton = [[controller toolbarController] wrenchButton];
38 const NSRect bounds = [wrenchButton bounds];
39 NSPoint anchorPoint = NSMakePoint(NSMidX(bounds), NSMaxY(bounds));
40 anchorPoint = [wrenchButton convertPoint:anchorPoint toView:nil];
41 anchorPoint = [parentWindow convertBaseToScreen:anchorPoint];
42
43 if (self = [super initWithWindowNibPath:@"OneClickSigninBubble"
44 parentWindow:parentWindow
45 anchoredAt:anchorPoint]) {
46 learnMoreCallback_ = learnMoreCallback;
47 advancedCallback_ = advancedCallback;
48 DCHECK(!learnMoreCallback_.is_null());
49 DCHECK(!advancedCallback_.is_null());
50 }
51 return self;
52 }
53
54 - (IBAction)ok:(id)sender {
55 [self close];
56 }
57
58 - (IBAction)onClickLearnMoreLink:(id)sender {
59 learnMoreCallback_.Run();
60 }
61
62 - (IBAction)onClickAdvancedLink:(id)sender {
63 advancedCallback_.Run();
64 }
65
66 - (void)awakeFromNib {
67 [super awakeFromNib];
68
69 // Set the message text manually, since we have to interpolate the
70 // product name.
71 NSString* message =
72 l10n_util::GetNSStringF(
73 IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE,
74 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
75 [messageField_ setStringValue:message];
76
77 // Lay out the text controls from the bottom up.
78 CGFloat totalYOffset = 0.0;
79
80 totalYOffset +=
81 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height;
82
83 ShiftOriginY(learnMoreLink_, totalYOffset);
84 totalYOffset +=
85 [GTMUILocalizerAndLayoutTweaker sizeToFitView:learnMoreLink_].height;
86
87 ShiftOriginY(messageField_, totalYOffset);
88 totalYOffset +=
89 [GTMUILocalizerAndLayoutTweaker
90 sizeToFitFixedWidthTextField:messageField_];
91
92 NSSize delta = NSMakeSize(0.0, totalYOffset);
93
94 // Resize bubble and window to hold the controls.
95 [GTMUILocalizerAndLayoutTweaker
96 resizeViewWithoutAutoResizingSubViews:[self bubble]
97 delta:delta];
98 [GTMUILocalizerAndLayoutTweaker
99 resizeWindowWithoutAutoResizingSubViews:[self window]
100 delta:delta];
101 }
102
103 @end // OneClickSigninBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698