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