Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/cocoa/tab_strip_controller.mm

Issue 501135: Revert 34998, more stabbing in the dark to find a perf regression - Mac: impl... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/tab_strip_controller.h ('k') | chrome/browser/cocoa/tab_strip_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/tab_strip_controller.h" 5 #import "chrome/browser/cocoa/tab_strip_controller.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 - (void)layoutTabsWithAnimation:(BOOL)animate 113 - (void)layoutTabsWithAnimation:(BOOL)animate
114 regenerateSubviews:(BOOL)doUpdate; 114 regenerateSubviews:(BOOL)doUpdate;
115 - (void)animationDidStopForController:(TabController*)controller 115 - (void)animationDidStopForController:(TabController*)controller
116 finished:(BOOL)finished; 116 finished:(BOOL)finished;
117 - (NSInteger)indexFromModelIndex:(NSInteger)index; 117 - (NSInteger)indexFromModelIndex:(NSInteger)index;
118 - (NSInteger)numberOfOpenTabs; 118 - (NSInteger)numberOfOpenTabs;
119 - (NSInteger)numberOfOpenPinnedTabs; 119 - (NSInteger)numberOfOpenPinnedTabs;
120 - (NSInteger)numberOfOpenUnpinnedTabs; 120 - (NSInteger)numberOfOpenUnpinnedTabs;
121 - (void)mouseMoved:(NSEvent*)event; 121 - (void)mouseMoved:(NSEvent*)event;
122 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; 122 - (void)setTabTrackingAreasEnabled:(BOOL)enabled;
123 - (void)droppingURLsAt:(NSPoint)point 123 - (void)droppingURLsAt:(NSPoint)location
124 givesIndex:(NSInteger*)index 124 givesIndex:(NSInteger*)index
125 disposition:(WindowOpenDisposition*)disposition; 125 disposition:(WindowOpenDisposition*)disposition;
126 @end 126 @end
127 127
128 // A simple view class that prevents the Window Server from dragging the area 128 // A simple view class that prevents the Window Server from dragging the area
129 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also 129 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also
130 // falsely pick up clicks during rapid tab closure, so we have to account for 130 // falsely pick up clicks during rapid tab closure, so we have to account for
131 // that. 131 // that.
132 @interface TabStripControllerDragBlockingView : NSView { 132 @interface TabStripControllerDragBlockingView : NSView {
133 TabStripController* controller_; // weak; owns us 133 TabStripController* controller_; // weak; owns us
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 [subviews addObject:tabView]; 1429 [subviews addObject:tabView];
1430 } 1430 }
1431 } 1431 }
1432 if (selectedTabView) { 1432 if (selectedTabView) {
1433 [subviews addObject:selectedTabView]; 1433 [subviews addObject:selectedTabView];
1434 } 1434 }
1435 [tabStripView_ setSubviews:subviews]; 1435 [tabStripView_ setSubviews:subviews];
1436 [self setTabTrackingAreasEnabled:mouseInside_]; 1436 [self setTabTrackingAreasEnabled:mouseInside_];
1437 } 1437 }
1438 1438
1439 // Get the index and disposition for a potential URL(s) drop given a point (in 1439 // Get the index and disposition for a potential URL(s) drop given a location
1440 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the 1440 // (in window base coordinates). It considers x coordinate of the given
1441 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's 1441 // location. If it's in the "middle" of a tab, it drops on that tab. If it's to
1442 // to the left, it inserts to the left, and similarly for the right. 1442 // the left, it inserts to the left, and similarly for the right.
1443 - (void)droppingURLsAt:(NSPoint)point 1443 - (void)droppingURLsAt:(NSPoint)location
1444 givesIndex:(NSInteger*)index 1444 givesIndex:(NSInteger*)index
1445 disposition:(WindowOpenDisposition*)disposition { 1445 disposition:(WindowOpenDisposition*)disposition {
1446 // Proportion of the tab which is considered the "middle" (and causes things 1446 // Proportion of the tab which is considered the "middle" (and causes things
1447 // to drop on that tab). 1447 // to drop on that tab).
1448 const double kMiddleProportion = 0.5; 1448 const double kMiddleProportion = 0.5;
1449 const double kLRProportion = (1.0 - kMiddleProportion) / 2.0; 1449 const double kLRProportion = (1.0 - kMiddleProportion) / 2.0;
1450 1450
1451 DCHECK(index && disposition); 1451 DCHECK(index && disposition);
1452 NSInteger i = 0; 1452 NSInteger i = 0;
1453 for (TabController* tab in tabArray_.get()) { 1453 for (TabController* tab in tabArray_.get()) {
1454 NSView* view = [tab view]; 1454 NSView* view = [tab view];
1455 DCHECK([view isKindOfClass:[TabView class]]); 1455 DCHECK([view isKindOfClass:[TabView class]]);
1456 1456
1457 // Recall that |-[NSView frame]| is in its superview's coordinates, so a 1457 // Recall that |-[NSView frame]| is in its superview's coordinates, so a
1458 // |TabView|'s frame is in the coordinates of the |TabStripView| (which 1458 // |TabView|'s frame is in the coordinates of the |TabStripView|.
1459 // matches the coordinate system of |point|). 1459 NSRect frame = [tabStripView_ convertRectToBase:[view frame]];
1460 NSRect frame = [view frame];
1461 1460
1462 // Modify the frame to make it "unoverlapped". 1461 // Modify the frame to make it "unoverlapped".
1463 frame.origin.x += kTabOverlap / 2.0; 1462 frame.origin.x += kTabOverlap / 2.0;
1464 frame.size.width -= kTabOverlap; 1463 frame.size.width -= kTabOverlap;
1465 if (frame.size.width < 1.0) 1464 if (frame.size.width < 1.0)
1466 frame.size.width = 1.0; // try to avoid complete failure 1465 frame.size.width = 1.0; // try to avoid complete failure
1467 1466
1468 // Drop in a new tab to the left of tab |i|? 1467 // Drop in a new tab to the left of tab |i|?
1469 if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { 1468 if (location.x < (frame.origin.x + kLRProportion * frame.size.width)) {
1470 *index = i; 1469 *index = i;
1471 *disposition = NEW_FOREGROUND_TAB; 1470 *disposition = NEW_FOREGROUND_TAB;
1472 return; 1471 return;
1473 } 1472 }
1474 1473
1475 // Drop on tab |i|? 1474 // Drop on tab |i|?
1476 if (point.x <= (frame.origin.x + 1475 if (location.x <= (frame.origin.x +
1477 (1.0 - kLRProportion) * frame.size.width)) { 1476 (1.0 - kLRProportion) * frame.size.width)) {
1478 *index = i; 1477 *index = i;
1479 *disposition = CURRENT_TAB; 1478 *disposition = CURRENT_TAB;
1480 return; 1479 return;
1481 } 1480 }
1482 1481
1483 // (Dropping in a new tab to the right of tab |i| will be taken care of in 1482 // (Dropping in a new tab to the right of tab |i| will be taken care of in
1484 // the next iteration.) 1483 // the next iteration.)
1485 i++; 1484 i++;
1486 } 1485 }
1487 1486
1488 // If we've made it here, we want to append a new tab to the end. 1487 // If we've made it here, we want to append a new tab to the end.
1489 *index = -1; 1488 *index = -1;
1490 *disposition = NEW_FOREGROUND_TAB; 1489 *disposition = NEW_FOREGROUND_TAB;
1491 } 1490 }
1492 1491
1493 // (URLDropTargetController protocol) 1492 // Drop URLs at the given location.
1494 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { 1493 - (void)dropURLs:(NSArray*)urls at:(NSPoint)location {
1495 DCHECK_EQ(view, tabStripView_.get());
1496
1497 if ([urls count] < 1) { 1494 if ([urls count] < 1) {
1498 NOTREACHED(); 1495 NOTREACHED();
1499 return; 1496 return;
1500 } 1497 }
1501 1498
1502 //TODO(viettrungluu): dropping multiple URLs. 1499 //TODO(viettrungluu): dropping multiple URLs.
1503 if ([urls count] > 1) 1500 if ([urls count] > 1)
1504 NOTIMPLEMENTED(); 1501 NOTIMPLEMENTED();
1505 1502
1506 // Get the first URL and fix it up. 1503 // Get the first URL and fix it up.
1507 GURL url(URLFixerUpper::FixupURL( 1504 GURL url(URLFixerUpper::FixupURL(
1508 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string())); 1505 base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string()));
1509 1506
1510 // Get the index and disposition. 1507 // Get the index and disposition.
1511 NSInteger index; 1508 NSInteger index;
1512 WindowOpenDisposition disposition; 1509 WindowOpenDisposition disposition;
1513 [self droppingURLsAt:point 1510 [self droppingURLsAt:location
1514 givesIndex:&index 1511 givesIndex:&index
1515 disposition:&disposition]; 1512 disposition:&disposition];
1516 1513
1517 // Either insert a new tab or open in a current tab. 1514 // Either insert a new tab or open in a current tab.
1518 switch (disposition) { 1515 switch (disposition) {
1519 case NEW_FOREGROUND_TAB: 1516 case NEW_FOREGROUND_TAB:
1520 UserMetrics::RecordAction("Tab_DropURLBetweenTabs", browser_->profile()); 1517 UserMetrics::RecordAction("Tab_DropURLBetweenTabs", browser_->profile());
1521 browser_->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, index, 1518 browser_->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, index,
1522 true, NULL); 1519 true, NULL);
1523 break; 1520 break;
1524 case CURRENT_TAB: 1521 case CURRENT_TAB:
1525 UserMetrics::RecordAction("Tab_DropURLOnTab", browser_->profile()); 1522 UserMetrics::RecordAction("Tab_DropURLOnTab", browser_->profile());
1526 tabStripModel_->GetTabContentsAt(index)->OpenURL(url, GURL(), CURRENT_TAB, 1523 tabStripModel_->GetTabContentsAt(index)->OpenURL(url, GURL(), CURRENT_TAB,
1527 PageTransition::TYPED); 1524 PageTransition::TYPED);
1528 tabStripModel_->SelectTabContentsAt(index, true); 1525 tabStripModel_->SelectTabContentsAt(index, true);
1529 break; 1526 break;
1530 default: 1527 default:
1531 NOTIMPLEMENTED(); 1528 NOTIMPLEMENTED();
1532 } 1529 }
1533 } 1530 }
1534 1531
1535 // (URLDropTargetController protocol) 1532 // Update (possibly showing) the indicator which indicates where an URL drop
1536 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { 1533 // would happen.
1537 DCHECK_EQ(view, tabStripView_.get()); 1534 - (void)indicateDropURLsAt:(NSPoint)location {
1538
1539 // The minimum y-coordinate at which one should consider place the arrow. 1535 // The minimum y-coordinate at which one should consider place the arrow.
1540 const CGFloat arrowBaseY = 25; 1536 const CGFloat arrowBaseY = 25;
1541 1537
1542 NSInteger index; 1538 NSInteger index;
1543 WindowOpenDisposition disposition; 1539 WindowOpenDisposition disposition;
1544 [self droppingURLsAt:point 1540 [self droppingURLsAt:location
1545 givesIndex:&index 1541 givesIndex:&index
1546 disposition:&disposition]; 1542 disposition:&disposition];
1547 1543
1548 NSPoint arrowPos = NSMakePoint(0, arrowBaseY); 1544 NSPoint arrowPos = NSMakePoint(0, arrowBaseY);
1549 if (index == -1) { 1545 if (index == -1) {
1550 // Append a tab at the end. 1546 // Append a tab at the end.
1551 DCHECK(disposition == NEW_FOREGROUND_TAB); 1547 DCHECK(disposition == NEW_FOREGROUND_TAB);
1552 NSInteger lastIndex = [tabArray_ count] - 1; 1548 NSInteger lastIndex = [tabArray_ count] - 1;
1553 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame]; 1549 NSRect overRect = [[[tabArray_ objectAtIndex:lastIndex] view] frame];
1554 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0; 1550 arrowPos.x = overRect.origin.x + overRect.size.width - kTabOverlap / 2.0;
(...skipping 11 matching lines...) Expand all
1566 default: 1562 default:
1567 NOTREACHED(); 1563 NOTREACHED();
1568 } 1564 }
1569 } 1565 }
1570 1566
1571 [tabStripView_ setDropArrowPosition:arrowPos]; 1567 [tabStripView_ setDropArrowPosition:arrowPos];
1572 [tabStripView_ setDropArrowShown:YES]; 1568 [tabStripView_ setDropArrowShown:YES];
1573 [tabStripView_ setNeedsDisplay:YES]; 1569 [tabStripView_ setNeedsDisplay:YES];
1574 } 1570 }
1575 1571
1576 // (URLDropTargetController protocol) 1572 // Hide the indicator which indicates where an URL drop would happen.
1577 - (void)hideDropURLsIndicatorInView:(NSView*)view { 1573 - (void)hideDropURLsIndicator {
1578 DCHECK_EQ(view, tabStripView_.get());
1579
1580 if ([tabStripView_ dropArrowShown]) { 1574 if ([tabStripView_ dropArrowShown]) {
1581 [tabStripView_ setDropArrowShown:NO]; 1575 [tabStripView_ setDropArrowShown:NO];
1582 [tabStripView_ setNeedsDisplay:YES]; 1576 [tabStripView_ setNeedsDisplay:YES];
1583 } 1577 }
1584 } 1578 }
1585 1579
1586 - (GTMWindowSheetController*)sheetController { 1580 - (GTMWindowSheetController*)sheetController {
1587 if (!sheetController_.get()) 1581 if (!sheetController_.get())
1588 sheetController_.reset([[GTMWindowSheetController alloc] 1582 sheetController_.reset([[GTMWindowSheetController alloc]
1589 initWithWindow:[switchView_ window] delegate:self]); 1583 initWithWindow:[switchView_ window] delegate:self]);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 // Show next sheet 1672 // Show next sheet
1679 NSWindowController* controller = [[tab window] windowController]; 1673 NSWindowController* controller = [[tab window] windowController];
1680 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); 1674 DCHECK([controller isKindOfClass:[BrowserWindowController class]]);
1681 windows.front()->Realize( 1675 windows.front()->Realize(
1682 static_cast<BrowserWindowController*>(controller)); 1676 static_cast<BrowserWindowController*>(controller));
1683 } 1677 }
1684 } 1678 }
1685 } 1679 }
1686 1680
1687 @end 1681 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/tab_strip_controller.h ('k') | chrome/browser/cocoa/tab_strip_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698