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_(NULL), | 370 popup_parent_host_view_(NULL), |
371 popup_child_host_view_(NULL), | 371 popup_child_host_view_(NULL), |
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), |
373 has_composition_text_(false), | 377 has_composition_text_(false), |
374 accept_return_character_(false), | 378 accept_return_character_(false), |
375 last_swapped_software_frame_scale_factor_(1.f), | 379 last_swapped_software_frame_scale_factor_(1.f), |
376 paint_canvas_(NULL), | 380 paint_canvas_(NULL), |
377 synthetic_move_sent_(false), | 381 synthetic_move_sent_(false), |
378 cursor_visibility_state_in_renderer_(UNKNOWN), | 382 cursor_visibility_state_in_renderer_(UNKNOWN), |
379 #if defined(OS_WIN) | 383 #if defined(OS_WIN) |
380 legacy_render_widget_host_HWND_(NULL), | 384 legacy_render_widget_host_HWND_(NULL), |
381 legacy_window_destroyed_(false), | 385 legacy_window_destroyed_(false), |
382 #endif | 386 #endif |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 853 gfx::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
850 current_cursor_.SetDisplayInfo(display); | 854 current_cursor_.SetDisplayInfo(display); |
851 UpdateCursorIfOverSelf(); | 855 UpdateCursorIfOverSelf(); |
852 } | 856 } |
853 | 857 |
854 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 858 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
855 is_loading_ = is_loading; | 859 is_loading_ = is_loading; |
856 UpdateCursorIfOverSelf(); | 860 UpdateCursorIfOverSelf(); |
857 } | 861 } |
858 | 862 |
859 void RenderWidgetHostViewAura::UpdateInputMethodIfNecessary( | 863 void RenderWidgetHostViewAura::TextInputStateChanged( |
860 bool text_input_state_changed) { | 864 const ViewHostMsg_TextInputState_Params& params) { |
861 if (!GetInputMethod()) | 865 if (text_input_type_ != params.type || |
862 return; | 866 text_input_mode_ != params.mode || |
863 | 867 can_compose_inline_ != params.can_compose_inline || |
864 if (text_input_state_changed) | 868 text_input_flags_ != params.flags) { |
865 GetInputMethod()->OnTextInputTypeChanged(this); | 869 text_input_type_ = params.type; |
866 | 870 text_input_mode_ = params.mode; |
867 const TextInputState* state = host_->delegate()->GetTextInputState(); | 871 can_compose_inline_ = params.can_compose_inline; |
868 | 872 text_input_flags_ = params.flags; |
869 if (state->show_ime_if_needed && state->type != ui::TEXT_INPUT_TYPE_NONE) | 873 if (GetInputMethod()) |
870 GetInputMethod()->ShowImeIfNeeded(); | 874 GetInputMethod()->OnTextInputTypeChanged(this); |
| 875 } |
| 876 if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) { |
| 877 if (GetInputMethod()) |
| 878 GetInputMethod()->ShowImeIfNeeded(); |
| 879 } |
871 } | 880 } |
872 | 881 |
873 void RenderWidgetHostViewAura::ImeCancelComposition() { | 882 void RenderWidgetHostViewAura::ImeCancelComposition() { |
874 if (GetInputMethod()) | 883 if (GetInputMethod()) |
875 GetInputMethod()->CancelComposition(this); | 884 GetInputMethod()->CancelComposition(this); |
876 has_composition_text_ = false; | 885 has_composition_text_ = false; |
877 } | 886 } |
878 | 887 |
879 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( | 888 void RenderWidgetHostViewAura::ImeCompositionRangeChanged( |
880 const gfx::Range& range, | 889 const gfx::Range& range, |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 } | 1466 } |
1458 | 1467 |
1459 void RenderWidgetHostViewAura::ClearCompositionText() { | 1468 void RenderWidgetHostViewAura::ClearCompositionText() { |
1460 // TODO(wjmaclean): can host_ ever be null? | 1469 // TODO(wjmaclean): can host_ ever be null? |
1461 if (host_ && has_composition_text_) | 1470 if (host_ && has_composition_text_) |
1462 host_->ImeCancelComposition(); | 1471 host_->ImeCancelComposition(); |
1463 has_composition_text_ = false; | 1472 has_composition_text_ = false; |
1464 } | 1473 } |
1465 | 1474 |
1466 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { | 1475 void RenderWidgetHostViewAura::InsertText(const base::string16& text) { |
1467 DCHECK(RenderWidgetHostImpl::From(GetRenderWidgetHost()) | 1476 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE); |
1468 ->delegate() | |
1469 ->GetTextInputState() | |
1470 ->type != ui::TEXT_INPUT_TYPE_NONE); | |
1471 // TODO(wjmaclean): can host_ ever be null? | 1477 // TODO(wjmaclean): can host_ ever be null? |
1472 if (host_) | 1478 if (host_) |
1473 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); | 1479 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false); |
1474 has_composition_text_ = false; | 1480 has_composition_text_ = false; |
1475 } | 1481 } |
1476 | 1482 |
1477 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1483 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
1478 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1484 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
1479 popup_child_host_view_->InsertChar(event); | 1485 popup_child_host_view_->InsertChar(event); |
1480 return; | 1486 return; |
1481 } | 1487 } |
1482 | 1488 |
1483 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1489 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
1484 // TODO(wjmaclean): can host_ ever be null? | 1490 // TODO(wjmaclean): can host_ ever be null? |
1485 if (host_ && | 1491 if (host_ && |
1486 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1492 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { |
1487 // Send a blink::WebInputEvent::Char event to |host_|. | 1493 // Send a blink::WebInputEvent::Char event to |host_|. |
1488 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1494 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
1489 } | 1495 } |
1490 } | 1496 } |
1491 | 1497 |
1492 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1498 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
1493 if (host_->delegate()) | 1499 return text_input_type_; |
1494 return host_->delegate()->GetTextInputState()->type; | |
1495 return text_input_state()->type; | |
1496 } | 1500 } |
1497 | 1501 |
1498 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { | 1502 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const { |
1499 if (host_->delegate()) | 1503 return text_input_mode_; |
1500 return host_->delegate()->GetTextInputState()->mode; | |
1501 return text_input_state()->mode; | |
1502 } | 1504 } |
1503 | 1505 |
1504 int RenderWidgetHostViewAura::GetTextInputFlags() const { | 1506 int RenderWidgetHostViewAura::GetTextInputFlags() const { |
1505 if (host_->delegate()) | 1507 return text_input_flags_; |
1506 return host_->delegate()->GetTextInputState()->flags; | |
1507 return text_input_state()->flags; | |
1508 } | 1508 } |
1509 | 1509 |
1510 bool RenderWidgetHostViewAura::CanComposeInline() const { | 1510 bool RenderWidgetHostViewAura::CanComposeInline() const { |
1511 if (host_->delegate()) | 1511 return can_compose_inline_; |
1512 return host_->delegate()->GetTextInputState()->can_compose_inline; | |
1513 return text_input_state()->can_compose_inline; | |
1514 } | 1512 } |
1515 | 1513 |
1516 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( | 1514 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
1517 const gfx::Rect& rect) const { | 1515 const gfx::Rect& rect) const { |
1518 gfx::Point origin = rect.origin(); | 1516 gfx::Point origin = rect.origin(); |
1519 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | 1517 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
1520 | 1518 |
1521 aura::Window* root_window = window_->GetRootWindow(); | 1519 aura::Window* root_window = window_->GetRootWindow(); |
1522 if (!root_window) | 1520 if (!root_window) |
1523 return rect; | 1521 return rect; |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", | 2321 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", |
2324 "new_origin", new_origin.ToString()); | 2322 "new_origin", new_origin.ToString()); |
2325 | 2323 |
2326 UpdateScreenInfo(window_); | 2324 UpdateScreenInfo(window_); |
2327 } | 2325 } |
2328 | 2326 |
2329 //////////////////////////////////////////////////////////////////////////////// | 2327 //////////////////////////////////////////////////////////////////////////////// |
2330 // RenderWidgetHostViewAura, private: | 2328 // RenderWidgetHostViewAura, private: |
2331 | 2329 |
2332 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2330 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
2333 // The WebContentsImpl should be notified about us so that it will not hold | |
2334 // an invalid text input state which was due to active text on this view. | |
2335 NotifyHostDelegateAboutShutdown(); | |
2336 | |
2337 // Ask the RWH to drop reference to us. | 2331 // Ask the RWH to drop reference to us. |
2338 if (!is_guest_view_hack_) | 2332 if (!is_guest_view_hack_) |
2339 host_->ViewDestroyed(); | 2333 host_->ViewDestroyed(); |
2340 | 2334 |
2341 selection_controller_.reset(); | 2335 selection_controller_.reset(); |
2342 selection_controller_client_.reset(); | 2336 selection_controller_client_.reset(); |
2343 | 2337 |
2344 delegated_frame_host_.reset(); | 2338 delegated_frame_host_.reset(); |
2345 window_observer_.reset(); | 2339 window_observer_.reset(); |
2346 if (window_) { | 2340 if (window_) { |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2933 | 2927 |
2934 //////////////////////////////////////////////////////////////////////////////// | 2928 //////////////////////////////////////////////////////////////////////////////// |
2935 // RenderWidgetHostViewBase, public: | 2929 // RenderWidgetHostViewBase, public: |
2936 | 2930 |
2937 // static | 2931 // static |
2938 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2932 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2939 GetScreenInfoForWindow(results, NULL); | 2933 GetScreenInfoForWindow(results, NULL); |
2940 } | 2934 } |
2941 | 2935 |
2942 } // namespace content | 2936 } // namespace content |
OLD | NEW |