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 "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" |
| 11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
| 12 #include "ui/gfx/range/range.h" | 12 #include "ui/gfx/range/range.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 bool AreDifferentTextInputStates(const content::TextInputState& old_state, | 18 bool ShouldUpdateTextInputState(const content::TextInputState& old_state, |
| 19 const content::TextInputState& new_state) { | 19 const content::TextInputState& new_state) { |
| 20 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
| 21 return old_state.type != new_state.type || old_state.mode != new_state.mode || | 21 return old_state.type != new_state.type || old_state.mode != new_state.mode || |
| 22 old_state.flags != new_state.flags || | 22 old_state.flags != new_state.flags || |
| 23 old_state.can_compose_inline != new_state.can_compose_inline; | 23 old_state.can_compose_inline != new_state.can_compose_inline; |
| 24 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
| 25 return old_state.type != new_state.type || | 25 return old_state.type != new_state.type || |
| 26 old_state.can_compose_inline != new_state.can_compose_inline; | 26 old_state.can_compose_inline != new_state.can_compose_inline; |
| 27 #else | 27 #else |
|
Shu Chen
2016/11/21 02:10:53
Can you please add #elif defined(OS_ANDROID) for t
EhsanK
2016/11/21 20:44:21
Acknowledged and done. Although I am not sure what
Charlie Reis
2016/11/23 23:27:21
If you really don't want it to be handled, you can
EhsanK
2016/11/24 03:59:45
Acknowledged.
| |
| 28 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168). | 28 // On Android, TextInputState update is sent only if there is some change in |
| 29 NOTREACHED(); | 29 // the state. So the new state is always different. |
| 30 return true; | 30 return true; |
| 31 #endif | 31 #endif |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 TextInputManager::TextInputManager() : active_view_(nullptr) {} | 36 TextInputManager::TextInputManager() : active_view_(nullptr) {} |
| 37 | 37 |
| 38 TextInputManager::~TextInputManager() { | 38 TextInputManager::~TextInputManager() { |
| 39 // If there is an active view, we should unregister it first so that the | 39 // If there is an active view, we should unregister it first so that the |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 for (auto* view : views) | 50 for (auto* view : views) |
| 51 Unregister(view); | 51 Unregister(view); |
| 52 } | 52 } |
| 53 | 53 |
| 54 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { | 54 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { |
| 55 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( | 55 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( |
| 56 active_view_->GetRenderWidgetHost()) | 56 active_view_->GetRenderWidgetHost()) |
| 57 : nullptr; | 57 : nullptr; |
| 58 } | 58 } |
| 59 | 59 |
| 60 const TextInputState* TextInputManager::GetTextInputState() const { | 60 const TextInputState* TextInputManager::GetTextInputState( |
| 61 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr; | 61 RenderWidgetHostViewBase* view) const { |
| 62 DCHECK(!view || IsRegistered(view)); | |
| 63 if (!view) | |
| 64 view = active_view_; | |
| 65 return !!view ? &text_input_state_map_.at(view) : nullptr; | |
| 62 } | 66 } |
| 63 | 67 |
| 64 const TextInputManager::SelectionRegion* TextInputManager::GetSelectionRegion( | 68 const TextInputManager::SelectionRegion* TextInputManager::GetSelectionRegion( |
| 65 RenderWidgetHostViewBase* view) const { | 69 RenderWidgetHostViewBase* view) const { |
| 66 DCHECK(!view || IsRegistered(view)); | 70 DCHECK(!view || IsRegistered(view)); |
| 67 if (!view) | 71 if (!view) |
| 68 view = active_view_; | 72 view = active_view_; |
| 69 return view ? &selection_region_map_.at(view) : nullptr; | 73 return view ? &selection_region_map_.at(view) : nullptr; |
| 70 } | 74 } |
| 71 | 75 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 98 // one other view has become active and we have received the corresponding | 102 // one other view has become active and we have received the corresponding |
| 99 // IPC from their RenderWidget sooner than this one. That also means we have | 103 // IPC from their RenderWidget sooner than this one. That also means we have |
| 100 // already synthesized the loss of TextInputState for the |view| before (see | 104 // already synthesized the loss of TextInputState for the |view| before (see |
| 101 // below). So we can forget about this method ever being called (no observer | 105 // below). So we can forget about this method ever being called (no observer |
| 102 // calls necessary). | 106 // calls necessary). |
| 103 return; | 107 return; |
| 104 } | 108 } |
| 105 | 109 |
| 106 // Since |view| is registered, we already have a previous value for its | 110 // Since |view| is registered, we already have a previous value for its |
| 107 // TextInputState. | 111 // TextInputState. |
| 108 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], | 112 bool changed = ShouldUpdateTextInputState(text_input_state_map_[view], |
| 109 text_input_state); | 113 text_input_state); |
| 110 | 114 |
| 111 text_input_state_map_[view] = text_input_state; | 115 text_input_state_map_[view] = text_input_state; |
| 112 | 116 |
| 113 // If |view| is different from |active_view| and its |TextInputState.type| is | 117 // If |view| is different from |active_view| and its |TextInputState.type| is |
| 114 // not NONE, |active_view_| should change to |view|. | 118 // not NONE, |active_view_| should change to |view|. |
| 115 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE && | 119 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE && |
| 116 active_view_ != view) { | 120 active_view_ != view) { |
| 117 if (active_view_) { | 121 if (active_view_) { |
| 118 // Ideally, we should always receive an IPC from |active_view_|'s | 122 // Ideally, we should always receive an IPC from |active_view_|'s |
| 119 // RenderWidget to reset its |TextInputState.type| to NONE, before any | 123 // RenderWidget to reset its |TextInputState.type| to NONE, before any |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 "point exceeds text length)."; | 345 "point exceeds text length)."; |
| 342 return false; | 346 return false; |
| 343 } | 347 } |
| 344 | 348 |
| 345 selected_text->clear(); | 349 selected_text->clear(); |
| 346 selected_text->append(text.substr(pos, n)); | 350 selected_text->append(text.substr(pos, n)); |
| 347 return true; | 351 return true; |
| 348 } | 352 } |
| 349 | 353 |
| 350 } // namespace content | 354 } // namespace content |
| OLD | NEW |