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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 finished:(BOOL)finished; | 167 finished:(BOOL)finished; |
168 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 168 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
169 - (void)clickNewTabButton:(id)sender; | 169 - (void)clickNewTabButton:(id)sender; |
170 - (NSInteger)numberOfOpenTabs; | 170 - (NSInteger)numberOfOpenTabs; |
171 - (NSInteger)numberOfOpenPinnedTabs; | 171 - (NSInteger)numberOfOpenPinnedTabs; |
172 - (NSInteger)numberOfOpenNonPinnedTabs; | 172 - (NSInteger)numberOfOpenNonPinnedTabs; |
173 - (void)mouseMoved:(NSEvent*)event; | 173 - (void)mouseMoved:(NSEvent*)event; |
174 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; | 174 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; |
175 - (void)droppingURLsAt:(NSPoint)point | 175 - (void)droppingURLsAt:(NSPoint)point |
176 givesIndex:(NSInteger*)index | 176 givesIndex:(NSInteger*)index |
177 disposition:(WindowOpenDisposition*)disposition; | 177 disposition:(WindowOpenDisposition*)disposition |
178 activateTab:(BOOL)enabled; | |
erikchen
2016/11/21 18:28:40
for consistency, please use activateTab:(BOOL)acti
shahriar
2016/11/22 03:46:30
Done.
| |
178 - (void)setNewTabButtonHoverState:(BOOL)showHover; | 179 - (void)setNewTabButtonHoverState:(BOOL)showHover; |
179 - (void)themeDidChangeNotification:(NSNotification*)notification; | 180 - (void)themeDidChangeNotification:(NSNotification*)notification; |
180 - (BOOL)doesAnyOtherWebContents:(content::WebContents*)selected | 181 - (BOOL)doesAnyOtherWebContents:(content::WebContents*)selected |
181 haveAlertState:(TabAlertState)state; | 182 haveAlertState:(TabAlertState)state; |
182 @end | 183 @end |
183 | 184 |
184 // A simple view class that contains the traffic light buttons. This class | 185 // A simple view class that contains the traffic light buttons. This class |
185 // ensures that the buttons display the icons when the mouse hovers over | 186 // ensures that the buttons display the icons when the mouse hovers over |
186 // them by overriding the _mouseInGroup method. | 187 // them by overriding the _mouseInGroup method. |
187 @interface CustomWindowControlsView : NSView { | 188 @interface CustomWindowControlsView : NSView { |
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2003 [tabStripView_ setSubviews:subviews]; | 2004 [tabStripView_ setSubviews:subviews]; |
2004 [self setTabTrackingAreasEnabled:mouseInside_]; | 2005 [self setTabTrackingAreasEnabled:mouseInside_]; |
2005 } | 2006 } |
2006 | 2007 |
2007 // Get the index and disposition for a potential URL(s) drop given a point (in | 2008 // Get the index and disposition for a potential URL(s) drop given a point (in |
2008 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the | 2009 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the |
2009 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's | 2010 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's |
2010 // to the left, it inserts to the left, and similarly for the right. | 2011 // to the left, it inserts to the left, and similarly for the right. |
2011 - (void)droppingURLsAt:(NSPoint)point | 2012 - (void)droppingURLsAt:(NSPoint)point |
2012 givesIndex:(NSInteger*)index | 2013 givesIndex:(NSInteger*)index |
2013 disposition:(WindowOpenDisposition*)disposition { | 2014 disposition:(WindowOpenDisposition*)disposition |
2015 activateTab:(BOOL)enabled { | |
2014 // Proportion of the tab which is considered the "middle" (and causes things | 2016 // Proportion of the tab which is considered the "middle" (and causes things |
2015 // to drop on that tab). | 2017 // to drop on that tab). |
2016 const double kMiddleProportion = 0.5; | 2018 const double kMiddleProportion = 0.5; |
2017 const double kLRProportion = (1.0 - kMiddleProportion) / 2.0; | 2019 const double kLRProportion = (1.0 - kMiddleProportion) / 2.0; |
2018 const CGFloat kTabOverlap = [TabStripController tabOverlap]; | 2020 const CGFloat kTabOverlap = [TabStripController tabOverlap]; |
2019 | 2021 |
2020 DCHECK(index && disposition); | 2022 DCHECK(index && disposition); |
2021 NSInteger i = 0; | 2023 NSInteger i = 0; |
2022 for (TabController* tab in tabArray_.get()) { | 2024 for (TabController* tab in tabArray_.get()) { |
2023 NSView* view = [tab view]; | 2025 NSView* view = [tab view]; |
2024 DCHECK([view isKindOfClass:[TabView class]]); | 2026 DCHECK([view isKindOfClass:[TabView class]]); |
2025 | 2027 |
2026 // Recall that |-[NSView frame]| is in its superview's coordinates, so a | 2028 // Recall that |-[NSView frame]| is in its superview's coordinates, so a |
2027 // |TabView|'s frame is in the coordinates of the |TabStripView| (which | 2029 // |TabView|'s frame is in the coordinates of the |TabStripView| (which |
2028 // matches the coordinate system of |point|). | 2030 // matches the coordinate system of |point|). |
2029 NSRect frame = [view frame]; | 2031 NSRect frame = [view frame]; |
2030 | 2032 |
2031 // Modify the frame to make it "unoverlapped". | 2033 // Modify the frame to make it "unoverlapped". |
2032 frame.origin.x += kTabOverlap / 2.0; | 2034 frame.origin.x += kTabOverlap / 2.0; |
2033 frame.size.width -= kTabOverlap; | 2035 frame.size.width -= kTabOverlap; |
2034 if (frame.size.width < 1.0) | 2036 if (frame.size.width < 1.0) |
2035 frame.size.width = 1.0; // try to avoid complete failure | 2037 frame.size.width = 1.0; // try to avoid complete failure |
2036 | 2038 |
2037 // Drop in a new tab to the left of tab |i|? | 2039 // Drop in a new tab to the left of tab |i|? |
2038 if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { | 2040 if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { |
2039 *index = i; | 2041 *index = i; |
2040 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 2042 if (enabled) |
erikchen
2016/11/21 18:28:40
Chromium style requires that multi-line if stateme
shahriar
2016/11/22 03:46:30
I fixed it as you said. But I thought when neither
erikchen
2016/11/22 18:12:48
Hm. I reread the Google style guide and you're rig
| |
2043 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | |
2044 else | |
2045 *disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; | |
2041 return; | 2046 return; |
2042 } | 2047 } |
2043 | 2048 |
2044 // Drop on tab |i|? | 2049 // Drop on tab |i|? |
2045 if (point.x <= (frame.origin.x + | 2050 if (point.x <= (frame.origin.x + |
2046 (1.0 - kLRProportion) * frame.size.width)) { | 2051 (1.0 - kLRProportion) * frame.size.width)) { |
2047 *index = i; | 2052 *index = i; |
2048 *disposition = WindowOpenDisposition::CURRENT_TAB; | 2053 *disposition = WindowOpenDisposition::CURRENT_TAB; |
2049 return; | 2054 return; |
2050 } | 2055 } |
2051 | 2056 |
2052 // (Dropping in a new tab to the right of tab |i| will be taken care of in | 2057 // (Dropping in a new tab to the right of tab |i| will be taken care of in |
2053 // the next iteration.) | 2058 // the next iteration.) |
2054 i++; | 2059 i++; |
2055 } | 2060 } |
2056 | 2061 |
2057 // If we've made it here, we want to append a new tab to the end. | 2062 // If we've made it here, we want to append a new tab to the end. |
2058 *index = -1; | 2063 *index = -1; |
2059 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | 2064 if (enabled) |
2065 *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | |
2066 else | |
2067 *disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; | |
2060 } | 2068 } |
2061 | 2069 |
2062 - (void)openURL:(GURL*)url inView:(NSView*)view at:(NSPoint)point { | 2070 - (void)openURL:(GURL*)url |
2071 inView:(NSView*)view | |
2072 at:(NSPoint)point | |
2073 activateTab:(BOOL)enabled { | |
2063 // Security: Block JavaScript to prevent self-XSS. | 2074 // Security: Block JavaScript to prevent self-XSS. |
2064 if (url->SchemeIs(url::kJavaScriptScheme)) | 2075 if (url->SchemeIs(url::kJavaScriptScheme)) |
2065 return; | 2076 return; |
2066 | 2077 |
2067 // Get the index and disposition. | 2078 // Get the index and disposition. |
2068 NSInteger index; | 2079 NSInteger index; |
2069 WindowOpenDisposition disposition; | 2080 WindowOpenDisposition disposition; |
2070 [self droppingURLsAt:point | 2081 [self droppingURLsAt:point |
2071 givesIndex:&index | 2082 givesIndex:&index |
2072 disposition:&disposition]; | 2083 disposition:&disposition |
2084 activateTab:enabled]; | |
2073 | 2085 |
2074 // Either insert a new tab or open in a current tab. | 2086 // Either insert a new tab or open in a current tab. |
2075 switch (disposition) { | 2087 switch (disposition) { |
2076 case WindowOpenDisposition::NEW_FOREGROUND_TAB: { | 2088 case WindowOpenDisposition::NEW_FOREGROUND_TAB: |
2089 case WindowOpenDisposition::NEW_BACKGROUND_TAB: { | |
2077 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); | 2090 content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); |
2078 chrome::NavigateParams params(browser_, *url, | 2091 chrome::NavigateParams params(browser_, *url, |
2079 ui::PAGE_TRANSITION_TYPED); | 2092 ui::PAGE_TRANSITION_TYPED); |
2080 params.disposition = disposition; | 2093 params.disposition = disposition; |
2081 params.tabstrip_index = index; | 2094 params.tabstrip_index = index; |
2082 params.tabstrip_add_types = | 2095 params.tabstrip_add_types = |
2083 TabStripModel::ADD_ACTIVE | TabStripModel::ADD_FORCE_INDEX; | 2096 TabStripModel::ADD_ACTIVE | TabStripModel::ADD_FORCE_INDEX; |
2084 chrome::Navigate(¶ms); | 2097 chrome::Navigate(¶ms); |
2085 break; | 2098 break; |
2086 } | 2099 } |
(...skipping 12 matching lines...) Expand all Loading... | |
2099 | 2112 |
2100 // (URLDropTargetController protocol) | 2113 // (URLDropTargetController protocol) |
2101 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { | 2114 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { |
2102 DCHECK_EQ(view, tabStripView_.get()); | 2115 DCHECK_EQ(view, tabStripView_.get()); |
2103 | 2116 |
2104 if ([urls count] < 1) { | 2117 if ([urls count] < 1) { |
2105 NOTREACHED(); | 2118 NOTREACHED(); |
2106 return; | 2119 return; |
2107 } | 2120 } |
2108 | 2121 |
2109 //TODO(viettrungluu): dropping multiple URLs. | 2122 for (id urlString in [urls reverseObjectEnumerator]) { |
2110 if ([urls count] > 1) | 2123 // Refactor this code. |
2111 NOTIMPLEMENTED(); | 2124 // https://crbug.com/665261. |
2125 GURL url = url_formatter::FixupURL(base::SysNSStringToUTF8(urlString), | |
2126 std::string()); | |
2112 | 2127 |
2113 // Get the first URL and fix it up. | 2128 // If the URL isn't valid, don't bother. |
2114 GURL url(GURL(url_formatter::FixupURL( | 2129 if (!url.is_valid()) |
2115 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string()))); | 2130 continue; |
2116 | 2131 |
2117 // If the URL isn't valid, don't bother. | 2132 if ([urls indexOfObject:urlString] == [urls count] - 1) |
erikchen
2016/11/21 18:28:40
This code makes the assumption that the urlString
shahriar
2016/11/22 03:46:30
Done.
| |
2118 if (!url.is_valid()) | 2133 [self openURL:&url inView:view at:point activateTab:YES]; |
2119 return; | 2134 else |
2120 | 2135 [self openURL:&url inView:view at:point activateTab:NO]; |
2121 [self openURL:&url inView:view at:point]; | 2136 } |
2122 } | 2137 } |
2123 | 2138 |
2124 // (URLDropTargetController protocol) | 2139 // (URLDropTargetController protocol) |
2125 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { | 2140 - (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point { |
2126 DCHECK_EQ(view, tabStripView_.get()); | 2141 DCHECK_EQ(view, tabStripView_.get()); |
2127 | 2142 |
2128 // If the input is plain text, classify the input and make the URL. | 2143 // If the input is plain text, classify the input and make the URL. |
2129 AutocompleteMatch match; | 2144 AutocompleteMatch match; |
2130 AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify( | 2145 AutocompleteClassifierFactory::GetForProfile(browser_->profile())->Classify( |
2131 base::SysNSStringToUTF16(text), false, false, | 2146 base::SysNSStringToUTF16(text), false, false, |
2132 metrics::OmniboxEventProto::BLANK, &match, NULL); | 2147 metrics::OmniboxEventProto::BLANK, &match, NULL); |
2133 GURL url(match.destination_url); | 2148 GURL url(match.destination_url); |
2134 | 2149 |
2135 [self openURL:&url inView:view at:point]; | 2150 [self openURL:&url inView:view at:point activateTab:YES]; |
2136 } | 2151 } |
2137 | 2152 |
2138 // (URLDropTargetController protocol) | 2153 // (URLDropTargetController protocol) |
2139 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { | 2154 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { |
2140 DCHECK_EQ(view, tabStripView_.get()); | 2155 DCHECK_EQ(view, tabStripView_.get()); |
2141 | 2156 |
2142 // The minimum y-coordinate at which one should consider place the arrow. | 2157 // The minimum y-coordinate at which one should consider place the arrow. |
2143 const CGFloat arrowBaseY = 25; | 2158 const CGFloat arrowBaseY = 25; |
2144 const CGFloat kTabOverlap = [TabStripController tabOverlap]; | 2159 const CGFloat kTabOverlap = [TabStripController tabOverlap]; |
2145 | 2160 |
2146 NSInteger index; | 2161 NSInteger index; |
2147 WindowOpenDisposition disposition; | 2162 WindowOpenDisposition disposition; |
2148 [self droppingURLsAt:point | 2163 [self droppingURLsAt:point |
2149 givesIndex:&index | 2164 givesIndex:&index |
2150 disposition:&disposition]; | 2165 disposition:&disposition |
2166 activateTab:YES]; | |
2151 | 2167 |
2152 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); | 2168 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); |
2153 if (index == -1) { | 2169 if (index == -1) { |
2154 // Append a tab at the end. | 2170 // Append a tab at the end. |
2155 DCHECK(disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB); | 2171 DCHECK(disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB); |
2156 NSInteger lastIndex = [tabArray_ count] - 1; | 2172 NSInteger lastIndex = [tabArray_ count] - 1; |
2157 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; | 2173 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; |
2158 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; | 2174 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; |
2159 } else { | 2175 } else { |
2160 NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame]; | 2176 NSRect overRect = [[[tabArray_ objectAtIndex:index] view] frame]; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2338 for (int i = 0; i < tabStripModel_->count(); i++) { | 2354 for (int i = 0; i < tabStripModel_->count(); i++) { |
2339 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; | 2355 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
2340 } | 2356 } |
2341 } | 2357 } |
2342 | 2358 |
2343 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2359 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
2344 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2360 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
2345 } | 2361 } |
2346 | 2362 |
2347 @end | 2363 @end |
OLD | NEW |