diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-17 04:04:57 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-17 04:04:57 +0000 |
commit | 44280837bfef2af68bd19dfac604501ba6058add (patch) | |
tree | 486fb61d94a3f2728ac5ad91b5f3db02cf02aff9 /ui/app_list | |
parent | 8611f01f36a713d0260e11670f24403be7294b7c (diff) | |
download | chromium_src-44280837bfef2af68bd19dfac604501ba6058add.zip chromium_src-44280837bfef2af68bd19dfac604501ba6058add.tar.gz chromium_src-44280837bfef2af68bd19dfac604501ba6058add.tar.bz2 |
Pull third-party Cocoa toolkit library files out of c/b/ui so it can be shared with /ui, add motivating use-case/stub (Cocoa app_list AppListView), and tests.
This moves third_party mac UI libraries bundled in with libbrowser_ui.a
(chrome_browser_ui.gypi) into a ui_cocoa_third_party_toolkits component target (ui.gyp).
This allows Cocoa UI components not part of the browser to use the third
party cocoa toolkit code.
The CL includes a stub motivating use case, AppListView (/ui/app_list/cocoa/), and unit tests.
Functionally, on OSX, ./Chromium.app/.. --show-app-list will now show a gray rounded
rectangle (the NSView), rather than the NSWindow, which is now transparent.
BUG=138633
TEST=--show-app-list will show a rounded rectangle for 1 second, rest covered by ./app_list_unittests
Review URL: https://chromiumcodereview.appspot.com/11864003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177340 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list')
-rw-r--r-- | ui/app_list/DEPS | 3 | ||||
-rw-r--r-- | ui/app_list/app_list.gyp | 12 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view.h | 24 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view.mm | 51 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view_unittest.mm | 37 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view_window.h | 2 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view_window.mm | 16 | ||||
-rw-r--r-- | ui/app_list/cocoa/app_list_view_window_unittest.mm | 51 |
8 files changed, 180 insertions, 16 deletions
diff --git a/ui/app_list/DEPS b/ui/app_list/DEPS index 9337d4b..4bb0b29 100644 --- a/ui/app_list/DEPS +++ b/ui/app_list/DEPS @@ -2,4 +2,7 @@ include_rules = [ "+skia", "+third_party/skia", "+ui", + + # Allow inclusion of third-party code: + "+third_party/GTM", # Google Toolbox for Mac. ] diff --git a/ui/app_list/app_list.gyp b/ui/app_list/app_list.gyp index e678365..24791d0 100644 --- a/ui/app_list/app_list.gyp +++ b/ui/app_list/app_list.gyp @@ -34,6 +34,8 @@ 'app_list_switches.h', 'app_list_view_delegate.h', 'apps_grid_view_delegate.h', + 'cocoa/app_list_view.h', + 'cocoa/app_list_view.mm', 'cocoa/app_list_view_window.h', 'cocoa/app_list_view_window.mm', 'pagination_model.cc', @@ -83,7 +85,14 @@ ['exclude', 'views/'], ], }], - ['OS!="mac"', { + ['OS=="mac"', { + 'dependencies': [ + '../ui.gyp:ui_cocoa_third_party_toolkits', + ], + 'include_dirs': [ + '../../third_party/GTM', + ], + }, { # OS!="mac" 'sources/': [ ['exclude', 'cocoa/'], ], @@ -107,6 +116,7 @@ 'test/app_list_test_suite.cc', 'test/app_list_test_suite.h', 'test/run_all_unittests.cc', + 'cocoa/app_list_view_unittest.mm', 'cocoa/app_list_view_window_unittest.mm', 'views/apps_grid_view_unittest.cc', 'views/test/apps_grid_view_test_api.cc', diff --git a/ui/app_list/cocoa/app_list_view.h b/ui/app_list/cocoa/app_list_view.h new file mode 100644 index 0000000..b6f918a --- /dev/null +++ b/ui/app_list/cocoa/app_list_view.h @@ -0,0 +1,24 @@ +// Copyright 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 <Cocoa/Cocoa.h> + +#include "base/memory/scoped_ptr.h" + +namespace app_list { +class AppListModel; +class AppListViewDelegate; +} + +// AppListView is the top-level view and controller of app list UI. +@interface AppListView : NSView { + @private + scoped_ptr<app_list::AppListModel> model_; + scoped_ptr<app_list::AppListViewDelegate> delegate_; +} + +// Takes ownership of |appListViewDelegate|. +- (id)initWithViewDelegate:(app_list::AppListViewDelegate*)appListViewDelegate; + +@end diff --git a/ui/app_list/cocoa/app_list_view.mm b/ui/app_list/cocoa/app_list_view.mm new file mode 100644 index 0000000..e6543c7 --- /dev/null +++ b/ui/app_list/cocoa/app_list_view.mm @@ -0,0 +1,51 @@ +// Copyright 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/app_list/cocoa/app_list_view.h" + +#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" +#include "ui/app_list/app_list_model.h" +#include "ui/app_list/app_list_view_delegate.h" + +// The roundedness of the corners of the bubble. +const int kBubbleCornerRadius = 3; +// The grayscale value for the window edge stroke. +const float kWindowEdge = 0.7f; + +@implementation AppListView; + +- (id)initWithViewDelegate:(app_list::AppListViewDelegate*)appListViewDelegate { + const int kViewWidth = 200; + const int kViewHeight = 200; + NSRect frame = NSMakeRect(0, 0, kViewWidth, kViewHeight); + if ((self = [super initWithFrame:frame])) { + model_.reset(new app_list::AppListModel()); + delegate_.reset(appListViewDelegate); + } + + return self; +} + +- (void)drawRect:(NSRect)rect { + NSRect bounds = [self bounds]; + NSBezierPath* border = + [NSBezierPath gtm_bezierPathWithRoundRect:bounds + cornerRadius:kBubbleCornerRadius]; + + [[NSColor grayColor] set]; + [border fill]; + + // Inset so the stroke is inside the bounds. + bounds = NSInsetRect(bounds, 0.5, 0.5); + + // TODO(tapted): Update the window border to use assets rather than vectors. + border = + [NSBezierPath gtm_bezierPathWithRoundRect:bounds + cornerRadius:kBubbleCornerRadius]; + + [[NSColor colorWithDeviceWhite:kWindowEdge alpha:1.0f] set]; + [border stroke]; +} + +@end diff --git a/ui/app_list/cocoa/app_list_view_unittest.mm b/ui/app_list/cocoa/app_list_view_unittest.mm new file mode 100644 index 0000000..1c5f322 --- /dev/null +++ b/ui/app_list/cocoa/app_list_view_unittest.mm @@ -0,0 +1,37 @@ +// Copyright 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. + +#include "base/memory/scoped_nsobject.h" +#import "testing/gtest_mac.h" +#import "ui/app_list/cocoa/app_list_view.h" +#import "ui/base/test/ui_cocoa_test_helper.h" + +namespace { + +class AppListViewTest : public ui::CocoaTest { + public: + AppListViewTest() {} + + virtual void SetUp() OVERRIDE { + ui::CocoaTest::SetUp(); + view_.reset([[AppListView alloc] initWithViewDelegate:NULL]); + [[test_window() contentView] addSubview:view_]; + } + + protected: + scoped_nsobject<AppListView> view_; + + private: + DISALLOW_COPY_AND_ASSIGN(AppListViewTest); +}; + +} // namespace + +TEST_VIEW(AppListViewTest, view_); + +// Test allocating the view with no delegate or model, and showing. +TEST_F(AppListViewTest, AddViewAndShow) { + EXPECT_TRUE([view_ superview]); + [view_ display]; +} diff --git a/ui/app_list/cocoa/app_list_view_window.h b/ui/app_list/cocoa/app_list_view_window.h index 8d18efa..2fe4222 100644 --- a/ui/app_list/cocoa/app_list_view_window.h +++ b/ui/app_list/cocoa/app_list_view_window.h @@ -9,4 +9,6 @@ - (id)initAsBubble; +- (void)setAppListView:(NSView*)view; + @end diff --git a/ui/app_list/cocoa/app_list_view_window.mm b/ui/app_list/cocoa/app_list_view_window.mm index 96a0049..50445de 100644 --- a/ui/app_list/cocoa/app_list_view_window.mm +++ b/ui/app_list/cocoa/app_list_view_window.mm @@ -4,21 +4,27 @@ #import "ui/app_list/cocoa/app_list_view_window.h" +#import "ui/base/cocoa/window_size_constants.h" + @implementation AppListViewWindow; - (id)initAsBubble { - const int kWindowWidth = 200; - const int kWindowHeight = 200; - NSRect frame = NSMakeRect(0, 0, kWindowWidth, kWindowHeight); - if ((self = [super initWithContentRect:frame + if ((self = [super initWithContentRect:ui::kWindowSizeDeterminedLater styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) { [self setReleasedWhenClosed:NO]; - [self setBackgroundColor:[NSColor grayColor]]; + [self setBackgroundColor:[NSColor clearColor]]; + [self setOpaque:NO]; + [self setHasShadow:NO]; } return self; } +- (void)setAppListView:(NSView*)view { + [self setContentSize:[view frame].size]; + [self setContentView:view]; +} + @end diff --git a/ui/app_list/cocoa/app_list_view_window_unittest.mm b/ui/app_list/cocoa/app_list_view_window_unittest.mm index 5f5e187..0c2de51 100644 --- a/ui/app_list/cocoa/app_list_view_window_unittest.mm +++ b/ui/app_list/cocoa/app_list_view_window_unittest.mm @@ -2,18 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/memory/scoped_nsobject.h" +#import "base/memory/scoped_nsobject.h" #import "testing/gtest_mac.h" +#import "ui/app_list/cocoa/app_list_view.h" #import "ui/app_list/cocoa/app_list_view_window.h" #import "ui/base/test/ui_cocoa_test_helper.h" -// Unit test harness for Cocoa-specific interactions with the app_list. +namespace { + class AppListViewWindowTest : public ui::CocoaTest { public: - AppListViewWindowTest() { - Init(); - window_.reset([[AppListViewWindow alloc] initAsBubble]); - } + AppListViewWindowTest(); + + void Show(); + void Release(); protected: scoped_nsobject<AppListViewWindow> window_; @@ -22,11 +24,40 @@ class AppListViewWindowTest : public ui::CocoaTest { DISALLOW_COPY_AND_ASSIGN(AppListViewWindowTest); }; -// Test showing, hiding and closing the AppListViewWindow with no content. -TEST_F(AppListViewWindowTest, ShowHideCloseRelease) { +AppListViewWindowTest::AppListViewWindowTest() { + Init(); + window_.reset([[AppListViewWindow alloc] initAsBubble]); +} + +void AppListViewWindowTest::Show() { [window_ makeKeyAndOrderFront:nil]; - [window_ close]; - [window_ setReleasedWhenClosed:YES]; +} + +void AppListViewWindowTest::Release() { + EXPECT_TRUE(window_.get()); + EXPECT_FALSE([window_ isReleasedWhenClosed]); [window_ close]; window_.reset(); } + +} // namespace + +// Test showing, hiding and closing the AppListViewWindow with no content. +TEST_F(AppListViewWindowTest, ShowHideCloseRelease) { + Show(); + EXPECT_TRUE([window_ isVisible]); + [window_ close]; // Hide. + EXPECT_FALSE([window_ isVisible]); + Show(); + Release(); +} + +// Test allocating the AppListView in an AppListViewWindow, and showing. +TEST_F(AppListViewWindowTest, AddViewAndShow) { + scoped_nsobject<AppListView> contentView( + [[AppListView alloc] initWithViewDelegate:NULL]); + [window_ setAppListView:contentView]; + Show(); + EXPECT_TRUE([contentView superview]); + Release(); +} |