[ash] Wrong LauncherItem state when overflow bubble is shown

When overflow bubble is shown, active state item in overflow bubble is changed
to running state item because overflow bubble get focus.

R=jamescook@chromium.org
BUG=283206
TEST=Compiles, Manual tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221235 0039d316-1c4b-4281-b951-d872f2087c98
parent ed4d7052
......@@ -14,6 +14,7 @@
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "ui/aura/root_window.h"
#include "ui/base/events/event.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/screen.h"
#include "ui/views/bubble/bubble_delegate.h"
......@@ -106,6 +107,9 @@ void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
set_color(SkColorSetARGB(kLauncherBackgroundAlpha, 0, 0, 0));
set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding));
set_move_with_anchor(true);
// Overflow bubble should not get focus. If it get focus when it is shown,
// active state item is changed to running state.
set_use_focusless(true);
// Makes bubble view has a layer and clip its children layers.
SetPaintToLayer(true);
......@@ -242,6 +246,7 @@ gfx::Rect OverflowBubbleView::GetBubbleBounds() {
OverflowBubble::OverflowBubble()
: bubble_(NULL),
anchor_(NULL),
launcher_view_(NULL) {
}
......@@ -255,6 +260,9 @@ void OverflowBubble::Show(views::View* anchor, LauncherView* launcher_view) {
OverflowBubbleView* bubble_view = new OverflowBubbleView();
bubble_view->InitOverflowBubble(anchor, launcher_view);
launcher_view_ = launcher_view;
anchor_ = anchor;
Shell::GetInstance()->AddPreTargetHandler(this);
bubble_ = bubble_view;
RootWindowController::ForWindow(anchor->GetWidget()->GetNativeView())->
......@@ -267,15 +275,34 @@ void OverflowBubble::Hide() {
if (!IsShowing())
return;
Shell::GetInstance()->RemovePreTargetHandler(this);
bubble_->GetWidget()->RemoveObserver(this);
bubble_->GetWidget()->Close();
bubble_ = NULL;
anchor_ = NULL;
launcher_view_ = NULL;
}
void OverflowBubble::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED &&
!bubble_->GetBoundsInScreen().Contains(event->root_location()) &&
!anchor_->GetBoundsInScreen().Contains(event->root_location())) {
Hide();
}
}
void OverflowBubble::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_PRESSED &&
!bubble_->GetBoundsInScreen().Contains(event->root_location()) &&
!anchor_->GetBoundsInScreen().Contains(event->root_location())) {
Hide();
}
}
void OverflowBubble::OnWidgetDestroying(views::Widget* widget) {
DCHECK(widget == bubble_->GetWidget());
bubble_ = NULL;
anchor_ = NULL;
launcher_view_ = NULL;
ShelfLayoutManager::ForLauncher(
widget->GetNativeView())->shelf_widget()->launcher()->SchedulePaint();
......
......@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/base/events/event_handler.h"
#include "ui/views/widget/widget_observer.h"
namespace views {
......@@ -23,7 +24,8 @@ namespace internal {
class LauncherView;
// OverflowBubble displays the overflown launcher items in a bubble.
class OverflowBubble : public views::WidgetObserver {
class OverflowBubble : public ui::EventHandler,
public views::WidgetObserver {
public:
OverflowBubble();
virtual ~OverflowBubble();
......@@ -37,10 +39,15 @@ class OverflowBubble : public views::WidgetObserver {
LauncherView* launcher_view() { return launcher_view_; }
private:
// Overridden from ui::EventHandler:
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
// Overridden from views::WidgetObserver:
virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
views::View* bubble_; // Owned by views hierarchy.
views::View* anchor_; // Owned by LauncherView.
LauncherView* launcher_view_; // Owned by |bubble_|.
DISALLOW_COPY_AND_ASSIGN(OverflowBubble);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment