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

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: DCHECK_GE Created 6 years, 6 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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 GetSystemMetrics(SM_CXPADDEDBORDER)); 1149 GetSystemMetrics(SM_CXPADDEDBORDER));
1141 } 1150 }
1142 } 1151 }
1143 1152
1144 bounds = gfx::win::ScreenToDIPRect(bounds); 1153 bounds = gfx::win::ScreenToDIPRect(bounds);
1145 #endif 1154 #endif
1146 1155
1147 return bounds; 1156 return bounds;
1148 } 1157 }
1149 1158
1159 void RenderWidgetHostViewAura::WheelEventAck(
1160 const blink::WebMouseWheelEvent& event,
1161 InputEventAckState ack_result) {
1162 if (overscroll_controller_) {
1163 overscroll_controller_->ReceivedEventACK(
1164 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1165 }
1166 }
1167
1150 void RenderWidgetHostViewAura::GestureEventAck( 1168 void RenderWidgetHostViewAura::GestureEventAck(
1151 const blink::WebGestureEvent& event, 1169 const blink::WebGestureEvent& event,
1152 InputEventAckState ack_result) { 1170 InputEventAckState ack_result) {
1153 if (touch_editing_client_) 1171 if (touch_editing_client_)
1154 touch_editing_client_->GestureEventAck(event.type); 1172 touch_editing_client_->GestureEventAck(event.type);
1173
1174 if (overscroll_controller_) {
1175 overscroll_controller_->ReceivedEventACK(
1176 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1177 }
1155 } 1178 }
1156 1179
1157 void RenderWidgetHostViewAura::ProcessAckedTouchEvent( 1180 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1158 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { 1181 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
1159 ScopedVector<ui::TouchEvent> events; 1182 ScopedVector<ui::TouchEvent> events;
1160 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, 1183 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events,
1161 SCREEN_COORDINATES)) 1184 SCREEN_COORDINATES))
1162 return; 1185 return;
1163 1186
1164 aura::WindowTreeHost* host = window_->GetHost(); 1187 aura::WindowTreeHost* host = window_->GetHost();
(...skipping 13 matching lines...) Expand all
1178 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() { 1201 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1179 return scoped_ptr<SyntheticGestureTarget>( 1202 return scoped_ptr<SyntheticGestureTarget>(
1180 new SyntheticGestureTargetAura(host_)); 1203 new SyntheticGestureTargetAura(host_));
1181 } 1204 }
1182 1205
1183 void RenderWidgetHostViewAura::SetScrollOffsetPinning( 1206 void RenderWidgetHostViewAura::SetScrollOffsetPinning(
1184 bool is_pinned_to_left, bool is_pinned_to_right) { 1207 bool is_pinned_to_left, bool is_pinned_to_right) {
1185 // Not needed. Mac-only. 1208 // Not needed. Mac-only.
1186 } 1209 }
1187 1210
1211 InputEventAckState RenderWidgetHostViewAura::FilterInputEvent(
1212 const blink::WebInputEvent& input_event) {
1213 bool consumed = false;
1214 if (input_event.type == WebInputEvent::GestureFlingStart) {
1215 const WebGestureEvent& gesture_event =
1216 static_cast<const WebGestureEvent&>(input_event);
1217 // Zero-velocity touchpad flings are an Aura-specific signal that the
1218 // touchpad scroll has ended, and should not be forwarded to the renderer.
1219 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad &&
1220 !gesture_event.data.flingStart.velocityX &&
1221 !gesture_event.data.flingStart.velocityY) {
1222 consumed = true;
1223 }
1224 }
1225
1226 if (overscroll_controller_)
1227 consumed |= overscroll_controller_->WillHandleEvent(input_event);
1228
1229 return consumed && !WebTouchEvent::isTouchEventType(input_event.type)
1230 ? INPUT_EVENT_ACK_STATE_CONSUMED
1231 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1232 }
1233
1188 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() { 1234 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() {
1189 if (GetBrowserAccessibilityManager()) 1235 if (GetBrowserAccessibilityManager())
1190 return; 1236 return;
1191 1237
1192 BrowserAccessibilityManager* manager = NULL; 1238 BrowserAccessibilityManager* manager = NULL;
1193 #if defined(OS_WIN) 1239 #if defined(OS_WIN)
1194 aura::WindowTreeHost* host = window_->GetHost(); 1240 aura::WindowTreeHost* host = window_->GetHost();
1195 if (!host) 1241 if (!host)
1196 return; 1242 return;
1197 HWND hwnd = host->GetAcceleratedWidget(); 1243 HWND hwnd = host->GetAcceleratedWidget();
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 LPARAM lparam = reinterpret_cast<LPARAM>(this); 1676 LPARAM lparam = reinterpret_cast<LPARAM>(this);
1631 EnumChildWindows(parent, WindowDestroyingCallback, lparam); 1677 EnumChildWindows(parent, WindowDestroyingCallback, lparam);
1632 #endif 1678 #endif
1633 1679
1634 // Make sure that the input method no longer references to this object before 1680 // Make sure that the input method no longer references to this object before
1635 // this object is removed from the root window (i.e. this object loses access 1681 // this object is removed from the root window (i.e. this object loses access
1636 // to the input method). 1682 // to the input method).
1637 ui::InputMethod* input_method = GetInputMethod(); 1683 ui::InputMethod* input_method = GetInputMethod();
1638 if (input_method) 1684 if (input_method)
1639 input_method->DetachTextInputClient(this); 1685 input_method->DetachTextInputClient(this);
1686
1687 if (overscroll_controller_)
1688 overscroll_controller_->Reset();
1640 } 1689 }
1641 1690
1642 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) { 1691 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) {
1643 host_->ViewDestroyed(); 1692 host_->ViewDestroyed();
1644 delete this; 1693 delete this;
1645 } 1694 }
1646 1695
1647 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1696 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1648 } 1697 }
1649 1698
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 } 1825 }
1777 return; 1826 return;
1778 } 1827 }
1779 1828
1780 // As the overscroll is handled during scroll events from the trackpad, the 1829 // As the overscroll is handled during scroll events from the trackpad, the
1781 // RWHVA window is transformed by the overscroll controller. This transform 1830 // RWHVA window is transformed by the overscroll controller. This transform
1782 // triggers a synthetic mouse-move event to be generated (by the aura 1831 // triggers a synthetic mouse-move event to be generated (by the aura
1783 // RootWindow). But this event interferes with the overscroll gesture. So, 1832 // RootWindow). But this event interferes with the overscroll gesture. So,
1784 // ignore such synthetic mouse-move events if an overscroll gesture is in 1833 // ignore such synthetic mouse-move events if an overscroll gesture is in
1785 // progress. 1834 // progress.
1786 if (host_->overscroll_controller() && 1835 if (overscroll_controller_ &&
1787 host_->overscroll_controller()->overscroll_mode() != OVERSCROLL_NONE && 1836 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE &&
1788 event->flags() & ui::EF_IS_SYNTHESIZED && 1837 event->flags() & ui::EF_IS_SYNTHESIZED &&
1789 (event->type() == ui::ET_MOUSE_ENTERED || 1838 (event->type() == ui::ET_MOUSE_ENTERED ||
1790 event->type() == ui::ET_MOUSE_EXITED || 1839 event->type() == ui::ET_MOUSE_EXITED ||
1791 event->type() == ui::ET_MOUSE_MOVED)) { 1840 event->type() == ui::ET_MOUSE_MOVED)) {
1792 event->StopPropagation(); 1841 event->StopPropagation();
1793 return; 1842 return;
1794 } 1843 }
1795 1844
1796 if (event->type() == ui::ET_MOUSEWHEEL) { 1845 if (event->type() == ui::ET_MOUSEWHEEL) {
1797 #if defined(OS_WIN) 1846 #if defined(OS_WIN)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 } else if (window_ == lost_focus) { 2081 } else if (window_ == lost_focus) {
2033 host_->SetActive(false); 2082 host_->SetActive(false);
2034 host_->Blur(); 2083 host_->Blur();
2035 2084
2036 DetachFromInputMethod(); 2085 DetachFromInputMethod();
2037 host_->SetInputMethodActive(false); 2086 host_->SetInputMethodActive(false);
2038 2087
2039 if (touch_editing_client_) 2088 if (touch_editing_client_)
2040 touch_editing_client_->EndTouchEditing(false); 2089 touch_editing_client_->EndTouchEditing(false);
2041 2090
2091 if (overscroll_controller_)
2092 overscroll_controller_->Cancel();
2093
2042 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); 2094 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2043 if (manager) 2095 if (manager)
2044 manager->OnWindowBlurred(); 2096 manager->OnWindowBlurred();
2045 2097
2046 // If we lose the focus while fullscreen, close the window; Pepper Flash 2098 // If we lose the focus while fullscreen, close the window; Pepper Flash
2047 // won't do it for us (unlike NPAPI Flash). However, we do not close the 2099 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2048 // window if we lose the focus to a window on another display. 2100 // window if we lose the focus to a window on another display.
2049 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_); 2101 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_);
2050 bool focusing_other_display = 2102 bool focusing_other_display =
2051 gained_focus && screen->GetNumDisplays() > 1 && 2103 gained_focus && screen->GetNumDisplays() > 1 &&
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2205 bool is_visible) { 2257 bool is_visible) {
2206 if (host_->is_hidden() || 2258 if (host_->is_hidden() ||
2207 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || 2259 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2208 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) 2260 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2209 return; 2261 return;
2210 2262
2211 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE; 2263 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
2212 host_->SendCursorVisibilityState(is_visible); 2264 host_->SendCursorVisibilityState(is_visible);
2213 } 2265 }
2214 2266
2267 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
2268 if (!enabled)
2269 overscroll_controller_.reset();
2270 else if (!overscroll_controller_)
2271 overscroll_controller_.reset(new OverscrollController());
2272 }
2273
2215 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( 2274 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2216 const gfx::Rect& rect, 2275 const gfx::Rect& rect,
2217 const gfx::Rect& clip) { 2276 const gfx::Rect& clip) {
2218 if (!clip.IsEmpty()) { 2277 if (!clip.IsEmpty()) {
2219 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); 2278 gfx::Rect to_paint = gfx::SubtractRects(rect, clip);
2220 if (!to_paint.IsEmpty()) 2279 if (!to_paint.IsEmpty())
2221 window_->SchedulePaintInRect(to_paint); 2280 window_->SchedulePaintInRect(to_paint);
2222 } else { 2281 } else {
2223 window_->SchedulePaintInRect(rect); 2282 window_->SchedulePaintInRect(rect);
2224 } 2283 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 2434
2376 //////////////////////////////////////////////////////////////////////////////// 2435 ////////////////////////////////////////////////////////////////////////////////
2377 // RenderWidgetHostViewBase, public: 2436 // RenderWidgetHostViewBase, public:
2378 2437
2379 // static 2438 // static
2380 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2439 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2381 GetScreenInfoForWindow(results, NULL); 2440 GetScreenInfoForWindow(results, NULL);
2382 } 2441 }
2383 2442
2384 } // namespace content 2443 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698