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

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

Issue 1948343002: [reland] Browser Side Text Input State Tracking for OOPIF (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase (Code changed during CQ Dry-run) Created 4 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 bool is_guest_view_hack) 446 bool is_guest_view_hack)
447 : host_(RenderWidgetHostImpl::From(host)), 447 : host_(RenderWidgetHostImpl::From(host)),
448 window_(nullptr), 448 window_(nullptr),
449 delegated_frame_host_(new DelegatedFrameHost(this)), 449 delegated_frame_host_(new DelegatedFrameHost(this)),
450 in_shutdown_(false), 450 in_shutdown_(false),
451 in_bounds_changed_(false), 451 in_bounds_changed_(false),
452 is_fullscreen_(false), 452 is_fullscreen_(false),
453 popup_parent_host_view_(nullptr), 453 popup_parent_host_view_(nullptr),
454 popup_child_host_view_(nullptr), 454 popup_child_host_view_(nullptr),
455 is_loading_(false), 455 is_loading_(false),
456 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
457 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
458 text_input_flags_(0),
459 can_compose_inline_(true),
460 has_composition_text_(false), 456 has_composition_text_(false),
461 accept_return_character_(false), 457 accept_return_character_(false),
462 begin_frame_source_(nullptr), 458 begin_frame_source_(nullptr),
463 needs_begin_frames_(false), 459 needs_begin_frames_(false),
464 synthetic_move_sent_(false), 460 synthetic_move_sent_(false),
465 cursor_visibility_state_in_renderer_(UNKNOWN), 461 cursor_visibility_state_in_renderer_(UNKNOWN),
466 #if defined(OS_WIN) 462 #if defined(OS_WIN)
467 legacy_render_widget_host_HWND_(nullptr), 463 legacy_render_widget_host_HWND_(nullptr),
468 legacy_window_destroyed_(false), 464 legacy_window_destroyed_(false),
469 virtual_keyboard_requested_(false), 465 virtual_keyboard_requested_(false),
470 #endif 466 #endif
471 has_snapped_to_boundary_(false), 467 has_snapped_to_boundary_(false),
472 is_guest_view_hack_(is_guest_view_hack), 468 is_guest_view_hack_(is_guest_view_hack),
473 set_focus_on_mouse_down_or_key_event_(false), 469 set_focus_on_mouse_down_or_key_event_(false),
474 device_scale_factor_(0.0f), 470 device_scale_factor_(0.0f),
475 disable_input_event_router_for_testing_(false), 471 disable_input_event_router_for_testing_(false),
476 weak_ptr_factory_(this) { 472 weak_ptr_factory_(this) {
477 if (!is_guest_view_hack_) 473 if (!is_guest_view_hack_)
478 host_->SetView(this); 474 host_->SetView(this);
479 475
480 // Let the page-level input event router know about our surface ID 476 // Let the page-level input event router know about our surface ID
481 // namespace for surface-based hit testing. 477 // namespace for surface-based hit testing.
482 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { 478 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) {
483 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner( 479 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner(
484 GetSurfaceIdNamespace(), this); 480 GetSurfaceIdNamespace(), this);
485 } 481 }
486 482
483 // We should start observing the TextInputManager for IME-related events as
484 // well as monitoring its lifetime.
485 if (GetTextInputManager())
486 GetTextInputManager()->AddObserver(this);
487
487 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> 488 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()->
488 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 489 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
489 SetOverscrollControllerEnabled(overscroll_enabled); 490 SetOverscrollControllerEnabled(overscroll_enabled);
490 491
491 selection_controller_client_.reset( 492 selection_controller_client_.reset(
492 new TouchSelectionControllerClientAura(this)); 493 new TouchSelectionControllerClientAura(this));
493 CreateSelectionController(); 494 CreateSelectionController();
494 } 495 }
495 496
496 //////////////////////////////////////////////////////////////////////////////// 497 ////////////////////////////////////////////////////////////////////////////////
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); 968 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
968 current_cursor_.SetDisplayInfo(display); 969 current_cursor_.SetDisplayInfo(display);
969 UpdateCursorIfOverSelf(); 970 UpdateCursorIfOverSelf();
970 } 971 }
971 972
972 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 973 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
973 is_loading_ = is_loading; 974 is_loading_ = is_loading;
974 UpdateCursorIfOverSelf(); 975 UpdateCursorIfOverSelf();
975 } 976 }
976 977
977 void RenderWidgetHostViewAura::TextInputStateChanged(
978 const TextInputState& params) {
979 if (text_input_type_ != params.type ||
980 text_input_mode_ != params.mode ||
981 can_compose_inline_ != params.can_compose_inline ||
982 text_input_flags_ != params.flags) {
983 text_input_type_ = params.type;
984 text_input_mode_ = params.mode;
985 can_compose_inline_ = params.can_compose_inline;
986 text_input_flags_ = params.flags;
987 if (GetInputMethod())
988 GetInputMethod()->OnTextInputTypeChanged(this);
989 }
990 if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) {
991 if (GetInputMethod())
992 GetInputMethod()->ShowImeIfNeeded();
993 }
994 }
995
996 void RenderWidgetHostViewAura::ImeCancelComposition() { 978 void RenderWidgetHostViewAura::ImeCancelComposition() {
997 if (GetInputMethod()) 979 if (GetInputMethod())
998 GetInputMethod()->CancelComposition(this); 980 GetInputMethod()->CancelComposition(this);
999 has_composition_text_ = false; 981 has_composition_text_ = false;
1000 } 982 }
1001 983
1002 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( 984 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
1003 const gfx::Range& range, 985 const gfx::Range& range,
1004 const std::vector<gfx::Rect>& character_bounds) { 986 const std::vector<gfx::Rect>& character_bounds) {
1005 composition_character_bounds_ = character_bounds; 987 composition_character_bounds_ = character_bounds;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 } 1477 }
1496 1478
1497 void RenderWidgetHostViewAura::ClearCompositionText() { 1479 void RenderWidgetHostViewAura::ClearCompositionText() {
1498 // TODO(wjmaclean): can host_ ever be null? 1480 // TODO(wjmaclean): can host_ ever be null?
1499 if (host_ && has_composition_text_) 1481 if (host_ && has_composition_text_)
1500 host_->ImeCancelComposition(); 1482 host_->ImeCancelComposition();
1501 has_composition_text_ = false; 1483 has_composition_text_ = false;
1502 } 1484 }
1503 1485
1504 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { 1486 void RenderWidgetHostViewAura::InsertText(const base::string16& text) {
1505 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); 1487 DCHECK_NE(GetTextInputType(), ui::TEXT_INPUT_TYPE_NONE);
1488
1506 // TODO(wjmaclean): can host_ ever be null? 1489 // TODO(wjmaclean): can host_ ever be null?
1507 if (host_) 1490 if (host_)
1508 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); 1491 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false);
1509 has_composition_text_ = false; 1492 has_composition_text_ = false;
1510 } 1493 }
1511 1494
1512 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { 1495 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) {
1513 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { 1496 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1514 popup_child_host_view_->InsertChar(event); 1497 popup_child_host_view_->InsertChar(event);
1515 return; 1498 return;
1516 } 1499 }
1517 1500
1518 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 1501 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1519 // TODO(wjmaclean): can host_ ever be null? 1502 // TODO(wjmaclean): can host_ ever be null?
1520 if (host_ && 1503 if (host_ &&
1521 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { 1504 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) {
1522 // Send a blink::WebInputEvent::Char event to |host_|. 1505 // Send a blink::WebInputEvent::Char event to |host_|.
1523 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); 1506 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter()));
1524 } 1507 }
1525 } 1508 }
1526 1509
1527 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { 1510 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1528 return text_input_type_; 1511 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1512 return text_input_manager_->GetTextInputState()->type;
1513 return ui::TEXT_INPUT_TYPE_NONE;
1529 } 1514 }
1530 1515
1531 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { 1516 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const {
1532 return text_input_mode_; 1517 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1518 return text_input_manager_->GetTextInputState()->mode;
1519 return ui::TEXT_INPUT_MODE_DEFAULT;
1533 } 1520 }
1534 1521
1535 int RenderWidgetHostViewAura::GetTextInputFlags() const { 1522 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1536 return text_input_flags_; 1523 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1524 return text_input_manager_->GetTextInputState()->flags;
1525 return 0;
1537 } 1526 }
1538 1527
1539 bool RenderWidgetHostViewAura::CanComposeInline() const { 1528 bool RenderWidgetHostViewAura::CanComposeInline() const {
1540 return can_compose_inline_; 1529 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1530 return text_input_manager_->GetTextInputState()->can_compose_inline;
1531 return true;
1541 } 1532 }
1542 1533
1543 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( 1534 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen(
1544 const gfx::Rect& rect) const { 1535 const gfx::Rect& rect) const {
1545 gfx::Point origin = rect.origin(); 1536 gfx::Point origin = rect.origin();
1546 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); 1537 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1547 1538
1548 aura::Window* root_window = window_->GetRootWindow(); 1539 aura::Window* root_window = window_->GetRootWindow();
1549 if (!root_window) 1540 if (!root_window)
1550 return rect; 1541 return rect;
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 DCHECK(!legacy_render_widget_host_HWND_); 2401 DCHECK(!legacy_render_widget_host_HWND_);
2411 if (virtual_keyboard_requested_) { 2402 if (virtual_keyboard_requested_) {
2412 DCHECK(keyboard_observer_.get()); 2403 DCHECK(keyboard_observer_.get());
2413 ui::OnScreenKeyboardDisplayManager* osk_display_manager = 2404 ui::OnScreenKeyboardDisplayManager* osk_display_manager =
2414 ui::OnScreenKeyboardDisplayManager::GetInstance(); 2405 ui::OnScreenKeyboardDisplayManager::GetInstance();
2415 DCHECK(osk_display_manager); 2406 DCHECK(osk_display_manager);
2416 osk_display_manager->RemoveObserver(keyboard_observer_.get()); 2407 osk_display_manager->RemoveObserver(keyboard_observer_.get());
2417 } 2408 }
2418 2409
2419 #endif 2410 #endif
2411
2412 if (text_input_manager_)
2413 text_input_manager_->RemoveObserver(this);
2420 } 2414 }
2421 2415
2422 void RenderWidgetHostViewAura::CreateAuraWindow() { 2416 void RenderWidgetHostViewAura::CreateAuraWindow() {
2423 DCHECK(!window_); 2417 DCHECK(!window_);
2424 window_ = new aura::Window(this); 2418 window_ = new aura::Window(this);
2425 window_observer_.reset(new WindowObserver(this)); 2419 window_observer_.reset(new WindowObserver(this));
2426 2420
2427 aura::client::SetTooltipText(window_, &tooltip_); 2421 aura::client::SetTooltipText(window_, &tooltip_);
2428 aura::client::SetActivationDelegate(window_, this); 2422 aura::client::SetActivationDelegate(window_, this);
2429 aura::client::SetFocusChangeObserver(window_, this); 2423 aura::client::SetFocusChangeObserver(window_, this);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
2991 } 2985 }
2992 2986
2993 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { 2987 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() {
2994 return delegated_frame_host_->GetSurfaceIdNamespace(); 2988 return delegated_frame_host_->GetSurfaceIdNamespace();
2995 } 2989 }
2996 2990
2997 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { 2991 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const {
2998 return delegated_frame_host_->SurfaceIdForTesting(); 2992 return delegated_frame_host_->SurfaceIdForTesting();
2999 } 2993 }
3000 2994
2995 void RenderWidgetHostViewAura::OnUpdateTextInputStateCalled(
2996 TextInputManager* text_input_manager,
2997 RenderWidgetHostViewBase* updated_view,
2998 bool did_update_state) {
2999 DCHECK_EQ(text_input_manager_, text_input_manager);
3000
3001 if (!GetInputMethod())
3002 return;
3003
3004 if (did_update_state)
3005 GetInputMethod()->OnTextInputTypeChanged(this);
3006
3007 const TextInputState* state = text_input_manager_->GetTextInputState();
3008
3009 if (state && state->show_ime_if_needed &&
3010 state->type != ui::TEXT_INPUT_TYPE_NONE)
3011 GetInputMethod()->ShowImeIfNeeded();
3012 }
3013
3001 //////////////////////////////////////////////////////////////////////////////// 3014 ////////////////////////////////////////////////////////////////////////////////
3002 // RenderWidgetHostViewBase, public: 3015 // RenderWidgetHostViewBase, public:
3003 3016
3004 // static 3017 // static
3005 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 3018 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
3006 GetScreenInfoForWindow(results, NULL); 3019 GetScreenInfoForWindow(results, NULL);
3007 } 3020 }
3008 3021
3009 } // namespace content 3022 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698