Chromium Code Reviews| 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" | 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
|
vasilii
2016/12/16 16:56:53
used?
vabr (Chromium)
2016/12/16 18:56:27
Not used -> removed.
| |
| 18 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 18 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 constexpr SkColor kWarmWelcomeColor = | |
| 22 SkColorSetARGBMacro(0xFF, 0x64, 0x64, 0x64); | |
| 23 | |
| 24 @implementation PendingPasswordViewController | 21 @implementation PendingPasswordViewController |
| 25 | 22 |
| 26 - (BOOL)textView:(NSTextView*)textView | 23 - (BOOL)textView:(NSTextView*)textView |
| 27 clickedOnLink:(id)link | 24 clickedOnLink:(id)link |
| 28 atIndex:(NSUInteger)charIndex { | 25 atIndex:(NSUInteger)charIndex { |
| 29 ManagePasswordsBubbleModel* model = [self model]; | 26 ManagePasswordsBubbleModel* model = [self model]; |
| 30 if (model) | 27 if (model) |
| 31 model->OnBrandLinkClicked(); | 28 model->OnBrandLinkClicked(); |
| 32 [self.delegate viewShouldDismiss]; | 29 [self.delegate viewShouldDismiss]; |
| 33 return YES; | 30 return YES; |
| 34 } | 31 } |
| 35 | 32 |
| 36 - (base::scoped_nsobject<NSButton>)newCloseButton { | 33 - (base::scoped_nsobject<NSButton>)newCloseButton { |
| 37 const int dimension = chrome_style::GetCloseButtonSize(); | 34 const int dimension = chrome_style::GetCloseButtonSize(); |
| 38 NSRect frame = NSMakeRect(0, 0, dimension, dimension); | 35 NSRect frame = NSMakeRect(0, 0, dimension, dimension); |
| 39 base::scoped_nsobject<NSButton> button( | 36 base::scoped_nsobject<NSButton> button( |
| 40 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); | 37 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); |
| 41 [button setAction:@selector(viewShouldDismiss)]; | 38 [button setAction:@selector(viewShouldDismiss)]; |
| 42 [button setTarget:self.delegate]; | 39 [button setTarget:self.delegate]; |
| 43 return button; | 40 return button; |
| 44 } | 41 } |
| 45 | 42 |
| 46 - (NSView*)createPasswordView { | 43 - (NSView*)createPasswordView { |
| 47 // Empty implementation, it should be implemented in child class. | 44 // Empty implementation, it should be implemented in child class. |
| 48 NOTREACHED(); | 45 NOTREACHED(); |
| 49 return nil; | 46 return nil; |
| 50 } | 47 } |
| 51 | 48 |
| 52 - (BOOL)shouldShowGoogleSmartLockWelcome { | |
| 53 return NO; | |
| 54 } | |
| 55 | |
| 56 - (NSArray*)createButtonsAndAddThemToView:(NSView*)view { | 49 - (NSArray*)createButtonsAndAddThemToView:(NSView*)view { |
| 57 // Empty implementation, it should be implemented in child class. | 50 // Empty implementation, it should be implemented in child class. |
| 58 NOTREACHED(); | 51 NOTREACHED(); |
| 59 return nil; | 52 return nil; |
| 60 } | 53 } |
| 61 | 54 |
| 62 - (void)loadView { | 55 - (void)loadView { |
| 63 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 56 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 64 | 57 |
| 65 // ----------------------------------- | 58 // ----------------------------------- |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 94 |
| 102 [view addSubview:titleView]; | 95 [view addSubview:titleView]; |
| 103 | 96 |
| 104 // Password item. | 97 // Password item. |
| 105 // It should be at least as wide as the box without the padding. | 98 // It should be at least as wide as the box without the padding. |
| 106 NSView* passwordRow = [self createPasswordView]; | 99 NSView* passwordRow = [self createPasswordView]; |
| 107 if (passwordRow) { | 100 if (passwordRow) { |
| 108 [view addSubview:passwordRow]; | 101 [view addSubview:passwordRow]; |
| 109 } | 102 } |
| 110 | 103 |
| 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]; | 104 NSArray* buttons = [self createButtonsAndAddThemToView:view]; |
| 127 | 105 |
| 128 // Compute the bubble width using the password item. | 106 // Compute the bubble width using the password item. |
| 129 const CGFloat contentWidth = | 107 const CGFloat contentWidth = |
| 130 kFramePadding + NSWidth([titleView frame]) + titleRightPadding; | 108 kFramePadding + NSWidth([titleView frame]) + titleRightPadding; |
| 131 const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth); | 109 const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth); |
| 132 | 110 |
| 133 // Layout the elements, starting at the bottom and moving up. | 111 // Layout the elements, starting at the bottom and moving up. |
| 134 | 112 |
| 135 // Buttons go on the bottom row and are right-aligned. | 113 // Buttons go on the bottom row and are right-aligned. |
| 136 // Start with [Save]. | 114 // Start with [Save]. |
| 137 CGFloat curX = width - kFramePadding + kRelatedControlHorizontalPadding; | 115 CGFloat curX = width - kFramePadding + kRelatedControlHorizontalPadding; |
| 138 CGFloat curY = kFramePadding; | 116 CGFloat curY = kFramePadding; |
| 139 | 117 |
| 140 for (NSButton* button in buttons) { | 118 for (NSButton* button in buttons) { |
| 141 curX -= kRelatedControlHorizontalPadding + NSWidth([button frame]); | 119 curX -= kRelatedControlHorizontalPadding + NSWidth([button frame]); |
| 142 [button setFrameOrigin:NSMakePoint(curX, curY)]; | 120 [button setFrameOrigin:NSMakePoint(curX, curY)]; |
| 143 } | 121 } |
| 144 | 122 |
| 145 curX = kFramePadding; | 123 curX = kFramePadding; |
| 146 curY = NSMaxY([buttons.firstObject frame]) + kUnrelatedControlVerticalPadding; | 124 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 | 125 |
| 153 if (passwordRow) { | 126 if (passwordRow) { |
| 154 // Password item goes on the next row. | 127 // Password item goes on the next row. |
| 155 [passwordRow setFrameOrigin:NSMakePoint(curX, curY)]; | 128 [passwordRow setFrameOrigin:NSMakePoint(curX, curY)]; |
| 156 | 129 |
| 157 // Title goes at the top after some padding. | 130 // Title goes at the top after some padding. |
| 158 curY = NSMaxY([passwordRow frame]) + kUnrelatedControlVerticalPadding; | 131 curY = NSMaxY([passwordRow frame]) + kUnrelatedControlVerticalPadding; |
| 159 } | 132 } |
| 160 [titleView setFrameOrigin:NSMakePoint(curX, curY)]; | 133 [titleView setFrameOrigin:NSMakePoint(curX, curY)]; |
| 161 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding; | 134 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 180 | 153 |
| 181 @end | 154 @end |
| 182 | 155 |
| 183 @implementation PendingPasswordViewController (Testing) | 156 @implementation PendingPasswordViewController (Testing) |
| 184 | 157 |
| 185 - (NSButton*)closeButton { | 158 - (NSButton*)closeButton { |
| 186 return closeButton_.get(); | 159 return closeButton_.get(); |
| 187 } | 160 } |
| 188 | 161 |
| 189 @end | 162 @end |
| OLD | NEW |