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

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

Issue 7618036: mac: Only let two-finger-scrolling trigger history if web doesn't swallow gesture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TestRenderViewHost Created 9 years, 4 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 8
9 #include <cmath> 9 #include <cmath>
10 #include <numeric> 10 #include <numeric>
(...skipping 25 matching lines...) Expand all
36 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 36 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
37 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" 37 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
38 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" 38 #import "chrome/browser/ui/cocoa/dev_tools_controller.h"
39 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 39 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
40 #import "chrome/browser/ui/cocoa/event_utils.h" 40 #import "chrome/browser/ui/cocoa/event_utils.h"
41 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 41 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
42 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 42 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
43 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 43 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
44 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 44 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
45 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 45 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
46 #import "chrome/browser/ui/cocoa/gesture_utils.h"
47 #import "chrome/browser/ui/cocoa/image_utils.h" 46 #import "chrome/browser/ui/cocoa/image_utils.h"
48 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 47 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
49 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 48 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
50 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" 49 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
51 #import "chrome/browser/ui/cocoa/sidebar_controller.h" 50 #import "chrome/browser/ui/cocoa/sidebar_controller.h"
52 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 51 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
53 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" 52 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h"
54 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" 53 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
55 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" 54 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
56 #import "chrome/browser/ui/cocoa/tabpose_window.h" 55 #import "chrome/browser/ui/cocoa/tabpose_window.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 @interface NSWindow (NSPrivateApis) 149 @interface NSWindow (NSPrivateApis)
151 // Note: These functions are private, use -[NSObject respondsToSelector:] 150 // Note: These functions are private, use -[NSObject respondsToSelector:]
152 // before calling them. 151 // before calling them.
153 152
154 - (void)setBottomCornerRounded:(BOOL)rounded; 153 - (void)setBottomCornerRounded:(BOOL)rounded;
155 154
156 - (NSRect)_growBoxRect; 155 - (NSRect)_growBoxRect;
157 156
158 @end 157 @end
159 158
160 // Forward-declare symbols that are part of the 10.6 SDK.
161 #if !defined(MAC_OS_X_VERSION_10_6) || \
162 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
163
164 enum {
165 NSTouchPhaseBegan = 1U << 0,
166 NSTouchPhaseMoved = 1U << 1,
167 NSTouchPhaseStationary = 1U << 2,
168 NSTouchPhaseEnded = 1U << 3,
169 NSTouchPhaseCancelled = 1U << 4,
170 NSTouchPhaseTouching = NSTouchPhaseBegan | NSTouchPhaseMoved |
171 NSTouchPhaseStationary,
172 NSTouchPhaseAny = NSUIntegerMax
173 };
174 typedef NSUInteger NSTouchPhase;
175
176 @interface NSEvent (SnowLeopardDeclarations)
177 - (NSSet*)touchesMatchingPhase:(NSTouchPhase)phase inView:(NSView*)view;
178 @end
179
180 @interface NSTouch : NSObject
181 - (NSPoint)normalizedPosition;
182 - (id<NSObject, NSCopying>)identity;
183 @end
184
185 #endif // MAC_OS_X_VERSION_10_6
186
187 // Provide the forward-declarations of new 10.7 SDK symbols so they can be 159 // Provide the forward-declarations of new 10.7 SDK symbols so they can be
188 // called when building with the 10.5 SDK. 160 // called when building with the 10.5 SDK.
189 #if !defined(MAC_OS_X_VERSION_10_7) || \ 161 #if !defined(MAC_OS_X_VERSION_10_7) || \
190 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 162 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
191 163
192 enum { 164 enum {
193 NSWindowAnimationBehaviorDefault = 0, 165 NSWindowAnimationBehaviorDefault = 0,
194 NSWindowAnimationBehaviorNone = 2, 166 NSWindowAnimationBehaviorNone = 2,
195 NSWindowAnimationBehaviorDocumentWindow = 3, 167 NSWindowAnimationBehaviorDocumentWindow = 3,
196 NSWindowAnimationBehaviorUtilityWindow = 4, 168 NSWindowAnimationBehaviorUtilityWindow = 4,
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 command = IDC_ZOOM_MINUS; 1749 command = IDC_ZOOM_MINUS;
1778 } 1750 }
1779 1751
1780 if (command && browser_->command_updater()->IsCommandEnabled(command)) { 1752 if (command && browser_->command_updater()->IsCommandEnabled(command)) {
1781 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1; 1753 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1;
1782 browser_->ExecuteCommandWithDisposition(command, 1754 browser_->ExecuteCommandWithDisposition(command,
1783 event_utils::WindowOpenDispositionFromNSEvent(event)); 1755 event_utils::WindowOpenDispositionFromNSEvent(event));
1784 } 1756 }
1785 } 1757 }
1786 1758
1787 // Documented in 10.6+, but present starting in 10.5. Called at the beginning
1788 // of a gesture.
1789 - (void)beginGestureWithEvent:(NSEvent*)event {
1790 totalMagnifyGestureAmount_ = 0;
1791 currentZoomStepDelta_ = 0;
1792
1793 // On Lion, there's support controlled by a System Preference for two- and
1794 // three-finger navigational gestures. If set to allow three-finger gestures,
1795 // the system gesture recognizer will automatically call |-swipeWithEvent:|
1796 // and that will be handled as it would be on Snow Leopard. The two-finger
1797 // gesture does not do this, so it must be manually recognized. See the note
1798 // inside RecognizeTwoFingerGestures() for detailed information on the
1799 // interaction of the different preferences.
1800 if (!gesture_utils::RecognizeTwoFingerGestures())
1801 return;
1802 NSSet* touches = [event touchesMatchingPhase:NSTouchPhaseAny
1803 inView:nil];
1804 if ([touches count] >= 2) {
1805 twoFingerGestureTouches_.reset([[NSMutableDictionary alloc] init]);
1806 for (NSTouch* touch in touches) {
1807 [twoFingerGestureTouches_ setObject:touch forKey:touch.identity];
1808 }
1809 }
1810 }
1811
1812 - (void)endGestureWithEvent:(NSEvent*)event {
1813 // This method only needs to process gesture events for two-finger navigation.
1814 if (!twoFingerGestureTouches_.get())
1815 return;
1816
1817 // When a multi-touch gesture ends, only one touch will be in the "End" phase.
1818 // Other touches will be in "Moved" or "Unknown" phases. So long as one is
1819 // ended, which it is by virtue of this method being called, the gesture can
1820 // be committed so long as the magnitude is great enough.
1821 NSSet* touches = [event touchesMatchingPhase:NSTouchPhaseAny
1822 inView:nil];
1823
1824 // Store the touch data locally and reset the ivar so that new gestures can
1825 // begin.
1826 scoped_nsobject<NSDictionary> beginTouches(
1827 twoFingerGestureTouches_.release());
1828
1829 // Construct a vector of magnitudes. Since gesture events do not have the
1830 // |-deltaX| property set, this creates the X/Y magnitudes for each finger.
1831 std::vector<CGFloat> deltasX;
1832 std::vector<CGFloat> deltasY;
1833 for (NSTouch* touch in touches) {
1834 NSTouch* beginTouch = [beginTouches objectForKey:touch.identity];
1835 if (!beginTouch)
1836 continue;
1837
1838 // The |normalizedPosition| is scaled from (0, 1).
1839 NSPoint beginPoint = beginTouch.normalizedPosition;
1840 NSPoint endPoint = touch.normalizedPosition;
1841
1842 deltasX.push_back(endPoint.x - beginPoint.x);
1843 deltasY.push_back(endPoint.y - beginPoint.y);
1844 }
1845
1846 // Need at least two points to gesture.
1847 if (deltasX.size() < 2)
1848 return;
1849
1850 CGFloat sumX = std::accumulate(deltasX.begin(), deltasX.end(), 0.0f);
1851 CGFloat sumY = std::accumulate(deltasY.begin(), deltasY.end(), 0.0f);
1852
1853 // If the Y magnitude is greater than the X, then don't treat this as a
1854 // gesture. It was likely a vertical scroll instead.
1855 if (std::abs(sumY) > std::abs(sumX))
1856 return;
1857
1858 // On Lion, the user can choose to use a "natural" scroll direction with
1859 // inverted axes.
1860 if (gesture_utils::IsScrollDirectionInverted())
1861 sumX *= -1;
1862
1863 int command_id = 0;
1864 if (sumX > 0.3)
1865 command_id = IDC_FORWARD;
1866 else if (sumX < -0.3)
1867 command_id = IDC_BACK;
1868 else
1869 return;
1870
1871 if (browser_->command_updater()->IsCommandEnabled(command_id)) {
1872 browser_->ExecuteCommandWithDisposition(command_id,
1873 event_utils::WindowOpenDispositionFromNSEvent(event));
1874 }
1875 }
1876
1877 // Delegate method called when window is resized. 1759 // Delegate method called when window is resized.
1878 - (void)windowDidResize:(NSNotification*)notification { 1760 - (void)windowDidResize:(NSNotification*)notification {
1879 // Resize (and possibly move) the status bubble. Note that we may get called 1761 // Resize (and possibly move) the status bubble. Note that we may get called
1880 // when the status bubble does not exist. 1762 // when the status bubble does not exist.
1881 if (statusBubble_) { 1763 if (statusBubble_) {
1882 statusBubble_->UpdateSizeAndPosition(); 1764 statusBubble_->UpdateSizeAndPosition();
1883 } 1765 }
1884 1766
1885 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 1767 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
1886 if (TabContents* contents = browser_->GetSelectedTabContents()) { 1768 if (TabContents* contents = browser_->GetSelectedTabContents()) {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 2175
2294 - (BOOL)supportsBookmarkBar { 2176 - (BOOL)supportsBookmarkBar {
2295 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2177 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2296 } 2178 }
2297 2179
2298 - (BOOL)isTabbedWindow { 2180 - (BOOL)isTabbedWindow {
2299 return browser_->is_type_tabbed(); 2181 return browser_->is_type_tabbed();
2300 } 2182 }
2301 2183
2302 @end // @implementation BrowserWindowController(WindowType) 2184 @end // @implementation BrowserWindowController(WindowType)
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_win.cc ('k') | chrome/browser/ui/cocoa/gesture_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698