| 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 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 | 1278 |
| 1279 gfx::NativeViewAccessible | 1279 gfx::NativeViewAccessible |
| 1280 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { | 1280 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { |
| 1281 #if defined(OS_WIN) | 1281 #if defined(OS_WIN) |
| 1282 if (legacy_render_widget_host_HWND_) | 1282 if (legacy_render_widget_host_HWND_) |
| 1283 return legacy_render_widget_host_HWND_->window_accessible(); | 1283 return legacy_render_widget_host_HWND_->window_accessible(); |
| 1284 #endif | 1284 #endif |
| 1285 return NULL; | 1285 return NULL; |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 void RenderWidgetHostViewAura::ShowDisambiguationPopup( | |
| 1289 const gfx::Rect& rect_pixels, | |
| 1290 const SkBitmap& zoomed_bitmap) { | |
| 1291 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 1292 if (rvh) { | |
| 1293 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
| 1294 // Suppress the link disambiguation popup if the virtual keyboard is | |
| 1295 // currently requested, as it doesn't interact well with the keyboard. | |
| 1296 if (delegate && delegate->IsVirtualKeyboardRequested()) | |
| 1297 return; | |
| 1298 } | |
| 1299 | |
| 1300 // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs | |
| 1301 // by scaling it by the inverse of the device scale factor. | |
| 1302 gfx::RectF screen_target_rect_f(rect_pixels); | |
| 1303 screen_target_rect_f.Scale(1.0f / current_device_scale_factor_); | |
| 1304 disambiguation_target_rect_ = gfx::ToEnclosingRect(screen_target_rect_f); | |
| 1305 | |
| 1306 float scale = static_cast<float>(zoomed_bitmap.width()) / | |
| 1307 static_cast<float>(rect_pixels.width()); | |
| 1308 gfx::Size zoomed_size = | |
| 1309 gfx::ScaleToCeiledSize(disambiguation_target_rect_.size(), scale); | |
| 1310 | |
| 1311 // Save of a copy of the |last_scroll_offset_| for comparison when the copy | |
| 1312 // callback fires, to ensure that we haven't scrolled. | |
| 1313 disambiguation_scroll_offset_ = last_scroll_offset_; | |
| 1314 | |
| 1315 CopyFromCompositingSurface( | |
| 1316 disambiguation_target_rect_, | |
| 1317 zoomed_size, | |
| 1318 base::Bind(&RenderWidgetHostViewAura::DisambiguationPopupRendered, | |
| 1319 weak_ptr_factory_.GetWeakPtr()), | |
| 1320 kN32_SkColorType); | |
| 1321 } | |
| 1322 | |
| 1323 void RenderWidgetHostViewAura::DisambiguationPopupRendered( | |
| 1324 const SkBitmap& result, | |
| 1325 ReadbackResponse response) { | |
| 1326 if ((response != READBACK_SUCCESS) || | |
| 1327 disambiguation_scroll_offset_ != last_scroll_offset_) | |
| 1328 return; | |
| 1329 | |
| 1330 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will | |
| 1331 // actually show the disambiguation popup. | |
| 1332 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 1333 if (!rvh) | |
| 1334 return; | |
| 1335 | |
| 1336 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
| 1337 if (!delegate) | |
| 1338 return; | |
| 1339 | |
| 1340 if (delegate->IsVirtualKeyboardRequested()) | |
| 1341 return; | |
| 1342 | |
| 1343 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView(); | |
| 1344 if (delegate_view) { | |
| 1345 delegate_view->ShowDisambiguationPopup( | |
| 1346 disambiguation_target_rect_, | |
| 1347 result, | |
| 1348 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationGesture, | |
| 1349 weak_ptr_factory_.GetWeakPtr()), | |
| 1350 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationMouse, | |
| 1351 weak_ptr_factory_.GetWeakPtr())); | |
| 1352 } | |
| 1353 } | |
| 1354 | |
| 1355 void RenderWidgetHostViewAura::HideDisambiguationPopup() { | |
| 1356 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 1357 if (!rvh) | |
| 1358 return; | |
| 1359 | |
| 1360 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
| 1361 if (!delegate) | |
| 1362 return; | |
| 1363 | |
| 1364 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView(); | |
| 1365 if (delegate_view) | |
| 1366 delegate_view->HideDisambiguationPopup(); | |
| 1367 } | |
| 1368 | |
| 1369 void RenderWidgetHostViewAura::ProcessDisambiguationGesture( | |
| 1370 ui::GestureEvent* event) { | |
| 1371 blink::WebGestureEvent web_gesture = content::MakeWebGestureEvent(*event); | |
| 1372 // If we fail to make a WebGestureEvent that is a Tap from the provided event, | |
| 1373 // don't forward it to Blink. | |
| 1374 if (web_gesture.type < blink::WebInputEvent::Type::GestureTap || | |
| 1375 web_gesture.type > blink::WebInputEvent::Type::GestureTapCancel) | |
| 1376 return; | |
| 1377 | |
| 1378 host_->ForwardGestureEvent(web_gesture); | |
| 1379 } | |
| 1380 | |
| 1381 void RenderWidgetHostViewAura::ProcessDisambiguationMouse( | |
| 1382 ui::MouseEvent* event) { | |
| 1383 blink::WebMouseEvent web_mouse = content::MakeWebMouseEvent(*event); | |
| 1384 host_->ForwardMouseEvent(web_mouse); | |
| 1385 } | |
| 1386 | |
| 1387 bool RenderWidgetHostViewAura::LockMouse() { | 1288 bool RenderWidgetHostViewAura::LockMouse() { |
| 1388 aura::Window* root_window = window_->GetRootWindow(); | 1289 aura::Window* root_window = window_->GetRootWindow(); |
| 1389 if (!root_window) | 1290 if (!root_window) |
| 1390 return false; | 1291 return false; |
| 1391 | 1292 |
| 1392 if (mouse_locked_) | 1293 if (mouse_locked_) |
| 1393 return true; | 1294 return true; |
| 1394 | 1295 |
| 1395 mouse_locked_ = true; | 1296 mouse_locked_ = true; |
| 1396 #if !defined(OS_WIN) | 1297 #if !defined(OS_WIN) |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 // dismiss them. | 1886 // dismiss them. |
| 1986 aura::WindowTreeHost* host = window_->GetHost(); | 1887 aura::WindowTreeHost* host = window_->GetHost(); |
| 1987 if (host) { | 1888 if (host) { |
| 1988 HWND parent = host->GetAcceleratedWidget(); | 1889 HWND parent = host->GetAcceleratedWidget(); |
| 1989 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); | 1890 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); |
| 1990 EnumThreadWindows(GetCurrentThreadId(), | 1891 EnumThreadWindows(GetCurrentThreadId(), |
| 1991 DismissOwnedPopups, | 1892 DismissOwnedPopups, |
| 1992 reinterpret_cast<LPARAM>(toplevel_hwnd)); | 1893 reinterpret_cast<LPARAM>(toplevel_hwnd)); |
| 1993 } | 1894 } |
| 1994 #endif | 1895 #endif |
| 1995 // The Disambiguation popup does not parent itself from this window, so we | |
| 1996 // manually dismiss it. | |
| 1997 HideDisambiguationPopup(); | |
| 1998 | |
| 1999 blink::WebMouseWheelEvent mouse_wheel_event = | 1896 blink::WebMouseWheelEvent mouse_wheel_event = |
| 2000 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event)); | 1897 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event)); |
| 2001 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) { | 1898 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) { |
| 2002 if (ShouldRouteEvent(event)) { | 1899 if (ShouldRouteEvent(event)) { |
| 2003 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( | 1900 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( |
| 2004 this, &mouse_wheel_event); | 1901 this, &mouse_wheel_event); |
| 2005 } else { | 1902 } else { |
| 2006 ProcessMouseWheelEvent(mouse_wheel_event); | 1903 ProcessMouseWheelEvent(mouse_wheel_event); |
| 2007 } | 1904 } |
| 2008 } | 1905 } |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2955 | 2852 |
| 2956 //////////////////////////////////////////////////////////////////////////////// | 2853 //////////////////////////////////////////////////////////////////////////////// |
| 2957 // RenderWidgetHostViewBase, public: | 2854 // RenderWidgetHostViewBase, public: |
| 2958 | 2855 |
| 2959 // static | 2856 // static |
| 2960 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2857 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2961 GetScreenInfoForWindow(results, NULL); | 2858 GetScreenInfoForWindow(results, NULL); |
| 2962 } | 2859 } |
| 2963 | 2860 |
| 2964 } // namespace content | 2861 } // namespace content |
| OLD | NEW |