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 #include <numeric> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 33 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
34 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 34 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
35 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 35 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
36 #import "chrome/browser/ui/cocoa/event_utils.h" | 36 #import "chrome/browser/ui/cocoa/event_utils.h" |
37 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 37 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
38 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 38 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
39 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 39 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
40 #import "chrome/browser/ui/cocoa/focus_tracker.h" | 40 #import "chrome/browser/ui/cocoa/focus_tracker.h" |
41 #import "chrome/browser/ui/cocoa/fullscreen_controller.h" | 41 #import "chrome/browser/ui/cocoa/fullscreen_controller.h" |
42 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 42 #import "chrome/browser/ui/cocoa/fullscreen_window.h" |
| 43 #import "chrome/browser/ui/cocoa/gesture_utils.h" |
43 #import "chrome/browser/ui/cocoa/image_utils.h" | 44 #import "chrome/browser/ui/cocoa/image_utils.h" |
44 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 45 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
45 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
46 #import "chrome/browser/ui/cocoa/sidebar_controller.h" | 47 #import "chrome/browser/ui/cocoa/sidebar_controller.h" |
47 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 48 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
48 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" | 49 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" |
49 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 50 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
50 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 51 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
51 #import "chrome/browser/ui/cocoa/tabpose_window.h" | 52 #import "chrome/browser/ui/cocoa/tabpose_window.h" |
52 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 53 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 // The button shouldn't do anything in incognito. | 1667 // The button shouldn't do anything in incognito. |
1667 [avatarButton_ setOpenMenuOnClick:!browser_->profile()->IsOffTheRecord()]; | 1668 [avatarButton_ setOpenMenuOnClick:!browser_->profile()->IsOffTheRecord()]; |
1668 | 1669 |
1669 // Install the view. | 1670 // Install the view. |
1670 [[[[self window] contentView] superview] addSubview:avatarButton_]; | 1671 [[[[self window] contentView] superview] addSubview:avatarButton_]; |
1671 } | 1672 } |
1672 | 1673 |
1673 // Documented in 10.6+, but present starting in 10.5. Called when we get a | 1674 // Documented in 10.6+, but present starting in 10.5. Called when we get a |
1674 // three-finger swipe. | 1675 // three-finger swipe. |
1675 - (void)swipeWithEvent:(NSEvent*)event { | 1676 - (void)swipeWithEvent:(NSEvent*)event { |
| 1677 CGFloat deltaX = [event deltaX]; |
| 1678 CGFloat deltaY = [event deltaY]; |
| 1679 |
| 1680 // On Lion, the user can choose to use a "natural" scroll direction with |
| 1681 // inverted axes. |
| 1682 if (gesture_utils::IsScrollDirectionInverted()) { |
| 1683 deltaX *= -1; |
| 1684 deltaY *= -1; |
| 1685 } |
| 1686 |
1676 // Map forwards and backwards to history; left is positive, right is negative. | 1687 // Map forwards and backwards to history; left is positive, right is negative. |
1677 unsigned int command = 0; | 1688 unsigned int command = 0; |
1678 if ([event deltaX] > 0.5) { | 1689 if (deltaX > 0.5) { |
1679 command = IDC_BACK; | 1690 command = IDC_BACK; |
1680 } else if ([event deltaX] < -0.5) { | 1691 } else if (deltaX < -0.5) { |
1681 command = IDC_FORWARD; | 1692 command = IDC_FORWARD; |
1682 } else if ([event deltaY] > 0.5) { | 1693 } else if (deltaY > 0.5) { |
1683 // TODO(pinkerton): figure out page-up, http://crbug.com/16305 | 1694 // TODO(pinkerton): figure out page-up, http://crbug.com/16305 |
1684 } else if ([event deltaY] < -0.5) { | 1695 } else if ([event deltaY] < -0.5) { |
1685 // TODO(pinkerton): figure out page-down, http://crbug.com/16305 | 1696 // TODO(pinkerton): figure out page-down, http://crbug.com/16305 |
1686 browser_->ExecuteCommand(IDC_TABPOSE); | 1697 browser_->ExecuteCommand(IDC_TABPOSE); |
1687 } | 1698 } |
1688 | 1699 |
1689 // Ensure the command is valid first (ExecuteCommand() won't do that) and | 1700 // Ensure the command is valid first (ExecuteCommand() won't do that) and |
1690 // then make it so. | 1701 // then make it so. |
1691 if (browser_->command_updater()->IsCommandEnabled(command)) | 1702 if (browser_->command_updater()->IsCommandEnabled(command)) |
1692 browser_->ExecuteCommandWithDisposition(command, | 1703 browser_->ExecuteCommandWithDisposition(command, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 // of a gesture. | 1742 // of a gesture. |
1732 - (void)beginGestureWithEvent:(NSEvent*)event { | 1743 - (void)beginGestureWithEvent:(NSEvent*)event { |
1733 totalMagnifyGestureAmount_ = 0; | 1744 totalMagnifyGestureAmount_ = 0; |
1734 currentZoomStepDelta_ = 0; | 1745 currentZoomStepDelta_ = 0; |
1735 | 1746 |
1736 // On Lion, there's support controlled by a System Preference for two- and | 1747 // On Lion, there's support controlled by a System Preference for two- and |
1737 // three-finger navigational gestures. If set to allow three-finger gestures, | 1748 // three-finger navigational gestures. If set to allow three-finger gestures, |
1738 // the system gesture recognizer will automatically call |-swipeWithEvent:| | 1749 // the system gesture recognizer will automatically call |-swipeWithEvent:| |
1739 // and that will be handled as it would be on Snow Leopard. The two-finger | 1750 // and that will be handled as it would be on Snow Leopard. The two-finger |
1740 // gesture does not do this, so it must be manually recognized. See the note | 1751 // gesture does not do this, so it must be manually recognized. See the note |
1741 // inside |-recognizeTwoFingerGestures| for detailed information on the | 1752 // inside RecognizeTwoFingerGestures() for detailed information on the |
1742 // interaction of the different preferences. | 1753 // interaction of the different preferences. |
1743 if (![self recognizeTwoFingerGestures]) | 1754 if (!gesture_utils::RecognizeTwoFingerGestures()) |
1744 return; | 1755 return; |
1745 NSSet* touches = [event touchesMatchingPhase:NSTouchPhaseAny | 1756 NSSet* touches = [event touchesMatchingPhase:NSTouchPhaseAny |
1746 inView:nil]; | 1757 inView:nil]; |
1747 if ([touches count] >= 2) { | 1758 if ([touches count] >= 2) { |
1748 twoFingerGestureTouches_.reset([[NSMutableDictionary alloc] init]); | 1759 twoFingerGestureTouches_.reset([[NSMutableDictionary alloc] init]); |
1749 for (NSTouch* touch in touches) { | 1760 for (NSTouch* touch in touches) { |
1750 [twoFingerGestureTouches_ setObject:touch forKey:touch.identity]; | 1761 [twoFingerGestureTouches_ setObject:touch forKey:touch.identity]; |
1751 } | 1762 } |
1752 } | 1763 } |
1753 } | 1764 } |
(...skipping 26 matching lines...) Expand all Loading... |
1780 // The |normalizedPosition| is scaled from (0,1). | 1791 // The |normalizedPosition| is scaled from (0,1). |
1781 magnitudes.push_back(touch.normalizedPosition.x - | 1792 magnitudes.push_back(touch.normalizedPosition.x - |
1782 beginTouch.normalizedPosition.x); | 1793 beginTouch.normalizedPosition.x); |
1783 } | 1794 } |
1784 | 1795 |
1785 // Need at least two points to gesture. | 1796 // Need at least two points to gesture. |
1786 if (magnitudes.size() < 2) | 1797 if (magnitudes.size() < 2) |
1787 return; | 1798 return; |
1788 | 1799 |
1789 CGFloat sum = std::accumulate(magnitudes.begin(), magnitudes.end(), 0.0f); | 1800 CGFloat sum = std::accumulate(magnitudes.begin(), magnitudes.end(), 0.0f); |
| 1801 // On Lion, the user can choose to use a "natural" scroll direction with |
| 1802 // inverted axes. |
| 1803 if (gesture_utils::IsScrollDirectionInverted()) |
| 1804 sum *= -1; |
| 1805 |
1790 int command_id = 0; | 1806 int command_id = 0; |
1791 if (sum > 0.3) | 1807 if (sum > 0.3) |
1792 command_id = IDC_FORWARD; | 1808 command_id = IDC_FORWARD; |
1793 else if (sum < -0.3) | 1809 else if (sum < -0.3) |
1794 command_id = IDC_BACK; | 1810 command_id = IDC_BACK; |
1795 else | 1811 else |
1796 return; | 1812 return; |
1797 | 1813 |
1798 if (browser_->command_updater()->IsCommandEnabled(command_id)) { | 1814 if (browser_->command_updater()->IsCommandEnabled(command_id)) { |
1799 browser_->ExecuteCommandWithDisposition(command_id, | 1815 browser_->ExecuteCommandWithDisposition(command_id, |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2283 | 2299 |
2284 - (BOOL)supportsBookmarkBar { | 2300 - (BOOL)supportsBookmarkBar { |
2285 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2301 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2286 } | 2302 } |
2287 | 2303 |
2288 - (BOOL)isTabbedWindow { | 2304 - (BOOL)isTabbedWindow { |
2289 return browser_->is_type_tabbed(); | 2305 return browser_->is_type_tabbed(); |
2290 } | 2306 } |
2291 | 2307 |
2292 @end // @implementation BrowserWindowController(WindowType) | 2308 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |