Commit e89b1bdf authored by benwells@chromium.org's avatar benwells@chromium.org

Remove need to sign in to use the App Launcher.

TBR=sky@chromium.org
BUG=378588

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274486 0039d316-1c4b-4281-b951-d872f2087c98
parent 07aa825a
......@@ -254,10 +254,6 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
virtual app_list::AppListModel* GetModel() OVERRIDE { return model_.get(); }
virtual app_list::SigninDelegate* GetSigninDelegate() OVERRIDE {
return NULL;
}
virtual app_list::SpeechUIModel* GetSpeechUI() OVERRIDE {
return &speech_ui_;
}
......
......@@ -30,7 +30,6 @@
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/url_constants.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/user_metrics.h"
......@@ -91,7 +90,6 @@ void PopulateUsers(const ProfileInfoCache& profile_info,
user.name = profile_info.GetNameOfProfileAtIndex(i);
user.email = profile_info.GetUserNameOfProfileAtIndex(i);
user.profile_path = profile_info.GetPathOfProfileAtIndex(i);
user.signin_required = profile_info.ProfileIsSigninRequiredAtIndex(i);
user.active = active_profile_path == user.profile_path;
users->push_back(user);
}
......@@ -101,27 +99,10 @@ void PopulateUsers(const ProfileInfoCache& profile_info,
AppListViewDelegate::AppListViewDelegate(Profile* profile,
AppListControllerDelegate* controller)
: controller_(controller),
profile_(profile),
model_(NULL),
scoped_observer_(this) {
: controller_(controller), profile_(profile), model_(NULL) {
CHECK(controller_);
SigninManagerFactory::GetInstance()->AddObserver(this);
// Start observing all already-created SigninManagers.
ProfileManager* profile_manager = g_browser_process->profile_manager();
std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
for (std::vector<Profile*>::iterator i = profiles.begin();
i != profiles.end();
++i) {
SigninManagerBase* manager =
SigninManagerFactory::GetForProfileIfExists(*i);
if (manager) {
DCHECK(!scoped_observer_.IsObserving(manager));
scoped_observer_.Add(manager);
}
}
profile_manager->GetProfileInfoCache().AddObserver(this);
app_list::StartPageService* service =
......@@ -148,10 +129,6 @@ AppListViewDelegate::~AppListViewDelegate() {
g_browser_process->
profile_manager()->GetProfileInfoCache().RemoveObserver(this);
SigninManagerFactory* factory = SigninManagerFactory::GetInstance();
if (factory)
factory->RemoveObserver(this);
// Ensure search controller is released prior to speech_ui_.
search_controller_.reset();
}
......@@ -174,29 +151,6 @@ void AppListViewDelegate::OnHotwordRecognized() {
ToggleSpeechRecognition();
}
void AppListViewDelegate::SigninManagerCreated(SigninManagerBase* manager) {
scoped_observer_.Add(manager);
}
void AppListViewDelegate::SigninManagerShutdown(SigninManagerBase* manager) {
if (scoped_observer_.IsObserving(manager))
scoped_observer_.Remove(manager);
}
void AppListViewDelegate::GoogleSigninFailed(
const GoogleServiceAuthError& error) {
OnProfileChanged();
}
void AppListViewDelegate::GoogleSigninSucceeded(const std::string& username,
const std::string& password) {
OnProfileChanged();
}
void AppListViewDelegate::GoogleSignedOut(const std::string& username) {
OnProfileChanged();
}
void AppListViewDelegate::OnProfileChanged() {
model_ = app_list::AppListSyncableServiceFactory::GetForProfile(
profile_)->model();
......@@ -205,8 +159,6 @@ void AppListViewDelegate::OnProfileChanged() {
profile_, model_->search_box(), model_->results(),
speech_ui_.get(), controller_));
signin_delegate_.SetProfile(profile_);
#if defined(USE_ASH)
app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_));
#endif
......@@ -248,10 +200,6 @@ app_list::AppListModel* AppListViewDelegate::GetModel() {
return model_;
}
app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
return &signin_delegate_;
}
app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() {
return speech_ui_.get();
}
......
......@@ -12,13 +12,9 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "chrome/browser/search/hotword_client.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
#include "chrome/browser/ui/app_list/start_page_observer.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "ui/app_list/app_list_view_delegate.h"
class AppListControllerDelegate;
......@@ -44,9 +40,7 @@ class AppSyncUIStateWatcher;
class AppListViewDelegate : public app_list::AppListViewDelegate,
public app_list::StartPageObserver,
public HotwordClient,
public ProfileInfoCacheObserver,
public SigninManagerBase::Observer,
public SigninManagerFactory::Observer {
public ProfileInfoCacheObserver {
public:
AppListViewDelegate(Profile* profile,
AppListControllerDelegate* controller);
......@@ -60,7 +54,6 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
virtual bool ForceNativeDesktop() const OVERRIDE;
virtual void SetProfileByPath(const base::FilePath& profile_path) OVERRIDE;
virtual app_list::AppListModel* GetModel() OVERRIDE;
virtual app_list::SigninDelegate* GetSigninDelegate() OVERRIDE;
virtual app_list::SpeechUIModel* GetSpeechUI() OVERRIDE;
virtual void GetShortcutPathForApp(
const std::string& app_id,
......@@ -105,16 +98,6 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
virtual void OnHotwordStateChanged(bool started) OVERRIDE;
virtual void OnHotwordRecognized() OVERRIDE;
// Overridden from SigninManagerFactory::Observer:
virtual void SigninManagerCreated(SigninManagerBase* manager) OVERRIDE;
virtual void SigninManagerShutdown(SigninManagerBase* manager) OVERRIDE;
// Overridden from SigninManagerBase::Observer:
virtual void GoogleSigninFailed(const GoogleServiceAuthError& error) OVERRIDE;
virtual void GoogleSigninSucceeded(const std::string& username,
const std::string& password) OVERRIDE;
virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
// Overridden from ProfileInfoCacheObserver:
virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE;
virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
......@@ -139,17 +122,12 @@ class AppListViewDelegate : public app_list::AppListViewDelegate,
Users users_;
ChromeSigninDelegate signin_delegate_;
#if defined(USE_ASH)
scoped_ptr<AppSyncUIStateWatcher> app_sync_ui_state_watcher_;
#endif
ObserverList<app_list::AppListViewDelegateObserver> observers_;
// Used to track the SigninManagers that this instance is observing so that
// this instance can be removed as an observer on its destruction.
ScopedObserver<SigninManagerBase, AppListViewDelegate> scoped_observer_;
DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};
......
// 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 "chrome/browser/ui/app_list/chrome_signin_delegate.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/common/page_transition_types.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
#if !defined(OS_CHROMEOS)
SigninManagerBase* GetSigninManager(Profile* profile) {
return SigninManagerFactory::GetForProfile(profile);
}
#endif // !defined(OS_CHROMEOS)
} // namespace
ChromeSigninDelegate::ChromeSigninDelegate() {}
ChromeSigninDelegate::~ChromeSigninDelegate() {}
void ChromeSigninDelegate::SetProfile(Profile* profile) {
profile_ = profile;
}
bool ChromeSigninDelegate::NeedSignin() {
#if defined(OS_CHROMEOS)
return false;
#else
if (!profile_)
return false;
if (!GetSigninManager(profile_))
return false;
return GetSigninManager(profile_)->GetAuthenticatedUsername().empty();
#endif
}
void ChromeSigninDelegate::ShowSignin() {
DCHECK(profile_);
chrome::ScopedTabbedBrowserDisplayer displayer(
profile_, chrome::GetActiveDesktop());
chrome::ShowBrowserSignin(displayer.browser(), signin::SOURCE_APP_LAUNCHER);
}
void ChromeSigninDelegate::OpenLearnMore() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
GURL gurl(rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_LEARN_MORE_LINK));
chrome::NavigateParams params(profile_, gurl, content::PAGE_TRANSITION_LINK);
chrome::Navigate(&params);
}
void ChromeSigninDelegate::OpenSettings() {
ExtensionService* service = profile_->GetExtensionService();
DCHECK(service);
const extensions::Extension* extension = service->GetInstalledExtension(
extension_misc::kSettingsAppId);
if (!extension)
return;
OpenApplication(AppLaunchParams(profile_, extension, NEW_FOREGROUND_TAB));
}
base::string16 ChromeSigninDelegate::GetSigninHeading() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_HEADING);
}
base::string16 ChromeSigninDelegate::GetSigninText() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_TEXT);
}
base::string16 ChromeSigninDelegate::GetSigninButtonText() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_BUTTON);
}
base::string16 ChromeSigninDelegate::GetLearnMoreLinkText() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_LEARN_MORE_TEXT);
}
base::string16 ChromeSigninDelegate::GetSettingsLinkText() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetLocalizedString(IDS_APP_LIST_SIGNIN_SETTINGS_TEXT);
}
// 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.
#ifndef CHROME_BROWSER_UI_APP_LIST_CHROME_SIGNIN_DELEGATE_H_
#define CHROME_BROWSER_UI_APP_LIST_CHROME_SIGNIN_DELEGATE_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/app_list/signin_delegate.h"
class Profile;
class ChromeSigninDelegate : public app_list::SigninDelegate {
public:
ChromeSigninDelegate();
virtual ~ChromeSigninDelegate();
void SetProfile(Profile* profile);
private:
// Overridden from app_list::SigninDelegate:
virtual bool NeedSignin() OVERRIDE;
virtual void ShowSignin() OVERRIDE;
virtual void OpenLearnMore() OVERRIDE;
virtual void OpenSettings() OVERRIDE;
virtual base::string16 GetSigninHeading() OVERRIDE;
virtual base::string16 GetSigninText() OVERRIDE;
virtual base::string16 GetSigninButtonText() OVERRIDE;
virtual base::string16 GetLearnMoreLinkText() OVERRIDE;
virtual base::string16 GetSettingsLinkText() OVERRIDE;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(ChromeSigninDelegate);
};
#endif // CHROME_BROWSER_UI_APP_LIST_CHROME_SIGNIN_DELEGATE_H_
......@@ -170,8 +170,6 @@
'browser/ui/app_list/app_list_util.h',
'browser/ui/app_list/app_list_view_delegate.cc',
'browser/ui/app_list/app_list_view_delegate.h',
'browser/ui/app_list/chrome_signin_delegate.cc',
'browser/ui/app_list/chrome_signin_delegate.h',
'browser/ui/app_list/drive/drive_app_converter.cc',
'browser/ui/app_list/drive/drive_app_converter.h',
'browser/ui/app_list/extension_app_item.cc',
......
......@@ -70,8 +70,6 @@
'cocoa/item_drag_controller.mm',
'cocoa/scroll_view_with_no_scrollbars.h',
'cocoa/scroll_view_with_no_scrollbars.mm',
'cocoa/signin_view_controller.h',
'cocoa/signin_view_controller.mm',
'pagination_model.cc',
'pagination_model.h',
'pagination_model_observer.h',
......@@ -80,8 +78,6 @@
'search_box_model_observer.h',
'search_result.cc',
'search_result.h',
'signin_delegate.cc',
'signin_delegate.h',
'speech_ui_model.cc',
'speech_ui_model.h',
'speech_ui_model_observer.h',
......@@ -132,8 +128,6 @@
'views/search_result_list_view_delegate.h',
'views/search_result_view.cc',
'views/search_result_view.h',
'views/signin_view.cc',
'views/signin_view.h',
'views/speech_view.cc',
'views/speech_view.h',
'views/start_page_view.cc',
......@@ -221,7 +215,6 @@
'cocoa/apps_grid_controller_unittest.mm',
'cocoa/apps_search_box_controller_unittest.mm',
'cocoa/apps_search_results_controller_unittest.mm',
'cocoa/signin_view_controller_unittest.mm',
'cocoa/test/apps_grid_controller_test_helper.h',
'cocoa/test/apps_grid_controller_test_helper.mm',
'test/run_all_unittests.cc',
......
......@@ -67,10 +67,6 @@ bool AppListMenu::IsCommandIdChecked(int command_id) const {
}
bool AppListMenu::IsCommandIdEnabled(int command_id) const {
if (command_id >= SELECT_PROFILE &&
command_id < SELECT_PROFILE + static_cast<int>(users_.size())) {
return !users_[command_id - SELECT_PROFILE].signin_required;
}
return true;
}
......
......@@ -6,7 +6,8 @@
namespace app_list {
AppListViewDelegate::User::User() : active(false), signin_required(false) {}
AppListViewDelegate::User::User() : active(false) {
}
AppListViewDelegate::User::~User() {}
......
......@@ -31,7 +31,6 @@ namespace app_list {
class AppListModel;
class AppListViewDelegateObserver;
class SearchResult;
class SigninDelegate;
class SpeechUIModel;
class APP_LIST_EXPORT AppListViewDelegate {
......@@ -52,9 +51,6 @@ class APP_LIST_EXPORT AppListViewDelegate {
// The path to this user's profile directory.
base::FilePath profile_path;
// Whether or not the current profile requires sign-in beofre use.
bool signin_required;
};
typedef std::vector<User> Users;
......@@ -73,9 +69,6 @@ class APP_LIST_EXPORT AppListViewDelegate {
// by the delegate, or owned elsewhere (e.g. a profile keyed service).
virtual AppListModel* GetModel() = 0;
// Gets the SigninDelegate for the app list. Owned by the AppListViewDelegate.
virtual SigninDelegate* GetSigninDelegate() = 0;
// Gets the SpeechUIModel for the app list. Owned by the AppListViewDelegate.
virtual SpeechUIModel* GetSpeechUI() = 0;
......
......@@ -22,7 +22,6 @@ class AppListModelObserverBridge;
@class AppListPagerView;
@class AppsGridController;
@class SigninViewController;
// Controller for the top-level view of the app list UI. It creates and hosts an
// AppsGridController (displaying an AppListModel), pager control to navigate
......@@ -37,9 +36,8 @@ APP_LIST_EXPORT
base::scoped_nsobject<AppsSearchBoxController> appsSearchBoxController_;
base::scoped_nsobject<AppsSearchResultsController>
appsSearchResultsController_;
base::scoped_nsobject<SigninViewController> signinViewController_;
// Subview for drawing the background. Hidden when the signin view is visible.
// Subview for drawing the background.
base::scoped_nsobject<NSView> backgroundView_;
// Subview of |backgroundView_| that slides out when search results are shown.
......
......@@ -13,10 +13,8 @@
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/app_list_view_delegate_observer.h"
#include "ui/app_list/signin_delegate.h"
#import "ui/app_list/cocoa/app_list_pager_view.h"
#import "ui/app_list/cocoa/apps_grid_controller.h"
#import "ui/app_list/cocoa/signin_view_controller.h"
#import "ui/base/cocoa/flipped_view.h"
#include "ui/app_list/search_box_model.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
......@@ -364,24 +362,6 @@ void AppListModelObserverBridge::OnProfilesChanged() {
- (void)onProfilesChanged {
[appsSearchBoxController_ rebuildMenu];
app_list::SigninDelegate* signinDelegate =
delegate_ ? delegate_->GetSigninDelegate() : NULL;
BOOL showSigninView = signinDelegate && signinDelegate->NeedSignin();
[[signinViewController_ view] removeFromSuperview];
signinViewController_.reset();
if (!showSigninView) {
[backgroundView_ setHidden:NO];
return;
}
[backgroundView_ setHidden:YES];
signinViewController_.reset(
[[SigninViewController alloc] initWithFrame:[backgroundView_ frame]
cornerRadius:kBubbleCornerRadius
delegate:signinDelegate]);
[[self view] addSubview:[signinViewController_ view]];
}
@end
......@@ -20,7 +20,6 @@ class AppListViewControllerTest : public AppsGridControllerTestHelper {
virtual void SetUp() OVERRIDE {
app_list_view_controller_.reset([[AppListViewController alloc] init]);
scoped_ptr<AppListTestViewDelegate> delegate(new AppListTestViewDelegate);
delegate->SetSignedIn(true);
[app_list_view_controller_
setDelegate:delegate.PassAs<app_list::AppListViewDelegate>()];
SetUpWithGridController([app_list_view_controller_ appsGridController]);
......@@ -104,25 +103,5 @@ TEST_F(AppListViewControllerTest, PagerChangingPage) {
EXPECT_EQ(1.0, [apps_grid_controller_ visiblePortionOfPage:0]);
}
// Test the view when the user is already signed in.
TEST_F(AppListViewControllerTest, SignedIn) {
// There should be just 1, visible subview when signed in.
EXPECT_EQ(1u, [[[app_list_view_controller_ view] subviews] count]);
EXPECT_FALSE([[app_list_view_controller_ backgroundView] isHidden]);
}
// Test the view when signin is required.
TEST_F(AppListViewControllerTest, NeedsSignin) {
// Begin the test with a signed out app list.
delegate()->SetSignedIn(false);
EXPECT_EQ(2u, [[[app_list_view_controller_ view] subviews] count]);
EXPECT_TRUE([[app_list_view_controller_ backgroundView] isHidden]);
// Simulate signing in, should enter the SignedIn state.
delegate()->SetSignedIn(true);
EXPECT_EQ(1u, [[[app_list_view_controller_ view] subviews] count]);
EXPECT_FALSE([[app_list_view_controller_ backgroundView] isHidden]);
}
} // namespace test
} // namespace app_list
// 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.
#ifndef UI_APP_LIST_COCOA_SIGNIN_VIEW_CONTROLLER_H_
#define UI_APP_LIST_COCOA_SIGNIN_VIEW_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include "ui/app_list/app_list_export.h"
namespace app_list {
class SigninDelegate;
}
// Controller for the app list signin page. The signin view shows a blue button
// that opens a browser window to conduct the signin flow. The delegate also
// provides UI text and actions for the view, including "Learn More" and
// "Settings" links.
APP_LIST_EXPORT
@interface SigninViewController : NSViewController {
@private
app_list::SigninDelegate* delegate_; // Weak. Owned by AppListViewDelegate.
}
- (id)initWithFrame:(NSRect)frame
cornerRadius:(CGFloat)cornerRadius
delegate:(app_list::SigninDelegate*)delegate;
@end
#endif // UI_APP_LIST_COCOA_SIGNIN_VIEW_CONTROLLER_H_
// 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/signin_view_controller.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkColor.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/signin_delegate.h"
#import "ui/base/cocoa/controls/blue_label_button.h"
#import "ui/base/cocoa/controls/hyperlink_button_cell.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
const CGFloat kTopPadding = 40;
const CGFloat kBottomPadding = 40;
const CGFloat kLeftPadding = 40;
const CGFloat kRightPadding = 40;
const CGFloat kHeadingPadding = 30;
const CGFloat kButtonPadding = 40;
const CGFloat kTitleFontSizeDelta = 5;
const SkColor kLinkColor = SkColorSetRGB(0x11, 0x55, 0xcc);
const SkColor kTextColor = SkColorSetRGB(0x33, 0x33, 0x33);
// Padding on the left of the text in the NSTextField and HyperlinkButtonCell.
const CGFloat kTextFieldPadding = 2;
} // namespace
@interface SigninViewController ()
- (void)onLearnMoreButtonClick:(id)sender;
- (void)onSettingsButtonClick:(id)sender;
- (void)onSigninButtonClick:(id)sender;
- (NSButton*)makeLinkButtonWithTitle:(NSString*)title
origin:(NSPoint)origin
action:(SEL)action;
- (NSTextField*)makeTextFieldWithText:(NSString*)text
font:(NSFont*)font
frame:(NSRect)frame;
- (void)populateAndLayoutView;
@end
@interface AppsSigninView : NSView {
@private
CGFloat cornerRadius_;
}
@property(assign, nonatomic) CGFloat cornerRadius;
@end
@implementation SigninViewController;
- (id)initWithFrame:(NSRect)frame
cornerRadius:(CGFloat)cornerRadius
delegate:(app_list::SigninDelegate*)delegate {
if ((self = [super init])) {
base::scoped_nsobject<AppsSigninView> appsSigninView(
[[AppsSigninView alloc] initWithFrame:frame]);
[appsSigninView setCornerRadius:cornerRadius];
delegate_ = delegate;
[self setView:appsSigninView];
[self populateAndLayoutView];
}
return self;
}
- (void)onLearnMoreButtonClick:(id)sender {
delegate_->OpenLearnMore();
}
- (void)onSettingsButtonClick:(id)sender {
delegate_->OpenSettings();
}
- (void)onSigninButtonClick:(id)sender {
delegate_->ShowSignin();
}
- (NSButton*)makeLinkButtonWithTitle:(NSString*)title
origin:(NSPoint)origin
action:(SEL)action {
base::scoped_nsobject<NSButton> button(
[[HyperlinkButtonCell buttonWithString:title] retain]);
[[button cell] setShouldUnderline:NO];
[[button cell] setTextColor:gfx::SkColorToSRGBNSColor(kLinkColor)];
[button sizeToFit];
origin.x -= kTextFieldPadding;
[button setFrameOrigin:origin];
[button setTarget:self];
[button setAction:action];
return button.autorelease();
}
- (NSTextField*)makeTextFieldWithText:(NSString*)text
font:(NSFont*)font
frame:(NSRect)frame {
base::scoped_nsobject<NSTextField> textField(
[[NSTextField alloc] initWithFrame:frame]);
[textField setEditable:NO];
[textField setSelectable:NO];
[textField setDrawsBackground:NO];
[textField setBezeled:NO];
NSDictionary* textAttributes = @{
NSFontAttributeName : font,
NSForegroundColorAttributeName : gfx::SkColorToSRGBNSColor(kTextColor)
};
base::scoped_nsobject<NSAttributedString> attributedText(
[[NSAttributedString alloc] initWithString:text
attributes:textAttributes]);
[textField setAttributedStringValue:attributedText];
[GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:textField];
NSPoint origin = [textField frame].origin;
origin.x -= kTextFieldPadding;
origin.y -= NSHeight([textField bounds]);
[textField setFrameOrigin:origin];
return textField.autorelease();
}
- (void)populateAndLayoutView {
NSView* signinView = [self view];
NSRect frame = [signinView frame];
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::FontList& baseFontList =
rb.GetFontList(ui::ResourceBundle::BaseFont);
NSString* titleText = base::SysUTF16ToNSString(delegate_->GetSigninHeading());
NSFont* titleFont = baseFontList.DeriveWithSizeDelta(kTitleFontSizeDelta)
.GetPrimaryFont().GetNativeFont();
NSRect rect = NSMakeRect(kLeftPadding, NSHeight(frame) - kTopPadding,
NSWidth(frame) - kLeftPadding - kRightPadding, 0);
NSTextField* titleTextView = [self makeTextFieldWithText:titleText
font:titleFont
frame:rect];
[signinView addSubview:titleTextView];
NSString* signinText = base::SysUTF16ToNSString(delegate_->GetSigninText());
rect.origin.y = floor(
NSMinY([titleTextView frame]) + [titleFont descender] - kHeadingPadding);
NSFont* signinTextFont = baseFontList.GetPrimaryFont().GetNativeFont();
NSTextField* signinTextView = [self makeTextFieldWithText:signinText
font:signinTextFont
frame:rect];
[signinView addSubview:signinTextView];
base::scoped_nsobject<BlueLabelButton> button(
[[BlueLabelButton alloc] initWithFrame:NSZeroRect]);
[button setTitle:base::SysUTF16ToNSString(delegate_->GetSigninButtonText())];
[button setKeyEquivalent:@"\r"];
[button setTarget:self];
[button setAction:@selector(onSigninButtonClick:)];
[button sizeToFit];
NSPoint buttonOrigin = NSMakePoint(kLeftPadding, floor(
NSMinY([signinTextView frame]) - [signinTextFont descender] -
NSHeight([button frame]) - kButtonPadding));
[button setFrameOrigin:buttonOrigin];
[signinView addSubview:button];
NSString* settingsLinkText =
base::SysUTF16ToNSString(delegate_->GetSettingsLinkText());
NSButton* settingsLink =
[self makeLinkButtonWithTitle:settingsLinkText
origin:NSMakePoint(kLeftPadding, kBottomPadding)
action:@selector(onSettingsButtonClick:)];
NSPoint origin = NSMakePoint(kLeftPadding,
NSMaxY([settingsLink frame]));
NSString* learnMoreLinkText =
base::SysUTF16ToNSString(delegate_->GetLearnMoreLinkText());
NSButton* learnMoreLink =
[self makeLinkButtonWithTitle:learnMoreLinkText
origin:origin
action:@selector(onLearnMoreButtonClick:)];
[signinView addSubview:learnMoreLink];
[signinView addSubview:settingsLink];
}
@end
@implementation AppsSigninView
@synthesize cornerRadius = cornerRadius_;
- (void)drawRect:(NSRect)dirtyRect {
[gfx::SkColorToSRGBNSColor(app_list::kContentsBackgroundColor) set];
[[NSBezierPath bezierPathWithRoundedRect:[self bounds]
xRadius:cornerRadius_
yRadius:cornerRadius_] fill];
}
@end
// 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/signin_view_controller.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/utf_string_conversions.h"
#import "testing/gtest_mac.h"
#include "ui/app_list/signin_delegate.h"
#include "ui/app_list/test/app_list_test_view_delegate.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"
@class TestSigninViewDelegate;
namespace {
// Helper function to cycle through the responder chain created implicitly
// from subviews, without having to interact with the event system.
NSControl* NextControl(NSControl* control) {
NSArray* siblings = [[control superview] subviews];
for (NSUInteger index = [siblings indexOfObject:control] + 1;
index < [siblings count] ; ++index) {
if ([[siblings objectAtIndex:index] acceptsFirstResponder])
return [siblings objectAtIndex:index];
}
return nil;
}
} // namespace
namespace app_list {
namespace test {
class SigninViewControllerTest : public ui::CocoaTest,
public SigninDelegate {
public:
SigninViewControllerTest()
: test_text_(base::ASCIIToUTF16("Sign in")),
needs_signin_(true),
show_signin_count_(0),
open_learn_more_count_(0),
open_settings_count_(0) {}
// ui::CocoaTest override:
virtual void SetUp() OVERRIDE;
// SigninDelegate overrides:
virtual bool NeedSignin() OVERRIDE { return needs_signin_; }
virtual void ShowSignin() OVERRIDE { ++show_signin_count_; }
virtual void OpenLearnMore() OVERRIDE { ++open_learn_more_count_; }
virtual void OpenSettings() OVERRIDE { ++open_settings_count_; }
virtual base::string16 GetSigninHeading() OVERRIDE { return test_text_; }
virtual base::string16 GetSigninText() OVERRIDE { return test_text_; }
virtual base::string16 GetSigninButtonText() OVERRIDE { return test_text_; }
virtual base::string16 GetLearnMoreLinkText() OVERRIDE { return test_text_; }
virtual base::string16 GetSettingsLinkText() OVERRIDE { return test_text_; }
protected:
const base::string16 test_text_;
base::scoped_nsobject<SigninViewController> signin_view_controller_;
bool needs_signin_;
int show_signin_count_;
int open_learn_more_count_;
int open_settings_count_;
private:
DISALLOW_COPY_AND_ASSIGN(SigninViewControllerTest);
};
void SigninViewControllerTest::SetUp() {
NSRect frame = NSMakeRect(0, 0, 400, 500);
signin_view_controller_.reset(
[[SigninViewController alloc] initWithFrame:frame
cornerRadius:3
delegate:this]);
ui::CocoaTest::SetUp();
[[test_window() contentView] addSubview:[signin_view_controller_ view]];
}
TEST_VIEW(SigninViewControllerTest, [signin_view_controller_ view]);
TEST_F(SigninViewControllerTest, NotSignedIn) {
NSArray* content_subviews = [[test_window() contentView] subviews];
EXPECT_EQ(1u, [content_subviews count]);
NSArray* subviews = [[content_subviews objectAtIndex:0] subviews];
EXPECT_LT(0u, [subviews count]);
// The first subview that acceptFirstResponder should be the signin button,
// and performing its action should show the signin dialog. Then "Learn more",
// followed by "Settings".
NSControl* control = NextControl([subviews objectAtIndex:0]);
EXPECT_EQ(0, show_signin_count_);
EXPECT_TRUE([[control target] performSelector:[control action]
withObject:control]);
EXPECT_EQ(1, show_signin_count_);
control = NextControl(control);
EXPECT_EQ(0, open_learn_more_count_);
EXPECT_TRUE([[control target] performSelector:[control action]
withObject:control]);
EXPECT_EQ(1, open_learn_more_count_);
control = NextControl(control);
EXPECT_EQ(0, open_settings_count_);
EXPECT_TRUE([[control target] performSelector:[control action]
withObject:control]);
EXPECT_EQ(1, open_settings_count_);
}
} // namespace test
} // namespace app_list
// 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 "ui/app_list/signin_delegate.h"
namespace app_list {
SigninDelegate::SigninDelegate() {}
SigninDelegate::~SigninDelegate() {}
} // namespace app_list
// 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.
#ifndef UI_APP_LIST_SIGNIN_DELEGATE_H_
#define UI_APP_LIST_SIGNIN_DELEGATE_H_
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "ui/app_list/app_list_export.h"
namespace app_list {
class APP_LIST_EXPORT SigninDelegate {
public:
SigninDelegate();
virtual ~SigninDelegate();
virtual bool NeedSignin() = 0;
virtual void ShowSignin() = 0;
virtual void OpenLearnMore() = 0;
virtual void OpenSettings() = 0;
virtual base::string16 GetSigninHeading() = 0;
virtual base::string16 GetSigninText() = 0;
virtual base::string16 GetSigninButtonText() = 0;
virtual base::string16 GetLearnMoreLinkText() = 0;
virtual base::string16 GetSettingsLinkText() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(SigninDelegate);
};
} // namespace app_list
#endif // UI_APP_LIST_SIGNIN_DELEGATE_H_
......@@ -11,64 +11,23 @@
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/app_list_view_delegate_observer.h"
#include "ui/app_list/signin_delegate.h"
#include "ui/app_list/test/app_list_test_model.h"
#include "ui/gfx/image/image_skia.h"
namespace app_list {
namespace test {
class TestSigninDelegate : public SigninDelegate {
public:
TestSigninDelegate() : signed_in_(true) {}
void set_signed_in(bool signed_in) { signed_in_ = signed_in; }
// SigninDelegate overrides:
virtual bool NeedSignin() OVERRIDE { return !signed_in_; }
virtual void ShowSignin() OVERRIDE {}
virtual void OpenLearnMore() OVERRIDE {}
virtual void OpenSettings() OVERRIDE {}
virtual base::string16 GetSigninHeading() OVERRIDE {
return base::string16();
}
virtual base::string16 GetSigninText() OVERRIDE { return base::string16(); }
virtual base::string16 GetSigninButtonText() OVERRIDE {
return base::string16();
}
virtual base::string16 GetLearnMoreLinkText() OVERRIDE {
return base::string16();
}
virtual base::string16 GetSettingsLinkText() OVERRIDE {
return base::string16();
}
private:
bool signed_in_;
DISALLOW_COPY_AND_ASSIGN(TestSigninDelegate);
};
AppListTestViewDelegate::AppListTestViewDelegate()
: dismiss_count_(0),
toggle_speech_recognition_count_(0),
open_search_result_count_(0),
next_profile_app_count_(0),
test_signin_delegate_(new TestSigninDelegate),
model_(new AppListTestModel),
speech_ui_(SPEECH_RECOGNITION_OFF) {
}
AppListTestViewDelegate::~AppListTestViewDelegate() {}
void AppListTestViewDelegate::SetSignedIn(bool signed_in) {
test_signin_delegate_->set_signed_in(signed_in);
FOR_EACH_OBSERVER(AppListViewDelegateObserver,
observers_,
OnProfilesChanged());
}
int AppListTestViewDelegate::GetToggleSpeechRecognitionCountAndReset() {
int count = toggle_speech_recognition_count_;
toggle_speech_recognition_count_ = 0;
......@@ -88,10 +47,6 @@ AppListModel* AppListTestViewDelegate::GetModel() {
return model_.get();
}
SigninDelegate* AppListTestViewDelegate::GetSigninDelegate() {
return test_signin_delegate_.get();
}
SpeechUIModel* AppListTestViewDelegate::GetSpeechUI() {
return &speech_ui_;
}
......
......@@ -19,7 +19,6 @@ namespace app_list {
namespace test {
class AppListTestModel;
class TestSigninDelegate;
// A concrete AppListViewDelegate for unit tests.
class AppListTestViewDelegate : public AppListViewDelegate {
......@@ -44,10 +43,6 @@ class AppListTestViewDelegate : public AppListViewDelegate {
auto_launch_timeout_ = timeout;
}
// Sets the signin status of the signin delegate, creating one if there isn't
// one already.
void SetSignedIn(bool signed_in);
// Returns the value of |toggle_speech_recognition_count_| and then
// resets this value to 0.
int GetToggleSpeechRecognitionCountAndReset();
......@@ -56,7 +51,6 @@ class AppListTestViewDelegate : public AppListViewDelegate {
virtual bool ForceNativeDesktop() const OVERRIDE;
virtual void SetProfileByPath(const base::FilePath& profile_path) OVERRIDE;
virtual AppListModel* GetModel() OVERRIDE;
virtual SigninDelegate* GetSigninDelegate() OVERRIDE;
virtual SpeechUIModel* GetSpeechUI() OVERRIDE;
virtual void GetShortcutPathForApp(
const std::string& app_id,
......@@ -101,7 +95,6 @@ class AppListTestViewDelegate : public AppListViewDelegate {
int next_profile_app_count_;
std::map<size_t, int> open_search_result_counts_;
Users users_;
scoped_ptr<TestSigninDelegate> test_signin_delegate_;
scoped_ptr<AppListTestModel> model_;
ObserverList<AppListViewDelegateObserver> observers_;
SpeechUIModel speech_ui_;
......
......@@ -13,7 +13,6 @@
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/pagination_model.h"
#include "ui/app_list/signin_delegate.h"
#include "ui/app_list/speech_ui_model.h"
#include "ui/app_list/views/app_list_background.h"
#include "ui/app_list/views/app_list_folder_view.h"
......@@ -22,7 +21,6 @@
#include "ui/app_list/views/apps_container_view.h"
#include "ui/app_list/views/contents_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/app_list/views/signin_view.h"
#include "ui/app_list/views/speech_view.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/layer.h"
......@@ -148,7 +146,6 @@ class HideViewAnimationObserver : public ui::ImplicitAnimationObserver {
AppListView::AppListView(AppListViewDelegate* delegate)
: delegate_(delegate),
app_list_main_view_(NULL),
signin_view_(NULL),
speech_view_(NULL),
overlay_view_(NULL),
animation_observer_(new HideViewAnimationObserver()) {
......@@ -254,12 +251,6 @@ void AppListView::Prerender() {
}
void AppListView::OnProfilesChanged() {
SigninDelegate* signin_delegate =
delegate_ ? delegate_->GetSigninDelegate() : NULL;
bool show_signin_view = signin_delegate && signin_delegate->NeedSignin();
signin_view_->SetVisible(show_signin_view);
app_list_main_view_->SetVisible(!show_signin_view);
app_list_main_view_->search_box_view()->InvalidateMenu();
}
......@@ -308,11 +299,6 @@ void AppListView::InitAsBubbleInternal(gfx::NativeView parent,
app_list_main_view_->layer()->SetMasksToBounds(true);
#endif
signin_view_ =
new SigninView(delegate_->GetSigninDelegate(),
app_list_main_view_->GetPreferredSize().width());
AddChildView(signin_view_);
// Speech recognition is available only when the start page exists.
if (delegate_ && delegate_->GetSpeechRecognitionContents()) {
speech_view_ = new SpeechView(delegate_.get());
......@@ -459,7 +445,6 @@ bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
void AppListView::Layout() {
const gfx::Rect contents_bounds = GetContentsBounds();
app_list_main_view_->SetBoundsRect(contents_bounds);
signin_view_->SetBoundsRect(contents_bounds);
if (speech_view_) {
gfx::Rect speech_bounds = contents_bounds;
......@@ -502,15 +487,11 @@ void AppListView::OnWidgetVisibilityChanged(views::Widget* widget,
if (!visible)
app_list_main_view_->ResetForShow();
// Whether we need to signin or not may have changed since last time we were
// shown.
Layout();
}
void AppListView::OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) {
if (signin_view_->visible() || !speech_view_)
if (!speech_view_)
return;
bool recognizing = (new_state == SPEECH_RECOGNITION_RECOGNIZING ||
......
......@@ -30,8 +30,6 @@ class AppListViewDelegate;
class AppListViewObserver;
class HideViewAnimationObserver;
class PaginationModel;
class SigninDelegate;
class SigninView;
class SpeechView;
// AppListView is the top-level view and controller of app list UI. It creates
......@@ -151,12 +149,9 @@ class APP_LIST_EXPORT AppListView : public views::BubbleDelegateView,
virtual void OnSpeechRecognitionStateChanged(
SpeechRecognitionState new_state) OVERRIDE;
SigninDelegate* GetSigninDelegate();
scoped_ptr<AppListViewDelegate> delegate_;
AppListMainView* app_list_main_view_;
SigninView* signin_view_;
SpeechView* speech_view_;
// A semi-transparent white overlay that covers the app list while dialogs are
......
// 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 "ui/app_list/views/signin_view.h"
#include "ui/app_list/signin_delegate.h"
#include "ui/gfx/font_list.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/layout/grid_layout.h"
namespace {
const int kTopPadding = 40;
const int kBottomPadding = 40;
const int kLeftPadding = 40;
const int kRightPadding = 40;
const int kHeadingPadding = 30;
const int kButtonPadding = 40;
const int kTitleFontSize = 18;
const int kTextFontSize = 13;
const int kButtonFontSize = 12;
} // namespace
namespace app_list {
SigninView::SigninView(SigninDelegate* delegate, int width)
: delegate_(delegate) {
if (!delegate_)
return;
const gfx::FontList base_font_list;
const gfx::FontList& title_font_list = base_font_list.DeriveWithSizeDelta(
kTitleFontSize - base_font_list.GetFontSize());
const gfx::FontList& text_font_list = base_font_list.DeriveWithSizeDelta(
kTextFontSize - base_font_list.GetFontSize());
const gfx::FontList& button_font_list = base_font_list.DeriveWithSizeDelta(
kButtonFontSize - base_font_list.GetFontSize());
int title_descender =
title_font_list.GetHeight() - title_font_list.GetBaseline();
int text_descender =
text_font_list.GetHeight() - text_font_list.GetBaseline();
views::GridLayout* layout = new views::GridLayout(this);
layout->SetInsets(kTopPadding, kLeftPadding, kBottomPadding - text_descender,
kRightPadding);
SetLayoutManager(layout);
const int kNormalSetId = 0;
views::ColumnSet* columns = layout->AddColumnSet(kNormalSetId);
columns->AddColumn(views::GridLayout::FILL,
views::GridLayout::FILL,
1,
views::GridLayout::USE_PREF,
0,
0);
const int kButtonSetId = 1;
columns = layout->AddColumnSet(kButtonSetId);
columns->AddColumn(views::GridLayout::LEADING,
views::GridLayout::FILL,
1,
views::GridLayout::USE_PREF,
0,
0);
views::Label* heading = new views::Label(delegate_->GetSigninHeading());
heading->SetFontList(title_font_list);
heading->SetHorizontalAlignment(gfx::ALIGN_LEFT);
layout->StartRow(0, kNormalSetId);
layout->AddView(heading);
views::Label* text = new views::Label(delegate_->GetSigninText());
text->SetFontList(text_font_list);
text->SetMultiLine(true);
text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
layout->StartRowWithPadding(0, kNormalSetId, 0,
kHeadingPadding - title_descender);
layout->AddView(text);
views::BlueButton* signin_button = new views::BlueButton(
this,
delegate_->GetSigninButtonText());
signin_button->SetFontList(button_font_list);
layout->StartRowWithPadding(0, kButtonSetId, 0,
kButtonPadding - text_descender);
layout->AddView(signin_button);
layout->StartRow(1, kNormalSetId);
learn_more_link_ = new views::Link(delegate_->GetLearnMoreLinkText());
learn_more_link_->set_listener(this);
learn_more_link_->SetFontList(text_font_list);
learn_more_link_->SetUnderline(false);
layout->AddView(learn_more_link_,
1,
1,
views::GridLayout::LEADING,
views::GridLayout::TRAILING);
layout->StartRow(0, kNormalSetId);
settings_link_ = new views::Link(delegate_->GetSettingsLinkText());
settings_link_->set_listener(this);
settings_link_->SetFontList(text_font_list);
settings_link_->SetUnderline(false);
layout->AddView(settings_link_,
1,
1,
views::GridLayout::LEADING,
views::GridLayout::TRAILING);
}
SigninView::~SigninView() {
}
void SigninView::ButtonPressed(views::Button* sender, const ui::Event& event) {
if (delegate_)
delegate_->ShowSignin();
}
void SigninView::LinkClicked(views::Link* source, int event_flags) {
if (delegate_) {
if (source == learn_more_link_)
delegate_->OpenLearnMore();
else if (source == settings_link_)
delegate_->OpenSettings();
else
NOTREACHED();
}
}
} // namespace app_list
// 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.
#ifndef UI_APP_LIST_VIEWS_SIGNIN_VIEW_H_
#define UI_APP_LIST_VIEWS_SIGNIN_VIEW_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/view.h"
namespace app_list {
class SigninDelegate;
// The SigninView is shown in the app list when the user needs to sign in.
class SigninView : public views::View,
public views::ButtonListener,
public views::LinkListener {
public:
SigninView(SigninDelegate* delegate, int width);
virtual ~SigninView();
private:
// views::ButtonListener overrides:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// views::LinkListener overrides:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
views::Link* learn_more_link_;
views::Link* settings_link_;
SigninDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(SigninView);
};
} // namespace app_list
#endif // UI_APP_LIST_VIEWS_SIGNIN_VIEW_H_
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