File: mock_input_method_manager_impl.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (140 lines) | stat: -rw-r--r-- 4,232 bytes parent folder | download | duplicates (6)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/ime/ash/mock_input_method_manager_impl.h"

#include <memory>
#include <optional>
#include <utility>

#include "ui/base/ime/ash/input_method_util.h"

namespace ash {
namespace input_method {

MockInputMethodManagerImpl::State::State(MockInputMethodManagerImpl* manager)
    : manager_(manager) {
  enabled_input_method_ids.emplace_back("xkb:us::eng");
}

scoped_refptr<InputMethodManager::State>
MockInputMethodManagerImpl::State::Clone() const {
  NOTIMPLEMENTED();
  return manager_->GetActiveIMEState();
}

InputMethodDescriptors MockInputMethodManagerImpl::State::
    GetEnabledInputMethodsSortedByLocalizedDisplayNames() const {
  // GetEnabledInputMethods() returns a one-element list, so already "sorted".
  return GetEnabledInputMethods();
}

InputMethodDescriptors
MockInputMethodManagerImpl::State::GetEnabledInputMethods() const {
  InputMethodDescriptors result;
  result.push_back(InputMethodUtil::GetFallbackInputMethodDescriptor());
  return result;
}

const InputMethodDescriptor*
MockInputMethodManagerImpl::State::GetInputMethodFromId(
    const std::string& input_method_id) const {
  static const InputMethodDescriptor defaultInputMethod =
      InputMethodUtil::GetFallbackInputMethodDescriptor();
  for (const auto& enabled_input_method_id : enabled_input_method_ids) {
    if (input_method_id == enabled_input_method_id) {
      return &defaultInputMethod;
    }
  }
  return nullptr;
}

InputMethodDescriptor MockInputMethodManagerImpl::State::GetCurrentInputMethod()
    const {
  InputMethodDescriptor descriptor =
      InputMethodUtil::GetFallbackInputMethodDescriptor();
  if (!current_input_method_id.empty()) {
    return InputMethodDescriptor(
        current_input_method_id, descriptor.name(), descriptor.indicator(),
        descriptor.keyboard_layout(), descriptor.language_codes(), true,
        GURL(),  // options page url.
        GURL(),  // input view page url.
        /*handwriting_language=*/std::nullopt);
  }
  return descriptor;
}

MockInputMethodManagerImpl::State::~State() = default;

MockInputMethodManagerImpl::MockInputMethodManagerImpl()
    : state_(new State(this)), util_(new InputMethodUtil(&delegate_)) {}

MockInputMethodManagerImpl::~MockInputMethodManagerImpl() = default;

void MockInputMethodManagerImpl::AddObserver(
    InputMethodManager::Observer* observer) {
  ++add_observer_count_;
}

void MockInputMethodManagerImpl::AddImeMenuObserver(ImeMenuObserver* observer) {
  ++add_menu_observer_count_;
}

void MockInputMethodManagerImpl::RemoveObserver(
    InputMethodManager::Observer* observer) {
  ++remove_observer_count_;
}

void MockInputMethodManagerImpl::RemoveImeMenuObserver(
    ImeMenuObserver* observer) {
  ++remove_menu_observer_count_;
}

bool MockInputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod()
    const {
  return mod3_used_;
}

ImeKeyboard* MockInputMethodManagerImpl::GetImeKeyboard() {
  return &keyboard_;
}

InputMethodUtil* MockInputMethodManagerImpl::GetInputMethodUtil() {
  return util_.get();
}

ComponentExtensionIMEManager*
MockInputMethodManagerImpl::GetComponentExtensionIMEManager() {
  return comp_ime_manager_.get();
}

scoped_refptr<InputMethodManager::State>
MockInputMethodManagerImpl::CreateNewState(Profile* profile) {
  NOTIMPLEMENTED();
  return state_;
}

scoped_refptr<InputMethodManager::State>
MockInputMethodManagerImpl::GetActiveIMEState() {
  return scoped_refptr<InputMethodManager::State>(state_.get());
}

void MockInputMethodManagerImpl::SetState(
    scoped_refptr<InputMethodManager::State> state) {
  state_ = scoped_refptr<MockInputMethodManagerImpl::State>(
      static_cast<MockInputMethodManagerImpl::State*>(state.get()));
}

void MockInputMethodManagerImpl::SetCurrentInputMethodId(
    const std::string& input_method_id) {
  state_->current_input_method_id = input_method_id;
}

void MockInputMethodManagerImpl::SetComponentExtensionIMEManager(
    std::unique_ptr<ComponentExtensionIMEManager> comp_ime_manager) {
  comp_ime_manager_ = std::move(comp_ime_manager);
}

}  // namespace input_method
}  // namespace ash