OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/text_input_manager.h" | 5 #include "content/browser/renderer_host/text_input_manager.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "content/browser/renderer_host/render_widget_host_impl.h" | 8 #include "content/browser/renderer_host/render_widget_host_impl.h" |
9 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 9 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (!view) | 83 if (!view) |
84 view = active_view_; | 84 view = active_view_; |
85 return !!view ? &text_selection_map_.at(view) : nullptr; | 85 return !!view ? &text_selection_map_.at(view) : nullptr; |
86 } | 86 } |
87 | 87 |
88 void TextInputManager::UpdateTextInputState( | 88 void TextInputManager::UpdateTextInputState( |
89 RenderWidgetHostViewBase* view, | 89 RenderWidgetHostViewBase* view, |
90 const TextInputState& text_input_state) { | 90 const TextInputState& text_input_state) { |
91 DCHECK(IsRegistered(view)); | 91 DCHECK(IsRegistered(view)); |
92 | 92 |
93 // Since |view| is registgered, we already have a previous value for its | 93 if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE && |
| 94 active_view_ != view) { |
| 95 // We reached here because an IPC is received to reset the TextInputState |
| 96 // for |view|. But |view| != |active_view_|, which suggests that at least |
| 97 // one other view has become active and we have received the corresponding |
| 98 // IPC from their RenderWidget sooner than this one. That also means we have |
| 99 // already synthesized the loss of TextInputState for the |view| before (see |
| 100 // below). So we can forget about this method ever being called (no observer |
| 101 // calls necessary). |
| 102 return; |
| 103 } |
| 104 |
| 105 // Since |view| is registered, we already have a previous value for its |
94 // TextInputState. | 106 // TextInputState. |
95 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], | 107 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], |
96 text_input_state); | 108 text_input_state); |
97 | 109 |
98 text_input_state_map_[view] = text_input_state; | 110 text_input_state_map_[view] = text_input_state; |
99 | 111 |
100 // |active_view_| is only updated when the state for |view| is not none. | 112 // If |view| is different from |active_view| and its |TextInputState.type| is |
101 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE) | 113 // not NONE, |active_view_| should change to |view|. |
| 114 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE && |
| 115 active_view_ != view) { |
| 116 if (active_view_) { |
| 117 // Ideally, we should always receive an IPC from |active_view_|'s |
| 118 // RenderWidget to reset its |TextInputState.type| to NONE, before any |
| 119 // other RenderWidget updates its TextInputState. But there is no |
| 120 // guarantee in the order of IPCs from different RenderWidgets and another |
| 121 // RenderWidget's IPC might arrive sooner and we reach here. To make the |
| 122 // IME behavior identical to the non-OOPIF case, we have to manually reset |
| 123 // the state for |active_view_|. |
| 124 text_input_state_map_[active_view_].type = ui::TEXT_INPUT_TYPE_NONE; |
| 125 RenderWidgetHostViewBase* active_view = active_view_; |
| 126 active_view_ = nullptr; |
| 127 NotifyObserversAboutInputStateUpdate(active_view, true); |
| 128 } |
102 active_view_ = view; | 129 active_view_ = view; |
| 130 } |
103 | 131 |
104 // If the state for |active_view_| is none, then we no longer have an | 132 // If the state for |active_view_| is none, then we no longer have an |
105 // |active_view_|. | 133 // |active_view_|. |
106 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) | 134 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) |
107 active_view_ = nullptr; | 135 active_view_ = nullptr; |
108 | 136 |
109 NotifyObserversAboutInputStateUpdate(view, changed); | 137 NotifyObserversAboutInputStateUpdate(view, changed); |
110 } | 138 } |
111 | 139 |
112 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { | 140 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 298 |
271 TextInputManager::TextSelection::TextSelection() | 299 TextInputManager::TextSelection::TextSelection() |
272 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} | 300 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} |
273 | 301 |
274 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = | 302 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = |
275 default; | 303 default; |
276 | 304 |
277 TextInputManager::TextSelection::~TextSelection() {} | 305 TextInputManager::TextSelection::~TextSelection() {} |
278 | 306 |
279 } // namespace content | 307 } // namespace content |
OLD | NEW |