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/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/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/renderer_host/dip_util.h" | 9 #include "content/browser/renderer_host/dip_util.h" |
10 #include "content/browser/renderer_host/overscroll_controller.h" | 10 #include "content/browser/renderer_host/overscroll_controller.h" |
11 #include "content/browser/renderer_host/render_view_host_factory.h" | 11 #include "content/browser/renderer_host/render_view_host_factory.h" |
12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 13 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
14 #include "content/browser/web_contents/interstitial_page_impl.h" | 14 #include "content/browser/web_contents/interstitial_page_impl.h" |
| 15 #include "content/browser/web_contents/navigation_entry_impl.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
20 #include "content/public/browser/overscroll_configuration.h" | 21 #include "content/public/browser/overscroll_configuration.h" |
21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/render_widget_host.h" | 23 #include "content/public/browser/render_widget_host.h" |
23 #include "content/public/browser/render_widget_host_view.h" | 24 #include "content/public/browser/render_widget_host_view.h" |
24 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
25 #include "content/public/browser/web_contents_view_delegate.h" | 26 #include "content/public/browser/web_contents_view_delegate.h" |
26 #include "content/public/browser/web_drag_dest_delegate.h" | 27 #include "content/public/browser/web_drag_dest_delegate.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
28 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
29 #include "ui/aura/client/drag_drop_client.h" | 30 #include "ui/aura/client/drag_drop_client.h" |
30 #include "ui/aura/client/drag_drop_delegate.h" | 31 #include "ui/aura/client/drag_drop_delegate.h" |
31 #include "ui/aura/root_window.h" | 32 #include "ui/aura/root_window.h" |
32 #include "ui/aura/root_window_observer.h" | 33 #include "ui/aura/root_window_observer.h" |
33 #include "ui/aura/window.h" | 34 #include "ui/aura/window.h" |
34 #include "ui/aura/window_observer.h" | 35 #include "ui/aura/window_observer.h" |
35 #include "ui/base/clipboard/custom_data_helper.h" | 36 #include "ui/base/clipboard/custom_data_helper.h" |
36 #include "ui/base/dragdrop/drag_drop_types.h" | 37 #include "ui/base/dragdrop/drag_drop_types.h" |
37 #include "ui/base/dragdrop/drag_utils.h" | 38 #include "ui/base/dragdrop/drag_utils.h" |
38 #include "ui/base/dragdrop/os_exchange_data.h" | 39 #include "ui/base/dragdrop/os_exchange_data.h" |
39 #include "ui/base/events/event.h" | 40 #include "ui/base/events/event.h" |
40 #include "ui/base/events/event_utils.h" | 41 #include "ui/base/events/event_utils.h" |
41 #include "ui/base/hit_test.h" | 42 #include "ui/base/hit_test.h" |
42 #include "ui/compositor/layer.h" | 43 #include "ui/compositor/layer.h" |
43 #include "ui/compositor/scoped_layer_animation_settings.h" | 44 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 45 #include "ui/gfx/canvas.h" |
| 46 #include "ui/gfx/image/image.h" |
| 47 #include "ui/gfx/image/image_png_rep.h" |
44 #include "ui/gfx/image/image_skia.h" | 48 #include "ui/gfx/image/image_skia.h" |
45 #include "ui/gfx/screen.h" | 49 #include "ui/gfx/screen.h" |
46 #include "webkit/glue/webdropdata.h" | 50 #include "webkit/glue/webdropdata.h" |
47 | 51 |
48 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
49 #include "ui/base/clipboard/clipboard_util_win.h" | 53 #include "ui/base/clipboard/clipboard_util_win.h" |
50 #endif | 54 #endif |
51 | 55 |
52 namespace content { | 56 namespace content { |
53 WebContentsView* CreateWebContentsView( | 57 WebContentsView* CreateWebContentsView( |
54 WebContentsImpl* web_contents, | 58 WebContentsImpl* web_contents, |
55 WebContentsViewDelegate* delegate, | 59 WebContentsViewDelegate* delegate, |
56 RenderViewHostDelegateView** render_view_host_delegate_view) { | 60 RenderViewHostDelegateView** render_view_host_delegate_view) { |
57 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 61 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
58 *render_view_host_delegate_view = rv; | 62 *render_view_host_delegate_view = rv; |
59 return rv; | 63 return rv; |
60 } | 64 } |
61 | 65 |
62 namespace { | 66 namespace { |
63 | 67 |
64 // The window delegate for the overscroll window. This redirects trackpad events | 68 // The window delegate for the overscroll window. This redirects trackpad events |
65 // to the web-contents window. The delegate destroys itself when the window is | 69 // to the web-contents window. The delegate destroys itself when the window is |
66 // destroyed. | 70 // destroyed. |
67 class OverscrollWindowDelegate : public aura::WindowDelegate { | 71 class OverscrollWindowDelegate : public aura::WindowDelegate { |
68 public: | 72 public: |
69 explicit OverscrollWindowDelegate(aura::Window* web_contents_window) | 73 OverscrollWindowDelegate(WebContentsImpl* web_contents, |
70 : web_contents_window_(web_contents_window) { | 74 OverscrollMode overscroll_mode) |
| 75 : web_contents_window_(web_contents->GetView()->GetContentNativeView()) { |
| 76 const NavigationControllerImpl& controller = web_contents->GetController(); |
| 77 const NavigationEntryImpl* entry = NULL; |
| 78 if (overscroll_mode == OVERSCROLL_WEST && controller.CanGoForward()) { |
| 79 entry = NavigationEntryImpl::FromNavigationEntry( |
| 80 controller.GetEntryAtOffset(1)); |
| 81 } else if (overscroll_mode == OVERSCROLL_EAST && controller.CanGoBack()) { |
| 82 entry = NavigationEntryImpl::FromNavigationEntry( |
| 83 controller.GetEntryAtOffset(-1)); |
| 84 } |
| 85 if (!entry || !entry->screenshot()) |
| 86 return; |
| 87 |
| 88 std::vector<gfx::ImagePNGRep> image_reps; |
| 89 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), |
| 90 ui::GetScaleFactorForNativeView(web_contents_window_))); |
| 91 image_ = gfx::Image(image_reps); |
71 } | 92 } |
72 | 93 |
73 private: | 94 private: |
74 virtual ~OverscrollWindowDelegate() {} | 95 virtual ~OverscrollWindowDelegate() {} |
75 | 96 |
76 // aura::WindowDelegate implementation: | 97 // aura::WindowDelegate implementation: |
77 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 98 virtual gfx::Size GetMinimumSize() const OVERRIDE { |
78 return gfx::Size(); | 99 return gfx::Size(); |
79 } | 100 } |
80 | 101 |
(...skipping 20 matching lines...) Expand all Loading... |
101 } | 122 } |
102 | 123 |
103 virtual bool CanFocus() OVERRIDE { | 124 virtual bool CanFocus() OVERRIDE { |
104 return false; | 125 return false; |
105 } | 126 } |
106 | 127 |
107 virtual void OnCaptureLost() OVERRIDE { | 128 virtual void OnCaptureLost() OVERRIDE { |
108 } | 129 } |
109 | 130 |
110 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 131 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 132 if (image_.IsEmpty()) |
| 133 canvas->DrawColor(SK_ColorGRAY); |
| 134 else |
| 135 canvas->DrawImageInt(image_.AsImageSkia(), 0, 0); |
111 } | 136 } |
112 | 137 |
113 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | 138 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
114 } | 139 } |
115 | 140 |
116 virtual void OnWindowDestroying() OVERRIDE { | 141 virtual void OnWindowDestroying() OVERRIDE { |
117 } | 142 } |
118 | 143 |
119 virtual void OnWindowDestroyed() OVERRIDE { | 144 virtual void OnWindowDestroyed() OVERRIDE { |
120 delete this; | 145 delete this; |
(...skipping 12 matching lines...) Expand all Loading... |
133 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE { | 158 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE { |
134 return scoped_refptr<ui::Texture>(); | 159 return scoped_refptr<ui::Texture>(); |
135 } | 160 } |
136 | 161 |
137 // Overridden from ui::EventHandler. | 162 // Overridden from ui::EventHandler. |
138 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { | 163 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { |
139 web_contents_window_->delegate()->OnScrollEvent(event); | 164 web_contents_window_->delegate()->OnScrollEvent(event); |
140 } | 165 } |
141 | 166 |
142 aura::Window* web_contents_window_; | 167 aura::Window* web_contents_window_; |
| 168 gfx::Image image_; |
143 | 169 |
144 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); | 170 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); |
145 }; | 171 }; |
146 | 172 |
147 // Listens to all mouse drag events during a drag and drop and sends them to | 173 // Listens to all mouse drag events during a drag and drop and sends them to |
148 // the renderer. | 174 // the renderer. |
149 class WebDragSourceAura : public MessageLoopForUI::Observer, | 175 class WebDragSourceAura : public MessageLoopForUI::Observer, |
150 public NotificationObserver { | 176 public NotificationObserver { |
151 public: | 177 public: |
152 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) | 178 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // completed immidiately, which triggers |OnImplicitAnimationsCompleted()| | 501 // completed immidiately, which triggers |OnImplicitAnimationsCompleted()| |
476 // callback, and that tries to reset |overscroll_window_| again, causing a | 502 // callback, and that tries to reset |overscroll_window_| again, causing a |
477 // double-free. So use a temporary variable here. | 503 // double-free. So use a temporary variable here. |
478 if (overscroll_window_.get()) { | 504 if (overscroll_window_.get()) { |
479 base::AutoReset<OverscrollMode> reset_state(¤t_overscroll_gesture_, | 505 base::AutoReset<OverscrollMode> reset_state(¤t_overscroll_gesture_, |
480 current_overscroll_gesture_); | 506 current_overscroll_gesture_); |
481 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); | 507 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); |
482 } | 508 } |
483 | 509 |
484 overscroll_window_.reset(new aura::Window(new OverscrollWindowDelegate( | 510 overscroll_window_.reset(new aura::Window(new OverscrollWindowDelegate( |
485 GetContentNativeView()))); | 511 web_contents_, |
| 512 current_overscroll_gesture_))); |
486 overscroll_window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | 513 overscroll_window_->SetType(aura::client::WINDOW_TYPE_CONTROL); |
487 overscroll_window_->SetTransparent(false); | 514 overscroll_window_->SetTransparent(false); |
488 overscroll_window_->Init(ui::LAYER_SOLID_COLOR); | 515 overscroll_window_->Init(ui::LAYER_TEXTURED); |
489 overscroll_window_->layer()->SetMasksToBounds(true); | 516 overscroll_window_->layer()->SetMasksToBounds(true); |
490 overscroll_window_->layer()->SetColor(SK_ColorGRAY); | |
491 overscroll_window_->SetName("OverscrollOverlay"); | 517 overscroll_window_->SetName("OverscrollOverlay"); |
492 | 518 |
493 window_->AddChild(overscroll_window_.get()); | 519 window_->AddChild(overscroll_window_.get()); |
494 | 520 |
495 gfx::Rect bounds = gfx::Rect(window_->bounds().size()); | 521 gfx::Rect bounds = gfx::Rect(window_->bounds().size()); |
496 if (current_overscroll_gesture_ == OVERSCROLL_WEST && | 522 if (current_overscroll_gesture_ == OVERSCROLL_WEST && |
497 web_contents_->GetController().CanGoForward()) { | 523 web_contents_->GetController().CanGoForward()) { |
498 // The overlay will be sliding in from the right edge towards the left. | 524 // The overlay will be sliding in from the right edge towards the left. |
499 // So position the overlay window on the right of the window. | 525 // So position the overlay window on the right of the window. |
500 bounds.Offset(bounds.width(), 0); | 526 bounds.Offset(bounds.width(), 0); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 event.location(), | 1105 event.location(), |
1080 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1106 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1081 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1107 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1082 if (drag_dest_delegate_) | 1108 if (drag_dest_delegate_) |
1083 drag_dest_delegate_->OnDrop(); | 1109 drag_dest_delegate_->OnDrop(); |
1084 current_drop_data_.reset(); | 1110 current_drop_data_.reset(); |
1085 return current_drag_op_; | 1111 return current_drag_op_; |
1086 } | 1112 } |
1087 | 1113 |
1088 } // namespace content | 1114 } // namespace content |
OLD | NEW |