Skip to content

Commit

Permalink
ash: Display system background while loading wallpaper.
Browse files Browse the repository at this point in the history
When the wallpaper takes a long time to load, areas of the
screen that aren't covered by other layers are painted
white.  This looks okay when we first boot, but not when
we're displaying the login after logging out or while we're
starting a guest session.

This makes us instead initialize SystemBackgroundController
immediately with either a #fefefe or black color depending
on whether this is the first Chrome run after boot or not.
Its color is updated to black after the login wallpaper
animation is finished.

BUG=151111,152751


Review URL: https://chromiumcodereview.appspot.com/11054005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159822 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
derat@chromium.org committed Oct 3, 2012
1 parent abd82e6 commit 697f04c
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 39 deletions.
2 changes: 2 additions & 0 deletions ash/desktop_background/desktop_background_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/desktop_background/desktop_background_view.h"
#include "ash/desktop_background/desktop_background_widget_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
Expand Down Expand Up @@ -277,6 +278,7 @@ void DesktopBackgroundController::OnWallpaperLoadCompleted(

void DesktopBackgroundController::NotifyAnimationFinished() {
Shell* shell = Shell::GetInstance();
shell->GetPrimaryRootWindowController()->HandleDesktopBackgroundVisible();
shell->user_wallpaper_delegate()->OnWallpaperAnimationFinished();
}

Expand Down
2 changes: 2 additions & 0 deletions ash/desktop_background/desktop_background_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ash/ash_export.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/desktop_background/desktop_background_widget_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_animations.h"
Expand Down Expand Up @@ -47,6 +48,7 @@ class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver,
// Overridden from ui::ImplicitAnimationObserver:
virtual void OnImplicitAnimationsCompleted() OVERRIDE {
ash::Shell* shell = ash::Shell::GetInstance();
shell->GetPrimaryRootWindowController()->HandleDesktopBackgroundVisible();
shell->user_wallpaper_delegate()->OnWallpaperAnimationFinished();
// Only removes old component when wallpaper animation finished. If we
// remove the old one too early, there will be a white flash during
Expand Down
22 changes: 22 additions & 0 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ash/wm/toplevel_window_event_handler.h"
#include "ash/wm/visibility_controller.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/workspace/system_background_controller.h"
#include "ash/wm/workspace_controller.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/aura_constants.h"
Expand All @@ -37,6 +38,12 @@
namespace ash {
namespace {

#if defined(OS_CHROMEOS)
// Color initially used for the system background after the system has first
// booted.
const SkColor kBootSystemBackgroundColor = 0xFFFEFEFE;
#endif

// Creates a new window for use as a container.
aura::Window* CreateContainer(int window_id,
const char* name,
Expand Down Expand Up @@ -189,6 +196,21 @@ void RootWindowController::CreateContainers() {
CreateContainersInRootWindow(root_window_.get());
}

void RootWindowController::CreateSystemBackground(
bool is_first_run_after_boot) {
SkColor color = SK_ColorBLACK;
#if defined(OS_CHROMEOS)
if (is_first_run_after_boot)
color = kBootSystemBackgroundColor;
#endif
background_.reset(new SystemBackgroundController(root_window_.get(), color));
}

void RootWindowController::HandleDesktopBackgroundVisible() {
if (background_.get())
background_->SetColor(SK_ColorBLACK);
}

void RootWindowController::CloseChildWindows() {
// Close background widget first as it depends on tooltip.
root_window_->SetProperty(kWindowDesktopComponent,
Expand Down
16 changes: 15 additions & 1 deletion ash/root_window_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace internal {
class EventClientImpl;
class RootWindowLayoutManager;
class ScreenDimmer;
class SystemBackgroundController;
class WorkspaceController;

// This class maintains the per root window state for ash. This class
Expand Down Expand Up @@ -57,8 +58,15 @@ class RootWindowController {

aura::Window* GetContainer(int container_id);

void CreateContainers();
void InitLayoutManagers();
void CreateContainers();

// Initializes |background_|. |is_first_run_after_boot| determines the
// background's initial color.
void CreateSystemBackground(bool is_first_run_after_boot);

// Updates |background_| to be black after the desktop background is visible.
void HandleDesktopBackgroundVisible();

// Deletes associated objects and clears the state, but doesn't delete
// the root window yet. This is used to delete a secondary displays'
Expand All @@ -83,6 +91,12 @@ class RootWindowController {
scoped_ptr<aura::RootWindow> root_window_;
internal::RootWindowLayoutManager* root_window_layout_;

// A background layer that's displayed beneath all other layers. Without
// this, portions of the root window that aren't covered by layers will be
// painted white; this can show up if e.g. it takes a long time to decode the
// desktop background image when displaying the login screen.
scoped_ptr<SystemBackgroundController> background_;

// An event filter that pre-handles all key events to send them to an IME.
scoped_ptr<internal::EventClientImpl> event_client_;
scoped_ptr<internal::ScreenDimmer> screen_dimmer_;
Expand Down
2 changes: 2 additions & 0 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ void Shell::Init() {
internal::RootWindowController* root_window_controller =
new internal::RootWindowController(root_window);
root_window_controller->CreateContainers();
root_window_controller->CreateSystemBackground(
delegate_.get() ? delegate_->IsFirstRunAfterBoot() : false);

CommandLine* command_line = CommandLine::ForCurrentProcess();

Expand Down
4 changes: 4 additions & 0 deletions ash/shell/shell_delegate_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ bool ShellDelegateImpl::IsSessionStarted() {
return true;
}

bool ShellDelegateImpl::IsFirstRunAfterBoot() {
return false;
}

void ShellDelegateImpl::LockScreen() {
ash::shell::CreateLockScreen();
locked_ = true;
Expand Down
1 change: 1 addition & 0 deletions ash/shell/shell_delegate_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ShellDelegateImpl : public ash::ShellDelegate {

virtual bool IsUserLoggedIn() OVERRIDE;
virtual bool IsSessionStarted() OVERRIDE;
virtual bool IsFirstRunAfterBoot() OVERRIDE;
virtual void LockScreen() OVERRIDE;
virtual void UnlockScreen() OVERRIDE;
virtual bool IsScreenLocked() const OVERRIDE;
Expand Down
5 changes: 5 additions & 0 deletions ash/shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class ASH_EXPORT ShellDelegate {
// Returns true if we're logged in and browser has been started
virtual bool IsSessionStarted() = 0;

// Returns true if this is the first time that the shell has been run after
// the system has booted. false is returned after the shell has been
// restarted, typically due to logging in as a guest or logging out.
virtual bool IsFirstRunAfterBoot() = 0;

// Invoked when a user locks the screen.
virtual void LockScreen() = 0;

Expand Down
7 changes: 4 additions & 3 deletions ash/shell_window_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const int kShellWindowId_LockScreenRelatedContainersContainer = 2;
const int kShellWindowId_UnparentedControlContainer = 3;

// System level background. Sits beneach the desktop background and is only
// visible when in a workspace other than the desktop. When switching from the
// desktop workspace to to another workspace the desktop background scales
// slightly. This exposes the system level background beneath it.
// visible when the desktop background has not yet been loaded or a workspace
// other than the desktop is being displayed. When switching from the desktop
// workspace to to another workspace the desktop background scales slightly.
// This exposes the system level background beneath it.
const int kShellWindowId_SystemBackgroundContainer = 4;

// The desktop background window.
Expand Down
4 changes: 4 additions & 0 deletions ash/test/test_shell_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ bool TestShellDelegate::IsSessionStarted() {
return true;
}

bool TestShellDelegate::IsFirstRunAfterBoot() {
return false;
}

void TestShellDelegate::LockScreen() {
locked_ = true;
}
Expand Down
1 change: 1 addition & 0 deletions ash/test/test_shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestShellDelegate : public ShellDelegate {
// Overridden from ShellDelegate:
virtual bool IsUserLoggedIn() OVERRIDE;
virtual bool IsSessionStarted() OVERRIDE;
virtual bool IsFirstRunAfterBoot() OVERRIDE;
virtual void LockScreen() OVERRIDE;
virtual void UnlockScreen() OVERRIDE;
virtual bool IsScreenLocked() const OVERRIDE;
Expand Down
13 changes: 11 additions & 2 deletions ash/wm/workspace/system_background_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/wm/workspace/system_background_controller.h"

#include "ash/shell_window_ids.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/gfx/canvas.h"
#include "ui/views/widget/widget.h"
Expand Down Expand Up @@ -49,7 +50,8 @@ views::View* SystemBackgroundController::View::GetContentsView() {
return this;
}

SystemBackgroundController::SystemBackgroundController(aura::RootWindow* root)
SystemBackgroundController::SystemBackgroundController(aura::RootWindow* root,
SkColor color)
: ALLOW_THIS_IN_INITIALIZER_LIST(view_(new View(this))) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(
Expand All @@ -62,7 +64,9 @@ SystemBackgroundController::SystemBackgroundController(aura::RootWindow* root)
// flicker.
params.layer_type = ui::LAYER_SOLID_COLOR;
widget->Init(params);
widget->GetNativeView()->layer()->SetColor(SK_ColorBLACK);
widget->GetNativeView()->SetProperty(aura::client::kAnimationsDisabledKey,
true);
widget->GetNativeView()->layer()->SetColor(color);
widget->SetBounds(params.parent->bounds());
widget->Show();
widget->GetNativeView()->SetName("SystemBackground");
Expand All @@ -73,5 +77,10 @@ SystemBackgroundController::~SystemBackgroundController() {
view_->Close();
}

void SystemBackgroundController::SetColor(SkColor color) {
if (view_)
view_->GetWidget()->GetNativeView()->layer()->SetColor(color);
}

} // namespace internal
} // namespace ash
7 changes: 6 additions & 1 deletion ash/wm/workspace/system_background_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "ash/ash_export.h"
#include "base/basictypes.h"

typedef unsigned int SkColor;

namespace aura {
class RootWindow;
};
Expand All @@ -20,9 +22,12 @@ namespace internal {
// level background.
class ASH_EXPORT SystemBackgroundController {
public:
explicit SystemBackgroundController(aura::RootWindow* root);
SystemBackgroundController(aura::RootWindow* root, SkColor color);
~SystemBackgroundController();

// Changes the background color.
void SetColor(SkColor color);

private:
class View;

Expand Down
20 changes: 0 additions & 20 deletions ash/wm/workspace/workspace_manager2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "ash/wm/window_animations.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/system_background_controller.h"
#include "ash/wm/workspace/workspace_layout_manager2.h"
#include "ash/wm/workspace/workspace2.h"
#include "base/auto_reset.h"
Expand Down Expand Up @@ -331,21 +330,6 @@ void WorkspaceManager2::SetActiveWorkspace(Workspace2* workspace,
contents_view_->StackChildAtTop(last_active->window());
}

destroy_background_timer_.Stop();
if (active_workspace_ == desktop_workspace()) {
base::TimeDelta delay(GetSystemBackgroundDestroyDuration());
if (ui::LayerAnimator::slow_animation_mode())
delay *= ui::LayerAnimator::slow_animation_scale_factor();
// Delay an extra 100ms to make sure everything settles down before
// destroying the background.
delay += base::TimeDelta::FromMilliseconds(100);
destroy_background_timer_.Start(
FROM_HERE, delay, this, &WorkspaceManager2::DestroySystemBackground);
} else if (!background_controller_.get()) {
background_controller_.reset(new SystemBackgroundController(
contents_view_->GetRootWindow()));
}

UpdateShelfVisibility();

if (animate_type != ANIMATE_NONE) {
Expand Down Expand Up @@ -456,10 +440,6 @@ void WorkspaceManager2::ScheduleDelete(Workspace2* workspace) {
&WorkspaceManager2::ProcessDeletion);
}

void WorkspaceManager2::DestroySystemBackground() {
background_controller_.reset();
}

void WorkspaceManager2::SetUnminimizingWorkspace(Workspace2* workspace) {
// The normal sequence of unminimizing a window is: Show() the window, which
// triggers changing the kShowStateKey to NORMAL and lastly the window is made
Expand Down
12 changes: 0 additions & 12 deletions ash/wm/workspace/workspace_manager2.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace ash {
namespace internal {

class ShelfLayoutManager;
class SystemBackgroundController;
class WorkspaceLayoutManager2;
class WorkspaceManagerTest2;
class Workspace2;
Expand Down Expand Up @@ -139,9 +138,6 @@ class ASH_EXPORT WorkspaceManager2
// any layers.
void ProcessDeletion();

// Deletes |background_controller_|. Called from |destroy_background_timer_|.
void DestroySystemBackground();

// Sets |unminimizing_workspace_| to |workspace|.
void SetUnminimizingWorkspace(Workspace2* workspace);

Expand Down Expand Up @@ -198,14 +194,6 @@ class ASH_EXPORT WorkspaceManager2
// See comments in SetUnminimizingWorkspace() for details.
base::WeakPtrFactory<WorkspaceManager2> clear_unminimizing_workspace_factory_;

// Used to show the system level background. Non-null when the background is
// visible.
scoped_ptr<SystemBackgroundController> background_controller_;

// Timer used to destroy the background. We wait to destroy until animations
// complete.
base::OneShotTimer<WorkspaceManager2> destroy_background_timer_;

// See comments in SetUnminimizingWorkspace() for details.
Workspace2* unminimizing_workspace_;

Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/ui/ash/chrome_shell_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ bool ChromeShellDelegate::IsSessionStarted() {
#endif
}

bool ChromeShellDelegate::IsFirstRunAfterBoot() {
#if defined(OS_CHROMEOS)
return CommandLine::ForCurrentProcess()->HasSwitch(switches::kFirstBoot);
#else
return false;
#endif
}

void ChromeShellDelegate::LockScreen() {
#if defined(OS_CHROMEOS)
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession) &&
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/ash/chrome_shell_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ChromeShellDelegate : public ash::ShellDelegate,
// ash::ShellDelegate overrides;
virtual bool IsUserLoggedIn() OVERRIDE;
virtual bool IsSessionStarted() OVERRIDE;
virtual bool IsFirstRunAfterBoot() OVERRIDE;
virtual void LockScreen() OVERRIDE;
virtual void UnlockScreen() OVERRIDE;
virtual bool IsScreenLocked() const OVERRIDE;
Expand Down

0 comments on commit 697f04c

Please sign in to comment.