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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 291003002: Move OverscrollController to RenderWidgetHostViewAura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix navigation screenshot Created 6 years, 7 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/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"
11 #include "base/command_line.h"
11 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "cc/output/copy_output_request.h" 16 #include "cc/output/copy_output_request.h"
16 #include "cc/output/copy_output_result.h" 17 #include "cc/output/copy_output_result.h"
17 #include "cc/resources/texture_mailbox.h" 18 #include "cc/resources/texture_mailbox.h"
18 #include "cc/trees/layer_tree_settings.h" 19 #include "cc/trees/layer_tree_settings.h"
19 #include "content/browser/accessibility/browser_accessibility_manager.h" 20 #include "content/browser/accessibility/browser_accessibility_manager.h"
20 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 21 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
21 #include "content/browser/frame_host/frame_tree.h" 22 #include "content/browser/frame_host/frame_tree.h"
22 #include "content/browser/frame_host/frame_tree_node.h" 23 #include "content/browser/frame_host/frame_tree_node.h"
23 #include "content/browser/frame_host/render_frame_host_impl.h" 24 #include "content/browser/frame_host/render_frame_host_impl.h"
24 #include "content/browser/gpu/compositor_util.h" 25 #include "content/browser/gpu/compositor_util.h"
25 #include "content/browser/renderer_host/compositor_resize_lock_aura.h" 26 #include "content/browser/renderer_host/compositor_resize_lock_aura.h"
26 #include "content/browser/renderer_host/dip_util.h" 27 #include "content/browser/renderer_host/dip_util.h"
27 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" 28 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
28 #include "content/browser/renderer_host/overscroll_controller.h" 29 #include "content/browser/renderer_host/overscroll_controller.h"
29 #include "content/browser/renderer_host/render_view_host_delegate.h" 30 #include "content/browser/renderer_host/render_view_host_delegate.h"
30 #include "content/browser/renderer_host/render_view_host_impl.h" 31 #include "content/browser/renderer_host/render_view_host_impl.h"
31 #include "content/browser/renderer_host/render_widget_host_impl.h" 32 #include "content/browser/renderer_host/render_widget_host_impl.h"
32 #include "content/browser/renderer_host/ui_events_helper.h" 33 #include "content/browser/renderer_host/ui_events_helper.h"
33 #include "content/browser/renderer_host/web_input_event_aura.h" 34 #include "content/browser/renderer_host/web_input_event_aura.h"
34 #include "content/common/gpu/client/gl_helper.h" 35 #include "content/common/gpu/client/gl_helper.h"
35 #include "content/common/gpu/gpu_messages.h" 36 #include "content/common/gpu/gpu_messages.h"
36 #include "content/common/view_messages.h" 37 #include "content/common/view_messages.h"
37 #include "content/public/browser/content_browser_client.h" 38 #include "content/public/browser/content_browser_client.h"
39 #include "content/public/browser/overscroll_configuration.h"
38 #include "content/public/browser/render_view_host.h" 40 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 41 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
40 #include "content/public/browser/user_metrics.h" 42 #include "content/public/browser/user_metrics.h"
43 #include "content/public/common/content_switches.h"
41 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 44 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
42 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 45 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
43 #include "third_party/WebKit/public/web/WebInputEvent.h" 46 #include "third_party/WebKit/public/web/WebInputEvent.h"
44 #include "ui/aura/client/aura_constants.h" 47 #include "ui/aura/client/aura_constants.h"
45 #include "ui/aura/client/cursor_client.h" 48 #include "ui/aura/client/cursor_client.h"
46 #include "ui/aura/client/cursor_client_observer.h" 49 #include "ui/aura/client/cursor_client_observer.h"
47 #include "ui/aura/client/focus_client.h" 50 #include "ui/aura/client/focus_client.h"
48 #include "ui/aura/client/screen_position_client.h" 51 #include "ui/aura/client/screen_position_client.h"
49 #include "ui/aura/client/window_tree_client.h" 52 #include "ui/aura/client/window_tree_client.h"
50 #include "ui/aura/env.h" 53 #include "ui/aura/env.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 89 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
87 #include "content/common/input_messages.h" 90 #include "content/common/input_messages.h"
88 #include "ui/events/linux/text_edit_command_auralinux.h" 91 #include "ui/events/linux/text_edit_command_auralinux.h"
89 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" 92 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
90 #endif 93 #endif
91 94
92 using gfx::RectToSkIRect; 95 using gfx::RectToSkIRect;
93 using gfx::SkIRectToRect; 96 using gfx::SkIRectToRect;
94 97
95 using blink::WebScreenInfo; 98 using blink::WebScreenInfo;
99 using blink::WebInputEvent;
100 using blink::WebGestureEvent;
96 using blink::WebTouchEvent; 101 using blink::WebTouchEvent;
97 102
98 namespace content { 103 namespace content {
99 104
100 namespace { 105 namespace {
101 106
102 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting 107 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting
103 // the border of the view, in order to get valid movement information. However, 108 // the border of the view, in order to get valid movement information. However,
104 // forcing the cursor back to the center of the view after each mouse move 109 // forcing the cursor back to the center of the view after each mouse move
105 // doesn't work well. It reduces the frequency of useful mouse move messages 110 // doesn't work well. It reduces the frequency of useful mouse move messages
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 touch_editing_client_(NULL), 432 touch_editing_client_(NULL),
428 weak_ptr_factory_(this) { 433 weak_ptr_factory_(this) {
429 host_->SetView(this); 434 host_->SetView(this);
430 window_observer_.reset(new WindowObserver(this)); 435 window_observer_.reset(new WindowObserver(this));
431 aura::client::SetTooltipText(window_, &tooltip_); 436 aura::client::SetTooltipText(window_, &tooltip_);
432 aura::client::SetActivationDelegate(window_, this); 437 aura::client::SetActivationDelegate(window_, this);
433 aura::client::SetActivationChangeObserver(window_, this); 438 aura::client::SetActivationChangeObserver(window_, this);
434 aura::client::SetFocusChangeObserver(window_, this); 439 aura::client::SetFocusChangeObserver(window_, this);
435 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 440 window_->set_layer_owner_delegate(delegated_frame_host_.get());
436 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 441 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
442
443 bool overscroll_enabled = CommandLine::ForCurrentProcess()->
444 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
445 SetOverscrollControllerEnabled(overscroll_enabled);
437 } 446 }
438 447
439 //////////////////////////////////////////////////////////////////////////////// 448 ////////////////////////////////////////////////////////////////////////////////
440 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: 449 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
441 450
442 bool RenderWidgetHostViewAura::OnMessageReceived( 451 bool RenderWidgetHostViewAura::OnMessageReceived(
443 const IPC::Message& message) { 452 const IPC::Message& message) {
444 bool handled = true; 453 bool handled = true;
445 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, message) 454 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, message)
446 // TODO(kevers): Move to RenderWidgetHostViewImpl and consolidate IPC 455 // TODO(kevers): Move to RenderWidgetHostViewImpl and consolidate IPC
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 GetSystemMetrics(SM_CXPADDEDBORDER)); 1153 GetSystemMetrics(SM_CXPADDEDBORDER));
1145 } 1154 }
1146 } 1155 }
1147 1156
1148 bounds = gfx::win::ScreenToDIPRect(bounds); 1157 bounds = gfx::win::ScreenToDIPRect(bounds);
1149 #endif 1158 #endif
1150 1159
1151 return bounds; 1160 return bounds;
1152 } 1161 }
1153 1162
1163 void RenderWidgetHostViewAura::WheelEventAck(
1164 const blink::WebMouseWheelEvent& event,
1165 InputEventAckState ack_result) {
1166 if (overscroll_controller_) {
1167 overscroll_controller_->ReceivedEventACK(
1168 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1169 }
1170 }
1171
1154 void RenderWidgetHostViewAura::GestureEventAck( 1172 void RenderWidgetHostViewAura::GestureEventAck(
1155 const blink::WebGestureEvent& event, 1173 const blink::WebGestureEvent& event,
1156 InputEventAckState ack_result) { 1174 InputEventAckState ack_result) {
1157 if (touch_editing_client_) 1175 if (touch_editing_client_)
1158 touch_editing_client_->GestureEventAck(event.type); 1176 touch_editing_client_->GestureEventAck(event.type);
1177
1178 if (overscroll_controller_) {
1179 overscroll_controller_->ReceivedEventACK(
1180 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1181 }
1159 } 1182 }
1160 1183
1161 void RenderWidgetHostViewAura::ProcessAckedTouchEvent( 1184 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1162 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { 1185 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
1163 ScopedVector<ui::TouchEvent> events; 1186 ScopedVector<ui::TouchEvent> events;
1164 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, 1187 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events,
1165 SCREEN_COORDINATES)) 1188 SCREEN_COORDINATES))
1166 return; 1189 return;
1167 1190
1168 aura::WindowTreeHost* host = window_->GetHost(); 1191 aura::WindowTreeHost* host = window_->GetHost();
(...skipping 13 matching lines...) Expand all
1182 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() { 1205 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1183 return scoped_ptr<SyntheticGestureTarget>( 1206 return scoped_ptr<SyntheticGestureTarget>(
1184 new SyntheticGestureTargetAura(host_)); 1207 new SyntheticGestureTargetAura(host_));
1185 } 1208 }
1186 1209
1187 void RenderWidgetHostViewAura::SetScrollOffsetPinning( 1210 void RenderWidgetHostViewAura::SetScrollOffsetPinning(
1188 bool is_pinned_to_left, bool is_pinned_to_right) { 1211 bool is_pinned_to_left, bool is_pinned_to_right) {
1189 // Not needed. Mac-only. 1212 // Not needed. Mac-only.
1190 } 1213 }
1191 1214
1215 InputEventAckState RenderWidgetHostViewAura::FilterInputEvent(
1216 const blink::WebInputEvent& input_event) {
1217 bool consumed = false;
1218 if (input_event.type == WebInputEvent::GestureFlingStart) {
1219 const WebGestureEvent& gesture_event =
1220 static_cast<const WebGestureEvent&>(input_event);
1221 // Zero-velocity touchpad flings are an Aura-specific signal that the
1222 // touchpad scroll has ended, and should not be forwarded to the renderer.
1223 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad &&
1224 !gesture_event.data.flingStart.velocityX &&
1225 !gesture_event.data.flingStart.velocityY) {
1226 consumed = true;
1227 }
1228 }
1229
1230 if (overscroll_controller_)
1231 consumed |= overscroll_controller_->WillHandleEvent(input_event);
1232
1233 return consumed && !WebTouchEvent::isTouchEventType(input_event.type)
1234 ? INPUT_EVENT_ACK_STATE_CONSUMED
1235 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1236 }
1237
1192 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() { 1238 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() {
1193 if (GetBrowserAccessibilityManager()) 1239 if (GetBrowserAccessibilityManager())
1194 return; 1240 return;
1195 1241
1196 BrowserAccessibilityManager* manager = NULL; 1242 BrowserAccessibilityManager* manager = NULL;
1197 #if defined(OS_WIN) 1243 #if defined(OS_WIN)
1198 aura::WindowTreeHost* host = window_->GetHost(); 1244 aura::WindowTreeHost* host = window_->GetHost();
1199 if (!host) 1245 if (!host)
1200 return; 1246 return;
1201 HWND hwnd = host->GetAcceleratedWidget(); 1247 HWND hwnd = host->GetAcceleratedWidget();
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 LPARAM lparam = reinterpret_cast<LPARAM>(this); 1680 LPARAM lparam = reinterpret_cast<LPARAM>(this);
1635 EnumChildWindows(parent, WindowDestroyingCallback, lparam); 1681 EnumChildWindows(parent, WindowDestroyingCallback, lparam);
1636 #endif 1682 #endif
1637 1683
1638 // Make sure that the input method no longer references to this object before 1684 // Make sure that the input method no longer references to this object before
1639 // this object is removed from the root window (i.e. this object loses access 1685 // this object is removed from the root window (i.e. this object loses access
1640 // to the input method). 1686 // to the input method).
1641 ui::InputMethod* input_method = GetInputMethod(); 1687 ui::InputMethod* input_method = GetInputMethod();
1642 if (input_method) 1688 if (input_method)
1643 input_method->DetachTextInputClient(this); 1689 input_method->DetachTextInputClient(this);
1690
1691 if (overscroll_controller_)
1692 overscroll_controller_->Reset();
1644 } 1693 }
1645 1694
1646 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) { 1695 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) {
1647 host_->ViewDestroyed(); 1696 host_->ViewDestroyed();
1648 delete this; 1697 delete this;
1649 } 1698 }
1650 1699
1651 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1700 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1652 } 1701 }
1653 1702
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 } 1829 }
1781 return; 1830 return;
1782 } 1831 }
1783 1832
1784 // As the overscroll is handled during scroll events from the trackpad, the 1833 // As the overscroll is handled during scroll events from the trackpad, the
1785 // RWHVA window is transformed by the overscroll controller. This transform 1834 // RWHVA window is transformed by the overscroll controller. This transform
1786 // triggers a synthetic mouse-move event to be generated (by the aura 1835 // triggers a synthetic mouse-move event to be generated (by the aura
1787 // RootWindow). But this event interferes with the overscroll gesture. So, 1836 // RootWindow). But this event interferes with the overscroll gesture. So,
1788 // ignore such synthetic mouse-move events if an overscroll gesture is in 1837 // ignore such synthetic mouse-move events if an overscroll gesture is in
1789 // progress. 1838 // progress.
1790 if (host_->overscroll_controller() && 1839 if (overscroll_controller_ &&
1791 host_->overscroll_controller()->overscroll_mode() != OVERSCROLL_NONE && 1840 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE &&
1792 event->flags() & ui::EF_IS_SYNTHESIZED && 1841 event->flags() & ui::EF_IS_SYNTHESIZED &&
1793 (event->type() == ui::ET_MOUSE_ENTERED || 1842 (event->type() == ui::ET_MOUSE_ENTERED ||
1794 event->type() == ui::ET_MOUSE_EXITED || 1843 event->type() == ui::ET_MOUSE_EXITED ||
1795 event->type() == ui::ET_MOUSE_MOVED)) { 1844 event->type() == ui::ET_MOUSE_MOVED)) {
1796 event->StopPropagation(); 1845 event->StopPropagation();
1797 return; 1846 return;
1798 } 1847 }
1799 1848
1800 if (event->type() == ui::ET_MOUSEWHEEL) { 1849 if (event->type() == ui::ET_MOUSEWHEEL) {
1801 #if defined(OS_WIN) 1850 #if defined(OS_WIN)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2036 } else if (window_ == lost_focus) { 2085 } else if (window_ == lost_focus) {
2037 host_->SetActive(false); 2086 host_->SetActive(false);
2038 host_->Blur(); 2087 host_->Blur();
2039 2088
2040 DetachFromInputMethod(); 2089 DetachFromInputMethod();
2041 host_->SetInputMethodActive(false); 2090 host_->SetInputMethodActive(false);
2042 2091
2043 if (touch_editing_client_) 2092 if (touch_editing_client_)
2044 touch_editing_client_->EndTouchEditing(false); 2093 touch_editing_client_->EndTouchEditing(false);
2045 2094
2095 if (overscroll_controller_)
2096 overscroll_controller_->Cancel();
2097
2046 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); 2098 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2047 if (manager) 2099 if (manager)
2048 manager->OnWindowBlurred(); 2100 manager->OnWindowBlurred();
2049 2101
2050 // If we lose the focus while fullscreen, close the window; Pepper Flash 2102 // If we lose the focus while fullscreen, close the window; Pepper Flash
2051 // won't do it for us (unlike NPAPI Flash). However, we do not close the 2103 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2052 // window if we lose the focus to a window on another display. 2104 // window if we lose the focus to a window on another display.
2053 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_); 2105 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_);
2054 bool focusing_other_display = 2106 bool focusing_other_display =
2055 gained_focus && screen->GetNumDisplays() > 1 && 2107 gained_focus && screen->GetNumDisplays() > 1 &&
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 bool is_visible) { 2261 bool is_visible) {
2210 if (host_->is_hidden() || 2262 if (host_->is_hidden() ||
2211 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || 2263 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2212 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) 2264 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2213 return; 2265 return;
2214 2266
2215 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE; 2267 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
2216 host_->SendCursorVisibilityState(is_visible); 2268 host_->SendCursorVisibilityState(is_visible);
2217 } 2269 }
2218 2270
2271 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
2272 if (!enabled)
2273 overscroll_controller_.reset();
2274 else if (!overscroll_controller_)
2275 overscroll_controller_.reset(new OverscrollController());
2276 }
2277
2219 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( 2278 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2220 const gfx::Rect& rect, 2279 const gfx::Rect& rect,
2221 const gfx::Rect& clip) { 2280 const gfx::Rect& clip) {
2222 if (!clip.IsEmpty()) { 2281 if (!clip.IsEmpty()) {
2223 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); 2282 gfx::Rect to_paint = gfx::SubtractRects(rect, clip);
2224 if (!to_paint.IsEmpty()) 2283 if (!to_paint.IsEmpty())
2225 window_->SchedulePaintInRect(to_paint); 2284 window_->SchedulePaintInRect(to_paint);
2226 } else { 2285 } else {
2227 window_->SchedulePaintInRect(rect); 2286 window_->SchedulePaintInRect(rect);
2228 } 2287 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 2438
2380 //////////////////////////////////////////////////////////////////////////////// 2439 ////////////////////////////////////////////////////////////////////////////////
2381 // RenderWidgetHostViewBase, public: 2440 // RenderWidgetHostViewBase, public:
2382 2441
2383 // static 2442 // static
2384 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2443 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2385 GetScreenInfoForWindow(results, NULL); 2444 GetScreenInfoForWindow(results, NULL);
2386 } 2445 }
2387 2446
2388 } // namespace content 2447 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698