Chromium Code Reviews| 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 #include "ui/gfx/geometry/rect.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 for (auto view : views) | 45 for (auto view : views) |
| 46 Unregister(view); | 46 Unregister(view); |
| 47 } | 47 } |
| 48 | 48 |
| 49 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { | 49 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { |
| 50 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( | 50 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( |
| 51 active_view_->GetRenderWidgetHost()) | 51 active_view_->GetRenderWidgetHost()) |
| 52 : nullptr; | 52 : nullptr; |
| 53 } | 53 } |
| 54 | 54 |
| 55 const TextInputState* TextInputManager::GetTextInputState() { | 55 const TextInputState* TextInputManager::GetTextInputState() const{ |
| 56 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr; | 56 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr; |
| 57 } | 57 } |
| 58 | 58 |
| 59 gfx::Rect TextInputManager::GetSelectionBoundsRect() { | 59 gfx::Rect TextInputManager::GetSelectionBoundsRect() const { |
| 60 if (!active_view_) | 60 if (!active_view_) |
| 61 return gfx::Rect(); | 61 return gfx::Rect(); |
| 62 | 62 |
| 63 return gfx::RectBetweenSelectionBounds( | 63 return gfx::RectBetweenSelectionBounds( |
| 64 selection_region_map_[active_view_].anchor, | 64 selection_region_map_.at(active_view_).anchor, |
| 65 selection_region_map_[active_view_].focus); | 65 selection_region_map_.at(active_view_).focus); |
| 66 } | 66 } |
| 67 | 67 |
| 68 const std::vector<gfx::Rect>* | 68 const std::vector<gfx::Rect>* |
| 69 TextInputManager::GetCompositionCharacterBounds() { | 69 TextInputManager::GetCompositionCharacterBounds() const { |
| 70 return !!active_view_ | 70 return !!active_view_ |
| 71 ? &composition_range_info_map_[active_view_].character_bounds | 71 ? &composition_range_info_map_.at(active_view_).character_bounds |
| 72 : nullptr; | 72 : nullptr; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void TextInputManager::UpdateTextInputState( | 75 void TextInputManager::UpdateTextInputState( |
| 76 RenderWidgetHostViewBase* view, | 76 RenderWidgetHostViewBase* view, |
| 77 const TextInputState& text_input_state) { | 77 const TextInputState& text_input_state) { |
| 78 DCHECK(IsRegistered(view)); | 78 DCHECK(IsRegistered(view)); |
| 79 | 79 |
| 80 // 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 |
| 81 // TextInputState. | 81 // TextInputState. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 } | 171 } |
| 172 | 172 |
| 173 FOR_EACH_OBSERVER(Observer, observer_list_, | 173 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 174 OnImeCompositionRangeChanged(this, view)); | 174 OnImeCompositionRangeChanged(this, view)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void TextInputManager::Register(RenderWidgetHostViewBase* view) { | 177 void TextInputManager::Register(RenderWidgetHostViewBase* view) { |
| 178 DCHECK(!IsRegistered(view)); | 178 DCHECK(!IsRegistered(view)); |
| 179 | 179 |
| 180 text_input_state_map_[view] = TextInputState(); | 180 text_input_state_map_[view] = TextInputState(); |
| 181 selection_region_map_[view] = SelectionRegion(); | |
| 182 composition_range_info_map_[view] = CompositionRangeInfo(); | |
|
Charlie Reis
2016/07/20 23:08:20
Yikes. I would suggest adding a comment to the .h
EhsanK
2016/07/21 16:06:02
Done.
| |
| 181 } | 183 } |
| 182 | 184 |
| 183 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { | 185 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { |
| 184 DCHECK(IsRegistered(view)); | 186 DCHECK(IsRegistered(view)); |
| 185 | 187 |
| 186 text_input_state_map_.erase(view); | 188 text_input_state_map_.erase(view); |
| 189 selection_region_map_.erase(view); | |
| 190 composition_range_info_map_.erase(view); | |
| 191 | |
| 187 if (active_view_ == view) { | 192 if (active_view_ == view) { |
| 188 active_view_ = nullptr; | 193 active_view_ = nullptr; |
| 189 NotifyObserversAboutInputStateUpdate(view, true); | 194 NotifyObserversAboutInputStateUpdate(view, true); |
| 190 } | 195 } |
| 191 view->DidUnregisterFromTextInputManager(this); | 196 view->DidUnregisterFromTextInputManager(this); |
| 192 } | 197 } |
| 193 | 198 |
| 194 bool TextInputManager::IsRegistered(RenderWidgetHostViewBase* view) const { | 199 bool TextInputManager::IsRegistered(RenderWidgetHostViewBase* view) const { |
| 195 return text_input_state_map_.count(view) == 1; | 200 return text_input_state_map_.count(view) == 1; |
| 196 } | 201 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 226 TextInputManager::SelectionRegion::SelectionRegion( | 231 TextInputManager::SelectionRegion::SelectionRegion( |
| 227 const SelectionRegion& other) = default; | 232 const SelectionRegion& other) = default; |
| 228 | 233 |
| 229 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} | 234 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} |
| 230 | 235 |
| 231 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( | 236 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( |
| 232 const CompositionRangeInfo& other) = default; | 237 const CompositionRangeInfo& other) = default; |
| 233 | 238 |
| 234 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} | 239 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} |
| 235 | 240 |
| 236 } // namespace content | 241 } // namespace content |
| OLD | NEW |