Skip to content

Commit

Permalink
Windows and notifications are hidden during first-run tutorial.
Browse files Browse the repository at this point in the history
Windows are hidden by hiding kShellWindowId_DefaultContainer and
kShellWindowId_AlwaysOnTopContainer.
NotificationBlocker used for hiding notifications.

BUG=269286
TEST=ash_unittests --gtest_filter=FirstRunHelperTest*

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240436 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dzhioev@chromium.org committed Dec 12, 2013
1 parent 1cbf5e5 commit a5c7880
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 24 deletions.
5 changes: 5 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
'drag_drop/drag_image_view.cc',
'drag_drop/drag_image_view.h',
'event_rewriter_delegate.h',
'first_run/desktop_cleaner.cc',
'first_run/desktop_cleaner.h',
'first_run/first_run_helper.cc',
'first_run/first_run_helper.h',
'first_run/first_run_helper_impl.cc',
Expand Down Expand Up @@ -909,6 +911,9 @@
'dependencies': [
'../chromeos/chromeos.gyp:power_manager_proto',
],
'sources': [
'first_run/first_run_helper_unittest.cc',
],
}],
['OS=="linux" and component=="shared_library" and linux_use_tcmalloc==1', {
'dependencies': [
Expand Down
118 changes: 118 additions & 0 deletions ash/first_run/desktop_cleaner.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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 "ash/first_run/desktop_cleaner.h"

#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification_blocker.h"

namespace ash {
namespace internal {

namespace {

const int kContainerIdsToHide[] = {
kShellWindowId_DefaultContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_PanelContainer,
// TODO(dzhioev): uncomment this when issue with BrowserView::CanActivate
// will be fixed.
// kShellWindowId_SystemModalContainer
};

} // namespace

class ContainerHider : public aura::WindowObserver,
public ui::ImplicitAnimationObserver {
public:
explicit ContainerHider(aura::Window* container)
: container_was_hidden_(!container->IsVisible()),
container_(container) {
if (container_was_hidden_)
return;
ui::Layer* layer = container_->layer();
ui::ScopedLayerAnimationSettings animation_settings(layer->GetAnimator());
animation_settings.AddObserver(this);
layer->SetOpacity(0.0);
}

virtual ~ContainerHider() {
if (container_was_hidden_ || !container_)
return;
if (!WasAnimationCompletedForProperty(ui::LayerAnimationElement::OPACITY)) {
// We are in the middle of animation.
StopObservingImplicitAnimations();
} else {
container_->Show();
}
ui::Layer* layer = container_->layer();
ui::ScopedLayerAnimationSettings animation_settings(layer->GetAnimator());
layer->SetOpacity(1.0);
}

private:
// Overriden from ui::ImplicitAnimationObserver.
virtual void OnImplicitAnimationsCompleted() OVERRIDE {
container_->Hide();
}

// Overriden from aura::WindowObserver.
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
DCHECK(window == container_);
container_ = NULL;
}

const bool container_was_hidden_;
aura::Window* container_;

DISALLOW_COPY_AND_ASSIGN(ContainerHider);
};

class NotificationBlocker : public message_center::NotificationBlocker {
public:
NotificationBlocker()
: message_center::NotificationBlocker(
message_center::MessageCenter::Get()) {
NotifyBlockingStateChanged();
}

virtual ~NotificationBlocker() {};

private:
// Overriden from message_center::NotificationBlocker.
virtual bool ShouldShowNotificationAsPopup(
const message_center::NotifierId& notifier_id) const OVERRIDE {
return false;
}

DISALLOW_COPY_AND_ASSIGN(NotificationBlocker);
};

DesktopCleaner::DesktopCleaner() {
// TODO(dzhioev): Add support for secondary displays.
aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
for (size_t i = 0; i < arraysize(kContainerIdsToHide); ++i) {
aura::Window* container =
Shell::GetContainer(root_window, kContainerIdsToHide[i]);
container_hiders_.push_back(make_linked_ptr(new ContainerHider(container)));
}
notification_blocker_.reset(new NotificationBlocker());
}

DesktopCleaner::~DesktopCleaner() {}

// static
std::vector<int> DesktopCleaner::GetContainersToHideForTest() {
return std::vector<int>(kContainerIdsToHide,
kContainerIdsToHide + arraysize(kContainerIdsToHide));
}

} // namespace internal
} // namespace ash

46 changes: 46 additions & 0 deletions ash/first_run/desktop_cleaner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 ASH_FIRST_RUN_DESKTOP_CLEANER_
#define ASH_FIRST_RUN_DESKTOP_CLEANER_

#include <vector>

#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"

namespace ash {

namespace test {
class FirstRunHelperTest;
}

namespace internal {

class ContainerHider;
class NotificationBlocker;

// Class used to "clean" ash desktop, i.e. hide all windows and notifications.
class ASH_EXPORT DesktopCleaner {
public:
DesktopCleaner();
~DesktopCleaner();

private:
// Returns the list of containers that DesctopCleaner hides.
static std::vector<int> GetContainersToHideForTest();

std::vector<linked_ptr<ContainerHider> > container_hiders_;
scoped_ptr<NotificationBlocker> notification_blocker_;

friend class ash::test::FirstRunHelperTest;
DISALLOW_COPY_AND_ASSIGN(DesktopCleaner);
};

} // namespace internal
} // namespace ash

#endif // ASH_FIRST_RUN_DESKTOP_CLEANER_
8 changes: 8 additions & 0 deletions ash/first_run/first_run_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ namespace ash {
FirstRunHelper::FirstRunHelper() {}
FirstRunHelper::~FirstRunHelper() {}

void FirstRunHelper::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}

void FirstRunHelper::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}

} // namespace chromeos

17 changes: 17 additions & 0 deletions ash/first_run/first_run_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/observer_list.h"

namespace gfx {
class Rect;
Expand All @@ -22,10 +23,21 @@ namespace ash {
// about shell elements.
// All returned coordinates are in screen coordinate system.
class ASH_EXPORT FirstRunHelper {
public:
class Observer {
public:
// Called when first-run UI was cancelled.
virtual void OnCancelled() = 0;
virtual ~Observer() {}
};

public:
FirstRunHelper();
virtual ~FirstRunHelper();

void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);

// Returns widget to place tutorial UI into it.
virtual views::Widget* GetOverlayWidget() = 0;

Expand Down Expand Up @@ -58,7 +70,12 @@ class ASH_EXPORT FirstRunHelper {
// bubble before calling this method.
virtual gfx::Rect GetHelpButtonBounds() = 0;

protected:
ObserverList<Observer>& observers() { return observers_; }

private:
ObserverList<Observer> observers_;

DISALLOW_COPY_AND_ASSIGN(FirstRunHelper);
};

Expand Down
6 changes: 4 additions & 2 deletions ash/first_run/first_run_helper_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ FirstRunHelperImpl::FirstRunHelperImpl()

FirstRunHelperImpl::~FirstRunHelperImpl() {
Shell::GetInstance()->overlay_filter()->Deactivate();
if (IsTrayBubbleOpened())
CloseTrayBubble();
widget_->Close();
}

Expand Down Expand Up @@ -78,11 +80,11 @@ gfx::Rect FirstRunHelperImpl::GetAppListBounds() {
}

void FirstRunHelperImpl::Cancel() {
NOTIMPLEMENTED();
FOR_EACH_OBSERVER(Observer, observers(), OnCancelled());
}

bool FirstRunHelperImpl::IsCancelingKeyEvent(ui::KeyEvent* event) {
return false;
return event->key_code() == ui::VKEY_ESCAPE;
}

aura::Window* FirstRunHelperImpl::GetWindow() {
Expand Down
2 changes: 2 additions & 0 deletions ash/first_run/first_run_helper_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ASH_FIRST_RUN_FIRST_RUN_HELPER_IMPL_H_

#include "ash/first_run/first_run_helper.h"
#include "ash/first_run/desktop_cleaner.h"
#include "ash/wm/overlay_event_filter.h"
#include "base/compiler_specific.h"

Expand Down Expand Up @@ -39,6 +40,7 @@ class FirstRunHelperImpl : public FirstRunHelper,

private:
views::Widget* widget_;
internal::DesktopCleaner cleaner_;

DISALLOW_COPY_AND_ASSIGN(FirstRunHelperImpl);
};
Expand Down
Loading

0 comments on commit a5c7880

Please sign in to comment.