| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, | 880 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status, |
| 868 int error_code) { | 881 int error_code) { |
| 869 UpdateCursorIfOverSelf(); | 882 UpdateCursorIfOverSelf(); |
| 870 Destroy(); | 883 Destroy(); |
| 871 } | 884 } |
| 872 | 885 |
| 873 void RenderWidgetHostViewAura::Destroy() { | 886 void RenderWidgetHostViewAura::Destroy() { |
| 874 // Beware, this function is not called on all destruction paths. It will | 887 // Beware, this function is not called on all destruction paths. It will |
| 875 // implicitly end up calling ~RenderWidgetHostViewAura though, so all | 888 // implicitly end up calling ~RenderWidgetHostViewAura though, so all |
| 876 // destruction/cleanup code should happen there, not here. | 889 // destruction/cleanup code should happen there, not here. |
| 890 |
| 891 // Remove observation from Compositor in here because we can't access |
| 892 // to compositor in destructor. |
| 893 if (needs_begin_frame_ && GetCompositor()) { |
| 894 GetCompositor()->RemoveBeginFrameObserver(this); |
| 895 needs_begin_frame_ = false; |
| 896 } |
| 897 |
| 877 in_shutdown_ = true; | 898 in_shutdown_ = true; |
| 878 delete window_; | 899 delete window_; |
| 879 } | 900 } |
| 880 | 901 |
| 881 void RenderWidgetHostViewAura::SetTooltipText( | 902 void RenderWidgetHostViewAura::SetTooltipText( |
| 882 const base::string16& tooltip_text) { | 903 const base::string16& tooltip_text) { |
| 883 tooltip_ = tooltip_text; | 904 tooltip_ = tooltip_text; |
| 884 aura::Window* root_window = window_->GetRootWindow(); | 905 aura::Window* root_window = window_->GetRootWindow(); |
| 885 aura::client::TooltipClient* tooltip_client = | 906 aura::client::TooltipClient* tooltip_client = |
| 886 aura::client::GetTooltipClient(root_window); | 907 aura::client::GetTooltipClient(root_window); |
| (...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2118 | 2139 |
| 2119 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, | 2140 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, |
| 2120 const gfx::Point& new_origin) { | 2141 const gfx::Point& new_origin) { |
| 2121 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", | 2142 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", |
| 2122 "new_origin", new_origin.ToString()); | 2143 "new_origin", new_origin.ToString()); |
| 2123 | 2144 |
| 2124 UpdateScreenInfo(window_); | 2145 UpdateScreenInfo(window_); |
| 2125 } | 2146 } |
| 2126 | 2147 |
| 2127 //////////////////////////////////////////////////////////////////////////////// | 2148 //////////////////////////////////////////////////////////////////////////////// |
| 2149 // ui::CompositorBeginFrameObserver implementation: |
| 2150 void RenderWidgetHostViewAura::OnSendBeginFrame( |
| 2151 const cc::BeginFrameArgs& args) { |
| 2152 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2153 DCHECK(host_); |
| 2154 TRACE_EVENT0("cc", "RenderWidgetHostViewAura::OnSendBeginFrame"); |
| 2155 |
| 2156 delegated_frame_host_->UpdateVSyncParameters(args); |
| 2157 |
| 2158 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); |
| 2159 |
| 2160 last_begin_frame_args_ = args; |
| 2161 } |
| 2162 |
| 2163 //////////////////////////////////////////////////////////////////////////////// |
| 2128 // RenderWidgetHostViewAura, private: | 2164 // RenderWidgetHostViewAura, private: |
| 2129 | 2165 |
| 2130 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2166 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| 2167 // When we are using unified BeginFrame(--enable-begin-frame-scheduling), |
| 2168 // |needs_begin_frame_| always be false in here. We can't remove |
| 2169 // observation from Compositor in this function because |window_| is already |
| 2170 // removed from window tree host. |
| 2171 DCHECK(!needs_begin_frame_); |
| 2172 |
| 2131 if (touch_editing_client_) | 2173 if (touch_editing_client_) |
| 2132 touch_editing_client_->OnViewDestroyed(); | 2174 touch_editing_client_->OnViewDestroyed(); |
| 2133 | 2175 |
| 2134 delegated_frame_host_.reset(); | 2176 delegated_frame_host_.reset(); |
| 2135 window_observer_.reset(); | 2177 window_observer_.reset(); |
| 2136 if (window_->GetHost()) | 2178 if (window_->GetHost()) |
| 2137 window_->GetHost()->RemoveObserver(this); | 2179 window_->GetHost()->RemoveObserver(this); |
| 2138 UnlockMouse(); | 2180 UnlockMouse(); |
| 2139 if (popup_parent_host_view_) { | 2181 if (popup_parent_host_view_) { |
| 2140 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 2182 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 | 2420 |
| 2379 #if defined(OS_WIN) | 2421 #if defined(OS_WIN) |
| 2380 // The parent may have changed here. Ensure that the legacy window is | 2422 // The parent may have changed here. Ensure that the legacy window is |
| 2381 // reparented accordingly. | 2423 // reparented accordingly. |
| 2382 if (legacy_render_widget_host_HWND_) | 2424 if (legacy_render_widget_host_HWND_) |
| 2383 legacy_render_widget_host_HWND_->UpdateParent( | 2425 legacy_render_widget_host_HWND_->UpdateParent( |
| 2384 reinterpret_cast<HWND>(GetNativeViewId())); | 2426 reinterpret_cast<HWND>(GetNativeViewId())); |
| 2385 #endif | 2427 #endif |
| 2386 | 2428 |
| 2387 delegated_frame_host_->AddedToWindow(); | 2429 delegated_frame_host_->AddedToWindow(); |
| 2430 |
| 2431 // When this RWHV is added to new root window, this RWHV should be added to |
| 2432 // the new compositor. |
| 2433 if (needs_begin_frame_) { |
| 2434 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2435 GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_); |
| 2436 } |
| 2388 } | 2437 } |
| 2389 | 2438 |
| 2390 void RenderWidgetHostViewAura::RemovingFromRootWindow() { | 2439 void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
| 2391 aura::client::CursorClient* cursor_client = | 2440 aura::client::CursorClient* cursor_client = |
| 2392 aura::client::GetCursorClient(window_->GetRootWindow()); | 2441 aura::client::GetCursorClient(window_->GetRootWindow()); |
| 2393 if (cursor_client) | 2442 if (cursor_client) |
| 2394 cursor_client->RemoveObserver(this); | 2443 cursor_client->RemoveObserver(this); |
| 2395 | 2444 |
| 2396 DetachFromInputMethod(); | 2445 DetachFromInputMethod(); |
| 2397 | 2446 |
| 2398 window_->GetHost()->RemoveObserver(this); | 2447 window_->GetHost()->RemoveObserver(this); |
| 2399 delegated_frame_host_->RemovingFromWindow(); | 2448 delegated_frame_host_->RemovingFromWindow(); |
| 2400 | 2449 |
| 2401 #if defined(OS_WIN) | 2450 #if defined(OS_WIN) |
| 2402 // Update the legacy window's parent temporarily to the desktop window. It | 2451 // Update the legacy window's parent temporarily to the desktop window. It |
| 2403 // will eventually get reparented to the right root. | 2452 // will eventually get reparented to the right root. |
| 2404 if (legacy_render_widget_host_HWND_) | 2453 if (legacy_render_widget_host_HWND_) |
| 2405 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); | 2454 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow()); |
| 2406 #endif | 2455 #endif |
| 2456 |
| 2457 // When this RWHV is removed from current root window, this RWHV should be |
| 2458 // removed from the current compositor which will be removed. |
| 2459 if (needs_begin_frame_) { |
| 2460 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2461 GetCompositor()->RemoveBeginFrameObserver(this); |
| 2462 } |
| 2407 } | 2463 } |
| 2408 | 2464 |
| 2409 void RenderWidgetHostViewAura::DetachFromInputMethod() { | 2465 void RenderWidgetHostViewAura::DetachFromInputMethod() { |
| 2410 ui::InputMethod* input_method = GetInputMethod(); | 2466 ui::InputMethod* input_method = GetInputMethod(); |
| 2411 if (input_method && input_method->GetTextInputClient() == this) | 2467 if (input_method && input_method->GetTextInputClient() == this) |
| 2412 input_method->SetFocusedTextInputClient(NULL); | 2468 input_method->SetFocusedTextInputClient(NULL); |
| 2413 } | 2469 } |
| 2414 | 2470 |
| 2415 void RenderWidgetHostViewAura::ForwardKeyboardEvent( | 2471 void RenderWidgetHostViewAura::ForwardKeyboardEvent( |
| 2416 const NativeWebKeyboardEvent& event) { | 2472 const NativeWebKeyboardEvent& event) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2438 } | 2494 } |
| 2439 #endif | 2495 #endif |
| 2440 | 2496 |
| 2441 host_->ForwardKeyboardEvent(event); | 2497 host_->ForwardKeyboardEvent(event); |
| 2442 } | 2498 } |
| 2443 | 2499 |
| 2444 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { | 2500 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { |
| 2445 return kN32_SkColorType; | 2501 return kN32_SkColorType; |
| 2446 } | 2502 } |
| 2447 | 2503 |
| 2504 void RenderWidgetHostViewAura::OnSetNeedsBeginFrame(bool enabled) { |
| 2505 DCHECK(begin_frame_scheduling_is_enabled_); |
| 2506 DCHECK(GetCompositor()); |
| 2507 |
| 2508 if (needs_begin_frame_ == enabled) |
| 2509 return; |
| 2510 |
| 2511 TRACE_EVENT1("cc", |
| 2512 "RenderWidgetHostViewAura::OnSetNeedsBeginFrame", |
| 2513 "enabled", |
| 2514 enabled); |
| 2515 if (enabled) |
| 2516 GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_); |
| 2517 else |
| 2518 GetCompositor()->RemoveBeginFrameObserver(this); |
| 2519 |
| 2520 needs_begin_frame_ = enabled; |
| 2521 } |
| 2522 |
| 2448 //////////////////////////////////////////////////////////////////////////////// | 2523 //////////////////////////////////////////////////////////////////////////////// |
| 2449 // DelegatedFrameHost, public: | 2524 // DelegatedFrameHost, public: |
| 2450 | 2525 |
| 2451 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { | 2526 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { |
| 2452 aura::WindowTreeHost* host = window_->GetHost(); | 2527 aura::WindowTreeHost* host = window_->GetHost(); |
| 2453 return host ? host->compositor() : NULL; | 2528 return host ? host->compositor() : NULL; |
| 2454 } | 2529 } |
| 2455 | 2530 |
| 2456 ui::Layer* RenderWidgetHostViewAura::GetLayer() { | 2531 ui::Layer* RenderWidgetHostViewAura::GetLayer() { |
| 2457 return window_->layer(); | 2532 return window_->layer(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 | 2569 |
| 2495 //////////////////////////////////////////////////////////////////////////////// | 2570 //////////////////////////////////////////////////////////////////////////////// |
| 2496 // RenderWidgetHostViewBase, public: | 2571 // RenderWidgetHostViewBase, public: |
| 2497 | 2572 |
| 2498 // static | 2573 // static |
| 2499 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2574 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2500 GetScreenInfoForWindow(results, NULL); | 2575 GetScreenInfoForWindow(results, NULL); |
| 2501 } | 2576 } |
| 2502 | 2577 |
| 2503 } // namespace content | 2578 } // namespace content |
| OLD | NEW |