- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / autofill / autofill_dialog_cocoa.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DIALOG_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DIALOG_COCOA_H_
7
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
13 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
14 #import "chrome/browser/ui/cocoa/autofill/autofill_layout.h"
15 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
16 #include "ui/gfx/size.h"
17
18 namespace content {
19   class NavigationController;
20 }
21
22 namespace autofill {
23   class AutofillDialogViewDelegate;
24 }
25
26 @class AutofillAccountChooser;
27 @class AutofillDialogWindowController;
28 @class AutofillMainContainer;
29 @class AutofillOverlayController;
30 @class AutofillSignInContainer;
31
32 namespace autofill {
33
34 class AutofillDialogCocoa : public AutofillDialogView,
35                             public TestableAutofillDialogView,
36                             public ConstrainedWindowMacDelegate {
37  public:
38   explicit AutofillDialogCocoa(AutofillDialogViewDelegate* delegate);
39   virtual ~AutofillDialogCocoa();
40
41   // AutofillDialogView implementation:
42   virtual void Show() OVERRIDE;
43   virtual void Hide() OVERRIDE;
44   virtual void UpdatesStarted() OVERRIDE;
45   virtual void UpdatesFinished() OVERRIDE;
46   virtual void UpdateAccountChooser() OVERRIDE;
47   virtual void UpdateButtonStrip() OVERRIDE;
48   virtual void UpdateOverlay() OVERRIDE;
49   virtual void UpdateDetailArea() OVERRIDE;
50   virtual void UpdateForErrors() OVERRIDE;
51   virtual void UpdateNotificationArea() OVERRIDE;
52   virtual void UpdateSection(DialogSection section) OVERRIDE;
53   virtual void UpdateErrorBubble() OVERRIDE;
54   virtual void FillSection(DialogSection section,
55                            const DetailInput& originating_input) OVERRIDE;
56   virtual void GetUserInput(DialogSection section,
57                             DetailOutputMap* output) OVERRIDE;
58   virtual string16 GetCvc() OVERRIDE;
59   virtual bool HitTestInput(const DetailInput& input,
60                             const gfx::Point& screen_point) OVERRIDE;
61   virtual bool SaveDetailsLocally() OVERRIDE;
62   virtual const content::NavigationController* ShowSignIn() OVERRIDE;
63   virtual void HideSignIn() OVERRIDE;
64   virtual void ModelChanged() OVERRIDE;
65   virtual TestableAutofillDialogView* GetTestableView() OVERRIDE;
66   virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE;
67
68   // TestableAutofillDialogView implementation:
69   // TODO(groby): Create a separate class to implement the testable interface:
70   // http://crbug.com/256864
71   virtual void SubmitForTesting() OVERRIDE;
72   virtual void CancelForTesting() OVERRIDE;
73   virtual string16 GetTextContentsOfInput(const DetailInput& input) OVERRIDE;
74   virtual void SetTextContentsOfInput(const DetailInput& input,
75                                       const string16& contents) OVERRIDE;
76   virtual void SetTextContentsOfSuggestionInput(
77       DialogSection section,
78       const base::string16& text) OVERRIDE;
79   virtual void ActivateInput(const DetailInput& input) OVERRIDE;
80   virtual gfx::Size GetSize() const OVERRIDE;
81   virtual content::WebContents* GetSignInWebContents() OVERRIDE;
82   virtual bool IsShowingOverlay() const OVERRIDE;
83
84   // ConstrainedWindowMacDelegate implementation:
85   virtual void OnConstrainedWindowClosed(
86       ConstrainedWindowMac* window) OVERRIDE;
87
88   AutofillDialogViewDelegate* delegate() { return delegate_; }
89
90   // Posts a close request on the current message loop.
91   void PerformClose();
92
93  private:
94   // Closes the sheet and ends the modal loop. Triggers cleanup sequence.
95   void CloseNow();
96
97   scoped_ptr<ConstrainedWindowMac> constrained_window_;
98   base::scoped_nsobject<AutofillDialogWindowController> sheet_delegate_;
99
100   // WeakPtrFactory for deferred close.
101   base::WeakPtrFactory<AutofillDialogCocoa> close_weak_ptr_factory_;
102
103   // The delegate |this| queries for logic and state.
104   AutofillDialogViewDelegate* delegate_;
105 };
106
107 }  // autofill
108
109 @interface AutofillDialogWindowController :
110     NSWindowController<NSWindowDelegate, AutofillLayout> {
111  @private
112   content::WebContents* webContents_;  // weak.
113   autofill::AutofillDialogCocoa* autofillDialog_;  // weak.
114
115   base::scoped_nsobject<AutofillMainContainer> mainContainer_;
116   base::scoped_nsobject<AutofillSignInContainer> signInContainer_;
117   base::scoped_nsobject<AutofillAccountChooser> accountChooser_;
118   base::scoped_nsobject<AutofillOverlayController> overlayController_;
119   base::scoped_nsobject<NSTextField> loadingShieldTextField_;
120   base::scoped_nsobject<NSTextField> titleTextField_;
121 }
122
123 // Designated initializer. The WebContents cannot be NULL.
124 - (id)initWithWebContents:(content::WebContents*)webContents
125            autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog;
126
127 // A child view request re-layouting.
128 - (void)requestRelayout;
129
130 // Cancels all previous requests to re-layout.
131 - (void)cancelRelayout;
132
133 // Validate data. If it is valid, notify the delegate that the user would
134 // like to use the data.
135 - (IBAction)accept:(id)sender;
136
137 // User cancels dialog.
138 - (IBAction)cancel:(id)sender;
139
140 // Forwarding AutofillDialogView calls.
141 - (void)show;
142 - (void)hide;
143 - (void)updateNotificationArea;
144 - (void)updateAccountChooser;
145 - (void)updateButtonStrip;
146 - (void)updateSection:(autofill::DialogSection)section;
147 - (void)fillSection:(autofill::DialogSection)section
148            forInput:(const autofill::DetailInput&)input;
149 - (void)getInputs:(autofill::DetailOutputMap*)outputs
150        forSection:(autofill::DialogSection)section;
151 - (NSString*)getCvc;
152 - (BOOL)saveDetailsLocally;
153 - (content::NavigationController*)showSignIn;
154 - (void)hideSignIn;
155 - (void)modelChanged;
156 - (void)updateErrorBubble;
157 - (void)onSignInResize:(NSSize)size;
158
159 @end
160
161
162 // Mirrors the TestableAutofillDialogView API on the C++ side.
163 @interface AutofillDialogWindowController (TestableAutofillDialogView)
164
165 - (void)setTextContents:(NSString*)text
166                forInput:(const autofill::DetailInput&)input;
167 - (void)setTextContents:(NSString*)text
168  ofSuggestionForSection:(autofill::DialogSection)section;
169 - (void)activateFieldForInput:(const autofill::DetailInput&)input;
170 - (content::WebContents*)getSignInWebContents;
171 - (BOOL)IsShowingOverlay;
172
173 @end
174
175 #endif  // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DIALOG_COCOA_H_