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 if (GetTextInputManager()) | |
400 GetTextInputManager()->AddObserver(this); | |
401 | |
403 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> | 402 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
404 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 403 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
405 SetOverscrollControllerEnabled(overscroll_enabled); | 404 SetOverscrollControllerEnabled(overscroll_enabled); |
406 | 405 |
407 selection_controller_client_.reset( | 406 selection_controller_client_.reset( |
408 new TouchSelectionControllerClientAura(this)); | 407 new TouchSelectionControllerClientAura(this)); |
409 CreateSelectionController(); | 408 CreateSelectionController(); |
410 } | 409 } |
411 | 410 |
412 //////////////////////////////////////////////////////////////////////////////// | 411 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 869 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
871 current_cursor_.SetDisplayInfo(display); | 870 current_cursor_.SetDisplayInfo(display); |
872 UpdateCursorIfOverSelf(); | 871 UpdateCursorIfOverSelf(); |
873 } | 872 } |
874 | 873 |
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 874 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
876 is_loading_ = is_loading; | 875 is_loading_ = is_loading; |
877 UpdateCursorIfOverSelf(); | 876 UpdateCursorIfOverSelf(); |
878 } | 877 } |
879 | 878 |
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() { | 879 void RenderWidgetHostViewAura::ImeCancelComposition() { |
900 if (GetInputMethod()) | 880 if (GetInputMethod()) |
901 GetInputMethod()->CancelComposition(this); | 881 GetInputMethod()->CancelComposition(this); |
902 has_composition_text_ = false; | 882 has_composition_text_ = false; |
903 } | 883 } |
904 | 884 |
905 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( | 885 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( |
906 const gfx::Range& range, | 886 const gfx::Range& range, |
907 const std::vector<gfx::Rect>& character_bounds) { | 887 const std::vector<gfx::Rect>& character_bounds) { |
908 composition_character_bounds_ = character_bounds; | 888 composition_character_bounds_ = character_bounds; |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1490 } | 1470 } |
1491 | 1471 |
1492 void RenderWidgetHostViewAura::ClearCompositionText() { | 1472 void RenderWidgetHostViewAura::ClearCompositionText() { |
1493 // TODO(wjmaclean): can host_ ever be null? | 1473 // TODO(wjmaclean): can host_ ever be null? |
1494 if (host_ && has_composition_text_) | 1474 if (host_ && has_composition_text_) |
1495 host_->ImeCancelComposition(); | 1475 host_->ImeCancelComposition(); |
1496 has_composition_text_ = false; | 1476 has_composition_text_ = false; |
1497 } | 1477 } |
1498 | 1478 |
1499 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { | 1479 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
1500 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); | 1480 DCHECK(GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE); |
1481 | |
1501 // TODO(wjmaclean): can host_ ever be null? | 1482 // TODO(wjmaclean): can host_ ever be null? |
1502 if (host_) | 1483 if (host_) |
1503 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); | 1484 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
1504 has_composition_text_ = false; | 1485 has_composition_text_ = false; |
1505 } | 1486 } |
1506 | 1487 |
1507 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1488 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
1508 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1489 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
1509 popup_child_host_view_->InsertChar(event); | 1490 popup_child_host_view_->InsertChar(event); |
1510 return; | 1491 return; |
1511 } | 1492 } |
1512 | 1493 |
1513 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1494 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
1514 // TODO(wjmaclean): can host_ ever be null? | 1495 // TODO(wjmaclean): can host_ ever be null? |
1515 if (host_ && | 1496 if (host_ && |
1516 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1497 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { |
1517 // Send a blink::WebInputEvent::Char event to |host_|. | 1498 // Send a blink::WebInputEvent::Char event to |host_|. |
1518 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1499 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
1519 } | 1500 } |
1520 } | 1501 } |
1521 | 1502 |
1522 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1503 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
1523 return text_input_type_; | 1504 if (GetTextInputManager() && GetTextInputManager()->GetTextInputState()) |
1505 return GetTextInputManager()->GetTextInputState()->type; | |
1506 return ui::TEXT_INPUT_TYPE_NONE; | |
1524 } | 1507 } |
1525 | 1508 |
1526 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { | 1509 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { |
1527 return text_input_mode_; | 1510 if (GetTextInputManager() && GetTextInputManager()->GetTextInputState()) |
1511 return GetTextInputManager()->GetTextInputState()->mode; | |
1512 return ui::TEXT_INPUT_MODE_DEFAULT; | |
1528 } | 1513 } |
1529 | 1514 |
1530 int RenderWidgetHostViewAura::GetTextInputFlags() const { | 1515 int RenderWidgetHostViewAura::GetTextInputFlags() const { |
1531 return text_input_flags_; | 1516 if (GetTextInputManager() && GetTextInputManager()->GetTextInputState()) |
1517 return GetTextInputManager()->GetTextInputState()->flags; | |
1518 return 0; | |
1532 } | 1519 } |
1533 | 1520 |
1534 bool RenderWidgetHostViewAura::CanComposeInline() const { | 1521 bool RenderWidgetHostViewAura::CanComposeInline() const { |
1535 return can_compose_inline_; | 1522 if (GetTextInputManager() && GetTextInputManager()->GetTextInputState()) |
1523 return GetTextInputManager()->GetTextInputState()->can_compose_inline; | |
1524 return true; | |
1536 } | 1525 } |
1537 | 1526 |
1538 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( | 1527 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
1539 const gfx::Rect& rect) const { | 1528 const gfx::Rect& rect) const { |
1540 gfx::Point origin = rect.origin(); | 1529 gfx::Point origin = rect.origin(); |
1541 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | 1530 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
1542 | 1531 |
1543 aura::Window* root_window = window_->GetRootWindow(); | 1532 aura::Window* root_window = window_->GetRootWindow(); |
1544 if (!root_window) | 1533 if (!root_window) |
1545 return rect; | 1534 return rect; |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2383 popup_child_host_view_->popup_parent_host_view_ = NULL; | 2372 popup_child_host_view_->popup_parent_host_view_ = NULL; |
2384 } | 2373 } |
2385 event_filter_for_popup_exit_.reset(); | 2374 event_filter_for_popup_exit_.reset(); |
2386 | 2375 |
2387 #if defined(OS_WIN) | 2376 #if defined(OS_WIN) |
2388 // The LegacyRenderWidgetHostHWND window should have been destroyed in | 2377 // The LegacyRenderWidgetHostHWND window should have been destroyed in |
2389 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should | 2378 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should |
2390 // be set to NULL. | 2379 // be set to NULL. |
2391 DCHECK(!legacy_render_widget_host_HWND_); | 2380 DCHECK(!legacy_render_widget_host_HWND_); |
2392 #endif | 2381 #endif |
2382 // We will ask the TextInputManager to unregister this view in the dtor or | |
2383 // RenderWidgetHostViewBase. Therefore, | |
2384 // if this view is still being tracked by TextInputManager, then we are also | |
2385 // observing the TextInputManager. | |
2386 if (GetTextInputManager() && GetTextInputManager()->IsRegisteredView(this)) | |
2387 GetTextInputManager()->RemoveObserver(this); | |
EhsanK
2016/05/06 18:23:43
We need to remove the observer here. If not, the R
| |
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 Loading... | |
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(GetTextInputManager() == text_input_manager); | |
2956 if (!GetInputMethod()) | |
2957 return; | |
2958 | |
2959 if (changed) | |
2960 GetInputMethod()->OnTextInputTypeChanged(this); | |
2961 | |
2962 const TextInputState* state = GetTextInputManager()->GetTextInputState(); | |
2963 | |
2964 if (state && state->show_ime_if_needed && | |
2965 state->type != ui::TEXT_INPUT_TYPE_NONE) | |
2966 GetInputMethod()->ShowImeIfNeeded(); | |
2967 } | |
2968 | |
2956 //////////////////////////////////////////////////////////////////////////////// | 2969 //////////////////////////////////////////////////////////////////////////////// |
2957 // RenderWidgetHostViewBase, public: | 2970 // RenderWidgetHostViewBase, public: |
2958 | 2971 |
2959 // static | 2972 // static |
2960 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2973 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2961 GetScreenInfoForWindow(results, NULL); | 2974 GetScreenInfoForWindow(results, NULL); |
2962 } | 2975 } |
2963 | 2976 |
2964 } // namespace content | 2977 } // namespace content |
OLD | NEW |