diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-28 21:40:07 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-28 21:40:07 +0000 |
commit | c67145b875007932f7f03fe6f8d9e1579fb453ae (patch) | |
tree | 2315d438aed5c7330949297ab24faae46a64d5b3 /ui/message_center | |
parent | 1e050ab18bccc088b3a7a8f8daf2e89915e3a5f2 (diff) | |
download | chromium_src-c67145b875007932f7f03fe6f8d9e1579fb453ae.zip chromium_src-c67145b875007932f7f03fe6f8d9e1579fb453ae.tar.gz chromium_src-c67145b875007932f7f03fe6f8d9e1579fb453ae.tar.bz2 |
[Mac][MC] Create the window controller for popup bubbles.
This UI is still not visible because nothing creates the windows.
BUG=179904
Review URL: https://chromiumcodereview.appspot.com/12583017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191217 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/cocoa/notification_controller.h | 17 | ||||
-rw-r--r-- | ui/message_center/cocoa/notification_controller.mm | 12 | ||||
-rw-r--r-- | ui/message_center/cocoa/notification_controller_unittest.mm | 42 | ||||
-rw-r--r-- | ui/message_center/cocoa/popup_controller.h | 36 | ||||
-rw-r--r-- | ui/message_center/cocoa/popup_controller.mm | 50 | ||||
-rw-r--r-- | ui/message_center/cocoa/popup_controller_unittest.mm | 38 | ||||
-rw-r--r-- | ui/message_center/message_center.gyp | 6 |
7 files changed, 191 insertions, 10 deletions
diff --git a/ui/message_center/cocoa/notification_controller.h b/ui/message_center/cocoa/notification_controller.h index e1a50d9..36d6c04 100644 --- a/ui/message_center/cocoa/notification_controller.h +++ b/ui/message_center/cocoa/notification_controller.h @@ -8,7 +8,11 @@ #import <Cocoa/Cocoa.h> #import "base/memory/scoped_nsobject.h" -#include "ui/message_center/notification.h" + +namespace message_center { +class Notification; +class NotificationChangeObserver; +} @class HoverImageButton; @@ -17,9 +21,12 @@ // the content for both a popup bubble and a view in the notification tray. @interface MCNotificationController : NSViewController { @protected - // The message object. + // The message object. Weak. const message_center::Notification* notification_; + // Observer of the notification, where action messages are forwarded. Weak. + message_center::NotificationChangeObserver* observer_; + // The button that invokes |-close:|, in the upper-right corner. scoped_nsobject<HoverImageButton> closeButton_; @@ -34,11 +41,15 @@ } // Creates a new controller for a given notification. -- (id)initWithNotification:(const message_center::Notification*)notification; +- (id)initWithNotification:(const message_center::Notification*)notification + changeObserver:(message_center::NotificationChangeObserver*)observer; // Action for clicking on the notification's |closeButton_|. - (void)close:(id)sender; +// Accessor for the notification. +- (const message_center::Notification*)notification; + @end #endif // UI_MESSAGE_CENTER_COCOA_NOTIFICATION_CONTROLLER_H_ diff --git a/ui/message_center/cocoa/notification_controller.mm b/ui/message_center/cocoa/notification_controller.mm index 8499367..3eda7e0 100644 --- a/ui/message_center/cocoa/notification_controller.mm +++ b/ui/message_center/cocoa/notification_controller.mm @@ -11,6 +11,8 @@ #import "ui/base/cocoa/hover_image_button.h" #include "ui/base/resource/resource_bundle.h" #include "ui/message_center/message_center_constants.h" +#include "ui/message_center/notification.h" +#include "ui/message_center/notification_change_observer.h" @interface MCNotificationController (Private) // Configures a NSBox to be borderless, titleless, and otherwise appearance- @@ -41,9 +43,11 @@ @implementation MCNotificationController -- (id)initWithNotification:(const message_center::Notification*)notification { +- (id)initWithNotification:(const message_center::Notification*)notification + changeObserver:(message_center::NotificationChangeObserver*)observer { if ((self = [super initWithNibName:nil bundle:nil])) { notification_ = notification; + observer_ = observer; } return self; } @@ -84,7 +88,11 @@ } - (void)close:(id)sender { - // TODO(rsesek): Figure me out. + observer_->OnRemoveNotification(notification_->id(), /*by_user=*/true); +} + +- (const message_center::Notification*)notification { + return notification_; } // Private ///////////////////////////////////////////////////////////////////// diff --git a/ui/message_center/cocoa/notification_controller_unittest.mm b/ui/message_center/cocoa/notification_controller_unittest.mm index db1b89b..c29dd2f 100644 --- a/ui/message_center/cocoa/notification_controller_unittest.mm +++ b/ui/message_center/cocoa/notification_controller_unittest.mm @@ -8,9 +8,21 @@ #include "base/memory/scoped_ptr.h" #include "base/utf_string_conversions.h" #include "base/strings/sys_string_conversions.h" +#include "testing/gmock/include/gmock/gmock.h" #import "ui/base/cocoa/hover_image_button.h" #import "ui/base/test/ui_cocoa_test_helper.h" #include "ui/message_center/message_center_constants.h" +#include "ui/message_center/notification.h" +#include "ui/message_center/notification_change_observer.h" + +namespace { + +class MockChangeObserver : public message_center::NotificationChangeObserver { + public: + MOCK_METHOD2(OnRemoveNotification, void(const std::string&, bool)); +}; + +} // namespace @implementation MCNotificationController (TestingInterface) - (NSButton*)closeButton { @@ -50,8 +62,8 @@ TEST_F(NotificationControllerTest, BasicLayout) { notification->set_icon(gfx::Image([TestIcon() retain])); scoped_nsobject<MCNotificationController> controller( - [[MCNotificationController alloc] initWithNotification: - notification.get()]); + [[MCNotificationController alloc] initWithNotification:notification.get() + changeObserver:NULL]); [controller view]; EXPECT_EQ(TestIcon(), [[controller iconView] image]); @@ -76,10 +88,32 @@ TEST_F(NotificationControllerTest, OverflowText) { std::string(), NULL)); scoped_nsobject<MCNotificationController> controller( - [[MCNotificationController alloc] initWithNotification: - notification.get()]); + [[MCNotificationController alloc] initWithNotification:notification.get() + changeObserver:NULL]); [controller view]; EXPECT_GT(NSHeight([[controller view] frame]), message_center::kNotificationIconSize); } + +TEST_F(NotificationControllerTest, Close) { + scoped_ptr<message_center::Notification> notification( + new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "an_id", + string16(), + string16(), + string16(), + std::string(), + NULL)); + MockChangeObserver observer; + + scoped_nsobject<MCNotificationController> controller( + [[MCNotificationController alloc] initWithNotification:notification.get() + changeObserver:&observer]); + [controller view]; + + EXPECT_CALL(observer, OnRemoveNotification("an_id", true)); + + [[controller closeButton] performClick:nil]; +} diff --git a/ui/message_center/cocoa/popup_controller.h b/ui/message_center/cocoa/popup_controller.h new file mode 100644 index 0000000..18deebc --- /dev/null +++ b/ui/message_center/cocoa/popup_controller.h @@ -0,0 +1,36 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_MESSAGE_CENTER_COCOA_POPUP_CONTROLLER_H_ +#define UI_MESSAGE_CENTER_COCOA_POPUP_CONTROLLER_H_ + +#import <Cocoa/Cocoa.h> + +#import "base/memory/scoped_nsobject.h" + +namespace message_center { +class Notification; +class NotificationChangeObserver; +} + +@class MCNotificationController; + +// A window controller that hosts a notification as a popup balloon on the +// user's desktop. Unlike most window controllers, this does not own itself and +// its lifetime must be managed manually. +@interface MCPopupController : NSWindowController { + @private + scoped_nsobject<MCNotificationController> notificationController_; +} + +// Designated initializer. +- (id)initWithNotification:(const message_center::Notification*)notification + changeObserver:(message_center::NotificationChangeObserver*)observer; + +// Accessor for the notification. +- (const message_center::Notification*)notification; + +@end + +#endif // UI_MESSAGE_CENTER_COCOA_POPUP_CONTROLLER_H_ diff --git a/ui/message_center/cocoa/popup_controller.mm b/ui/message_center/cocoa/popup_controller.mm new file mode 100644 index 0000000..4891f8a --- /dev/null +++ b/ui/message_center/cocoa/popup_controller.mm @@ -0,0 +1,50 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "ui/message_center/cocoa/popup_controller.h" + +#import "ui/base/cocoa/window_size_constants.h" +#import "ui/message_center/cocoa/notification_controller.h" +#include "ui/message_center/message_center.h" + +#if !defined(MAC_OS_X_VERSION_10_7) || \ + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 +enum { + NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8 +}; +#endif // MAC_OS_X_VERSION_10_7 + +@implementation MCPopupController + +- (id)initWithNotification:(const message_center::Notification*)notification + changeObserver:(message_center::NotificationChangeObserver*)observer { + scoped_nsobject<NSWindow> window( + [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:YES]); + if ((self = [super initWithWindow:window])) { + notificationController_.reset( + [[MCNotificationController alloc] initWithNotification:notification + changeObserver:observer]); + [window setReleasedWhenClosed:NO]; + + [window setLevel:NSFloatingWindowLevel]; + [window setExcludedFromWindowsMenu:YES]; + [window setCollectionBehavior: + NSWindowCollectionBehaviorIgnoresCycle | + NSWindowCollectionBehaviorFullScreenAuxiliary]; + + [window setHasShadow:YES]; + [window setFrame:[[notificationController_ view] frame] display:NO]; + [window setContentView:[notificationController_ view]]; + } + return self; +} + +- (const message_center::Notification*)notification { + return [notificationController_ notification]; +} + +@end diff --git a/ui/message_center/cocoa/popup_controller_unittest.mm b/ui/message_center/cocoa/popup_controller_unittest.mm new file mode 100644 index 0000000..42afece --- /dev/null +++ b/ui/message_center/cocoa/popup_controller_unittest.mm @@ -0,0 +1,38 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "ui/message_center/cocoa/popup_controller.h" + +#include "base/memory/scoped_nsobject.h" +#include "base/memory/scoped_ptr.h" +#include "base/utf_string_conversions.h" +#include "base/sys_string_conversions.h" +#import "ui/base/test/ui_cocoa_test_helper.h" +#include "ui/message_center/notification.h" +#include "ui/message_center/notification_change_observer.h" + +class PopupControllerTest : public ui::CocoaTest { +}; + +TEST_F(PopupControllerTest, Creation) { + scoped_ptr<message_center::Notification> notification( + new message_center::Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + "", + ASCIIToUTF16("Added to circles"), + ASCIIToUTF16("Jonathan and 5 others"), + string16(), + std::string(), + NULL)); + + scoped_nsobject<MCPopupController> controller( + [[MCPopupController alloc] initWithNotification:notification.get() + changeObserver:NULL]); + + EXPECT_TRUE([controller window]); + EXPECT_EQ(notification.get(), [controller notification]); + + [controller showWindow:nil]; + [controller close]; +} diff --git a/ui/message_center/message_center.gyp b/ui/message_center/message_center.gyp index 42c6abb..440b3e5 100644 --- a/ui/message_center/message_center.gyp +++ b/ui/message_center/message_center.gyp @@ -25,8 +25,10 @@ 'MESSAGE_CENTER_IMPLEMENTATION', ], 'sources': [ - 'cocoa/notification_controller.mm', 'cocoa/notification_controller.h', + 'cocoa/notification_controller.mm', + 'cocoa/popup_controller.h', + 'cocoa/popup_controller.mm', 'message_center.cc', 'message_center.h', 'message_center_constants.cc', @@ -94,6 +96,7 @@ '../../base/base.gyp:base', '../../base/base.gyp:test_support_base', '../../skia/skia.gyp:skia', + '../../testing/gmock.gyp:gmock', '../../testing/gtest.gyp:gtest', '../ui.gyp:run_ui_unittests', '../ui.gyp:ui', @@ -101,6 +104,7 @@ ], 'sources': [ 'cocoa/notification_controller_unittest.mm', + 'cocoa/popup_controller_unittest.mm', 'message_center_tray_unittest.cc', 'notification_list_unittest.cc', ], |