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/public/test/text_input_test_utils.h" | 5 #include "content/public/test/text_input_test_utils.h" |
6 | 6 |
7 #include <unordered_set> | 7 #include <unordered_set> |
8 | 8 |
9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 bool TextInputManagerTester::GetTextInputValue(std::string* value) { | 356 bool TextInputManagerTester::GetTextInputValue(std::string* value) { |
357 DCHECK(observer_->text_input_manager()); | 357 DCHECK(observer_->text_input_manager()); |
358 const TextInputState* state = | 358 const TextInputState* state = |
359 observer_->text_input_manager()->GetTextInputState(); | 359 observer_->text_input_manager()->GetTextInputState(); |
360 if (!state) | 360 if (!state) |
361 return false; | 361 return false; |
362 *value = state->value; | 362 *value = state->value; |
363 return true; | 363 return true; |
364 } | 364 } |
365 | 365 |
| 366 bool TextInputManagerTester::GetTextInputCursorPosition(int* position) { |
| 367 DCHECK(observer_->text_input_manager()); |
| 368 const TextInputState* state = |
| 369 observer_->text_input_manager()->GetTextInputState(); |
| 370 if (!state) |
| 371 return false; |
| 372 *position = state->selection_start; |
| 373 return true; |
| 374 } |
| 375 |
366 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { | 376 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { |
367 DCHECK(observer_->text_input_manager()); | 377 DCHECK(observer_->text_input_manager()); |
368 return observer_->text_input_manager()->active_view_for_testing(); | 378 return observer_->text_input_manager()->active_view_for_testing(); |
369 } | 379 } |
370 | 380 |
371 RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { | 381 RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { |
372 return observer_->GetUpdatedView(); | 382 return observer_->GetUpdatedView(); |
373 } | 383 } |
374 | 384 |
375 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) { | 385 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) { |
376 DCHECK(observer_->text_input_manager()); | 386 DCHECK(observer_->text_input_manager()); |
377 | 387 |
378 if (!observer_->text_input_manager()->GetActiveWidget()) | 388 if (!observer_->text_input_manager()->GetActiveWidget()) |
379 return false; | 389 return false; |
380 | 390 |
381 *length = observer_->text_input_manager()->GetTextSelection()->text().size(); | 391 *length = observer_->text_input_manager()->GetTextSelection()->text().size(); |
382 return true; | 392 return true; |
383 } | 393 } |
384 | 394 |
385 bool TextInputManagerTester::GetLastCompositionRangeLength(uint32_t* length) { | 395 bool TextInputManagerTester::GetLastCompositionRangeLength(uint32_t* length) { |
386 if (!observer_->last_composition_range()) | 396 if (!observer_->last_composition_range()) |
387 return false; | 397 return false; |
388 *length = observer_->last_composition_range()->length(); | 398 *length = observer_->last_composition_range()->length(); |
389 return true; | 399 return true; |
390 } | 400 } |
391 | 401 |
| 402 bool TextInputManagerTester::GetTextSelectionUserInitiatedForView( |
| 403 RenderWidgetHostView* view, |
| 404 bool* user_initiated) { |
| 405 TextInputManager* manager = observer_->text_input_manager(); |
| 406 DCHECK(manager); |
| 407 |
| 408 RenderWidgetHostViewBase* view_base = |
| 409 static_cast<RenderWidgetHostViewBase*>(view); |
| 410 if (!manager->IsRegistered(view_base)) |
| 411 return false; |
| 412 |
| 413 *user_initiated = manager->GetTextSelection(view_base)->user_initiated(); |
| 414 return true; |
| 415 } |
| 416 |
392 bool TextInputManagerTester::IsTextInputStateChanged() { | 417 bool TextInputManagerTester::IsTextInputStateChanged() { |
393 return observer_->text_input_state_changed(); | 418 return observer_->text_input_state_changed(); |
394 } | 419 } |
395 | 420 |
396 TestRenderWidgetHostViewDestructionObserver:: | 421 TestRenderWidgetHostViewDestructionObserver:: |
397 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view) | 422 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view) |
398 : observer_( | 423 : observer_( |
399 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {} | 424 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {} |
400 | 425 |
401 TestRenderWidgetHostViewDestructionObserver:: | 426 TestRenderWidgetHostViewDestructionObserver:: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 482 |
458 #ifdef USE_AURA | 483 #ifdef USE_AURA |
459 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( | 484 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( |
460 web_contents->GetRenderWidgetHostView()); | 485 web_contents->GetRenderWidgetHostView()); |
461 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); | 486 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); |
462 #endif | 487 #endif |
463 return observer; | 488 return observer; |
464 } | 489 } |
465 | 490 |
466 } // namespace content | 491 } // namespace content |
OLD | NEW |