1 // Copyright (c) 2012 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.
5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_CONTROLLER_H_
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_CONTROLLER_H_
10 #include "base/strings/string16.h"
11 #include "ui/base/dragdrop/os_exchange_data.h"
12 #include "ui/views/views_export.h"
17 class SimpleMenuModel
;
24 // This defines the callback interface for other code to be notified of changes
25 // in the state of a text field.
26 class VIEWS_EXPORT TextfieldController
{
28 // This method is called whenever the text in the field is changed by the
29 // user. It won't be called if the text is changed by calling
30 // Textfield::SetText() or Textfield::AppendText().
31 virtual void ContentsChanged(Textfield
* sender
,
32 const base::string16
& new_contents
) {}
34 // This method is called to get notified about keystrokes in the edit.
35 // Returns true if the message was handled and should not be processed
36 // further. If it returns false the processing continues.
37 virtual bool HandleKeyEvent(Textfield
* sender
,
38 const ui::KeyEvent
& key_event
);
40 // This method is called to get notified about mouse events in the edit.
41 // Returns true if the message was handled and should not be processed
42 // further. Currently, only mouse down events are sent here.
43 virtual bool HandleMouseEvent(Textfield
* sender
,
44 const ui::MouseEvent
& mouse_event
);
46 // Called before performing a user action that may change the textfield.
47 // It's currently only supported by Views implementation.
48 virtual void OnBeforeUserAction(Textfield
* sender
) {}
50 // Called after performing a user action that may change the textfield.
51 // It's currently only supported by Views implementation.
52 virtual void OnAfterUserAction(Textfield
* sender
) {}
54 // Called after performing a Cut or Copy operation.
55 virtual void OnAfterCutOrCopy(ui::ClipboardType clipboard_type
) {}
57 // Called after performing a Paste operation.
58 virtual void OnAfterPaste() {}
60 // Called after the textfield has written drag data to give the controller a
61 // chance to modify the drag data.
62 virtual void OnWriteDragData(ui::OSExchangeData
* data
) {}
64 // Called after the textfield has set default drag operations to give the
65 // controller a chance to update them.
66 virtual void OnGetDragOperationsForTextfield(int* drag_operations
) {}
68 // Enables the controller to append to the accepted drop formats.
69 virtual void AppendDropFormats(
71 std::set
<ui::OSExchangeData::CustomFormat
>* custom_formats
) {}
73 // Called when a drop of dragged data happens on the textfield. This method is
74 // called before regular handling of the drop. If this returns a drag
75 // operation other than |ui::DragDropTypes::DRAG_NONE|, regular handling is
77 virtual int OnDrop(const ui::OSExchangeData
& data
);
79 // Gives the controller a chance to modify the context menu contents.
80 virtual void UpdateContextMenu(ui::SimpleMenuModel
* menu_contents
) {}
83 virtual ~TextfieldController() {}
88 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_CONTROLLER_H_