diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 17:15:27 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 17:15:27 +0000 |
commit | e1272045536e5261a8d5565d1eed08b32f8314cf (patch) | |
tree | 353af8a696d12111b6884cfa55983750149ed780 /ash | |
parent | 46629cefcccebe73fec85422ebd40beeae2b1515 (diff) | |
download | chromium_src-e1272045536e5261a8d5565d1eed08b32f8314cf.zip chromium_src-e1272045536e5261a8d5565d1eed08b32f8314cf.tar.gz chromium_src-e1272045536e5261a8d5565d1eed08b32f8314cf.tar.bz2 |
Move avatar holder img/code to ash
Removed GetLoggedInUsers method that is no longer used.
I'm planning to move frame related code to ash/frame (such as custom_frame_view_ash, caption).
BUG=338782
Review URL: https://codereview.chromium.org/197773004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/frame/frame_util.cc | 35 | ||||
-rw-r--r-- | ash/frame/frame_util.h | 28 | ||||
-rw-r--r-- | ash/resources/ash_resources.grd | 2 | ||||
-rw-r--r-- | ash/session_state_delegate.h | 20 | ||||
-rw-r--r-- | ash/session_state_delegate_stub.cc | 11 | ||||
-rw-r--r-- | ash/session_state_delegate_stub.h | 6 | ||||
-rw-r--r-- | ash/system/user/tray_user.cc | 18 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.cc | 11 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.h | 6 |
10 files changed, 118 insertions, 21 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 7d8688f..19cf0b7 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -175,6 +175,8 @@ 'frame/custom_frame_view_ash.h', 'frame/frame_border_hit_test_controller.cc', 'frame/frame_border_hit_test_controller.h', + 'frame/frame_util.cc', + 'frame/frame_util.h', 'frame/header_painter.cc', 'frame/header_painter.h', 'gpu_support.h', diff --git a/ash/frame/frame_util.cc b/ash/frame/frame_util.cc new file mode 100644 index 0000000..bfa8c33 --- /dev/null +++ b/ash/frame/frame_util.cc @@ -0,0 +1,35 @@ +// Copyright 2014 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 "ash/frame/frame_util.h" + +#include "ash/session_state_delegate.h" +#include "ash/shell.h" +#include "grit/ash_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/image/image_skia_operations.h" + +namespace ash { + +gfx::Image GetAvatarImageForContext(content::BrowserContext* context) { + static const gfx::ImageSkia* holder = + ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( + IDR_AVATAR_HOLDER); + static const gfx::ImageSkia* holder_mask = + ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( + IDR_AVATAR_HOLDER_MASK); + gfx::ImageSkia user_image = + Shell::GetInstance()->session_state_delegate()->GetUserImage(context); + gfx::ImageSkia resized = gfx::ImageSkiaOperations::CreateResizedImage( + user_image, skia::ImageOperations::RESIZE_BEST, holder->size()); + gfx::ImageSkia masked = + gfx::ImageSkiaOperations::CreateMaskedImage(resized, *holder_mask); + gfx::ImageSkia result = + gfx::ImageSkiaOperations::CreateSuperimposedImage(*holder, masked); + return gfx::Image(result); +} + +} // namespace ash + diff --git a/ash/frame/frame_util.h b/ash/frame/frame_util.h new file mode 100644 index 0000000..ef8e0c4 --- /dev/null +++ b/ash/frame/frame_util.h @@ -0,0 +1,28 @@ +// Copyright 2014 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 ASH_FRAME_FRAME_UTIL_H_ +#define ASH_FRAME_FRAME_UTIL_H_ + +#include "ash/ash_export.h" + +namespace content { +class BrowserContext; +} + +namespace gfx { +class Image; +} + +namespace ash { + +// Returns the avatar image to be used in the title bar +// for the user associated witht the |context|. +ASH_EXPORT gfx::Image GetAvatarImageForContext( + content::BrowserContext* context); + +} // namespace ash + +#endif // ASH_FRAME_FRAME_UTIL_H_ + diff --git a/ash/resources/ash_resources.grd b/ash/resources/ash_resources.grd index 312ad06..1a051da 100644 --- a/ash/resources/ash_resources.grd +++ b/ash/resources/ash_resources.grd @@ -279,6 +279,8 @@ <structure type="chrome_scaled_image" name="IDR_AURA_WINDOW_POSITION_RIGHT_RESTORE" file="common/window_position_right_normal_restore.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_WINDOW_POSITION_RIGHT_RESTORE_H" file="common/window_position_right_hover_restore.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_WINDOW_POSITION_RIGHT_RESTORE_P" file="common/window_position_right_pressed_restore.png" /> + <structure type="chrome_scaled_image" name="IDR_AVATAR_HOLDER" file="cros/avatar_holder.png" /> + <structure type="chrome_scaled_image" name="IDR_AVATAR_HOLDER_MASK" file="cros/avatar_holder_mask.png" /> </structures> </release> </grit> diff --git a/ash/session_state_delegate.h b/ash/session_state_delegate.h index 31e34c9..4df1617 100644 --- a/ash/session_state_delegate.h +++ b/ash/session_state_delegate.h @@ -15,6 +15,10 @@ namespace aura { class Window; } // namespace aura +namespace content { +class BrowserContext; +} + namespace gfx { class ImageSkia; } // namespace gfx @@ -31,6 +35,8 @@ typedef int MultiProfileIndex; typedef std::vector<std::string> UserIdList; // Delegate for checking and modifying the session state. +// TODO(oshima): Replace MultiProfileIndex with BrowsreContext, bacause +// GetUserXXX are useful for non multi profile scenario in ash_shell. class ASH_EXPORT SessionStateDelegate { public: // Defines the cycle direction for |CycleActiveUser|. @@ -41,6 +47,10 @@ class ASH_EXPORT SessionStateDelegate { virtual ~SessionStateDelegate() {}; + // Returns the browser context for the user given by |index|. + virtual content::BrowserContext* GetBrowserContextByIndex( + MultiProfileIndex index) = 0; + // Returns the maximum possible number of logged in users. virtual int GetMaximumNumberOfLoggedInUsers() const = 0; @@ -91,12 +101,12 @@ class ASH_EXPORT SessionStateDelegate { // Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|. virtual const std::string GetUserID(MultiProfileIndex index) const = 0; - // Gets the avatar image for the user with the given |index|. - // Note that |index| can at maximum be |NumberOfLoggedInUsers() - 1|. - virtual const gfx::ImageSkia& GetUserImage(MultiProfileIndex index) const = 0; + // Gets the avatar image for the user associated with the |context|. + virtual const gfx::ImageSkia& GetUserImage( + content::BrowserContext* context) const = 0; - // Returns a list of all logged in users. - virtual void GetLoggedInUsers(UserIdList* users) = 0; + // Whether or not the window's title should show the avatar. + virtual bool ShouldShowAvatar(aura::Window* window) = 0; // Switches to another active user with |user_id| // (if that user has already signed in). diff --git a/ash/session_state_delegate_stub.cc b/ash/session_state_delegate_stub.cc index fea3a56..7fc01da 100644 --- a/ash/session_state_delegate_stub.cc +++ b/ash/session_state_delegate_stub.cc @@ -17,6 +17,12 @@ SessionStateDelegateStub::SessionStateDelegateStub() : screen_locked_(false) { SessionStateDelegateStub::~SessionStateDelegateStub() { } +content::BrowserContext* +SessionStateDelegateStub::GetBrowserContextByIndex( + MultiProfileIndex index) { + return NULL; +} + int SessionStateDelegateStub::GetMaximumNumberOfLoggedInUsers() const { return 3; } @@ -72,11 +78,12 @@ const std::string SessionStateDelegateStub::GetUserID( } const gfx::ImageSkia& SessionStateDelegateStub::GetUserImage( - MultiProfileIndex index) const { + content::BrowserContext* context) const { return null_image_; } -void SessionStateDelegateStub::GetLoggedInUsers(UserIdList* users) { +bool SessionStateDelegateStub::ShouldShowAvatar(aura::Window* window) { + return false; } void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { diff --git a/ash/session_state_delegate_stub.h b/ash/session_state_delegate_stub.h index 4a11833..8c27e9a 100644 --- a/ash/session_state_delegate_stub.h +++ b/ash/session_state_delegate_stub.h @@ -19,6 +19,8 @@ class SessionStateDelegateStub : public SessionStateDelegate { virtual ~SessionStateDelegateStub(); // SessionStateDelegate: + virtual content::BrowserContext* GetBrowserContextByIndex( + MultiProfileIndex index) OVERRIDE; virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE; virtual int NumberOfLoggedInUsers() const OVERRIDE; virtual bool IsActiveUserSessionStarted() const OVERRIDE; @@ -35,8 +37,8 @@ class SessionStateDelegateStub : public SessionStateDelegate { virtual const std::string GetUserID( ash::MultiProfileIndex index) const OVERRIDE; virtual const gfx::ImageSkia& GetUserImage( - ash::MultiProfileIndex index) const OVERRIDE; - virtual void GetLoggedInUsers(UserIdList* users) OVERRIDE; + content::BrowserContext* context) const OVERRIDE; + virtual bool ShouldShowAvatar(aura::Window* window) OVERRIDE; virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; virtual void CycleActiveUser(CycleUser cycle_user) OVERRIDE; virtual void AddSessionStateObserver( diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc index bd01bbe..8384b9e5 100644 --- a/ash/system/user/tray_user.cc +++ b/ash/system/user/tray_user.cc @@ -921,10 +921,12 @@ views::View* UserView::CreateIconForUserCard(user::LoginStatus login) { GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), gfx::Size(kUserIconSize, kUserIconSize)); } else { - icon->SetImage( - Shell::GetInstance()->session_state_delegate()-> - GetUserImage(multiprofile_index_), - gfx::Size(kUserIconSize, kUserIconSize)); + SessionStateDelegate* delegate = + Shell::GetInstance()->session_state_delegate(); + content::BrowserContext* context = delegate->GetBrowserContextByIndex( + multiprofile_index_); + icon->SetImage(delegate->GetUserImage(context), + gfx::Size(kUserIconSize, kUserIconSize)); } return icon; } @@ -1332,10 +1334,10 @@ void TrayUser::UpdateAvatarImage(user::LoginStatus status) { int icon_size = switches::UseAlternateShelfLayout() ? kUserIconLargeSize : kUserIconSize; - avatar_->SetImage( - Shell::GetInstance()->session_state_delegate()->GetUserImage( - GetTrayIndex()), - gfx::Size(icon_size, icon_size)); + content::BrowserContext* context = session_state_delegate-> + GetBrowserContextByIndex(GetTrayIndex()); + avatar_->SetImage(session_state_delegate->GetUserImage(context), + gfx::Size(icon_size, icon_size)); // Unit tests might come here with no images for some users. if (avatar_->size().IsEmpty()) diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc index e1085c0..722981f 100644 --- a/ash/test/test_session_state_delegate.cc +++ b/ash/test/test_session_state_delegate.cc @@ -40,6 +40,12 @@ TestSessionStateDelegate::TestSessionStateDelegate() TestSessionStateDelegate::~TestSessionStateDelegate() { } +content::BrowserContext* +TestSessionStateDelegate::GetBrowserContextByIndex( + MultiProfileIndex index) { + return NULL; +} + int TestSessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const { return 3; } @@ -133,11 +139,12 @@ const std::string TestSessionStateDelegate::GetUserID( } const gfx::ImageSkia& TestSessionStateDelegate::GetUserImage( - MultiProfileIndex index) const { + content::BrowserContext* context) const { return null_image_; } -void TestSessionStateDelegate::GetLoggedInUsers(UserIdList* users) { +bool TestSessionStateDelegate::ShouldShowAvatar(aura::Window* window) { + return false; } void TestSessionStateDelegate::SwitchActiveUser(const std::string& user_id) { diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h index 1277a068..21c34f6 100644 --- a/ash/test/test_session_state_delegate.h +++ b/ash/test/test_session_state_delegate.h @@ -22,6 +22,8 @@ class TestSessionStateDelegate : public SessionStateDelegate { const std::string& get_activated_user() { return activated_user_; } // SessionStateDelegate: + virtual content::BrowserContext* GetBrowserContextByIndex( + MultiProfileIndex index) OVERRIDE; virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE; virtual int NumberOfLoggedInUsers() const OVERRIDE; virtual bool IsActiveUserSessionStarted() const OVERRIDE; @@ -38,8 +40,8 @@ class TestSessionStateDelegate : public SessionStateDelegate { virtual const std::string GetUserID( ash::MultiProfileIndex index) const OVERRIDE; virtual const gfx::ImageSkia& GetUserImage( - ash::MultiProfileIndex index) const OVERRIDE; - virtual void GetLoggedInUsers(UserIdList* users) OVERRIDE; + content::BrowserContext* context) const OVERRIDE; + virtual bool ShouldShowAvatar(aura::Window* window) OVERRIDE; virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; virtual void CycleActiveUser(CycleUser cycle_user) OVERRIDE; virtual void AddSessionStateObserver( |