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

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: 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"
(...skipping 10 matching lines...) Expand all
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"
38 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 40 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
40 #include "content/public/browser/user_metrics.h" 41 #include "content/public/browser/user_metrics.h"
42 #include "content/public/common/content_switches.h"
41 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 43 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
42 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 44 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
43 #include "third_party/WebKit/public/web/WebInputEvent.h" 45 #include "third_party/WebKit/public/web/WebInputEvent.h"
44 #include "ui/aura/client/aura_constants.h" 46 #include "ui/aura/client/aura_constants.h"
45 #include "ui/aura/client/cursor_client.h" 47 #include "ui/aura/client/cursor_client.h"
46 #include "ui/aura/client/cursor_client_observer.h" 48 #include "ui/aura/client/cursor_client_observer.h"
47 #include "ui/aura/client/focus_client.h" 49 #include "ui/aura/client/focus_client.h"
48 #include "ui/aura/client/screen_position_client.h" 50 #include "ui/aura/client/screen_position_client.h"
49 #include "ui/aura/client/window_tree_client.h" 51 #include "ui/aura/client/window_tree_client.h"
50 #include "ui/aura/env.h" 52 #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) 88 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
87 #include "content/common/input_messages.h" 89 #include "content/common/input_messages.h"
88 #include "ui/events/linux/text_edit_command_auralinux.h" 90 #include "ui/events/linux/text_edit_command_auralinux.h"
89 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" 91 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
90 #endif 92 #endif
91 93
92 using gfx::RectToSkIRect; 94 using gfx::RectToSkIRect;
93 using gfx::SkIRectToRect; 95 using gfx::SkIRectToRect;
94 96
95 using blink::WebScreenInfo; 97 using blink::WebScreenInfo;
98 using blink::WebInputEvent;
99 using blink::WebGestureEvent;
96 using blink::WebTouchEvent; 100 using blink::WebTouchEvent;
97 101
98 namespace content { 102 namespace content {
99 103
100 namespace { 104 namespace {
101 105
102 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting 106 // 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, 107 // 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 108 // 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 109 // 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), 431 touch_editing_client_(NULL),
428 weak_ptr_factory_(this) { 432 weak_ptr_factory_(this) {
429 host_->SetView(this); 433 host_->SetView(this);
430 window_observer_.reset(new WindowObserver(this)); 434 window_observer_.reset(new WindowObserver(this));
431 aura::client::SetTooltipText(window_, &tooltip_); 435 aura::client::SetTooltipText(window_, &tooltip_);
432 aura::client::SetActivationDelegate(window_, this); 436 aura::client::SetActivationDelegate(window_, this);
433 aura::client::SetActivationChangeObserver(window_, this); 437 aura::client::SetActivationChangeObserver(window_, this);
434 aura::client::SetFocusChangeObserver(window_, this); 438 aura::client::SetFocusChangeObserver(window_, this);
435 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 439 window_->set_layer_owner_delegate(delegated_frame_host_.get());
436 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 440 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
441
442 bool overscroll_enabled =
443 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
444 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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 GetSystemMetrics(SM_CXPADDEDBORDER)); 1152 GetSystemMetrics(SM_CXPADDEDBORDER));
1144 } 1153 }
1145 } 1154 }
1146 1155
1147 bounds = gfx::win::ScreenToDIPRect(bounds); 1156 bounds = gfx::win::ScreenToDIPRect(bounds);
1148 #endif 1157 #endif
1149 1158
1150 return bounds; 1159 return bounds;
1151 } 1160 }
1152 1161
1162 void RenderWidgetHostViewAura::WheelEventAck(
1163 const blink::WebMouseWheelEvent& event,
1164 InputEventAckState ack_result) {
1165 if (overscroll_controller_) {
1166 overscroll_controller_->ReceivedEventACK(
1167 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1168 }
1169 }
1170
1153 void RenderWidgetHostViewAura::GestureEventAck( 1171 void RenderWidgetHostViewAura::GestureEventAck(
1154 const blink::WebGestureEvent& event, 1172 const blink::WebGestureEvent& event,
1155 InputEventAckState ack_result) { 1173 InputEventAckState ack_result) {
1156 if (touch_editing_client_) 1174 if (touch_editing_client_)
1157 touch_editing_client_->GestureEventAck(event.type); 1175 touch_editing_client_->GestureEventAck(event.type);
1176
1177 if (overscroll_controller_) {
1178 overscroll_controller_->ReceivedEventACK(
1179 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1180 }
1158 } 1181 }
1159 1182
1160 void RenderWidgetHostViewAura::ProcessAckedTouchEvent( 1183 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1161 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { 1184 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
1162 ScopedVector<ui::TouchEvent> events; 1185 ScopedVector<ui::TouchEvent> events;
1163 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, 1186 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events,
1164 SCREEN_COORDINATES)) 1187 SCREEN_COORDINATES))
1165 return; 1188 return;
1166 1189
1167 aura::WindowTreeHost* host = window_->GetHost(); 1190 aura::WindowTreeHost* host = window_->GetHost();
(...skipping 13 matching lines...) Expand all
1181 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() { 1204 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1182 return scoped_ptr<SyntheticGestureTarget>( 1205 return scoped_ptr<SyntheticGestureTarget>(
1183 new SyntheticGestureTargetAura(host_)); 1206 new SyntheticGestureTargetAura(host_));
1184 } 1207 }
1185 1208
1186 void RenderWidgetHostViewAura::SetScrollOffsetPinning( 1209 void RenderWidgetHostViewAura::SetScrollOffsetPinning(
1187 bool is_pinned_to_left, bool is_pinned_to_right) { 1210 bool is_pinned_to_left, bool is_pinned_to_right) {
1188 // Not needed. Mac-only. 1211 // Not needed. Mac-only.
1189 } 1212 }
1190 1213
1214 InputEventAckState RenderWidgetHostViewAura::FilterInputEvent(
1215 const blink::WebInputEvent& input_event) {
1216 bool consumed = false;
1217 if (input_event.type == WebInputEvent::GestureFlingStart) {
1218 const WebGestureEvent& gesture_event =
1219 static_cast<const WebGestureEvent&>(input_event);
1220 // Zero-velocity touchpad flings are an Aura-specific signal that the
1221 // touchpad scroll has ended, and should not be forwarded to the renderer.
1222 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad &&
1223 !gesture_event.data.flingStart.velocityX &&
1224 !gesture_event.data.flingStart.velocityY) {
1225 consumed = true;
1226 }
1227 }
1228
1229 if (overscroll_controller_) {
1230 consumed |= (overscroll_controller_->DispatchEvent(input_event) ==
1231 OverscrollController::CONSUMED);
1232 }
1233
1234 // TODO(jdduke): Determine if necessary.
1235 /*
1236 if (disposition == OverscrollController::SHOULD_FORWARD_TO_GESTURE_QUEUE) {
1237 DCHECK(WebInputEvent::isGestureEventType(input_event.type));
1238 DCHECK(host_);
1239 const blink::WebGestureEvent& gesture_event =
1240 static_cast<const blink::WebGestureEvent&>(input_event);
1241 consumed = true;
1242 host_->ForwardGestureEvent(
1243 GestureEventWithLatencyInfo(gesture_event, latency_info));
1244 }
1245 */
1246
1247 return consumed && !WebTouchEvent::isTouchEventType(input_event.type)
1248 ? INPUT_EVENT_ACK_STATE_CONSUMED
1249 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1250 }
1251
1191 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() { 1252 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() {
1192 if (GetBrowserAccessibilityManager()) 1253 if (GetBrowserAccessibilityManager())
1193 return; 1254 return;
1194 1255
1195 BrowserAccessibilityManager* manager = NULL; 1256 BrowserAccessibilityManager* manager = NULL;
1196 #if defined(OS_WIN) 1257 #if defined(OS_WIN)
1197 aura::WindowTreeHost* host = window_->GetHost(); 1258 aura::WindowTreeHost* host = window_->GetHost();
1198 if (!host) 1259 if (!host)
1199 return; 1260 return;
1200 HWND hwnd = host->GetAcceleratedWidget(); 1261 HWND hwnd = host->GetAcceleratedWidget();
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 LPARAM lparam = reinterpret_cast<LPARAM>(this); 1693 LPARAM lparam = reinterpret_cast<LPARAM>(this);
1633 EnumChildWindows(parent, WindowDestroyingCallback, lparam); 1694 EnumChildWindows(parent, WindowDestroyingCallback, lparam);
1634 #endif 1695 #endif
1635 1696
1636 // Make sure that the input method no longer references to this object before 1697 // Make sure that the input method no longer references to this object before
1637 // this object is removed from the root window (i.e. this object loses access 1698 // this object is removed from the root window (i.e. this object loses access
1638 // to the input method). 1699 // to the input method).
1639 ui::InputMethod* input_method = GetInputMethod(); 1700 ui::InputMethod* input_method = GetInputMethod();
1640 if (input_method) 1701 if (input_method)
1641 input_method->DetachTextInputClient(this); 1702 input_method->DetachTextInputClient(this);
1703
1704 if (overscroll_controller_)
1705 overscroll_controller_->Reset();
1642 } 1706 }
1643 1707
1644 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) { 1708 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) {
1645 host_->ViewDestroyed(); 1709 host_->ViewDestroyed();
1646 delete this; 1710 delete this;
1647 } 1711 }
1648 1712
1649 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1713 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1650 } 1714 }
1651 1715
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 } 1842 }
1779 return; 1843 return;
1780 } 1844 }
1781 1845
1782 // As the overscroll is handled during scroll events from the trackpad, the 1846 // As the overscroll is handled during scroll events from the trackpad, the
1783 // RWHVA window is transformed by the overscroll controller. This transform 1847 // RWHVA window is transformed by the overscroll controller. This transform
1784 // triggers a synthetic mouse-move event to be generated (by the aura 1848 // triggers a synthetic mouse-move event to be generated (by the aura
1785 // RootWindow). But this event interferes with the overscroll gesture. So, 1849 // RootWindow). But this event interferes with the overscroll gesture. So,
1786 // ignore such synthetic mouse-move events if an overscroll gesture is in 1850 // ignore such synthetic mouse-move events if an overscroll gesture is in
1787 // progress. 1851 // progress.
1788 if (host_->overscroll_controller() && 1852 if (overscroll_controller_ &&
1789 host_->overscroll_controller()->overscroll_mode() != OVERSCROLL_NONE && 1853 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE &&
1790 event->flags() & ui::EF_IS_SYNTHESIZED && 1854 event->flags() & ui::EF_IS_SYNTHESIZED &&
1791 (event->type() == ui::ET_MOUSE_ENTERED || 1855 (event->type() == ui::ET_MOUSE_ENTERED ||
1792 event->type() == ui::ET_MOUSE_EXITED || 1856 event->type() == ui::ET_MOUSE_EXITED ||
1793 event->type() == ui::ET_MOUSE_MOVED)) { 1857 event->type() == ui::ET_MOUSE_MOVED)) {
1794 event->StopPropagation(); 1858 event->StopPropagation();
1795 return; 1859 return;
1796 } 1860 }
1797 1861
1798 if (event->type() == ui::ET_MOUSEWHEEL) { 1862 if (event->type() == ui::ET_MOUSEWHEEL) {
1799 #if defined(OS_WIN) 1863 #if defined(OS_WIN)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 } else if (window_ == lost_focus) { 2098 } else if (window_ == lost_focus) {
2035 host_->SetActive(false); 2099 host_->SetActive(false);
2036 host_->Blur(); 2100 host_->Blur();
2037 2101
2038 DetachFromInputMethod(); 2102 DetachFromInputMethod();
2039 host_->SetInputMethodActive(false); 2103 host_->SetInputMethodActive(false);
2040 2104
2041 if (touch_editing_client_) 2105 if (touch_editing_client_)
2042 touch_editing_client_->EndTouchEditing(false); 2106 touch_editing_client_->EndTouchEditing(false);
2043 2107
2108 if (overscroll_controller_)
2109 overscroll_controller_->Cancel();
2110
2044 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); 2111 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2045 if (manager) 2112 if (manager)
2046 manager->OnWindowBlurred(); 2113 manager->OnWindowBlurred();
2047 2114
2048 // If we lose the focus while fullscreen, close the window; Pepper Flash 2115 // If we lose the focus while fullscreen, close the window; Pepper Flash
2049 // won't do it for us (unlike NPAPI Flash). However, we do not close the 2116 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2050 // window if we lose the focus to a window on another display. 2117 // window if we lose the focus to a window on another display.
2051 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_); 2118 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_);
2052 bool focusing_other_display = 2119 bool focusing_other_display =
2053 gained_focus && screen->GetNumDisplays() > 1 && 2120 gained_focus && screen->GetNumDisplays() > 1 &&
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 bool is_visible) { 2274 bool is_visible) {
2208 if (host_->is_hidden() || 2275 if (host_->is_hidden() ||
2209 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || 2276 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2210 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) 2277 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2211 return; 2278 return;
2212 2279
2213 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE; 2280 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
2214 host_->SendCursorVisibilityState(is_visible); 2281 host_->SendCursorVisibilityState(is_visible);
2215 } 2282 }
2216 2283
2284 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
2285 if (!enabled)
2286 overscroll_controller_.reset();
2287 else if (!overscroll_controller_)
2288 overscroll_controller_.reset(new OverscrollController());
2289 }
2290
2217 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( 2291 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2218 const gfx::Rect& rect, 2292 const gfx::Rect& rect,
2219 const gfx::Rect& clip) { 2293 const gfx::Rect& clip) {
2220 if (!clip.IsEmpty()) { 2294 if (!clip.IsEmpty()) {
2221 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); 2295 gfx::Rect to_paint = gfx::SubtractRects(rect, clip);
2222 if (!to_paint.IsEmpty()) 2296 if (!to_paint.IsEmpty())
2223 window_->SchedulePaintInRect(to_paint); 2297 window_->SchedulePaintInRect(to_paint);
2224 } else { 2298 } else {
2225 window_->SchedulePaintInRect(rect); 2299 window_->SchedulePaintInRect(rect);
2226 } 2300 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 2453
2380 //////////////////////////////////////////////////////////////////////////////// 2454 ////////////////////////////////////////////////////////////////////////////////
2381 // RenderWidgetHostViewBase, public: 2455 // RenderWidgetHostViewBase, public:
2382 2456
2383 // static 2457 // static
2384 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2458 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2385 GetScreenInfoForWindow(results, NULL); 2459 GetScreenInfoForWindow(results, NULL);
2386 } 2460 }
2387 2461
2388 } // namespace content 2462 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698