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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 completed_mode_ = OVERSCROLL_NONE; | 116 completed_mode_ = OVERSCROLL_NONE; |
117 delta_x_ = delta_y_ = 0.f; | 117 delta_x_ = delta_y_ = 0.f; |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
121 // Overridden from OverscrollControllerDelegate: | 121 // Overridden from OverscrollControllerDelegate: |
122 virtual gfx::Rect GetVisibleBounds() const OVERRIDE { | 122 virtual gfx::Rect GetVisibleBounds() const OVERRIDE { |
123 return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect(); | 123 return view_->IsShowing() ? view_->GetViewBounds() : gfx::Rect(); |
124 } | 124 } |
125 | 125 |
126 virtual void OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE { | 126 virtual bool OnOverscrollUpdate(float delta_x, float delta_y) OVERRIDE { |
127 delta_x_ = delta_x; | 127 delta_x_ = delta_x; |
128 delta_y_ = delta_y; | 128 delta_y_ = delta_y; |
| 129 return true; |
129 } | 130 } |
130 | 131 |
131 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE { | 132 virtual void OnOverscrollComplete(OverscrollMode overscroll_mode) OVERRIDE { |
132 EXPECT_EQ(current_mode_, overscroll_mode); | 133 EXPECT_EQ(current_mode_, overscroll_mode); |
133 completed_mode_ = overscroll_mode; | 134 completed_mode_ = overscroll_mode; |
134 current_mode_ = OVERSCROLL_NONE; | 135 current_mode_ = OVERSCROLL_NONE; |
135 } | 136 } |
136 | 137 |
137 virtual void OnOverscrollModeChange(OverscrollMode old_mode, | 138 virtual void OnOverscrollModeChange(OverscrollMode old_mode, |
138 OverscrollMode new_mode) OVERRIDE { | 139 OverscrollMode new_mode) OVERRIDE { |
(...skipping 2388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 SimulateGestureScrollUpdateEvent(125, -5, 0); | 2528 SimulateGestureScrollUpdateEvent(125, -5, 0); |
2528 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 2529 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
2529 | 2530 |
2530 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 2531 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
2531 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2532 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
2532 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); | 2533 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
2533 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); | 2534 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
2534 EXPECT_EQ(0U, sink_->message_count()); | 2535 EXPECT_EQ(0U, sink_->message_count()); |
2535 | 2536 |
2536 // Send another update event, but in the reverse direction. The overscroll | 2537 // Send another update event, but in the reverse direction. The overscroll |
2537 // controller will consume the event, and reset the overscroll mode. | 2538 // controller will not consume the event, because it is not triggering |
| 2539 // gesture-nav. |
2538 SimulateGestureScrollUpdateEvent(-260, 0, 0); | 2540 SimulateGestureScrollUpdateEvent(-260, 0, 0); |
2539 EXPECT_EQ(0U, sink_->message_count()); | 2541 EXPECT_EQ(1U, sink_->message_count()); |
2540 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 2542 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
2541 | 2543 |
2542 // Since the overscroll mode has been reset, the next scroll update events | 2544 // Since the overscroll mode has been reset, the next scroll update events |
2543 // should reach the renderer. | 2545 // should reach the renderer. |
2544 SimulateGestureScrollUpdateEvent(-20, 0, 0); | 2546 SimulateGestureScrollUpdateEvent(-20, 0, 0); |
2545 EXPECT_EQ(1U, sink_->message_count()); | 2547 EXPECT_EQ(1U, sink_->message_count()); |
2546 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); | 2548 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
2547 } | 2549 } |
2548 | 2550 |
| 2551 TEST_F(RenderWidgetHostViewAuraOverscrollTest, |
| 2552 OverscrollDirectionChangeMouseWheel) { |
| 2553 SetUpOverscrollEnvironment(); |
| 2554 |
| 2555 // Send wheel event and receive ack as not consumed. |
| 2556 SimulateWheelEvent(125, -5, 0, true); |
| 2557 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 2558 SendInputEventACK(WebInputEvent::MouseWheel, |
| 2559 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2560 EXPECT_EQ(OVERSCROLL_EAST, overscroll_mode()); |
| 2561 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2562 EXPECT_EQ(0U, sink_->message_count()); |
| 2563 |
| 2564 // Send another wheel event, but in the reverse direction. The overscroll |
| 2565 // controller will not consume the event, because it is not triggering |
| 2566 // gesture-nav. |
| 2567 SimulateWheelEvent(-260, 0, 0, true); |
| 2568 EXPECT_EQ(1U, sink_->message_count()); |
| 2569 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2570 |
| 2571 // Since the overscroll mode has been reset, the next wheel event should reach |
| 2572 // the renderer. |
| 2573 SimulateWheelEvent(-20, 0, 0, true); |
| 2574 EXPECT_EQ(1U, sink_->message_count()); |
| 2575 EXPECT_EQ(OVERSCROLL_NONE, overscroll_mode()); |
| 2576 } |
| 2577 |
2549 // Tests that if a mouse-move event completes the overscroll gesture, future | 2578 // Tests that if a mouse-move event completes the overscroll gesture, future |
2550 // move events do reach the renderer. | 2579 // move events do reach the renderer. |
2551 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) { | 2580 TEST_F(RenderWidgetHostViewAuraOverscrollTest, OverscrollMouseMoveCompletion) { |
2552 SetUpOverscrollEnvironment(); | 2581 SetUpOverscrollEnvironment(); |
2553 | 2582 |
2554 SimulateWheelEvent(5, 0, 0, true); // sent directly | 2583 SimulateWheelEvent(5, 0, 0, true); // sent directly |
2555 SimulateWheelEvent(-1, 0, 0, true); // enqueued | 2584 SimulateWheelEvent(-1, 0, 0, true); // enqueued |
2556 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event | 2585 SimulateWheelEvent(-10, -3, 0, true); // coalesced into previous event |
2557 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event | 2586 SimulateWheelEvent(-15, -1, 0, true); // coalesced into previous event |
2558 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event | 2587 SimulateWheelEvent(-30, -3, 0, true); // coalesced into previous event |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2718 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); | 2747 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
2719 | 2748 |
2720 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 2749 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
2721 blink::WebGestureDeviceTouchscreen); | 2750 blink::WebGestureDeviceTouchscreen); |
2722 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); | 2751 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
2723 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); | 2752 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
2724 EXPECT_EQ(3U, sink_->message_count()); | 2753 EXPECT_EQ(3U, sink_->message_count()); |
2725 } | 2754 } |
2726 | 2755 |
2727 } // namespace content | 2756 } // namespace content |
OLD | NEW |