summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-29 18:01:23 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-29 18:01:23 +0000
commit403dc94ea7160dd133f262cf504e5a07ec1e50b6 (patch)
tree79741798b0f408e12d47eb4ebc5f15b6fe96c94f
parent38b80bbab9db5a423cace41e4e7757eb4f27806c (diff)
downloadchromium_src-403dc94ea7160dd133f262cf504e5a07ec1e50b6.zip
chromium_src-403dc94ea7160dd133f262cf504e5a07ec1e50b6.tar.gz
chromium_src-403dc94ea7160dd133f262cf504e5a07ec1e50b6.tar.bz2
Polish launcher tooltip visibility.
Add ShelfLayoutManager::Observer for two cases: - AutoHide: catches the auto hiding status to close the tooltip property - FullScreen: catches the shelf visibility changes to close it too Check the visibility of Shelf itself in case of tooltip showing. Then the toolip won't show if the shelf is hidden. R=derat@chromium.org,davemoore@chromium.org BUG=133551 TEST=manually done on lumpy, made sure aura_shell_unittests passed Review URL: https://chromiumcodereview.appspot.com/10700030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144930 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/launcher/launcher.cc6
-rw-r--r--ash/launcher/launcher.h4
-rw-r--r--ash/launcher/launcher_tooltip_manager.cc44
-rw-r--r--ash/launcher/launcher_tooltip_manager.h15
-rw-r--r--ash/launcher/launcher_view.cc6
-rw-r--r--ash/launcher/launcher_view.h5
-rw-r--r--ash/launcher/launcher_view_unittest.cc3
-rw-r--r--ash/shell.cc2
-rw-r--r--ash/wm/shelf_layout_manager.cc15
-rw-r--r--ash/wm/shelf_layout_manager.h15
10 files changed, 103 insertions, 12 deletions
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc
index f8314bc..bc879e7 100644
--- a/ash/launcher/launcher.cc
+++ b/ash/launcher/launcher.cc
@@ -95,7 +95,8 @@ void Launcher::DelegateView::Layout() {
// Launcher --------------------------------------------------------------------
-Launcher::Launcher(aura::Window* window_container)
+Launcher::Launcher(aura::Window* window_container,
+ internal::ShelfLayoutManager* shelf_layout_manager)
: widget_(NULL),
window_container_(window_container),
delegate_view_(NULL),
@@ -119,7 +120,8 @@ Launcher::Launcher(aura::Window* window_container)
params.parent = Shell::GetContainer(
window_container_->GetRootWindow(),
ash::internal::kShellWindowId_LauncherContainer);
- launcher_view_ = new internal::LauncherView(model_.get(), delegate_.get());
+ launcher_view_ = new internal::LauncherView(
+ model_.get(), delegate_.get(), shelf_layout_manager);
launcher_view_->Init();
delegate_view_ = new DelegateView(this);
delegate_view_->AddChildView(launcher_view_);
diff --git a/ash/launcher/launcher.h b/ash/launcher/launcher.h
index 890ea36..af1ef1d 100644
--- a/ash/launcher/launcher.h
+++ b/ash/launcher/launcher.h
@@ -32,6 +32,7 @@ namespace ash {
namespace internal {
class FocusCycler;
class LauncherView;
+class ShelfLayoutManager;
}
class LauncherIconObserver;
@@ -40,7 +41,8 @@ class LauncherModel;
class ASH_EXPORT Launcher : public internal::BackgroundAnimatorDelegate {
public:
- explicit Launcher(aura::Window* window_container);
+ explicit Launcher(aura::Window* window_container,
+ internal::ShelfLayoutManager* shelf_layout_manager);
virtual ~Launcher();
// Sets the focus cycler. Also adds the launcher to the cycle.
diff --git a/ash/launcher/launcher_tooltip_manager.cc b/ash/launcher/launcher_tooltip_manager.cc
index a9b533c..72a1224 100644
--- a/ash/launcher/launcher_tooltip_manager.cc
+++ b/ash/launcher/launcher_tooltip_manager.cc
@@ -7,6 +7,8 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_animations.h"
+#include "base/bind.h"
+#include "base/message_loop.h"
#include "base/time.h"
#include "base/timer.h"
#include "ui/aura/window.h"
@@ -102,13 +104,20 @@ void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() {
host_->OnBubbleClosed(this);
}
-LauncherTooltipManager::LauncherTooltipManager(ShelfAlignment alignment)
+LauncherTooltipManager::LauncherTooltipManager(
+ ShelfAlignment alignment, ShelfLayoutManager* shelf_layout_manager)
: view_(NULL),
anchor_(NULL),
- alignment_(alignment) {}
+ alignment_(alignment),
+ shelf_layout_manager_(shelf_layout_manager) {
+ if (shelf_layout_manager)
+ shelf_layout_manager->AddObserver(this);
+}
LauncherTooltipManager::~LauncherTooltipManager() {
Close();
+ if (shelf_layout_manager_)
+ shelf_layout_manager_->RemoveObserver(this);
}
void LauncherTooltipManager::ShowDelayed(views::View* anchor,
@@ -120,6 +129,9 @@ void LauncherTooltipManager::ShowDelayed(views::View* anchor,
Close();
}
+ if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
+ return;
+
CreateBubble(anchor, text);
gfx::NativeView native_view = view_->GetWidget()->GetNativeView();
SetWindowVisibilityAnimationType(
@@ -133,6 +145,9 @@ void LauncherTooltipManager::ShowImmediately(views::View* anchor,
if (view_ && IsVisible())
Close();
+ if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
+ return;
+
CreateBubble(anchor, text);
gfx::NativeView native_view = view_->GetWidget()->GetNativeView();
SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE);
@@ -169,6 +184,10 @@ void LauncherTooltipManager::ResetTimer() {
return;
}
+ // We don't start the timer if the shelf isn't visible.
+ if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible())
+ return;
+
base::OneShotTimer<LauncherTooltipManager>* new_timer =
new base::OneShotTimer<LauncherTooltipManager>();
new_timer->Start(
@@ -190,6 +209,27 @@ bool LauncherTooltipManager::IsVisible() {
return view_ && view_->GetWidget() && view_->GetWidget()->IsVisible();
}
+void LauncherTooltipManager::WillVisibilityStateChange(
+ ShelfLayoutManager::VisibilityState new_state) {
+ if (new_state == ShelfLayoutManager::HIDDEN) {
+ StopTimer();
+ Close();
+ }
+}
+
+void LauncherTooltipManager::OnAutoHideStateChanged(
+ ShelfLayoutManager::AutoHideState new_state) {
+ if (new_state == ShelfLayoutManager::AUTO_HIDE_HIDDEN) {
+ StopTimer();
+ // AutoHide state change happens during an event filter, so immediate close
+ // may cause a crash in the HandleMouseEvent() after the filter. So we just
+ // schedule the Close here.
+ MessageLoopForUI::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&LauncherTooltipManager::Close, base::Unretained(this)));
+ }
+}
+
void LauncherTooltipManager::ShowInternal() {
if (view_)
view_->Show();
diff --git a/ash/launcher/launcher_tooltip_manager.h b/ash/launcher/launcher_tooltip_manager.h
index 5451ccf..37bdfc71 100644
--- a/ash/launcher/launcher_tooltip_manager.h
+++ b/ash/launcher/launcher_tooltip_manager.h
@@ -7,6 +7,7 @@
#pragma once
#include "ash/ash_export.h"
+#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/shelf_types.h"
#include "base/basictypes.h"
#include "base/string16.h"
@@ -32,9 +33,10 @@ namespace internal {
// LauncherTooltipManager manages the tooltip balloon poping up on launcher
// items.
-class ASH_EXPORT LauncherTooltipManager {
+class ASH_EXPORT LauncherTooltipManager : public ShelfLayoutManager::Observer {
public:
- LauncherTooltipManager(ShelfAlignment alignment);
+ LauncherTooltipManager(ShelfAlignment alignment,
+ ShelfLayoutManager* shelf_layout_manager);
~LauncherTooltipManager();
// Called when the bubble is closed.
@@ -63,6 +65,13 @@ class ASH_EXPORT LauncherTooltipManager {
// Returns true if the tooltip is currently visible.
bool IsVisible();
+protected:
+ // ShelfLayoutManager::Observer overrides:
+ virtual void WillVisibilityStateChange(
+ ShelfLayoutManager::VisibilityState new_state) OVERRIDE;
+ virtual void OnAutoHideStateChanged(
+ ShelfLayoutManager::AutoHideState new_state) OVERRIDE;
+
private:
class LauncherTooltipBubble;
friend class test::LauncherViewTest;
@@ -76,6 +85,8 @@ class ASH_EXPORT LauncherTooltipManager {
ShelfAlignment alignment_;
scoped_ptr<base::Timer> timer_;
+ ShelfLayoutManager* shelf_layout_manager_;
+
DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManager);
};
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc
index d5112c2..a226631 100644
--- a/ash/launcher/launcher_view.cc
+++ b/ash/launcher/launcher_view.cc
@@ -260,7 +260,9 @@ class LauncherView::StartFadeAnimationDelegate
DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate);
};
-LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate)
+LauncherView::LauncherView(LauncherModel* model,
+ LauncherDelegate* delegate,
+ ShelfLayoutManager* shelf_layout_manager)
: model_(model),
delegate_(delegate),
view_model_(new views::ViewModel),
@@ -277,7 +279,7 @@ LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate)
bounds_animator_->AddObserver(this);
set_context_menu_controller(this);
focus_search_.reset(new LauncherFocusSearch(view_model_.get()));
- tooltip_.reset(new LauncherTooltipManager(alignment_));
+ tooltip_.reset(new LauncherTooltipManager(alignment_, shelf_layout_manager));
}
LauncherView::~LauncherView() {
diff --git a/ash/launcher/launcher_view.h b/ash/launcher/launcher_view.h
index 1db7a6b..1c61fca 100644
--- a/ash/launcher/launcher_view.h
+++ b/ash/launcher/launcher_view.h
@@ -41,6 +41,7 @@ namespace internal {
class LauncherButton;
class LauncherTooltipManager;
+class ShelfLayoutManager;
class ASH_EXPORT LauncherView : public views::View,
public LauncherModelObserver,
@@ -50,7 +51,9 @@ class ASH_EXPORT LauncherView : public views::View,
public views::FocusTraversable,
public views::BoundsAnimatorObserver {
public:
- LauncherView(LauncherModel* model, LauncherDelegate* delegate);
+ LauncherView(LauncherModel* model,
+ LauncherDelegate* delegate,
+ ShelfLayoutManager* shelf_layout_manager);
virtual ~LauncherView();
LauncherTooltipManager* tooltip_manager() { return tooltip_.get(); }
diff --git a/ash/launcher/launcher_view_unittest.cc b/ash/launcher/launcher_view_unittest.cc
index 556c99d..61530e8 100644
--- a/ash/launcher/launcher_view_unittest.cc
+++ b/ash/launcher/launcher_view_unittest.cc
@@ -176,7 +176,8 @@ class LauncherViewTest : public aura::test::AuraTestBase {
model_.reset(new LauncherModel);
- launcher_view_.reset(new internal::LauncherView(model_.get(), &delegate_));
+ launcher_view_.reset(new internal::LauncherView(
+ model_.get(), &delegate_, NULL));
launcher_view_->Init();
// The bounds should be big enough for 4 buttons + overflow chevron.
launcher_view_->SetBounds(0, 0, 500, 50);
diff --git a/ash/shell.cc b/ash/shell.cc
index 236a1ec..db3fe04 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -621,7 +621,7 @@ void Shell::CreateLauncher() {
aura::Window* default_container =
GetPrimaryRootWindowController()->
GetContainer(internal::kShellWindowId_DefaultContainer);
- launcher_.reset(new Launcher(default_container));
+ launcher_.reset(new Launcher(default_container, shelf_));
launcher_->SetFocusCycler(focus_cycler_.get());
shelf_->SetLauncher(launcher_.get());
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc
index 156fad1..cf0c624 100644
--- a/ash/wm/shelf_layout_manager.cc
+++ b/ash/wm/shelf_layout_manager.cc
@@ -279,6 +279,8 @@ void ShelfLayoutManager::UpdateAutoHideState() {
if (auto_hide_state == AUTO_HIDE_HIDDEN) {
// Hides happen immediately.
SetState(state_.visibility_state);
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnAutoHideStateChanged(auto_hide_state));
} else {
auto_hide_timer_.Stop();
auto_hide_timer_.Start(
@@ -296,6 +298,14 @@ void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) {
UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE);
}
+void ShelfLayoutManager::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void ShelfLayoutManager::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
////////////////////////////////////////////////////////////////////////////////
// ShelfLayoutManager, aura::LayoutManager implementation:
@@ -345,6 +355,9 @@ void ShelfLayoutManager::SetState(VisibilityState visibility_state) {
if (state_.Equals(state))
return; // Nothing changed.
+ FOR_EACH_OBSERVER(Observer, observers_,
+ WillVisibilityStateChange(visibility_state));
+
if (state.visibility_state == AUTO_HIDE) {
// When state is AUTO_HIDE we need to track when the mouse is over the
// launcher to unhide the shelf. AutoHideEventFilter does that for us.
@@ -507,6 +520,8 @@ bool ShelfLayoutManager::GetLauncherPaintsBackground() const {
void ShelfLayoutManager::UpdateAutoHideStateNow() {
SetState(state_.visibility_state);
+ FOR_EACH_OBSERVER(Observer, observers_, OnAutoHideStateChanged(
+ CalculateAutoHideState(state_.visibility_state)));
}
ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState(
diff --git a/ash/wm/shelf_layout_manager.h b/ash/wm/shelf_layout_manager.h
index dac537a..c93d6ec 100644
--- a/ash/wm/shelf_layout_manager.h
+++ b/ash/wm/shelf_layout_manager.h
@@ -12,6 +12,7 @@
#include "ash/wm/shelf_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/observer_list.h"
#include "base/timer.h"
#include "ui/aura/client/activation_change_observer.h"
#include "ui/aura/layout_manager.h"
@@ -59,6 +60,15 @@ class ASH_EXPORT ShelfLayoutManager :
AUTO_HIDE_HIDDEN,
};
+ class Observer {
+ public:
+ // Called when the visibility change is scheduled.
+ virtual void WillVisibilityStateChange(VisibilityState new_state) {}
+
+ // Called when the auto hide state is changed.
+ virtual void OnAutoHideStateChanged(AutoHideState new_state) {}
+ };
+
// We reserve a small area at the bottom of the workspace area to ensure that
// the bottom-of-window resize handle can be hit.
// TODO(jamescook): Some day we may want the workspace area to be an even
@@ -130,6 +140,9 @@ class ASH_EXPORT ShelfLayoutManager :
// the shelf renders slightly differently.
void SetWindowOverlapsShelf(bool value);
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
// Overridden from aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
@@ -252,6 +265,8 @@ class ASH_EXPORT ShelfLayoutManager :
// trigger showing the launcher.
scoped_ptr<AutoHideEventFilter> event_filter_;
+ ObserverList<Observer> observers_;
+
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager);
};