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