| 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/common/shelf/overflow_bubble.h" | 5 #include "ash/common/shelf/overflow_bubble.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/overflow_bubble_view.h" | 7 #include "ash/common/shelf/overflow_bubble_view.h" |
| 8 #include "ash/common/shelf/overflow_button.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/system/tray/tray_background_view.h" | 10 #include "ash/common/system/tray/tray_background_view.h" |
| 10 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 11 #include "ash/shelf/shelf_view.h" | 12 #include "ash/shelf/shelf_view.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 14 | 15 |
| 15 namespace ash { | 16 namespace ash { |
| 16 | 17 |
| 17 OverflowBubble::OverflowBubble(WmShelf* wm_shelf) | 18 OverflowBubble::OverflowBubble(WmShelf* wm_shelf) |
| 18 : wm_shelf_(wm_shelf), | 19 : wm_shelf_(wm_shelf), |
| 19 bubble_(nullptr), | 20 bubble_(nullptr), |
| 20 anchor_(nullptr), | 21 button_(nullptr), |
| 21 shelf_view_(nullptr) { | 22 shelf_view_(nullptr) { |
| 22 WmShell::Get()->AddPointerDownWatcher(this); | 23 WmShell::Get()->AddPointerDownWatcher(this); |
| 23 } | 24 } |
| 24 | 25 |
| 25 OverflowBubble::~OverflowBubble() { | 26 OverflowBubble::~OverflowBubble() { |
| 26 Hide(); | 27 Hide(); |
| 27 WmShell::Get()->RemovePointerDownWatcher(this); | 28 WmShell::Get()->RemovePointerDownWatcher(this); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) { | 31 void OverflowBubble::Show(OverflowButton* button, ShelfView* shelf_view) { |
| 31 Hide(); | 32 Hide(); |
| 32 | 33 |
| 33 bubble_ = new OverflowBubbleView(wm_shelf_); | 34 bubble_ = new OverflowBubbleView(wm_shelf_); |
| 34 bubble_->InitOverflowBubble(anchor, shelf_view); | 35 bubble_->InitOverflowBubble(button, shelf_view); |
| 35 shelf_view_ = shelf_view; | 36 shelf_view_ = shelf_view; |
| 36 anchor_ = anchor; | 37 button_ = button; |
| 37 | 38 |
| 38 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); | 39 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); |
| 39 bubble_->GetWidget()->AddObserver(this); | 40 bubble_->GetWidget()->AddObserver(this); |
| 40 bubble_->GetWidget()->Show(); | 41 bubble_->GetWidget()->Show(); |
| 42 |
| 43 button->OnOverflowBubbleShown(); |
| 41 } | 44 } |
| 42 | 45 |
| 43 void OverflowBubble::Hide() { | 46 void OverflowBubble::Hide() { |
| 44 if (!IsShowing()) | 47 if (!IsShowing()) |
| 45 return; | 48 return; |
| 46 | 49 |
| 50 OverflowButton* button = button_; |
| 51 |
| 47 bubble_->GetWidget()->RemoveObserver(this); | 52 bubble_->GetWidget()->RemoveObserver(this); |
| 48 bubble_->GetWidget()->Close(); | 53 bubble_->GetWidget()->Close(); |
| 49 bubble_ = NULL; | 54 bubble_ = nullptr; |
| 50 anchor_ = NULL; | 55 button_ = nullptr; |
| 51 shelf_view_ = NULL; | 56 shelf_view_ = nullptr; |
| 52 } | |
| 53 | 57 |
| 54 void OverflowBubble::HideBubbleAndRefreshButton() { | 58 button->OnOverflowBubbleHidden(); |
| 55 if (!IsShowing()) | |
| 56 return; | |
| 57 | |
| 58 views::View* anchor = anchor_; | |
| 59 Hide(); | |
| 60 // Update overflow button (|anchor|) status when overflow bubble is hidden | |
| 61 // by outside event of overflow button. | |
| 62 anchor->SchedulePaint(); | |
| 63 } | 59 } |
| 64 | 60 |
| 65 void OverflowBubble::ProcessPressedEvent( | 61 void OverflowBubble::ProcessPressedEvent( |
| 66 const gfx::Point& event_location_in_screen) { | 62 const gfx::Point& event_location_in_screen) { |
| 67 if (IsShowing() && !shelf_view_->IsShowingMenu() && | 63 if (IsShowing() && !shelf_view_->IsShowingMenu() && |
| 68 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && | 64 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && |
| 69 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) { | 65 !button_->GetBoundsInScreen().Contains(event_location_in_screen)) { |
| 70 HideBubbleAndRefreshButton(); | 66 Hide(); |
| 71 } | 67 } |
| 72 } | 68 } |
| 73 | 69 |
| 74 void OverflowBubble::OnMousePressed(const ui::MouseEvent& event, | 70 void OverflowBubble::OnMousePressed(const ui::MouseEvent& event, |
| 75 const gfx::Point& location_in_screen, | 71 const gfx::Point& location_in_screen, |
| 76 views::Widget* target) { | 72 views::Widget* target) { |
| 77 ProcessPressedEvent(location_in_screen); | 73 ProcessPressedEvent(location_in_screen); |
| 78 } | 74 } |
| 79 | 75 |
| 80 void OverflowBubble::OnTouchPressed(const ui::TouchEvent& event, | 76 void OverflowBubble::OnTouchPressed(const ui::TouchEvent& event, |
| 81 const gfx::Point& location_in_screen, | 77 const gfx::Point& location_in_screen, |
| 82 views::Widget* target) { | 78 views::Widget* target) { |
| 83 ProcessPressedEvent(location_in_screen); | 79 ProcessPressedEvent(location_in_screen); |
| 84 } | 80 } |
| 85 | 81 |
| 86 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { | 82 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { |
| 87 DCHECK(widget == bubble_->GetWidget()); | 83 DCHECK(widget == bubble_->GetWidget()); |
| 88 bubble_ = NULL; | 84 bubble_ = nullptr; |
| 89 anchor_ = NULL; | 85 button_ = nullptr; |
| 90 wm_shelf_->SchedulePaint(); | 86 wm_shelf_->SchedulePaint(); |
| 91 shelf_view_ = NULL; | 87 shelf_view_ = nullptr; |
| 92 } | 88 } |
| 93 | 89 |
| 94 } // namespace ash | 90 } // namespace ash |
| OLD | NEW |