Chromium Code Reviews| 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 { | 29 namespace { |
|
Nico
2013/11/27 01:03:06
const has implicit internal linkage, empty namespa
groby-ooo-7-16
2013/11/27 01:34:04
Done.
| |
| 30 | 30 |
| 31 const CGFloat kMinimumContentsHeight = 101; | 31 const CGFloat kMinimumContentsHeight = 101; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 #pragma mark AutofillDialogWindow | |
| 36 | |
| 37 // Window class for the AutofillDialog. Its main purpose is the proper handling | |
| 38 // of layout requests - i.e. ensuring that layout is fully done before any | |
| 39 // updates of the display happen. | |
| 40 @interface AutofillDialogWindow : ConstrainedWindowCustomWindow { | |
| 41 @private | |
| 42 BOOL needsLayout; // Indicates that the subviews need to be laid out. | |
|
Nico
2013/11/27 01:03:06
don't we name instance variables with a trailing _
groby-ooo-7-16
2013/11/27 01:34:04
Yes, we do. My brain is already eating turkey, it
| |
| 43 } | |
| 44 | |
| 45 // Request a new layout for all subviews. Layout occurs right before -display | |
| 46 // or -displayIfNeeded are invoked. | |
| 47 - (void)requestRelayout; | |
| 48 | |
| 49 // Layout the window's subviews. Delegates to the controller. | |
| 50 - (void)performLayout; | |
| 51 | |
| 52 @end | |
| 53 | |
| 54 | |
| 55 @implementation AutofillDialogWindow | |
| 56 | |
| 57 - (void)requestRelayout { | |
| 58 needsLayout = YES; | |
| 59 } | |
| 60 | |
| 61 - (void)performLayout { | |
| 62 if (needsLayout) { | |
| 63 needsLayout = NO; | |
| 64 AutofillDialogWindowController* controller = | |
| 65 base::mac::ObjCCastStrict<AutofillDialogWindowController>( | |
| 66 [self windowController]); | |
| 67 [controller performLayout]; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 - (void)display { | |
| 72 [self performLayout]; | |
| 73 [super display]; | |
| 74 } | |
| 75 | |
| 76 - (void)displayIfNeeded { | |
| 77 [self performLayout]; | |
| 78 [super displayIfNeeded]; | |
| 79 } | |
| 80 | |
| 81 @end | |
| 82 | |
| 35 #pragma mark Field Editor | 83 #pragma mark Field Editor |
| 36 | 84 |
| 37 @interface AutofillDialogFieldEditor : NSTextView | 85 @interface AutofillDialogFieldEditor : NSTextView |
| 38 @end | 86 @end |
| 39 | 87 |
| 40 | 88 |
| 41 @implementation AutofillDialogFieldEditor | 89 @implementation AutofillDialogFieldEditor |
| 42 | 90 |
| 43 - (void)mouseDown:(NSEvent*)event { | 91 - (void)mouseDown:(NSEvent*)event { |
| 44 // Delegate _must_ be notified before mouseDown is complete, since it needs | 92 // Delegate _must_ be notified before mouseDown is complete, since it needs |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 74 | 122 |
| 75 // Update size constraints on sign-in container. | 123 // Update size constraints on sign-in container. |
| 76 - (void)updateSignInSizeConstraints; | 124 - (void)updateSignInSizeConstraints; |
| 77 | 125 |
| 78 // Notification that the WebContent's view frame has changed. | 126 // Notification that the WebContent's view frame has changed. |
| 79 - (void)onContentViewFrameDidChange:(NSNotification*)notification; | 127 - (void)onContentViewFrameDidChange:(NSNotification*)notification; |
| 80 | 128 |
| 81 // Update whether or not the main container is hidden. | 129 // Update whether or not the main container is hidden. |
| 82 - (void)updateMainContainerVisibility; | 130 - (void)updateMainContainerVisibility; |
| 83 | 131 |
| 132 - (AutofillDialogWindow*)autofillWindow; | |
| 133 | |
| 84 @end | 134 @end |
| 85 | 135 |
| 86 | 136 |
| 87 @implementation AutofillDialogWindowController (NSWindowDelegate) | 137 @implementation AutofillDialogWindowController (NSWindowDelegate) |
| 88 | 138 |
| 89 - (id)windowWillReturnFieldEditor:(NSWindow*)window toObject:(id)client { | 139 - (id)windowWillReturnFieldEditor:(NSWindow*)window toObject:(id)client { |
| 90 AutofillTextField* textfield = base::mac::ObjCCast<AutofillTextField>(client); | 140 AutofillTextField* textfield = base::mac::ObjCCast<AutofillTextField>(client); |
| 91 if (!textfield) | 141 if (!textfield) |
| 92 return nil; | 142 return nil; |
| 93 | 143 |
| 94 if (!fieldEditor_) { | 144 if (!fieldEditor_) { |
| 95 fieldEditor_.reset([[AutofillDialogFieldEditor alloc] init]); | 145 fieldEditor_.reset([[AutofillDialogFieldEditor alloc] init]); |
| 96 [fieldEditor_ setFieldEditor:YES]; | 146 [fieldEditor_ setFieldEditor:YES]; |
| 97 } | 147 } |
| 98 return fieldEditor_.get(); | 148 return fieldEditor_.get(); |
| 99 } | 149 } |
| 100 | 150 |
| 101 @end | 151 @end |
| 102 | 152 |
| 103 | 153 |
| 104 @implementation AutofillDialogWindowController | 154 @implementation AutofillDialogWindowController |
| 105 | 155 |
| 106 - (id)initWithWebContents:(content::WebContents*)webContents | 156 - (id)initWithWebContents:(content::WebContents*)webContents |
| 107 dialog:(autofill::AutofillDialogCocoa*)dialog { | 157 dialog:(autofill::AutofillDialogCocoa*)dialog { |
| 108 DCHECK(webContents); | 158 DCHECK(webContents); |
| 109 | 159 |
| 110 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( | 160 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( |
| 111 [[ConstrainedWindowCustomWindow alloc] | 161 [[AutofillDialogWindow alloc] |
| 112 initWithContentRect:ui::kWindowSizeDeterminedLater]); | 162 initWithContentRect:ui::kWindowSizeDeterminedLater]); |
| 113 | 163 |
| 114 if ((self = [super initWithWindow:window])) { | 164 if ((self = [super initWithWindow:window])) { |
| 115 [window setDelegate:self]; | 165 [window setDelegate:self]; |
| 116 webContents_ = webContents; | 166 webContents_ = webContents; |
| 117 dialog_ = dialog; | 167 dialog_ = dialog; |
| 118 | 168 |
| 119 header_.reset([[AutofillHeader alloc] initWithDelegate:dialog->delegate()]); | 169 header_.reset([[AutofillHeader alloc] initWithDelegate:dialog->delegate()]); |
| 120 | 170 |
| 121 mainContainer_.reset([[AutofillMainContainer alloc] | 171 mainContainer_.reset([[AutofillMainContainer alloc] |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 } | 239 } |
| 190 | 240 |
| 191 - (void)updateMainContainerVisibility { | 241 - (void)updateMainContainerVisibility { |
| 192 BOOL visible = | 242 BOOL visible = |
| 193 [[loadingShieldController_ view] isHidden] && | 243 [[loadingShieldController_ view] isHidden] && |
| 194 [[overlayController_ view] isHidden] && | 244 [[overlayController_ view] isHidden] && |
| 195 [[signInContainer_ view] isHidden]; | 245 [[signInContainer_ view] isHidden]; |
| 196 [[mainContainer_ view] setHidden:!visible]; | 246 [[mainContainer_ view] setHidden:!visible]; |
| 197 } | 247 } |
| 198 | 248 |
| 199 - (void)cancelRelayout { | 249 - (AutofillDialogWindow*)autofillWindow { |
| 200 [NSObject cancelPreviousPerformRequestsWithTarget:self | 250 return base::mac::ObjCCastStrict<AutofillDialogWindow>([self window]); |
| 201 selector:@selector(performLayout) | |
| 202 object:nil]; | |
| 203 } | 251 } |
| 204 | 252 |
| 205 - (void)requestRelayout { | 253 - (void)requestRelayout { |
| 206 [self cancelRelayout]; | 254 [[self autofillWindow] requestRelayout]; |
| 207 [self performSelector:@selector(performLayout) withObject:nil afterDelay:0.0]; | |
| 208 } | 255 } |
| 209 | 256 |
| 210 - (NSSize)preferredSize { | 257 - (NSSize)preferredSize { |
| 211 NSSize size; | 258 NSSize size; |
| 212 | 259 |
| 213 if (![[overlayController_ view] isHidden]) { | 260 if (![[overlayController_ view] isHidden]) { |
| 214 size.height = [overlayController_ heightForWidth:size.width]; | 261 size.height = [overlayController_ heightForWidth:size.width]; |
| 215 } else { | 262 } else { |
| 216 // Overall size is determined by either main container or sign in view. | 263 // Overall size is determined by either main container or sign in view. |
| 217 if ([[signInContainer_ view] isHidden]) | 264 if ([[signInContainer_ view] isHidden]) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 | 448 |
| 402 - (content::WebContents*)getSignInWebContents { | 449 - (content::WebContents*)getSignInWebContents { |
| 403 return [signInContainer_ webContents]; | 450 return [signInContainer_ webContents]; |
| 404 } | 451 } |
| 405 | 452 |
| 406 - (BOOL)isShowingOverlay { | 453 - (BOOL)isShowingOverlay { |
| 407 return ![[overlayController_ view] isHidden]; | 454 return ![[overlayController_ view] isHidden]; |
| 408 } | 455 } |
| 409 | 456 |
| 410 @end | 457 @end |
| OLD | NEW |