OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1391 } | 1374 } |
1392 | 1375 |
1393 void RenderWidgetHostViewAura::ClearCompositionText() { | 1376 void RenderWidgetHostViewAura::ClearCompositionText() { |
1394 // TODO(wjmaclean): can host_ ever be null? | 1377 // TODO(wjmaclean): can host_ ever be null? |
1395 if (host_ && has_composition_text_) | 1378 if (host_ && has_composition_text_) |
1396 host_->ImeCancelComposition(); | 1379 host_->ImeCancelComposition(); |
1397 has_composition_text_ = false; | 1380 has_composition_text_ = false; |
1398 } | 1381 } |
1399 | 1382 |
1400 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { | 1383 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
1401 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); | 1384 DCHECK(GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE); |
1385 | |
1402 // TODO(wjmaclean): can host_ ever be null? | 1386 // TODO(wjmaclean): can host_ ever be null? |
1403 if (host_) | 1387 if (host_) |
1404 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); | 1388 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
1405 has_composition_text_ = false; | 1389 has_composition_text_ = false; |
1406 } | 1390 } |
1407 | 1391 |
1408 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1392 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
1409 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1393 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
1410 popup_child_host_view_->InsertChar(event); | 1394 popup_child_host_view_->InsertChar(event); |
1411 return; | 1395 return; |
1412 } | 1396 } |
1413 | 1397 |
1414 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1398 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
1415 // TODO(wjmaclean): can host_ ever be null? | 1399 // TODO(wjmaclean): can host_ ever be null? |
1416 if (host_ && | 1400 if (host_ && |
1417 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1401 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { |
1418 // Send a blink::WebInputEvent::Char event to |host_|. | 1402 // Send a blink::WebInputEvent::Char event to |host_|. |
1419 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1403 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
1420 } | 1404 } |
1421 } | 1405 } |
1422 | 1406 |
1423 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1407 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
1424 return text_input_type_; | 1408 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
1409 return text_input_manager_->GetTextInputState()->type; | |
1410 return ui::TEXT_INPUT_TYPE_NONE; | |
1425 } | 1411 } |
1426 | 1412 |
1427 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { | 1413 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { |
1428 return text_input_mode_; | 1414 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
1415 return text_input_manager_->GetTextInputState()->mode; | |
1416 return ui::TEXT_INPUT_MODE_DEFAULT; | |
1429 } | 1417 } |
1430 | 1418 |
1431 int RenderWidgetHostViewAura::GetTextInputFlags() const { | 1419 int RenderWidgetHostViewAura::GetTextInputFlags() const { |
1432 return text_input_flags_; | 1420 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
1421 return text_input_manager_->GetTextInputState()->flags; | |
1422 return 0; | |
1433 } | 1423 } |
1434 | 1424 |
1435 bool RenderWidgetHostViewAura::CanComposeInline() const { | 1425 bool RenderWidgetHostViewAura::CanComposeInline() const { |
1436 return can_compose_inline_; | 1426 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
1427 return text_input_manager_->GetTextInputState()->can_compose_inline; | |
1428 return true; | |
1437 } | 1429 } |
1438 | 1430 |
1439 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( | 1431 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
1440 const gfx::Rect& rect) const { | 1432 const gfx::Rect& rect) const { |
1441 gfx::Point origin = rect.origin(); | 1433 gfx::Point origin = rect.origin(); |
1442 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | 1434 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
1443 | 1435 |
1444 aura::Window* root_window = window_->GetRootWindow(); | 1436 aura::Window* root_window = window_->GetRootWindow(); |
1445 if (!root_window) | 1437 if (!root_window) |
1446 return rect; | 1438 return rect; |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2280 popup_child_host_view_->popup_parent_host_view_ = NULL; | 2272 popup_child_host_view_->popup_parent_host_view_ = NULL; |
2281 } | 2273 } |
2282 event_filter_for_popup_exit_.reset(); | 2274 event_filter_for_popup_exit_.reset(); |
2283 | 2275 |
2284 #if defined(OS_WIN) | 2276 #if defined(OS_WIN) |
2285 // The LegacyRenderWidgetHostHWND window should have been destroyed in | 2277 // The LegacyRenderWidgetHostHWND window should have been destroyed in |
2286 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should | 2278 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should |
2287 // be set to NULL. | 2279 // be set to NULL. |
2288 DCHECK(!legacy_render_widget_host_HWND_); | 2280 DCHECK(!legacy_render_widget_host_HWND_); |
2289 #endif | 2281 #endif |
2282 | |
2283 if (text_input_manager_) | |
2284 text_input_manager_->RemoveObserver(this); | |
2290 } | 2285 } |
2291 | 2286 |
2292 void RenderWidgetHostViewAura::CreateAuraWindow() { | 2287 void RenderWidgetHostViewAura::CreateAuraWindow() { |
2293 DCHECK(!window_); | 2288 DCHECK(!window_); |
2294 window_ = new aura::Window(this); | 2289 window_ = new aura::Window(this); |
2295 window_observer_.reset(new WindowObserver(this)); | 2290 window_observer_.reset(new WindowObserver(this)); |
2296 | 2291 |
2297 aura::client::SetTooltipText(window_, &tooltip_); | 2292 aura::client::SetTooltipText(window_, &tooltip_); |
2298 aura::client::SetActivationDelegate(window_, this); | 2293 aura::client::SetActivationDelegate(window_, this); |
2299 aura::client::SetFocusChangeObserver(window_, this); | 2294 aura::client::SetFocusChangeObserver(window_, this); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2856 } | 2851 } |
2857 | 2852 |
2858 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { | 2853 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { |
2859 return delegated_frame_host_->GetSurfaceIdNamespace(); | 2854 return delegated_frame_host_->GetSurfaceIdNamespace(); |
2860 } | 2855 } |
2861 | 2856 |
2862 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { | 2857 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { |
2863 return delegated_frame_host_->SurfaceIdForTesting(); | 2858 return delegated_frame_host_->SurfaceIdForTesting(); |
2864 } | 2859 } |
2865 | 2860 |
2861 void RenderWidgetHostViewAura::OnTextInputStateUpdated( | |
2862 TextInputManager* text_input_manager, | |
2863 RenderWidgetHostViewBase* updated_view, | |
2864 bool changed) { | |
2865 DCHECK(text_input_manager_ == text_input_manager); | |
2866 if (!GetInputMethod()) | |
2867 return; | |
2868 | |
2869 if (changed) | |
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 | |
2879 void RenderWidgetHostViewAura::OnTextInputManagerDestroyed( | |
Shu Chen
2016/05/13 07:20:41
nit: maybe clearer to rename this as OnDestroyingT
EhsanK
2016/05/13 16:00:56
Acknowledged.
| |
2880 TextInputManager* text_input_manager) { | |
2881 DCHECK(text_input_manager && text_input_manager_ == text_input_manager); | |
2882 | |
2883 if (text_input_manager_->IsRegisteredView(this)) | |
2884 text_input_manager_->Unregister(this); | |
2885 | |
2886 text_input_manager_->RemoveObserver(this); | |
2887 | |
2888 text_input_manager_ = nullptr; | |
2889 } | |
2866 //////////////////////////////////////////////////////////////////////////////// | 2890 //////////////////////////////////////////////////////////////////////////////// |
2867 // RenderWidgetHostViewBase, public: | 2891 // RenderWidgetHostViewBase, public: |
2868 | 2892 |
2869 // static | 2893 // static |
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2894 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2871 GetScreenInfoForWindow(results, NULL); | 2895 GetScreenInfoForWindow(results, NULL); |
2872 } | 2896 } |
2873 | 2897 |
2874 } // namespace content | 2898 } // namespace content |
OLD | NEW |