Index: content/browser/renderer_host/text_input_manager.cc |
diff --git a/content/browser/renderer_host/text_input_manager.cc b/content/browser/renderer_host/text_input_manager.cc |
index 07c5de9f65fc2367565ab37e3dce5874eb56369c..09e8862bbe252a0a98077add7c18ac3b68ece2db 100644 |
--- a/content/browser/renderer_host/text_input_manager.cc |
+++ b/content/browser/renderer_host/text_input_manager.cc |
@@ -4,10 +4,12 @@ |
#include "content/browser/renderer_host/text_input_manager.h" |
+#include "base/strings/string16.h" |
#include "content/browser/renderer_host/render_widget_host_impl.h" |
#include "content/browser/renderer_host/render_widget_host_view_base.h" |
#include "content/common/view_messages.h" |
#include "ui/gfx/geometry/rect.h" |
+#include "ui/gfx/range/range.h" |
namespace content { |
@@ -72,6 +74,14 @@ const std::vector<gfx::Rect>* TextInputManager::GetCompositionCharacterBounds() |
: nullptr; |
} |
+const TextInputManager::TextSelection* TextInputManager::GetTextSelection( |
+ RenderWidgetHostViewBase* view) const { |
+ DCHECK(!view || IsRegistered(view)); |
+ if (!view) |
+ view = active_view_; |
+ return !!view ? &text_selection_map_.at(view) : nullptr; |
+} |
+ |
void TextInputManager::UpdateTextInputState( |
RenderWidgetHostViewBase* view, |
const TextInputState& text_input_state) { |
@@ -174,12 +184,28 @@ void TextInputManager::ImeCompositionRangeChanged( |
OnImeCompositionRangeChanged(this, view)); |
} |
+void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view, |
+ const base::string16& text, |
+ size_t offset, |
+ const gfx::Range& range) { |
+ DCHECK(IsRegistered(view)); |
+ |
+ text_selection_map_[view].text = text; |
+ text_selection_map_[view].offset = offset; |
+ text_selection_map_[view].range.set_start(range.start()); |
+ text_selection_map_[view].range.set_end(range.end()); |
+ |
+ FOR_EACH_OBSERVER(Observer, observer_list_, |
+ OnTextSelectionChanged(this, view)); |
+} |
+ |
void TextInputManager::Register(RenderWidgetHostViewBase* view) { |
DCHECK(!IsRegistered(view)); |
text_input_state_map_[view] = TextInputState(); |
selection_region_map_[view] = SelectionRegion(); |
composition_range_info_map_[view] = CompositionRangeInfo(); |
+ text_selection_map_[view] = TextSelection(); |
} |
void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { |
@@ -188,6 +214,7 @@ void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { |
text_input_state_map_.erase(view); |
selection_region_map_.erase(view); |
composition_range_info_map_.erase(view); |
+ text_selection_map_.erase(view); |
if (active_view_ == view) { |
active_view_ = nullptr; |
@@ -238,4 +265,12 @@ TextInputManager::CompositionRangeInfo::CompositionRangeInfo( |
TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} |
+TextInputManager::TextSelection::TextSelection() |
+ : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} |
+ |
+TextInputManager::TextSelection::TextSelection(const TextSelection& other) = |
+ default; |
+ |
+TextInputManager::TextSelection::~TextSelection() {} |
+ |
} // namespace content |