OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/passwords/pending_password_view_controller.h" | 7 #import "chrome/browser/ui/cocoa/passwords/pending_password_view_controller.h" |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "chrome/browser/ui/cocoa/chrome_style.h" | 11 #include "chrome/browser/ui/cocoa/chrome_style.h" |
12 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 12 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
13 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" | 13 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" |
14 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 14 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
16 #include "skia/ext/skia_utils_mac.h" | 16 #include "skia/ext/skia_utils_mac.h" |
17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | |
18 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 17 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 | 19 |
21 constexpr SkColor kWarmWelcomeColor = | |
22 SkColorSetARGBMacro(0xFF, 0x64, 0x64, 0x64); | |
23 | |
24 @implementation PendingPasswordViewController | 20 @implementation PendingPasswordViewController |
25 | 21 |
26 - (BOOL)textView:(NSTextView*)textView | 22 - (BOOL)textView:(NSTextView*)textView |
27 clickedOnLink:(id)link | 23 clickedOnLink:(id)link |
28 atIndex:(NSUInteger)charIndex { | 24 atIndex:(NSUInteger)charIndex { |
29 ManagePasswordsBubbleModel* model = [self model]; | 25 ManagePasswordsBubbleModel* model = [self model]; |
30 if (model) | 26 if (model) |
31 model->OnBrandLinkClicked(); | 27 model->OnBrandLinkClicked(); |
32 [self.delegate viewShouldDismiss]; | 28 [self.delegate viewShouldDismiss]; |
33 return YES; | 29 return YES; |
34 } | 30 } |
35 | 31 |
36 - (base::scoped_nsobject<NSButton>)newCloseButton { | 32 - (base::scoped_nsobject<NSButton>)newCloseButton { |
37 const int dimension = chrome_style::GetCloseButtonSize(); | 33 const int dimension = chrome_style::GetCloseButtonSize(); |
38 NSRect frame = NSMakeRect(0, 0, dimension, dimension); | 34 NSRect frame = NSMakeRect(0, 0, dimension, dimension); |
39 base::scoped_nsobject<NSButton> button( | 35 base::scoped_nsobject<NSButton> button( |
40 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); | 36 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); |
41 [button setAction:@selector(viewShouldDismiss)]; | 37 [button setAction:@selector(viewShouldDismiss)]; |
42 [button setTarget:self.delegate]; | 38 [button setTarget:self.delegate]; |
43 return button; | 39 return button; |
44 } | 40 } |
45 | 41 |
46 - (NSView*)createPasswordView { | 42 - (NSView*)createPasswordView { |
47 // Empty implementation, it should be implemented in child class. | 43 // Empty implementation, it should be implemented in child class. |
48 NOTREACHED(); | 44 NOTREACHED(); |
49 return nil; | 45 return nil; |
50 } | 46 } |
51 | 47 |
52 - (BOOL)shouldShowGoogleSmartLockWelcome { | |
53 return NO; | |
54 } | |
55 | |
56 - (NSArray*)createButtonsAndAddThemToView:(NSView*)view { | 48 - (NSArray*)createButtonsAndAddThemToView:(NSView*)view { |
57 // Empty implementation, it should be implemented in child class. | 49 // Empty implementation, it should be implemented in child class. |
58 NOTREACHED(); | 50 NOTREACHED(); |
59 return nil; | 51 return nil; |
60 } | 52 } |
61 | 53 |
62 - (void)loadView { | 54 - (void)loadView { |
63 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 55 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
64 | 56 |
65 // ----------------------------------- | 57 // ----------------------------------- |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 93 |
102 [view addSubview:titleView]; | 94 [view addSubview:titleView]; |
103 | 95 |
104 // Password item. | 96 // Password item. |
105 // It should be at least as wide as the box without the padding. | 97 // It should be at least as wide as the box without the padding. |
106 NSView* passwordRow = [self createPasswordView]; | 98 NSView* passwordRow = [self createPasswordView]; |
107 if (passwordRow) { | 99 if (passwordRow) { |
108 [view addSubview:passwordRow]; | 100 [view addSubview:passwordRow]; |
109 } | 101 } |
110 | 102 |
111 base::scoped_nsobject<NSTextField> warm_welcome; | |
112 if ([self shouldShowGoogleSmartLockWelcome]) { | |
113 base::string16 label_text = | |
114 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK_WELCOME); | |
115 warm_welcome.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | |
116 InitLabel(warm_welcome.get(), label_text); | |
117 [[warm_welcome cell] setWraps:YES]; | |
118 [warm_welcome setFrameSize:NSMakeSize(kDesiredBubbleWidth - 2*kFramePadding, | |
119 MAXFLOAT)]; | |
120 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:warm_welcome]; | |
121 NSColor* color = skia::SkColorToSRGBNSColor(kWarmWelcomeColor); | |
122 [warm_welcome setTextColor:color]; | |
123 [view addSubview:warm_welcome.get()]; | |
124 } | |
125 | |
126 NSArray* buttons = [self createButtonsAndAddThemToView:view]; | 103 NSArray* buttons = [self createButtonsAndAddThemToView:view]; |
127 | 104 |
128 // Compute the bubble width using the password item. | 105 // Compute the bubble width using the password item. |
129 const CGFloat contentWidth = | 106 const CGFloat contentWidth = |
130 kFramePadding + NSWidth([titleView frame]) + titleRightPadding; | 107 kFramePadding + NSWidth([titleView frame]) + titleRightPadding; |
131 const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth); | 108 const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth); |
132 | 109 |
133 // Layout the elements, starting at the bottom and moving up. | 110 // Layout the elements, starting at the bottom and moving up. |
134 | 111 |
135 // Buttons go on the bottom row and are right-aligned. | 112 // Buttons go on the bottom row and are right-aligned. |
136 // Start with [Save]. | 113 // Start with [Save]. |
137 CGFloat curX = width - kFramePadding + kRelatedControlHorizontalPadding; | 114 CGFloat curX = width - kFramePadding + kRelatedControlHorizontalPadding; |
138 CGFloat curY = kFramePadding; | 115 CGFloat curY = kFramePadding; |
139 | 116 |
140 for (NSButton* button in buttons) { | 117 for (NSButton* button in buttons) { |
141 curX -= kRelatedControlHorizontalPadding + NSWidth([button frame]); | 118 curX -= kRelatedControlHorizontalPadding + NSWidth([button frame]); |
142 [button setFrameOrigin:NSMakePoint(curX, curY)]; | 119 [button setFrameOrigin:NSMakePoint(curX, curY)]; |
143 } | 120 } |
144 | 121 |
145 curX = kFramePadding; | 122 curX = kFramePadding; |
146 curY = NSMaxY([buttons.firstObject frame]) + kUnrelatedControlVerticalPadding; | 123 curY = NSMaxY([buttons.firstObject frame]) + kUnrelatedControlVerticalPadding; |
147 // The Smart Lock warm welcome is placed above after some padding. | |
148 if (warm_welcome) { | |
149 [warm_welcome setFrameOrigin:NSMakePoint(curX, curY)]; | |
150 curY = NSMaxY([warm_welcome frame]) + kUnrelatedControlVerticalPadding; | |
151 } | |
152 | 124 |
153 if (passwordRow) { | 125 if (passwordRow) { |
154 // Password item goes on the next row. | 126 // Password item goes on the next row. |
155 [passwordRow setFrameOrigin:NSMakePoint(curX, curY)]; | 127 [passwordRow setFrameOrigin:NSMakePoint(curX, curY)]; |
156 | 128 |
157 // Title goes at the top after some padding. | 129 // Title goes at the top after some padding. |
158 curY = NSMaxY([passwordRow frame]) + kUnrelatedControlVerticalPadding; | 130 curY = NSMaxY([passwordRow frame]) + kUnrelatedControlVerticalPadding; |
159 } | 131 } |
160 [titleView setFrameOrigin:NSMakePoint(curX, curY)]; | 132 [titleView setFrameOrigin:NSMakePoint(curX, curY)]; |
161 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding; | 133 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding; |
(...skipping 18 matching lines...) Expand all Loading... |
180 | 152 |
181 @end | 153 @end |
182 | 154 |
183 @implementation PendingPasswordViewController (Testing) | 155 @implementation PendingPasswordViewController (Testing) |
184 | 156 |
185 - (NSButton*)closeButton { | 157 - (NSButton*)closeButton { |
186 return closeButton_.get(); | 158 return closeButton_.get(); |
187 } | 159 } |
188 | 160 |
189 @end | 161 @end |
OLD | NEW |