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_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
12 #import "chrome/browser/themes/theme_properties.h" | 12 #import "chrome/browser/themes/theme_properties.h" |
13 #import "chrome/browser/themes/theme_service.h" | 13 #import "chrome/browser/themes/theme_service.h" |
14 #import "chrome/browser/ui/cocoa/sprite_view.h" | 14 #import "chrome/browser/ui/cocoa/sprite_view.h" |
15 #import "chrome/browser/ui/cocoa/tabs/media_indicator_button_cocoa.h" | 15 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h" |
16 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 16 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
17 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 17 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
18 #import "chrome/browser/ui/cocoa/themed_window.h" | 18 #import "chrome/browser/ui/cocoa/themed_window.h" |
19 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
20 #import "extensions/common/extension.h" | 20 #import "extensions/common/extension.h" |
21 #import "ui/base/cocoa/menu_controller.h" | 21 #import "ui/base/cocoa/menu_controller.h" |
22 #include "ui/base/material_design/material_design_controller.h" | 22 #include "ui/base/material_design/material_design_controller.h" |
23 | 23 |
24 @implementation TabController | 24 @implementation TabController |
25 | 25 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 selector:@selector(themeChangedNotification:) | 144 selector:@selector(themeChangedNotification:) |
145 name:kBrowserThemeDidChangeNotification | 145 name:kBrowserThemeDidChangeNotification |
146 object:nil]; | 146 object:nil]; |
147 | 147 |
148 [self internalSetSelected:selected_]; | 148 [self internalSetSelected:selected_]; |
149 } | 149 } |
150 return self; | 150 return self; |
151 } | 151 } |
152 | 152 |
153 - (void)dealloc { | 153 - (void)dealloc { |
154 [mediaIndicatorButton_ setAnimationDoneTarget:nil withAction:nil]; | 154 [alertIndicatorButton_ setAnimationDoneTarget:nil withAction:nil]; |
155 [mediaIndicatorButton_ setClickTarget:nil withAction:nil]; | 155 [alertIndicatorButton_ setClickTarget:nil withAction:nil]; |
156 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 156 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
157 [[self tabView] setController:nil]; | 157 [[self tabView] setController:nil]; |
158 [super dealloc]; | 158 [super dealloc]; |
159 } | 159 } |
160 | 160 |
161 // The internals of |-setSelected:| and |-setActive:| but doesn't set the | 161 // The internals of |-setSelected:| and |-setActive:| but doesn't set the |
162 // backing variables. This updates the drawing state and marks self as needing | 162 // backing variables. This updates the drawing state and marks self as needing |
163 // a re-draw. | 163 // a re-draw. |
164 - (void)internalSetSelected:(BOOL)selected { | 164 - (void)internalSetSelected:(BOOL)selected { |
165 TabView* tabView = [self tabView]; | 165 TabView* tabView = [self tabView]; |
(...skipping 25 matching lines...) Expand all Loading... |
191 - (void)toggleMute:(id)sender { | 191 - (void)toggleMute:(id)sender { |
192 if ([[self target] respondsToSelector:@selector(toggleMute:)]) { | 192 if ([[self target] respondsToSelector:@selector(toggleMute:)]) { |
193 [[self target] performSelector:@selector(toggleMute:) | 193 [[self target] performSelector:@selector(toggleMute:) |
194 withObject:[self view]]; | 194 withObject:[self view]]; |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 - (void)closeTab:(id)sender { | 198 - (void)closeTab:(id)sender { |
199 using base::UserMetricsAction; | 199 using base::UserMetricsAction; |
200 | 200 |
201 if (mediaIndicatorButton_ && ![mediaIndicatorButton_ isHidden]) { | 201 if (alertIndicatorButton_ && ![alertIndicatorButton_ isHidden]) { |
202 if ([mediaIndicatorButton_ isEnabled]) { | 202 if ([alertIndicatorButton_ isEnabled]) { |
203 content::RecordAction(UserMetricsAction("CloseTab_MuteToggleAvailable")); | 203 content::RecordAction(UserMetricsAction("CloseTab_MuteToggleAvailable")); |
204 } else if ([mediaIndicatorButton_ showingMediaState] == | 204 } else if ([alertIndicatorButton_ showingAlertState] == |
205 TAB_MEDIA_STATE_AUDIO_PLAYING) { | 205 TabAlertState::AUDIO_PLAYING) { |
206 content::RecordAction(UserMetricsAction("CloseTab_AudioIndicator")); | 206 content::RecordAction(UserMetricsAction("CloseTab_AudioIndicator")); |
207 } else { | 207 } else { |
208 content::RecordAction(UserMetricsAction("CloseTab_RecordingIndicator")); | 208 content::RecordAction(UserMetricsAction("CloseTab_RecordingIndicator")); |
209 } | 209 } |
210 } else { | 210 } else { |
211 content::RecordAction(UserMetricsAction("CloseTab_NoMediaIndicator")); | 211 content::RecordAction(UserMetricsAction("CloseTab_NoAlertIndicator")); |
212 } | 212 } |
213 | 213 |
214 if ([[self target] respondsToSelector:@selector(closeTab:)]) { | 214 if ([[self target] respondsToSelector:@selector(closeTab:)]) { |
215 [[self target] performSelector:@selector(closeTab:) | 215 [[self target] performSelector:@selector(closeTab:) |
216 withObject:[self view]]; | 216 withObject:[self view]]; |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 - (void)selectTab:(id)sender { | 220 - (void)selectTab:(id)sender { |
221 if ([[self tabView] isClosing]) | 221 if ([[self tabView] isClosing]) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 266 } |
267 | 267 |
268 - (void)setIconView:(SpriteView*)iconView { | 268 - (void)setIconView:(SpriteView*)iconView { |
269 [iconView_ removeFromSuperview]; | 269 [iconView_ removeFromSuperview]; |
270 iconView_.reset([iconView retain]); | 270 iconView_.reset([iconView retain]); |
271 | 271 |
272 if (iconView_) | 272 if (iconView_) |
273 [[self view] addSubview:iconView_]; | 273 [[self view] addSubview:iconView_]; |
274 } | 274 } |
275 | 275 |
276 - (MediaIndicatorButton*)mediaIndicatorButton { | 276 - (AlertIndicatorButton*)alertIndicatorButton { |
277 return mediaIndicatorButton_; | 277 return alertIndicatorButton_; |
278 } | 278 } |
279 | 279 |
280 - (void)setMediaState:(TabMediaState)mediaState { | 280 - (void)setAlertState:(TabAlertState)alertState { |
281 if (!mediaIndicatorButton_ && mediaState != TAB_MEDIA_STATE_NONE) { | 281 if (!alertIndicatorButton_ && alertState != TabAlertState::NONE) { |
282 mediaIndicatorButton_.reset([[MediaIndicatorButton alloc] init]); | 282 alertIndicatorButton_.reset([[AlertIndicatorButton alloc] init]); |
283 [self updateVisibility]; // Do layout and visibility before adding subview. | 283 [self updateVisibility]; // Do layout and visibility before adding subview. |
284 [[self view] addSubview:mediaIndicatorButton_]; | 284 [[self view] addSubview:alertIndicatorButton_]; |
285 [mediaIndicatorButton_ setAnimationDoneTarget:self | 285 [alertIndicatorButton_ setAnimationDoneTarget:self |
286 withAction:@selector(updateVisibility)]; | 286 withAction:@selector(updateVisibility)]; |
287 [mediaIndicatorButton_ setClickTarget:self | 287 [alertIndicatorButton_ setClickTarget:self |
288 withAction:@selector(toggleMute:)]; | 288 withAction:@selector(toggleMute:)]; |
289 } | 289 } |
290 [mediaIndicatorButton_ transitionToMediaState:mediaState]; | 290 [alertIndicatorButton_ transitionToAlertState:alertState]; |
291 } | 291 } |
292 | 292 |
293 - (HoverCloseButton*)closeButton { | 293 - (HoverCloseButton*)closeButton { |
294 return closeButton_; | 294 return closeButton_; |
295 } | 295 } |
296 | 296 |
297 - (NSString*)toolTip { | 297 - (NSString*)toolTip { |
298 return [[self tabView] toolTipText]; | 298 return [[self tabView] toolTipText]; |
299 } | 299 } |
300 | 300 |
(...skipping 12 matching lines...) Expand all Loading... |
313 if (availableWidth >= widthPerIcon && | 313 if (availableWidth >= widthPerIcon && |
314 availableWidth < (widthPerIcon + kPaddingBetweenIcons)) { | 314 availableWidth < (widthPerIcon + kPaddingBetweenIcons)) { |
315 return 1; | 315 return 1; |
316 } | 316 } |
317 return availableWidth / (widthPerIcon + kPaddingBetweenIcons); | 317 return availableWidth / (widthPerIcon + kPaddingBetweenIcons); |
318 } | 318 } |
319 | 319 |
320 - (BOOL)shouldShowIcon { | 320 - (BOOL)shouldShowIcon { |
321 return chrome::ShouldTabShowFavicon( | 321 return chrome::ShouldTabShowFavicon( |
322 [self iconCapacity], [self pinned], [self active], iconView_ != nil, | 322 [self iconCapacity], [self pinned], [self active], iconView_ != nil, |
323 !mediaIndicatorButton_ ? TAB_MEDIA_STATE_NONE : | 323 !alertIndicatorButton_ ? TabAlertState::NONE : |
324 [mediaIndicatorButton_ showingMediaState]); | 324 [alertIndicatorButton_ showingAlertState]); |
325 } | 325 } |
326 | 326 |
327 - (BOOL)shouldShowMediaIndicator { | 327 - (BOOL)shouldShowAlertIndicator { |
328 return chrome::ShouldTabShowMediaIndicator( | 328 return chrome::ShouldTabShowAlertIndicator( |
329 [self iconCapacity], [self pinned], [self active], iconView_ != nil, | 329 [self iconCapacity], [self pinned], [self active], iconView_ != nil, |
330 !mediaIndicatorButton_ ? TAB_MEDIA_STATE_NONE : | 330 !alertIndicatorButton_ ? TabAlertState::NONE : |
331 [mediaIndicatorButton_ showingMediaState]); | 331 [alertIndicatorButton_ showingAlertState]); |
332 } | 332 } |
333 | 333 |
334 - (BOOL)shouldShowCloseButton { | 334 - (BOOL)shouldShowCloseButton { |
335 return chrome::ShouldTabShowCloseButton( | 335 return chrome::ShouldTabShowCloseButton( |
336 [self iconCapacity], [self pinned], [self active]); | 336 [self iconCapacity], [self pinned], [self active]); |
337 } | 337 } |
338 | 338 |
339 - (void)setIconImage:(NSImage*)image { | 339 - (void)setIconImage:(NSImage*)image { |
340 [self setIconImage:image withToastAnimation:NO]; | 340 [self setIconImage:image withToastAnimation:NO]; |
341 } | 341 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 isIconShowing_ = newShowIcon; | 378 isIconShowing_ = newShowIcon; |
379 | 379 |
380 // If the tab is a pinned-tab, hide the title. | 380 // If the tab is a pinned-tab, hide the title. |
381 TabView* tabView = [self tabView]; | 381 TabView* tabView = [self tabView]; |
382 [tabView setTitleHidden:[self pinned]]; | 382 [tabView setTitleHidden:[self pinned]]; |
383 | 383 |
384 BOOL newShowCloseButton = [self shouldShowCloseButton]; | 384 BOOL newShowCloseButton = [self shouldShowCloseButton]; |
385 | 385 |
386 [closeButton_ setHidden:!newShowCloseButton]; | 386 [closeButton_ setHidden:!newShowCloseButton]; |
387 | 387 |
388 BOOL newShowMediaIndicator = [self shouldShowMediaIndicator]; | 388 BOOL newShowAlertIndicator = [self shouldShowAlertIndicator]; |
389 | 389 |
390 [mediaIndicatorButton_ setHidden:!newShowMediaIndicator]; | 390 [alertIndicatorButton_ setHidden:!newShowAlertIndicator]; |
391 | 391 |
392 if (newShowMediaIndicator) { | 392 if (newShowAlertIndicator) { |
393 NSRect newFrame = [mediaIndicatorButton_ frame]; | 393 NSRect newFrame = [alertIndicatorButton_ frame]; |
394 newFrame.size = [[mediaIndicatorButton_ image] size]; | 394 newFrame.size = [[alertIndicatorButton_ image] size]; |
395 if ([self pinned]) { | 395 if ([self pinned]) { |
396 // Tab is pinned: Position the media indicator in the center. | 396 // Tab is pinned: Position the alert indicator in the center. |
397 const CGFloat tabWidth = [TabController pinnedTabWidth]; | 397 const CGFloat tabWidth = [TabController pinnedTabWidth]; |
398 newFrame.origin.x = std::floor((tabWidth - NSWidth(newFrame)) / 2); | 398 newFrame.origin.x = std::floor((tabWidth - NSWidth(newFrame)) / 2); |
399 newFrame.origin.y = NSMinY(originalIconFrame_) - | 399 newFrame.origin.y = NSMinY(originalIconFrame_) - |
400 std::floor((NSHeight(newFrame) - NSHeight(originalIconFrame_)) / 2); | 400 std::floor((NSHeight(newFrame) - NSHeight(originalIconFrame_)) / 2); |
401 } else { | 401 } else { |
402 // The Frame for the mediaIndicatorButton_ depends on whether iconView_ | 402 // The Frame for the alertIndicatorButton_ depends on whether iconView_ |
403 // and/or closeButton_ are visible, and where they have been positioned. | 403 // and/or closeButton_ are visible, and where they have been positioned. |
404 const NSRect closeButtonFrame = [closeButton_ frame]; | 404 const NSRect closeButtonFrame = [closeButton_ frame]; |
405 newFrame.origin.x = NSMinX(closeButtonFrame); | 405 newFrame.origin.x = NSMinX(closeButtonFrame); |
406 // Position to the left of the close button when it is showing. | 406 // Position to the left of the close button when it is showing. |
407 if (newShowCloseButton) | 407 if (newShowCloseButton) |
408 newFrame.origin.x -= NSWidth(newFrame); | 408 newFrame.origin.x -= NSWidth(newFrame); |
409 // Media indicator is centered vertically, with respect to closeButton_. | 409 // Alert indicator is centered vertically, with respect to closeButton_. |
410 newFrame.origin.y = NSMinY(closeButtonFrame) - | 410 newFrame.origin.y = NSMinY(closeButtonFrame) - |
411 std::floor((NSHeight(newFrame) - NSHeight(closeButtonFrame)) / 2); | 411 std::floor((NSHeight(newFrame) - NSHeight(closeButtonFrame)) / 2); |
412 } | 412 } |
413 [mediaIndicatorButton_ setFrame:newFrame]; | 413 [alertIndicatorButton_ setFrame:newFrame]; |
414 [mediaIndicatorButton_ updateEnabledForMuteToggle]; | 414 [alertIndicatorButton_ updateEnabledForMuteToggle]; |
415 } | 415 } |
416 | 416 |
417 // Adjust the title view based on changes to the icon's and close button's | 417 // Adjust the title view based on changes to the icon's and close button's |
418 // visibility. | 418 // visibility. |
419 NSRect oldTitleFrame = [tabView titleFrame]; | 419 NSRect oldTitleFrame = [tabView titleFrame]; |
420 NSRect newTitleFrame; | 420 NSRect newTitleFrame; |
421 newTitleFrame.size.height = oldTitleFrame.size.height; | 421 newTitleFrame.size.height = oldTitleFrame.size.height; |
422 newTitleFrame.origin.y = oldTitleFrame.origin.y; | 422 newTitleFrame.origin.y = oldTitleFrame.origin.y; |
423 | 423 |
424 if (newShowIcon) { | 424 if (newShowIcon) { |
425 newTitleFrame.origin.x = NSMaxX([iconView_ frame]) + 4; | 425 newTitleFrame.origin.x = NSMaxX([iconView_ frame]) + 4; |
426 | 426 |
427 if (!ui::MaterialDesignController::IsModeMaterial()) { | 427 if (!ui::MaterialDesignController::IsModeMaterial()) { |
428 newTitleFrame.origin.x -= 4; | 428 newTitleFrame.origin.x -= 4; |
429 } | 429 } |
430 } else { | 430 } else { |
431 newTitleFrame.origin.x = originalIconFrame_.origin.x; | 431 newTitleFrame.origin.x = originalIconFrame_.origin.x; |
432 } | 432 } |
433 | 433 |
434 if (newShowMediaIndicator) { | 434 if (newShowAlertIndicator) { |
435 newTitleFrame.size.width = NSMinX([mediaIndicatorButton_ frame]) - | 435 newTitleFrame.size.width = NSMinX([alertIndicatorButton_ frame]) - |
436 newTitleFrame.origin.x; | 436 newTitleFrame.origin.x; |
437 } else if (newShowCloseButton) { | 437 } else if (newShowCloseButton) { |
438 newTitleFrame.size.width = NSMinX([closeButton_ frame]) - | 438 newTitleFrame.size.width = NSMinX([closeButton_ frame]) - |
439 newTitleFrame.origin.x; | 439 newTitleFrame.origin.x; |
440 } else { | 440 } else { |
441 newTitleFrame.size.width = NSMaxX([closeButton_ frame]) - | 441 newTitleFrame.size.width = NSMaxX([closeButton_ frame]) - |
442 newTitleFrame.origin.x; | 442 newTitleFrame.origin.x; |
443 } | 443 } |
444 | 444 |
445 [tabView setTitleFrame:newTitleFrame]; | 445 [tabView setTitleFrame:newTitleFrame]; |
(...skipping 21 matching lines...) Expand all Loading... |
467 YES : NO; | 467 YES : NO; |
468 } | 468 } |
469 return NO; | 469 return NO; |
470 } | 470 } |
471 | 471 |
472 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { | 472 - (void)maybeStartDrag:(NSEvent*)event forTab:(TabController*)tab { |
473 [[target_ dragController] maybeStartDrag:event forTab:tab]; | 473 [[target_ dragController] maybeStartDrag:event forTab:tab]; |
474 } | 474 } |
475 | 475 |
476 @end | 476 @end |
OLD | NEW |