Commit a7aa5167 authored by andresantoso's avatar andresantoso Committed by Commit bot

MacViews: Support continuous scrolling and horizontal scrolling

Add support for continuous devices (Magic Mouse and trackpad) using NSEvent
APIs introduced in 10.7.
Tweak ScrollView/ScrollBar to allow horizontal scrolling from MouseWheel
events.

BUG=363529

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

Cr-Commit-Position: refs/heads/master@{#293038}
parent 683b1856
......@@ -70,6 +70,7 @@ typedef NSUInteger NSWindowButton;
- (NSEventPhase)momentumPhase;
- (NSEventPhase)phase;
- (BOOL)hasPreciseScrollingDeltas;
- (CGFloat)scrollingDeltaX;
- (CGFloat)scrollingDeltaY;
- (void)trackSwipeEventWithOptions:(NSEventSwipeTrackingOptions)options
......
......@@ -6,6 +6,8 @@
#include <Cocoa/Cocoa.h>
#import "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "build/build_config.h"
......@@ -130,14 +132,24 @@ int GetChangedMouseButtonFlagsFromNative(
}
gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& event) {
// Empirically, a value of 0.1 is typical for one mousewheel click. Positive
// values when scrolling up or to the left. Scrolling quickly results in a
// higher delta per click, up to about 15.0. (Quartz documentation suggests
// +/-10).
// Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120).
const CGFloat kWheelDeltaMultiplier = 1000;
return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX],
kWheelDeltaMultiplier * [event deltaY]);
if ([event respondsToSelector:@selector(hasPreciseScrollingDeltas)] &&
[event hasPreciseScrollingDeltas]) {
// Handle continuous scrolling devices such as a Magic Mouse or a trackpad.
// -scrollingDelta{X|Y} have float return types but they return values that
// are already rounded to integers.
// The values are the same as the values returned from calling
// CGEventGetIntegerValueField(kCGScrollWheelEventPointDeltaAxis{1|2}).
return gfx::Vector2d([event scrollingDeltaX], [event scrollingDeltaY]);
} else {
// Empirically, a value of 0.1 is typical for one mousewheel click. Positive
// values when scrolling up or to the left. Scrolling quickly results in a
// higher delta per click, up to about 15.0. (Quartz documentation suggests
// +/-10).
// Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120).
const CGFloat kWheelDeltaMultiplier = 1000;
return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX],
kWheelDeltaMultiplier * [event deltaY]);
}
}
base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
......
......@@ -149,7 +149,11 @@
}
- (void)scrollWheel:(NSEvent*)theEvent {
[self handleMouseEvent:theEvent];
if (!hostedView_)
return;
ui::MouseWheelEvent event(theEvent);
hostedView_->GetWidget()->OnMouseEvent(&event);
}
- (void)deleteBackward:(id)sender {
......
......@@ -354,12 +354,12 @@ bool ScrollView::OnKeyPressed(const ui::KeyEvent& event) {
bool ScrollView::OnMouseWheel(const ui::MouseWheelEvent& e) {
bool processed = false;
// Give vertical scrollbar priority
if (vert_sb_->visible())
processed = vert_sb_->OnMouseWheel(e);
if (!processed && horiz_sb_->visible())
processed = horiz_sb_->OnMouseWheel(e);
if (horiz_sb_->visible())
processed = horiz_sb_->OnMouseWheel(e) || processed;
return processed;
}
......
......@@ -194,7 +194,7 @@ bool BaseScrollBar::OnKeyPressed(const ui::KeyEvent& event) {
}
bool BaseScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) {
ScrollByContentsOffset(event.y_offset());
OnScroll(event.x_offset(), event.y_offset());
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment