OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
11 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" | 11 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" |
12 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 12 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
13 #import "chrome/browser/ui/cocoa/autofill/autofill_header.h" | 13 #import "chrome/browser/ui/cocoa/autofill/autofill_header.h" |
14 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" | 14 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" |
15 #import "chrome/browser/ui/cocoa/autofill/autofill_loading_shield_controller.h" | 15 #import "chrome/browser/ui/cocoa/autofill/autofill_loading_shield_controller.h" |
16 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" | 16 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
17 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" | 17 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" |
18 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | 18 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
19 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" | 19 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" |
20 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" | 20 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_view.h" | 23 #include "content/public/browser/web_contents_view.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #import "ui/base/cocoa/flipped_view.h" | 25 #import "ui/base/cocoa/flipped_view.h" |
26 #include "ui/base/cocoa/window_size_constants.h" | 26 #include "ui/base/cocoa/window_size_constants.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 | 28 |
29 namespace { | |
30 | |
31 const CGFloat kMinimumContentsHeight = 101; | 29 const CGFloat kMinimumContentsHeight = 101; |
32 | 30 |
33 } // namespace | 31 #pragma mark AutofillDialogWindow |
| 32 |
| 33 // Window class for the AutofillDialog. Its main purpose is the proper handling |
| 34 // of layout requests - i.e. ensuring that layout is fully done before any |
| 35 // updates of the display happen. |
| 36 @interface AutofillDialogWindow : ConstrainedWindowCustomWindow { |
| 37 @private |
| 38 BOOL needsLayout_; // Indicates that the subviews need to be laid out. |
| 39 } |
| 40 |
| 41 // Request a new layout for all subviews. Layout occurs right before -display |
| 42 // or -displayIfNeeded are invoked. |
| 43 - (void)requestRelayout; |
| 44 |
| 45 // Layout the window's subviews. Delegates to the controller. |
| 46 - (void)performLayout; |
| 47 |
| 48 @end |
| 49 |
| 50 |
| 51 @implementation AutofillDialogWindow |
| 52 |
| 53 - (void)requestRelayout { |
| 54 needsLayout_ = YES; |
| 55 } |
| 56 |
| 57 - (void)performLayout { |
| 58 if (needsLayout_) { |
| 59 needsLayout_ = NO; |
| 60 AutofillDialogWindowController* controller = |
| 61 base::mac::ObjCCastStrict<AutofillDialogWindowController>( |
| 62 [self windowController]); |
| 63 [controller performLayout]; |
| 64 } |
| 65 } |
| 66 |
| 67 - (void)display { |
| 68 [self performLayout]; |
| 69 [super display]; |
| 70 } |
| 71 |
| 72 - (void)displayIfNeeded { |
| 73 [self performLayout]; |
| 74 [super displayIfNeeded]; |
| 75 } |
| 76 |
| 77 @end |
34 | 78 |
35 #pragma mark Field Editor | 79 #pragma mark Field Editor |
36 | 80 |
37 @interface AutofillDialogFieldEditor : NSTextView | 81 @interface AutofillDialogFieldEditor : NSTextView |
38 @end | 82 @end |
39 | 83 |
40 | 84 |
41 @implementation AutofillDialogFieldEditor | 85 @implementation AutofillDialogFieldEditor |
42 | 86 |
43 - (void)mouseDown:(NSEvent*)event { | 87 - (void)mouseDown:(NSEvent*)event { |
(...skipping 30 matching lines...) Expand all Loading... |
74 | 118 |
75 // Update size constraints on sign-in container. | 119 // Update size constraints on sign-in container. |
76 - (void)updateSignInSizeConstraints; | 120 - (void)updateSignInSizeConstraints; |
77 | 121 |
78 // Notification that the WebContent's view frame has changed. | 122 // Notification that the WebContent's view frame has changed. |
79 - (void)onContentViewFrameDidChange:(NSNotification*)notification; | 123 - (void)onContentViewFrameDidChange:(NSNotification*)notification; |
80 | 124 |
81 // Update whether or not the main container is hidden. | 125 // Update whether or not the main container is hidden. |
82 - (void)updateMainContainerVisibility; | 126 - (void)updateMainContainerVisibility; |
83 | 127 |
| 128 - (AutofillDialogWindow*)autofillWindow; |
| 129 |
84 @end | 130 @end |
85 | 131 |
86 | 132 |
87 @implementation AutofillDialogWindowController (NSWindowDelegate) | 133 @implementation AutofillDialogWindowController (NSWindowDelegate) |
88 | 134 |
89 - (id)windowWillReturnFieldEditor:(NSWindow*)window toObject:(id)client { | 135 - (id)windowWillReturnFieldEditor:(NSWindow*)window toObject:(id)client { |
90 AutofillTextField* textfield = base::mac::ObjCCast<AutofillTextField>(client); | 136 AutofillTextField* textfield = base::mac::ObjCCast<AutofillTextField>(client); |
91 if (!textfield) | 137 if (!textfield) |
92 return nil; | 138 return nil; |
93 | 139 |
94 if (!fieldEditor_) { | 140 if (!fieldEditor_) { |
95 fieldEditor_.reset([[AutofillDialogFieldEditor alloc] init]); | 141 fieldEditor_.reset([[AutofillDialogFieldEditor alloc] init]); |
96 [fieldEditor_ setFieldEditor:YES]; | 142 [fieldEditor_ setFieldEditor:YES]; |
97 } | 143 } |
98 return fieldEditor_.get(); | 144 return fieldEditor_.get(); |
99 } | 145 } |
100 | 146 |
101 @end | 147 @end |
102 | 148 |
103 | 149 |
104 @implementation AutofillDialogWindowController | 150 @implementation AutofillDialogWindowController |
105 | 151 |
106 - (id)initWithWebContents:(content::WebContents*)webContents | 152 - (id)initWithWebContents:(content::WebContents*)webContents |
107 dialog:(autofill::AutofillDialogCocoa*)dialog { | 153 dialog:(autofill::AutofillDialogCocoa*)dialog { |
108 DCHECK(webContents); | 154 DCHECK(webContents); |
109 | 155 |
110 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( | 156 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( |
111 [[ConstrainedWindowCustomWindow alloc] | 157 [[AutofillDialogWindow alloc] |
112 initWithContentRect:ui::kWindowSizeDeterminedLater]); | 158 initWithContentRect:ui::kWindowSizeDeterminedLater]); |
113 | 159 |
114 if ((self = [super initWithWindow:window])) { | 160 if ((self = [super initWithWindow:window])) { |
115 [window setDelegate:self]; | 161 [window setDelegate:self]; |
116 webContents_ = webContents; | 162 webContents_ = webContents; |
117 dialog_ = dialog; | 163 dialog_ = dialog; |
118 | 164 |
119 header_.reset([[AutofillHeader alloc] initWithDelegate:dialog->delegate()]); | 165 header_.reset([[AutofillHeader alloc] initWithDelegate:dialog->delegate()]); |
120 | 166 |
121 mainContainer_.reset([[AutofillMainContainer alloc] | 167 mainContainer_.reset([[AutofillMainContainer alloc] |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 235 } |
190 | 236 |
191 - (void)updateMainContainerVisibility { | 237 - (void)updateMainContainerVisibility { |
192 BOOL visible = | 238 BOOL visible = |
193 [[loadingShieldController_ view] isHidden] && | 239 [[loadingShieldController_ view] isHidden] && |
194 [[overlayController_ view] isHidden] && | 240 [[overlayController_ view] isHidden] && |
195 [[signInContainer_ view] isHidden]; | 241 [[signInContainer_ view] isHidden]; |
196 [[mainContainer_ view] setHidden:!visible]; | 242 [[mainContainer_ view] setHidden:!visible]; |
197 } | 243 } |
198 | 244 |
199 - (void)cancelRelayout { | 245 - (AutofillDialogWindow*)autofillWindow { |
200 [NSObject cancelPreviousPerformRequestsWithTarget:self | 246 return base::mac::ObjCCastStrict<AutofillDialogWindow>([self window]); |
201 selector:@selector(performLayout) | |
202 object:nil]; | |
203 } | 247 } |
204 | 248 |
205 - (void)requestRelayout { | 249 - (void)requestRelayout { |
206 [self cancelRelayout]; | 250 [[self autofillWindow] requestRelayout]; |
207 [self performSelector:@selector(performLayout) withObject:nil afterDelay:0.0]; | |
208 } | 251 } |
209 | 252 |
210 - (NSSize)preferredSize { | 253 - (NSSize)preferredSize { |
211 NSSize size; | 254 NSSize size; |
212 | 255 |
213 if (![[overlayController_ view] isHidden]) { | 256 if (![[overlayController_ view] isHidden]) { |
214 size.height = [overlayController_ heightForWidth:size.width]; | 257 size.height = [overlayController_ heightForWidth:size.width]; |
215 } else { | 258 } else { |
216 // Overall size is determined by either main container or sign in view. | 259 // Overall size is determined by either main container or sign in view. |
217 if ([[signInContainer_ view] isHidden]) | 260 if ([[signInContainer_ view] isHidden]) |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 444 |
402 - (content::WebContents*)getSignInWebContents { | 445 - (content::WebContents*)getSignInWebContents { |
403 return [signInContainer_ webContents]; | 446 return [signInContainer_ webContents]; |
404 } | 447 } |
405 | 448 |
406 - (BOOL)isShowingOverlay { | 449 - (BOOL)isShowingOverlay { |
407 return ![[overlayController_ view] isHidden]; | 450 return ![[overlayController_ view] isHidden]; |
408 } | 451 } |
409 | 452 |
410 @end | 453 @end |
OLD | NEW |