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

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: Using the Destruction Observer for RWHVAura Created 4 years, 7 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 bool is_guest_view_hack) 363 bool is_guest_view_hack)
364 : host_(RenderWidgetHostImpl::From(host)), 364 : host_(RenderWidgetHostImpl::From(host)),
365 window_(nullptr), 365 window_(nullptr),
366 delegated_frame_host_(new DelegatedFrameHost(this)), 366 delegated_frame_host_(new DelegatedFrameHost(this)),
367 in_shutdown_(false), 367 in_shutdown_(false),
368 in_bounds_changed_(false), 368 in_bounds_changed_(false),
369 is_fullscreen_(false), 369 is_fullscreen_(false),
370 popup_parent_host_view_(nullptr), 370 popup_parent_host_view_(nullptr),
371 popup_child_host_view_(nullptr), 371 popup_child_host_view_(nullptr),
372 is_loading_(false), 372 is_loading_(false),
373 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
374 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
375 text_input_flags_(0),
376 can_compose_inline_(true),
377 has_composition_text_(false), 373 has_composition_text_(false),
378 accept_return_character_(false), 374 accept_return_character_(false),
379 begin_frame_source_(nullptr), 375 begin_frame_source_(nullptr),
380 needs_begin_frames_(false), 376 needs_begin_frames_(false),
381 synthetic_move_sent_(false), 377 synthetic_move_sent_(false),
382 cursor_visibility_state_in_renderer_(UNKNOWN), 378 cursor_visibility_state_in_renderer_(UNKNOWN),
383 #if defined(OS_WIN) 379 #if defined(OS_WIN)
384 legacy_render_widget_host_HWND_(nullptr), 380 legacy_render_widget_host_HWND_(nullptr),
385 legacy_window_destroyed_(false), 381 legacy_window_destroyed_(false),
386 #endif 382 #endif
387 has_snapped_to_boundary_(false), 383 has_snapped_to_boundary_(false),
388 is_guest_view_hack_(is_guest_view_hack), 384 is_guest_view_hack_(is_guest_view_hack),
389 set_focus_on_mouse_down_or_key_event_(false), 385 set_focus_on_mouse_down_or_key_event_(false),
390 device_scale_factor_(0.0f), 386 device_scale_factor_(0.0f),
391 disable_input_event_router_for_testing_(false), 387 disable_input_event_router_for_testing_(false),
392 weak_ptr_factory_(this) { 388 weak_ptr_factory_(this) {
393 if (!is_guest_view_hack_) 389 if (!is_guest_view_hack_)
394 host_->SetView(this); 390 host_->SetView(this);
395 391
396 // Let the page-level input event router know about our surface ID 392 // Let the page-level input event router know about our surface ID
397 // namespace for surface-based hit testing. 393 // namespace for surface-based hit testing.
398 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { 394 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) {
399 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner( 395 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner(
400 GetSurfaceIdNamespace(), this); 396 GetSurfaceIdNamespace(), this);
401 } 397 }
402 398
399 // We should start observing the TextInputManager for IME-related events as
400 // well as monitoring its lifetime.
401 text_input_manager_ = GetTextInputManager();
402 if (text_input_manager_)
403 text_input_manager_->AddObserver(this);
404
403 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> 405 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()->
404 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 406 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
405 SetOverscrollControllerEnabled(overscroll_enabled); 407 SetOverscrollControllerEnabled(overscroll_enabled);
406 408
407 selection_controller_client_.reset( 409 selection_controller_client_.reset(
408 new TouchSelectionControllerClientAura(this)); 410 new TouchSelectionControllerClientAura(this));
409 CreateSelectionController(); 411 CreateSelectionController();
410 } 412 }
411 413
412 //////////////////////////////////////////////////////////////////////////////// 414 ////////////////////////////////////////////////////////////////////////////////
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); 872 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
871 current_cursor_.SetDisplayInfo(display); 873 current_cursor_.SetDisplayInfo(display);
872 UpdateCursorIfOverSelf(); 874 UpdateCursorIfOverSelf();
873 } 875 }
874 876
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 877 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
876 is_loading_ = is_loading; 878 is_loading_ = is_loading;
877 UpdateCursorIfOverSelf(); 879 UpdateCursorIfOverSelf();
878 } 880 }
879 881
880 void RenderWidgetHostViewAura::TextInputStateChanged(
881 const TextInputState& params) {
882 if (text_input_type_ != params.type ||
883 text_input_mode_ != params.mode ||
884 can_compose_inline_ != params.can_compose_inline ||
885 text_input_flags_ != params.flags) {
886 text_input_type_ = params.type;
887 text_input_mode_ = params.mode;
888 can_compose_inline_ = params.can_compose_inline;
889 text_input_flags_ = params.flags;
890 if (GetInputMethod())
891 GetInputMethod()->OnTextInputTypeChanged(this);
892 }
893 if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) {
894 if (GetInputMethod())
895 GetInputMethod()->ShowImeIfNeeded();
896 }
897 }
898
899 void RenderWidgetHostViewAura::ImeCancelComposition() { 882 void RenderWidgetHostViewAura::ImeCancelComposition() {
900 if (GetInputMethod()) 883 if (GetInputMethod())
901 GetInputMethod()->CancelComposition(this); 884 GetInputMethod()->CancelComposition(this);
902 has_composition_text_ = false; 885 has_composition_text_ = false;
903 } 886 }
904 887
905 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( 888 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
906 const gfx::Range& range, 889 const gfx::Range& range,
907 const std::vector<gfx::Rect>& character_bounds) { 890 const std::vector<gfx::Rect>& character_bounds) {
908 composition_character_bounds_ = character_bounds; 891 composition_character_bounds_ = character_bounds;
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 } 1473 }
1491 1474
1492 void RenderWidgetHostViewAura::ClearCompositionText() { 1475 void RenderWidgetHostViewAura::ClearCompositionText() {
1493 // TODO(wjmaclean): can host_ ever be null? 1476 // TODO(wjmaclean): can host_ ever be null?
1494 if (host_ && has_composition_text_) 1477 if (host_ && has_composition_text_)
1495 host_->ImeCancelComposition(); 1478 host_->ImeCancelComposition();
1496 has_composition_text_ = false; 1479 has_composition_text_ = false;
1497 } 1480 }
1498 1481
1499 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { 1482 void RenderWidgetHostViewAura::InsertText(const base::string16& text) {
1500 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); 1483 DCHECK(GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE);
1484
1501 // TODO(wjmaclean): can host_ ever be null? 1485 // TODO(wjmaclean): can host_ ever be null?
1502 if (host_) 1486 if (host_)
1503 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); 1487 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false);
1504 has_composition_text_ = false; 1488 has_composition_text_ = false;
1505 } 1489 }
1506 1490
1507 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { 1491 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) {
1508 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { 1492 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1509 popup_child_host_view_->InsertChar(event); 1493 popup_child_host_view_->InsertChar(event);
1510 return; 1494 return;
1511 } 1495 }
1512 1496
1513 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 1497 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1514 // TODO(wjmaclean): can host_ ever be null? 1498 // TODO(wjmaclean): can host_ ever be null?
1515 if (host_ && 1499 if (host_ &&
1516 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { 1500 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) {
1517 // Send a blink::WebInputEvent::Char event to |host_|. 1501 // Send a blink::WebInputEvent::Char event to |host_|.
1518 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); 1502 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter()));
1519 } 1503 }
1520 } 1504 }
1521 1505
1522 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { 1506 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1523 return text_input_type_; 1507 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1508 return text_input_manager_->GetTextInputState()->type;
1509 return ui::TEXT_INPUT_TYPE_NONE;
1524 } 1510 }
1525 1511
1526 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { 1512 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const {
1527 return text_input_mode_; 1513 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1514 return text_input_manager_->GetTextInputState()->mode;
1515 return ui::TEXT_INPUT_MODE_DEFAULT;
1528 } 1516 }
1529 1517
1530 int RenderWidgetHostViewAura::GetTextInputFlags() const { 1518 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1531 return text_input_flags_; 1519 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1520 return text_input_manager_->GetTextInputState()->flags;
1521 return 0;
1532 } 1522 }
1533 1523
1534 bool RenderWidgetHostViewAura::CanComposeInline() const { 1524 bool RenderWidgetHostViewAura::CanComposeInline() const {
1535 return can_compose_inline_; 1525 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1526 return text_input_manager_->GetTextInputState()->can_compose_inline;
1527 return true;
1536 } 1528 }
1537 1529
1538 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( 1530 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen(
1539 const gfx::Rect& rect) const { 1531 const gfx::Rect& rect) const {
1540 gfx::Point origin = rect.origin(); 1532 gfx::Point origin = rect.origin();
1541 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); 1533 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1542 1534
1543 aura::Window* root_window = window_->GetRootWindow(); 1535 aura::Window* root_window = window_->GetRootWindow();
1544 if (!root_window) 1536 if (!root_window)
1545 return rect; 1537 return rect;
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 popup_child_host_view_->popup_parent_host_view_ = NULL; 2375 popup_child_host_view_->popup_parent_host_view_ = NULL;
2384 } 2376 }
2385 event_filter_for_popup_exit_.reset(); 2377 event_filter_for_popup_exit_.reset();
2386 2378
2387 #if defined(OS_WIN) 2379 #if defined(OS_WIN)
2388 // The LegacyRenderWidgetHostHWND window should have been destroyed in 2380 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2389 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should 2381 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2390 // be set to NULL. 2382 // be set to NULL.
2391 DCHECK(!legacy_render_widget_host_HWND_); 2383 DCHECK(!legacy_render_widget_host_HWND_);
2392 #endif 2384 #endif
2385
2386 if (text_input_manager_)
2387 text_input_manager_->RemoveObserver(this);
2393 } 2388 }
2394 2389
2395 void RenderWidgetHostViewAura::CreateAuraWindow() { 2390 void RenderWidgetHostViewAura::CreateAuraWindow() {
2396 DCHECK(!window_); 2391 DCHECK(!window_);
2397 window_ = new aura::Window(this); 2392 window_ = new aura::Window(this);
2398 window_observer_.reset(new WindowObserver(this)); 2393 window_observer_.reset(new WindowObserver(this));
2399 2394
2400 aura::client::SetTooltipText(window_, &tooltip_); 2395 aura::client::SetTooltipText(window_, &tooltip_);
2401 aura::client::SetActivationDelegate(window_, this); 2396 aura::client::SetActivationDelegate(window_, this);
2402 aura::client::SetFocusChangeObserver(window_, this); 2397 aura::client::SetFocusChangeObserver(window_, this);
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
2946 } 2941 }
2947 2942
2948 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { 2943 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() {
2949 return delegated_frame_host_->GetSurfaceIdNamespace(); 2944 return delegated_frame_host_->GetSurfaceIdNamespace();
2950 } 2945 }
2951 2946
2952 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { 2947 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const {
2953 return delegated_frame_host_->SurfaceIdForTesting(); 2948 return delegated_frame_host_->SurfaceIdForTesting();
2954 } 2949 }
2955 2950
2951 void RenderWidgetHostViewAura::OnTextInputStateUpdated(
2952 TextInputManager* text_input_manager,
2953 RenderWidgetHostViewBase* updated_view,
2954 bool changed) {
2955 DCHECK(text_input_manager_ == text_input_manager);
2956 if (!GetInputMethod())
2957 return;
2958
2959 if (changed)
2960 GetInputMethod()->OnTextInputTypeChanged(this);
2961
2962 const TextInputState* state = text_input_manager_->GetTextInputState();
2963
2964 if (state && state->show_ime_if_needed &&
2965 state->type != ui::TEXT_INPUT_TYPE_NONE)
2966 GetInputMethod()->ShowImeIfNeeded();
2967 }
2968
2969 void RenderWidgetHostViewAura::OnTextInputManagerDestroyed(
2970 TextInputManager* text_input_manager) {
2971 DCHECK(text_input_manager && text_input_manager_ == text_input_manager);
2972
2973 if (text_input_manager_->IsRegisteredView(this))
2974 text_input_manager_->Unregister(this);
2975
2976 text_input_manager_->RemoveObserver(this);
2977
2978 text_input_manager_ = nullptr;
2979 }
2956 //////////////////////////////////////////////////////////////////////////////// 2980 ////////////////////////////////////////////////////////////////////////////////
2957 // RenderWidgetHostViewBase, public: 2981 // RenderWidgetHostViewBase, public:
2958 2982
2959 // static 2983 // static
2960 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2984 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2961 GetScreenInfoForWindow(results, NULL); 2985 GetScreenInfoForWindow(results, NULL);
2962 } 2986 }
2963 2987
2964 } // namespace content 2988 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698