Chromium Code Reviews| Index: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| index 97eb5f57a8c69e4dc60dc633054ae5fa214548fe..0e15a273c08218d010f0fbbecae4500b49a6efb8 100644 |
| --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm |
| @@ -174,7 +174,8 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| - (void)setTabTrackingAreasEnabled:(BOOL)enabled; |
| - (void)droppingURLsAt:(NSPoint)point |
| givesIndex:(NSInteger*)index |
| - disposition:(WindowOpenDisposition*)disposition; |
| + disposition:(WindowOpenDisposition*)disposition |
| + activateTab:(BOOL)activateTab; |
| - (void)setNewTabButtonHoverState:(BOOL)showHover; |
| - (void)themeDidChangeNotification:(NSNotification*)notification; |
| - (BOOL)doesAnyOtherWebContents:(content::WebContents*)selected |
| @@ -2010,7 +2011,8 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| // to the left, it inserts to the left, and similarly for the right. |
| - (void)droppingURLsAt:(NSPoint)point |
| givesIndex:(NSInteger*)index |
| - disposition:(WindowOpenDisposition*)disposition { |
| + disposition:(WindowOpenDisposition*)disposition |
| + activateTab:(BOOL)activateTab { |
| // Proportion of the tab which is considered the "middle" (and causes things |
| // to drop on that tab). |
| const double kMiddleProportion = 0.5; |
| @@ -2037,7 +2039,11 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| // Drop in a new tab to the left of tab |i|? |
| if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { |
| *index = i; |
| - *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| + if (activateTab) { |
| + *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| + } else { |
| + *disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| + } |
| return; |
| } |
| @@ -2056,10 +2062,17 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| // If we've made it here, we want to append a new tab to the end. |
| *index = -1; |
| - *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| + if (activateTab) { |
| + *disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| + } else { |
| + *disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| + } |
| } |
| -- (void)openURL:(GURL*)url inView:(NSView*)view at:(NSPoint)point { |
| +- (void)openURL:(GURL*)url |
| + inView:(NSView*)view |
| + at:(NSPoint)point |
| + activateTab:(BOOL)activateTab { |
| // Security: Block JavaScript to prevent self-XSS. |
| if (url->SchemeIs(url::kJavaScriptScheme)) |
| return; |
| @@ -2069,11 +2082,13 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| WindowOpenDisposition disposition; |
| [self droppingURLsAt:point |
| givesIndex:&index |
| - disposition:&disposition]; |
| + disposition:&disposition |
| + activateTab:activateTab]; |
| // Either insert a new tab or open in a current tab. |
| switch (disposition) { |
| - case WindowOpenDisposition::NEW_FOREGROUND_TAB: { |
| + case WindowOpenDisposition::NEW_FOREGROUND_TAB: |
| + case WindowOpenDisposition::NEW_BACKGROUND_TAB: { |
| content::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs")); |
| chrome::NavigateParams params(browser_, *url, |
| ui::PAGE_TRANSITION_TYPED); |
| @@ -2106,19 +2121,22 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| return; |
| } |
| - //TODO(viettrungluu): dropping multiple URLs. |
| - if ([urls count] > 1) |
| - NOTIMPLEMENTED(); |
| - |
| - // Get the first URL and fix it up. |
| - GURL url(GURL(url_formatter::FixupURL( |
| - base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string()))); |
| + for (NSInteger index = [urls count] - 1; index >= 0; index--) { |
|
erikchen
2016/11/22 22:52:25
Comparison against 0 is fine, you just need to use
|
| + // Refactor this code. |
| + // https://crbug.com/665261. |
| + GURL url = url_formatter::FixupURL( |
| + base::SysNSStringToUTF8([urls objectAtIndex:index]), std::string()); |
| - // If the URL isn't valid, don't bother. |
| - if (!url.is_valid()) |
| - return; |
| + // If the URL isn't valid, don't bother. |
| + if (!url.is_valid()) |
| + continue; |
| - [self openURL:&url inView:view at:point]; |
| + if (index == static_cast<NSInteger>([urls count]) - 1) { |
| + [self openURL:&url inView:view at:point activateTab:YES]; |
| + } else { |
| + [self openURL:&url inView:view at:point activateTab:NO]; |
| + } |
| + } |
| } |
| // (URLDropTargetController protocol) |
| @@ -2132,7 +2150,7 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| metrics::OmniboxEventProto::BLANK, &match, NULL); |
| GURL url(match.destination_url); |
| - [self openURL:&url inView:view at:point]; |
| + [self openURL:&url inView:view at:point activateTab:YES]; |
| } |
| // (URLDropTargetController protocol) |
| @@ -2147,7 +2165,8 @@ CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| WindowOpenDisposition disposition; |
| [self droppingURLsAt:point |
| givesIndex:&index |
| - disposition:&disposition]; |
| + disposition:&disposition |
| + activateTab:YES]; |
| NSPoint arrowPos = NSMakePoint(0, arrowBaseY); |
| if (index == -1) { |