| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tabs/tab_strip_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 2000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2011 | 2011 |
| 2012 // Modify the frame to make it "unoverlapped". | 2012 // Modify the frame to make it "unoverlapped". |
| 2013 frame.origin.x += kTabOverlap / 2.0; | 2013 frame.origin.x += kTabOverlap / 2.0; |
| 2014 frame.size.width -= kTabOverlap; | 2014 frame.size.width -= kTabOverlap; |
| 2015 if (frame.size.width < 1.0) | 2015 if (frame.size.width < 1.0) |
| 2016 frame.size.width = 1.0; // try to avoid complete failure | 2016 frame.size.width = 1.0; // try to avoid complete failure |
| 2017 | 2017 |
| 2018 // Drop in a new tab to the left of tab |i|? | 2018 // Drop in a new tab to the left of tab |i|? |
| 2019 if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { | 2019 if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { |
| 2020 *index = i; | 2020 *index = i; |
| 2021 *disposition = NEW_FOREGROUND_TAB; | 2021 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2022 return; | 2022 return; |
| 2023 } | 2023 } |
| 2024 | 2024 |
| 2025 // Drop on tab |i|? | 2025 // Drop on tab |i|? |
| 2026 if (point.x <= (frame.origin.x + | 2026 if (point.x <= (frame.origin.x + |
| 2027 (1.0 - kLRProportion) * frame.size.width)) { | 2027 (1.0 - kLRProportion) * frame.size.width)) { |
| 2028 *index = i; | 2028 *index = i; |
| 2029 *disposition = CURRENT_TAB; | 2029 *disposition = WindowOpenDisposition::CURRENT_TAB; |
| 2030 return; | 2030 return; |
| 2031 } | 2031 } |
| 2032 | 2032 |
| 2033 // (Dropping in a new tab to the right of tab |i| will be taken care of in | 2033 // (Dropping in a new tab to the right of tab |i| will be taken care of in |
| 2034 // the next iteration.) | 2034 // the next iteration.) |
| 2035 i++; | 2035 i++; |
| 2036 } | 2036 } |
| 2037 | 2037 |
| 2038 // If we've made it here, we want to append a new tab to the end. | 2038 // If we've made it here, we want to append a new tab to the end. |
| 2039 *index = -1; | 2039 *index = -1; |
| 2040 *disposition = NEW_FOREGROUND_TAB; | 2040 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2041 } | 2041 } |
| 2042 | 2042 |
| 2043 - (void)openURL:(GURL*)url inView:(NSView*)view at:(NSPoint)point { | 2043 - (void)openURL:(GURL*)url inView:(NSView*)view at:(NSPoint)point { |
| 2044 // Get the index and disposition. | 2044 // Get the index and disposition. |
| 2045 NSInteger index; | 2045 NSInteger index; |
| 2046 WindowOpenDisposition disposition; | 2046 WindowOpenDisposition disposition; |
| 2047 [self droppingURLsAt:point | 2047 [self droppingURLsAt:point |
| 2048 givesIndex:&index | 2048 givesIndex:&index |
| 2049 disposition:&disposition]; | 2049 disposition:&disposition]; |
| 2050 | 2050 |
| 2051 // Either insert a new tab or open in a current tab. | 2051 // Either insert a new tab or open in a current tab. |
| 2052 switch (disposition) { | 2052 switch (disposition) { |
| 2053 case NEW_FOREGROUND_TAB: { | 2053 case WindowOpenDisposition::NEW_FOREGROUND_TAB: { |
| 2054 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); | 2054 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); |
| 2055 chrome::NavigateParams params(browser_, *url, | 2055 chrome::NavigateParams params(browser_, *url, |
| 2056 ui::PAGE_TRANSITION_TYPED); | 2056 ui::PAGE_TRANSITION_TYPED); |
| 2057 params.disposition = disposition; | 2057 params.disposition = disposition; |
| 2058 params.tabstrip_index = index; | 2058 params.tabstrip_index = index; |
| 2059 params.tabstrip_add_types = | 2059 params.tabstrip_add_types = |
| 2060 TabStripModel::ADD_ACTIVE | TabStripModel::ADD_FORCE_INDEX; | 2060 TabStripModel::ADD_ACTIVE | TabStripModel::ADD_FORCE_INDEX; |
| 2061 chrome::Navigate(¶ms); | 2061 chrome::Navigate(¶ms); |
| 2062 break; | 2062 break; |
| 2063 } | 2063 } |
| 2064 case CURRENT_TAB: { | 2064 case WindowOpenDisposition::CURRENT_TAB: { |
| 2065 content::RecordAction(UserMetricsAction("Tab_DropURLOnTab")); | 2065 content::RecordAction(UserMetricsAction("Tab_DropURLOnTab")); |
| 2066 OpenURLParams params( | 2066 OpenURLParams params(*url, Referrer(), WindowOpenDisposition::CURRENT_TAB, |
| 2067 *url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false); | 2067 ui::PAGE_TRANSITION_TYPED, false); |
| 2068 tabStripModel_->GetWebContentsAt(index)->OpenURL(params); | 2068 tabStripModel_->GetWebContentsAt(index)->OpenURL(params); |
| 2069 tabStripModel_->ActivateTabAt(index, true); | 2069 tabStripModel_->ActivateTabAt(index, true); |
| 2070 break; | 2070 break; |
| 2071 } | 2071 } |
| 2072 default: | 2072 default: |
| 2073 NOTIMPLEMENTED(); | 2073 NOTIMPLEMENTED(); |
| 2074 } | 2074 } |
| 2075 } | 2075 } |
| 2076 | 2076 |
| 2077 // (URLDropTargetController protocol) | 2077 // (URLDropTargetController protocol) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2122 | 2122 |
| 2123 NSInteger index; | 2123 NSInteger index; |
| 2124 WindowOpenDisposition disposition; | 2124 WindowOpenDisposition disposition; |
| 2125 [self droppingURLsAt:point | 2125 [self droppingURLsAt:point |
| 2126 givesIndex:&index | 2126 givesIndex:&index |
| 2127 disposition:&disposition]; | 2127 disposition:&disposition]; |
| 2128 | 2128 |
| 2129 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); | 2129 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); |
| 2130 if (index == -1) { | 2130 if (index == -1) { |
| 2131 // Append a tab at the end. | 2131 // Append a tab at the end. |
| 2132 DCHECK(disposition == NEW_FOREGROUND_TAB); | 2132 DCHECK(disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB); |
| 2133 NSInteger lastIndex = [tabArray_ count] - 1; | 2133 NSInteger lastIndex = [tabArray_ count] - 1; |
| 2134 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; | 2134 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; |
| 2135 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; | 2135 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; |
| 2136 } else { | 2136 } else { |
| 2137 NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame]; | 2137 NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame]; |
| 2138 switch (disposition) { | 2138 switch (disposition) { |
| 2139 case NEW_FOREGROUND_TAB: | 2139 case WindowOpenDisposition::NEW_FOREGROUND_TAB: |
| 2140 // Insert tab (to the left of the given tab). | 2140 // Insert tab (to the left of the given tab). |
| 2141 arrowPos.x = overRect.origin.x + kTabOverlap / 2.0; | 2141 arrowPos.x = overRect.origin.x + kTabOverlap / 2.0; |
| 2142 break; | 2142 break; |
| 2143 case CURRENT_TAB: | 2143 case WindowOpenDisposition::CURRENT_TAB: |
| 2144 // Overwrite the given tab. | 2144 // Overwrite the given tab. |
| 2145 arrowPos.x = overRect.origin.x + overRect.size.width / 2.0; | 2145 arrowPos.x = overRect.origin.x + overRect.size.width / 2.0; |
| 2146 break; | 2146 break; |
| 2147 default: | 2147 default: |
| 2148 NOTREACHED(); | 2148 NOTREACHED(); |
| 2149 } | 2149 } |
| 2150 } | 2150 } |
| 2151 | 2151 |
| 2152 [tabStripView_ setDropArrowPosition:arrowPos]; | 2152 [tabStripView_ setDropArrowPosition:arrowPos]; |
| 2153 [tabStripView_ setDropArrowShown:YES]; | 2153 [tabStripView_ setDropArrowShown:YES]; |
| 2154 [tabStripView_ setNeedsDisplay:YES]; | 2154 [tabStripView_ setNeedsDisplay:YES]; |
| 2155 | 2155 |
| 2156 // Perform a delayed tab transition if hovering directly over a tab. | 2156 // Perform a delayed tab transition if hovering directly over a tab. |
| 2157 if (index != -1 && disposition == CURRENT_TAB) { | 2157 if (index != -1 && disposition == WindowOpenDisposition::CURRENT_TAB) { |
| 2158 NSInteger modelIndex = [self modelIndexFromIndex:index]; | 2158 NSInteger modelIndex = [self modelIndexFromIndex:index]; |
| 2159 // Only start the transition if it has a valid model index (i.e. it's not | 2159 // Only start the transition if it has a valid model index (i.e. it's not |
| 2160 // in the middle of closing). | 2160 // in the middle of closing). |
| 2161 if (modelIndex != NSNotFound) { | 2161 if (modelIndex != NSNotFound) { |
| 2162 hoverTabSelector_->StartTabTransition(modelIndex); | 2162 hoverTabSelector_->StartTabTransition(modelIndex); |
| 2163 return; | 2163 return; |
| 2164 } | 2164 } |
| 2165 } | 2165 } |
| 2166 // If a tab transition was not started, cancel the pending one. | 2166 // If a tab transition was not started, cancel the pending one. |
| 2167 hoverTabSelector_->CancelTabTransition(); | 2167 hoverTabSelector_->CancelTabTransition(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2315 for (int i = 0; i < tabStripModel_->count(); i++) { | 2315 for (int i = 0; i < tabStripModel_->count(); i++) { |
| 2316 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; | 2316 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
| 2317 } | 2317 } |
| 2318 } | 2318 } |
| 2319 | 2319 |
| 2320 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2320 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
| 2321 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2321 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
| 2322 } | 2322 } |
| 2323 | 2323 |
| 2324 @end | 2324 @end |
| OLD | NEW |