Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm

Issue 6927001: Merge 84005 - Mac. Ensure no more than one visibly selected item in each bookmark folder menu. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm
===================================================================
--- chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm (revision 84009)
+++ chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm (working copy)
@@ -210,12 +210,6 @@
// otherwise only border the button when the mouse is inside the button.
- (void)forceButtonBorderToStayOnAlways:(BOOL)forceOn;
-// On 10.6 event dispatch for an NSButtonCell's
-// showsBorderOnlyWhileMouseInside seems broken if scrolling the
-// view that contains the button. It appears that a mouseExited:
-// gets lost, so the button stays highlit forever. We accomodate
-// here.
-- (void)toggleButtonBorderingWhileMouseInside;
@end
@implementation BookmarkButton (BookmarkBarFolderMenuHighlighting)
@@ -225,12 +219,6 @@
[self setNeedsDisplay];
}
-- (void)toggleButtonBorderingWhileMouseInside {
- BOOL toggle = [self showsBorderOnlyWhileMouseInside];
- [self setShowsBorderOnlyWhileMouseInside:!toggle];
- [self setShowsBorderOnlyWhileMouseInside:toggle];
-}
-
@end
@implementation BookmarkBarFolderController
@@ -865,19 +853,74 @@
}
}
+- (int)indexOfButton:(BookmarkButton*)button {
+ if (button == nil)
+ return -1;
+ int index = [buttons_ indexOfObject:button];
+ return (index == NSNotFound) ? -1 : index;
+}
+
+- (BookmarkButton*)buttonAtIndex:(int)which {
+ if (which < 0 || which >= [self buttonCount])
+ return nil;
+ return [buttons_ objectAtIndex:which];
+}
+
+// Private, called by performOneScroll only.
+// If the button at index contains the mouse it will select it and return YES.
+// Otherwise returns NO.
+- (BOOL)selectButtonIfHoveredAtIndex:(int)index {
+ BookmarkButton *btn = [self buttonAtIndex:index];
+ if ([[btn cell] isMouseReallyInside]) {
+ buttonThatMouseIsIn_ = btn;
+ [self setSelectedButtonByIndex:index];
+ return YES;
+ }
+ return NO;
+}
+
// Perform a single scroll of the specified amount.
- (void)performOneScroll:(CGFloat)delta {
if (delta == 0.0)
return;
CGFloat finalDelta = [self determineFinalScrollDelta:delta];
- if (finalDelta > 0.0 || finalDelta < 0.0) {
- if (buttonThatMouseIsIn_)
- [buttonThatMouseIsIn_ toggleButtonBorderingWhileMouseInside];
- NSRect windowFrame = [[self window] frame];
- NSSize newSize = NSMakeSize(NSWidth(windowFrame), 0.0);
- [self adjustWindowLeft:windowFrame.origin.x
- size:newSize
- scrollingBy:finalDelta];
+ if (finalDelta == 0.0)
+ return;
+ int index = [self indexOfButton:buttonThatMouseIsIn_];
+ // Check for a current mouse-initiated selection.
+ BOOL maintainHoverSelection =
+ (buttonThatMouseIsIn_ &&
+ [[buttonThatMouseIsIn_ cell] isMouseReallyInside] &&
+ selectedIndex_ != -1 &&
+ index == selectedIndex_);
+ NSRect windowFrame = [[self window] frame];
+ NSSize newSize = NSMakeSize(NSWidth(windowFrame), 0.0);
+ [self adjustWindowLeft:windowFrame.origin.x
+ size:newSize
+ scrollingBy:finalDelta];
+ // We have now scrolled.
+ if (!maintainHoverSelection)
+ return;
+ // Is mouse still in the same hovered button?
+ if ([[buttonThatMouseIsIn_ cell] isMouseReallyInside])
+ return;
+ // The finalDelta scroll direction will tell us us whether to search up or
+ // down the buttons array for the newly hovered button.
+ if (finalDelta < 0.0) { // Scrolled up, so search backwards for new hover.
+ index--;
+ while (index >= 0) {
+ if ([self selectButtonIfHoveredAtIndex:index])
+ return;
+ index--;
+ }
+ } else { // Scrolled down, so search forward for new hovered button.
+ index++;
+ int btnMax = [self buttonCount];
+ while (index < btnMax) {
+ if ([self selectButtonIfHoveredAtIndex:index])
+ return;
+ index++;
+ }
}
}
@@ -1268,20 +1311,6 @@
[self autorelease];
}
-- (int)indexOfButton:(BookmarkButton*)button {
- int btnCount = [self buttonCount];
- for (int i = 0 ; i < btnCount ; ++i)
- if ([buttons_ objectAtIndex:i] == button)
- return i;
- return -1;
-}
-
-- (BookmarkButton*)buttonAtIndex:(int)which {
- if (which < 0 || which >= [self buttonCount])
- return nil;
- return [buttons_ objectAtIndex:which];
-}
-
#pragma mark BookmarkButtonDelegate Protocol
- (void)fillPasteboard:(NSPasteboard*)pboard
@@ -1318,6 +1347,7 @@
- (void)mouseExitedButton:(id)sender event:(NSEvent*)event {
if (buttonThatMouseIsIn_ == sender)
buttonThatMouseIsIn_ = nil;
+ [self setSelectedButtonByIndex:-1];
// Stop any timer about opening a new hover-open folder.
@@ -1509,10 +1539,8 @@
// greater than range values too.
- (void)setStateOfButtonByIndex:(int)index
state:(bool)state {
- if (index < 0 || index > ([self buttonCount] -1))
- return;
-
- [[buttons_ objectAtIndex:index] highlight:state];
+ if (index >= 0 && index < [self buttonCount])
+ [[buttons_ objectAtIndex:index] highlight:state];
}
// Selects the required button and deselects the previously selected one.
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.mm ('k') | chrome/browser/ui/cocoa/gradient_button_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698