Skip to content

Commit

Permalink
Made page zoom handling work with smooth scroll devices
Browse files Browse the repository at this point in the history
This CL is a smaller set of the CL https://codereview.chromium.org/688253002/
It fixes some broken functionality exposed by that CL.

R=avi
BUG=384970

Review URL: https://codereview.chromium.org/1554253004

Cr-Commit-Position: refs/heads/master@{#367850}
  • Loading branch information
w-shackleton authored and Commit bot committed Jan 6, 2016
1 parent 7c9a7de commit 49bcd39
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ Wesley Lancel <wesleylancel@gmail.com>
Wesley Wigham <t-weswig@microsoft.com>
Wesley Wigham <wwigham@gmail.com>
Will Hirsch <chromium@willhirsch.co.uk>
Will Shackleton <w.shackleton@gmail.com>
William Xie <william.xie@intel.com>
Xiang Long <xiang.long@intel.com>
Xiaolei Yu <dreifachstein@gmail.com>
Expand Down
11 changes: 10 additions & 1 deletion content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stddef.h>

#include <cmath>
#include <utility>

#include "base/command_line.h"
Expand Down Expand Up @@ -396,6 +397,7 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
closed_by_user_gesture_(false),
minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
zoom_scroll_remainder_(0),
render_view_message_source_(NULL),
render_frame_message_source_(NULL),
fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
Expand Down Expand Up @@ -1587,7 +1589,14 @@ bool WebContentsImpl::HandleWheelEvent(
if (delegate_ && event.wheelTicksY &&
(event.modifiers & blink::WebInputEvent::ControlKey) &&
!event.canScroll) {
delegate_->ContentsZoomChange(event.wheelTicksY > 0);
// Count only integer cumulative scrolls as zoom events; this handles
// smooth scroll and regular scroll device behavior.
zoom_scroll_remainder_ += event.wheelTicksY;
int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
if (whole_zoom_scroll_remainder_ != 0) {
delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
}
return true;
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,9 @@ class CONTENT_EXPORT WebContentsImpl
int minimum_zoom_percent_;
int maximum_zoom_percent_;

// Used to correctly handle integer zooming through a smooth scroll device.
float zoom_scroll_remainder_;

// The intrinsic size of the page.
gfx::Size preferred_size_;

Expand Down

0 comments on commit 49bcd39

Please sign in to comment.