| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "cc/layers/layer.h" | 16 #include "cc/layers/layer.h" |
| 17 #include "cc/output/copy_output_request.h" | 17 #include "cc/output/copy_output_request.h" |
| 18 #include "cc/output/copy_output_result.h" | 18 #include "cc/output/copy_output_result.h" |
| 19 #include "cc/resources/texture_mailbox.h" | 19 #include "cc/resources/texture_mailbox.h" |
| 20 #include "cc/trees/layer_tree_settings.h" | |
| 21 #include "content/browser/accessibility/browser_accessibility_manager.h" | 20 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 22 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 21 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 23 #include "content/browser/frame_host/frame_tree.h" | 22 #include "content/browser/frame_host/frame_tree.h" |
| 24 #include "content/browser/frame_host/frame_tree_node.h" | 23 #include "content/browser/frame_host/frame_tree_node.h" |
| 25 #include "content/browser/frame_host/render_frame_host_impl.h" | 24 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 26 #include "content/browser/gpu/compositor_util.h" | 25 #include "content/browser/gpu/compositor_util.h" |
| 27 #include "content/browser/renderer_host/compositor_resize_lock_aura.h" | 26 #include "content/browser/renderer_host/compositor_resize_lock_aura.h" |
| 28 #include "content/browser/renderer_host/dip_util.h" | 27 #include "content/browser/renderer_host/dip_util.h" |
| 29 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" | 28 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" |
| 30 #include "content/browser/renderer_host/overscroll_controller.h" | 29 #include "content/browser/renderer_host/overscroll_controller.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 54 #include "ui/aura/env.h" | 53 #include "ui/aura/env.h" |
| 55 #include "ui/aura/window.h" | 54 #include "ui/aura/window.h" |
| 56 #include "ui/aura/window_event_dispatcher.h" | 55 #include "ui/aura/window_event_dispatcher.h" |
| 57 #include "ui/aura/window_observer.h" | 56 #include "ui/aura/window_observer.h" |
| 58 #include "ui/aura/window_tracker.h" | 57 #include "ui/aura/window_tracker.h" |
| 59 #include "ui/aura/window_tree_host.h" | 58 #include "ui/aura/window_tree_host.h" |
| 60 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 59 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 61 #include "ui/base/hit_test.h" | 60 #include "ui/base/hit_test.h" |
| 62 #include "ui/base/ime/input_method.h" | 61 #include "ui/base/ime/input_method.h" |
| 63 #include "ui/base/ui_base_types.h" | 62 #include "ui/base/ui_base_types.h" |
| 64 #include "ui/compositor/compositor_vsync_manager.h" | |
| 65 #include "ui/compositor/dip_util.h" | 63 #include "ui/compositor/dip_util.h" |
| 66 #include "ui/events/event.h" | 64 #include "ui/events/event.h" |
| 67 #include "ui/events/event_utils.h" | 65 #include "ui/events/event_utils.h" |
| 68 #include "ui/events/gestures/gesture_recognizer.h" | 66 #include "ui/events/gestures/gesture_recognizer.h" |
| 69 #include "ui/gfx/canvas.h" | 67 #include "ui/gfx/canvas.h" |
| 70 #include "ui/gfx/display.h" | 68 #include "ui/gfx/display.h" |
| 71 #include "ui/gfx/rect_conversions.h" | 69 #include "ui/gfx/rect_conversions.h" |
| 72 #include "ui/gfx/screen.h" | 70 #include "ui/gfx/screen.h" |
| 73 #include "ui/gfx/size_conversions.h" | 71 #include "ui/gfx/size_conversions.h" |
| 74 #include "ui/gfx/skia_util.h" | 72 #include "ui/gfx/skia_util.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 last_swapped_software_frame_scale_factor_(1.f), | 443 last_swapped_software_frame_scale_factor_(1.f), |
| 446 paint_canvas_(NULL), | 444 paint_canvas_(NULL), |
| 447 synthetic_move_sent_(false), | 445 synthetic_move_sent_(false), |
| 448 cursor_visibility_state_in_renderer_(UNKNOWN), | 446 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 449 #if defined(OS_WIN) | 447 #if defined(OS_WIN) |
| 450 legacy_render_widget_host_HWND_(NULL), | 448 legacy_render_widget_host_HWND_(NULL), |
| 451 legacy_window_destroyed_(false), | 449 legacy_window_destroyed_(false), |
| 452 #endif | 450 #endif |
| 453 has_snapped_to_boundary_(false), | 451 has_snapped_to_boundary_(false), |
| 454 touch_editing_client_(NULL), | 452 touch_editing_client_(NULL), |
| 453 needs_begin_frame_(false), |
| 454 begin_frame_scheduling_is_enabled_(false), |
| 455 weak_ptr_factory_(this) { | 455 weak_ptr_factory_(this) { |
| 456 host_->SetView(this); | 456 host_->SetView(this); |
| 457 window_observer_.reset(new WindowObserver(this)); | 457 window_observer_.reset(new WindowObserver(this)); |
| 458 aura::client::SetTooltipText(window_, &tooltip_); | 458 aura::client::SetTooltipText(window_, &tooltip_); |
| 459 aura::client::SetActivationDelegate(window_, this); | 459 aura::client::SetActivationDelegate(window_, this); |
| 460 aura::client::SetActivationChangeObserver(window_, this); | 460 aura::client::SetActivationChangeObserver(window_, this); |
| 461 aura::client::SetFocusChangeObserver(window_, this); | 461 aura::client::SetFocusChangeObserver(window_, this); |
| 462 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 462 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
| 463 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 463 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
| 464 | 464 |
| 465 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> | 465 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> |
| 466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
| 467 SetOverscrollControllerEnabled(overscroll_enabled); | 467 SetOverscrollControllerEnabled(overscroll_enabled); |
| 468 |
| 469 #if !defined(OS_CHROMEOS) |
| 470 begin_frame_scheduling_is_enabled_ = true; |
| 471 #endif |
| 468 } | 472 } |
| 469 | 473 |
| 470 //////////////////////////////////////////////////////////////////////////////// | 474 //////////////////////////////////////////////////////////////////////////////// |
| 471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 475 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
| 472 | 476 |
| 477 bool RenderWidgetHostViewAura::OnMessageReceived(const IPC::Message& msg) { |
| 478 bool handled = true; |
| 479 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, msg) |
| 480 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrame, OnSetNeedsBeginFrame) |
| 481 IPC_MESSAGE_UNHANDLED(handled = false) |
| 482 IPC_END_MESSAGE_MAP() |
| 483 return handled; |
| 484 } |
| 485 |
| 473 void RenderWidgetHostViewAura::InitAsChild( | 486 void RenderWidgetHostViewAura::InitAsChild( |
| 474 gfx::NativeView parent_view) { | 487 gfx::NativeView parent_view) { |
| 475 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 488 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 476 window_->Init(aura::WINDOW_LAYER_TEXTURED); | 489 window_->Init(aura::WINDOW_LAYER_TEXTURED); |
| 477 window_->SetName("RenderWidgetHostViewAura"); | 490 window_->SetName("RenderWidgetHostViewAura"); |
| 478 } | 491 } |
| 479 | 492 |
| 480 void RenderWidgetHostViewAura::InitAsPopup( | 493 void RenderWidgetHostViewAura::InitAsPopup( |
| 481 RenderWidgetHostView* parent_host_view, | 494 RenderWidgetHostView* parent_host_view, |
| 482 const gfx::Rect& bounds_in_screen) { | 495 const gfx::Rect& bounds_in_screen) { |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, | 878 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, |
| 866 int error_code) { | 879 int error_code) { |
| 867 UpdateCursorIfOverSelf(); | 880 UpdateCursorIfOverSelf(); |
| 868 Destroy(); | 881 Destroy(); |
| 869 } | 882 } |
| 870 | 883 |
| 871 void RenderWidgetHostViewAura::Destroy() { | 884 void RenderWidgetHostViewAura::Destroy() { |
| 872 // Beware, this function is not called on all destruction paths. It will | 885 // Beware, this function is not called on all destruction paths. It will |
| 873 // implicitly end up calling ~RenderWidgetHostViewAura though, so all | 886 // implicitly end up calling ~RenderWidgetHostViewAura though, so all |
| 874 // destruction/cleanup code should happen there, not here. | 887 // destruction/cleanup code should happen there, not here. |
| 888 |
| 889 // Remove observation from Compositor in here because we can't access |
| 890 // to compositor in destructor. |
| 891 if (needs_begin_frame_ && GetCompositor()) { |
| 892 GetCompositor()->RemoveBeginFrameObserver(this); |
| 893 needs_begin_frame_ = false; |
| 894 } |
| 895 |
| 875 in_shutdown_ = true; | 896 in_shutdown_ = true; |
| 876 delete window_; | 897 delete window_; |
| 877 } | 898 } |
| 878 | 899 |
| 879 void RenderWidgetHostViewAura::SetTooltipText( | 900 void RenderWidgetHostViewAura::SetTooltipText( |
| 880 const base::string16& tooltip_text) { | 901 const base::string16& tooltip_text) { |
| 881 tooltip_ = tooltip_text; | 902 tooltip_ = tooltip_text; |
| 882 aura::Window* root_window = window_->GetRootWindow(); | 903 aura::Window* root_window = window_->GetRootWindow(); |
| 883 aura::client::TooltipClient* tooltip_client = | 904 aura::client::TooltipClient* tooltip_client = |
| 884 aura::client::GetTooltipClient(root_window); | 905 aura::client::GetTooltipClient(root_window); |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2120 | 2141 |
| 2121 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, | 2142 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, |
| 2122 const gfx::Point& new_origin) { | 2143 const gfx::Point& new_origin) { |
| 2123 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", | 2144 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", |
| 2124 "new_origin", new_origin.ToString()); | 2145 "new_origin", new_origin.ToString()); |
| 2125 | 2146 |
| 2126 UpdateScreenInfo(window_); | 2147 UpdateScreenInfo(window_); |
| 2127 } | 2148 } |
| 2128 | 2149 |
| 2129 //////////////////////////////////////////////////////////////////////////////// | 2150 //////////////////////////////////////////////////////////////////////////////// |
| 2151 // ui::CompositorBeginFrameObserver implementation: |
| 2152 void RenderWidgetHostViewAura::OnSendBeginFrame( |
| 2153 const cc::BeginFrameArgs& args) { |
| 2154 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2155 DCHECK(host_); |
| 2156 TRACE_EVENT0("cc", "RenderWidgetHostViewAura::OnSendBeginFrame"); |
| 2157 |
| 2158 delegated_frame_host_->UpdateVSyncParameters(args); |
| 2159 |
| 2160 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); |
| 2161 |
| 2162 last_begin_frame_args_ = args; |
| 2163 } |
| 2164 |
| 2165 //////////////////////////////////////////////////////////////////////////////// |
| 2130 // RenderWidgetHostViewAura, private: | 2166 // RenderWidgetHostViewAura, private: |
| 2131 | 2167 |
| 2132 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2168 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| 2169 // When we are using unified BeginFrame(--enable-begin-frame-scheduling), |
| 2170 // |needs_begin_frame_| always be false in here. We can't remove |
| 2171 // observation from Compositor in this function because |window_| is already |
| 2172 // removed from window tree host. |
| 2173 DCHECK(!needs_begin_frame_); |
| 2174 |
| 2133 if (touch_editing_client_) | 2175 if (touch_editing_client_) |
| 2134 touch_editing_client_->OnViewDestroyed(); | 2176 touch_editing_client_->OnViewDestroyed(); |
| 2135 | 2177 |
| 2136 delegated_frame_host_.reset(); | 2178 delegated_frame_host_.reset(); |
| 2137 window_observer_.reset(); | 2179 window_observer_.reset(); |
| 2138 if (window_->GetHost()) | 2180 if (window_->GetHost()) |
| 2139 window_->GetHost()->RemoveObserver(this); | 2181 window_->GetHost()->RemoveObserver(this); |
| 2140 UnlockMouse(); | 2182 UnlockMouse(); |
| 2141 if (popup_parent_host_view_) { | 2183 if (popup_parent_host_view_) { |
| 2142 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 2184 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 | 2429 |
| 2388 #if defined(OS_WIN) | 2430 #if defined(OS_WIN) |
| 2389 // The parent may have changed here. Ensure that the legacy window is | 2431 // The parent may have changed here. Ensure that the legacy window is |
| 2390 // reparented accordingly. | 2432 // reparented accordingly. |
| 2391 if (legacy_render_widget_host_HWND_) | 2433 if (legacy_render_widget_host_HWND_) |
| 2392 legacy_render_widget_host_HWND_->UpdateParent( | 2434 legacy_render_widget_host_HWND_->UpdateParent( |
| 2393 reinterpret_cast<HWND>(GetNativeViewId())); | 2435 reinterpret_cast<HWND>(GetNativeViewId())); |
| 2394 #endif | 2436 #endif |
| 2395 | 2437 |
| 2396 delegated_frame_host_->AddedToWindow(); | 2438 delegated_frame_host_->AddedToWindow(); |
| 2439 |
| 2440 // When this RWHV is added to new root window, this RWHV should be added to |
| 2441 // the new compositor. |
| 2442 if (needs_begin_frame_) { |
| 2443 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2444 GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_); |
| 2445 } |
| 2397 } | 2446 } |
| 2398 | 2447 |
| 2399 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 2448 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
| 2400 aura::client::CursorClient* cursor_client = | 2449 aura::client::CursorClient* cursor_client = |
| 2401 aura::client::GetCursorClient(window_->GetRootWindow()); | 2450 aura::client::GetCursorClient(window_->GetRootWindow()); |
| 2402 if (cursor_client) | 2451 if (cursor_client) |
| 2403 cursor_client->RemoveObserver(this); | 2452 cursor_client->RemoveObserver(this); |
| 2404 | 2453 |
| 2405 DetachFromInputMethod(); | 2454 DetachFromInputMethod(); |
| 2406 | 2455 |
| 2407 window_->GetHost()->RemoveObserver(this); | 2456 window_->GetHost()->RemoveObserver(this); |
| 2408 delegated_frame_host_->RemovingFromWindow(); | 2457 delegated_frame_host_->RemovingFromWindow(); |
| 2409 | 2458 |
| 2410 #if defined(OS_WIN) | 2459 #if defined(OS_WIN) |
| 2411 // Update the legacy window's parent temporarily to the desktop window. It | 2460 // Update the legacy window's parent temporarily to the desktop window. It |
| 2412 // will eventually get reparented to the right root. | 2461 // will eventually get reparented to the right root. |
| 2413 if (legacy_render_widget_host_HWND_) | 2462 if (legacy_render_widget_host_HWND_) |
| 2414 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); | 2463 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); |
| 2415 #endif | 2464 #endif |
| 2465 |
| 2466 // When this RWHV is removed from current root window, this RWHV should be |
| 2467 // removed from the current compositor which will be removed. |
| 2468 if (needs_begin_frame_) { |
| 2469 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2470 GetCompositor()->RemoveBeginFrameObserver(this); |
| 2471 } |
| 2416 } | 2472 } |
| 2417 | 2473 |
| 2418 void RenderWidgetHostViewAura::DetachFromInputMethod() { | 2474 void RenderWidgetHostViewAura::DetachFromInputMethod() { |
| 2419 ui::InputMethod* input_method = GetInputMethod(); | 2475 ui::InputMethod* input_method = GetInputMethod(); |
| 2420 if (input_method && input_method->GetTextInputClient() == this) | 2476 if (input_method && input_method->GetTextInputClient() == this) |
| 2421 input_method->SetFocusedTextInputClient(NULL); | 2477 input_method->SetFocusedTextInputClient(NULL); |
| 2422 } | 2478 } |
| 2423 | 2479 |
| 2424 void RenderWidgetHostViewAura::ForwardKeyboardEvent( | 2480 void RenderWidgetHostViewAura::ForwardKeyboardEvent( |
| 2425 const NativeWebKeyboardEvent& event) { | 2481 const NativeWebKeyboardEvent& event) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2447 } | 2503 } |
| 2448 #endif | 2504 #endif |
| 2449 | 2505 |
| 2450 host_->ForwardKeyboardEvent(event); | 2506 host_->ForwardKeyboardEvent(event); |
| 2451 } | 2507 } |
| 2452 | 2508 |
| 2453 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { | 2509 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { |
| 2454 return kN32_SkColorType; | 2510 return kN32_SkColorType; |
| 2455 } | 2511 } |
| 2456 | 2512 |
| 2513 void RenderWidgetHostViewAura::OnSetNeedsBeginFrame(bool enabled) { |
| 2514 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2515 DCHECK(GetCompositor()); |
| 2516 |
| 2517 if (needs_begin_frame_ == enabled) |
| 2518 return; |
| 2519 |
| 2520 TRACE_EVENT1("cc", |
| 2521 "RenderWidgetHostViewAura::OnSetNeedsBeginFrame", |
| 2522 "enabled", |
| 2523 enabled); |
| 2524 if (enabled) |
| 2525 GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_); |
| 2526 else |
| 2527 GetCompositor()->RemoveBeginFrameObserver(this); |
| 2528 |
| 2529 needs_begin_frame_ = enabled; |
| 2530 } |
| 2531 |
| 2457 //////////////////////////////////////////////////////////////////////////////// | 2532 //////////////////////////////////////////////////////////////////////////////// |
| 2458 // DelegatedFrameHost, public: | 2533 // DelegatedFrameHost, public: |
| 2459 | 2534 |
| 2460 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { | 2535 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { |
| 2461 aura::WindowTreeHost* host = window_->GetHost(); | 2536 aura::WindowTreeHost* host = window_->GetHost(); |
| 2462 return host ? host->compositor() : NULL; | 2537 return host ? host->compositor() : NULL; |
| 2463 } | 2538 } |
| 2464 | 2539 |
| 2465 ui::Layer* RenderWidgetHostViewAura::GetLayer() { | 2540 ui::Layer* RenderWidgetHostViewAura::GetLayer() { |
| 2466 return window_->layer(); | 2541 return window_->layer(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2503 | 2578 |
| 2504 //////////////////////////////////////////////////////////////////////////////// | 2579 //////////////////////////////////////////////////////////////////////////////// |
| 2505 // RenderWidgetHostViewBase, public: | 2580 // RenderWidgetHostViewBase, public: |
| 2506 | 2581 |
| 2507 // static | 2582 // static |
| 2508 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2583 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2509 GetScreenInfoForWindow(results, NULL); | 2584 GetScreenInfoForWindow(results, NULL); |
| 2510 } | 2585 } |
| 2511 | 2586 |
| 2512 } // namespace content | 2587 } // namespace content |
| OLD | NEW |