Skip to content
Snippets Groups Projects
Commit 34f8fee2 authored by viettrungluu@chromium.org's avatar viettrungluu@chromium.org
Browse files

Mac: Resize status bubble when window is resized.

BUG=22956
TEST=Load a (slow-loading) web site so that a status bubble will appear and be visible for a while. While the status bubble is visible, resize the window. The status bubble should move and/or resize appropriately.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28448 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ab71d18
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
#import "chrome/browser/cocoa/clear_browsing_data_controller.h"
#import "chrome/browser/cocoa/download_shelf_controller.h"
#include "chrome/browser/cocoa/page_info_window_mac.h"
#include "chrome/browser/cocoa/status_bubble_mac.h"
#include "chrome/browser/cocoa/task_manager_mac.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/download/download_shelf.h"
......
......@@ -31,7 +31,7 @@ class ConstrainedWindowMac;
@class GTMWindowSheetController;
@class InfoBarContainerController;
class LocationBar;
class StatusBubble;
class StatusBubbleMac;
class TabContents;
@class TabContentsController;
@class TabStripController;
......@@ -65,7 +65,7 @@ class TabStripModelObserverBridge;
scoped_nsobject<TabStripController> tabStripController_;
scoped_nsobject<FindBarCocoaController> findBarCocoaController_;
scoped_nsobject<InfoBarContainerController> infoBarContainerController_;
scoped_ptr<StatusBubble> statusBubble_;
scoped_ptr<StatusBubbleMac> statusBubble_;
scoped_nsobject<DownloadShelfController> downloadShelfController_;
scoped_nsobject<ExtensionShelfController> extensionShelfController_;
scoped_nsobject<BookmarkBarController> bookmarkBarController_;
......@@ -91,7 +91,7 @@ class TabStripModelObserverBridge;
- (LocationBar*)locationBar;
// Access the C++ bridge object representing the status bubble for the window.
- (StatusBubble*)statusBubble;
- (StatusBubbleMac*)statusBubble;
// Updates the toolbar (and transitively the location bar) with the states of
// the specified |tab|. If |shouldRestore| is true, we're switching
......@@ -156,6 +156,9 @@ class TabStripModelObserverBridge;
- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window;
- (void)removeConstrainedWindow:(ConstrainedWindowMac*)window;
// Delegate method called when window is resized.
- (void)windowDidResize:(NSNotification*)notification;
@end
......
......@@ -647,7 +647,7 @@ willPositionSheet:(NSWindow*)sheet
return [toolbarController_ locationBar];
}
- (StatusBubble*)statusBubble {
- (StatusBubbleMac*)statusBubble {
return statusBubble_.get();
}
......@@ -1081,6 +1081,14 @@ willPositionSheet:(NSWindow*)sheet
bookmarkBubbleController_.reset(nil);
}
// Delegate method called when window is resized.
- (void)windowDidResize:(NSNotification*)notification {
// Resize (and possibly move) the status bubble. Note that we may get called
// when the status bubble does not exist.
if(statusBubble_.get())
statusBubble_->UpdateSizeAndPosition();
}
@end
@implementation BrowserWindowController (Private)
......
......@@ -26,6 +26,11 @@ class StatusBubbleMac : public StatusBubble {
virtual void MouseMoved();
virtual void UpdateDownloadShelfVisibility(bool visible);
// Mac-specific method: Update the size and position of the status bubble to
// match the parent window. Safe to call even when the status bubble does not
// exist.
void UpdateSizeAndPosition();
private:
friend class StatusBubbleMacTest;
......@@ -38,6 +43,9 @@ class StatusBubbleMac : public StatusBubble {
void FadeIn();
void FadeOut();
// Calculate the appropriate frame for the status bubble window.
NSRect CalculateWindowFrame();
// The window we attach ourselves to.
NSWindow* parent_; // WEAK
......
......@@ -182,11 +182,8 @@ void StatusBubbleMac::Create() {
if (window_)
return;
NSRect rect = [parent_ frame];
rect.size.height = kWindowHeight;
rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width);
// TODO(avi):fix this for RTL
window_ = [[NSWindow alloc] initWithContentRect:rect
window_ = [[NSWindow alloc] initWithContentRect:CalculateWindowFrame()
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES];
......@@ -227,3 +224,18 @@ void StatusBubbleMac::FadeOut() {
[NSAnimationContext endGrouping];
}
void StatusBubbleMac::UpdateSizeAndPosition() {
if (!window_)
return;
[window_ setFrame:CalculateWindowFrame() display:YES];
}
NSRect StatusBubbleMac::CalculateWindowFrame() {
DCHECK(parent_);
NSRect rect = [parent_ frame];
rect.size.height = kWindowHeight;
rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width);
return rect;
}
......@@ -17,7 +17,6 @@
@end
@implementation StatusBubbleMacTestWindowDelegate
- (GTMTheme *)gtm_themeForWindow:(NSWindow *)window {
NSLog(@"gettheme");
return [[[GTMTheme alloc] init] autorelease];
}
@end
......@@ -119,3 +118,49 @@ TEST_F(StatusBubbleMacTest, Delete) {
bubble->SetStatus(L"showing");
delete bubble;
}
TEST_F(StatusBubbleMacTest, UpdateSizeAndPosition) {
// Test |UpdateSizeAndPosition()| when status bubble does not exist (shouldn't
// crash; shouldn't create window).
EXPECT_FALSE(GetWindow());
bubble_->UpdateSizeAndPosition();
EXPECT_FALSE(GetWindow());
// Create a status bubble (with contents) and call resize (without actually
// resizing); the frame size shouldn't change.
bubble_->SetStatus(L"UpdateSizeAndPosition test");
ASSERT_TRUE(GetWindow());
NSRect rect_before = [GetWindow() frame];
bubble_->UpdateSizeAndPosition();
NSRect rect_after = [GetWindow() frame];
EXPECT_TRUE(NSEqualRects(rect_before, rect_after));
// Move the window and call resize; only the origin should change.
NSWindow* window = cocoa_helper_.window();
ASSERT_TRUE(window);
NSRect frame = [window frame];
rect_before = [GetWindow() frame];
frame.origin.x += 10.0; // (fairly arbitrary nonzero value)
frame.origin.y += 10.0; // (fairly arbitrary nonzero value)
[window setFrame:frame display:YES];
bubble_->UpdateSizeAndPosition();
rect_after = [GetWindow() frame];
EXPECT_NE(rect_before.origin.x, rect_after.origin.x);
EXPECT_NE(rect_before.origin.y, rect_after.origin.y);
EXPECT_EQ(rect_before.size.width, rect_after.size.width);
EXPECT_EQ(rect_before.size.height, rect_after.size.height);
// Resize the window (without moving). The origin shouldn't change. The width
// should change (in the current implementation), but not the height.
frame = [window frame];
rect_before = [GetWindow() frame];
frame.size.width += 50.0; // (fairly arbitrary nonzero value)
frame.size.height += 50.0; // (fairly arbitrary nonzero value)
[window setFrame:frame display:YES];
bubble_->UpdateSizeAndPosition();
rect_after = [GetWindow() frame];
EXPECT_EQ(rect_before.origin.x, rect_after.origin.x);
EXPECT_EQ(rect_before.origin.y, rect_after.origin.y);
EXPECT_NE(rect_before.size.width, rect_after.size.width);
EXPECT_EQ(rect_before.size.height, rect_after.size.height);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment