Commit d7d85e9d authored by andresantoso's avatar andresantoso Committed by Commit bot

Mac: Remove download shelf from AX hierarchy when not visible.

When the download shelf is closed, it's still in the view hierarchy with height
of 0. To make it not appear in the AX hierarchy, we hide the view after the
close animation is finished.

BUG=417698

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

Cr-Commit-Position: refs/heads/master@{#297300}
parent 4f8f50d2
......@@ -252,10 +252,12 @@ const NSSize kHoverCloseButtonDefaultSize = { 18, 18 };
// do no animation over janky animation. Find a way to make animating in
// smoother.
AnimatableView* view = [self animatableView];
if (show)
if (show) {
[view setHeight:maxShelfHeight_];
else
[view setHidden:NO];
} else {
[view animateToNewHeight:0 duration:kDownloadShelfCloseDuration];
}
barIsVisible_ = show;
[self updateCloseButton];
......@@ -270,8 +272,10 @@ const NSSize kHoverCloseButtonDefaultSize = { 18, 18 };
}
- (void)animationDidEnd:(NSAnimation*)animation {
if (![self isVisible])
if (![self isVisible]) {
[self closed];
[[self view] setHidden:YES]; // So that it doesn't appear in AX hierarchy.
}
}
- (float)height {
......
......@@ -4,6 +4,7 @@
#import <Cocoa/Cocoa.h>
#import "base/mac/scoped_block.h"
#import "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/download/download_shelf.h"
......@@ -60,6 +61,10 @@ using ::testing::AnyNumber;
}
@end
@interface DownloadShelfController (Testing)
- (void)animationDidEnd:(NSAnimation*)animation;
@end
// Subclass of the DownloadShelfController to override scheduleAutoClose and
// cancelAutoClose. During regular operation, a scheduled autoClose waits for 5
// seconds before closing the shelf (unless it is cancelled during this
......@@ -69,7 +74,11 @@ using ::testing::AnyNumber;
@public
int scheduleAutoCloseCount_;
int cancelAutoCloseCount_;
base::mac::ScopedBlock<dispatch_block_t> closeAnimationHandler_;
}
// Handler will be called at the end of a close animation.
- (void)setCloseAnimationHandler:(dispatch_block_t)handler;
@end
@implementation CountingDownloadShelfController
......@@ -81,6 +90,17 @@ using ::testing::AnyNumber;
-(void)cancelAutoClose {
++cancelAutoCloseCount_;
}
- (void)setCloseAnimationHandler:(dispatch_block_t)handler {
closeAnimationHandler_.reset(handler);
}
- (void)animationDidEnd:(NSAnimation*)animation {
[super animationDidEnd:animation];
if (closeAnimationHandler_)
closeAnimationHandler_.get()();
}
@end
namespace {
......@@ -360,4 +380,21 @@ TEST_F(DownloadShelfControllerTest, CancelAutoCloseOnExit) {
shelf_.reset();
}
// The view should not be hidden when the shelf is shown.
// The view should be hidden after the closing animation.
TEST_F(DownloadShelfControllerTest, ViewVisibility) {
[shelf_ showDownloadShelf:YES isUserAction:NO];
EXPECT_FALSE([[shelf_ view] isHidden]);
[shelf_ setCloseAnimationHandler:^{
base::MessageLoop::current()->QuitNow();
}];
[shelf_ showDownloadShelf:NO isUserAction:NO];
base::MessageLoop::current()->Run();
EXPECT_TRUE([[shelf_ view] isHidden]);
[shelf_ showDownloadShelf:YES isUserAction:NO];
EXPECT_FALSE([[shelf_ view] isHidden]);
}
} // namespace
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