| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/shelf/overflow_bubble.h" | 5 #include "ash/shelf/overflow_bubble.h" |
| 6 | 6 |
| 7 #include "ash/shelf/overflow_bubble_view.h" | 7 #include "ash/shelf/overflow_bubble_view.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_view.h" | 9 #include "ash/shelf/shelf_view.h" |
| 10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/system/tray/tray_background_view.h" | 12 #include "ash/system/tray/tray_background_view.h" |
| 13 #include "ui/aura/client/screen_position_client.h" | |
| 14 #include "ui/aura/window_event_dispatcher.h" | |
| 15 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 16 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 17 | 15 |
| 18 namespace ash { | 16 namespace ash { |
| 19 | 17 |
| 20 OverflowBubble::OverflowBubble() | 18 OverflowBubble::OverflowBubble() |
| 21 : bubble_(NULL), | 19 : bubble_(NULL), |
| 22 anchor_(NULL), | 20 anchor_(NULL), |
| 23 shelf_view_(NULL) { | 21 shelf_view_(NULL) { |
| 22 Shell::GetInstance()->AddPointerWatcher(this); |
| 24 } | 23 } |
| 25 | 24 |
| 26 OverflowBubble::~OverflowBubble() { | 25 OverflowBubble::~OverflowBubble() { |
| 27 Hide(); | 26 Hide(); |
| 27 Shell::GetInstance()->RemovePointerWatcher(this); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) { | 30 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) { |
| 31 Hide(); | 31 Hide(); |
| 32 | 32 |
| 33 bubble_ = new OverflowBubbleView(); | 33 bubble_ = new OverflowBubbleView(); |
| 34 bubble_->InitOverflowBubble(anchor, shelf_view); | 34 bubble_->InitOverflowBubble(anchor, shelf_view); |
| 35 shelf_view_ = shelf_view; | 35 shelf_view_ = shelf_view; |
| 36 anchor_ = anchor; | 36 anchor_ = anchor; |
| 37 | 37 |
| 38 // TODO(jamescook): Change this to a PointerWatcher. | |
| 39 Shell::GetInstance()->AddPreTargetHandler(this); | |
| 40 | |
| 41 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); | 38 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); |
| 42 bubble_->GetWidget()->AddObserver(this); | 39 bubble_->GetWidget()->AddObserver(this); |
| 43 bubble_->GetWidget()->Show(); | 40 bubble_->GetWidget()->Show(); |
| 44 } | 41 } |
| 45 | 42 |
| 46 void OverflowBubble::Hide() { | 43 void OverflowBubble::Hide() { |
| 47 if (!IsShowing()) | 44 if (!IsShowing()) |
| 48 return; | 45 return; |
| 49 | 46 |
| 50 Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 51 bubble_->GetWidget()->RemoveObserver(this); | 47 bubble_->GetWidget()->RemoveObserver(this); |
| 52 bubble_->GetWidget()->Close(); | 48 bubble_->GetWidget()->Close(); |
| 53 bubble_ = NULL; | 49 bubble_ = NULL; |
| 54 anchor_ = NULL; | 50 anchor_ = NULL; |
| 55 shelf_view_ = NULL; | 51 shelf_view_ = NULL; |
| 56 } | 52 } |
| 57 | 53 |
| 58 void OverflowBubble::HideBubbleAndRefreshButton() { | 54 void OverflowBubble::HideBubbleAndRefreshButton() { |
| 59 if (!IsShowing()) | 55 if (!IsShowing()) |
| 60 return; | 56 return; |
| 61 | 57 |
| 62 views::View* anchor = anchor_; | 58 views::View* anchor = anchor_; |
| 63 Hide(); | 59 Hide(); |
| 64 // Update overflow button (|anchor|) status when overflow bubble is hidden | 60 // Update overflow button (|anchor|) status when overflow bubble is hidden |
| 65 // by outside event of overflow button. | 61 // by outside event of overflow button. |
| 66 anchor->SchedulePaint(); | 62 anchor->SchedulePaint(); |
| 67 } | 63 } |
| 68 | 64 |
| 69 void OverflowBubble::ProcessPressedEvent(ui::LocatedEvent* event) { | 65 void OverflowBubble::ProcessPressedEvent( |
| 70 aura::Window* target = static_cast<aura::Window*>(event->target()); | 66 const gfx::Point& event_location_in_screen) { |
| 71 gfx::Point event_location_in_screen = event->location(); | 67 if (IsShowing() && !shelf_view_->IsShowingMenu() && |
| 72 aura::client::GetScreenPositionClient(target->GetRootWindow())-> | |
| 73 ConvertPointToScreen(target, &event_location_in_screen); | |
| 74 if (!shelf_view_->IsShowingMenu() && | |
| 75 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && | 68 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && |
| 76 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) { | 69 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) { |
| 77 HideBubbleAndRefreshButton(); | 70 HideBubbleAndRefreshButton(); |
| 78 } | 71 } |
| 79 } | 72 } |
| 80 | 73 |
| 81 void OverflowBubble::OnMouseEvent(ui::MouseEvent* event) { | 74 void OverflowBubble::OnMousePressed(const ui::MouseEvent& event, |
| 82 if (event->type() == ui::ET_MOUSE_PRESSED) | 75 const gfx::Point& location_in_screen) { |
| 83 ProcessPressedEvent(event); | 76 ProcessPressedEvent(location_in_screen); |
| 84 } | 77 } |
| 85 | 78 |
| 86 void OverflowBubble::OnTouchEvent(ui::TouchEvent* event) { | 79 void OverflowBubble::OnTouchPressed(const ui::TouchEvent& event, |
| 87 if (event->type() == ui::ET_TOUCH_PRESSED) | 80 const gfx::Point& location_in_screen) { |
| 88 ProcessPressedEvent(event); | 81 ProcessPressedEvent(location_in_screen); |
| 89 } | 82 } |
| 90 | 83 |
| 91 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { | 84 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { |
| 92 DCHECK(widget == bubble_->GetWidget()); | 85 DCHECK(widget == bubble_->GetWidget()); |
| 93 bubble_ = NULL; | 86 bubble_ = NULL; |
| 94 anchor_ = NULL; | 87 anchor_ = NULL; |
| 95 shelf_view_->shelf()->SchedulePaint(); | 88 shelf_view_->shelf()->SchedulePaint(); |
| 96 shelf_view_ = NULL; | 89 shelf_view_ = NULL; |
| 97 } | 90 } |
| 98 | 91 |
| 99 } // namespace ash | 92 } // namespace ash |
| OLD | NEW |