| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() const { |
| 61 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr; | 61 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 gfx::Rect TextInputManager::GetSelectionBoundsRect() const { | 64 const TextInputManager::SelectionRegion* TextInputManager::GetSelectionRegion( |
| 65 if (!active_view_) | 65 RenderWidgetHostViewBase* view) const { |
| 66 return gfx::Rect(); | 66 DCHECK(!view || IsRegistered(view)); |
| 67 | 67 if (!view) |
| 68 return gfx::RectBetweenSelectionBounds( | 68 view = active_view_; |
| 69 selection_region_map_.at(active_view_).anchor, | 69 return view ? &selection_region_map_.at(view) : nullptr; |
| 70 selection_region_map_.at(active_view_).focus); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 const TextInputManager::CompositionRangeInfo* | 72 const TextInputManager::CompositionRangeInfo* |
| 74 TextInputManager::GetCompositionRangeInfo( | 73 TextInputManager::GetCompositionRangeInfo( |
| 75 RenderWidgetHostViewBase* view) const { | 74 RenderWidgetHostViewBase* view) const { |
| 76 DCHECK(!view || IsRegistered(view)); | 75 DCHECK(!view || IsRegistered(view)); |
| 77 if (!view) | 76 if (!view) |
| 78 view = active_view_; | 77 view = active_view_; |
| 79 return active_view_ ? &composition_range_info_map_.at(active_view_) : nullptr; | 78 return active_view_ ? &composition_range_info_map_.at(active_view_) : nullptr; |
| 80 } | 79 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { | 141 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { |
| 143 DCHECK(IsRegistered(view)); | 142 DCHECK(IsRegistered(view)); |
| 144 FOR_EACH_OBSERVER(Observer, observer_list_, | 143 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 145 OnImeCancelComposition(this, view)); | 144 OnImeCancelComposition(this, view)); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void TextInputManager::SelectionBoundsChanged( | 147 void TextInputManager::SelectionBoundsChanged( |
| 149 RenderWidgetHostViewBase* view, | 148 RenderWidgetHostViewBase* view, |
| 150 const ViewHostMsg_SelectionBounds_Params& params) { | 149 const ViewHostMsg_SelectionBounds_Params& params) { |
| 151 DCHECK(IsRegistered(view)); | 150 DCHECK(IsRegistered(view)); |
| 152 | 151 // Converting the anchor point to root's coordinate space (for child frame |
| 153 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168). | 152 // views). |
| 153 gfx::Point anchor_origin_transformed = |
| 154 view->TransformPointToRootCoordSpace(params.anchor_rect.origin()); |
| 154 #if defined(USE_AURA) | 155 #if defined(USE_AURA) |
| 155 gfx::SelectionBound anchor_bound, focus_bound; | 156 gfx::SelectionBound anchor_bound, focus_bound; |
| 156 // Converting the points to the |view|'s root coordinate space (for child | 157 |
| 157 // frame views). | 158 anchor_bound.SetEdge(gfx::PointF(anchor_origin_transformed), |
| 158 anchor_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace( | |
| 159 params.anchor_rect.origin())), | |
| 160 gfx::PointF(view->TransformPointToRootCoordSpace( | 159 gfx::PointF(view->TransformPointToRootCoordSpace( |
| 161 params.anchor_rect.bottom_left()))); | 160 params.anchor_rect.bottom_left()))); |
| 162 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace( | 161 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace( |
| 163 params.focus_rect.origin())), | 162 params.focus_rect.origin())), |
| 164 gfx::PointF(view->TransformPointToRootCoordSpace( | 163 gfx::PointF(view->TransformPointToRootCoordSpace( |
| 165 params.focus_rect.bottom_left()))); | 164 params.focus_rect.bottom_left()))); |
| 166 | 165 |
| 167 if (params.anchor_rect == params.focus_rect) { | 166 if (params.anchor_rect == params.focus_rect) { |
| 168 anchor_bound.set_type(gfx::SelectionBound::CENTER); | 167 anchor_bound.set_type(gfx::SelectionBound::CENTER); |
| 169 focus_bound.set_type(gfx::SelectionBound::CENTER); | 168 focus_bound.set_type(gfx::SelectionBound::CENTER); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 186 focus_bound.set_type(gfx::SelectionBound::LEFT); | 185 focus_bound.set_type(gfx::SelectionBound::LEFT); |
| 187 } | 186 } |
| 188 } | 187 } |
| 189 | 188 |
| 190 if (anchor_bound == selection_region_map_[view].anchor && | 189 if (anchor_bound == selection_region_map_[view].anchor && |
| 191 focus_bound == selection_region_map_[view].focus) | 190 focus_bound == selection_region_map_[view].focus) |
| 192 return; | 191 return; |
| 193 | 192 |
| 194 selection_region_map_[view].anchor = anchor_bound; | 193 selection_region_map_[view].anchor = anchor_bound; |
| 195 selection_region_map_[view].focus = focus_bound; | 194 selection_region_map_[view].focus = focus_bound; |
| 196 | 195 #else |
| 196 if (params.anchor_rect == params.focus_rect) { |
| 197 selection_region_map_[view].caret_rect.set_origin( |
| 198 anchor_origin_transformed); |
| 199 selection_region_map_[view].caret_rect.set_size(params.anchor_rect.size()); |
| 200 } |
| 201 selection_region_map_[view].first_selection_rect.set_origin( |
| 202 anchor_origin_transformed); |
| 203 selection_region_map_[view].first_selection_rect.set_size( |
| 204 params.anchor_rect.size()); |
| 205 #endif // USE_AURA |
| 197 FOR_EACH_OBSERVER(Observer, observer_list_, | 206 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 198 OnSelectionBoundsChanged(this, view)); | 207 OnSelectionBoundsChanged(this, view)); |
| 199 #endif | |
| 200 } | 208 } |
| 201 | 209 |
| 202 // TODO(ekaramad): We use |range| only on Mac OS; but we still track its value | 210 // TODO(ekaramad): We use |range| only on Mac OS; but we still track its value |
| 203 // here for other platforms. See if there is a nice way around this with minimal | 211 // here for other platforms. See if there is a nice way around this with minimal |
| 204 // #ifdefs for platform specific code (https://crbug.com/602427). | 212 // #ifdefs for platform specific code (https://crbug.com/602427). |
| 205 void TextInputManager::ImeCompositionRangeChanged( | 213 void TextInputManager::ImeCompositionRangeChanged( |
| 206 RenderWidgetHostViewBase* view, | 214 RenderWidgetHostViewBase* view, |
| 207 const gfx::Range& range, | 215 const gfx::Range& range, |
| 208 const std::vector<gfx::Rect>& character_bounds) { | 216 const std::vector<gfx::Rect>& character_bounds) { |
| 209 DCHECK(IsRegistered(view)); | 217 DCHECK(IsRegistered(view)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 "point exceeds text length)."; | 342 "point exceeds text length)."; |
| 335 return false; | 343 return false; |
| 336 } | 344 } |
| 337 | 345 |
| 338 selected_text->clear(); | 346 selected_text->clear(); |
| 339 selected_text->append(text.substr(pos, n)); | 347 selected_text->append(text.substr(pos, n)); |
| 340 return true; | 348 return true; |
| 341 } | 349 } |
| 342 | 350 |
| 343 } // namespace content | 351 } // namespace content |
| OLD | NEW |