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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 255843004: Update trackpad pinch-zoom code for corrected scale semantics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "content/browser/frame_host/cross_site_transferring_request.h" 7 #include "content/browser/frame_host/cross_site_transferring_request.h"
8 #include "content/browser/frame_host/interstitial_page_impl.h" 8 #include "content/browser/frame_host/interstitial_page_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 10 #include "content/browser/renderer_host/render_view_host_impl.h"
(...skipping 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 2492
2493 scoped_ptr<ContentsZoomChangedDelegate> delegate( 2493 scoped_ptr<ContentsZoomChangedDelegate> delegate(
2494 new ContentsZoomChangedDelegate()); 2494 new ContentsZoomChangedDelegate());
2495 contents()->SetDelegate(delegate.get()); 2495 contents()->SetDelegate(delegate.get());
2496 2496
2497 const float kZoomStepValue = 0.6f; 2497 const float kZoomStepValue = 0.6f;
2498 blink::WebGestureEvent event = SyntheticWebGestureEventBuilder::Build( 2498 blink::WebGestureEvent event = SyntheticWebGestureEventBuilder::Build(
2499 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchpad); 2499 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchpad);
2500 2500
2501 // A pinch less than the step value doesn't change the zoom level. 2501 // A pinch less than the step value doesn't change the zoom level.
2502 event.data.pinchUpdate.scale = kZoomStepValue * 0.8f; 2502 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 0.8f;
2503 EXPECT_TRUE(contents()->HandleGestureEvent(event)); 2503 EXPECT_TRUE(contents()->HandleGestureEvent(event));
2504 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); 2504 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2505 2505
2506 // But repeating the event so the combined scale is greater does. 2506 // But repeating the event so the combined scale is greater does.
2507 EXPECT_TRUE(contents()->HandleGestureEvent(event)); 2507 EXPECT_TRUE(contents()->HandleGestureEvent(event));
2508 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); 2508 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2509 EXPECT_TRUE(delegate->last_zoom_in()); 2509 EXPECT_TRUE(delegate->last_zoom_in());
2510 2510
2511 // Pinching back out one step goes back to 100%. 2511 // Pinching back out one step goes back to 100%.
2512 event.data.pinchUpdate.scale = -kZoomStepValue; 2512 event.data.pinchUpdate.scale = 1.0f - kZoomStepValue;
2513 EXPECT_TRUE(contents()->HandleGestureEvent(event)); 2513 EXPECT_TRUE(contents()->HandleGestureEvent(event));
2514 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); 2514 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2515 EXPECT_FALSE(delegate->last_zoom_in()); 2515 EXPECT_FALSE(delegate->last_zoom_in());
2516 2516
2517 // Pinching out again doesn't zoom (step is twice as large around 100%). 2517 // Pinching out again doesn't zoom (step is twice as large around 100%).
2518 EXPECT_TRUE(contents()->HandleGestureEvent(event)); 2518 EXPECT_TRUE(contents()->HandleGestureEvent(event));
2519 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); 2519 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2520 2520
2521 // And again now it zooms once per step. 2521 // And again now it zooms once per step.
2522 EXPECT_TRUE(contents()->HandleGestureEvent(event)); 2522 EXPECT_TRUE(contents()->HandleGestureEvent(event));
2523 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount()); 2523 EXPECT_EQ(1, delegate->GetAndResetContentsZoomChangedCallCount());
2524 EXPECT_FALSE(delegate->last_zoom_in()); 2524 EXPECT_FALSE(delegate->last_zoom_in());
2525 2525
2526 // No other type of gesture event is handled by WebContentsImpl (for example 2526 // No other type of gesture event is handled by WebContentsImpl (for example
2527 // a touchscreen pinch gesture). 2527 // a touchscreen pinch gesture).
2528 event = SyntheticWebGestureEventBuilder::Build( 2528 event = SyntheticWebGestureEventBuilder::Build(
2529 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchscreen); 2529 WebInputEvent::GesturePinchUpdate, WebGestureEvent::Touchscreen);
2530 event.data.pinchUpdate.scale = kZoomStepValue * 3; 2530 event.data.pinchUpdate.scale = 1.0f + kZoomStepValue * 3;
2531 EXPECT_FALSE(contents()->HandleGestureEvent(event)); 2531 EXPECT_FALSE(contents()->HandleGestureEvent(event));
2532 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount()); 2532 EXPECT_EQ(0, delegate->GetAndResetContentsZoomChangedCallCount());
2533 2533
2534 // Ensure pointers to the delegate aren't kept beyond it's lifetime. 2534 // Ensure pointers to the delegate aren't kept beyond it's lifetime.
2535 contents()->SetDelegate(NULL); 2535 contents()->SetDelegate(NULL);
2536 } 2536 }
2537 2537
2538 } // namespace content 2538 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698