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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 DCHECK(!view || IsRegistered(view)); | 79 DCHECK(!view || IsRegistered(view)); |
80 if (!view) | 80 if (!view) |
81 view = active_view_; | 81 view = active_view_; |
82 return !!view ? &text_selection_map_.at(view) : nullptr; | 82 return !!view ? &text_selection_map_.at(view) : nullptr; |
83 } | 83 } |
84 | 84 |
85 void TextInputManager::UpdateTextInputState( | 85 void TextInputManager::UpdateTextInputState( |
86 RenderWidgetHostViewBase* view, | 86 RenderWidgetHostViewBase* view, |
87 const TextInputState& text_input_state) { | 87 const TextInputState& text_input_state) { |
88 DCHECK(IsRegistered(view)); | 88 DCHECK(IsRegistered(view)); |
89 | |
90 // Since |view| is registgered, we already have a previous value for its | 89 // Since |view| is registgered, we already have a previous value for its |
91 // TextInputState. | 90 // TextInputState. |
92 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], | 91 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], |
93 text_input_state); | 92 text_input_state); |
94 | 93 |
95 text_input_state_map_[view] = text_input_state; | 94 text_input_state_map_[view] = text_input_state; |
96 | 95 |
97 // |active_view_| is only updated when the state for |view| is not none. | 96 // If |view| is different from |active_view| and its |TextInputState.type| is |
98 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE) | 97 // not NONE, |active_view_| should change to |view|. |
98 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE && | |
99 active_view_ != view) { | |
100 if (active_view_) { | |
101 // Ideally, we should always receive an IPC from |active_view_|'s | |
102 // RenderWidget to reset its |TextInputState.type| to NONE, before any | |
103 // other RenderWidget updates its TextInputState. But there is no | |
104 // guarantee in the order of IPCs from different RenderWidges and another | |
kenrb
2016/07/26 20:40:38
nit: Typo 'RenderWidges'
EhsanK
2016/07/26 21:27:56
Done.
| |
105 // RenderWidget's IPC might arrive sooner and we reach here. To make the | |
106 // IME behavior identical to the non-OOPIF case, we have to manually reset | |
107 // the state for |active_view_|. | |
108 text_input_state_map_[active_view_].type = ui::TEXT_INPUT_TYPE_NONE; | |
109 RenderWidgetHostViewBase* active_view = active_view_; | |
110 active_view_ = nullptr; | |
111 NotifyObserversAboutInputStateUpdate(active_view, true); | |
112 } | |
99 active_view_ = view; | 113 active_view_ = view; |
114 } | |
100 | 115 |
101 // If the state for |active_view_| is none, then we no longer have an | 116 // If the state for |active_view_| is none, then we no longer have an |
102 // |active_view_|. | 117 // |active_view_|. |
103 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) | 118 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) |
104 active_view_ = nullptr; | 119 active_view_ = nullptr; |
105 | 120 |
106 NotifyObserversAboutInputStateUpdate(view, changed); | 121 NotifyObserversAboutInputStateUpdate(view, changed); |
107 } | 122 } |
108 | 123 |
109 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { | 124 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 | 282 |
268 TextInputManager::TextSelection::TextSelection() | 283 TextInputManager::TextSelection::TextSelection() |
269 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} | 284 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} |
270 | 285 |
271 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = | 286 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = |
272 default; | 287 default; |
273 | 288 |
274 TextInputManager::TextSelection::~TextSelection() {} | 289 TextInputManager::TextSelection::~TextSelection() {} |
275 | 290 |
276 } // namespace content | 291 } // namespace content |
OLD | NEW |