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;
// Sent when a user-initiated drag to resize the container has finished.
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
// provides mechanisms for resizing.
@interface BrowserActionsContainerView : NSView {
......
......@@ -15,6 +15,10 @@ NSString* const kBrowserActionGrippyDraggingNotification =
@"BrowserActionGrippyDraggingNotification";
NSString* const kBrowserActionGrippyDragFinishedNotification =
@"BrowserActionGrippyDragFinishedNotification";
NSString* const kBrowserActionGrippyWillDragNotification =
@"BrowserActionGrippyWillDragNotification";
NSString* const kTranslationWithDelta =
@"TranslationWithDelta";
namespace {
const CGFloat kAnimationDuration = 0.2;
......@@ -118,6 +122,16 @@ const CGFloat kMinimumContainerWidth = 10.0;
(NSWidth(containerFrame) > kMinimumContainerWidth);
canDragLeft_ = (withDelta <= initialDragPoint_.x) &&
(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_))
return;
......
......@@ -119,6 +119,10 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
// toolbar know that the drag has finished.
- (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
// button is within the container.
- (void)actionButtonDragging:(NSNotification*)notification;
......@@ -305,6 +309,11 @@ class ExtensionServiceObserverBridge
selector:@selector(containerDragFinished:)
name:kBrowserActionGrippyDragFinishedNotification
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
// stays in sync.
[[NSNotificationCenter defaultCenter]
......@@ -670,6 +679,13 @@ class ExtensionServiceObserverBridge
object:self];
}
- (void)containerWillTranslateOnX:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter]
postNotificationName:kBrowserActionGrippyWillDragNotification
object:self
userInfo:notification.userInfo];
}
- (void)actionButtonDragging:(NSNotification*)notification {
if (![self chevronIsHidden])
[self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES];
......
......@@ -90,6 +90,7 @@ const CGFloat kWrenchMenuLeftPadding = 3.0;
- (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate;
- (void)maintainMinimumLocationBarWidth;
- (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification;
- (void)browserActionsContainerWillDrag:(NSNotification*)notification;
- (void)browserActionsContainerDragged:(NSNotification*)notification;
- (void)browserActionsContainerDragFinished:(NSNotification*)notification;
- (void)browserActionsVisibilityChanged:(NSNotification*)notification;
......@@ -589,6 +590,11 @@ class NotificationBridge : public WrenchMenuBadgeController::Delegate {
browserActionsController_.reset([[BrowserActionsController alloc]
initWithBrowser:browser_
containerView:browserActionsContainerView_]);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(browserActionsContainerWillDrag:)
name:kBrowserActionGrippyWillDragNotification
object:browserActionsController_];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(browserActionsContainerDragged:)
......@@ -639,6 +645,18 @@ class NotificationBridge : public WrenchMenuBadgeController::Delegate {
[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 {
[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