Commit a738bf5a authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

mac: Delete the Cocoa app menu.

Bug: 832676
Change-Id: I2e98924794cb7165f1355aeeb66a419c82f4a82a
Reviewed-on: https://chromium-review.googlesource.com/1239640
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593467}
parent 145d1eba
This diff is collapsed.
......@@ -8,7 +8,6 @@ import("//ui/base/ui_features.gni")
assert(is_mac)
translated_xibs = [
"AppMenu.xib",
"SaveAccessoryView.xib",
"TaskManager.xib",
"Toolbar.xib",
......
......@@ -50,16 +50,6 @@ jumbo_split_static_library("ui") {
"cocoa/animatable_image.mm",
"cocoa/animatable_view.h",
"cocoa/animatable_view.mm",
"cocoa/app_menu/app_menu_button_cell.h",
"cocoa/app_menu/app_menu_button_cell.mm",
"cocoa/app_menu/app_menu_controller.h",
"cocoa/app_menu/app_menu_controller.mm",
"cocoa/app_menu/menu_tracked_button.h",
"cocoa/app_menu/menu_tracked_button.mm",
"cocoa/app_menu/menu_tracked_root_view.h",
"cocoa/app_menu/menu_tracked_root_view.mm",
"cocoa/app_menu/recent_tabs_menu_model_delegate.h",
"cocoa/app_menu/recent_tabs_menu_model_delegate.mm",
"cocoa/apps/chrome_app_window_client_views_cocoa.mm",
"cocoa/apps/native_app_window_cocoa.h",
"cocoa/apps/native_app_window_cocoa.mm",
......
rsesek@chromium.org
# COMPONENT: UI>Browser>Core
// Copyright (c) 2010 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_APP_MENU_APP_MENU_BUTTON_CELL_H_
#define CHROME_BROWSER_UI_COCOA_APP_MENU_APP_MENU_BUTTON_CELL_H_
#import <Cocoa/Cocoa.h>
// The AppMenuButtonCell overrides drawing the background gradient to use the
// same colors as NSSmallSquareBezelStyle but as a smooth gradient, rather than
// two blocks of colors. This also uses the blue menu highlight color for the
// pressed state.
@interface AppMenuButtonCell : NSButtonCell {
}
@end
#endif // CHROME_BROWSER_UI_COCOA_APP_MENU_APP_MENU_BUTTON_CELL_H_
// Copyright (c) 2011 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/app_menu/app_menu_button_cell.h"
#include "base/mac/scoped_nsobject.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
@implementation AppMenuButtonCell
- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView {
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
// Inset the rect to match the appearance of the layout of interface builder.
// The bounding rect of buttons is actually larger than the display rect shown
// there.
frame = NSInsetRect(frame, 0.0, 1.0);
// Stroking the rect gives a weak stroke. Filling and insetting gives a
// strong, un-anti-aliased border.
[[NSColor colorWithDeviceWhite:0.663 alpha:1.0] set];
NSRectFill(frame);
frame = NSInsetRect(frame, 1.0, 1.0);
// The default state should be a subtle gray gradient.
if (![self isHighlighted]) {
NSColor* end = [NSColor colorWithDeviceWhite:0.922 alpha:1.0];
base::scoped_nsobject<NSGradient> gradient(
[[NSGradient alloc] initWithStartingColor:[NSColor whiteColor]
endingColor:end]);
[gradient drawInRect:frame angle:90.0];
} else {
// |+selectedMenuItemColor| appears to be a gradient, so just filling the
// rect with that color produces the desired effect.
[[NSColor selectedMenuItemColor] set];
NSRectFill(frame);
}
}
- (NSBackgroundStyle)interiorBackgroundStyle {
if ([self isHighlighted])
return NSBackgroundStyleDark;
return [super interiorBackgroundStyle];
}
@end
// Copyright (c) 2011 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.
#include "base/mac/scoped_nsobject.h"
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/ui/cocoa/app_menu/app_menu_button_cell.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@interface TestAppMenuButton : NSButton
@end
@implementation TestAppMenuButton
+ (Class)cellClass {
return [AppMenuButtonCell class];
}
@end
namespace {
class AppMenuButtonCellTest : public CocoaTest {
public:
void SetUp() override {
CocoaTest::SetUp();
NSRect frame = NSMakeRect(10, 10, 50, 19);
button_.reset([[TestAppMenuButton alloc] initWithFrame:frame]);
[button_ setBezelStyle:NSSmallSquareBezelStyle];
[[button_ cell] setControlSize:NSSmallControlSize];
[button_ setTitle:@"Allays"];
[button_ setButtonType:NSMomentaryPushInButton];
}
base::scoped_nsobject<NSButton> button_;
};
TEST_F(AppMenuButtonCellTest, Draw) {
ASSERT_TRUE(button_.get());
[[test_window() contentView] addSubview:button_.get()];
[button_ setNeedsDisplay:YES];
}
TEST_F(AppMenuButtonCellTest, DrawHighlight) {
ASSERT_TRUE(button_.get());
[[test_window() contentView] addSubview:button_.get()];
[button_ highlight:YES];
[button_ setNeedsDisplay:YES];
}
} // namespace
// Copyright (c) 2012 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_APP_MENU_APP_MENU_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_APP_MENU_APP_MENU_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
#import "base/mac/scoped_nsobject.h"
#include "base/time/time.h"
#import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
#import "ui/base/cocoa/menu_controller.h"
class BookmarkMenuBridge;
class Browser;
@class BrowserActionsContainerView;
@class BrowserActionsController;
@class MenuTrackedRootView;
class RecentTabsMenuModelDelegate;
@class ToolbarController;
@class AppMenuButtonViewController;
class AppMenuModel;
namespace AppMenuControllerInternal {
class AcceleratorDelegate;
class ToolbarActionsBarObserverHelper;
class ZoomLevelObserver;
} // namespace AppMenuControllerInternal
namespace ui {
class AcceleratorProvider;
} // namespace ui
// The App menu has a creative layout, with buttons in menu items. There is a
// cross-platform model for this special menu, but on the Mac it's easier to
// get spacing and alignment precisely right using a NIB. To do that, we
// subclass the generic MenuControllerCocoa implementation and special-case the
// two items that require specific layout and load them from the NIB.
//
// This object is owned by the ToolbarController and receives its NIB-based
// views using the shim view controller below.
@interface AppMenuController
: MenuControllerCocoa<NSMenuDelegate, HasWeakBrowserPointer> {
@private
// Used to provide accelerators for the menu.
std::unique_ptr<AppMenuControllerInternal::AcceleratorDelegate>
acceleratorDelegate_;
// The model, rebuilt each time the |-menuNeedsUpdate:|.
std::unique_ptr<AppMenuModel> appMenuModel_;
// Used to update icons in the recent tabs menu. This must be declared after
// |appMenuModel_| so that it gets deleted first.
std::unique_ptr<RecentTabsMenuModelDelegate> recentTabsMenuModelDelegate_;
// A shim NSViewController that loads the buttons from the NIB because ObjC
// doesn't have multiple inheritance as this class is a MenuControllerCocoa.
base::scoped_nsobject<AppMenuButtonViewController> buttonViewController_;
// The browser for which this controller exists.
Browser* browser_; // weak
// Used to build the bookmark submenu.
std::unique_ptr<BookmarkMenuBridge> bookmarkMenuBridge_;
// Observer for page zoom level change notifications.
std::unique_ptr<AppMenuControllerInternal::ZoomLevelObserver>
zoom_level_observer_;
// Observer for the main window's ToolbarActionsBar changing size.
std::unique_ptr<AppMenuControllerInternal::ToolbarActionsBarObserverHelper>
toolbar_actions_bar_observer_;
// The controller for the toolbar actions overflow that is stored in the
// app menu.
// This will only be present if the extension action redesign switch is on.
base::scoped_nsobject<BrowserActionsController> browserActionsController_;
// The menu item containing the browser actions overflow container.
NSMenuItem* browserActionsMenuItem_;
// The time at which the menu was opened.
base::TimeTicks menuOpenTime_;
}
// Designated initializer.
- (id)initWithBrowser:(Browser*)browser;
// Used to dispatch commands from the App menu. The custom items within the
// menu cannot be hooked up directly to First Responder because the window in
// which the controls reside is not the BrowserWindowController, but a
// NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system.
- (IBAction)dispatchAppMenuCommand:(id)sender;
// Returns the weak reference to the AppMenuModel.
- (AppMenuModel*)appMenuModel;
// Creates a RecentTabsMenuModelDelegate instance which will take care of
// updating the recent tabs submenu.
- (void)updateRecentTabsSubmenu;
// Updates the browser actions section of the menu.
- (void)updateBrowserActionsSubmenu;
// Retuns the weak reference to the BrowserActionsController.
- (BrowserActionsController*)browserActionsController;
- (ui::AcceleratorProvider*)acceleratorProvider;
@end
////////////////////////////////////////////////////////////////////////////////
// Shim view controller that merely unpacks objects from a NIB.
@interface AppMenuButtonViewController : NSViewController {
@private
AppMenuController* controller_;
MenuTrackedRootView* editItem_;
NSButton* editCut_;
NSButton* editCopy_;
NSButton* editPaste_;
MenuTrackedRootView* zoomItem_;
NSButton* zoomPlus_;
NSButton* zoomDisplay_;
NSButton* zoomMinus_;
NSButton* zoomFullScreen_;
MenuTrackedRootView* toolbarActionsOverflowItem_;
BrowserActionsContainerView* overflowActionsContainerView_;
}
@property(retain, nonatomic) IBOutlet MenuTrackedRootView* editItem;
@property(retain, nonatomic) IBOutlet NSButton* editCut;
@property(retain, nonatomic) IBOutlet NSButton* editCopy;
@property(retain, nonatomic) IBOutlet NSButton* editPaste;
@property(retain, nonatomic) IBOutlet MenuTrackedRootView* zoomItem;
@property(retain, nonatomic) IBOutlet NSButton* zoomPlus;
@property(retain, nonatomic) IBOutlet NSButton* zoomDisplay;
@property(retain, nonatomic) IBOutlet NSButton* zoomMinus;
@property(retain, nonatomic) IBOutlet NSButton* zoomFullScreen;
@property(retain, nonatomic)
IBOutlet MenuTrackedRootView* toolbarActionsOverflowItem;
@property(retain, nonatomic)
IBOutlet BrowserActionsContainerView* overflowActionsContainerView;
- (id)initWithController:(AppMenuController*)controller;
- (IBAction)dispatchAppMenuCommand:(id)sender;
@end
#endif // CHROME_BROWSER_UI_COCOA_APP_MENU_APP_MENU_CONTROLLER_H_
// Copyright (c) 2010 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_APP_MENU_MENU_TRACKED_BUTTON_H_
#define CHROME_BROWSER_UI_COCOA_APP_MENU_MENU_TRACKED_BUTTON_H_
#import <Cocoa/Cocoa.h>
// A MenuTrackedButton is meant to be used whenever a button is placed inside
// the custom view of an NSMenuItem. If the user opens the menu in a non-sticky
// fashion (i.e. clicks, holds, and drags) and then releases the mouse over
// a MenuTrackedButton, it will |-performClick:| itself.
//
// To create the hover state effects, there are two code paths. When the menu
// is opened sticky, a tracking rect produces mouse entered/exit events that
// allow for setting the cell's highlight property. When in a drag cycle,
// however, the only event received is |-mouseDragged:|. Therefore, a
// delayed selector is scheduled to poll the mouse location after each drag
// event. This checks if the user is still over the button after the drag
// events stop being sent, indicating either the user is hovering without
// movement or that the mouse is no longer over the receiver.
@interface MenuTrackedButton : NSButton {
@private
// If the button received a |-mouseEntered:| event. This short-circuits the
// custom drag tracking logic.
BOOL didEnter_;
// Whether or not the user is in a click-drag-release event sequence. If so
// and this receives a |-mouseUp:|, then this will click itself.
BOOL tracking_;
// In order to get hover effects when the menu is sticky-opened, a tracking
// rect needs to be installed on the button.
NSTrackingRectTag trackingTag_;
}
@property(nonatomic, readonly, getter=isTracking) BOOL tracking;
@end
#endif // CHROME_BROWSER_UI_COCOA_APP_MENU_MENU_TRACKED_BUTTON_H_
// Copyright (c) 2011 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/app_menu/menu_tracked_button.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
@interface MenuTrackedButton (Private)
- (void)doHighlight:(BOOL)highlight;
- (void)checkMouseInRect;
- (NSRect)insetBounds;
@end
@implementation MenuTrackedButton
@synthesize tracking = tracking_;
- (void)updateTrackingAreas {
[super updateTrackingAreas];
[self removeTrackingRect:trackingTag_];
trackingTag_ = [self addTrackingRect:NSInsetRect([self bounds], 1, 1)
owner:self
userData:NULL
assumeInside:NO];
}
- (void)viewDidMoveToWindow {
[self updateTrackingAreas];
[self doHighlight:NO];
}
- (void)mouseEntered:(NSEvent*)theEvent {
if (!tracking_) {
didEnter_ = YES;
}
[self doHighlight:YES];
[super mouseEntered:theEvent];
}
- (void)mouseExited:(NSEvent*)theEvent {
didEnter_ = NO;
tracking_ = NO;
[self doHighlight:NO];
[super mouseExited:theEvent];
}
- (void)mouseDragged:(NSEvent*)theEvent {
tracking_ = !didEnter_;
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
BOOL highlight = NSPointInRect(point, [self insetBounds]);
[self doHighlight:highlight];
// If tracking in non-sticky mode, poll the mouse cursor to see if it is still
// over the button and thus needs to be highlighted. The delay is the
// smallest that still produces the effect while minimizing jank. Smaller
// values make the selector fire too close to immediately/now for the mouse to
// have moved off the receiver, and larger values produce lag.
if (tracking_) {
[self performSelector:@selector(checkMouseInRect)
withObject:nil
afterDelay:0.05
inModes:[NSArray arrayWithObject:NSEventTrackingRunLoopMode]];
}
[super mouseDragged:theEvent];
}
- (void)mouseUp:(NSEvent*)theEvent {
[self doHighlight:NO];
if (!tracking_) {
return [super mouseUp:theEvent];
}
[self performClick:self];
tracking_ = NO;
}
- (void)doHighlight:(BOOL)highlight {
[[self cell] setHighlighted:highlight];
[self setNeedsDisplay];
}
// Checks if the user's current mouse location is over this button. If it is,
// the user is merely hovering here. If it is not, then disable the highlight.
// If the menu is opened in non-sticky mode, the button does not receive enter/
// exit mouse events and thus polling is necessary.
- (void)checkMouseInRect {
NSPoint point = [NSEvent mouseLocation];
point = ui::ConvertPointFromScreenToWindow([self window], point);
point = [self convertPoint:point fromView:nil];
if (!NSPointInRect(point, [self insetBounds])) {
[self doHighlight:NO];
}
}
// Returns the bounds of the receiver slightly inset to avoid highlighting both
// buttons in a pair that overlap.
- (NSRect)insetBounds {
return NSInsetRect([self bounds], 2, 1);
}
@end
// Copyright (c) 2010 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_APP_MENU_MENU_TRACKED_ROOT_VIEW_H_
#define CHROME_BROWSER_UI_COCOA_APP_MENU_MENU_TRACKED_ROOT_VIEW_H_
#import <Cocoa/Cocoa.h>
// An instance of MenuTrackedRootView should be the root of the view hierarchy
// of the custom view of NSMenuItems. If the user opens the menu in a non-
// sticky fashion (i.e. clicks, holds, and drags) and then releases the mouse
// over the menu item, it will cancel tracking on the |[menuItem_ menu]|.
@interface MenuTrackedRootView : NSView {
@private
// The menu item whose custom view's root view is an instance of this class.
NSMenuItem* menuItem_; // weak
}
@property(assign, nonatomic) NSMenuItem* menuItem;
@end
#endif // CHROME_BROWSER_UI_COCOA_APP_MENU_MENU_TRACKED_ROOT_VIEW_H_
// Copyright (c) 2010 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/app_menu/menu_tracked_root_view.h"
@implementation MenuTrackedRootView
@synthesize menuItem = menuItem_;
- (void)mouseUp:(NSEvent*)theEvent {
[[menuItem_ menu] cancelTracking];
}
@end
// Copyright (c) 2011 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 <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/app_menu/menu_tracked_root_view.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
#include "third_party/ocmock/gtest_support.h"
class MenuTrackedRootViewTest : public CocoaTest {
public:
void SetUp() override {
CocoaTest::SetUp();
view_.reset([[MenuTrackedRootView alloc] init]);
}
base::scoped_nsobject<MenuTrackedRootView> view_;
};
TEST_F(MenuTrackedRootViewTest, MouseUp) {
id menu = [OCMockObject mockForClass:[NSMenu class]];
[[menu expect] cancelTracking];
id menuItem = [OCMockObject mockForClass:[NSMenuItem class]];
[[[menuItem stub] andReturn:menu] menu];
[view_ setMenuItem:menuItem];
NSEvent* event = [NSEvent mouseEventWithType:NSLeftMouseUp
location:NSMakePoint(42, 42)
modifierFlags:0
timestamp:0
windowNumber:[test_window() windowNumber]
context:nil
eventNumber:1
clickCount:1
pressure:1.0];
[view_ mouseUp:event];
EXPECT_OCMOCK_VERIFY(menu);
EXPECT_OCMOCK_VERIFY(menuItem);
}
// Copyright (c) 2012 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_APP_MENU_RECENT_TABS_MENU_MODEL_DELEGATE_H_
#define CHROME_BROWSER_UI_COCOA_APP_MENU_RECENT_TABS_MENU_MODEL_DELEGATE_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "ui/base/models/menu_model_delegate.h"
namespace ui {
class MenuModel;
}
// Updates the recent tabs menu when the model changes.
class RecentTabsMenuModelDelegate : public ui::MenuModelDelegate {
public:
// |model| must live longer than this object.
RecentTabsMenuModelDelegate(ui::MenuModel* model, NSMenu* menu);
~RecentTabsMenuModelDelegate() override;
// ui::MenuModelDelegate:
void OnIconChanged(int index) override;
private:
ui::MenuModel* model_; // weak
base::scoped_nsobject<NSMenu> menu_;
DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate);
};
#endif // CHROME_BROWSER_UI_COCOA_APP_MENU_RECENT_TABS_MENU_MODEL_DELEGATE_H_
// Copyright (c) 2012 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/app_menu/recent_tabs_menu_model_delegate.h"
#include "ui/base/models/menu_model.h"
#include "ui/gfx/image/image.h"
RecentTabsMenuModelDelegate::RecentTabsMenuModelDelegate(
ui::MenuModel* model,
NSMenu* menu)
: model_(model),
menu_([menu retain]) {
model_->SetMenuModelDelegate(this);
}
RecentTabsMenuModelDelegate::~RecentTabsMenuModelDelegate() {
model_->SetMenuModelDelegate(NULL);
}
void RecentTabsMenuModelDelegate::OnIconChanged(int index) {
gfx::Image icon;
if (!model_->GetIconAt(index, &icon))
return;
NSMenuItem* item = [menu_ itemAtIndex:index];
[item setImage:icon.ToNSImage()];
}
......@@ -16,7 +16,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
......@@ -137,14 +136,6 @@ void ToolbarActionViewDelegateBridge::ShowContextMenu() {
// Otherwise, we have to slide the button out.
contextMenuRunning_ = true;
AppMenuController* appMenuController =
[[[BrowserWindowController browserWindowControllerForWindow:
[controller_ browser]->window()->GetNativeWindow()]
toolbarController] appMenuController];
// If the app menu is open, we have to first close it. Part of this happens
// asynchronously, so we have to use a posted task to open the next menu.
if ([appMenuController isMenuOpen])
[appMenuController cancel];
[controller_ toolbarActionsBar]->PopOutAction(
viewController_,
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/extensions/extension_message_bubble_controller.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
......@@ -240,13 +239,7 @@ void ToolbarActionsBarBridge::ShowToolbarActionBubble(
}
bool ToolbarActionsBarBridge::CloseOverflowMenuIfOpen() {
AppMenuController* appMenuController =
[[controller_ toolbarController] appMenuController];
if (![appMenuController isMenuOpen])
return false;
[appMenuController cancel];
return true;
return false;
}
} // namespace
......
......@@ -29,7 +29,6 @@ class Profile;
@class ReloadButtonCocoa;
@class ToolbarButtonCocoa;
@class ToolbarViewCocoa;
@class AppMenuController;
namespace content {
class WebContents;
......@@ -72,9 +71,6 @@ class NotificationBridge;
base::scoped_nsobject<BackForwardMenuController> forwardMenuController_;
base::scoped_nsobject<BrowserActionsController> browserActionsController_;
// Lazily-instantiated menu controller.
base::scoped_nsobject<AppMenuController> appMenuController_;
// Used for monitoring the optional toolbar button prefs.
std::unique_ptr<ToolbarControllerInternal::NotificationBridge>
notificationBridge_;
......@@ -189,9 +185,6 @@ class NotificationBridge;
// Returns the app menu button.
- (NSButton*)appMenuButton;
// Returns the app menu controller.
- (AppMenuController*)appMenuController;
// Returns true of the location bar is focused.
- (BOOL)isLocationBarFocused;
......@@ -202,7 +195,6 @@ class NotificationBridge;
// Returns an array of views in the order of the outlets above.
- (NSArray*)toolbarViews;
- (void)showOptionalHomeButton;
- (void)installAppMenu;
// Return a hover button for the current event.
- (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent;
// Adjusts browser actions container view in response to toolbar frame changes.
......
......@@ -27,7 +27,6 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h"
#import "chrome/browser/ui/cocoa/background_gradient_view.h"
#include "chrome/browser/ui/cocoa/drag_util.h"
#import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
......@@ -396,7 +395,6 @@ class NotificationBridge : public AppMenuIconController::Delegate {
&ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged,
base::Unretained(notificationBridge_.get())));
[self showOptionalHomeButton];
[self installAppMenu];
[self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO];
......@@ -456,7 +454,6 @@ class NotificationBridge : public AppMenuIconController::Delegate {
[backMenuController_ browserWillBeDestroyed];
[forwardMenuController_ browserWillBeDestroyed];
[browserActionsController_ browserWillBeDestroyed];
[appMenuController_ browserWillBeDestroyed];
[self cleanUp];
}
......@@ -644,8 +641,7 @@ class NotificationBridge : public AppMenuIconController::Delegate {
}
- (void)zoomChangedForActiveTab:(BOOL)canShowBubble {
locationBarView_->ZoomChangedForActiveTab(
canShowBubble && ![appMenuController_ isMenuOpen]);
locationBarView_->ZoomChangedForActiveTab(canShowBubble);
}
- (void)setIsLoading:(BOOL)isLoading force:(BOOL)force {
......@@ -724,18 +720,6 @@ class NotificationBridge : public AppMenuIconController::Delegate {
[homeButton_ setHidden:hide];
}
// Install the app menu buttons. Calling this repeatedly is inexpensive so it
// can be done every time the buttons are shown.
- (void)installAppMenu {
if (appMenuController_.get())
return;
appMenuController_.reset(
[[AppMenuController alloc] initWithBrowser:browser_]);
[appMenuController_ setUseWithPopUpButtonCell:YES];
[appMenuButton_ setAttachedMenu:[appMenuController_ menu]];
}
- (void)updateAppMenuButtonSeverity:(AppMenuIconController::Severity)severity
iconType:(AppMenuIconController::IconType)iconType
animate:(BOOL)animate {
......@@ -1014,10 +998,6 @@ class NotificationBridge : public AppMenuIconController::Delegate {
return appMenuButton_;
}
- (AppMenuController*)appMenuController {
return appMenuController_.get();
}
- (BOOL)isLocationBarFocused {
OmniboxEditModel* model = locationBarView_->GetOmniboxView()->model();
return model->has_focus();
......
......@@ -7,8 +7,6 @@
#include <memory>
#include "build/build_config.h"
class Browser;
namespace test {
......@@ -17,10 +15,6 @@ class AppMenuTestApi {
public:
static std::unique_ptr<AppMenuTestApi> Create(Browser* browser);
#if defined(OS_MACOSX)
static std::unique_ptr<AppMenuTestApi> CreateCocoa(Browser* browser);
#endif
AppMenuTestApi() = default;
virtual ~AppMenuTestApi() = default;
......
// Copyright 2018 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.
#include "chrome/browser/ui/views/media_router/app_menu_test_api.h"
#import <Cocoa/Cocoa.h>
#include "base/macros.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/test/run_loop_testing.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "ui/base/ui_features.h"
namespace {
class AppMenuTestApiCocoa : public test::AppMenuTestApi {
public:
explicit AppMenuTestApiCocoa(Browser* browser);
~AppMenuTestApiCocoa() override;
// AppMenuTestApi:
bool IsMenuShowing() override;
void ShowMenu() override;
void ExecuteCommand(int command) override;
private:
AppMenuController* GetAppMenuController();
NSButton* GetAppMenuButton();
ToolbarController* GetToolbarController();
bool menu_showing_ = false;
Browser* browser_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AppMenuTestApiCocoa);
};
AppMenuTestApiCocoa::AppMenuTestApiCocoa(Browser* browser)
: browser_(browser) {}
AppMenuTestApiCocoa::~AppMenuTestApiCocoa() {}
bool AppMenuTestApiCocoa::IsMenuShowing() {
return menu_showing_;
}
// Note: this class fakes the state of the app menu. In principle, the body
// should be something like this:
// return [GetAppMenuButton() performClick:nil];
// but doing that starts a nested run loop for the menu, which hangs the rest of
// the test. Instead, keep track of whether the menu is supposed to be showing
// or not. This class can't *actually* show the real menu because of
// https://crbug.com/823495.
// TODO(ellyjones): Use the real menu here.
void AppMenuTestApiCocoa::ShowMenu() {
menu_showing_ = true;
}
void AppMenuTestApiCocoa::ExecuteCommand(int command) {
menu_showing_ = false;
base::scoped_nsobject<NSButton> button([[NSButton alloc] init]);
[button setTag:command];
[GetAppMenuController() dispatchAppMenuCommand:button.get()];
chrome::testing::NSRunLoopRunAllPending();
}
AppMenuController* AppMenuTestApiCocoa::GetAppMenuController() {
return [GetToolbarController() appMenuController];
}
NSButton* AppMenuTestApiCocoa::GetAppMenuButton() {
return [GetToolbarController() appMenuButton];
}
ToolbarController* AppMenuTestApiCocoa::GetToolbarController() {
NSWindow* window = browser_->window()->GetNativeWindow();
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:window];
return [bwc toolbarController];
}
} // namespace
namespace test {
std::unique_ptr<AppMenuTestApi> AppMenuTestApi::CreateCocoa(Browser* browser) {
return std::make_unique<AppMenuTestApiCocoa>(browser);
}
#if !BUILDFLAG(MAC_VIEWS_BROWSER)
std::unique_ptr<AppMenuTestApi> AppMenuTestApi::Create(Browser* browser) {
return std::make_unique<AppMenuTestApiCocoa>(browser);
}
#endif // !MAC_VIEWS_BROWSER
}
......@@ -11,7 +11,6 @@
#include "chrome/browser/ui/views/toolbar/app_menu.h"
#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views_mode_controller.h"
namespace {
......@@ -66,10 +65,6 @@ AppMenu* AppMenuTestApiViews::GetAppMenu() {
namespace test {
std::unique_ptr<AppMenuTestApi> AppMenuTestApi::Create(Browser* browser) {
#if defined(OS_MACOSX)
if (views_mode_controller::IsViewsBrowserCocoa())
return AppMenuTestApi::CreateCocoa(browser);
#endif
return std::make_unique<AppMenuTestApiViews>(browser);
}
......
......@@ -278,6 +278,7 @@ static_library("test_support") {
public_deps += [ "//ui/views:test_support" ]
sources += [
"../browser/ui/views/media_router/app_menu_test_api.h",
"../browser/ui/views/media_router/app_menu_test_api_views.cc",
"views/accessibility_checker.cc",
"views/accessibility_checker.h",
"views/chrome_test_views_delegate.cc",
......@@ -285,14 +286,6 @@ static_library("test_support") {
"views/chrome_views_test_base.cc",
"views/chrome_views_test_base.h",
]
if (is_mac) {
sources +=
[ "../browser/ui/views/media_router/app_menu_test_api_cocoa.mm" ]
}
if (!is_mac || mac_views_browser) {
sources +=
[ "../browser/ui/views/media_router/app_menu_test_api_views.cc" ]
}
}
if (enable_extensions) {
......@@ -4126,9 +4119,6 @@ test("unit_tests") {
cocoa_test_sources = [
"../browser/ui/cocoa/animatable_image_unittest.mm",
"../browser/ui/cocoa/animatable_view_unittest.mm",
"../browser/ui/cocoa/app_menu/app_menu_button_cell_unittest.mm",
"../browser/ui/cocoa/app_menu/app_menu_controller_unittest.mm",
"../browser/ui/cocoa/app_menu/menu_tracked_root_view_unittest.mm",
"../browser/ui/cocoa/autofill/autofill_bubble_controller_unittest.mm",
"../browser/ui/cocoa/autofill/autofill_tooltip_controller_unittest.mm",
"../browser/ui/cocoa/background_gradient_view_unittest.mm",
......@@ -5119,8 +5109,6 @@ if (!is_android) {
# The browser window can be views or Cocoa on Mac, but this is chosen at
# runtime. This block captures tests that only run with a Cocoa browser.
sources += [
"../browser/ui/cocoa/extensions/browser_action_button_interactive_uitest.mm",
# Note permission_bubble_cocoa_interactive_uitest tests both Cocoa and
# toolkit-views secondary UI. It should not be deleted with the Cocoa
# bubble (but it can be deleted with the Cocoa browser window).
......
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