OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/mac/bundle_locations.h" | |
9 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
14 #include "chrome/browser/ui/chrome_style.h" | 11 #include "chrome/browser/ui/chrome_style.h" |
15 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" | 12 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" |
16 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" | 13 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" |
17 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 14 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
18 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" | |
19 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" | 15 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
20 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" | 16 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" |
21 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | 17 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
22 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" | 18 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" |
23 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" | 19 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
24 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | |
25 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 20 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
26 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_view.h" | 22 #include "content/public/browser/web_contents_view.h" |
28 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
29 #import "ui/base/cocoa/flipped_view.h" | 24 #import "ui/base/cocoa/flipped_view.h" |
30 #include "ui/base/cocoa/window_size_constants.h" | 25 #include "ui/base/cocoa/window_size_constants.h" |
31 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/gfx/platform_font.h" | |
33 | 27 |
| 28 namespace { |
34 const CGFloat kAccountChooserHeight = 20.0; | 29 const CGFloat kAccountChooserHeight = 20.0; |
35 const CGFloat kMinimumContentsHeight = 101; | 30 const CGFloat kMinimumContentsHeight = 101; |
36 | 31 |
37 // Height of all decorations & paddings on main dialog together. | 32 // Height of all decorations & paddings on main dialog together. |
38 const CGFloat kDecorationHeight = kAccountChooserHeight + | 33 const CGFloat kDecorationHeight = kAccountChooserHeight + |
39 autofill::kDetailVerticalPadding + | 34 autofill::kDetailVerticalPadding + |
40 chrome_style::kClientBottomPadding + | 35 chrome_style::kClientBottomPadding + |
41 chrome_style::kTitleTopPadding; | 36 chrome_style::kTitleTopPadding; |
42 | 37 } // namespace |
43 namespace autofill { | |
44 | |
45 // static | |
46 AutofillDialogView* AutofillDialogView::Create( | |
47 AutofillDialogViewDelegate* delegate) { | |
48 return new AutofillDialogCocoa(delegate); | |
49 } | |
50 | |
51 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogViewDelegate* delegate) | |
52 : close_weak_ptr_factory_(this), | |
53 delegate_(delegate) { | |
54 } | |
55 | |
56 AutofillDialogCocoa::~AutofillDialogCocoa() { | |
57 // Cancel potential relayout requests, since the AutofillDialogController | |
58 // is about to go away, but relayout requests assume it will still exist. | |
59 [sheet_delegate_ cancelRelayout]; | |
60 } | |
61 | |
62 void AutofillDialogCocoa::Show() { | |
63 // This should only be called once. | |
64 DCHECK(!sheet_delegate_.get()); | |
65 sheet_delegate_.reset([[AutofillDialogWindowController alloc] | |
66 initWithWebContents:delegate_->GetWebContents() | |
67 autofillDialog:this]); | |
68 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | |
69 [[CustomConstrainedWindowSheet alloc] | |
70 initWithCustomWindow:[sheet_delegate_ window]]); | |
71 constrained_window_.reset( | |
72 new ConstrainedWindowMac(this, delegate_->GetWebContents(), sheet)); | |
73 [sheet_delegate_ show]; | |
74 } | |
75 | |
76 void AutofillDialogCocoa::Hide() { | |
77 [sheet_delegate_ hide]; | |
78 } | |
79 | |
80 void AutofillDialogCocoa::PerformClose() { | |
81 if (!close_weak_ptr_factory_.HasWeakPtrs()) { | |
82 base::MessageLoop::current()->PostTask( | |
83 FROM_HERE, | |
84 base::Bind(&AutofillDialogCocoa::CloseNow, | |
85 close_weak_ptr_factory_.GetWeakPtr())); | |
86 } | |
87 } | |
88 | |
89 void AutofillDialogCocoa::CloseNow() { | |
90 constrained_window_->CloseWebContentsModalDialog(); | |
91 } | |
92 | |
93 void AutofillDialogCocoa::UpdatesStarted() { | |
94 } | |
95 | |
96 void AutofillDialogCocoa::UpdatesFinished() { | |
97 } | |
98 | |
99 void AutofillDialogCocoa::UpdateAccountChooser() { | |
100 [sheet_delegate_ updateAccountChooser]; | |
101 } | |
102 | |
103 void AutofillDialogCocoa::UpdateButtonStrip() { | |
104 [sheet_delegate_ updateButtonStrip]; | |
105 } | |
106 | |
107 void AutofillDialogCocoa::UpdateOverlay() { | |
108 // TODO(estade): only update the overlay. | |
109 UpdateButtonStrip(); | |
110 } | |
111 | |
112 void AutofillDialogCocoa::UpdateDetailArea() { | |
113 } | |
114 | |
115 void AutofillDialogCocoa::UpdateForErrors() { | |
116 } | |
117 | |
118 void AutofillDialogCocoa::UpdateNotificationArea() { | |
119 [sheet_delegate_ updateNotificationArea]; | |
120 } | |
121 | |
122 void AutofillDialogCocoa::UpdateSection(DialogSection section) { | |
123 [sheet_delegate_ updateSection:section]; | |
124 } | |
125 | |
126 void AutofillDialogCocoa::FillSection(DialogSection section, | |
127 const DetailInput& originating_input) { | |
128 [sheet_delegate_ fillSection:section forInput:originating_input]; | |
129 } | |
130 | |
131 void AutofillDialogCocoa::GetUserInput(DialogSection section, | |
132 DetailOutputMap* output) { | |
133 [sheet_delegate_ getInputs:output forSection:section]; | |
134 } | |
135 | |
136 string16 AutofillDialogCocoa::GetCvc() { | |
137 return base::SysNSStringToUTF16([sheet_delegate_ getCvc]); | |
138 } | |
139 | |
140 bool AutofillDialogCocoa::HitTestInput(const DetailInput& input, | |
141 const gfx::Point& screen_point) { | |
142 // TODO(dbeam): implement. | |
143 return false; | |
144 } | |
145 | |
146 bool AutofillDialogCocoa::SaveDetailsLocally() { | |
147 return [sheet_delegate_ saveDetailsLocally]; | |
148 } | |
149 | |
150 const content::NavigationController* AutofillDialogCocoa::ShowSignIn() { | |
151 return [sheet_delegate_ showSignIn]; | |
152 } | |
153 | |
154 void AutofillDialogCocoa::HideSignIn() { | |
155 [sheet_delegate_ hideSignIn]; | |
156 } | |
157 | |
158 void AutofillDialogCocoa::ModelChanged() { | |
159 [sheet_delegate_ modelChanged]; | |
160 } | |
161 | |
162 void AutofillDialogCocoa::UpdateErrorBubble() { | |
163 [sheet_delegate_ updateErrorBubble]; | |
164 } | |
165 | |
166 TestableAutofillDialogView* AutofillDialogCocoa::GetTestableView() { | |
167 return this; | |
168 } | |
169 | |
170 void AutofillDialogCocoa::OnSignInResize(const gfx::Size& pref_size) { | |
171 [sheet_delegate_ onSignInResize: | |
172 NSMakeSize(pref_size.width(), pref_size.height())]; | |
173 } | |
174 | |
175 void AutofillDialogCocoa::SubmitForTesting() { | |
176 [sheet_delegate_ accept:nil]; | |
177 } | |
178 | |
179 void AutofillDialogCocoa::CancelForTesting() { | |
180 [sheet_delegate_ cancel:nil]; | |
181 } | |
182 | |
183 string16 AutofillDialogCocoa::GetTextContentsOfInput(const DetailInput& input) { | |
184 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | |
185 DialogSection section = static_cast<DialogSection>(i); | |
186 DetailOutputMap contents; | |
187 [sheet_delegate_ getInputs:&contents forSection:section]; | |
188 DetailOutputMap::const_iterator it = contents.find(&input); | |
189 if (it != contents.end()) | |
190 return it->second; | |
191 } | |
192 | |
193 NOTREACHED(); | |
194 return string16(); | |
195 } | |
196 | |
197 void AutofillDialogCocoa::SetTextContentsOfInput(const DetailInput& input, | |
198 const string16& contents) { | |
199 [sheet_delegate_ setTextContents:base::SysUTF16ToNSString(contents) | |
200 forInput:input]; | |
201 } | |
202 | |
203 void AutofillDialogCocoa::SetTextContentsOfSuggestionInput( | |
204 DialogSection section, | |
205 const base::string16& text) { | |
206 [sheet_delegate_ setTextContents:base::SysUTF16ToNSString(text) | |
207 ofSuggestionForSection:section]; | |
208 } | |
209 | |
210 void AutofillDialogCocoa::ActivateInput(const DetailInput& input) { | |
211 [sheet_delegate_ activateFieldForInput:input]; | |
212 } | |
213 | |
214 gfx::Size AutofillDialogCocoa::GetSize() const { | |
215 return gfx::Size(NSSizeToCGSize([[sheet_delegate_ window] frame].size)); | |
216 } | |
217 | |
218 content::WebContents* AutofillDialogCocoa::GetSignInWebContents() { | |
219 return [sheet_delegate_ getSignInWebContents]; | |
220 } | |
221 | |
222 | |
223 bool AutofillDialogCocoa::IsShowingOverlay() const { | |
224 return [sheet_delegate_ IsShowingOverlay]; | |
225 } | |
226 | |
227 void AutofillDialogCocoa::OnConstrainedWindowClosed( | |
228 ConstrainedWindowMac* window) { | |
229 constrained_window_.reset(); | |
230 // |this| belongs to |delegate_|, so no self-destruction here. | |
231 delegate_->ViewClosed(); | |
232 } | |
233 | |
234 } // autofill | |
235 | 38 |
236 #pragma mark "Loading" Shield | 39 #pragma mark "Loading" Shield |
237 | 40 |
238 @interface AutofillOpaqueView : NSView | 41 @interface AutofillOpaqueView : NSView |
239 @end | 42 @end |
240 | 43 |
241 @implementation AutofillOpaqueView | 44 @implementation AutofillOpaqueView |
242 | 45 |
243 - (BOOL)isOpaque { | 46 - (BOOL)isOpaque { |
244 return YES; | 47 return YES; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 472 |
670 - (content::WebContents*)getSignInWebContents { | 473 - (content::WebContents*)getSignInWebContents { |
671 return [signInContainer_ webContents]; | 474 return [signInContainer_ webContents]; |
672 } | 475 } |
673 | 476 |
674 - (BOOL)IsShowingOverlay { | 477 - (BOOL)IsShowingOverlay { |
675 return ![[overlayController_ view] isHidden]; | 478 return ![[overlayController_ view] isHidden]; |
676 } | 479 } |
677 | 480 |
678 @end | 481 @end |
OLD | NEW |