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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 7461080: [Mac] Respect natural/inverted scroll direction on Lion when gesturing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #include <numeric> 8 #include <numeric>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 // The button shouldn't do anything in incognito. 1666 // The button shouldn't do anything in incognito.
1667 [avatarButton_ setOpenMenuOnClick:!browser_->profile()->IsOffTheRecord()]; 1667 [avatarButton_ setOpenMenuOnClick:!browser_->profile()->IsOffTheRecord()];
1668 1668
1669 // Install the view. 1669 // Install the view.
1670 [[[[self window] contentView] superview] addSubview:avatarButton_]; 1670 [[[[self window] contentView] superview] addSubview:avatarButton_];
1671 } 1671 }
1672 1672
1673 // Documented in 10.6+, but present starting in 10.5. Called when we get a 1673 // Documented in 10.6+, but present starting in 10.5. Called when we get a
1674 // three-finger swipe. 1674 // three-finger swipe.
1675 - (void)swipeWithEvent:(NSEvent*)event { 1675 - (void)swipeWithEvent:(NSEvent*)event {
1676 CGFloat deltaX = [event deltaX];
1677 CGFloat deltaY = [event deltaY];
1678
1679 // On Lion, the user can choose to use a "natural" scroll direction with
1680 // inverted axes.
1681 if ([self isScrollDirectionInverted]) {
1682 deltaX *= -1;
1683 deltaY *= -1;
1684 }
1685
1676 // Map forwards and backwards to history; left is positive, right is negative. 1686 // Map forwards and backwards to history; left is positive, right is negative.
1677 unsigned int command = 0; 1687 unsigned int command = 0;
1678 if ([event deltaX] > 0.5) { 1688 if (deltaX > 0.5) {
1679 command = IDC_BACK; 1689 command = IDC_BACK;
1680 } else if ([event deltaX] < -0.5) { 1690 } else if (deltaX < -0.5) {
1681 command = IDC_FORWARD; 1691 command = IDC_FORWARD;
1682 } else if ([event deltaY] > 0.5) { 1692 } else if (deltaY > 0.5) {
1683 // TODO(pinkerton): figure out page-up, http://crbug.com/16305 1693 // TODO(pinkerton): figure out page-up, http://crbug.com/16305
1684 } else if ([event deltaY] < -0.5) { 1694 } else if ([event deltaY] < -0.5) {
1685 // TODO(pinkerton): figure out page-down, http://crbug.com/16305 1695 // TODO(pinkerton): figure out page-down, http://crbug.com/16305
1686 browser_->ExecuteCommand(IDC_TABPOSE); 1696 browser_->ExecuteCommand(IDC_TABPOSE);
1687 } 1697 }
1688 1698
1689 // Ensure the command is valid first (ExecuteCommand() won't do that) and 1699 // Ensure the command is valid first (ExecuteCommand() won't do that) and
1690 // then make it so. 1700 // then make it so.
1691 if (browser_->command_updater()->IsCommandEnabled(command)) 1701 if (browser_->command_updater()->IsCommandEnabled(command))
1692 browser_->ExecuteCommandWithDisposition(command, 1702 browser_->ExecuteCommandWithDisposition(command,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 // The |normalizedPosition| is scaled from (0,1). 1790 // The |normalizedPosition| is scaled from (0,1).
1781 magnitudes.push_back(touch.normalizedPosition.x - 1791 magnitudes.push_back(touch.normalizedPosition.x -
1782 beginTouch.normalizedPosition.x); 1792 beginTouch.normalizedPosition.x);
1783 } 1793 }
1784 1794
1785 // Need at least two points to gesture. 1795 // Need at least two points to gesture.
1786 if (magnitudes.size() < 2) 1796 if (magnitudes.size() < 2)
1787 return; 1797 return;
1788 1798
1789 CGFloat sum = std::accumulate(magnitudes.begin(), magnitudes.end(), 0.0f); 1799 CGFloat sum = std::accumulate(magnitudes.begin(), magnitudes.end(), 0.0f);
1800 // On Lion, the user can choose to use a "natural" scroll direction with
1801 // inverted axes.
1802 if ([self isScrollDirectionInverted])
1803 sum *= -1;
1804
1790 int command_id = 0; 1805 int command_id = 0;
1791 if (sum > 0.3) 1806 if (sum > 0.3)
1792 command_id = IDC_FORWARD; 1807 command_id = IDC_FORWARD;
1793 else if (sum < -0.3) 1808 else if (sum < -0.3)
1794 command_id = IDC_BACK; 1809 command_id = IDC_BACK;
1795 else 1810 else
1796 return; 1811 return;
1797 1812
1798 if (browser_->command_updater()->IsCommandEnabled(command_id)) { 1813 if (browser_->command_updater()->IsCommandEnabled(command_id)) {
1799 browser_->ExecuteCommandWithDisposition(command_id, 1814 browser_->ExecuteCommandWithDisposition(command_id,
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 2298
2284 - (BOOL)supportsBookmarkBar { 2299 - (BOOL)supportsBookmarkBar {
2285 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2300 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2286 } 2301 }
2287 2302
2288 - (BOOL)isTabbedWindow { 2303 - (BOOL)isTabbedWindow {
2289 return browser_->is_type_tabbed(); 2304 return browser_->is_type_tabbed();
2290 } 2305 }
2291 2306
2292 @end // @implementation BrowserWindowController(WindowType) 2307 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698