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

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

Issue 1554253004: Made page zoom handling work with smooth scroll devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to std::lround Created 4 years, 11 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
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('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 "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/process/process.h" 18 #include "base/process/process.h"
18 #include "base/profiler/scoped_tracker.h" 19 #include "base/profiler/scoped_tracker.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 capturer_count_(0), 390 capturer_count_(0),
390 should_normally_be_visible_(true), 391 should_normally_be_visible_(true),
391 is_being_destroyed_(false), 392 is_being_destroyed_(false),
392 notify_disconnection_(false), 393 notify_disconnection_(false),
393 dialog_manager_(NULL), 394 dialog_manager_(NULL),
394 is_showing_before_unload_dialog_(false), 395 is_showing_before_unload_dialog_(false),
395 last_active_time_(base::TimeTicks::Now()), 396 last_active_time_(base::TimeTicks::Now()),
396 closed_by_user_gesture_(false), 397 closed_by_user_gesture_(false),
397 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), 398 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
398 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), 399 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
400 zoom_scroll_remainder_(0),
399 render_view_message_source_(NULL), 401 render_view_message_source_(NULL),
400 render_frame_message_source_(NULL), 402 render_frame_message_source_(NULL),
401 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), 403 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
402 fullscreen_widget_had_focus_at_shutdown_(false), 404 fullscreen_widget_had_focus_at_shutdown_(false),
403 is_subframe_(false), 405 is_subframe_(false),
404 force_disable_overscroll_content_(false), 406 force_disable_overscroll_content_(false),
405 last_dialog_suppressed_(false), 407 last_dialog_suppressed_(false),
406 geolocation_service_context_(new GeolocationServiceContext()), 408 geolocation_service_context_(new GeolocationServiceContext()),
407 accessibility_mode_( 409 accessibility_mode_(
408 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), 410 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 #if !defined(OS_MACOSX) 1582 #if !defined(OS_MACOSX)
1581 // On platforms other than Mac, control+mousewheel may change zoom. On Mac, 1583 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1582 // this isn't done for two reasons: 1584 // this isn't done for two reasons:
1583 // -the OS already has a gesture to do this through pinch-zoom 1585 // -the OS already has a gesture to do this through pinch-zoom
1584 // -if a user starts an inertial scroll, let's go, and presses control 1586 // -if a user starts an inertial scroll, let's go, and presses control
1585 // (i.e. control+tab) then the OS's buffered scroll events will come in 1587 // (i.e. control+tab) then the OS's buffered scroll events will come in
1586 // with control key set which isn't what the user wants 1588 // with control key set which isn't what the user wants
1587 if (delegate_ && event.wheelTicksY && 1589 if (delegate_ && event.wheelTicksY &&
1588 (event.modifiers & blink::WebInputEvent::ControlKey) && 1590 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1589 !event.canScroll) { 1591 !event.canScroll) {
1590 delegate_->ContentsZoomChange(event.wheelTicksY > 0); 1592 // Count only integer cumulative scrolls as zoom events; this handles
1593 // smooth scroll and regular scroll device behavior.
1594 zoom_scroll_remainder_ += event.wheelTicksY;
1595 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1596 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1597 if (whole_zoom_scroll_remainder_ != 0) {
1598 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1599 }
1591 return true; 1600 return true;
1592 } 1601 }
1593 #endif 1602 #endif
1594 return false; 1603 return false;
1595 } 1604 }
1596 1605
1597 bool WebContentsImpl::PreHandleGestureEvent( 1606 bool WebContentsImpl::PreHandleGestureEvent(
1598 const blink::WebGestureEvent& event) { 1607 const blink::WebGestureEvent& event) {
1599 return delegate_ && delegate_->PreHandleGestureEvent(this, event); 1608 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
1600 } 1609 }
(...skipping 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4721 const WebContentsObserver::MediaPlayerId& id) { 4730 const WebContentsObserver::MediaPlayerId& id) {
4722 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); 4731 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4723 } 4732 }
4724 4733
4725 void WebContentsImpl::MediaStoppedPlaying( 4734 void WebContentsImpl::MediaStoppedPlaying(
4726 const WebContentsObserver::MediaPlayerId& id) { 4735 const WebContentsObserver::MediaPlayerId& id) {
4727 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); 4736 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4728 } 4737 }
4729 4738
4730 } // namespace content 4739 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698