Commit 2823e2f1 authored by rsesek@chromium.org's avatar rsesek@chromium.org

[Mac] Delete more bookmark bar folder code. This removes things that were missed last time.

One of the issues is that a nested event loop in |-mouseDown:| was causing the
thread to block after the menu closes, because the opening of the menu pumps the
mouseUp event.

BUG=91850
TEST=Open a bookmark from the folder and the spinner spins.

Review URL: http://codereview.chromium.org/7528007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95901 0039d316-1c4b-4281-b951-d872f2087c98
parent f5554e64
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
#include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
#import "content/common/chrome_application_mac.h"
#include "webkit/glue/window_open_disposition.h" #include "webkit/glue/window_open_disposition.h"
@class BookmarkBarController; @class BookmarkBarController;
...@@ -79,7 +78,6 @@ willAnimateFromState:(bookmarks::VisualState)oldState ...@@ -79,7 +78,6 @@ willAnimateFromState:(bookmarks::VisualState)oldState
BookmarkBarToolbarViewController, BookmarkBarToolbarViewController,
BookmarkButtonDelegate, BookmarkButtonDelegate,
BookmarkButtonControllerProtocol, BookmarkButtonControllerProtocol,
CrApplicationEventHookProtocol,
NSUserInterfaceValidations> { NSUserInterfaceValidations> {
@private @private
// The visual state of the bookmark bar. If an animation is running, this is // The visual state of the bookmark bar. If an animation is running, this is
......
...@@ -210,7 +210,6 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -210,7 +210,6 @@ void RecordAppLaunch(Profile* profile, GURL url) {
- (void)addButtonsToView; - (void)addButtonsToView;
- (void)centerNoItemsLabel; - (void)centerNoItemsLabel;
- (void)setNodeForBarMenu; - (void)setNodeForBarMenu;
- (void)watchForExitEvent:(BOOL)watch;
- (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate;
- (BOOL)animationEnabled; - (BOOL)animationEnabled;
...@@ -326,7 +325,6 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -326,7 +325,6 @@ void RecordAppLaunch(Profile* profile, GURL url) {
bridge_.reset(NULL); bridge_.reset(NULL);
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[self watchForExitEvent:NO];
[super dealloc]; [super dealloc];
} }
...@@ -519,7 +517,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -519,7 +517,7 @@ void RecordAppLaunch(Profile* profile, GURL url) {
#pragma mark Actions #pragma mark Actions
- (IBAction)openBookmark:(id)sender { - (IBAction)openBookmark:(id)sender {
BOOL isMenuItem = [[sender cell] isFolderButtonCell]; BOOL isMenuItem = [sender isFolder];
BOOL animate = isMenuItem && [self animationEnabled]; BOOL animate = isMenuItem && [self animationEnabled];
DCHECK([sender respondsToSelector:@selector(bookmarkNode)]); DCHECK([sender respondsToSelector:@selector(bookmarkNode)]);
const BookmarkNode* node = [sender bookmarkNode]; const BookmarkNode* node = [sender bookmarkNode];
...@@ -779,59 +777,6 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -779,59 +777,6 @@ void RecordAppLaunch(Profile* profile, GURL url) {
} }
} }
// Main menubar observation code, so we can know to close our fake menus if the
// user clicks on the actual menubar, as multiple unconnected menus sharing
// the screen looks weird.
// Needed because the hookForEvent method doesn't see the click on the menubar.
// Gets called when the menubar is clicked.
- (void)begunTracking:(NSNotification *)notification {
[self closeFolderAndStopTrackingMenus];
}
// Install the callback.
- (void)startObservingMenubar {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(begunTracking:)
name:NSMenuDidBeginTrackingNotification
object:[NSApp mainMenu]];
}
// Remove the callback.
- (void)stopObservingMenubar {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self
name:NSMenuDidBeginTrackingNotification
object:[NSApp mainMenu]];
}
// End of menubar observation code.
// Begin (or end) watching for a click outside this window. Unlike
// normal NSWindows, bookmark folder "fake menu" windows do not become
// key or main. Thus, traditional notification (e.g. WillResignKey)
// won't work. Our strategy is to watch (at the app level) for a
// "click outside" these windows to detect when they logically lose
// focus.
- (void)watchForExitEvent:(BOOL)watch {
CrApplication* app = static_cast<CrApplication*>([NSApplication
sharedApplication]);
DCHECK([app isKindOfClass:[CrApplication class]]);
if (watch) {
if (!watchingForExitEvent_) {
[app addEventHook:self];
[self startObservingMenubar];
}
} else {
if (watchingForExitEvent_) {
[app removeEventHook:self];
[self stopObservingMenubar];
}
}
watchingForExitEvent_ = watch;
}
// Keep the "no items" label centered in response to a frame size change. // Keep the "no items" label centered in response to a frame size change.
- (void)centerNoItemsLabel { - (void)centerNoItemsLabel {
// Note that this computation is done in the parent's coordinate system, // Note that this computation is done in the parent's coordinate system,
...@@ -1703,58 +1648,6 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1703,58 +1648,6 @@ void RecordAppLaunch(Profile* profile, GURL url) {
[[otherBookmarksButton_ cell] setTextColor:color]; [[otherBookmarksButton_ cell] setTextColor:color];
} }
// Return YES if the event indicates an exit from the bookmark bar
// folder menus. E.g. "click outside" of the area we are watching.
// At this time we are watching the area that includes all popup
// bookmark folder windows.
- (BOOL)isEventAnExitEvent:(NSEvent*)event {
NSWindow* eventWindow = [event window];
NSWindow* myWindow = [[self view] window];
switch ([event type]) {
case NSLeftMouseDown:
case NSRightMouseDown:
// If the click is in my window but NOT in the bookmark bar, consider
// it a click 'outside'. Clicks directly on an active button (i.e. one
// that is a folder and for which its folder menu is showing) are 'in'.
// All other clicks on the bookmarks bar are counted as 'outside'
// because they should close any open bookmark folder menu.
if (eventWindow == myWindow) {
NSView* hitView =
[[eventWindow contentView] hitTest:[event locationInWindow]];
if (hitView == [folderController_ parentButton])
return NO;
if (![hitView isDescendantOf:[self view]] || hitView == buttonView_)
return YES;
}
break;
case NSKeyDown: {
// Event hooks often see the same keydown event twice due to the way key
// events get dispatched and redispatched, so ignore if this keydown
// event has the EXACT same timestamp as the previous keydown.
static NSTimeInterval lastKeyDownEventTime;
NSTimeInterval thisTime = [event timestamp];
if (lastKeyDownEventTime != thisTime) {
lastKeyDownEventTime = thisTime;
if ([event modifierFlags] & NSCommandKeyMask)
return YES;
}
return NO;
}
case NSKeyUp:
return NO;
case NSLeftMouseDragged:
// We can get here with the following sequence:
// - open a bookmark folder
// - right-click (and unclick) on it to open context menu
// - move mouse to window titlebar then click-drag it by the titlebar
// http://crbug.com/49333
return NO;
default:
break;
}
return NO;
}
#pragma mark Drag & Drop #pragma mark Drag & Drop
// Find something like std::is_between<T>? I can't believe one doesn't exist. // Find something like std::is_between<T>? I can't believe one doesn't exist.
...@@ -2241,7 +2134,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { ...@@ -2241,7 +2134,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) {
// Close all bookmark folders. "Folder" here is the fake menu for // Close all bookmark folders. "Folder" here is the fake menu for
// bookmark folders, not a button context menu. // bookmark folders, not a button context menu.
- (void)closeAllBookmarkFolders { - (void)closeAllBookmarkFolders {
[self watchForExitEvent:NO];
[folderController_ closeMenu]; [folderController_ closeMenu];
folderController_ = nil; folderController_ = nil;
} }
...@@ -2428,10 +2320,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { ...@@ -2428,10 +2320,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) {
[folderController_ autorelease]; [folderController_ autorelease];
[folderController_ openMenu]; [folderController_ openMenu];
// Only BookmarkBarController has this; the
// BookmarkBarFolderController does not.
[self watchForExitEvent:YES];
// No longer need to hold the lock; the folderController_ now owns it. // No longer need to hold the lock; the folderController_ now owns it.
[browserController releaseBarVisibilityForOwner:self [browserController releaseBarVisibilityForOwner:self
withAnimation:NO withAnimation:NO
...@@ -2583,14 +2471,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { ...@@ -2583,14 +2471,6 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) {
return nil; return nil;
} }
#pragma mark BookmarkButtonControllerProtocol
// NOT an override of a standard Cocoa call made to NSViewControllers.
- (void)hookForEvent:(NSEvent*)theEvent {
if ([self isEventAnExitEvent:theEvent])
[self closeFolderAndStopTrackingMenus];
}
#pragma mark TestingAPI Only #pragma mark TestingAPI Only
- (NSMenu*)buttonContextMenu { - (NSMenu*)buttonContextMenu {
......
// 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.
#ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_FOLDER_BUTTON_CELL_H_
#define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_FOLDER_BUTTON_CELL_H_
#pragma once
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
class BookmarkNode;
// A button cell that handles drawing/highlighting of buttons in the
// bookmark bar. This cell forwards mouseEntered/mouseExited events
// to its control view so that pseudo-menu operations
// (e.g. hover-over to open) can be implemented.
@interface BookmarkBarFolderButtonCell : BookmarkButtonCell {
@private
scoped_nsobject<NSColor> frameColor_;
}
// Create a button cell which draws without a theme and with a frame
// color provided by the ThemeService defaults.
+ (id)buttonCellForNode:(const BookmarkNode*)node
contextMenu:(NSMenu*)contextMenu
cellText:(NSString*)cellText
cellImage:(NSImage*)cellImage;
@end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_FOLDER_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/bookmarks/bookmark_bar_folder_button_cell.h"
@implementation BookmarkBarFolderButtonCell
+ (id)buttonCellForNode:(const BookmarkNode*)node
contextMenu:(NSMenu*)contextMenu
cellText:(NSString*)cellText
cellImage:(NSImage*)cellImage {
id buttonCell =
[[[BookmarkBarFolderButtonCell alloc] initForNode:node
contextMenu:contextMenu
cellText:cellText
cellImage:cellImage]
autorelease];
return buttonCell;
}
- (BOOL)isFolderButtonCell {
return YES;
}
- (void)setMouseInside:(BOOL)flag animate:(BOOL)animated {
}
@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/memory/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
namespace {
class BookmarkBarFolderButtonCellTest : public CocoaTest {
};
// Basic creation.
TEST_F(BookmarkBarFolderButtonCellTest, Create) {
scoped_nsobject<BookmarkBarFolderButtonCell> cell;
cell.reset([[BookmarkBarFolderButtonCell buttonCellForNode:nil
contextMenu:nil
cellText:nil
cellImage:nil] retain]);
EXPECT_TRUE(cell);
}
} // namespace
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
#include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" #include "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h"
#include "chrome/browser/ui/cocoa/browser_test_helper.h" #include "chrome/browser/ui/cocoa/browser_test_helper.h"
......
...@@ -256,75 +256,10 @@ BookmarkButton* gDraggedButton = nil; // Weak ...@@ -256,75 +256,10 @@ BookmarkButton* gDraggedButton = nil; // Weak
} }
- (void)performMouseDownAction:(NSEvent*)theEvent { - (void)performMouseDownAction:(NSEvent*)theEvent {
int eventMask = NSLeftMouseUpMask | NSMouseEnteredMask | NSMouseExitedMask |
NSLeftMouseDraggedMask;
BOOL keepGoing = YES;
[[self target] performSelector:[self action] withObject:self]; [[self target] performSelector:[self action] withObject:self];
self.actionHasFired = YES; self.actionHasFired = YES;
DraggableButton* insideBtn = nil;
while (keepGoing) {
theEvent = [[self window] nextEventMatchingMask:eventMask];
if (!theEvent)
continue;
NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
BOOL isInside = [self mouse:mouseLoc inRect:[self bounds]];
switch ([theEvent type]) {
case NSMouseEntered:
case NSMouseExited: {
NSView* trackedView = (NSView*)[[theEvent trackingArea] owner];
if (trackedView && [trackedView isKindOfClass:[self class]]) {
BookmarkButton* btn = static_cast<BookmarkButton*>(trackedView);
if (![btn acceptsTrackInFrom:self])
break;
if ([theEvent type] == NSMouseEntered) {
[[NSCursor arrowCursor] set];
[[btn cell] mouseEntered:theEvent];
insideBtn = btn;
} else {
[[btn cell] mouseExited:theEvent];
if (insideBtn == btn)
insideBtn = nil;
}
}
break;
}
case NSLeftMouseDragged: {
if (insideBtn)
[insideBtn mouseDragged:theEvent];
break;
}
case NSLeftMouseUp: {
self.durationMouseWasDown = [theEvent timestamp] - self.whenMouseDown;
if (!isInside && insideBtn && insideBtn != self) {
// Has tracked onto another BookmarkButton menu item, and released,
// so fire its action.
[[insideBtn target] performSelector:[insideBtn action]
withObject:insideBtn];
} else {
[self secondaryMouseUpAction:isInside];
[[self cell] mouseExited:theEvent];
[[insideBtn cell] mouseExited:theEvent];
}
keepGoing = NO;
break;
}
default:
/* Ignore any other kind of event. */
break;
}
}
} }
// mouseEntered: and mouseExited: are called from our
// BookmarkButtonCell. We redirect this information to our delegate. // BookmarkButtonCell. We redirect this information to our delegate.
// The controller can then perform menu-like actions (e.g. "hover over // The controller can then perform menu-like actions (e.g. "hover over
// to open menu"). // to open menu").
...@@ -352,8 +287,7 @@ BookmarkButton* gDraggedButton = nil; // Weak ...@@ -352,8 +287,7 @@ BookmarkButton* gDraggedButton = nil; // Weak
} }
- (BOOL)canBecomeKeyView { - (BOOL)canBecomeKeyView {
// If button is an item in a folder menu, don't become key. return NO;
return ![[self cell] isFolderButtonCell];
} }
// This only gets called after a click that wasn't a drag, and only on folders. // This only gets called after a click that wasn't a drag, and only on folders.
......
...@@ -55,8 +55,6 @@ class BookmarkNode; ...@@ -55,8 +55,6 @@ class BookmarkNode;
// Set the color of text in this cell. // Set the color of text in this cell.
- (void)setTextColor:(NSColor*)color; - (void)setTextColor:(NSColor*)color;
- (BOOL)isFolderButtonCell;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BUTTON_CELL_H_ #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BUTTON_CELL_H_
...@@ -71,10 +71,6 @@ ...@@ -71,10 +71,6 @@
[self configureBookmarkButtonCell]; [self configureBookmarkButtonCell];
} }
- (BOOL)isFolderButtonCell {
return NO;
}
// Perform all normal init routines specific to the BookmarkButtonCell. // Perform all normal init routines specific to the BookmarkButtonCell.
- (void)configureBookmarkButtonCell { - (void)configureBookmarkButtonCell {
[self setButtonType:NSMomentaryPushInButton]; [self setButtonType:NSMomentaryPushInButton];
......
...@@ -2316,8 +2316,6 @@ ...@@ -2316,8 +2316,6 @@
'browser/ui/cocoa/bookmarks/bookmark_bar_constants.h', 'browser/ui/cocoa/bookmarks/bookmark_bar_constants.h',
'browser/ui/cocoa/bookmarks/bookmark_bar_controller.h', 'browser/ui/cocoa/bookmarks/bookmark_bar_controller.h',
'browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm', 'browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h',
'browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h', 'browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h',
'browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm', 'browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_state.h', 'browser/ui/cocoa/bookmarks/bookmark_bar_state.h',
......
...@@ -1722,7 +1722,6 @@ ...@@ -1722,7 +1722,6 @@
'browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller_unittest.mm', 'browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller_unittest.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_bridge_unittest.mm', 'browser/ui/cocoa/bookmarks/bookmark_bar_bridge_unittest.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm', 'browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell_unittest.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm', 'browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller_unittest.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm', 'browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm',
'browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h', 'browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h',
......
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