Commit e9cc4e84 authored by malcolm.2.wang's avatar malcolm.2.wang Committed by Commit bot

To ensure that the location bar will not reach the minimum width.

Fix the width of location bar will be less than the minimum width, when
dragging the browserActionsContainer to the left.

Before the browserActionsContainer will translate on x-axis, sending a
notification to see whether it will be allowed. This will give the
toolbar controller a chance to check if the width of location bar will
reach the minimum by dragging the browserActionsContainer.

BUG=329842
TEST=manually tested.

Review URL: https://codereview.chromium.org/636283004

Cr-Commit-Position: refs/heads/master@{#302209}
parent 73eab036
...@@ -16,6 +16,12 @@ extern NSString* const kBrowserActionGrippyDraggingNotification; ...@@ -16,6 +16,12 @@ extern NSString* const kBrowserActionGrippyDraggingNotification;
// Sent when a user-initiated drag to resize the container has finished. // Sent when a user-initiated drag to resize the container has finished.
extern NSString* const kBrowserActionGrippyDragFinishedNotification; extern NSString* const kBrowserActionGrippyDragFinishedNotification;
// Sent before the dragging will resize the container.
extern NSString* const kBrowserActionGrippyWillDragNotification;
// Key which is used to notify the translation with delta.
extern NSString* const kTranslationWithDelta;
// The view that encompasses the Browser Action buttons in the toolbar and // The view that encompasses the Browser Action buttons in the toolbar and
// provides mechanisms for resizing. // provides mechanisms for resizing.
@interface BrowserActionsContainerView : NSView { @interface BrowserActionsContainerView : NSView {
......
...@@ -15,6 +15,10 @@ NSString* const kBrowserActionGrippyDraggingNotification = ...@@ -15,6 +15,10 @@ NSString* const kBrowserActionGrippyDraggingNotification =
@"BrowserActionGrippyDraggingNotification"; @"BrowserActionGrippyDraggingNotification";
NSString* const kBrowserActionGrippyDragFinishedNotification = NSString* const kBrowserActionGrippyDragFinishedNotification =
@"BrowserActionGrippyDragFinishedNotification"; @"BrowserActionGrippyDragFinishedNotification";
NSString* const kBrowserActionGrippyWillDragNotification =
@"BrowserActionGrippyWillDragNotification";
NSString* const kTranslationWithDelta =
@"TranslationWithDelta";
namespace { namespace {
const CGFloat kAnimationDuration = 0.2; const CGFloat kAnimationDuration = 0.2;
...@@ -118,6 +122,16 @@ const CGFloat kMinimumContainerWidth = 10.0; ...@@ -118,6 +122,16 @@ const CGFloat kMinimumContainerWidth = 10.0;
(NSWidth(containerFrame) > kMinimumContainerWidth); (NSWidth(containerFrame) > kMinimumContainerWidth);
canDragLeft_ = (withDelta <= initialDragPoint_.x) && canDragLeft_ = (withDelta <= initialDragPoint_.x) &&
(NSWidth(containerFrame) < maxWidth_); (NSWidth(containerFrame) < maxWidth_);
// Notify others to see whether this dragging is allowed.
if (canDragLeft_ || canDragRight_) {
NSDictionary* userInfo = @{ kTranslationWithDelta : @(dX) };
[[NSNotificationCenter defaultCenter]
postNotificationName:kBrowserActionGrippyWillDragNotification
object:self
userInfo:userInfo];
}
if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_))
return; return;
......
...@@ -119,6 +119,10 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0; ...@@ -119,6 +119,10 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
// toolbar know that the drag has finished. // toolbar know that the drag has finished.
- (void)containerDragFinished:(NSNotification*)notification; - (void)containerDragFinished:(NSNotification*)notification;
// Sends a notification for the toolbar to determine whether the container can
// translate with a delta on x-axis.
- (void)containerWillTranslateOnX:(NSNotification*)notification;
// Adjusts the position of the surrounding action buttons depending on where the // Adjusts the position of the surrounding action buttons depending on where the
// button is within the container. // button is within the container.
- (void)actionButtonDragging:(NSNotification*)notification; - (void)actionButtonDragging:(NSNotification*)notification;
...@@ -305,6 +309,11 @@ class ExtensionServiceObserverBridge ...@@ -305,6 +309,11 @@ class ExtensionServiceObserverBridge
selector:@selector(containerDragFinished:) selector:@selector(containerDragFinished:)
name:kBrowserActionGrippyDragFinishedNotification name:kBrowserActionGrippyDragFinishedNotification
object:containerView_]; object:containerView_];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(containerWillTranslateOnX:)
name:kBrowserActionGrippyWillDragNotification
object:containerView_];
// Listen for a finished drag from any button to make sure each open window // Listen for a finished drag from any button to make sure each open window
// stays in sync. // stays in sync.
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
...@@ -670,6 +679,13 @@ class ExtensionServiceObserverBridge ...@@ -670,6 +679,13 @@ class ExtensionServiceObserverBridge
object:self]; object:self];
} }
- (void)containerWillTranslateOnX:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter]
postNotificationName:kBrowserActionGrippyWillDragNotification
object:self
userInfo:notification.userInfo];
}
- (void)actionButtonDragging:(NSNotification*)notification { - (void)actionButtonDragging:(NSNotification*)notification {
if (![self chevronIsHidden]) if (![self chevronIsHidden])
[self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES]; [self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES];
......
...@@ -90,6 +90,7 @@ const CGFloat kWrenchMenuLeftPadding = 3.0; ...@@ -90,6 +90,7 @@ const CGFloat kWrenchMenuLeftPadding = 3.0;
- (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate;
- (void)maintainMinimumLocationBarWidth; - (void)maintainMinimumLocationBarWidth;
- (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification;
- (void)browserActionsContainerWillDrag:(NSNotification*)notification;
- (void)browserActionsContainerDragged:(NSNotification*)notification; - (void)browserActionsContainerDragged:(NSNotification*)notification;
- (void)browserActionsContainerDragFinished:(NSNotification*)notification; - (void)browserActionsContainerDragFinished:(NSNotification*)notification;
- (void)browserActionsVisibilityChanged:(NSNotification*)notification; - (void)browserActionsVisibilityChanged:(NSNotification*)notification;
...@@ -589,6 +590,11 @@ class NotificationBridge : public WrenchMenuBadgeController::Delegate { ...@@ -589,6 +590,11 @@ class NotificationBridge : public WrenchMenuBadgeController::Delegate {
browserActionsController_.reset([[BrowserActionsController alloc] browserActionsController_.reset([[BrowserActionsController alloc]
initWithBrowser:browser_ initWithBrowser:browser_
containerView:browserActionsContainerView_]); containerView:browserActionsContainerView_]);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(browserActionsContainerWillDrag:)
name:kBrowserActionGrippyWillDragNotification
object:browserActionsController_];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver:self addObserver:self
selector:@selector(browserActionsContainerDragged:) selector:@selector(browserActionsContainerDragged:)
...@@ -639,6 +645,18 @@ class NotificationBridge : public WrenchMenuBadgeController::Delegate { ...@@ -639,6 +645,18 @@ class NotificationBridge : public WrenchMenuBadgeController::Delegate {
[self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES];
} }
- (void)browserActionsContainerWillDrag:(NSNotification*)notification {
CGFloat deltaX = [[notification.userInfo objectForKey:kTranslationWithDelta]
floatValue];
CGFloat locationBarWidth = NSWidth([locationBar_ frame]);
BOOL locationBarWillBeAtMinSize =
(locationBarWidth + deltaX) <= kMinimumLocationBarWidth;
// Prevent the |browserActionsContainerView_| from dragging if the width of
// location bar will reach the minimum.
[browserActionsContainerView_ setCanDragLeft:!locationBarWillBeAtMinSize];
}
- (void)browserActionsVisibilityChanged:(NSNotification*)notification { - (void)browserActionsVisibilityChanged:(NSNotification*)notification {
[self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO];
} }
......
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