Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: content/browser/renderer_host/text_input_manager.cc

Issue 2418143004: Reduce FOR_EACH_OBSERVER usage in content/browser/renderer_host (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // If the state for |active_view_| is none, then we no longer have an 133 // If the state for |active_view_| is none, then we no longer have an
134 // |active_view_|. 134 // |active_view_|.
135 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) 135 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
136 active_view_ = nullptr; 136 active_view_ = nullptr;
137 137
138 NotifyObserversAboutInputStateUpdate(view, changed); 138 NotifyObserversAboutInputStateUpdate(view, changed);
139 } 139 }
140 140
141 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { 141 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) {
142 DCHECK(IsRegistered(view)); 142 DCHECK(IsRegistered(view));
143 FOR_EACH_OBSERVER(Observer, observer_list_, 143 for (auto& observer : observer_list_)
144 OnImeCancelComposition(this, view)); 144 observer.OnImeCancelComposition(this, view);
145 } 145 }
146 146
147 void TextInputManager::SelectionBoundsChanged( 147 void TextInputManager::SelectionBoundsChanged(
148 RenderWidgetHostViewBase* view, 148 RenderWidgetHostViewBase* view,
149 const ViewHostMsg_SelectionBounds_Params& params) { 149 const ViewHostMsg_SelectionBounds_Params& params) {
150 DCHECK(IsRegistered(view)); 150 DCHECK(IsRegistered(view));
151 // Converting the anchor point to root's coordinate space (for child frame 151 // Converting the anchor point to root's coordinate space (for child frame
152 // views). 152 // views).
153 gfx::Point anchor_origin_transformed = 153 gfx::Point anchor_origin_transformed =
154 view->TransformPointToRootCoordSpace(params.anchor_rect.origin()); 154 view->TransformPointToRootCoordSpace(params.anchor_rect.origin());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (params.anchor_rect == params.focus_rect) { 196 if (params.anchor_rect == params.focus_rect) {
197 selection_region_map_[view].caret_rect.set_origin( 197 selection_region_map_[view].caret_rect.set_origin(
198 anchor_origin_transformed); 198 anchor_origin_transformed);
199 selection_region_map_[view].caret_rect.set_size(params.anchor_rect.size()); 199 selection_region_map_[view].caret_rect.set_size(params.anchor_rect.size());
200 } 200 }
201 selection_region_map_[view].first_selection_rect.set_origin( 201 selection_region_map_[view].first_selection_rect.set_origin(
202 anchor_origin_transformed); 202 anchor_origin_transformed);
203 selection_region_map_[view].first_selection_rect.set_size( 203 selection_region_map_[view].first_selection_rect.set_size(
204 params.anchor_rect.size()); 204 params.anchor_rect.size());
205 205
206 FOR_EACH_OBSERVER(Observer, observer_list_, 206 for (auto& observer : observer_list_)
207 OnSelectionBoundsChanged(this, view)); 207 observer.OnSelectionBoundsChanged(this, view);
208 } 208 }
209 209
210 // 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
211 // 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
212 // #ifdefs for platform specific code (https://crbug.com/602427). 212 // #ifdefs for platform specific code (https://crbug.com/602427).
213 void TextInputManager::ImeCompositionRangeChanged( 213 void TextInputManager::ImeCompositionRangeChanged(
214 RenderWidgetHostViewBase* view, 214 RenderWidgetHostViewBase* view,
215 const gfx::Range& range, 215 const gfx::Range& range,
216 const std::vector<gfx::Rect>& character_bounds) { 216 const std::vector<gfx::Rect>& character_bounds) {
217 DCHECK(IsRegistered(view)); 217 DCHECK(IsRegistered(view));
218 composition_range_info_map_[view].character_bounds.clear(); 218 composition_range_info_map_[view].character_bounds.clear();
219 219
220 // The values for the bounds should be converted to root view's coordinates 220 // The values for the bounds should be converted to root view's coordinates
221 // before being stored. 221 // before being stored.
222 for (auto rect : character_bounds) { 222 for (auto rect : character_bounds) {
223 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect( 223 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect(
224 view->TransformPointToRootCoordSpace(rect.origin()), rect.size())); 224 view->TransformPointToRootCoordSpace(rect.origin()), rect.size()));
225 } 225 }
226 226
227 composition_range_info_map_[view].range.set_start(range.start()); 227 composition_range_info_map_[view].range.set_start(range.start());
228 composition_range_info_map_[view].range.set_end(range.end()); 228 composition_range_info_map_[view].range.set_end(range.end());
229 229
230 FOR_EACH_OBSERVER(Observer, observer_list_, 230 for (auto& observer : observer_list_)
231 OnImeCompositionRangeChanged(this, view)); 231 observer.OnImeCompositionRangeChanged(this, view);
232 } 232 }
233 233
234 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view, 234 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view,
235 const base::string16& text, 235 const base::string16& text,
236 size_t offset, 236 size_t offset,
237 const gfx::Range& range) { 237 const gfx::Range& range) {
238 DCHECK(IsRegistered(view)); 238 DCHECK(IsRegistered(view));
239 239
240 text_selection_map_[view].text = text; 240 text_selection_map_[view].text = text;
241 text_selection_map_[view].offset = offset; 241 text_selection_map_[view].offset = offset;
242 text_selection_map_[view].range.set_start(range.start()); 242 text_selection_map_[view].range.set_start(range.start());
243 text_selection_map_[view].range.set_end(range.end()); 243 text_selection_map_[view].range.set_end(range.end());
244 244
245 FOR_EACH_OBSERVER(Observer, observer_list_, 245 for (auto& observer : observer_list_)
246 OnTextSelectionChanged(this, view)); 246 observer.OnTextSelectionChanged(this, view);
247 } 247 }
248 248
249 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 249 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
250 DCHECK(!IsRegistered(view)); 250 DCHECK(!IsRegistered(view));
251 251
252 text_input_state_map_[view] = TextInputState(); 252 text_input_state_map_[view] = TextInputState();
253 selection_region_map_[view] = SelectionRegion(); 253 selection_region_map_[view] = SelectionRegion();
254 composition_range_info_map_[view] = CompositionRangeInfo(); 254 composition_range_info_map_[view] = CompositionRangeInfo();
255 text_selection_map_[view] = TextSelection(); 255 text_selection_map_[view] = TextSelection();
256 } 256 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 292
293 ui::TextInputType TextInputManager::GetTextInputTypeForViewForTesting( 293 ui::TextInputType TextInputManager::GetTextInputTypeForViewForTesting(
294 RenderWidgetHostViewBase* view) { 294 RenderWidgetHostViewBase* view) {
295 DCHECK(IsRegistered(view)); 295 DCHECK(IsRegistered(view));
296 return text_input_state_map_[view].type; 296 return text_input_state_map_[view].type;
297 } 297 }
298 298
299 void TextInputManager::NotifyObserversAboutInputStateUpdate( 299 void TextInputManager::NotifyObserversAboutInputStateUpdate(
300 RenderWidgetHostViewBase* updated_view, 300 RenderWidgetHostViewBase* updated_view,
301 bool did_update_state) { 301 bool did_update_state) {
302 FOR_EACH_OBSERVER( 302 for (auto& observer : observer_list_)
303 Observer, observer_list_, 303 observer.OnUpdateTextInputStateCalled(this, updated_view, did_update_state);
304 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
305 } 304 }
306 305
307 TextInputManager::SelectionRegion::SelectionRegion() {} 306 TextInputManager::SelectionRegion::SelectionRegion() {}
308 307
309 TextInputManager::SelectionRegion::SelectionRegion( 308 TextInputManager::SelectionRegion::SelectionRegion(
310 const SelectionRegion& other) = default; 309 const SelectionRegion& other) = default;
311 310
312 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} 311 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {}
313 312
314 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( 313 TextInputManager::CompositionRangeInfo::CompositionRangeInfo(
(...skipping 27 matching lines...) Expand all
342 "point exceeds text length)."; 341 "point exceeds text length).";
343 return false; 342 return false;
344 } 343 }
345 344
346 selected_text->clear(); 345 selected_text->clear();
347 selected_text->append(text.substr(pos, n)); 346 selected_text->append(text.substr(pos, n));
348 return true; 347 return true;
349 } 348 }
350 349
351 } // namespace content 350 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_base.cc ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698