Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 351683002: Adds link disambiguation popup support to Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: responding to cpu's feedback Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/browser_plugin/browser_plugin_guest.h" 12 #include "content/browser/browser_plugin/browser_plugin_guest.h"
13 #include "content/browser/download/drag_download_util.h" 13 #include "content/browser/download/drag_download_util.h"
14 #include "content/browser/frame_host/interstitial_page_impl.h" 14 #include "content/browser/frame_host/interstitial_page_impl.h"
15 #include "content/browser/frame_host/navigation_entry_impl.h" 15 #include "content/browser/frame_host/navigation_entry_impl.h"
16 #include "content/browser/renderer_host/dip_util.h" 16 #include "content/browser/renderer_host/dip_util.h"
17 #include "content/browser/renderer_host/overscroll_controller.h" 17 #include "content/browser/renderer_host/overscroll_controller.h"
18 #include "content/browser/renderer_host/render_view_host_factory.h" 18 #include "content/browser/renderer_host/render_view_host_factory.h"
19 #include "content/browser/renderer_host/render_view_host_impl.h" 19 #include "content/browser/renderer_host/render_view_host_impl.h"
20 #include "content/browser/renderer_host/render_widget_host_impl.h" 20 #include "content/browser/renderer_host/render_widget_host_impl.h"
21 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 21 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
22 #include "content/browser/renderer_host/web_input_event_aura.h"
22 #include "content/browser/web_contents/aura/gesture_nav_simple.h" 23 #include "content/browser/web_contents/aura/gesture_nav_simple.h"
23 #include "content/browser/web_contents/aura/image_window_delegate.h" 24 #include "content/browser/web_contents/aura/image_window_delegate.h"
24 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" 25 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h"
25 #include "content/browser/web_contents/aura/shadow_layer_delegate.h" 26 #include "content/browser/web_contents/aura/shadow_layer_delegate.h"
26 #include "content/browser/web_contents/aura/window_slider.h" 27 #include "content/browser/web_contents/aura/window_slider.h"
27 #include "content/browser/web_contents/touch_editable_impl_aura.h" 28 #include "content/browser/web_contents/touch_editable_impl_aura.h"
28 #include "content/browser/web_contents/web_contents_impl.h" 29 #include "content/browser/web_contents/web_contents_impl.h"
29 #include "content/public/browser/content_browser_client.h" 30 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/notification_observer.h" 31 #include "content/public/browser/notification_observer.h"
31 #include "content/public/browser/notification_registrar.h" 32 #include "content/public/browser/notification_registrar.h"
32 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
33 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
34 #include "content/public/browser/overscroll_configuration.h" 35 #include "content/public/browser/overscroll_configuration.h"
35 #include "content/public/browser/render_view_host.h" 36 #include "content/public/browser/render_view_host.h"
36 #include "content/public/browser/render_widget_host.h" 37 #include "content/public/browser/render_widget_host.h"
37 #include "content/public/browser/render_widget_host_view.h" 38 #include "content/public/browser/render_widget_host_view.h"
38 #include "content/public/browser/web_contents_delegate.h" 39 #include "content/public/browser/web_contents_delegate.h"
39 #include "content/public/browser/web_contents_observer.h" 40 #include "content/public/browser/web_contents_observer.h"
40 #include "content/public/browser/web_contents_view_delegate.h" 41 #include "content/public/browser/web_contents_view_delegate.h"
41 #include "content/public/browser/web_drag_dest_delegate.h" 42 #include "content/public/browser/web_drag_dest_delegate.h"
42 #include "content/public/common/content_client.h" 43 #include "content/public/common/content_client.h"
43 #include "content/public/common/content_switches.h" 44 #include "content/public/common/content_switches.h"
44 #include "content/public/common/drop_data.h" 45 #include "content/public/common/drop_data.h"
45 #include "net/base/filename_util.h" 46 #include "net/base/filename_util.h"
46 #include "third_party/WebKit/public/web/WebInputEvent.h" 47 #include "third_party/WebKit/public/web/WebInputEvent.h"
47 #include "ui/aura/client/aura_constants.h" 48 #include "ui/aura/client/aura_constants.h"
49 #include "ui/aura/client/screen_position_client.h"
48 #include "ui/aura/client/window_tree_client.h" 50 #include "ui/aura/client/window_tree_client.h"
49 #include "ui/aura/env.h" 51 #include "ui/aura/env.h"
50 #include "ui/aura/window.h" 52 #include "ui/aura/window.h"
51 #include "ui/aura/window_observer.h" 53 #include "ui/aura/window_observer.h"
52 #include "ui/aura/window_tree_host.h" 54 #include "ui/aura/window_tree_host.h"
53 #include "ui/aura/window_tree_host_observer.h" 55 #include "ui/aura/window_tree_host_observer.h"
54 #include "ui/base/clipboard/clipboard.h" 56 #include "ui/base/clipboard/clipboard.h"
55 #include "ui/base/clipboard/custom_data_helper.h" 57 #include "ui/base/clipboard/custom_data_helper.h"
56 #include "ui/base/dragdrop/drag_drop_types.h" 58 #include "ui/base/dragdrop/drag_drop_types.h"
57 #include "ui/base/dragdrop/drag_utils.h" 59 #include "ui/base/dragdrop/drag_utils.h"
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 return; 797 return;
796 } 798 }
797 view->overscroll_controller()->set_delegate(this); 799 view->overscroll_controller()->set_delegate(this);
798 if (!navigation_overlay_) 800 if (!navigation_overlay_)
799 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 801 navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_));
800 } 802 }
801 803
802 void WebContentsViewAura::PrepareOverscrollWindow() { 804 void WebContentsViewAura::PrepareOverscrollWindow() {
803 // If there is an existing |overscroll_window_| which is in the middle of an 805 // If there is an existing |overscroll_window_| which is in the middle of an
804 // animation, then destroying the window here causes the animation to be 806 // animation, then destroying the window here causes the animation to be
805 // completed immidiately, which triggers |OnImplicitAnimationsCompleted()| 807 // completed immediately, which triggers |OnImplicitAnimationsCompleted()|
806 // callback, and that tries to reset |overscroll_window_| again, causing a 808 // callback, and that tries to reset |overscroll_window_| again, causing a
807 // double-free. So use a temporary variable here. 809 // double-free. So use a temporary variable here.
808 if (overscroll_window_) { 810 if (overscroll_window_) {
809 base::AutoReset<OverscrollMode> reset_state(&current_overscroll_gesture_, 811 base::AutoReset<OverscrollMode> reset_state(&current_overscroll_gesture_,
810 current_overscroll_gesture_); 812 current_overscroll_gesture_);
811 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); 813 scoped_ptr<aura::Window> reset_window(overscroll_window_.release());
812 } 814 }
813 815
814 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( 816 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate(
815 web_contents_, 817 web_contents_,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( 975 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura(
974 web_contents_->GetRenderWidgetHostView()); 976 web_contents_->GetRenderWidgetHostView());
975 touch_editable_->AttachToView(rwhva); 977 touch_editable_->AttachToView(rwhva);
976 } 978 }
977 979
978 void WebContentsViewAura::OverscrollUpdateForWebContentsDelegate(int delta_y) { 980 void WebContentsViewAura::OverscrollUpdateForWebContentsDelegate(int delta_y) {
979 if (web_contents_->GetDelegate() && IsScrollEndEffectEnabled()) 981 if (web_contents_->GetDelegate() && IsScrollEndEffectEnabled())
980 web_contents_->GetDelegate()->OverscrollUpdate(delta_y); 982 web_contents_->GetDelegate()->OverscrollUpdate(delta_y);
981 } 983 }
982 984
985 void WebContentsViewAura::ProcessLinkDisambiguationGesture(
986 ui::GestureEvent* event) {
987 blink::WebGestureEvent web_gesture = content::MakeWebGestureEvent(event);
988 // If we fail to make a WebGestureEvent that is a Tap from the provided event,
989 // don't forward it to Blink.
990 if (web_gesture.type < blink::WebInputEvent::Type::GestureTap ||
991 web_gesture.type > blink::WebInputEvent::Type::GestureTapCancel)
992 return;
993
994 RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura(
995 web_contents_->GetRenderWidgetHostView());
996 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
997 rwhva->GetRenderWidgetHost());
998 host->ForwardGestureEvent(web_gesture);
999 }
1000
983 //////////////////////////////////////////////////////////////////////////////// 1001 ////////////////////////////////////////////////////////////////////////////////
984 // WebContentsViewAura, WebContentsView implementation: 1002 // WebContentsViewAura, WebContentsView implementation:
985 1003
986 gfx::NativeView WebContentsViewAura::GetNativeView() const { 1004 gfx::NativeView WebContentsViewAura::GetNativeView() const {
987 return window_.get(); 1005 return window_.get();
988 } 1006 }
989 1007
990 gfx::NativeView WebContentsViewAura::GetContentNativeView() const { 1008 gfx::NativeView WebContentsViewAura::GetContentNativeView() const {
991 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 1009 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
992 return rwhv ? rwhv->GetNativeView() : NULL; 1010 return rwhv ? rwhv->GetNativeView() : NULL;
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1467 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1450 } 1468 }
1451 1469
1452 bool WebContentsViewAura::HasHitTestMask() const { 1470 bool WebContentsViewAura::HasHitTestMask() const {
1453 return false; 1471 return false;
1454 } 1472 }
1455 1473
1456 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { 1474 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const {
1457 } 1475 }
1458 1476
1477 void WebContentsViewAura::OnLinkDisambiguationPopupRequested(
1478 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) {
1479 // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs
1480 // by dividing by the device scale factor.
1481 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_.get());
1482 if (!screen) return;
1483 float device_scale_factor = screen->GetDisplayNearestWindow(
1484 window_.get()).device_scale_factor();
1485 gfx::RectF screen_target_rect_f(target_rect);
1486 screen_target_rect_f.Scale(1.0f / device_scale_factor);
1487 gfx::Rect screen_target_rect(gfx::ToEnclosingRect(screen_target_rect_f));
1488
1489 if (delegate_) {
1490 delegate_->ShowLinkDisambiguationPopup(
1491 screen_target_rect,
1492 zoomed_bitmap,
1493 window_.get(),
1494 base::Bind(&WebContentsViewAura::ProcessLinkDisambiguationGesture,
1495 base::Unretained(this)));
1496 }
1497 }
1498
1459 //////////////////////////////////////////////////////////////////////////////// 1499 ////////////////////////////////////////////////////////////////////////////////
1460 // WebContentsViewAura, ui::EventHandler implementation: 1500 // WebContentsViewAura, ui::EventHandler implementation:
1461 1501
1462 void WebContentsViewAura::OnKeyEvent(ui::KeyEvent* event) { 1502 void WebContentsViewAura::OnKeyEvent(ui::KeyEvent* event) {
1463 } 1503 }
1464 1504
1465 void WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) { 1505 void WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) {
1466 if (!web_contents_->GetDelegate()) 1506 if (!web_contents_->GetDelegate())
1467 return; 1507 return;
1468 1508
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 if (visible) { 1648 if (visible) {
1609 if (!web_contents_->should_normally_be_visible()) 1649 if (!web_contents_->should_normally_be_visible())
1610 web_contents_->WasShown(); 1650 web_contents_->WasShown();
1611 } else { 1651 } else {
1612 if (web_contents_->should_normally_be_visible()) 1652 if (web_contents_->should_normally_be_visible())
1613 web_contents_->WasHidden(); 1653 web_contents_->WasHidden();
1614 } 1654 }
1615 } 1655 }
1616 1656
1617 } // namespace content 1657 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698