Chromium Code Reviews| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 #include "ui/aura/env.h" | 54 #include "ui/aura/env.h" |
| 55 #include "ui/aura/window.h" | 55 #include "ui/aura/window.h" |
| 56 #include "ui/aura/window_event_dispatcher.h" | 56 #include "ui/aura/window_event_dispatcher.h" |
| 57 #include "ui/aura/window_observer.h" | 57 #include "ui/aura/window_observer.h" |
| 58 #include "ui/aura/window_tracker.h" | 58 #include "ui/aura/window_tracker.h" |
| 59 #include "ui/aura/window_tree_host.h" | 59 #include "ui/aura/window_tree_host.h" |
| 60 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 60 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 61 #include "ui/base/hit_test.h" | 61 #include "ui/base/hit_test.h" |
| 62 #include "ui/base/ime/input_method.h" | 62 #include "ui/base/ime/input_method.h" |
| 63 #include "ui/base/ui_base_types.h" | 63 #include "ui/base/ui_base_types.h" |
| 64 #include "ui/compositor/compositor_vsync_manager.h" | |
| 65 #include "ui/compositor/dip_util.h" | 64 #include "ui/compositor/dip_util.h" |
| 66 #include "ui/events/event.h" | 65 #include "ui/events/event.h" |
| 67 #include "ui/events/event_utils.h" | 66 #include "ui/events/event_utils.h" |
| 68 #include "ui/events/gestures/gesture_recognizer.h" | 67 #include "ui/events/gestures/gesture_recognizer.h" |
| 69 #include "ui/gfx/canvas.h" | 68 #include "ui/gfx/canvas.h" |
| 70 #include "ui/gfx/display.h" | 69 #include "ui/gfx/display.h" |
| 71 #include "ui/gfx/rect_conversions.h" | 70 #include "ui/gfx/rect_conversions.h" |
| 72 #include "ui/gfx/screen.h" | 71 #include "ui/gfx/screen.h" |
| 73 #include "ui/gfx/size_conversions.h" | 72 #include "ui/gfx/size_conversions.h" |
| 74 #include "ui/gfx/skia_util.h" | 73 #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), | 444 last_swapped_software_frame_scale_factor_(1.f), |
| 446 paint_canvas_(NULL), | 445 paint_canvas_(NULL), |
| 447 synthetic_move_sent_(false), | 446 synthetic_move_sent_(false), |
| 448 cursor_visibility_state_in_renderer_(UNKNOWN), | 447 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 449 #if defined(OS_WIN) | 448 #if defined(OS_WIN) |
| 450 legacy_render_widget_host_HWND_(NULL), | 449 legacy_render_widget_host_HWND_(NULL), |
| 451 legacy_window_destroyed_(false), | 450 legacy_window_destroyed_(false), |
| 452 #endif | 451 #endif |
| 453 has_snapped_to_boundary_(false), | 452 has_snapped_to_boundary_(false), |
| 454 touch_editing_client_(NULL), | 453 touch_editing_client_(NULL), |
| 454 needs_begin_frame_(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 = CommandLine::ForCurrentProcess()-> | 465 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
| 466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
| 467 SetOverscrollControllerEnabled(overscroll_enabled); | 467 SetOverscrollControllerEnabled(overscroll_enabled); |
| 468 } | 468 } |
| 469 | 469 |
| 470 //////////////////////////////////////////////////////////////////////////////// | 470 //////////////////////////////////////////////////////////////////////////////// |
| 471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
| 472 | 472 |
| 473 bool RenderWidgetHostViewAura::OnMessageReceived(const IPC::Message& msg) { | |
| 474 bool handled = true; | |
| 475 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, msg) | |
| 476 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrame, OnSetNeedsBeginFrame) | |
| 477 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 478 IPC_END_MESSAGE_MAP() | |
| 479 return handled; | |
| 480 } | |
| 481 | |
| 473 void RenderWidgetHostViewAura::InitAsChild( | 482 void RenderWidgetHostViewAura::InitAsChild( |
| 474 gfx::NativeView parent_view) { | 483 gfx::NativeView parent_view) { |
| 475 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 484 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 476 window_->Init(aura::WINDOW_LAYER_TEXTURED); | 485 window_->Init(aura::WINDOW_LAYER_TEXTURED); |
| 477 window_->SetName("RenderWidgetHostViewAura"); | 486 window_->SetName("RenderWidgetHostViewAura"); |
| 478 } | 487 } |
| 479 | 488 |
| 480 void RenderWidgetHostViewAura::InitAsPopup( | 489 void RenderWidgetHostViewAura::InitAsPopup( |
| 481 RenderWidgetHostView* parent_host_view, | 490 RenderWidgetHostView* parent_host_view, |
| 482 const gfx::Rect& bounds_in_screen) { | 491 const gfx::Rect& bounds_in_screen) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 | 572 |
| 564 aura::Window* root = window_->GetRootWindow(); | 573 aura::Window* root = window_->GetRootWindow(); |
| 565 if (root) { | 574 if (root) { |
| 566 aura::client::CursorClient* cursor_client = | 575 aura::client::CursorClient* cursor_client = |
| 567 aura::client::GetCursorClient(root); | 576 aura::client::GetCursorClient(root); |
| 568 if (cursor_client) | 577 if (cursor_client) |
| 569 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); | 578 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
| 570 } | 579 } |
| 571 | 580 |
| 572 delegated_frame_host_->WasShown(); | 581 delegated_frame_host_->WasShown(); |
| 582 GetCompositor()->begin_frame_manager()->AddObserver(this); | |
| 583 RequestBeginFrame(); | |
| 573 | 584 |
| 574 #if defined(OS_WIN) | 585 #if defined(OS_WIN) |
| 575 if (legacy_render_widget_host_HWND_) { | 586 if (legacy_render_widget_host_HWND_) { |
| 576 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent | 587 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent |
| 577 // window before reparenting any plugins. This ensures that the plugin | 588 // window before reparenting any plugins. This ensures that the plugin |
| 578 // windows stay on top of the child Zorder in the parent and receive | 589 // windows stay on top of the child Zorder in the parent and receive |
| 579 // mouse events, etc. | 590 // mouse events, etc. |
| 580 legacy_render_widget_host_HWND_->UpdateParent( | 591 legacy_render_widget_host_HWND_->UpdateParent( |
| 581 GetNativeView()->GetHost()->GetAcceleratedWidget()); | 592 GetNativeView()->GetHost()->GetAcceleratedWidget()); |
| 582 legacy_render_widget_host_HWND_->SetBounds( | 593 legacy_render_widget_host_HWND_->SetBounds( |
| 583 window_->GetBoundsInRootWindow()); | 594 window_->GetBoundsInRootWindow()); |
| 584 } | 595 } |
| 585 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 596 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
| 586 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); | 597 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam); |
| 587 #endif | 598 #endif |
| 588 } | 599 } |
| 589 | 600 |
| 590 void RenderWidgetHostViewAura::WasHidden() { | 601 void RenderWidgetHostViewAura::WasHidden() { |
| 591 if (!host_ || host_->is_hidden()) | 602 if (!host_ || host_->is_hidden()) |
| 592 return; | 603 return; |
| 593 host_->WasHidden(); | 604 host_->WasHidden(); |
| 594 delegated_frame_host_->WasHidden(); | 605 delegated_frame_host_->WasHidden(); |
| 606 if (GetCompositor()) | |
| 607 GetCompositor()->begin_frame_manager()->RemoveObserver(this); | |
| 595 | 608 |
| 596 #if defined(OS_WIN) | 609 #if defined(OS_WIN) |
| 597 constrained_rects_.clear(); | 610 constrained_rects_.clear(); |
| 598 aura::WindowTreeHost* host = window_->GetHost(); | 611 aura::WindowTreeHost* host = window_->GetHost(); |
| 599 if (host) { | 612 if (host) { |
| 600 HWND parent = host->GetAcceleratedWidget(); | 613 HWND parent = host->GetAcceleratedWidget(); |
| 601 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 614 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
| 602 EnumChildWindows(parent, HideWindowsCallback, lparam); | 615 EnumChildWindows(parent, HideWindowsCallback, lparam); |
| 603 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global | 616 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global |
| 604 // hidden window on the same lines as Windowed plugin windows. | 617 // hidden window on the same lines as Windowed plugin windows. |
| (...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2112 | 2125 |
| 2113 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, | 2126 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, |
| 2114 const gfx::Point& new_origin) { | 2127 const gfx::Point& new_origin) { |
| 2115 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", | 2128 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved", |
| 2116 "new_origin", new_origin.ToString()); | 2129 "new_origin", new_origin.ToString()); |
| 2117 | 2130 |
| 2118 UpdateScreenInfo(window_); | 2131 UpdateScreenInfo(window_); |
| 2119 } | 2132 } |
| 2120 | 2133 |
| 2121 //////////////////////////////////////////////////////////////////////////////// | 2134 //////////////////////////////////////////////////////////////////////////////// |
| 2135 // ui::BeginFrameManager::Observer implementation: | |
| 2136 void RenderWidgetHostViewAura::OnSendBeginFrame( | |
| 2137 const cc::BeginFrameArgs& args) { | |
| 2138 TRACE_EVENT0("cc", "RenderWidgetHostViewAura::OnSendBeginFrame"); | |
| 2139 if (!host_) | |
| 2140 return; | |
| 2141 | |
| 2142 // Flush input here? | |
| 2143 | |
| 2144 cc::BeginFrameArgs adjusted_args(args); | |
| 2145 | |
| 2146 delegated_frame_host_->UpdateVSyncParameters(adjusted_args); | |
| 2147 | |
| 2148 // TODO(brianderson): Use adaptive draw-time estimation. | |
| 2149 base::TimeDelta estimated_browser_composite_time = | |
| 2150 base::TimeDelta::FromMicroseconds( | |
| 2151 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); | |
| 2152 | |
| 2153 adjusted_args.deadline -= estimated_browser_composite_time; | |
| 2154 | |
| 2155 host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), adjusted_args)); | |
| 2156 | |
| 2157 if (needs_begin_frame_) { | |
| 2158 base::MessageLoop::current()->PostTask( | |
| 2159 FROM_HERE, | |
| 2160 base::Bind(&RenderWidgetHostViewAura::RequestBeginFrame, | |
| 2161 weak_ptr_factory_.GetWeakPtr())); | |
| 2162 } | |
| 2163 } | |
| 2164 | |
| 2165 //////////////////////////////////////////////////////////////////////////////// | |
| 2122 // RenderWidgetHostViewAura, private: | 2166 // RenderWidgetHostViewAura, private: |
| 2123 | 2167 |
| 2124 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2168 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| 2125 if (touch_editing_client_) | 2169 if (touch_editing_client_) |
| 2126 touch_editing_client_->OnViewDestroyed(); | 2170 touch_editing_client_->OnViewDestroyed(); |
| 2127 | 2171 |
| 2128 delegated_frame_host_.reset(); | 2172 delegated_frame_host_.reset(); |
| 2129 window_observer_.reset(); | 2173 window_observer_.reset(); |
| 2130 if (window_->GetHost()) | 2174 if (window_->GetHost()) |
| 2131 window_->GetHost()->RemoveObserver(this); | 2175 window_->GetHost()->RemoveObserver(this); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2274 snapped = window_->GetRootWindow(); | 2318 snapped = window_->GetRootWindow(); |
| 2275 } else { | 2319 } else { |
| 2276 snapped = window_->GetToplevelWindow(); | 2320 snapped = window_->GetToplevelWindow(); |
| 2277 } | 2321 } |
| 2278 if (snapped && snapped != window_) | 2322 if (snapped && snapped != window_) |
| 2279 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); | 2323 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); |
| 2280 | 2324 |
| 2281 has_snapped_to_boundary_ = true; | 2325 has_snapped_to_boundary_ = true; |
| 2282 } | 2326 } |
| 2283 | 2327 |
| 2328 void RenderWidgetHostViewAura::RequestBeginFrame() const { | |
| 2329 DCHECK(GetCompositor()); | |
| 2330 GetCompositor()->begin_frame_manager()->RequestBeginFrame(); | |
| 2331 } | |
| 2332 | |
| 2284 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { | 2333 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
| 2285 if (HasDisplayPropertyChanged(window_)) | 2334 if (HasDisplayPropertyChanged(window_)) |
| 2286 host_->InvalidateScreenInfo(); | 2335 host_->InvalidateScreenInfo(); |
| 2287 | 2336 |
| 2288 SnapToPhysicalPixelBoundary(); | 2337 SnapToPhysicalPixelBoundary(); |
| 2289 // Don't recursively call SetBounds if this bounds update is the result of | 2338 // Don't recursively call SetBounds if this bounds update is the result of |
| 2290 // a Window::SetBoundsInternal call. | 2339 // a Window::SetBoundsInternal call. |
| 2291 if (!in_bounds_changed_) | 2340 if (!in_bounds_changed_) |
| 2292 window_->SetBounds(rect); | 2341 window_->SetBounds(rect); |
| 2293 host_->WasResized(); | 2342 host_->WasResized(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2432 } | 2481 } |
| 2433 #endif | 2482 #endif |
| 2434 | 2483 |
| 2435 host_->ForwardKeyboardEvent(event); | 2484 host_->ForwardKeyboardEvent(event); |
| 2436 } | 2485 } |
| 2437 | 2486 |
| 2438 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { | 2487 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { |
| 2439 return kN32_SkColorType; | 2488 return kN32_SkColorType; |
| 2440 } | 2489 } |
| 2441 | 2490 |
| 2491 void RenderWidgetHostViewAura::OnSetNeedsBeginFrame(bool enabled) { | |
| 2492 if (needs_begin_frame_ == enabled) | |
| 2493 return; | |
|
brianderson
2014/08/21 00:14:00
I think it would be better for the RWHV to add or
simonhong
2014/08/26 08:24:48
It's much much better than now!
Thanks :)
| |
| 2494 | |
| 2495 TRACE_EVENT1("cc", "RenderWidgetHostViewAura::OnSetNeedsBeginFrame", | |
| 2496 "enabled", enabled); | |
| 2497 if(GetCompositor() && enabled) | |
| 2498 RequestBeginFrame(); | |
| 2499 | |
| 2500 needs_begin_frame_ = enabled; | |
| 2501 } | |
| 2502 | |
| 2442 //////////////////////////////////////////////////////////////////////////////// | 2503 //////////////////////////////////////////////////////////////////////////////// |
| 2443 // DelegatedFrameHost, public: | 2504 // DelegatedFrameHost, public: |
| 2444 | 2505 |
| 2445 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { | 2506 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const { |
| 2446 aura::WindowTreeHost* host = window_->GetHost(); | 2507 aura::WindowTreeHost* host = window_->GetHost(); |
| 2447 return host ? host->compositor() : NULL; | 2508 return host ? host->compositor() : NULL; |
| 2448 } | 2509 } |
| 2449 | 2510 |
| 2450 ui::Layer* RenderWidgetHostViewAura::GetLayer() { | 2511 ui::Layer* RenderWidgetHostViewAura::GetLayer() { |
| 2451 return window_->layer(); | 2512 return window_->layer(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2493 | 2554 |
| 2494 //////////////////////////////////////////////////////////////////////////////// | 2555 //////////////////////////////////////////////////////////////////////////////// |
| 2495 // RenderWidgetHostViewBase, public: | 2556 // RenderWidgetHostViewBase, public: |
| 2496 | 2557 |
| 2497 // static | 2558 // static |
| 2498 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2559 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2499 GetScreenInfoForWindow(results, NULL); | 2560 GetScreenInfoForWindow(results, NULL); |
| 2500 } | 2561 } |
| 2501 | 2562 |
| 2502 } // namespace content | 2563 } // namespace content |
| OLD | NEW |