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