| 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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 bool is_guest_view_hack) | 447 bool is_guest_view_hack) |
| 448 : host_(RenderWidgetHostImpl::From(host)), | 448 : host_(RenderWidgetHostImpl::From(host)), |
| 449 window_(nullptr), | 449 window_(nullptr), |
| 450 delegated_frame_host_(new DelegatedFrameHost(this)), | 450 delegated_frame_host_(new DelegatedFrameHost(this)), |
| 451 in_shutdown_(false), | 451 in_shutdown_(false), |
| 452 in_bounds_changed_(false), | 452 in_bounds_changed_(false), |
| 453 is_fullscreen_(false), | 453 is_fullscreen_(false), |
| 454 popup_parent_host_view_(nullptr), | 454 popup_parent_host_view_(nullptr), |
| 455 popup_child_host_view_(nullptr), | 455 popup_child_host_view_(nullptr), |
| 456 is_loading_(false), | 456 is_loading_(false), |
| 457 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | |
| 458 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | |
| 459 text_input_flags_(0), | |
| 460 can_compose_inline_(true), | |
| 461 has_composition_text_(false), | 457 has_composition_text_(false), |
| 462 accept_return_character_(false), | 458 accept_return_character_(false), |
| 463 begin_frame_source_(nullptr), | 459 begin_frame_source_(nullptr), |
| 464 needs_begin_frames_(false), | 460 needs_begin_frames_(false), |
| 465 synthetic_move_sent_(false), | 461 synthetic_move_sent_(false), |
| 466 cursor_visibility_state_in_renderer_(UNKNOWN), | 462 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 467 #if defined(OS_WIN) | 463 #if defined(OS_WIN) |
| 468 legacy_render_widget_host_HWND_(nullptr), | 464 legacy_render_widget_host_HWND_(nullptr), |
| 469 legacy_window_destroyed_(false), | 465 legacy_window_destroyed_(false), |
| 470 virtual_keyboard_requested_(false), | 466 virtual_keyboard_requested_(false), |
| 471 #endif | 467 #endif |
| 472 has_snapped_to_boundary_(false), | 468 has_snapped_to_boundary_(false), |
| 473 is_guest_view_hack_(is_guest_view_hack), | 469 is_guest_view_hack_(is_guest_view_hack), |
| 474 set_focus_on_mouse_down_or_key_event_(false), | 470 set_focus_on_mouse_down_or_key_event_(false), |
| 475 device_scale_factor_(0.0f), | 471 device_scale_factor_(0.0f), |
| 476 disable_input_event_router_for_testing_(false), | 472 disable_input_event_router_for_testing_(false), |
| 477 weak_ptr_factory_(this) { | 473 weak_ptr_factory_(this) { |
| 478 if (!is_guest_view_hack_) | 474 if (!is_guest_view_hack_) |
| 479 host_->SetView(this); | 475 host_->SetView(this); |
| 480 | 476 |
| 481 // Let the page-level input event router know about our surface ID | 477 // Let the page-level input event router know about our surface ID |
| 482 // namespace for surface-based hit testing. | 478 // namespace for surface-based hit testing. |
| 483 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { | 479 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { |
| 484 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner( | 480 host_->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner( |
| 485 GetSurfaceIdNamespace(), this); | 481 GetSurfaceIdNamespace(), this); |
| 486 } | 482 } |
| 487 | 483 |
| 484 // We should start observing the TextInputManager for IME-related events as |
| 485 // well as monitoring its lifetime. |
| 486 if (GetTextInputManager()) |
| 487 GetTextInputManager()->AddObserver(this); |
| 488 |
| 488 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> | 489 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
| 489 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 490 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
| 490 SetOverscrollControllerEnabled(overscroll_enabled); | 491 SetOverscrollControllerEnabled(overscroll_enabled); |
| 491 | 492 |
| 492 selection_controller_client_.reset( | 493 selection_controller_client_.reset( |
| 493 new TouchSelectionControllerClientAura(this)); | 494 new TouchSelectionControllerClientAura(this)); |
| 494 CreateSelectionController(); | 495 CreateSelectionController(); |
| 495 } | 496 } |
| 496 | 497 |
| 497 //////////////////////////////////////////////////////////////////////////////// | 498 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 969 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
| 969 current_cursor_.SetDisplayInfo(display); | 970 current_cursor_.SetDisplayInfo(display); |
| 970 UpdateCursorIfOverSelf(); | 971 UpdateCursorIfOverSelf(); |
| 971 } | 972 } |
| 972 | 973 |
| 973 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 974 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
| 974 is_loading_ = is_loading; | 975 is_loading_ = is_loading; |
| 975 UpdateCursorIfOverSelf(); | 976 UpdateCursorIfOverSelf(); |
| 976 } | 977 } |
| 977 | 978 |
| 978 void RenderWidgetHostViewAura::TextInputStateChanged( | |
| 979 const TextInputState& params) { | |
| 980 if (text_input_type_ != params.type || | |
| 981 text_input_mode_ != params.mode || | |
| 982 can_compose_inline_ != params.can_compose_inline || | |
| 983 text_input_flags_ != params.flags) { | |
| 984 text_input_type_ = params.type; | |
| 985 text_input_mode_ = params.mode; | |
| 986 can_compose_inline_ = params.can_compose_inline; | |
| 987 text_input_flags_ = params.flags; | |
| 988 if (GetInputMethod()) | |
| 989 GetInputMethod()->OnTextInputTypeChanged(this); | |
| 990 } | |
| 991 if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) { | |
| 992 if (GetInputMethod()) | |
| 993 GetInputMethod()->ShowImeIfNeeded(); | |
| 994 } | |
| 995 } | |
| 996 | |
| 997 void RenderWidgetHostViewAura::ImeCancelComposition() { | 979 void RenderWidgetHostViewAura::ImeCancelComposition() { |
| 998 if (GetInputMethod()) | 980 if (GetInputMethod()) |
| 999 GetInputMethod()->CancelComposition(this); | 981 GetInputMethod()->CancelComposition(this); |
| 1000 has_composition_text_ = false; | 982 has_composition_text_ = false; |
| 1001 } | 983 } |
| 1002 | 984 |
| 1003 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( | 985 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( |
| 1004 const gfx::Range& range, | 986 const gfx::Range& range, |
| 1005 const std::vector<gfx::Rect>& character_bounds) { | 987 const std::vector<gfx::Rect>& character_bounds) { |
| 1006 composition_character_bounds_ = character_bounds; | 988 composition_character_bounds_ = character_bounds; |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 } | 1471 } |
| 1490 | 1472 |
| 1491 void RenderWidgetHostViewAura::ClearCompositionText() { | 1473 void RenderWidgetHostViewAura::ClearCompositionText() { |
| 1492 // TODO(wjmaclean): can host_ ever be null? | 1474 // TODO(wjmaclean): can host_ ever be null? |
| 1493 if (host_ && has_composition_text_) | 1475 if (host_ && has_composition_text_) |
| 1494 host_->ImeCancelComposition(); | 1476 host_->ImeCancelComposition(); |
| 1495 has_composition_text_ = false; | 1477 has_composition_text_ = false; |
| 1496 } | 1478 } |
| 1497 | 1479 |
| 1498 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { | 1480 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
| 1499 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); | 1481 DCHECK_NE(GetTextInputType(), ui::TEXT_INPUT_TYPE_NONE); |
| 1482 |
| 1500 // TODO(wjmaclean): can host_ ever be null? | 1483 // TODO(wjmaclean): can host_ ever be null? |
| 1501 if (host_) | 1484 if (host_) |
| 1502 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); | 1485 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
| 1503 has_composition_text_ = false; | 1486 has_composition_text_ = false; |
| 1504 } | 1487 } |
| 1505 | 1488 |
| 1506 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1489 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
| 1507 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1490 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
| 1508 popup_child_host_view_->InsertChar(event); | 1491 popup_child_host_view_->InsertChar(event); |
| 1509 return; | 1492 return; |
| 1510 } | 1493 } |
| 1511 | 1494 |
| 1512 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1495 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
| 1513 // TODO(wjmaclean): can host_ ever be null? | 1496 // TODO(wjmaclean): can host_ ever be null? |
| 1514 if (host_ && | 1497 if (host_ && |
| 1515 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1498 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { |
| 1516 // Send a blink::WebInputEvent::Char event to |host_|. | 1499 // Send a blink::WebInputEvent::Char event to |host_|. |
| 1517 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1500 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
| 1518 } | 1501 } |
| 1519 } | 1502 } |
| 1520 | 1503 |
| 1521 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1504 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
| 1522 return text_input_type_; | 1505 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
| 1506 return text_input_manager_->GetTextInputState()->type; |
| 1507 return ui::TEXT_INPUT_TYPE_NONE; |
| 1523 } | 1508 } |
| 1524 | 1509 |
| 1525 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { | 1510 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { |
| 1526 return text_input_mode_; | 1511 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
| 1512 return text_input_manager_->GetTextInputState()->mode; |
| 1513 return ui::TEXT_INPUT_MODE_DEFAULT; |
| 1527 } | 1514 } |
| 1528 | 1515 |
| 1529 int RenderWidgetHostViewAura::GetTextInputFlags() const { | 1516 int RenderWidgetHostViewAura::GetTextInputFlags() const { |
| 1530 return text_input_flags_; | 1517 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
| 1518 return text_input_manager_->GetTextInputState()->flags; |
| 1519 return 0; |
| 1531 } | 1520 } |
| 1532 | 1521 |
| 1533 bool RenderWidgetHostViewAura::CanComposeInline() const { | 1522 bool RenderWidgetHostViewAura::CanComposeInline() const { |
| 1534 return can_compose_inline_; | 1523 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
| 1524 return text_input_manager_->GetTextInputState()->can_compose_inline; |
| 1525 return true; |
| 1535 } | 1526 } |
| 1536 | 1527 |
| 1537 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( | 1528 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
| 1538 const gfx::Rect& rect) const { | 1529 const gfx::Rect& rect) const { |
| 1539 gfx::Point origin = rect.origin(); | 1530 gfx::Point origin = rect.origin(); |
| 1540 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | 1531 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
| 1541 | 1532 |
| 1542 aura::Window* root_window = window_->GetRootWindow(); | 1533 aura::Window* root_window = window_->GetRootWindow(); |
| 1543 if (!root_window) | 1534 if (!root_window) |
| 1544 return rect; | 1535 return rect; |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2401 DCHECK(!legacy_render_widget_host_HWND_); | 2392 DCHECK(!legacy_render_widget_host_HWND_); |
| 2402 if (virtual_keyboard_requested_) { | 2393 if (virtual_keyboard_requested_) { |
| 2403 DCHECK(keyboard_observer_.get()); | 2394 DCHECK(keyboard_observer_.get()); |
| 2404 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | 2395 ui::OnScreenKeyboardDisplayManager* osk_display_manager = |
| 2405 ui::OnScreenKeyboardDisplayManager::GetInstance(); | 2396 ui::OnScreenKeyboardDisplayManager::GetInstance(); |
| 2406 DCHECK(osk_display_manager); | 2397 DCHECK(osk_display_manager); |
| 2407 osk_display_manager->RemoveObserver(keyboard_observer_.get()); | 2398 osk_display_manager->RemoveObserver(keyboard_observer_.get()); |
| 2408 } | 2399 } |
| 2409 | 2400 |
| 2410 #endif | 2401 #endif |
| 2402 |
| 2403 if (text_input_manager_) |
| 2404 text_input_manager_->RemoveObserver(this); |
| 2411 } | 2405 } |
| 2412 | 2406 |
| 2413 void RenderWidgetHostViewAura::CreateAuraWindow() { | 2407 void RenderWidgetHostViewAura::CreateAuraWindow() { |
| 2414 DCHECK(!window_); | 2408 DCHECK(!window_); |
| 2415 window_ = new aura::Window(this); | 2409 window_ = new aura::Window(this); |
| 2416 window_observer_.reset(new WindowObserver(this)); | 2410 window_observer_.reset(new WindowObserver(this)); |
| 2417 | 2411 |
| 2418 aura::client::SetTooltipText(window_, &tooltip_); | 2412 aura::client::SetTooltipText(window_, &tooltip_); |
| 2419 aura::client::SetActivationDelegate(window_, this); | 2413 aura::client::SetActivationDelegate(window_, this); |
| 2420 aura::client::SetFocusChangeObserver(window_, this); | 2414 aura::client::SetFocusChangeObserver(window_, this); |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2982 } | 2976 } |
| 2983 | 2977 |
| 2984 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { | 2978 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() { |
| 2985 return delegated_frame_host_->GetSurfaceIdNamespace(); | 2979 return delegated_frame_host_->GetSurfaceIdNamespace(); |
| 2986 } | 2980 } |
| 2987 | 2981 |
| 2988 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { | 2982 cc::SurfaceId RenderWidgetHostViewAura::SurfaceIdForTesting() const { |
| 2989 return delegated_frame_host_->SurfaceIdForTesting(); | 2983 return delegated_frame_host_->SurfaceIdForTesting(); |
| 2990 } | 2984 } |
| 2991 | 2985 |
| 2986 void RenderWidgetHostViewAura::OnUpdateTextInputStateCalled( |
| 2987 TextInputManager* text_input_manager, |
| 2988 RenderWidgetHostViewBase* updated_view, |
| 2989 bool did_update_state) { |
| 2990 DCHECK_EQ(text_input_manager_, text_input_manager); |
| 2991 |
| 2992 if (!GetInputMethod()) |
| 2993 return; |
| 2994 |
| 2995 if (did_update_state) |
| 2996 GetInputMethod()->OnTextInputTypeChanged(this); |
| 2997 |
| 2998 const TextInputState* state = text_input_manager_->GetTextInputState(); |
| 2999 |
| 3000 if (state && state->show_ime_if_needed && |
| 3001 state->type != ui::TEXT_INPUT_TYPE_NONE) |
| 3002 GetInputMethod()->ShowImeIfNeeded(); |
| 3003 } |
| 3004 |
| 2992 //////////////////////////////////////////////////////////////////////////////// | 3005 //////////////////////////////////////////////////////////////////////////////// |
| 2993 // RenderWidgetHostViewBase, public: | 3006 // RenderWidgetHostViewBase, public: |
| 2994 | 3007 |
| 2995 // static | 3008 // static |
| 2996 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 3009 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2997 GetScreenInfoForWindow(results, NULL); | 3010 GetScreenInfoForWindow(results, NULL); |
| 2998 } | 3011 } |
| 2999 | 3012 |
| 3000 } // namespace content | 3013 } // namespace content |
| OLD | NEW |