Chromium Code Reviews| Index: ash/launcher/launcher.cc |
| diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc |
| index 3c1543fc7a1b6ff6c8eace28635456810666e041..58d8b56670f2ea4bad3195cfdec63f5b8df909ce 100644 |
| --- a/ash/launcher/launcher.cc |
| +++ b/ash/launcher/launcher.cc |
| @@ -11,23 +11,35 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_delegate.h" |
| #include "ash/shell_window_ids.h" |
| +#include "ash/wm/shelf_layout_manager.h" |
| +#include "base/timer.h" |
| #include "ui/aura/window.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/compositor/layer.h" |
| #include "ui/gfx/image/image.h" |
| #include "ui/views/accessible_pane_view.h" |
| -#include "ui/views/painter.h" |
| +#include "ui/views/background.h" |
| #include "ui/views/widget/widget.h" |
| #include "ui/views/widget/widget_delegate.h" |
| namespace ash { |
| +namespace { |
| + |
| +// Duration of the background animation. |
| +const int kBackgroundDurationMS = 1000; |
| + |
| +// Delay before showing the launcher after the mouse enters the view. |
| +const int kShowDelayMS = 300; |
| + |
| +} |
| + |
| // The contents view of the Widget. This view contains LauncherView and |
| // sizes it to the width of the widget minus the size of the status area. |
| class Launcher::DelegateView : public views::WidgetDelegate, |
| - public views::AccessiblePaneView { |
| + public views::AccessiblePaneView{ |
|
Ben Goodger (Google)
2012/03/21 05:16:50
you lost a space here
|
| public: |
| - explicit DelegateView(); |
| + explicit DelegateView(Launcher* launcher); |
| virtual ~DelegateView(); |
| void SetStatusWidth(int width); |
| @@ -40,16 +52,16 @@ class Launcher::DelegateView : public views::WidgetDelegate, |
| // views::View overrides |
| virtual gfx::Size GetPreferredSize() OVERRIDE; |
| virtual void Layout() OVERRIDE; |
| + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
| + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
| + // views::WidgetDelegateView overrides: |
| virtual views::Widget* GetWidget() OVERRIDE { |
| return View::GetWidget(); |
| } |
| - |
| virtual const views::Widget* GetWidget() const OVERRIDE { |
| return View::GetWidget(); |
| } |
| - |
| - // views::WidgetDelegateView overrides: |
| virtual bool CanActivate() const OVERRIDE { |
| // We don't want mouse clicks to activate us, but we need to allow |
| // activation when the user is using the keyboard (FocusCycler). |
| @@ -57,24 +69,31 @@ class Launcher::DelegateView : public views::WidgetDelegate, |
| } |
| private: |
| + // Shows the launcher. |
| + void ShowLauncher(); |
| + |
| + Launcher* launcher_; |
| + |
| + // Width of the status area. |
| int status_width_; |
| + |
| const internal::FocusCycler* focus_cycler_; |
| + base::OneShotTimer<DelegateView> show_timer_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(DelegateView); |
| }; |
| -Launcher::DelegateView::DelegateView() |
| - : status_width_(0), |
| +Launcher::DelegateView::DelegateView(Launcher* launcher) |
| + : launcher_(launcher), |
| + status_width_(0), |
| focus_cycler_(NULL) { |
| + set_notify_enter_exit_on_child(true); |
| } |
| Launcher::DelegateView::~DelegateView() { |
| } |
| -void Launcher::SetFocusCycler(const internal::FocusCycler* focus_cycler) { |
| - delegate_view_->set_focus_cycler(focus_cycler); |
| -} |
| - |
| void Launcher::DelegateView::SetStatusWidth(int width) { |
| if (status_width_ == width) |
| return; |
| @@ -93,11 +112,41 @@ void Launcher::DelegateView::Layout() { |
| child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height()); |
| } |
| +void Launcher::DelegateView::OnMouseEntered(const views::MouseEvent& event) { |
| + if (!show_timer_.IsRunning()) { |
| + // The user may be trying to target a button near the bottom of the screen |
| + // and accidentally moved into the launcher area. Delay showing. |
| + show_timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kShowDelayMS), |
| + this, &DelegateView::ShowLauncher); |
| + } |
| +} |
| + |
| +void Launcher::DelegateView::OnMouseExited(const views::MouseEvent& event) { |
| + show_timer_.Stop(); |
| + internal::ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); |
| + shelf->SetState(shelf->visibility_state(), |
| + internal::ShelfLayoutManager::AUTO_HIDE_HIDDEN); |
| +} |
| + |
| +void Launcher::DelegateView::ShowLauncher() { |
| + show_timer_.Stop(); |
| + internal::ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); |
| + shelf->SetState(shelf->visibility_state(), |
| + internal::ShelfLayoutManager::AUTO_HIDE_SHOWN); |
| +} |
| + |
| + |
| +// Launcher -------------------------------------------------------------------- |
| + |
| Launcher::Launcher(aura::Window* window_container) |
| : widget_(NULL), |
| window_container_(window_container), |
| delegate_view_(NULL), |
| - launcher_view_(NULL) { |
| + launcher_view_(NULL), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(background_animation_(this)), |
| + renders_background_(false), |
| + background_alpha_(0) { |
| model_.reset(new LauncherModel); |
| if (Shell::GetInstance()->delegate()) { |
| delegate_.reset( |
| @@ -114,7 +163,7 @@ Launcher::Launcher(aura::Window* window_container) |
| ash::internal::kShellWindowId_LauncherContainer); |
| launcher_view_ = new internal::LauncherView(model_.get(), delegate_.get()); |
| launcher_view_->Init(); |
| - delegate_view_ = new DelegateView; |
| + delegate_view_ = new DelegateView(this); |
| delegate_view_->AddChildView(launcher_view_); |
| params.delegate = delegate_view_; |
| widget_->Init(params); |
| @@ -127,11 +176,31 @@ Launcher::Launcher(aura::Window* window_container) |
| widget_->SetContentsView(delegate_view_); |
| widget_->Show(); |
| widget_->GetNativeView()->SetName("LauncherView"); |
| + background_animation_.SetSlideDuration(kBackgroundDurationMS); |
| } |
| Launcher::~Launcher() { |
| } |
| +void Launcher::SetFocusCycler(const internal::FocusCycler* focus_cycler) { |
| + delegate_view_->set_focus_cycler(focus_cycler); |
| +} |
| + |
| +void Launcher::SetRendersBackground(bool value, BackgroundChangeSpeed speed) { |
| + if (renders_background_ == value) |
| + return; |
| + renders_background_ = value; |
| + if (speed == CHANGE_IMMEDIATE && !background_animation_.is_animating()) { |
| + background_animation_.Reset(value ? 1.0f : 0.0f); |
| + AnimationProgressed(&background_animation_); |
| + return; |
| + } |
| + if (renders_background_) |
| + background_animation_.Show(); |
| + else |
| + background_animation_.Hide(); |
| +} |
| + |
| void Launcher::SetStatusWidth(int width) { |
| delegate_view_->SetStatusWidth(width); |
| } |
| @@ -161,4 +230,19 @@ internal::LauncherView* Launcher::GetLauncherViewForTest() { |
| return static_cast<internal::LauncherView*>( |
| widget_->GetContentsView()->child_at(0)); |
| } |
| + |
| +void Launcher::AnimationProgressed(const ui::Animation* animation) { |
| + int alpha = animation->CurrentValueBetween(0, 128); |
|
Ben Goodger (Google)
2012/03/21 05:16:50
kOnstant
|
| + if (background_alpha_ == alpha) |
| + return; |
| + background_alpha_ = alpha; |
| + if (alpha == 0) { |
| + delegate_view_->set_background(NULL); |
| + } else { |
| + delegate_view_->set_background( |
| + views::Background::CreateSolidBackground(0, 0, 0, alpha)); |
| + } |
| + delegate_view_->SchedulePaint(); |
| +} |
| + |
| } // namespace ash |