summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 21:02:36 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 21:02:36 +0000
commit34f8fee20dd1c07adcb4960310dd1f387d7b7bf3 (patch)
tree4d69c8742f0bc52889f19dd8fc7f14dbe86947b1 /chrome
parent9ab71d1832cb2651d60769aa263f5fc086a0b6be (diff)
downloadchromium_src-34f8fee20dd1c07adcb4960310dd1f387d7b7bf3.zip
chromium_src-34f8fee20dd1c07adcb4960310dd1f387d7b7bf3.tar.gz
chromium_src-34f8fee20dd1c07adcb4960310dd1f387d7b7bf3.tar.bz2
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
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.mm1
-rw-r--r--chrome/browser/cocoa/browser_window_controller.h9
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm10
-rw-r--r--chrome/browser/cocoa/status_bubble_mac.h8
-rw-r--r--chrome/browser/cocoa/status_bubble_mac.mm20
-rw-r--r--chrome/browser/cocoa/status_bubble_mac_unittest.mm47
6 files changed, 86 insertions, 9 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm
index f32e6b4..42bb480 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/cocoa/browser_window_cocoa.mm
@@ -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"
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h
index 0bd84e9..da08d45 100644
--- a/chrome/browser/cocoa/browser_window_controller.h
+++ b/chrome/browser/cocoa/browser_window_controller.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
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index 3951e4c..b9562fa 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -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)
diff --git a/chrome/browser/cocoa/status_bubble_mac.h b/chrome/browser/cocoa/status_bubble_mac.h
index de305de..9dc177d 100644
--- a/chrome/browser/cocoa/status_bubble_mac.h
+++ b/chrome/browser/cocoa/status_bubble_mac.h
@@ -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
diff --git a/chrome/browser/cocoa/status_bubble_mac.mm b/chrome/browser/cocoa/status_bubble_mac.mm
index 7b592c6..3eef461 100644
--- a/chrome/browser/cocoa/status_bubble_mac.mm
+++ b/chrome/browser/cocoa/status_bubble_mac.mm
@@ -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;
+}
diff --git a/chrome/browser/cocoa/status_bubble_mac_unittest.mm b/chrome/browser/cocoa/status_bubble_mac_unittest.mm
index 2482d96..d462f0d 100644
--- a/chrome/browser/cocoa/status_bubble_mac_unittest.mm
+++ b/chrome/browser/cocoa/status_bubble_mac_unittest.mm
@@ -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);
+}