1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
2eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// found in the LICENSE file.
4eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#ifndef CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_INPUT_FIELD_H_
6eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_INPUT_FIELD_H_
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#import <Cocoa/Cocoa.h>
97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@protocol AutofillInputField;
117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Access to cell state for autofill input controls.
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@protocol AutofillInputCell<NSObject>
147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@property(nonatomic, assign) BOOL invalid;
167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@property(nonatomic, copy) NSString* fieldValue;
174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)@property(nonatomic, copy) NSString* defaultValue;
187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@end
207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Delegate to handle editing events on the AutofillInputFields.
227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@protocol AutofillInputDelegate<NSObject>
237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Indicates if an event should be forwarded on.
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)enum KeyEventHandled {
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  kKeyEventNotHandled,
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  kKeyEventHandled
28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The input field received a key event. This should return kKeyEventHandled if
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// it handled the event, or kEventNotHandled if it should be forwarded to the
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// input's super class.
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)- (KeyEventHandled)keyEvent:(NSEvent*)event forInput:(id)sender;
34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Input field or its editor received a mouseDown: message.
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)- (void)onMouseDown:(NSControl<AutofillInputField>*)sender;
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// An input field just became first responder.
397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch- (void)fieldBecameFirstResponder:(NSControl<AutofillInputField>*)field;
407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// The user made changes to the value in the field. This is only invoked by
427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// AutofillTextFields.
437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch- (void)didChange:(id)sender;
447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// The user is done with this field. This indicates a loss of firstResponder
467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// status.
477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch- (void)didEndEditing:(id)sender;
487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@end
507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Protocol to allow access to any given input field in an Autofill dialog, no
527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// matter what the underlying control is. All controls act as proxies for their
537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// cells, so inherits from AutofillInputCell.
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch@protocol AutofillInputField
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)@property(nonatomic, assign) id<AutofillInputDelegate> inputDelegate;
577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch@property(nonatomic, copy) NSString* fieldValue;
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)@property(nonatomic, copy) NSString* defaultValue;
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Indicates if the field is at its default setting.
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)@property(nonatomic, readonly) BOOL isDefault;
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Indicates if the field is valid. Empty string or nil indicates a valid
657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// field, everything else is a message to be displayed to the user when the
667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// field has firstResponder status.
677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@property(nonatomic, copy) NSString* validityMessage;
687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// A reflection of the state of the validityMessage described above.
707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch@property(nonatomic, readonly) BOOL invalid;
717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch@end
73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif  // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_INPUT_FIELD_H_
75