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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 finished:(BOOL)finished; | 172 finished:(BOOL)finished; |
173 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 173 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
174 - (void)clickNewTabButton:(id)sender; | 174 - (void)clickNewTabButton:(id)sender; |
175 - (NSInteger)numberOfOpenTabs; | 175 - (NSInteger)numberOfOpenTabs; |
176 - (NSInteger)numberOfOpenPinnedTabs; | 176 - (NSInteger)numberOfOpenPinnedTabs; |
177 - (NSInteger)numberOfOpenNonPinnedTabs; | 177 - (NSInteger)numberOfOpenNonPinnedTabs; |
178 - (void)mouseMoved:(NSEvent*)event; | 178 - (void)mouseMoved:(NSEvent*)event; |
179 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; | 179 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; |
180 - (void)droppingURLsAt:(NSPoint)point | 180 - (void)droppingURLsAt:(NSPoint)point |
181 givesIndex:(NSInteger*)index | 181 givesIndex:(NSInteger*)index |
182 disposition:(WindowOpenDisposition*)disposition; | 182 disposition:(WindowOpenDisposition*)disposition |
| 183 activateTab:(BOOL)activateTab; |
183 - (void)setNewTabButtonHoverState:(BOOL)showHover; | 184 - (void)setNewTabButtonHoverState:(BOOL)showHover; |
184 - (void)themeDidChangeNotification:(NSNotification*)notification; | 185 - (void)themeDidChangeNotification:(NSNotification*)notification; |
185 - (BOOL)doesAnyOtherWebContents:(content::WebContents*)selected | 186 - (BOOL)doesAnyOtherWebContents:(content::WebContents*)selected |
186 haveAlertState:(TabAlertState)state; | 187 haveAlertState:(TabAlertState)state; |
187 @end | 188 @end |
188 | 189 |
189 // A simple view class that contains the traffic light buttons. This class | 190 // A simple view class that contains the traffic light buttons. This class |
190 // ensures that the buttons display the icons when the mouse hovers over | 191 // ensures that the buttons display the icons when the mouse hovers over |
191 // them by overriding the _mouseInGroup method. | 192 // them by overriding the _mouseInGroup method. |
192 @interface CustomWindowControlsView : NSView { | 193 @interface CustomWindowControlsView : NSView { |
(...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 [tabStripView_ setSubviews:subviews]; | 2032 [tabStripView_ setSubviews:subviews]; |
2032 [self setTabTrackingAreasEnabled:mouseInside_]; | 2033 [self setTabTrackingAreasEnabled:mouseInside_]; |
2033 } | 2034 } |
2034 | 2035 |
2035 // Get the index and disposition for a potential URL(s) drop given a point (in | 2036 // Get the index and disposition for a potential URL(s) drop given a point (in |
2036 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the | 2037 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the |
2037 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's | 2038 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's |
2038 // to the left, it inserts to the left, and similarly for the right. | 2039 // to the left, it inserts to the left, and similarly for the right. |
2039 - (void)droppingURLsAt:(NSPoint)point | 2040 - (void)droppingURLsAt:(NSPoint)point |
2040 givesIndex:(NSInteger*)index | 2041 givesIndex:(NSInteger*)index |
2041 disposition:(WindowOpenDisposition*)disposition { | 2042 disposition:(WindowOpenDisposition*)disposition |
| 2043 activateTab:(BOOL)activateTab { |
2042 // Proportion of the tab which is considered the "middle" (and causes things | 2044 // Proportion of the tab which is considered the "middle" (and causes things |
2043 // to drop on that tab). | 2045 // to drop on that tab). |
2044 const double kMiddleProportion = 0.5; | 2046 const double kMiddleProportion = 0.5; |
2045 const double kLRProportion = (1.0 - kMiddleProportion) / 2.0; | 2047 const double kLRProportion = (1.0 - kMiddleProportion) / 2.0; |
2046 const CGFloat kTabOverlap = [TabStripController tabOverlap]; | 2048 const CGFloat kTabOverlap = [TabStripController tabOverlap]; |
2047 | 2049 |
2048 DCHECK(index && disposition); | 2050 DCHECK(index && disposition); |
2049 NSInteger i = 0; | 2051 NSInteger i = 0; |
2050 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | 2052 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
2051 for (TabController* tab in tabArray_.get()) { | 2053 for (TabController* tab in tabArray_.get()) { |
(...skipping 10 matching lines...) Expand all Loading... |
2062 frame.size.width -= kTabOverlap; | 2064 frame.size.width -= kTabOverlap; |
2063 if (frame.size.width < 1.0) | 2065 if (frame.size.width < 1.0) |
2064 frame.size.width = 1.0; // try to avoid complete failure | 2066 frame.size.width = 1.0; // try to avoid complete failure |
2065 | 2067 |
2066 CGFloat rightEdge = NSMaxX(frame) - kLRProportion * frame.size.width; | 2068 CGFloat rightEdge = NSMaxX(frame) - kLRProportion * frame.size.width; |
2067 CGFloat leftEdge = frame.origin.x + kLRProportion * frame.size.width; | 2069 CGFloat leftEdge = frame.origin.x + kLRProportion * frame.size.width; |
2068 | 2070 |
2069 // Drop in a new tab before tab |i|? | 2071 // Drop in a new tab before tab |i|? |
2070 if (isRTL ? point.x > rightEdge : point.x < leftEdge) { | 2072 if (isRTL ? point.x > rightEdge : point.x < leftEdge) { |
2071 *index = i; | 2073 *index = i; |
2072 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 2074 if (activateTab) { |
| 2075 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2076 } else { |
| 2077 *disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 2078 } |
2073 return; | 2079 return; |
2074 } | 2080 } |
2075 | 2081 |
2076 // Drop on tab |i|? | 2082 // Drop on tab |i|? |
2077 if (isRTL ? point.x >= leftEdge : point.x <= rightEdge) { | 2083 if (isRTL ? point.x >= leftEdge : point.x <= rightEdge) { |
2078 *index = i; | 2084 *index = i; |
2079 *disposition = WindowOpenDisposition::CURRENT_TAB; | 2085 *disposition = WindowOpenDisposition::CURRENT_TAB; |
2080 return; | 2086 return; |
2081 } | 2087 } |
2082 | 2088 |
2083 // (Dropping in a new tab to the right of tab |i| will be taken care of in | 2089 // (Dropping in a new tab to the right of tab |i| will be taken care of in |
2084 // the next iteration.) | 2090 // the next iteration.) |
2085 i++; | 2091 i++; |
2086 } | 2092 } |
2087 | 2093 |
2088 // If we've made it here, we want to append a new tab to the end. | 2094 // If we've made it here, we want to append a new tab to the end. |
2089 *index = -1; | 2095 *index = -1; |
2090 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 2096 if (activateTab) { |
| 2097 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2098 } else { |
| 2099 *disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 2100 } |
2091 } | 2101 } |
2092 | 2102 |
2093 - (void)openURL:(GURL*)url inView:(NSView*)view at:(NSPoint)point { | 2103 - (void)openURL:(GURL*)url |
| 2104 inView:(NSView*)view |
| 2105 at:(NSPoint)point |
| 2106 activateTab:(BOOL)activateTab { |
2094 // Security: Block JavaScript to prevent self-XSS. | 2107 // Security: Block JavaScript to prevent self-XSS. |
2095 if (url->SchemeIs(url::kJavaScriptScheme)) | 2108 if (url->SchemeIs(url::kJavaScriptScheme)) |
2096 return; | 2109 return; |
2097 | 2110 |
2098 // Get the index and disposition. | 2111 // Get the index and disposition. |
2099 NSInteger index; | 2112 NSInteger index; |
2100 WindowOpenDisposition disposition; | 2113 WindowOpenDisposition disposition; |
2101 [self droppingURLsAt:point | 2114 [self droppingURLsAt:point |
2102 givesIndex:&index | 2115 givesIndex:&index |
2103 disposition:&disposition]; | 2116 disposition:&disposition |
| 2117 activateTab:activateTab]; |
2104 | 2118 |
2105 // Either insert a new tab or open in a current tab. | 2119 // Either insert a new tab or open in a current tab. |
2106 switch (disposition) { | 2120 switch (disposition) { |
2107 case WindowOpenDisposition::NEW_FOREGROUND_TAB: { | 2121 case WindowOpenDisposition::NEW_FOREGROUND_TAB: |
| 2122 case WindowOpenDisposition::NEW_BACKGROUND_TAB: { |
2108 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); | 2123 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); |
2109 chrome::NavigateParams params(browser_, *url, | 2124 chrome::NavigateParams params(browser_, *url, |
2110 ui::PAGE_TRANSITION_TYPED); | 2125 ui::PAGE_TRANSITION_TYPED); |
2111 params.disposition = disposition; | 2126 params.disposition = disposition; |
2112 params.tabstrip_index = index; | 2127 params.tabstrip_index = index; |
2113 params.tabstrip_add_types = | 2128 params.tabstrip_add_types = |
2114 TabStripModel::ADD_ACTIVE | TabStripModel::ADD_FORCE_INDEX; | 2129 TabStripModel::ADD_ACTIVE | TabStripModel::ADD_FORCE_INDEX; |
2115 chrome::Navigate(¶ms); | 2130 chrome::Navigate(¶ms); |
2116 break; | 2131 break; |
2117 } | 2132 } |
(...skipping 12 matching lines...) Expand all Loading... |
2130 | 2145 |
2131 // (URLDropTargetController protocol) | 2146 // (URLDropTargetController protocol) |
2132 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { | 2147 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { |
2133 DCHECK_EQ(view, tabStripView_.get()); | 2148 DCHECK_EQ(view, tabStripView_.get()); |
2134 | 2149 |
2135 if ([urls count] < 1) { | 2150 if ([urls count] < 1) { |
2136 NOTREACHED(); | 2151 NOTREACHED(); |
2137 return; | 2152 return; |
2138 } | 2153 } |
2139 | 2154 |
2140 //TODO(viettrungluu): dropping multiple URLs. | 2155 for (NSInteger index = [urls count] - 1; index >= 0; index--) { |
2141 if ([urls count] > 1) | 2156 // Refactor this code. |
2142 NOTIMPLEMENTED(); | 2157 // https://crbug.com/665261. |
| 2158 GURL url = url_formatter::FixupURL( |
| 2159 base::SysNSStringToUTF8([urls objectAtIndex:index]), std::string()); |
2143 | 2160 |
2144 // Get the first URL and fix it up. | 2161 // If the URL isn't valid, don't bother. |
2145 GURL url(GURL(url_formatter::FixupURL( | 2162 if (!url.is_valid()) |
2146 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string()))); | 2163 continue; |
2147 | 2164 |
2148 // If the URL isn't valid, don't bother. | 2165 if (index == static_cast<NSInteger>([urls count]) - 1) { |
2149 if (!url.is_valid()) | 2166 [self openURL:&url inView:view at:point activateTab:YES]; |
2150 return; | 2167 } else { |
2151 | 2168 [self openURL:&url inView:view at:point activateTab:NO]; |
2152 [self openURL:&url inView:view at:point]; | 2169 } |
| 2170 } |
2153 } | 2171 } |
2154 | 2172 |
2155 // (URLDropTargetController protocol) | 2173 // (URLDropTargetController protocol) |
2156 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { | 2174 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { |
2157 DCHECK_EQ(view, tabStripView_.get()); | 2175 DCHECK_EQ(view, tabStripView_.get()); |
2158 | 2176 |
2159 // If the input is plain text, classify the input and make the URL. | 2177 // If the input is plain text, classify the input and make the URL. |
2160 AutocompleteMatch match; | 2178 AutocompleteMatch match; |
2161 AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify( | 2179 AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify( |
2162 base::SysNSStringToUTF16(text), false, false, | 2180 base::SysNSStringToUTF16(text), false, false, |
2163 metrics::OmniboxEventProto::BLANK, &match, NULL); | 2181 metrics::OmniboxEventProto::BLANK, &match, NULL); |
2164 GURL url(match.destination_url); | 2182 GURL url(match.destination_url); |
2165 | 2183 |
2166 [self openURL:&url inView:view at:point]; | 2184 [self openURL:&url inView:view at:point activateTab:YES]; |
2167 } | 2185 } |
2168 | 2186 |
2169 // (URLDropTargetController protocol) | 2187 // (URLDropTargetController protocol) |
2170 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { | 2188 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { |
2171 DCHECK_EQ(view, tabStripView_.get()); | 2189 DCHECK_EQ(view, tabStripView_.get()); |
2172 | 2190 |
2173 // The minimum y-coordinate at which one should consider place the arrow. | 2191 // The minimum y-coordinate at which one should consider place the arrow. |
2174 const CGFloat arrowBaseY = 25; | 2192 const CGFloat arrowBaseY = 25; |
2175 const CGFloat kTabOverlap = [TabStripController tabOverlap]; | 2193 const CGFloat kTabOverlap = [TabStripController tabOverlap]; |
2176 | 2194 |
2177 NSInteger index; | 2195 NSInteger index; |
2178 WindowOpenDisposition disposition; | 2196 WindowOpenDisposition disposition; |
2179 [self droppingURLsAt:point | 2197 [self droppingURLsAt:point |
2180 givesIndex:&index | 2198 givesIndex:&index |
2181 disposition:&disposition]; | 2199 disposition:&disposition |
| 2200 activateTab:YES]; |
2182 | 2201 |
2183 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); | 2202 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); |
2184 if (index == -1) { | 2203 if (index == -1) { |
2185 // Append a tab at the end. | 2204 // Append a tab at the end. |
2186 DCHECK(disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB); | 2205 DCHECK(disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB); |
2187 NSInteger lastIndex = [tabArray_ count] - 1; | 2206 NSInteger lastIndex = [tabArray_ count] - 1; |
2188 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; | 2207 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; |
2189 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; | 2208 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; |
2190 } else { | 2209 } else { |
2191 NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame]; | 2210 NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame]; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 for (int i = 0; i < tabStripModel_->count(); i++) { | 2400 for (int i = 0; i < tabStripModel_->count(); i++) { |
2382 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; | 2401 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
2383 } | 2402 } |
2384 } | 2403 } |
2385 | 2404 |
2386 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2405 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
2387 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2406 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
2388 } | 2407 } |
2389 | 2408 |
2390 @end | 2409 @end |
OLD | NEW |