summaryrefslogtreecommitdiff
path: root/chromium/content/common/text_input_state.h
blob: 11c2c3f16394649c66c643b1d0e09b50b3efa00b (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
// Copyright 2016 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 CONTENT_COMMON_TEXT_INPUT_STATE_H_
#define CONTENT_COMMON_TEXT_INPUT_STATE_H_

#include "base/optional.h"
#include "base/strings/string16.h"
#include "content/common/content_export.h"
#include "ui/base/ime/text_input_action.h"
#include "ui/base/ime/text_input_mode.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/geometry/rect.h"

namespace content {

// The text input state information for handling IME on the browser side. The
// text input state information such as type, mode, etc. are used by the input
// method to handle IME (the usage is specific to each platform).
struct CONTENT_EXPORT TextInputState {
  TextInputState();
  TextInputState(const TextInputState& other);
  ~TextInputState();

  // Type of the input field.
  ui::TextInputType type = ui::TEXT_INPUT_TYPE_NONE;

  // The mode of input field.
  ui::TextInputMode mode = ui::TEXT_INPUT_MODE_DEFAULT;

  // The action of the input field.
  ui::TextInputAction action = ui::TextInputAction::kDefault;

  // The flags of input field (autocorrect, autocomplete, etc.)
  int flags = 0;

  // The value of input field.
  base::string16 value;

  // The cursor position of the current selection start, or the caret position
  // if nothing is selected.
  int selection_start = 0;

  // The cursor position of the current selection end, or the caret position if
  // nothing is selected.
  int selection_end = 0;

  // The start position of the current composition, or -1 if there is none.
  int composition_start = -1;

  // The end position of the current composition, or -1 if there is none.
  int composition_end = -1;

  // Whether or not inline composition can be performed for the current input.
  bool can_compose_inline = true;

  // Whether or not the IME should be shown as a result of this update. Even if
  // true, the IME will only be shown if the input is appropriate (e.g. not
  // TEXT_INPUT_TYPE_NONE).
  bool show_ime_if_needed = false;

  // Whether or not the IME should always be hidden as a result of this update.
  bool always_hide_ime = false;

  // Whether or not this is a reply to a request from IME.
  bool reply_to_request = false;

  // Store control and selection bounds of EditContext.
  // These optionals will be nullopts if there isn't any active EditContext.
  // For non EditContext scenarios, the bounds are returned via
  // |GetCompositionCharacterBounds|
  base::Optional<gfx::Rect> edit_context_control_bounds;
  base::Optional<gfx::Rect> edit_context_selection_bounds;
};

}  // namespace content

#endif  // CONTENT_COMMON_TEXT_INPUT_STATE_H_