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.
4
5#ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_CONTROLLER_H_
6#define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_CONTROLLER_H_
7
8#include <set>
9
10#include "base/strings/string16.h"
11#include "ui/base/dragdrop/os_exchange_data.h"
12#include "ui/views/views_export.h"
13
14namespace ui {
15class KeyEvent;
16class MouseEvent;
17class SimpleMenuModel;
18}  // namespace ui
19
20namespace views {
21
22class Textfield;
23
24// This defines the callback interface for other code to be notified of changes
25// in the state of a text field.
26class VIEWS_EXPORT TextfieldController {
27 public:
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) {}
33
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);
39
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);
45
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) {}
49
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) {}
53
54  // Called after performing a Cut or Copy operation.
55  virtual void OnAfterCutOrCopy(ui::ClipboardType clipboard_type) {}
56
57  // Called after performing a Paste operation.
58  virtual void OnAfterPaste() {}
59
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) {}
63
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) {}
67
68  // Enables the controller to append to the accepted drop formats.
69  virtual void AppendDropFormats(
70      int* formats,
71      std::set<ui::OSExchangeData::CustomFormat>* custom_formats) {}
72
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
76  // skipped.
77  virtual int OnDrop(const ui::OSExchangeData& data);
78
79  // Gives the controller a chance to modify the context menu contents.
80  virtual void UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {}
81
82 protected:
83  virtual ~TextfieldController() {}
84};
85
86}  // namespace views
87
88#endif  // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_CONTROLLER_H_
89