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 11 matching lines...) Expand all Loading... |
22 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 22 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
23 #include "content/browser/frame_host/frame_tree.h" | 23 #include "content/browser/frame_host/frame_tree.h" |
24 #include "content/browser/frame_host/frame_tree_node.h" | 24 #include "content/browser/frame_host/frame_tree_node.h" |
25 #include "content/browser/frame_host/render_frame_host_impl.h" | 25 #include "content/browser/frame_host/render_frame_host_impl.h" |
26 #include "content/browser/gpu/compositor_util.h" | 26 #include "content/browser/gpu/compositor_util.h" |
27 #include "content/browser/renderer_host/compositor_resize_lock_aura.h" | 27 #include "content/browser/renderer_host/compositor_resize_lock_aura.h" |
28 #include "content/browser/renderer_host/dip_util.h" | 28 #include "content/browser/renderer_host/dip_util.h" |
29 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" | 29 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" |
30 #include "content/browser/renderer_host/overscroll_controller.h" | 30 #include "content/browser/renderer_host/overscroll_controller.h" |
31 #include "content/browser/renderer_host/render_view_host_delegate.h" | 31 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 32 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
32 #include "content/browser/renderer_host/render_view_host_impl.h" | 33 #include "content/browser/renderer_host/render_view_host_impl.h" |
33 #include "content/browser/renderer_host/render_widget_host_impl.h" | 34 #include "content/browser/renderer_host/render_widget_host_impl.h" |
34 #include "content/browser/renderer_host/ui_events_helper.h" | 35 #include "content/browser/renderer_host/ui_events_helper.h" |
35 #include "content/browser/renderer_host/web_input_event_aura.h" | 36 #include "content/browser/renderer_host/web_input_event_aura.h" |
36 #include "content/common/gpu/client/gl_helper.h" | 37 #include "content/common/gpu/client/gl_helper.h" |
37 #include "content/common/gpu/gpu_messages.h" | 38 #include "content/common/gpu/gpu_messages.h" |
38 #include "content/common/view_messages.h" | 39 #include "content/common/view_messages.h" |
39 #include "content/public/browser/content_browser_client.h" | 40 #include "content/public/browser/content_browser_client.h" |
40 #include "content/public/browser/overscroll_configuration.h" | 41 #include "content/public/browser/overscroll_configuration.h" |
41 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 return legacy_render_widget_host_HWND_->window_accessible(); | 1225 return legacy_render_widget_host_HWND_->window_accessible(); |
1225 #endif | 1226 #endif |
1226 return NULL; | 1227 return NULL; |
1227 | 1228 |
1228 } | 1229 } |
1229 | 1230 |
1230 gfx::GLSurfaceHandle RenderWidgetHostViewAura::GetCompositingSurface() { | 1231 gfx::GLSurfaceHandle RenderWidgetHostViewAura::GetCompositingSurface() { |
1231 return ImageTransportFactory::GetInstance()->GetSharedSurfaceHandle(); | 1232 return ImageTransportFactory::GetInstance()->GetSharedSurfaceHandle(); |
1232 } | 1233 } |
1233 | 1234 |
| 1235 void RenderWidgetHostViewAura::ShowDisambiguationPopup( |
| 1236 const gfx::Rect& rect_pixels, |
| 1237 const SkBitmap& zoomed_bitmap) { |
| 1238 // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs |
| 1239 // by scaling it by the inverse of the device scale factor. |
| 1240 gfx::RectF screen_target_rect_f(rect_pixels); |
| 1241 screen_target_rect_f.Scale(1.0f / current_device_scale_factor_); |
| 1242 disambiguation_target_rect_ = gfx::ToEnclosingRect(screen_target_rect_f); |
| 1243 |
| 1244 float scale = static_cast<float>(zoomed_bitmap.width()) / |
| 1245 static_cast<float>(rect_pixels.width()); |
| 1246 gfx::Size zoomed_size(gfx::ToCeiledSize( |
| 1247 gfx::ScaleSize(disambiguation_target_rect_.size(), scale))); |
| 1248 |
| 1249 // Save of a copy of the |last_scroll_offset_| for comparison when the copy |
| 1250 // callback fires, to ensure that we haven't scrolled. |
| 1251 disambiguation_scroll_offset_ = last_scroll_offset_; |
| 1252 |
| 1253 CopyFromCompositingSurface( |
| 1254 disambiguation_target_rect_, |
| 1255 zoomed_size, |
| 1256 base::Bind(&RenderWidgetHostViewAura::DisambiguationPopupRendered, |
| 1257 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 1258 <RenderWidgetHostViewAura>(this)), |
| 1259 kN32_SkColorType); |
| 1260 } |
| 1261 |
| 1262 void RenderWidgetHostViewAura::DisambiguationPopupRendered( |
| 1263 bool success, |
| 1264 const SkBitmap& result) { |
| 1265 if (!success || disambiguation_scroll_offset_ != last_scroll_offset_) |
| 1266 return; |
| 1267 |
| 1268 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will |
| 1269 // actually show the delegate. |
| 1270 RenderViewHostDelegate* delegate = NULL; |
| 1271 if (host_->IsRenderView()) |
| 1272 delegate = RenderViewHost::From(host_)->GetDelegate(); |
| 1273 RenderViewHostDelegateView* delegate_view = NULL; |
| 1274 if (delegate) |
| 1275 delegate_view = delegate->GetDelegateView(); |
| 1276 if (delegate_view) { |
| 1277 delegate_view->ShowDisambiguationPopup( |
| 1278 disambiguation_target_rect_, |
| 1279 result, |
| 1280 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationGesture, |
| 1281 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 1282 <RenderWidgetHostViewAura>(this)), |
| 1283 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationMouse, |
| 1284 base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 1285 <RenderWidgetHostViewAura>(this))); |
| 1286 } |
| 1287 } |
| 1288 |
| 1289 void RenderWidgetHostViewAura::HideDisambiguationPopup() { |
| 1290 RenderViewHostDelegate* delegate = NULL; |
| 1291 if (host_->IsRenderView()) |
| 1292 delegate = RenderViewHost::From(host_)->GetDelegate(); |
| 1293 RenderViewHostDelegateView* delegate_view = NULL; |
| 1294 if (delegate) |
| 1295 delegate_view = delegate->GetDelegateView(); |
| 1296 if (delegate_view) |
| 1297 delegate_view->HideDisambiguationPopup(); |
| 1298 } |
| 1299 |
| 1300 void RenderWidgetHostViewAura::ProcessDisambiguationGesture( |
| 1301 ui::GestureEvent* event) { |
| 1302 blink::WebGestureEvent web_gesture = content::MakeWebGestureEvent(event); |
| 1303 // If we fail to make a WebGestureEvent that is a Tap from the provided event, |
| 1304 // don't forward it to Blink. |
| 1305 if (web_gesture.type < blink::WebInputEvent::Type::GestureTap || |
| 1306 web_gesture.type > blink::WebInputEvent::Type::GestureTapCancel) |
| 1307 return; |
| 1308 |
| 1309 host_->ForwardGestureEvent(web_gesture); |
| 1310 } |
| 1311 |
| 1312 void RenderWidgetHostViewAura::ProcessDisambiguationMouse( |
| 1313 ui::MouseEvent* event) { |
| 1314 blink::WebMouseEvent web_mouse = content::MakeWebMouseEvent(event); |
| 1315 host_->ForwardMouseEvent(web_mouse); |
| 1316 } |
| 1317 |
1234 bool RenderWidgetHostViewAura::LockMouse() { | 1318 bool RenderWidgetHostViewAura::LockMouse() { |
1235 aura::Window* root_window = window_->GetRootWindow(); | 1319 aura::Window* root_window = window_->GetRootWindow(); |
1236 if (!root_window) | 1320 if (!root_window) |
1237 return false; | 1321 return false; |
1238 | 1322 |
1239 if (mouse_locked_) | 1323 if (mouse_locked_) |
1240 return true; | 1324 return true; |
1241 | 1325 |
1242 mouse_locked_ = true; | 1326 mouse_locked_ = true; |
1243 #if !defined(OS_WIN) | 1327 #if !defined(OS_WIN) |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 // dismiss them. | 1924 // dismiss them. |
1841 aura::WindowTreeHost* host = window_->GetHost(); | 1925 aura::WindowTreeHost* host = window_->GetHost(); |
1842 if (host) { | 1926 if (host) { |
1843 HWND parent = host->GetAcceleratedWidget(); | 1927 HWND parent = host->GetAcceleratedWidget(); |
1844 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); | 1928 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); |
1845 EnumThreadWindows(GetCurrentThreadId(), | 1929 EnumThreadWindows(GetCurrentThreadId(), |
1846 DismissOwnedPopups, | 1930 DismissOwnedPopups, |
1847 reinterpret_cast<LPARAM>(toplevel_hwnd)); | 1931 reinterpret_cast<LPARAM>(toplevel_hwnd)); |
1848 } | 1932 } |
1849 #endif | 1933 #endif |
| 1934 // The Disambiguation popup does not parent itself from this window, so we |
| 1935 // manually dismiss it. |
| 1936 HideDisambiguationPopup(); |
| 1937 |
1850 blink::WebMouseWheelEvent mouse_wheel_event = | 1938 blink::WebMouseWheelEvent mouse_wheel_event = |
1851 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); | 1939 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); |
1852 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) | 1940 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) |
1853 host_->ForwardWheelEvent(mouse_wheel_event); | 1941 host_->ForwardWheelEvent(mouse_wheel_event); |
1854 } else if (CanRendererHandleEvent(event) && | 1942 } else if (CanRendererHandleEvent(event) && |
1855 !(event->flags() & ui::EF_FROM_TOUCH)) { | 1943 !(event->flags() & ui::EF_FROM_TOUCH)) { |
1856 blink::WebMouseEvent mouse_event = MakeWebMouseEvent(event); | 1944 blink::WebMouseEvent mouse_event = MakeWebMouseEvent(event); |
1857 ModifyEventMovementAndCoords(&mouse_event); | 1945 ModifyEventMovementAndCoords(&mouse_event); |
1858 host_->ForwardMouseEvent(mouse_event); | 1946 host_->ForwardMouseEvent(mouse_event); |
1859 // Ensure that we get keyboard focus on mouse down as a plugin window may | 1947 // Ensure that we get keyboard focus on mouse down as a plugin window may |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2503 | 2591 |
2504 //////////////////////////////////////////////////////////////////////////////// | 2592 //////////////////////////////////////////////////////////////////////////////// |
2505 // RenderWidgetHostViewBase, public: | 2593 // RenderWidgetHostViewBase, public: |
2506 | 2594 |
2507 // static | 2595 // static |
2508 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2596 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2509 GetScreenInfoForWindow(results, NULL); | 2597 GetScreenInfoForWindow(results, NULL); |
2510 } | 2598 } |
2511 | 2599 |
2512 } // namespace content | 2600 } // namespace content |
OLD | NEW |