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