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