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

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: Changed Public Test API Methods to non-const 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 if (GetTextInputManager())
402 GetTextInputManager()->AddObserver(this);
403
403 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> 404 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()->
404 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 405 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
405 SetOverscrollControllerEnabled(overscroll_enabled); 406 SetOverscrollControllerEnabled(overscroll_enabled);
406 407
407 selection_controller_client_.reset( 408 selection_controller_client_.reset(
408 new TouchSelectionControllerClientAura(this)); 409 new TouchSelectionControllerClientAura(this));
409 CreateSelectionController(); 410 CreateSelectionController();
410 } 411 }
411 412
412 //////////////////////////////////////////////////////////////////////////////// 413 ////////////////////////////////////////////////////////////////////////////////
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); 871 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
871 current_cursor_.SetDisplayInfo(display); 872 current_cursor_.SetDisplayInfo(display);
872 UpdateCursorIfOverSelf(); 873 UpdateCursorIfOverSelf();
873 } 874 }
874 875
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 876 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
876 is_loading_ = is_loading; 877 is_loading_ = is_loading;
877 UpdateCursorIfOverSelf(); 878 UpdateCursorIfOverSelf();
878 } 879 }
879 880
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() { 881 void RenderWidgetHostViewAura::ImeCancelComposition() {
900 if (GetInputMethod()) 882 if (GetInputMethod())
901 GetInputMethod()->CancelComposition(this); 883 GetInputMethod()->CancelComposition(this);
902 has_composition_text_ = false; 884 has_composition_text_ = false;
903 } 885 }
904 886
905 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( 887 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
906 const gfx::Range& range, 888 const gfx::Range& range,
907 const std::vector<gfx::Rect>& character_bounds) { 889 const std::vector<gfx::Rect>& character_bounds) {
908 composition_character_bounds_ = character_bounds; 890 composition_character_bounds_ = character_bounds;
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 } 1373 }
1392 1374
1393 void RenderWidgetHostViewAura::ClearCompositionText() { 1375 void RenderWidgetHostViewAura::ClearCompositionText() {
1394 // TODO(wjmaclean): can host_ ever be null? 1376 // TODO(wjmaclean): can host_ ever be null?
1395 if (host_ && has_composition_text_) 1377 if (host_ && has_composition_text_)
1396 host_->ImeCancelComposition(); 1378 host_->ImeCancelComposition();
1397 has_composition_text_ = false; 1379 has_composition_text_ = false;
1398 } 1380 }
1399 1381
1400 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { 1382 void RenderWidgetHostViewAura::InsertText(const base::string16& text) {
1401 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); 1383 DCHECK(GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE);
Charlie Reis 2016/05/26 06:22:04 nit: DCHECK_NE
EhsanK 2016/05/30 15:06:08 Done.
1384
1402 // TODO(wjmaclean): can host_ ever be null? 1385 // TODO(wjmaclean): can host_ ever be null?
1403 if (host_) 1386 if (host_)
1404 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); 1387 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false);
1405 has_composition_text_ = false; 1388 has_composition_text_ = false;
1406 } 1389 }
1407 1390
1408 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { 1391 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) {
1409 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { 1392 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1410 popup_child_host_view_->InsertChar(event); 1393 popup_child_host_view_->InsertChar(event);
1411 return; 1394 return;
1412 } 1395 }
1413 1396
1414 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 1397 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1415 // TODO(wjmaclean): can host_ ever be null? 1398 // TODO(wjmaclean): can host_ ever be null?
1416 if (host_ && 1399 if (host_ &&
1417 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { 1400 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) {
1418 // Send a blink::WebInputEvent::Char event to |host_|. 1401 // Send a blink::WebInputEvent::Char event to |host_|.
1419 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); 1402 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter()));
1420 } 1403 }
1421 } 1404 }
1422 1405
1423 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { 1406 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1424 return text_input_type_; 1407 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1408 return text_input_manager_->GetTextInputState()->type;
1409 return ui::TEXT_INPUT_TYPE_NONE;
1425 } 1410 }
1426 1411
1427 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { 1412 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const {
1428 return text_input_mode_; 1413 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1414 return text_input_manager_->GetTextInputState()->mode;
1415 return ui::TEXT_INPUT_MODE_DEFAULT;
1429 } 1416 }
1430 1417
1431 int RenderWidgetHostViewAura::GetTextInputFlags() const { 1418 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1432 return text_input_flags_; 1419 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1420 return text_input_manager_->GetTextInputState()->flags;
1421 return 0;
1433 } 1422 }
1434 1423
1435 bool RenderWidgetHostViewAura::CanComposeInline() const { 1424 bool RenderWidgetHostViewAura::CanComposeInline() const {
1436 return can_compose_inline_; 1425 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1426 return text_input_manager_->GetTextInputState()->can_compose_inline;
1427 return true;
1437 } 1428 }
1438 1429
1439 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( 1430 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen(
1440 const gfx::Rect& rect) const { 1431 const gfx::Rect& rect) const {
1441 gfx::Point origin = rect.origin(); 1432 gfx::Point origin = rect.origin();
1442 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); 1433 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1443 1434
1444 aura::Window* root_window = window_->GetRootWindow(); 1435 aura::Window* root_window = window_->GetRootWindow();
1445 if (!root_window) 1436 if (!root_window)
1446 return rect; 1437 return rect;
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 popup_child_host_view_->popup_parent_host_view_ = NULL; 2271 popup_child_host_view_->popup_parent_host_view_ = NULL;
2281 } 2272 }
2282 event_filter_for_popup_exit_.reset(); 2273 event_filter_for_popup_exit_.reset();
2283 2274
2284 #if defined(OS_WIN) 2275 #if defined(OS_WIN)
2285 // The LegacyRenderWidgetHostHWND window should have been destroyed in 2276 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2286 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should 2277 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2287 // be set to NULL. 2278 // be set to NULL.
2288 DCHECK(!legacy_render_widget_host_HWND_); 2279 DCHECK(!legacy_render_widget_host_HWND_);
2289 #endif 2280 #endif
2281
2282 if (text_input_manager_)
2283 text_input_manager_->RemoveObserver(this);
2290 } 2284 }
2291 2285
2292 void RenderWidgetHostViewAura::CreateAuraWindow() { 2286 void RenderWidgetHostViewAura::CreateAuraWindow() {
2293 DCHECK(!window_); 2287 DCHECK(!window_);
2294 window_ = new aura::Window(this); 2288 window_ = new aura::Window(this);
2295 window_observer_.reset(new WindowObserver(this)); 2289 window_observer_.reset(new WindowObserver(this));
2296 2290
2297 aura::client::SetTooltipText(window_, &tooltip_); 2291 aura::client::SetTooltipText(window_, &tooltip_);
2298 aura::client::SetActivationDelegate(window_, this); 2292 aura::client::SetActivationDelegate(window_, this);
2299 aura::client::SetFocusChangeObserver(window_, this); 2293 aura::client::SetFocusChangeObserver(window_, this);
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 } 2850 }
2857 2851
2858 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { 2852 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() {
2859 return delegated_frame_host_->GetSurfaceIdNamespace(); 2853 return delegated_frame_host_->GetSurfaceIdNamespace();
2860 } 2854 }
2861 2855
2862 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { 2856 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const {
2863 return delegated_frame_host_->SurfaceIdForTesting(); 2857 return delegated_frame_host_->SurfaceIdForTesting();
2864 } 2858 }
2865 2859
2860 void RenderWidgetHostViewAura::OnUpdateTextInputStateCalled(
2861 TextInputManager* text_input_manager,
2862 RenderWidgetHostViewBase* updated_view,
2863 bool did_update_state) {
2864 DCHECK_EQ(text_input_manager_, text_input_manager);
2865
2866 if (!GetInputMethod())
2867 return;
2868
2869 if (did_update_state)
2870 GetInputMethod()->OnTextInputTypeChanged(this);
2871
2872 const TextInputState* state = text_input_manager_->GetTextInputState();
2873
2874 if (state && state->show_ime_if_needed &&
2875 state->type != ui::TEXT_INPUT_TYPE_NONE)
2876 GetInputMethod()->ShowImeIfNeeded();
2877 }
2878
2866 //////////////////////////////////////////////////////////////////////////////// 2879 ////////////////////////////////////////////////////////////////////////////////
2867 // RenderWidgetHostViewBase, public: 2880 // RenderWidgetHostViewBase, public:
2868 2881
2869 // static 2882 // static
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2883 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2871 GetScreenInfoForWindow(results, NULL); 2884 GetScreenInfoForWindow(results, NULL);
2872 } 2885 }
2873 2886
2874 } // namespace content 2887 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698