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") {
"cocoa/tab_contents/tab_contents_controller.mm",
"cocoa/tabbed_browser_window.h",
"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.mm",
"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 {
kTabCrashed,
};
@class AlertIndicatorButtonCocoa;
@class MenuControllerCocoa;
@class TabViewCocoa;
@protocol TabControllerTarget;
......@@ -59,7 +58,6 @@ enum TabLoadingState {
@property(assign, nonatomic) BOOL selected;
@property(assign, nonatomic) id target;
@property(assign, nonatomic) GURL url;
@property(readonly, nonatomic) AlertIndicatorButtonCocoa* alertIndicatorButton;
@property(readonly, nonatomic) HoverCloseButton* closeButton;
// Default height for tabs.
......@@ -120,7 +118,6 @@ enum TabLoadingState {
- (NSView*)iconView;
- (int)iconCapacity;
- (BOOL)shouldShowIcon;
- (BOOL)shouldShowAlertIndicator;
- (BOOL)shouldShowCloseButton;
@end // TabControllerCocoa(TestingAPI)
......
......@@ -16,7 +16,6 @@
#import "chrome/browser/themes/theme_properties.h"
#import "chrome/browser/themes/theme_service.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"
#include "chrome/browser/ui/cocoa/tabs/tab_favicon_view.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
......@@ -64,7 +63,6 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate {
base::scoped_nsobject<TabFaviconView> iconView_;
base::scoped_nsobject<NSImage> icon_;
base::scoped_nsobject<NSView> attentionDotView_;
base::scoped_nsobject<AlertIndicatorButtonCocoa> alertIndicatorButton_;
base::scoped_nsobject<HoverCloseButton> closeButton_;
BOOL active_;
......@@ -198,8 +196,6 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
}
- (void)dealloc {
[alertIndicatorButton_ setAnimationDoneTarget:nil withAction:nil];
[alertIndicatorButton_ setClickTarget:nil withAction:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[self tabView] setController:nil];
[super dealloc];
......@@ -253,21 +249,6 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
}
- (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:)]) {
[[self target] performSelector:@selector(closeTab:)
withObject:[self view]];
......@@ -347,21 +328,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
}
}
- (AlertIndicatorButtonCocoa*)alertIndicatorButton {
return alertIndicatorButton_;
}
- (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 {
......@@ -425,15 +392,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
- (BOOL)shouldShowIcon {
return chrome::ShouldTabShowFavicon(
[self iconCapacity], [self pinned], [self active], [self showIcon],
!alertIndicatorButton_ ? TabAlertState::NONE
: [alertIndicatorButton_ showingAlertState]);
}
- (BOOL)shouldShowAlertIndicator {
return chrome::ShouldTabShowAlertIndicator(
[self iconCapacity], [self pinned], [self active], [self showIcon],
!alertIndicatorButton_ ? TabAlertState::NONE
: [alertIndicatorButton_ showingAlertState]);
TabAlertState::NONE);
}
- (BOOL)shouldShowCloseButton {
......@@ -543,38 +502,8 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
[closeButton_ setHidden:!newShowCloseButton];
BOOL newShowAlertIndicator = [self shouldShowAlertIndicator];
[alertIndicatorButton_ setHidden:!newShowAlertIndicator];
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
// visibility.
NSRect oldTitleFrame = [tabView titleFrame];
......@@ -584,9 +513,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
CGFloat titleLeft, titleRight;
if (isRTL) {
if (newShowAlertIndicator) {
titleLeft = NSMaxX([alertIndicatorButton_ frame]);
} else if (newShowCloseButton) {
if (newShowCloseButton) {
titleLeft = NSMaxX([closeButton_ frame]);
} else {
titleLeft = kTabLeadingPadding;
......@@ -597,9 +524,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
} else {
titleLeft = newShowIcon ? NSMaxX([iconView_ frame]) + kTitleLeadingPadding
: kTabLeadingPadding;
if (newShowAlertIndicator) {
titleRight = NSMinX([alertIndicatorButton_ frame]);
} else if (newShowCloseButton) {
if (newShowCloseButton) {
titleRight = NSMinX([closeButton_ frame]);
} else {
titleRight = NSWidth([[self tabView] frame]) - kTabTrailingPadding;
......@@ -632,7 +557,7 @@ constexpr CGFloat kPinnedTabWidth = kDefaultTabHeight * 2;
return base::SysUTF16ToNSString(chrome::AssembleTabAccessibilityLabel(
base::SysNSStringToUTF16([self title]),
[self loadingState] == kTabCrashed, false,
[[self alertIndicatorButton] showingAlertState]));
TabAlertState::NONE));
}
- (void)themeChangedNotification:(NSNotification*)notification {
......
......@@ -37,7 +37,6 @@
#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/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_strip_drag_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
......
......@@ -13,7 +13,6 @@
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/cocoa/cocoa_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_window_controller.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
......@@ -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
// buttons is available for click-to-select. If neither are visible, the
// entire tab region is available.
AlertIndicatorButtonCocoa* const indicator =
[controller_ alertIndicatorButton];
const int indicatorLeft = (!indicator || [indicator isHidden]) ?
NSWidth([self frame]) : NSMinX([indicator frame]);
const int indicatorLeft = NSWidth([self frame]);
const int closeButtonLeft = (!closeButton_ || [closeButton_ isHidden])
? NSWidth([self frame])
: NSMinX([closeButton_ frame]);
......
......@@ -4179,7 +4179,6 @@ test("unit_tests") {
"../browser/ui/cocoa/styled_text_field_cell_unittest.mm",
"../browser/ui/cocoa/styled_text_field_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_strip_controller_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