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

Side by Side Diff: chrome/browser/ui/cocoa/passwords/pending_password_view_controller.mm

Issue 1637043002: Don't try to use ManagePasswordsBubbleModel if the password bubble was closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
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/chrome_style.h" 11 #include "chrome/browser/ui/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"
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 const SkColor kWarmWelcomeColor = SkColorSetRGB(0x64, 0x64, 0x64); 21 const SkColor kWarmWelcomeColor = SkColorSetRGB(0x64, 0x64, 0x64);
22 22
23 @implementation PendingPasswordViewController 23 @implementation PendingPasswordViewController
24 24
25 - (id)initWithModel:(ManagePasswordsBubbleModel*)model
26 delegate:(id<ManagePasswordsBubbleContentViewDelegate>)delegate {
27 if (([super initWithDelegate:delegate])) {
28 model_ = model;
29 }
30 return self;
31 }
32
33 - (BOOL)textView:(NSTextView*)textView 25 - (BOOL)textView:(NSTextView*)textView
34 clickedOnLink:(id)link 26 clickedOnLink:(id)link
35 atIndex:(NSUInteger)charIndex { 27 atIndex:(NSUInteger)charIndex {
36 model_->OnBrandLinkClicked(); 28 ManagePasswordsBubbleModel* model = [self model];
29 if (model)
30 model->OnBrandLinkClicked();
37 [delegate_ viewShouldDismiss]; 31 [delegate_ viewShouldDismiss];
38 return YES; 32 return YES;
39 } 33 }
40 34
41 - (base::scoped_nsobject<NSButton>)newCloseButton { 35 - (base::scoped_nsobject<NSButton>)newCloseButton {
42 const int dimension = chrome_style::GetCloseButtonSize(); 36 const int dimension = chrome_style::GetCloseButtonSize();
43 NSRect frame = NSMakeRect(0, 0, dimension, dimension); 37 NSRect frame = NSMakeRect(0, 0, dimension, dimension);
44 base::scoped_nsobject<NSButton> button( 38 base::scoped_nsobject<NSButton> button(
45 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); 39 [[WebUIHoverCloseButton alloc] initWithFrame:frame]);
46 [button setAction:@selector(viewShouldDismiss)]; 40 [button setAction:@selector(viewShouldDismiss)];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // password row, and the buttons row on one line each, but not smaller than 77 // password row, and the buttons row on one line each, but not smaller than
84 // kDesiredBubbleWidth. 78 // kDesiredBubbleWidth.
85 79
86 // Create the elements and add them to the view. 80 // Create the elements and add them to the view.
87 81
88 // Close button. 82 // Close button.
89 closeButton_ = [self newCloseButton]; 83 closeButton_ = [self newCloseButton];
90 [view addSubview:closeButton_]; 84 [view addSubview:closeButton_];
91 85
92 // Title. 86 // Title.
87 ManagePasswordsBubbleModel* model = [self model];
93 HyperlinkTextView* titleView = TitleLabelWithLink( 88 HyperlinkTextView* titleView = TitleLabelWithLink(
94 model_->title(), model_->title_brand_link_range(), self); 89 model->title(), model->title_brand_link_range(), self);
95 90
96 // Force the text to wrap to fit in the bubble size. 91 // Force the text to wrap to fit in the bubble size.
97 int titleRightPadding = 92 int titleRightPadding =
98 2 * chrome_style::kCloseButtonPadding + NSWidth([closeButton_ frame]); 93 2 * chrome_style::kCloseButtonPadding + NSWidth([closeButton_ frame]);
99 int titleWidth = kDesiredBubbleWidth - kFramePadding - titleRightPadding; 94 int titleWidth = kDesiredBubbleWidth - kFramePadding - titleRightPadding;
100 [titleView setVerticallyResizable:YES]; 95 [titleView setVerticallyResizable:YES];
101 [titleView setFrameSize:NSMakeSize(titleWidth, MAXFLOAT)]; 96 [titleView setFrameSize:NSMakeSize(titleWidth, MAXFLOAT)];
102 // Set the same text inset as in |passwordRow|. 97 // Set the same text inset as in |passwordRow|.
103 [[titleView textContainer] setLineFragmentPadding:kTitleTextInset]; 98 [[titleView textContainer] setLineFragmentPadding:kTitleTextInset];
104 [titleView sizeToFit]; 99 [titleView sizeToFit];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 [closeButton_ setFrameOrigin:closeButtonOrigin]; 165 [closeButton_ setFrameOrigin:closeButtonOrigin];
171 166
172 // Update the bubble size. 167 // Update the bubble size.
173 168
174 [view setFrame:NSMakeRect(0, 0, width, height)]; 169 [view setFrame:NSMakeRect(0, 0, width, height)];
175 170
176 [self setView:view]; 171 [self setView:view];
177 } 172 }
178 173
179 - (ManagePasswordsBubbleModel*)model { 174 - (ManagePasswordsBubbleModel*)model {
180 return model_; 175 return [delegate_ model];
181 } 176 }
182 177
183 @end 178 @end
184 179
185 @implementation PendingPasswordViewController (Testing) 180 @implementation PendingPasswordViewController (Testing)
186 181
187 - (NSButton*)closeButton { 182 - (NSButton*)closeButton {
188 return closeButton_.get(); 183 return closeButton_.get();
189 } 184 }
190 185
191 @end 186 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698