| 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 "content/browser/renderer_host/render_widget_host_impl.h" | 7 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 8 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 8 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 10 #include "ui/gfx/geometry/rect.h" |
| 10 | 11 |
| 11 namespace content { | 12 namespace content { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 bool AreDifferentTextInputStates(const content::TextInputState& old_state, | 16 bool AreDifferentTextInputStates(const content::TextInputState& old_state, |
| 16 const content::TextInputState& new_state) { | 17 const content::TextInputState& new_state) { |
| 17 #if defined(USE_AURA) | 18 #if defined(USE_AURA) |
| 18 return old_state.type != new_state.type || old_state.mode != new_state.mode || | 19 return old_state.type != new_state.type || old_state.mode != new_state.mode || |
| 19 old_state.flags != new_state.flags || | 20 old_state.flags != new_state.flags || |
| (...skipping 18 matching lines...) Expand all Loading... |
| 38 | 39 |
| 39 // Unregister all the remaining views. | 40 // Unregister all the remaining views. |
| 40 std::vector<RenderWidgetHostViewBase*> views; | 41 std::vector<RenderWidgetHostViewBase*> views; |
| 41 for (auto pair : text_input_state_map_) | 42 for (auto pair : text_input_state_map_) |
| 42 views.push_back(pair.first); | 43 views.push_back(pair.first); |
| 43 | 44 |
| 44 for (auto view : views) | 45 for (auto view : views) |
| 45 Unregister(view); | 46 Unregister(view); |
| 46 } | 47 } |
| 47 | 48 |
| 48 const TextInputState* TextInputManager::GetTextInputState() { | |
| 49 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr; | |
| 50 } | |
| 51 | |
| 52 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { | 49 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { |
| 53 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( | 50 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( |
| 54 active_view_->GetRenderWidgetHost()) | 51 active_view_->GetRenderWidgetHost()) |
| 55 : nullptr; | 52 : nullptr; |
| 56 } | 53 } |
| 57 | 54 |
| 55 const TextInputState* TextInputManager::GetTextInputState() { |
| 56 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr; |
| 57 } |
| 58 |
| 58 gfx::Rect TextInputManager::GetSelectionBoundsRect() { | 59 gfx::Rect TextInputManager::GetSelectionBoundsRect() { |
| 59 if (!active_view_) | 60 if (!active_view_) |
| 60 return gfx::Rect(); | 61 return gfx::Rect(); |
| 61 | 62 |
| 62 return gfx::RectBetweenSelectionBounds( | 63 return gfx::RectBetweenSelectionBounds( |
| 63 selection_region_map_[active_view_].anchor, | 64 selection_region_map_[active_view_].anchor, |
| 64 selection_region_map_[active_view_].focus); | 65 selection_region_map_[active_view_].focus); |
| 65 } | 66 } |
| 66 | 67 |
| 68 const std::vector<gfx::Rect>* |
| 69 TextInputManager::GetCompositionCharacterBounds() { |
| 70 return !!active_view_ |
| 71 ? &composition_range_info_map_[active_view_].character_bounds |
| 72 : nullptr; |
| 73 } |
| 74 |
| 67 void TextInputManager::UpdateTextInputState( | 75 void TextInputManager::UpdateTextInputState( |
| 68 RenderWidgetHostViewBase* view, | 76 RenderWidgetHostViewBase* view, |
| 69 const TextInputState& text_input_state) { | 77 const TextInputState& text_input_state) { |
| 70 DCHECK(IsRegistered(view)); | 78 DCHECK(IsRegistered(view)); |
| 71 | 79 |
| 72 // Since |view| is registgered, we already have a previous value for its | 80 // Since |view| is registgered, we already have a previous value for its |
| 73 // TextInputState. | 81 // TextInputState. |
| 74 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], | 82 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], |
| 75 text_input_state); | 83 text_input_state); |
| 76 | 84 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 return; | 149 return; |
| 142 | 150 |
| 143 selection_region_map_[view].anchor = anchor_bound; | 151 selection_region_map_[view].anchor = anchor_bound; |
| 144 selection_region_map_[view].focus = focus_bound; | 152 selection_region_map_[view].focus = focus_bound; |
| 145 | 153 |
| 146 FOR_EACH_OBSERVER(Observer, observer_list_, | 154 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 147 OnSelectionBoundsChanged(this, view)); | 155 OnSelectionBoundsChanged(this, view)); |
| 148 #endif | 156 #endif |
| 149 } | 157 } |
| 150 | 158 |
| 159 void TextInputManager::ImeCompositionRangeChanged( |
| 160 RenderWidgetHostViewBase* view, |
| 161 const gfx::Range& range, |
| 162 const std::vector<gfx::Rect>& character_bounds) { |
| 163 DCHECK(IsRegistered(view)); |
| 164 composition_range_info_map_[view].character_bounds.clear(); |
| 165 |
| 166 // The values for the bounds should be converted to root view's coordinates |
| 167 // before being stored. |
| 168 for (auto rect : character_bounds) { |
| 169 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect( |
| 170 view->TransformPointToRootCoordSpace(rect.origin()), rect.size())); |
| 171 } |
| 172 |
| 173 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 174 OnImeCompositionRangeChanged(this, view)); |
| 175 } |
| 176 |
| 151 void TextInputManager::Register(RenderWidgetHostViewBase* view) { | 177 void TextInputManager::Register(RenderWidgetHostViewBase* view) { |
| 152 DCHECK(!IsRegistered(view)); | 178 DCHECK(!IsRegistered(view)); |
| 153 | 179 |
| 154 text_input_state_map_[view] = TextInputState(); | 180 text_input_state_map_[view] = TextInputState(); |
| 155 } | 181 } |
| 156 | 182 |
| 157 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { | 183 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { |
| 158 DCHECK(IsRegistered(view)); | 184 DCHECK(IsRegistered(view)); |
| 159 | 185 |
| 160 text_input_state_map_.erase(view); | 186 text_input_state_map_.erase(view); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 FOR_EACH_OBSERVER( | 219 FOR_EACH_OBSERVER( |
| 194 Observer, observer_list_, | 220 Observer, observer_list_, |
| 195 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); | 221 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); |
| 196 } | 222 } |
| 197 | 223 |
| 198 TextInputManager::SelectionRegion::SelectionRegion() {} | 224 TextInputManager::SelectionRegion::SelectionRegion() {} |
| 199 | 225 |
| 200 TextInputManager::SelectionRegion::SelectionRegion( | 226 TextInputManager::SelectionRegion::SelectionRegion( |
| 201 const SelectionRegion& other) = default; | 227 const SelectionRegion& other) = default; |
| 202 | 228 |
| 229 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} |
| 230 |
| 231 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( |
| 232 const CompositionRangeInfo& other) = default; |
| 233 |
| 234 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} |
| 235 |
| 203 } // namespace content | 236 } // namespace content |
| OLD | NEW |