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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/i18n/rtl.h" |
14 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
15 #include "base/mac/scoped_nsautorelease_pool.h" | 16 #include "base/mac/scoped_nsautorelease_pool.h" |
16 #include "base/mac/sdk_forward_declarations.h" | 17 #include "base/mac/sdk_forward_declarations.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
19 #include "base/strings/sys_string_conversions.h" | 20 #include "base/strings/sys_string_conversions.h" |
20 #include "chrome/app/chrome_command_ids.h" | 21 #include "chrome/app/chrome_command_ids.h" |
21 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 22 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
22 #include "chrome/browser/extensions/tab_helper.h" | 23 #include "chrome/browser/extensions/tab_helper.h" |
23 #include "chrome/browser/favicon/favicon_utils.h" | 24 #include "chrome/browser/favicon/favicon_utils.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_navigator.h" | 29 #include "chrome/browser/ui/browser_navigator.h" |
29 #include "chrome/browser/ui/browser_navigator_params.h" | 30 #include "chrome/browser/ui/browser_navigator_params.h" |
30 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
31 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
32 #include "chrome/browser/ui/cocoa/drag_util.h" | 33 #include "chrome/browser/ui/cocoa/drag_util.h" |
33 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 34 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 35 #include "chrome/browser/ui/cocoa/l10n_util.h" |
34 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 36 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
35 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" | 37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" |
36 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 38 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
37 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h" | 39 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h" |
38 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 43 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
42 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 44 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
43 #import "chrome/browser/ui/cocoa/themed_window.h" | 45 #import "chrome/browser/ui/cocoa/themed_window.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // ettect the gtm_setDuration: provides. | 131 // ettect the gtm_setDuration: provides. |
130 [[NSAnimationContext currentContext] setDuration:kMinimumTimeInterval]; | 132 [[NSAnimationContext currentContext] setDuration:kMinimumTimeInterval]; |
131 } | 133 } |
132 } | 134 } |
133 | 135 |
134 private: | 136 private: |
135 bool animate_; | 137 bool animate_; |
136 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); | 138 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); |
137 }; | 139 }; |
138 | 140 |
| 141 CGFloat FlipXInView(NSView* view, CGFloat width, CGFloat x) { |
| 142 if (cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL()) |
| 143 return [view frame].size.width - x - width; |
| 144 return x; |
| 145 } |
| 146 |
139 } // namespace | 147 } // namespace |
140 | 148 |
141 @interface TabStripController (Private) | 149 @interface TabStripController (Private) |
142 - (void)addSubviewToPermanentList:(NSView*)aView; | 150 - (void)addSubviewToPermanentList:(NSView*)aView; |
143 - (void)regenerateSubviewList; | 151 - (void)regenerateSubviewList; |
144 - (NSInteger)indexForContentsView:(NSView*)view; | 152 - (NSInteger)indexForContentsView:(NSView*)view; |
145 - (NSImage*)iconImageForContents:(content::WebContents*)contents | 153 - (NSImage*)iconImageForContents:(content::WebContents*)contents |
146 atIndex:(NSInteger)modelIndex; | 154 atIndex:(NSInteger)modelIndex; |
147 - (void)updateIconsForContents:(content::WebContents*)contents | 155 - (void)updateIconsForContents:(content::WebContents*)contents |
148 atIndex:(NSInteger)modelIndex; | 156 atIndex:(NSInteger)modelIndex; |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 } | 1000 } |
993 | 1001 |
994 // Separate integral and fractional parts. | 1002 // Separate integral and fractional parts. |
995 CGFloat integralPart = std::floor(nonPinnedTabWidth); | 1003 CGFloat integralPart = std::floor(nonPinnedTabWidth); |
996 nonPinnedTabWidthFraction = nonPinnedTabWidth - integralPart; | 1004 nonPinnedTabWidthFraction = nonPinnedTabWidth - integralPart; |
997 nonPinnedTabWidth = integralPart; | 1005 nonPinnedTabWidth = integralPart; |
998 } | 1006 } |
999 | 1007 |
1000 BOOL visible = [[tabStripView_ window] isVisible]; | 1008 BOOL visible = [[tabStripView_ window] isVisible]; |
1001 | 1009 |
1002 CGFloat offset = [self leftIndentForControls]; | 1010 CGFloat offset = |
| 1011 cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL() |
| 1012 ? [self rightIndentForControls] |
| 1013 : [self leftIndentForControls]; |
1003 bool hasPlaceholderGap = false; | 1014 bool hasPlaceholderGap = false; |
1004 // Whether or not the last tab processed by the loop was a pinned tab. | 1015 // Whether or not the last tab processed by the loop was a pinned tab. |
1005 BOOL isLastTabPinned = NO; | 1016 BOOL isLastTabPinned = NO; |
1006 CGFloat tabWidthAccumulatedFraction = 0; | 1017 CGFloat tabWidthAccumulatedFraction = 0; |
1007 NSInteger laidOutNonPinnedTabs = 0; | 1018 NSInteger laidOutNonPinnedTabs = 0; |
1008 | 1019 |
1009 for (TabController* tab in tabArray_.get()) { | 1020 for (TabController* tab in tabArray_.get()) { |
1010 // Ignore a tab that is going through a close animation. | 1021 // Ignore a tab that is going through a close animation. |
1011 if ([closingControllers_ containsObject:tab]) | 1022 if ([closingControllers_ containsObject:tab]) |
1012 continue; | 1023 continue; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 // it in a specific location (i.e., from a drop). | 1112 // it in a specific location (i.e., from a drop). |
1102 if (newTab && visible && animate) { | 1113 if (newTab && visible && animate) { |
1103 if (NSEqualRects(droppedTabFrame_, NSZeroRect)) { | 1114 if (NSEqualRects(droppedTabFrame_, NSZeroRect)) { |
1104 [[tab view] setFrame:NSOffsetRect(tabFrame, 0, -NSHeight(tabFrame))]; | 1115 [[tab view] setFrame:NSOffsetRect(tabFrame, 0, -NSHeight(tabFrame))]; |
1105 } else { | 1116 } else { |
1106 [[tab view] setFrame:droppedTabFrame_]; | 1117 [[tab view] setFrame:droppedTabFrame_]; |
1107 droppedTabFrame_ = NSZeroRect; | 1118 droppedTabFrame_ = NSZeroRect; |
1108 } | 1119 } |
1109 } | 1120 } |
1110 | 1121 |
| 1122 tabFrame.origin.x = |
| 1123 FlipXInView(tabStripView_, tabFrame.size.width, tabFrame.origin.x); |
| 1124 |
1111 // Check the frame by identifier to avoid redundant calls to animator. | 1125 // Check the frame by identifier to avoid redundant calls to animator. |
1112 id frameTarget = visible && animate ? [[tab view] animator] : [tab view]; | 1126 id frameTarget = visible && animate ? [[tab view] animator] : [tab view]; |
1113 NSValue* identifier = [NSValue valueWithPointer:[tab view]]; | 1127 NSValue* identifier = [NSValue valueWithPointer:[tab view]]; |
1114 NSValue* oldTargetValue = [targetFrames_ objectForKey:identifier]; | 1128 NSValue* oldTargetValue = [targetFrames_ objectForKey:identifier]; |
1115 if (!oldTargetValue || | 1129 if (!oldTargetValue || |
1116 !NSEqualRects([oldTargetValue rectValue], tabFrame)) { | 1130 !NSEqualRects([oldTargetValue rectValue], tabFrame)) { |
1117 // Redraw the tab once it moves to its final location. Because we're | 1131 // Redraw the tab once it moves to its final location. Because we're |
1118 // using Core Animation, each tab caches its contents until told to | 1132 // using Core Animation, each tab caches its contents until told to |
1119 // redraw. Without forcing a redraw at the end of the move, tabs will | 1133 // redraw. Without forcing a redraw at the end of the move, tabs will |
1120 // display the wrong content when using a theme that creates transparent | 1134 // display the wrong content when using a theme that creates transparent |
(...skipping 20 matching lines...) Expand all Loading... |
1141 // be hidden, doing it again doesn't hurt. Otherwise position it | 1155 // be hidden, doing it again doesn't hurt. Otherwise position it |
1142 // appropriately, showing it if necessary. | 1156 // appropriately, showing it if necessary. |
1143 if (forceNewTabButtonHidden_) { | 1157 if (forceNewTabButtonHidden_) { |
1144 [newTabButton_ setHidden:YES]; | 1158 [newTabButton_ setHidden:YES]; |
1145 } else { | 1159 } else { |
1146 NSRect newTabNewFrame = [newTabButton_ frame]; | 1160 NSRect newTabNewFrame = [newTabButton_ frame]; |
1147 // We've already ensured there's enough space for the new tab button | 1161 // We've already ensured there's enough space for the new tab button |
1148 // so we don't have to check it against the available space. We do need | 1162 // so we don't have to check it against the available space. We do need |
1149 // to make sure we put it after any placeholder. | 1163 // to make sure we put it after any placeholder. |
1150 CGFloat maxTabX = MAX(offset, NSMaxX(placeholderFrame_) - kTabOverlap); | 1164 CGFloat maxTabX = MAX(offset, NSMaxX(placeholderFrame_) - kTabOverlap); |
| 1165 if (cocoa_l10n_util::ExperimentalMacRTLIsEnabled() && base::i18n::IsRTL()) { |
| 1166 maxTabX = FlipXInView(tabStripView_, [newTabButton_ frame].size.width, |
| 1167 maxTabX) - |
| 1168 (2 * kNewTabButtonOffset); |
| 1169 } |
1151 newTabNewFrame.origin = NSMakePoint(maxTabX + kNewTabButtonOffset, 0); | 1170 newTabNewFrame.origin = NSMakePoint(maxTabX + kNewTabButtonOffset, 0); |
1152 if ([tabContentsArray_ count]) | 1171 if ([tabContentsArray_ count]) |
1153 [newTabButton_ setHidden:NO]; | 1172 [newTabButton_ setHidden:NO]; |
1154 | 1173 |
1155 if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { | 1174 if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { |
1156 // Set the new tab button image correctly based on where the cursor is. | 1175 // Set the new tab button image correctly based on where the cursor is. |
1157 NSWindow* window = [tabStripView_ window]; | 1176 NSWindow* window = [tabStripView_ window]; |
1158 NSPoint currentMouse = [window mouseLocationOutsideOfEventStream]; | 1177 NSPoint currentMouse = [window mouseLocationOutsideOfEventStream]; |
1159 currentMouse = [tabStripView_ convertPoint:currentMouse fromView:nil]; | 1178 currentMouse = [tabStripView_ convertPoint:currentMouse fromView:nil]; |
1160 | 1179 |
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 for (int i = 0; i < tabStripModel_->count(); i++) { | 2334 for (int i = 0; i < tabStripModel_->count(); i++) { |
2316 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; | 2335 [self updateIconsForContents:tabStripModel_->GetWebContentsAt(i) atIndex:i]; |
2317 } | 2336 } |
2318 } | 2337 } |
2319 | 2338 |
2320 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2339 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
2321 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2340 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
2322 } | 2341 } |
2323 | 2342 |
2324 @end | 2343 @end |
OLD | NEW |