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 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <numeric> | 10 #include <numeric> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
14 #import "base/memory/scoped_nsobject.h" | 14 #import "base/memory/scoped_nsobject.h" |
15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" // IDC_* | 16 #include "chrome/app/chrome_command_ids.h" // IDC_* |
17 #include "chrome/browser/bookmarks/bookmark_editor.h" | 17 #include "chrome/browser/bookmarks/bookmark_editor.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/google/google_util.h" | 19 #include "chrome/browser/google/google_util.h" |
20 #include "chrome/browser/instant/instant_controller.h" | 20 #include "chrome/browser/instant/instant_controller.h" |
21 #include "chrome/browser/mac/closure_blocks_leopard_compat.h" | |
Mark Mentovai
2011/08/15 14:43:57
Remove this from this file. You haven’t used any ^
Nico
2011/08/15 16:39:46
AOn 2011/08/15 14:43:57, Mark Mentovai wrote:
| |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_info_cache.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/sync_ui_util_mac.h" | 26 #include "chrome/browser/sync/sync_ui_util_mac.h" |
26 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" | 27 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
27 #include "chrome/browser/tabs/tab_strip_model.h" | 28 #include "chrome/browser/tabs/tab_strip_model.h" |
28 #include "chrome/browser/themes/theme_service.h" | 29 #include "chrome/browser/themes/theme_service.h" |
29 #include "chrome/browser/themes/theme_service_factory.h" | 30 #include "chrome/browser/themes/theme_service_factory.h" |
30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
32 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 33 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
33 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 34 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
34 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 35 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
35 #import "chrome/browser/ui/cocoa/browser/avatar_button.h" | 36 #import "chrome/browser/ui/cocoa/browser/avatar_button.h" |
36 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 37 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
37 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 38 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
38 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 39 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
39 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 40 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
40 #import "chrome/browser/ui/cocoa/event_utils.h" | 41 #import "chrome/browser/ui/cocoa/event_utils.h" |
41 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 42 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
42 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 43 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
43 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 44 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
44 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 45 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
45 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 46 #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" | 47 #import "chrome/browser/ui/cocoa/image_utils.h" |
48 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 48 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
49 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 49 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
50 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 50 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
51 #import "chrome/browser/ui/cocoa/sidebar_controller.h" | 51 #import "chrome/browser/ui/cocoa/sidebar_controller.h" |
52 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 52 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
53 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" | 53 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" |
54 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 54 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
55 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 55 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
56 #import "chrome/browser/ui/cocoa/tabpose_window.h" | 56 #import "chrome/browser/ui/cocoa/tabpose_window.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 @interface NSWindow (NSPrivateApis) | 150 @interface NSWindow (NSPrivateApis) |
151 // Note: These functions are private, use -[NSObject respondsToSelector:] | 151 // Note: These functions are private, use -[NSObject respondsToSelector:] |
152 // before calling them. | 152 // before calling them. |
153 | 153 |
154 - (void)setBottomCornerRounded:(BOOL)rounded; | 154 - (void)setBottomCornerRounded:(BOOL)rounded; |
155 | 155 |
156 - (NSRect)_growBoxRect; | 156 - (NSRect)_growBoxRect; |
157 | 157 |
158 @end | 158 @end |
159 | 159 |
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 | 160 // Provide the forward-declarations of new 10.7 SDK symbols so they can be |
188 // called when building with the 10.5 SDK. | 161 // called when building with the 10.5 SDK. |
189 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 162 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
190 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 163 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
191 | 164 |
192 enum { | 165 enum { |
193 NSWindowAnimationBehaviorDefault = 0, | 166 NSWindowAnimationBehaviorDefault = 0, |
194 NSWindowAnimationBehaviorNone = 2, | 167 NSWindowAnimationBehaviorNone = 2, |
195 NSWindowAnimationBehaviorDocumentWindow = 3, | 168 NSWindowAnimationBehaviorDocumentWindow = 3, |
196 NSWindowAnimationBehaviorUtilityWindow = 4, | 169 NSWindowAnimationBehaviorUtilityWindow = 4, |
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1777 command = IDC_ZOOM_MINUS; | 1750 command = IDC_ZOOM_MINUS; |
1778 } | 1751 } |
1779 | 1752 |
1780 if (command && browser_->command_updater()->IsCommandEnabled(command)) { | 1753 if (command && browser_->command_updater()->IsCommandEnabled(command)) { |
1781 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1; | 1754 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1; |
1782 browser_->ExecuteCommandWithDisposition(command, | 1755 browser_->ExecuteCommandWithDisposition(command, |
1783 event_utils::WindowOpenDispositionFromNSEvent(event)); | 1756 event_utils::WindowOpenDispositionFromNSEvent(event)); |
1784 } | 1757 } |
1785 } | 1758 } |
1786 | 1759 |
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. | 1760 // Delegate method called when window is resized. |
1878 - (void)windowDidResize:(NSNotification*)notification { | 1761 - (void)windowDidResize:(NSNotification*)notification { |
1879 // Resize (and possibly move) the status bubble. Note that we may get called | 1762 // Resize (and possibly move) the status bubble. Note that we may get called |
1880 // when the status bubble does not exist. | 1763 // when the status bubble does not exist. |
1881 if (statusBubble_) { | 1764 if (statusBubble_) { |
1882 statusBubble_->UpdateSizeAndPosition(); | 1765 statusBubble_->UpdateSizeAndPosition(); |
1883 } | 1766 } |
1884 | 1767 |
1885 // Let the selected RenderWidgetHostView know, so that it can tell plugins. | 1768 // Let the selected RenderWidgetHostView know, so that it can tell plugins. |
1886 if (TabContents* contents = browser_->GetSelectedTabContents()) { | 1769 if (TabContents* contents = browser_->GetSelectedTabContents()) { |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2293 | 2176 |
2294 - (BOOL)supportsBookmarkBar { | 2177 - (BOOL)supportsBookmarkBar { |
2295 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2178 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2296 } | 2179 } |
2297 | 2180 |
2298 - (BOOL)isTabbedWindow { | 2181 - (BOOL)isTabbedWindow { |
2299 return browser_->is_type_tabbed(); | 2182 return browser_->is_type_tabbed(); |
2300 } | 2183 } |
2301 | 2184 |
2302 @end // @implementation BrowserWindowController(WindowType) | 2185 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |