Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/tab_view.h" | 5 #import "chrome/browser/cocoa/tab_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac_util.h" | |
| 8 #include "base/nsimage_cache_mac.h" | 9 #include "base/nsimage_cache_mac.h" |
| 10 #include "base/scoped_cftyperef.h" | |
| 9 #include "chrome/browser/browser_theme_provider.h" | 11 #include "chrome/browser/browser_theme_provider.h" |
| 10 #import "chrome/browser/cocoa/tab_controller.h" | 12 #import "chrome/browser/cocoa/tab_controller.h" |
| 11 #import "chrome/browser/cocoa/tab_window_controller.h" | 13 #import "chrome/browser/cocoa/tab_window_controller.h" |
| 12 #import "chrome/browser/cocoa/themed_window.h" | 14 #import "chrome/browser/cocoa/themed_window.h" |
| 13 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // Constants for inset and control points for tab shape. | 19 // Constants for inset and control points for tab shape. |
| 18 const CGFloat kInsetMultiplier = 2.0/3.0; | 20 const CGFloat kInsetMultiplier = 2.0/3.0; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 39 // has moved less than the threshold, we want to close the tab. | 41 // has moved less than the threshold, we want to close the tab. |
| 40 const CGFloat kRapidCloseDist = 2.5; | 42 const CGFloat kRapidCloseDist = 2.5; |
| 41 | 43 |
| 42 } // namespace | 44 } // namespace |
| 43 | 45 |
| 44 @interface TabView(Private) | 46 @interface TabView(Private) |
| 45 | 47 |
| 46 - (void)resetLastGlowUpdateTime; | 48 - (void)resetLastGlowUpdateTime; |
| 47 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; | 49 - (NSTimeInterval)timeElapsedSinceLastGlowUpdate; |
| 48 - (void)adjustGlowValue; | 50 - (void)adjustGlowValue; |
| 51 // TODO(davidben): When we stop supporting 10.5, this can be removed. | |
| 52 - (int)getWorkspaceID:(NSWindow*)window useCache:(BOOL)useCache; | |
| 49 | 53 |
| 50 @end // TabView(Private) | 54 @end // TabView(Private) |
| 51 | 55 |
| 52 @implementation TabView | 56 @implementation TabView |
| 53 | 57 |
| 54 @synthesize state = state_; | 58 @synthesize state = state_; |
| 55 @synthesize hoverAlpha = hoverAlpha_; | 59 @synthesize hoverAlpha = hoverAlpha_; |
| 56 @synthesize alertAlpha = alertAlpha_; | 60 @synthesize alertAlpha = alertAlpha_; |
| 57 @synthesize closing = closing_; | 61 @synthesize closing = closing_; |
| 58 | 62 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 158 |
| 155 // Returns an array of controllers that could be a drop target, ordered front to | 159 // Returns an array of controllers that could be a drop target, ordered front to |
| 156 // back. It has to be of the appropriate class, and visible (obviously). Note | 160 // back. It has to be of the appropriate class, and visible (obviously). Note |
| 157 // that the window cannot be a target for itself. | 161 // that the window cannot be a target for itself. |
| 158 - (NSArray*)dropTargetsForController:(TabWindowController*)dragController { | 162 - (NSArray*)dropTargetsForController:(TabWindowController*)dragController { |
| 159 NSMutableArray* targets = [NSMutableArray array]; | 163 NSMutableArray* targets = [NSMutableArray array]; |
| 160 NSWindow* dragWindow = [dragController window]; | 164 NSWindow* dragWindow = [dragController window]; |
| 161 for (NSWindow* window in [NSApp orderedWindows]) { | 165 for (NSWindow* window in [NSApp orderedWindows]) { |
| 162 if (window == dragWindow) continue; | 166 if (window == dragWindow) continue; |
| 163 if (![window isVisible]) continue; | 167 if (![window isVisible]) continue; |
| 168 // Skip windows on the wrong space. | |
| 169 if ([window respondsToSelector:@selector(isOnActiveSpace)]) { | |
| 170 if (![window performSelector:@selector(isOnActiveSpace)]) | |
| 171 continue; | |
| 172 } else { | |
| 173 // TODO(davidben): When we stop supporting 10.5, this can be | |
| 174 // removed. | |
| 175 // | |
| 176 // We don't cache the workspace of |dragWindow| because it may | |
| 177 // move around spaces. | |
| 178 if ([self getWorkspaceID:dragWindow useCache:NO] != | |
| 179 [self getWorkspaceID:window useCache:YES]) | |
| 180 continue; | |
| 181 } | |
| 164 NSWindowController* controller = [window windowController]; | 182 NSWindowController* controller = [window windowController]; |
| 165 if ([controller isKindOfClass:[TabWindowController class]]) { | 183 if ([controller isKindOfClass:[TabWindowController class]]) { |
| 166 TabWindowController* realController = | 184 TabWindowController* realController = |
| 167 static_cast<TabWindowController*>(controller); | 185 static_cast<TabWindowController*>(controller); |
| 168 if ([realController canReceiveFrom:dragController]) | 186 if ([realController canReceiveFrom:dragController]) |
| 169 [targets addObject:controller]; | 187 [targets addObject:controller]; |
| 170 } | 188 } |
| 171 } | 189 } |
| 172 return targets; | 190 return targets; |
| 173 } | 191 } |
| 174 | 192 |
| 175 // Call to clear out transient weak references we hold during drags. | 193 // Call to clear out transient weak references we hold during drags. |
| 176 - (void)resetDragControllers { | 194 - (void)resetDragControllers { |
| 177 draggedController_ = nil; | 195 draggedController_ = nil; |
| 178 dragWindow_ = nil; | 196 dragWindow_ = nil; |
| 179 dragOverlay_ = nil; | 197 dragOverlay_ = nil; |
| 180 sourceController_ = nil; | 198 sourceController_ = nil; |
| 181 sourceWindow_ = nil; | 199 sourceWindow_ = nil; |
| 182 targetController_ = nil; | 200 targetController_ = nil; |
| 201 workspaceIDCache_.clear(); | |
| 183 } | 202 } |
| 184 | 203 |
| 185 // Sets whether the window background should be visible or invisible when | 204 // Sets whether the window background should be visible or invisible when |
| 186 // dragging a tab. The background should be invisible when the mouse is over a | 205 // dragging a tab. The background should be invisible when the mouse is over a |
| 187 // potential drop target for the tab (the tab strip). It should be visible when | 206 // potential drop target for the tab (the tab strip). It should be visible when |
| 188 // there's no drop target so the window looks more fully realized and ready to | 207 // there's no drop target so the window looks more fully realized and ready to |
| 189 // become a stand-alone window. | 208 // become a stand-alone window. |
| 190 - (void)setWindowBackgroundVisibility:(BOOL)shouldBeVisible { | 209 - (void)setWindowBackgroundVisibility:(BOOL)shouldBeVisible { |
| 191 if (chromeIsVisible_ == shouldBeVisible) | 210 if (chromeIsVisible_ == shouldBeVisible) |
| 192 return; | 211 return; |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 } | 978 } |
| 960 } | 979 } |
| 961 | 980 |
| 962 if (nextUpdate < kNoUpdate) | 981 if (nextUpdate < kNoUpdate) |
| 963 [self performSelector:_cmd withObject:nil afterDelay:nextUpdate]; | 982 [self performSelector:_cmd withObject:nil afterDelay:nextUpdate]; |
| 964 | 983 |
| 965 [self resetLastGlowUpdateTime]; | 984 [self resetLastGlowUpdateTime]; |
| 966 [self setNeedsDisplay:YES]; | 985 [self setNeedsDisplay:YES]; |
| 967 } | 986 } |
| 968 | 987 |
| 988 // Returns the workspace id of |window|. If |useCache|, then we lookup | |
|
pink (ping after 24hrs)
2010/07/19 17:14:35
avoid the use of "we", it makes mark grumpy.
davidben
2010/07/19 17:25:17
...I've really got to do something about that habi
| |
| 989 // and remember the value in |workspaceIDCache_| until the end of the | |
| 990 // current drag. | |
| 991 - (int)getWorkspaceID:(NSWindow*)window useCache:(BOOL)useCache { | |
| 992 CGWindowID windowID = [window windowNumber]; | |
| 993 if (useCache) { | |
| 994 std::map<CGWindowID, int>::iterator iter = | |
| 995 workspaceIDCache_.find(windowID); | |
| 996 if (iter != workspaceIDCache_.end()) | |
| 997 return iter->second; | |
| 998 } | |
| 999 | |
| 1000 int workspace = -1; | |
| 1001 // It's possible to query in bulk, but probably not necessary. | |
| 1002 scoped_cftyperef<CFArrayRef> windowIDs(CFArrayCreate( | |
| 1003 NULL, reinterpret_cast<const void **>(&windowID), 1, NULL)); | |
| 1004 scoped_cftyperef<CFArrayRef> descriptions( | |
| 1005 CGWindowListCreateDescriptionFromArray(windowIDs)); | |
| 1006 DCHECK(CFArrayGetCount(descriptions.get()) <= 1); | |
| 1007 if (CFArrayGetCount(descriptions.get()) > 0) { | |
| 1008 CFDictionaryRef dict = static_cast<CFDictionaryRef>( | |
| 1009 CFArrayGetValueAtIndex(descriptions.get(), 0)); | |
| 1010 DCHECK(CFGetTypeID(dict) == CFDictionaryGetTypeID()); | |
| 1011 | |
| 1012 // Sanity check the ID. | |
| 1013 CFNumberRef otherIDRef = (CFNumberRef)mac_util::GetValueFromDictionary( | |
| 1014 dict, kCGWindowNumber, CFNumberGetTypeID()); | |
| 1015 CGWindowID otherID; | |
| 1016 if (otherIDRef && | |
| 1017 CFNumberGetValue(otherIDRef, kCGWindowIDCFNumberType, &otherID) && | |
| 1018 otherID == windowID) { | |
| 1019 // And then get the workspace. | |
| 1020 CFNumberRef workspaceRef = (CFNumberRef)mac_util::GetValueFromDictionary( | |
| 1021 dict, kCGWindowWorkspace, CFNumberGetTypeID()); | |
| 1022 if (!workspaceRef || | |
| 1023 !CFNumberGetValue(workspaceRef, kCFNumberIntType, &workspace)) { | |
| 1024 workspace = -1; | |
| 1025 } | |
| 1026 } else { | |
| 1027 NOTREACHED(); | |
| 1028 } | |
| 1029 } | |
| 1030 if (useCache) { | |
| 1031 workspaceIDCache_[windowID] = workspace; | |
| 1032 } | |
| 1033 return workspace; | |
| 1034 } | |
| 1035 | |
| 969 @end // @implementation TabView(Private) | 1036 @end // @implementation TabView(Private) |
| OLD | NEW |