Commit 5de70a38 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

mac: Delete AlertIndicatorButtonCocoa.

Bug: 832676
Change-Id: Ib83450567e95f83f819980fccb2ea81c6be2a326
Reviewed-on: https://chromium-review.googlesource.com/1241496Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593725}
parent 8d62c04a
...@@ -233,8 +233,6 @@ jumbo_split_static_library("ui") { ...@@ -233,8 +233,6 @@ jumbo_split_static_library("ui") {
"cocoa/tab_contents/tab_contents_controller.mm", "cocoa/tab_contents/tab_contents_controller.mm",
"cocoa/tabbed_browser_window.h", "cocoa/tabbed_browser_window.h",
"cocoa/tabbed_browser_window.mm", "cocoa/tabbed_browser_window.mm",
"cocoa/tabs/alert_indicator_button_cocoa.h",
"cocoa/tabs/alert_indicator_button_cocoa.mm",
"cocoa/tabs/tab_controller.h", "cocoa/tabs/tab_controller.h",
"cocoa/tabs/tab_controller.mm", "cocoa/tabs/tab_controller.mm",
"cocoa/tabs/tab_controller_target.h", "cocoa/tabs/tab_controller_target.h",
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_TABS_ALERT_INDICATOR_BUTTON_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_TABS_ALERT_INDICATOR_BUTTON_COCOA_H_
#include <memory>
#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#import "ui/base/cocoa/hover_button.h"
namespace gfx {
class Animation;
class AnimationDelegate;
} // namespace gfx
// This is an HoverButtonCocoa subclass that serves as both the alert indicator
// icon (audio, tab capture, etc.), and as a mute button. It is meant to only
// be used as a subview of TabViewCocoa.
//
// When the indicator is transitioned to the audio playing or muting state, the
// button functionality is enabled and begins handling mouse events. Otherwise,
// this view behaves like an image and all mouse events will be handled by the
// its superview.
//
// Note: Send the |-setClickTarget:withAction:| message instead of the
// |-setTarget:| and |-setAction:| messages to be notified of button clicks.
@interface AlertIndicatorButtonCocoa : HoverButtonCocoa<ThemedWindowDrawing> {
@private
class FadeAnimationDelegate;
// Current TabAlertState. When animating fade-in/out, this reflects the
// indicator state at the end of the animation.
TabAlertState alertState_;
// Alert indicator fade-in/out animation (i.e., only on show/hide, not a
// continuous animation).
std::unique_ptr<gfx::AnimationDelegate> fadeAnimationDelegate_;
std::unique_ptr<gfx::Animation> fadeAnimation_;
TabAlertState showingAlertState_;
// Set to YES while the button is in the temporary dormant period after mute
// has been toggled.
BOOL isDormant_;
// Target and action invoked whenever a fade-in/out animation completes. This
// is used by TabControllerCocoa to layout the TabViewCocoa after an indicator
// has completely faded out.
id animationDoneTarget_; // weak
SEL animationDoneAction_;
// The image to show when the mouse hovers over the button.
base::scoped_nsobject<NSImage> affordanceImage_;
// Target and action invoked whenever an enabled button is clicked.
id clickTarget_; // weak
SEL clickAction_;
}
@property(readonly, nonatomic) TabAlertState showingAlertState;
// Initialize a new AlertIndicatorButtonCocoa in TabAlertState::NONE (i.e., a
// non-active indicator).
- (id)init;
// Updates button images, starts fade animations, and activates/deactivates
// button functionality as appropriate.
- (void)transitionToAlertState:(TabAlertState)nextState;
// Determines whether the AlertIndicatorButtonCocoa will be clickable for
// toggling muting. This should be called whenever the frame of this view is
// changed, and also whenever the active/inactive state of the tab has changed.
// Internally, |-transitionToAlertState:| will call this.
- (void)updateEnabledForMuteToggle;
// Register a message be sent to |target| whenever fade animations complete. A
// weak reference on |target| is held.
- (void)setAnimationDoneTarget:(id)target withAction:(SEL)action;
// Request a message be sent to |target| whenever the enabled button has been
// clicked. A weak reference on |target| is held.
- (void)setClickTarget:(id)target withAction:(SEL)action;
// ThemedWindowDrawing protocol support.
- (void)windowDidChangeTheme;
- (void)windowDidChangeActive;
@end
#endif // CHROME_BROWSER_UI_COCOA_TABS_ALERT_INDICATOR_BUTTON_COCOA_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
#include <string>
#include "base/command_line.h"
#include "base/mac/scoped_nsobject.h"
#include "base/test/scoped_task_environment.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "chrome/common/chrome_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
// A simple target to confirm an action was invoked.
@interface AlertIndicatorButtonTestTarget : NSObject {
@private
int count_;
}
@property(readonly, nonatomic) int count;
- (void)incrementCount:(id)sender;
@end
@implementation AlertIndicatorButtonTestTarget
@synthesize count = count_;
- (void)incrementCount:(id)sender {
++count_;
}
@end
namespace {
class AlertIndicatorButtonTestCocoa : public CocoaTest {
public:
AlertIndicatorButtonTestCocoa()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
std::string("--") + switches::kEnableTabAudioMuting);
// Create the AlertIndicatorButtonCocoa and add it to a view.
button_.reset([[AlertIndicatorButtonCocoa alloc] init]);
EXPECT_TRUE(button_ != nil);
[[test_window() contentView] addSubview:button_.get()];
// Initially the button is disabled and showing no indicator.
EXPECT_EQ(TabAlertState::NONE, [button_ showingAlertState]);
EXPECT_FALSE([button_ isEnabled]);
// Register target to be notified of clicks.
base::scoped_nsobject<AlertIndicatorButtonTestTarget> clickTarget(
[[AlertIndicatorButtonTestTarget alloc] init]);
EXPECT_EQ(0, [clickTarget count]);
[button_ setClickTarget:clickTarget withAction:@selector(incrementCount:)];
// Transition to audio indicator mode, and expect button is enabled.
[button_ transitionToAlertState:TabAlertState::AUDIO_PLAYING];
EXPECT_EQ(TabAlertState::AUDIO_PLAYING, [button_ showingAlertState]);
EXPECT_TRUE([button_ isEnabled]);
// Click, and expect one click notification.
EXPECT_EQ(0, [clickTarget count]);
[button_ performClick:button_];
EXPECT_EQ(1, [clickTarget count]);
// Transition to audio muting mode, and expect button is still enabled. A
// click should result in another click notification.
[button_ transitionToAlertState:TabAlertState::AUDIO_MUTING];
EXPECT_EQ(TabAlertState::AUDIO_MUTING, [button_ showingAlertState]);
EXPECT_TRUE([button_ isEnabled]);
[button_ performClick:button_];
EXPECT_EQ(2, [clickTarget count]);
// Transition to capturing mode. Now, the button is disabled since it
// should only be drawing the indicator icon (i.e., there is nothing to
// mute). A click should NOT result in another click notification.
[button_ transitionToAlertState:TabAlertState::TAB_CAPTURING];
EXPECT_EQ(TabAlertState::TAB_CAPTURING, [button_ showingAlertState]);
EXPECT_FALSE([button_ isEnabled]);
[button_ performClick:button_];
EXPECT_EQ(2, [clickTarget count]);
}
base::scoped_nsobject<AlertIndicatorButtonCocoa> button_;
// Needed for gfx::Animation.
base::test::ScopedTaskEnvironment scoped_task_environment_;
};
TEST_VIEW(AlertIndicatorButtonTestCocoa, button_)
} // namespace
...@@ -23,7 +23,6 @@ enum TabLoadingState { ...@@ -23,7 +23,6 @@ enum TabLoadingState {
kTabCrashed, kTabCrashed,
}; };
@class AlertIndicatorButtonCocoa;
@class MenuControllerCocoa; @class MenuControllerCocoa;
@class TabViewCocoa; @class TabViewCocoa;
@protocol TabControllerTarget; @protocol TabControllerTarget;
...@@ -59,7 +58,6 @@ enum TabLoadingState { ...@@ -59,7 +58,6 @@ enum TabLoadingState {
@property(assign, nonatomic) BOOL selected; @property(assign, nonatomic) BOOL selected;
@property(assign, nonatomic) id target; @property(assign, nonatomic) id target;
@property(assign, nonatomic) GURL url; @property(assign, nonatomic) GURL url;
@property(readonly, nonatomic) AlertIndicatorButtonCocoa* alertIndicatorButton;
@property(readonly, nonatomic) HoverCloseButton* closeButton; @property(readonly, nonatomic) HoverCloseButton* closeButton;
// Default height for tabs. // Default height for tabs.
...@@ -120,7 +118,6 @@ enum TabLoadingState { ...@@ -120,7 +118,6 @@ enum TabLoadingState {
- (NSView*)iconView; - (NSView*)iconView;
- (int)iconCapacity; - (int)iconCapacity;
- (BOOL)shouldShowIcon; - (BOOL)shouldShowIcon;
- (BOOL)shouldShowAlertIndicator;
- (BOOL)shouldShowCloseButton; - (BOOL)shouldShowCloseButton;
@end // TabControllerCocoa(TestingAPI) @end // TabControllerCocoa(TestingAPI)
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#import "chrome/browser/themes/theme_properties.h" #import "chrome/browser/themes/theme_properties.h"
#import "chrome/browser/themes/theme_service.h" #import "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/cocoa/l10n_util.h" #include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
#include "chrome/browser/ui/cocoa/tabs/tab_favicon_view.h" #include "chrome/browser/ui/cocoa/tabs/tab_favicon_view.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
...@@ -64,7 +63,6 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate { ...@@ -64,7 +63,6 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate {
base::scoped_nsobject<TabFaviconView> iconView_; base::scoped_nsobject<TabFaviconView> iconView_;
base::scoped_nsobject<NSImage> icon_; base::scoped_nsobject<NSImage> icon_;
base::scoped_nsobject<NSView> attentionDotView_; base::scoped_nsobject<NSView> attentionDotView_;
base::scoped_nsobject<AlertIndicatorButtonCocoa> alertIndicatorButton_;
base::scoped_nsobject<HoverCloseButton> closeButton_; base::scoped_nsobject<HoverCloseButton> closeButton_;
BOOL active_; BOOL active_;
...@@ -198,8 +196,6 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -198,8 +196,6 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
} }
- (void)dealloc { - (void)dealloc {
[alertIndicatorButton_ setAnimationDoneTarget:nil withAction:nil];
[alertIndicatorButton_ setClickTarget:nil withAction:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[[self tabView] setController:nil]; [[self tabView] setController:nil];
[super dealloc]; [super dealloc];
...@@ -253,21 +249,6 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -253,21 +249,6 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
} }
- (void)closeTab:(id)sender { - (void)closeTab:(id)sender {
using base::UserMetricsAction;
if (alertIndicatorButton_ && ![alertIndicatorButton_ isHidden]) {
if ([alertIndicatorButton_ isEnabled]) {
base::RecordAction(UserMetricsAction("CloseTab_MuteToggleAvailable"));
} else if ([alertIndicatorButton_ showingAlertState] ==
TabAlertState::AUDIO_PLAYING) {
base::RecordAction(UserMetricsAction("CloseTab_AudioIndicator"));
} else {
base::RecordAction(UserMetricsAction("CloseTab_RecordingIndicator"));
}
} else {
base::RecordAction(UserMetricsAction("CloseTab_NoAlertIndicator"));
}
if ([[self target] respondsToSelector:@selector(closeTab:)]) { if ([[self target] respondsToSelector:@selector(closeTab:)]) {
[[self target] performSelector:@selector(closeTab:) [[self target] performSelector:@selector(closeTab:)
withObject:[self view]]; withObject:[self view]];
...@@ -347,21 +328,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -347,21 +328,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
} }
} }
- (AlertIndicatorButtonCocoa*)alertIndicatorButton {
return alertIndicatorButton_;
}
- (void)setAlertState:(TabAlertState)alertState { - (void)setAlertState:(TabAlertState)alertState {
if (!alertIndicatorButton_ && alertState != TabAlertState::NONE) {
alertIndicatorButton_.reset([[AlertIndicatorButtonCocoa alloc] init]);
[self updateVisibility]; // Do layout and visibility before adding subview.
[[self view] addSubview:alertIndicatorButton_];
[alertIndicatorButton_ setAnimationDoneTarget:self
withAction:@selector(updateVisibility)];
[alertIndicatorButton_ setClickTarget:self
withAction:@selector(toggleMute:)];
}
[alertIndicatorButton_ transitionToAlertState:alertState];
} }
- (BOOL)blocked { - (BOOL)blocked {
...@@ -425,15 +392,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -425,15 +392,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
- (BOOL)shouldShowIcon { - (BOOL)shouldShowIcon {
return chrome::ShouldTabShowFavicon( return chrome::ShouldTabShowFavicon(
[self iconCapacity], [self pinned], [self active], [self showIcon], [self iconCapacity], [self pinned], [self active], [self showIcon],
!alertIndicatorButton_ ? TabAlertState::NONE TabAlertState::NONE);
: [alertIndicatorButton_ showingAlertState]);
}
- (BOOL)shouldShowAlertIndicator {
return chrome::ShouldTabShowAlertIndicator(
[self iconCapacity], [self pinned], [self active], [self showIcon],
!alertIndicatorButton_ ? TabAlertState::NONE
: [alertIndicatorButton_ showingAlertState]);
} }
- (BOOL)shouldShowCloseButton { - (BOOL)shouldShowCloseButton {
...@@ -543,38 +502,8 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -543,38 +502,8 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
[closeButton_ setHidden:!newShowCloseButton]; [closeButton_ setHidden:!newShowCloseButton];
BOOL newShowAlertIndicator = [self shouldShowAlertIndicator];
[alertIndicatorButton_ setHidden:!newShowAlertIndicator];
BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
if (newShowAlertIndicator) {
NSRect newFrame = [alertIndicatorButton_ frame];
newFrame.size = [[alertIndicatorButton_ image] size];
if ([self pinned]) {
// Tab is pinned: Position the alert indicator in the center.
const CGFloat tabWidth = [TabControllerCocoa pinnedTabWidth];
newFrame.origin.x = std::floor((tabWidth - NSWidth(newFrame)) / 2);
newFrame.origin.y =
kTabElementYOrigin -
std::floor((NSHeight(newFrame) - gfx::kFaviconSize) / 2);
} else {
// The Frame for the alertIndicatorButton_ depends on whether iconView_
// and/or closeButton_ are visible, and where they have been positioned.
const NSRect closeButtonFrame = [closeButton_ frame];
newFrame.origin.x = NSMinX(closeButtonFrame);
// Position before the close button when it is showing.
if (newShowCloseButton)
newFrame.origin.x += isRTL ? NSWidth(newFrame) : -NSWidth(newFrame);
// Alert indicator is centered vertically, with respect to closeButton_.
newFrame.origin.y = NSMinY(closeButtonFrame) -
std::floor((NSHeight(newFrame) - NSHeight(closeButtonFrame)) / 2);
}
[alertIndicatorButton_ setFrame:newFrame];
[alertIndicatorButton_ updateEnabledForMuteToggle];
}
// Adjust the title view based on changes to the icon's and close button's // Adjust the title view based on changes to the icon's and close button's
// visibility. // visibility.
NSRect oldTitleFrame = [tabView titleFrame]; NSRect oldTitleFrame = [tabView titleFrame];
...@@ -584,9 +513,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -584,9 +513,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
CGFloat titleLeft, titleRight; CGFloat titleLeft, titleRight;
if (isRTL) { if (isRTL) {
if (newShowAlertIndicator) { if (newShowCloseButton) {
titleLeft = NSMaxX([alertIndicatorButton_ frame]);
} else if (newShowCloseButton) {
titleLeft = NSMaxX([closeButton_ frame]); titleLeft = NSMaxX([closeButton_ frame]);
} else { } else {
titleLeft = kTabLeadingPadding; titleLeft = kTabLeadingPadding;
...@@ -597,9 +524,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -597,9 +524,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
} else { } else {
titleLeft = newShowIcon ? NSMaxX([iconView_ frame]) + kTitleLeadingPadding titleLeft = newShowIcon ? NSMaxX([iconView_ frame]) + kTitleLeadingPadding
: kTabLeadingPadding; : kTabLeadingPadding;
if (newShowAlertIndicator) { if (newShowCloseButton) {
titleRight = NSMinX([alertIndicatorButton_ frame]);
} else if (newShowCloseButton) {
titleRight = NSMinX([closeButton_ frame]); titleRight = NSMinX([closeButton_ frame]);
} else { } else {
titleRight = NSWidth([[self tabView] frame]) - kTabTrailingPadding; titleRight = NSWidth([[self tabView] frame]) - kTabTrailingPadding;
...@@ -632,7 +557,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2; ...@@ -632,7 +557,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
return base::SysUTF16ToNSString(chrome::AssembleTabAccessibilityLabel( return base::SysUTF16ToNSString(chrome::AssembleTabAccessibilityLabel(
base::SysNSStringToUTF16([self title]), base::SysNSStringToUTF16([self title]),
[self loadingState] == kTabCrashed, false, [self loadingState] == kTabCrashed, false,
[[self alertIndicatorButton] showingAlertState])); TabAlertState::NONE));
} }
- (void)themeChangedNotification:(NSNotification*)notification { - (void)themeChangedNotification:(NSNotification*)notification {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
...@@ -110,10 +109,6 @@ class TabControllerTest : public CocoaTest { ...@@ -110,10 +109,6 @@ class TabControllerTest : public CocoaTest {
protected: protected:
void CheckLayoutAndVisibilityOfSubviewsForAllStates(bool is_rtl) { void CheckLayoutAndVisibilityOfSubviewsForAllStates(bool is_rtl) {
static const TabAlertState kAlertStatesToTest[] = {
TabAlertState::NONE, TabAlertState::TAB_CAPTURING,
TabAlertState::AUDIO_PLAYING, TabAlertState::AUDIO_MUTING};
NSWindow* const window = test_window(); NSWindow* const window = test_window();
// Create TabControllerCocoa instance and place its view into the test // Create TabControllerCocoa instance and place its view into the test
...@@ -127,26 +122,13 @@ class TabControllerTest : public CocoaTest { ...@@ -127,26 +122,13 @@ class TabControllerTest : public CocoaTest {
base::scoped_nsobject<NSImage> favicon( base::scoped_nsobject<NSImage> favicon(
rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
// Trigger TabControllerCocoa to auto-create the AlertIndicatorButtonCocoa.
[controller setAlertState:TabAlertState::AUDIO_PLAYING];
[controller setAlertState:TabAlertState::NONE];
base::scoped_nsobject<AlertIndicatorButtonCocoa> alertIndicatorButton(
[[controller alertIndicatorButton] retain]);
ASSERT_TRUE(alertIndicatorButton.get());
// Perform layout over all possible combinations, checking for correct // Perform layout over all possible combinations, checking for correct
// results. // results.
for (int isPinnedTab = 0; isPinnedTab < 2; ++isPinnedTab) { for (int isPinnedTab = 0; isPinnedTab < 2; ++isPinnedTab) {
for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) { for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) {
for (size_t alertStateIndex = 0;
alertStateIndex < arraysize(kAlertStatesToTest);
++alertStateIndex) {
const TabAlertState alertState = kAlertStatesToTest[alertStateIndex];
SCOPED_TRACE(::testing::Message() SCOPED_TRACE(::testing::Message()
<< (isActiveTab ? "Active" : "Inactive") << ' ' << (isActiveTab ? "Active" : "Inactive") << ' '
<< (isPinnedTab ? "Pinned " : "") << (isPinnedTab ? "Pinned " : ""));
<< "Tab with alert indicator state "
<< static_cast<uint8_t>(alertState));
// Simulate what tab_strip_controller would do to set up the // Simulate what tab_strip_controller would do to set up the
// TabControllerCocoa state. // TabControllerCocoa state.
...@@ -155,7 +137,6 @@ class TabControllerTest : public CocoaTest { ...@@ -155,7 +137,6 @@ class TabControllerTest : public CocoaTest {
[controller setIconImage:favicon [controller setIconImage:favicon
forLoadingState:kTabDone forLoadingState:kTabDone
showIcon:YES]; showIcon:YES];
[controller setAlertState:alertState];
[controller updateVisibility]; [controller updateVisibility];
// Test layout for every width from maximum to minimum. // Test layout for every width from maximum to minimum.
...@@ -182,7 +163,6 @@ class TabControllerTest : public CocoaTest { ...@@ -182,7 +163,6 @@ class TabControllerTest : public CocoaTest {
} }
} }
} }
}
private: private:
static void CheckForExpectedLayoutAndVisibilityOfSubviews( static void CheckForExpectedLayoutAndVisibilityOfSubviews(
...@@ -201,24 +181,6 @@ class TabControllerTest : public CocoaTest { ...@@ -201,24 +181,6 @@ class TabControllerTest : public CocoaTest {
EXPECT_LE(NSMinY(tabFrame), NSMinY(iconFrame)); EXPECT_LE(NSMinY(tabFrame), NSMinY(iconFrame));
EXPECT_LE(NSMaxY(iconFrame), NSMaxY(tabFrame)); EXPECT_LE(NSMaxY(iconFrame), NSMaxY(tabFrame));
} }
if ([controller shouldShowIcon] && [controller shouldShowAlertIndicator]) {
EXPECT_LE(NSMaxX([[controller iconView] frame]),
NSMinX([[controller alertIndicatorButton] frame]));
}
if ([controller shouldShowAlertIndicator]) {
const NSRect alertIndicatorFrame =
[[controller alertIndicatorButton] frame];
if (NSWidth(titleFrame) > 0)
EXPECT_LE(NSMaxX(titleFrame), NSMinX(alertIndicatorFrame));
EXPECT_LE(NSMaxX(alertIndicatorFrame), NSMaxX(tabFrame));
EXPECT_LE(NSMinY(tabFrame), NSMinY(alertIndicatorFrame));
EXPECT_LE(NSMaxY(alertIndicatorFrame), NSMaxY(tabFrame));
}
if ([controller shouldShowAlertIndicator] &&
[controller shouldShowCloseButton]) {
EXPECT_LE(NSMaxX([[controller alertIndicatorButton] frame]),
NSMinX([[controller closeButton] frame]));
}
if ([controller shouldShowCloseButton]) { if ([controller shouldShowCloseButton]) {
const NSRect closeButtonFrame = [[controller closeButton] frame]; const NSRect closeButtonFrame = [[controller closeButton] frame];
if (NSWidth(titleFrame) > 0) if (NSWidth(titleFrame) > 0)
...@@ -241,22 +203,6 @@ class TabControllerTest : public CocoaTest { ...@@ -241,22 +203,6 @@ class TabControllerTest : public CocoaTest {
if (NSWidth(titleFrame) > 0) if (NSWidth(titleFrame) > 0)
EXPECT_LE(NSMaxX(closeButtonFrame), NSMinX(titleFrame)); EXPECT_LE(NSMaxX(closeButtonFrame), NSMinX(titleFrame));
} }
if ([controller shouldShowCloseButton] &&
[controller shouldShowAlertIndicator]) {
EXPECT_LE(NSMaxX([[controller closeButton] frame]),
NSMinX([[controller alertIndicatorButton] frame]));
}
if ([controller shouldShowAlertIndicator]) {
const NSRect alertIndicatorFrame =
[[controller alertIndicatorButton] frame];
EXPECT_TRUE(NSContainsRect(tabFrame, alertIndicatorFrame));
if (NSWidth(titleFrame) > 0)
EXPECT_LE(NSMaxX(alertIndicatorFrame), NSMinX(titleFrame));
}
if ([controller shouldShowAlertIndicator] && [controller shouldShowIcon]) {
EXPECT_LE(NSMaxX([[controller alertIndicatorButton] frame]),
NSMinX([[controller iconView] frame]));
}
if ([controller shouldShowIcon]) { if ([controller shouldShowIcon]) {
const NSRect iconFrame = [[controller iconView] frame]; const NSRect iconFrame = [[controller iconView] frame];
EXPECT_TRUE(NSContainsRect(tabFrame, iconFrame)); EXPECT_TRUE(NSContainsRect(tabFrame, iconFrame));
...@@ -268,17 +214,9 @@ class TabControllerTest : public CocoaTest { ...@@ -268,17 +214,9 @@ class TabControllerTest : public CocoaTest {
static void CheckVisibilityOfSubviews(const TabControllerCocoa* controller) { static void CheckVisibilityOfSubviews(const TabControllerCocoa* controller) {
// Check whether subviews should be visible when they are supposed to be, // Check whether subviews should be visible when they are supposed to be,
// given Tab size and TabRendererData state. // given Tab size and TabRendererData state.
const TabAlertState indicatorState =
[[controller alertIndicatorButton] showingAlertState];
if ([controller pinned]) { if ([controller pinned]) {
EXPECT_EQ(1, [controller iconCapacity]); EXPECT_EQ(1, [controller iconCapacity]);
if (indicatorState != TabAlertState::NONE) {
EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_TRUE([controller shouldShowAlertIndicator]);
} else {
EXPECT_TRUE([controller shouldShowIcon]); EXPECT_TRUE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowAlertIndicator]);
}
EXPECT_FALSE([controller shouldShowCloseButton]); EXPECT_FALSE([controller shouldShowCloseButton]);
} else if ([controller selected]) { } else if ([controller selected]) {
EXPECT_TRUE([controller shouldShowCloseButton]); EXPECT_TRUE([controller shouldShowCloseButton]);
...@@ -286,24 +224,13 @@ class TabControllerTest : public CocoaTest { ...@@ -286,24 +224,13 @@ class TabControllerTest : public CocoaTest {
case 0: case 0:
case 1: case 1:
EXPECT_FALSE([controller shouldShowIcon]); EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowAlertIndicator]);
break; break;
case 2: case 2:
if (indicatorState != TabAlertState::NONE) {
EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_TRUE([controller shouldShowAlertIndicator]);
} else {
EXPECT_TRUE([controller shouldShowIcon]); EXPECT_TRUE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowAlertIndicator]);
}
break; break;
default: default:
EXPECT_LE(3, [controller iconCapacity]); EXPECT_LE(3, [controller iconCapacity]);
EXPECT_TRUE([controller shouldShowIcon]); EXPECT_TRUE([controller shouldShowIcon]);
if (indicatorState != TabAlertState::NONE)
EXPECT_TRUE([controller shouldShowAlertIndicator]);
else
EXPECT_FALSE([controller shouldShowAlertIndicator]);
break; break;
} }
} else { // Tab not selected/active and not pinned tab. } else { // Tab not selected/active and not pinned tab.
...@@ -311,25 +238,14 @@ class TabControllerTest : public CocoaTest { ...@@ -311,25 +238,14 @@ class TabControllerTest : public CocoaTest {
case 0: case 0:
EXPECT_FALSE([controller shouldShowCloseButton]); EXPECT_FALSE([controller shouldShowCloseButton]);
EXPECT_FALSE([controller shouldShowIcon]); EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowAlertIndicator]);
break; break;
case 1: case 1:
EXPECT_FALSE([controller shouldShowCloseButton]); EXPECT_FALSE([controller shouldShowCloseButton]);
if (indicatorState != TabAlertState::NONE) {
EXPECT_FALSE([controller shouldShowIcon]);
EXPECT_TRUE([controller shouldShowAlertIndicator]);
} else {
EXPECT_TRUE([controller shouldShowIcon]); EXPECT_TRUE([controller shouldShowIcon]);
EXPECT_FALSE([controller shouldShowAlertIndicator]);
}
break; break;
default: default:
EXPECT_LE(2, [controller iconCapacity]); EXPECT_LE(2, [controller iconCapacity]);
EXPECT_TRUE([controller shouldShowIcon]); EXPECT_TRUE([controller shouldShowIcon]);
if (indicatorState != TabAlertState::NONE)
EXPECT_TRUE([controller shouldShowAlertIndicator]);
else
EXPECT_FALSE([controller shouldShowAlertIndicator]);
break; break;
} }
} }
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "chrome/browser/ui/cocoa/l10n_util.h" #include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h"
#import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
#import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/cocoa/cocoa_util.h" #include "chrome/browser/ui/cocoa/cocoa_util.h"
#include "chrome/browser/ui/cocoa/l10n_util.h" #include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
#import "chrome/browser/ui/cocoa/tabs/tab_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
#import "chrome/browser/ui/cocoa/themed_window.h" #import "chrome/browser/ui/cocoa/themed_window.h"
...@@ -734,10 +733,7 @@ ui::ThreePartImage& GetStrokeImage(bool active, StrokeType stroke_type) { ...@@ -734,10 +733,7 @@ ui::ThreePartImage& GetStrokeImage(bool active, StrokeType stroke_type) {
// Assume the entire region to the left of the alert indicator and/or close // Assume the entire region to the left of the alert indicator and/or close
// buttons is available for click-to-select. If neither are visible, the // buttons is available for click-to-select. If neither are visible, the
// entire tab region is available. // entire tab region is available.
AlertIndicatorButtonCocoa* const indicator = const int indicatorLeft = NSWidth([self frame]);
[controller_ alertIndicatorButton];
const int indicatorLeft = (!indicator || [indicator isHidden]) ?
NSWidth([self frame]) : NSMinX([indicator frame]);
const int closeButtonLeft = (!closeButton_ || [closeButton_ isHidden]) const int closeButtonLeft = (!closeButton_ || [closeButton_ isHidden])
? NSWidth([self frame]) ? NSWidth([self frame])
: NSMinX([closeButton_ frame]); : NSMinX([closeButton_ frame]);
......
...@@ -4179,7 +4179,6 @@ test("unit_tests") { ...@@ -4179,7 +4179,6 @@ test("unit_tests") {
"../browser/ui/cocoa/styled_text_field_cell_unittest.mm", "../browser/ui/cocoa/styled_text_field_cell_unittest.mm",
"../browser/ui/cocoa/styled_text_field_unittest.mm", "../browser/ui/cocoa/styled_text_field_unittest.mm",
"../browser/ui/cocoa/tabbed_browser_window_unittest.mm", "../browser/ui/cocoa/tabbed_browser_window_unittest.mm",
"../browser/ui/cocoa/tabs/alert_indicator_button_cocoa_unittest.mm",
"../browser/ui/cocoa/tabs/tab_controller_unittest.mm", "../browser/ui/cocoa/tabs/tab_controller_unittest.mm",
"../browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm", "../browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm",
"../browser/ui/cocoa/tabs/tab_strip_view_unittest.mm", "../browser/ui/cocoa/tabs/tab_strip_view_unittest.mm",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment