summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield/native_textfield_wrapper.h
blob: f4439da3bd29e28f2cefe05f5f4eec0f87d6bd33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_
#define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_
#pragma once

#include "base/string16.h"
#include "ui/gfx/native_widget_types.h"
#include "views/views_export.h"

namespace gfx {
class Insets;
class SelectionModel;
struct StyleRange;
}  // namespace gfx

namespace ui {
class Range;
class TextInputClient;
}  // namespace ui

namespace views {

class KeyEvent;
class Textfield;
class View;

// An interface implemented by an object that provides a platform-native
// text field.
class VIEWS_EXPORT NativeTextfieldWrapper {
 public:
  // The Textfield calls this when it is destroyed to clean up the wrapper
  // object.
  virtual ~NativeTextfieldWrapper() {}

  // Gets the text displayed in the wrapped native text field.
  virtual string16 GetText() const = 0;

  // Updates the text displayed with the text held by the Textfield.
  virtual void UpdateText() = 0;

  // Adds the specified text to the text already displayed by the wrapped native
  // text field.
  virtual void AppendText(const string16& text) = 0;

  // Gets the text that is selected in the wrapped native text field.
  virtual string16 GetSelectedText() const = 0;

  // Selects all the text in the edit.  Use this in place of SetSelAll() to
  // avoid selecting the "phantom newline" at the end of the edit.
  virtual void SelectAll() = 0;

  // Clears the selection within the edit field and sets the caret to the end.
  virtual void ClearSelection() = 0;

  // Updates the border display for the native text field with the state desired
  // by the Textfield.
  virtual void UpdateBorder() = 0;

  // Updates the text color used when painting the native text field.
  virtual void UpdateTextColor() = 0;

  // Updates the background color used when painting the native text field.
  virtual void UpdateBackgroundColor() = 0;

  // Updates the read-only state of the native text field.
  virtual void UpdateReadOnly() = 0;

  // Updates the font used to render text in the native text field.
  virtual void UpdateFont() = 0;

  // Updates the visibility of the text in the native text field.
  virtual void UpdateIsPassword() = 0;

  // Updates the enabled state of the native text field.
  virtual void UpdateEnabled() = 0;

  // Returns the insets for the text field.
  virtual gfx::Insets CalculateInsets() = 0;

  // Updates the horizontal margins for the native text field.
  virtual void UpdateHorizontalMargins() = 0;

  // Updates the vertical margins for the native text field.
  virtual void UpdateVerticalMargins() = 0;

  // Sets the focus to the text field. Returns false if the wrapper
  // didn't take focus.
  virtual bool SetFocus() = 0;

  // Retrieves the views::View that hosts the native control.
  virtual View* GetView() = 0;

  // Returns a handle to the underlying native view for testing.
  virtual gfx::NativeView GetTestingHandle() const = 0;

  // Returns whether or not an IME is composing text.
  virtual bool IsIMEComposing() const = 0;

  // Gets the selected range.
  virtual void GetSelectedRange(ui::Range* range) const = 0;

  // Selects the text given by |range|.
  virtual void SelectRange(const ui::Range& range) = 0;

  // Gets the selection model.
  virtual void GetSelectionModel(gfx::SelectionModel* sel) const = 0;

  // Selects the text given by |sel|.
  virtual void SelectSelectionModel(const gfx::SelectionModel& sel) = 0;

  // Returns the currnet cursor position.
  virtual size_t GetCursorPosition() const = 0;

  // Following methods are to forward key/focus related events to the
  // views wrapper so that TextfieldViews can handle key inputs without
  // having focus.

  // Invoked when a key is pressed/release on Textfield.  Subclasser
  // should return true if the event has been processed and false
  // otherwise.
  // See also View::OnKeyPressed/OnKeyReleased.
  virtual bool HandleKeyPressed(const views::KeyEvent& e) = 0;
  virtual bool HandleKeyReleased(const views::KeyEvent& e) = 0;

  // Invoked when focus is being moved from or to the Textfield.
  // See also View::OnFocus/OnBlur.
  virtual void HandleFocus() = 0;
  virtual void HandleBlur() = 0;

  // Returns the View's TextInputClient instance or NULL if the View doesn't
  // support text input.
  virtual ui::TextInputClient* GetTextInputClient() = 0;

  // Applies the |style| to the text specified by its range.
  // See |Textfield::ApplyStyleRange| for detail.
  virtual void ApplyStyleRange(const gfx::StyleRange& style) = 0;

  // Applies the default style to the textfield.
  virtual void ApplyDefaultStyle() = 0;

  // Clears Edit history.
  virtual void ClearEditHistory() = 0;

  // Creates an appropriate NativeTextfieldWrapper for the platform.
  static NativeTextfieldWrapper* CreateWrapper(Textfield* field);
};

}  // namespace views

#endif  // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_