OLD | NEW |
---|---|
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 | 9 |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
11 #import "base/memory/scoped_nsobject.h" | 12 #import "base/memory/scoped_nsobject.h" |
12 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" // IDC_* | 14 #include "chrome/app/chrome_command_ids.h" // IDC_* |
14 #include "chrome/browser/bookmarks/bookmark_editor.h" | 15 #include "chrome/browser/bookmarks/bookmark_editor.h" |
15 #include "chrome/browser/google/google_util.h" | 16 #include "chrome/browser/google/google_util.h" |
16 #include "chrome/browser/instant/instant_controller.h" | 17 #include "chrome/browser/instant/instant_controller.h" |
17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // animated. Basically, the BWC doesn't see the global picture, but it sees | 135 // animated. Basically, the BWC doesn't see the global picture, but it sees |
135 // grows and shrinks in small increments (as dictated by the animation). Thus | 136 // grows and shrinks in small increments (as dictated by the animation). Thus |
136 // window growth/shrinkage (at the top/bottom) have to be tracked incrementally. | 137 // window growth/shrinkage (at the top/bottom) have to be tracked incrementally. |
137 // Allowing shrinking from the zoomed state also requires tracking: We check on | 138 // Allowing shrinking from the zoomed state also requires tracking: We check on |
138 // any shrink whether we're both zoomed and have previously grown -- if so, we | 139 // any shrink whether we're both zoomed and have previously grown -- if so, we |
139 // set a flag, and constrain any resize by the allowed amounts. On further | 140 // set a flag, and constrain any resize by the allowed amounts. On further |
140 // shrinks, we check the flag (since the size/position of the window will no | 141 // shrinks, we check the flag (since the size/position of the window will no |
141 // longer indicate that the window is shrinking from an apparent zoomed state) | 142 // longer indicate that the window is shrinking from an apparent zoomed state) |
142 // and if it's set we continue to constrain the resize. | 143 // and if it's set we continue to constrain the resize. |
143 | 144 |
144 | |
145 @interface NSWindow (NSPrivateApis) | 145 @interface NSWindow (NSPrivateApis) |
146 // Note: These functions are private, use -[NSObject respondsToSelector:] | 146 // Note: These functions are private, use -[NSObject respondsToSelector:] |
147 // before calling them. | 147 // before calling them. |
148 | 148 |
149 - (void)setBottomCornerRounded:(BOOL)rounded; | 149 - (void)setBottomCornerRounded:(BOOL)rounded; |
150 | 150 |
151 - (NSRect)_growBoxRect; | 151 - (NSRect)_growBoxRect; |
152 | 152 |
153 @end | 153 @end |
154 | 154 |
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1698 browser_->ExecuteCommandWithDisposition(command, | 1698 browser_->ExecuteCommandWithDisposition(command, |
1699 event_utils::WindowOpenDispositionFromNSEvent(event)); | 1699 event_utils::WindowOpenDispositionFromNSEvent(event)); |
1700 } | 1700 } |
1701 } | 1701 } |
1702 | 1702 |
1703 // Documented in 10.6+, but present starting in 10.5. Called at the beginning | 1703 // Documented in 10.6+, but present starting in 10.5. Called at the beginning |
1704 // of a gesture. | 1704 // of a gesture. |
1705 - (void)beginGestureWithEvent:(NSEvent*)event { | 1705 - (void)beginGestureWithEvent:(NSEvent*)event { |
1706 totalMagnifyGestureAmount_ = 0; | 1706 totalMagnifyGestureAmount_ = 0; |
1707 currentZoomStepDelta_ = 0; | 1707 currentZoomStepDelta_ = 0; |
1708 | |
1709 // On Lion, there's support controlled by a System Preference for two- and | |
1710 // three-finger navigational gestures. If set to allow three-finger gestures, | |
1711 // the system gesture recognizer will automatically call |-swipeWithEvent:| | |
1712 // and that will be handled as it would be on Snow Leopard. The two-finger | |
1713 // gesture does not do this, so it must be manually recogniezd. See the note | |
Nico
2011/07/22 20:21:14
recognized
mnemonic: "i before e except around z"
Robert Sesek
2011/07/22 20:26:23
I fixed sooo many typos before I uploaded this. I'
| |
1714 // inside |-recognizeTwoFingerGestures| for detailed information on the | |
1715 // interaction of the different preferences. | |
1716 NSSet* touches = [event touchesMatchingPhase:NSTouchPhaseAny | |
1717 inView:nil]; | |
1718 if ([self recognizeTwoFingerGestures] && [touches count] >= 2) { | |
1719 twoFingerGestureTouches_.reset([[NSMutableDictionary alloc] init]); | |
1720 for (NSTouch* touch in touches) { | |
1721 [twoFingerGestureTouches_ setObject:touch forKey:touch.identity]; | |
1722 } | |
1723 } | |
1724 } | |
1725 | |
1726 - (void)endGestureWithEvent:(NSEvent*)event { | |
1727 // This method only needs to process gesture events for two-finger navigation. | |
1728 if (!twoFingerGestureTouches_.get()) | |
1729 return; | |
1730 | |
1731 // When a multi-touch gesture ends, only one touch will be in the "End" phase. | |
1732 // Other touches will be in "Moved" or "Unknown" phases. So long as one is | |
1733 // ended, which it is by virtue of this method being called, the gesture can | |
1734 // be committed so long as the magnitude is great enough. | |
Nico
2011/07/22 20:21:14
So two-finger drag followed by lifting one finger
Robert Sesek
2011/07/22 20:26:23
Yeah; it's funky but is also what Safari does. I t
| |
1735 NSSet* touches = [event touchesMatchingPhase:NSTouchPhaseAny | |
1736 inView:nil]; | |
1737 | |
1738 // Store the touch data locally and reset the ivar so that new gestures can | |
1739 // begin. | |
1740 scoped_nsobject<NSDictionary> beginTouches( | |
1741 twoFingerGestureTouches_.release()); | |
1742 | |
1743 // Construct a vector of magnitudes. Since gesture events do not have the | |
1744 // |-deltaX| property set, this creates the X magnitude for each finger. | |
1745 std::vector<CGFloat> magnitudes; | |
1746 for (NSTouch* touch in touches) { | |
1747 NSTouch* beginTouch = [beginTouches objectForKey:touch.identity]; | |
1748 if (!beginTouch) | |
1749 continue; | |
Nico
2011/07/22 20:21:14
Does this ever happen in practice? I'd assume ever
Robert Sesek
2011/07/22 20:26:23
Yes, it can. You can add new fingers mid-gesture.
| |
1750 | |
1751 // The |normalizedPosition| scaled from (0,1). | |
Nico
2011/07/22 20:21:14
"is scaled"?
Robert Sesek
2011/07/22 20:26:23
Done.
| |
1752 magnitudes.push_back(touch.normalizedPosition.x - | |
1753 beginTouch.normalizedPosition.x); | |
1754 } | |
1755 | |
1756 // Need at least two points to gesture. | |
1757 if (magnitudes.size() < 2) | |
1758 return; | |
1759 | |
1760 CGFloat sum = std::accumulate(magnitudes.begin(), magnitudes.end(), 0.0f); | |
1761 int command_id = 0; | |
1762 if (sum > 0.3) | |
1763 command_id = IDC_FORWARD; | |
1764 else if (sum < -0.3) | |
1765 command_id = IDC_BACK; | |
1766 else | |
1767 return; | |
1768 | |
1769 if (browser_->command_updater()->IsCommandEnabled(command_id)) { | |
1770 browser_->ExecuteCommandWithDisposition(command_id, | |
1771 event_utils::WindowOpenDispositionFromNSEvent(event)); | |
1772 } | |
1708 } | 1773 } |
1709 | 1774 |
1710 // Delegate method called when window is resized. | 1775 // Delegate method called when window is resized. |
1711 - (void)windowDidResize:(NSNotification*)notification { | 1776 - (void)windowDidResize:(NSNotification*)notification { |
1712 // Resize (and possibly move) the status bubble. Note that we may get called | 1777 // Resize (and possibly move) the status bubble. Note that we may get called |
1713 // when the status bubble does not exist. | 1778 // when the status bubble does not exist. |
1714 if (statusBubble_) { | 1779 if (statusBubble_) { |
1715 statusBubble_->UpdateSizeAndPosition(); | 1780 statusBubble_->UpdateSizeAndPosition(); |
1716 } | 1781 } |
1717 | 1782 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2189 | 2254 |
2190 - (BOOL)supportsBookmarkBar { | 2255 - (BOOL)supportsBookmarkBar { |
2191 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2256 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2192 } | 2257 } |
2193 | 2258 |
2194 - (BOOL)isTabbedWindow { | 2259 - (BOOL)isTabbedWindow { |
2195 return browser_->is_type_tabbed(); | 2260 return browser_->is_type_tabbed(); |
2196 } | 2261 } |
2197 | 2262 |
2198 @end // @implementation BrowserWindowController(WindowType) | 2263 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |