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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 bool is_guest_view_hack) | 364 bool is_guest_view_hack) |
365 : host_(RenderWidgetHostImpl::From(host)), | 365 : host_(RenderWidgetHostImpl::From(host)), |
366 window_(nullptr), | 366 window_(nullptr), |
367 delegated_frame_host_(new DelegatedFrameHost(this)), | 367 delegated_frame_host_(new DelegatedFrameHost(this)), |
368 in_shutdown_(false), | 368 in_shutdown_(false), |
369 in_bounds_changed_(false), | 369 in_bounds_changed_(false), |
370 is_fullscreen_(false), | 370 is_fullscreen_(false), |
371 popup_parent_host_view_(NULL), | 371 popup_parent_host_view_(NULL), |
372 popup_child_host_view_(NULL), | 372 popup_child_host_view_(NULL), |
373 is_loading_(false), | 373 is_loading_(false), |
374 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | |
375 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | |
376 text_input_flags_(0), | |
377 can_compose_inline_(true), | |
378 has_composition_text_(false), | 374 has_composition_text_(false), |
379 accept_return_character_(false), | 375 accept_return_character_(false), |
380 last_swapped_software_frame_scale_factor_(1.f), | 376 last_swapped_software_frame_scale_factor_(1.f), |
381 paint_canvas_(NULL), | 377 paint_canvas_(NULL), |
382 synthetic_move_sent_(false), | 378 synthetic_move_sent_(false), |
383 cursor_visibility_state_in_renderer_(UNKNOWN), | 379 cursor_visibility_state_in_renderer_(UNKNOWN), |
384 #if defined(OS_WIN) | 380 #if defined(OS_WIN) |
385 legacy_render_widget_host_HWND_(NULL), | 381 legacy_render_widget_host_HWND_(NULL), |
386 legacy_window_destroyed_(false), | 382 legacy_window_destroyed_(false), |
387 #endif | 383 #endif |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 850 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
855 current_cursor_.SetDisplayInfo(display); | 851 current_cursor_.SetDisplayInfo(display); |
856 UpdateCursorIfOverSelf(); | 852 UpdateCursorIfOverSelf(); |
857 } | 853 } |
858 | 854 |
859 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 855 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
860 is_loading_ = is_loading; | 856 is_loading_ = is_loading; |
861 UpdateCursorIfOverSelf(); | 857 UpdateCursorIfOverSelf(); |
862 } | 858 } |
863 | 859 |
864 void RenderWidgetHostViewAura::TextInputStateChanged( | 860 void RenderWidgetHostViewAura::UpdateInputMethodIfNecessary( |
865 const ViewHostMsg_TextInputState_Params& params) { | 861 bool text_input_state_changed) { |
866 if (text_input_type_ != params.type || | 862 if (!GetInputMethod()) |
867 text_input_mode_ != params.mode || | 863 return; |
868 can_compose_inline_ != params.can_compose_inline || | 864 |
869 text_input_flags_ != params.flags) { | 865 if (text_input_state_changed) |
870 text_input_type_ = params.type; | 866 GetInputMethod()->OnTextInputTypeChanged(this); |
871 text_input_mode_ = params.mode; | 867 |
872 can_compose_inline_ = params.can_compose_inline; | 868 TextInputState state = host_->delegate()->GetTextInputState(); |
873 text_input_flags_ = params.flags; | 869 |
874 if (GetInputMethod()) | 870 if (state.show_ime_if_needed && state.type != ui::TEXT_INPUT_TYPE_NONE) |
875 GetInputMethod()->OnTextInputTypeChanged(this); | 871 GetInputMethod()->ShowImeIfNeeded(); |
876 } | |
877 if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) { | |
878 if (GetInputMethod()) | |
879 GetInputMethod()->ShowImeIfNeeded(); | |
880 } | |
881 } | 872 } |
882 | 873 |
883 void RenderWidgetHostViewAura::ImeCancelComposition() { | 874 void RenderWidgetHostViewAura::ImeCancelComposition() { |
884 if (GetInputMethod()) | 875 if (GetInputMethod()) |
885 GetInputMethod()->CancelComposition(this); | 876 GetInputMethod()->CancelComposition(this); |
886 has_composition_text_ = false; | 877 has_composition_text_ = false; |
887 } | 878 } |
888 | 879 |
889 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( | 880 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( |
890 const gfx::Range& range, | 881 const gfx::Range& range, |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 } | 1458 } |
1468 | 1459 |
1469 void RenderWidgetHostViewAura::ClearCompositionText() { | 1460 void RenderWidgetHostViewAura::ClearCompositionText() { |
1470 // TODO(wjmaclean): can host_ ever be null? | 1461 // TODO(wjmaclean): can host_ ever be null? |
1471 if (host_ && has_composition_text_) | 1462 if (host_ && has_composition_text_) |
1472 host_->ImeCancelComposition(); | 1463 host_->ImeCancelComposition(); |
1473 has_composition_text_ = false; | 1464 has_composition_text_ = false; |
1474 } | 1465 } |
1475 | 1466 |
1476 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { | 1467 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
1477 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); | 1468 DCHECK(RenderWidgetHostImpl::From(GetRenderWidgetHost()) |
| 1469 ->delegate() |
| 1470 ->GetTextInputState() |
| 1471 .type != ui::TEXT_INPUT_TYPE_NONE); |
1478 // TODO(wjmaclean): can host_ ever be null? | 1472 // TODO(wjmaclean): can host_ ever be null? |
1479 if (host_) | 1473 if (host_) |
1480 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); | 1474 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
1481 has_composition_text_ = false; | 1475 has_composition_text_ = false; |
1482 } | 1476 } |
1483 | 1477 |
1484 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1478 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
1485 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1479 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
1486 popup_child_host_view_->InsertChar(event); | 1480 popup_child_host_view_->InsertChar(event); |
1487 return; | 1481 return; |
1488 } | 1482 } |
1489 | 1483 |
1490 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1484 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
1491 // TODO(wjmaclean): can host_ ever be null? | 1485 // TODO(wjmaclean): can host_ ever be null? |
1492 if (host_ && | 1486 if (host_ && |
1493 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1487 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { |
1494 // Send a blink::WebInputEvent::Char event to |host_|. | 1488 // Send a blink::WebInputEvent::Char event to |host_|. |
1495 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1489 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
1496 } | 1490 } |
1497 } | 1491 } |
1498 | 1492 |
1499 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1493 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
1500 return text_input_type_; | 1494 if (host_->delegate()) |
| 1495 return host_->delegate()->GetTextInputState().type; |
| 1496 return text_input_state()->type; |
1501 } | 1497 } |
1502 | 1498 |
1503 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { | 1499 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { |
1504 return text_input_mode_; | 1500 if (host_->delegate()) |
| 1501 return host_->delegate()->GetTextInputState().mode; |
| 1502 return text_input_state()->mode; |
1505 } | 1503 } |
1506 | 1504 |
1507 int RenderWidgetHostViewAura::GetTextInputFlags() const { | 1505 int RenderWidgetHostViewAura::GetTextInputFlags() const { |
1508 return text_input_flags_; | 1506 if (host_->delegate()) |
| 1507 return host_->delegate()->GetTextInputState().flags; |
| 1508 return text_input_state()->flags; |
1509 } | 1509 } |
1510 | 1510 |
1511 bool RenderWidgetHostViewAura::CanComposeInline() const { | 1511 bool RenderWidgetHostViewAura::CanComposeInline() const { |
1512 return can_compose_inline_; | 1512 if (host_->delegate()) |
| 1513 return host_->delegate()->GetTextInputState().can_compose_inline; |
| 1514 return text_input_state()->can_compose_inline; |
1513 } | 1515 } |
1514 | 1516 |
1515 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( | 1517 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
1516 const gfx::Rect& rect) const { | 1518 const gfx::Rect& rect) const { |
1517 gfx::Point origin = rect.origin(); | 1519 gfx::Point origin = rect.origin(); |
1518 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | 1520 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
1519 | 1521 |
1520 aura::Window* root_window = window_->GetRootWindow(); | 1522 aura::Window* root_window = window_->GetRootWindow(); |
1521 if (!root_window) | 1523 if (!root_window) |
1522 return rect; | 1524 return rect; |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2654 if (window_->GetHost()->compositor()) | 2656 if (window_->GetHost()->compositor()) |
2655 begin_frame_observer_proxy_.SetCompositor(window_->GetHost()->compositor()); | 2657 begin_frame_observer_proxy_.SetCompositor(window_->GetHost()->compositor()); |
2656 } | 2658 } |
2657 | 2659 |
2658 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 2660 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
2659 aura::client::CursorClient* cursor_client = | 2661 aura::client::CursorClient* cursor_client = |
2660 aura::client::GetCursorClient(window_->GetRootWindow()); | 2662 aura::client::GetCursorClient(window_->GetRootWindow()); |
2661 if (cursor_client) | 2663 if (cursor_client) |
2662 cursor_client->RemoveObserver(this); | 2664 cursor_client->RemoveObserver(this); |
2663 | 2665 |
| 2666 // The WebContentsImpl should be notified about us so that it will not hold |
| 2667 // an invalid text input state which was due to active text on this view. |
| 2668 NotifyHostDelegateAboutShutdown(); |
| 2669 |
2664 DetachFromInputMethod(); | 2670 DetachFromInputMethod(); |
2665 | 2671 |
2666 window_->GetHost()->RemoveObserver(this); | 2672 window_->GetHost()->RemoveObserver(this); |
2667 delegated_frame_host_->ResetCompositor(); | 2673 delegated_frame_host_->ResetCompositor(); |
2668 begin_frame_observer_proxy_.ResetCompositor(); | 2674 begin_frame_observer_proxy_.ResetCompositor(); |
2669 | 2675 |
2670 #if defined(OS_WIN) | 2676 #if defined(OS_WIN) |
2671 // Update the legacy window's parent temporarily to the desktop window. It | 2677 // Update the legacy window's parent temporarily to the desktop window. It |
2672 // will eventually get reparented to the right root. | 2678 // will eventually get reparented to the right root. |
2673 if (legacy_render_widget_host_HWND_) | 2679 if (legacy_render_widget_host_HWND_) |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2930 | 2936 |
2931 //////////////////////////////////////////////////////////////////////////////// | 2937 //////////////////////////////////////////////////////////////////////////////// |
2932 // RenderWidgetHostViewBase, public: | 2938 // RenderWidgetHostViewBase, public: |
2933 | 2939 |
2934 // static | 2940 // static |
2935 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2941 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2936 GetScreenInfoForWindow(results, NULL); | 2942 GetScreenInfoForWindow(results, NULL); |
2937 } | 2943 } |
2938 | 2944 |
2939 } // namespace content | 2945 } // namespace content |
OLD | NEW |