summaryrefslogtreecommitdiffstats
path: root/components/test_runner/text_input_controller.h
blob: 8edb56e4ac5c2f267d8dbd0694df59a8053415e2 (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
// Copyright 2014 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 COMPONENTS_TEST_RUNNER_TEXT_INPUT_CONTROLLER_H_
#define COMPONENTS_TEST_RUNNER_TEXT_INPUT_CONTROLLER_H_

#include <string>
#include <vector>

#include "base/macros.h"
#include "base/memory/weak_ptr.h"

namespace blink {
class WebFrame;
class WebView;
}

namespace test_runner {

// TextInputController is bound to window.textInputController in Javascript
// when content_shell is running. Layout tests use it to exercise various
// corners of text input.
class TextInputController : public base::SupportsWeakPtr<TextInputController> {
 public:
  TextInputController();
  ~TextInputController();

  void Install(blink::WebFrame* frame);

  void SetWebView(blink::WebView* view);

 private:
  friend class TextInputControllerBindings;

  void InsertText(const std::string& text);
  void UnmarkText();
  void DoCommand(const std::string& text);
  void SetMarkedText(const std::string& text, int start, int length);
  bool HasMarkedText();
  std::vector<int> MarkedRange();
  std::vector<int> SelectedRange();
  std::vector<int> FirstRectForCharacterRange(unsigned location,
                                              unsigned length);
  void SetComposition(const std::string& text);

  blink::WebView* view_;

  base::WeakPtrFactory<TextInputController> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(TextInputController);
};

}  // namespace test_runner

#endif  // COMPONENTS_TEST_RUNNER_TEXT_INPUT_CONTROLLER_H_