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/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 Loading... |
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 Loading... |
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 Loading... |
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 = CommandLine::ForCurrentProcess()-> |
| 443 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
| 444 SetOverscrollControllerEnabled(overscroll_enabled); |
437 } | 445 } |
438 | 446 |
439 //////////////////////////////////////////////////////////////////////////////// | 447 //////////////////////////////////////////////////////////////////////////////// |
440 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 448 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
441 | 449 |
442 bool RenderWidgetHostViewAura::OnMessageReceived( | 450 bool RenderWidgetHostViewAura::OnMessageReceived( |
443 const IPC::Message& message) { | 451 const IPC::Message& message) { |
444 bool handled = true; | 452 bool handled = true; |
445 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, message) | 453 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura, message) |
446 // TODO(kevers): Move to RenderWidgetHostViewImpl and consolidate IPC | 454 // TODO(kevers): Move to RenderWidgetHostViewImpl and consolidate IPC |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 GetSystemMetrics(SM_CXPADDEDBORDER)); | 1151 GetSystemMetrics(SM_CXPADDEDBORDER)); |
1144 } | 1152 } |
1145 } | 1153 } |
1146 | 1154 |
1147 bounds = gfx::win::ScreenToDIPRect(bounds); | 1155 bounds = gfx::win::ScreenToDIPRect(bounds); |
1148 #endif | 1156 #endif |
1149 | 1157 |
1150 return bounds; | 1158 return bounds; |
1151 } | 1159 } |
1152 | 1160 |
| 1161 void RenderWidgetHostViewAura::WheelEventAck( |
| 1162 const blink::WebMouseWheelEvent& event, |
| 1163 InputEventAckState ack_result) { |
| 1164 if (overscroll_controller_) { |
| 1165 overscroll_controller_->ReceivedEventACK( |
| 1166 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); |
| 1167 } |
| 1168 } |
| 1169 |
1153 void RenderWidgetHostViewAura::GestureEventAck( | 1170 void RenderWidgetHostViewAura::GestureEventAck( |
1154 const blink::WebGestureEvent& event, | 1171 const blink::WebGestureEvent& event, |
1155 InputEventAckState ack_result) { | 1172 InputEventAckState ack_result) { |
1156 if (touch_editing_client_) | 1173 if (touch_editing_client_) |
1157 touch_editing_client_->GestureEventAck(event.type); | 1174 touch_editing_client_->GestureEventAck(event.type); |
| 1175 |
| 1176 if (overscroll_controller_) { |
| 1177 overscroll_controller_->ReceivedEventACK( |
| 1178 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); |
| 1179 } |
1158 } | 1180 } |
1159 | 1181 |
1160 void RenderWidgetHostViewAura::ProcessAckedTouchEvent( | 1182 void RenderWidgetHostViewAura::ProcessAckedTouchEvent( |
1161 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { | 1183 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { |
1162 ScopedVector<ui::TouchEvent> events; | 1184 ScopedVector<ui::TouchEvent> events; |
1163 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, | 1185 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, |
1164 SCREEN_COORDINATES)) | 1186 SCREEN_COORDINATES)) |
1165 return; | 1187 return; |
1166 | 1188 |
1167 aura::WindowTreeHost* host = window_->GetHost(); | 1189 aura::WindowTreeHost* host = window_->GetHost(); |
(...skipping 13 matching lines...) Expand all Loading... |
1181 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() { | 1203 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() { |
1182 return scoped_ptr<SyntheticGestureTarget>( | 1204 return scoped_ptr<SyntheticGestureTarget>( |
1183 new SyntheticGestureTargetAura(host_)); | 1205 new SyntheticGestureTargetAura(host_)); |
1184 } | 1206 } |
1185 | 1207 |
1186 void RenderWidgetHostViewAura::SetScrollOffsetPinning( | 1208 void RenderWidgetHostViewAura::SetScrollOffsetPinning( |
1187 bool is_pinned_to_left, bool is_pinned_to_right) { | 1209 bool is_pinned_to_left, bool is_pinned_to_right) { |
1188 // Not needed. Mac-only. | 1210 // Not needed. Mac-only. |
1189 } | 1211 } |
1190 | 1212 |
| 1213 InputEventAckState RenderWidgetHostViewAura::FilterInputEvent( |
| 1214 const blink::WebInputEvent& input_event) { |
| 1215 bool consumed = false; |
| 1216 if (input_event.type == WebInputEvent::GestureFlingStart) { |
| 1217 const WebGestureEvent& gesture_event = |
| 1218 static_cast<const WebGestureEvent&>(input_event); |
| 1219 // Zero-velocity touchpad flings are an Aura-specific signal that the |
| 1220 // touchpad scroll has ended, and should not be forwarded to the renderer. |
| 1221 if (gesture_event.sourceDevice == WebGestureEvent::Touchpad && |
| 1222 !gesture_event.data.flingStart.velocityX && |
| 1223 !gesture_event.data.flingStart.velocityY) { |
| 1224 consumed = true; |
| 1225 } |
| 1226 } |
| 1227 |
| 1228 if (overscroll_controller_) |
| 1229 consumed |= overscroll_controller_->WillHandleEvent(input_event); |
| 1230 |
| 1231 return consumed && !WebTouchEvent::isTouchEventType(input_event.type) |
| 1232 ? INPUT_EVENT_ACK_STATE_CONSUMED |
| 1233 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 1234 } |
| 1235 |
1191 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() { | 1236 void RenderWidgetHostViewAura::CreateBrowserAccessibilityManagerIfNeeded() { |
1192 if (GetBrowserAccessibilityManager()) | 1237 if (GetBrowserAccessibilityManager()) |
1193 return; | 1238 return; |
1194 | 1239 |
1195 BrowserAccessibilityManager* manager = NULL; | 1240 BrowserAccessibilityManager* manager = NULL; |
1196 #if defined(OS_WIN) | 1241 #if defined(OS_WIN) |
1197 aura::WindowTreeHost* host = window_->GetHost(); | 1242 aura::WindowTreeHost* host = window_->GetHost(); |
1198 if (!host) | 1243 if (!host) |
1199 return; | 1244 return; |
1200 HWND hwnd = host->GetAcceleratedWidget(); | 1245 HWND hwnd = host->GetAcceleratedWidget(); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 1677 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
1633 EnumChildWindows(parent, WindowDestroyingCallback, lparam); | 1678 EnumChildWindows(parent, WindowDestroyingCallback, lparam); |
1634 #endif | 1679 #endif |
1635 | 1680 |
1636 // Make sure that the input method no longer references to this object before | 1681 // 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 | 1682 // this object is removed from the root window (i.e. this object loses access |
1638 // to the input method). | 1683 // to the input method). |
1639 ui::InputMethod* input_method = GetInputMethod(); | 1684 ui::InputMethod* input_method = GetInputMethod(); |
1640 if (input_method) | 1685 if (input_method) |
1641 input_method->DetachTextInputClient(this); | 1686 input_method->DetachTextInputClient(this); |
| 1687 |
| 1688 if (overscroll_controller_) |
| 1689 overscroll_controller_->Reset(); |
1642 } | 1690 } |
1643 | 1691 |
1644 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) { | 1692 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) { |
1645 host_->ViewDestroyed(); | 1693 host_->ViewDestroyed(); |
1646 delete this; | 1694 delete this; |
1647 } | 1695 } |
1648 | 1696 |
1649 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { | 1697 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) { |
1650 } | 1698 } |
1651 | 1699 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1778 } | 1826 } |
1779 return; | 1827 return; |
1780 } | 1828 } |
1781 | 1829 |
1782 // As the overscroll is handled during scroll events from the trackpad, the | 1830 // As the overscroll is handled during scroll events from the trackpad, the |
1783 // RWHVA window is transformed by the overscroll controller. This transform | 1831 // RWHVA window is transformed by the overscroll controller. This transform |
1784 // triggers a synthetic mouse-move event to be generated (by the aura | 1832 // triggers a synthetic mouse-move event to be generated (by the aura |
1785 // RootWindow). But this event interferes with the overscroll gesture. So, | 1833 // RootWindow). But this event interferes with the overscroll gesture. So, |
1786 // ignore such synthetic mouse-move events if an overscroll gesture is in | 1834 // ignore such synthetic mouse-move events if an overscroll gesture is in |
1787 // progress. | 1835 // progress. |
1788 if (host_->overscroll_controller() && | 1836 if (overscroll_controller_ && |
1789 host_->overscroll_controller()->overscroll_mode() != OVERSCROLL_NONE && | 1837 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE && |
1790 event->flags() & ui::EF_IS_SYNTHESIZED && | 1838 event->flags() & ui::EF_IS_SYNTHESIZED && |
1791 (event->type() == ui::ET_MOUSE_ENTERED || | 1839 (event->type() == ui::ET_MOUSE_ENTERED || |
1792 event->type() == ui::ET_MOUSE_EXITED || | 1840 event->type() == ui::ET_MOUSE_EXITED || |
1793 event->type() == ui::ET_MOUSE_MOVED)) { | 1841 event->type() == ui::ET_MOUSE_MOVED)) { |
1794 event->StopPropagation(); | 1842 event->StopPropagation(); |
1795 return; | 1843 return; |
1796 } | 1844 } |
1797 | 1845 |
1798 if (event->type() == ui::ET_MOUSEWHEEL) { | 1846 if (event->type() == ui::ET_MOUSEWHEEL) { |
1799 #if defined(OS_WIN) | 1847 #if defined(OS_WIN) |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 host_->SetInputMethodActive(false); | 2076 host_->SetInputMethodActive(false); |
2029 } | 2077 } |
2030 | 2078 |
2031 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | 2079 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); |
2032 if (manager) | 2080 if (manager) |
2033 manager->OnWindowFocused(); | 2081 manager->OnWindowFocused(); |
2034 } else if (window_ == lost_focus) { | 2082 } else if (window_ == lost_focus) { |
2035 host_->SetActive(false); | 2083 host_->SetActive(false); |
2036 host_->Blur(); | 2084 host_->Blur(); |
2037 | 2085 |
| 2086 |
2038 DetachFromInputMethod(); | 2087 DetachFromInputMethod(); |
2039 host_->SetInputMethodActive(false); | 2088 host_->SetInputMethodActive(false); |
2040 | 2089 |
2041 if (touch_editing_client_) | 2090 if (touch_editing_client_) |
2042 touch_editing_client_->EndTouchEditing(false); | 2091 touch_editing_client_->EndTouchEditing(false); |
2043 | 2092 |
| 2093 if (overscroll_controller_) |
| 2094 overscroll_controller_->Cancel(); |
| 2095 |
2044 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | 2096 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); |
2045 if (manager) | 2097 if (manager) |
2046 manager->OnWindowBlurred(); | 2098 manager->OnWindowBlurred(); |
2047 | 2099 |
2048 // If we lose the focus while fullscreen, close the window; Pepper Flash | 2100 // 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 | 2101 // 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. | 2102 // window if we lose the focus to a window on another display. |
2051 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_); | 2103 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_); |
2052 bool focusing_other_display = | 2104 bool focusing_other_display = |
2053 gained_focus && screen->GetNumDisplays() > 1 && | 2105 gained_focus && screen->GetNumDisplays() > 1 && |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2207 bool is_visible) { | 2259 bool is_visible) { |
2208 if (host_->is_hidden() || | 2260 if (host_->is_hidden() || |
2209 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || | 2261 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || |
2210 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) | 2262 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) |
2211 return; | 2263 return; |
2212 | 2264 |
2213 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE; | 2265 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE; |
2214 host_->SendCursorVisibilityState(is_visible); | 2266 host_->SendCursorVisibilityState(is_visible); |
2215 } | 2267 } |
2216 | 2268 |
| 2269 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) { |
| 2270 if (!enabled) |
| 2271 overscroll_controller_.reset(); |
| 2272 else if (!overscroll_controller_) |
| 2273 overscroll_controller_.reset(new OverscrollController()); |
| 2274 } |
| 2275 |
2217 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( | 2276 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( |
2218 const gfx::Rect& rect, | 2277 const gfx::Rect& rect, |
2219 const gfx::Rect& clip) { | 2278 const gfx::Rect& clip) { |
2220 if (!clip.IsEmpty()) { | 2279 if (!clip.IsEmpty()) { |
2221 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); | 2280 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); |
2222 if (!to_paint.IsEmpty()) | 2281 if (!to_paint.IsEmpty()) |
2223 window_->SchedulePaintInRect(to_paint); | 2282 window_->SchedulePaintInRect(to_paint); |
2224 } else { | 2283 } else { |
2225 window_->SchedulePaintInRect(rect); | 2284 window_->SchedulePaintInRect(rect); |
2226 } | 2285 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |