| 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 overflow_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* overflow_button, |
| 32 DCHECK(anchor); | 33 ShelfView* shelf_view) { |
| 34 DCHECK(overflow_button); |
| 33 DCHECK(shelf_view); | 35 DCHECK(shelf_view); |
| 34 | 36 |
| 35 Hide(); | 37 Hide(); |
| 36 | 38 |
| 37 bubble_ = new OverflowBubbleView(wm_shelf_); | 39 bubble_ = new OverflowBubbleView(wm_shelf_); |
| 38 bubble_->InitOverflowBubble(anchor, shelf_view); | 40 bubble_->InitOverflowBubble(overflow_button, shelf_view); |
| 39 shelf_view_ = shelf_view; | 41 shelf_view_ = shelf_view; |
| 40 anchor_ = anchor; | 42 overflow_button_ = overflow_button; |
| 41 | 43 |
| 42 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); | 44 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); |
| 43 bubble_->GetWidget()->AddObserver(this); | 45 bubble_->GetWidget()->AddObserver(this); |
| 44 bubble_->GetWidget()->Show(); | 46 bubble_->GetWidget()->Show(); |
| 47 |
| 48 overflow_button->OnOverflowBubbleShown(); |
| 45 } | 49 } |
| 46 | 50 |
| 47 void OverflowBubble::Hide() { | 51 void OverflowBubble::Hide() { |
| 48 if (!IsShowing()) | 52 if (!IsShowing()) |
| 49 return; | 53 return; |
| 50 | 54 |
| 55 OverflowButton* overflow_button = overflow_button_; |
| 56 |
| 51 bubble_->GetWidget()->RemoveObserver(this); | 57 bubble_->GetWidget()->RemoveObserver(this); |
| 52 bubble_->GetWidget()->Close(); | 58 bubble_->GetWidget()->Close(); |
| 53 bubble_ = NULL; | 59 bubble_ = nullptr; |
| 54 anchor_ = NULL; | 60 overflow_button_ = nullptr; |
| 55 shelf_view_ = NULL; | 61 shelf_view_ = nullptr; |
| 56 } | |
| 57 | 62 |
| 58 void OverflowBubble::HideBubbleAndRefreshButton() { | 63 overflow_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 } | 64 } |
| 68 | 65 |
| 69 void OverflowBubble::ProcessPressedEvent( | 66 void OverflowBubble::ProcessPressedEvent( |
| 70 const gfx::Point& event_location_in_screen) { | 67 const gfx::Point& event_location_in_screen) { |
| 71 if (IsShowing() && !shelf_view_->IsShowingMenu() && | 68 if (IsShowing() && !shelf_view_->IsShowingMenu() && |
| 72 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && | 69 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && |
| 73 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) { | 70 !overflow_button_->GetBoundsInScreen().Contains( |
| 74 HideBubbleAndRefreshButton(); | 71 event_location_in_screen)) { |
| 72 Hide(); |
| 75 } | 73 } |
| 76 } | 74 } |
| 77 | 75 |
| 78 void OverflowBubble::OnPointerEventObserved( | 76 void OverflowBubble::OnPointerEventObserved( |
| 79 const ui::PointerEvent& event, | 77 const ui::PointerEvent& event, |
| 80 const gfx::Point& location_in_screen, | 78 const gfx::Point& location_in_screen, |
| 81 views::Widget* target) { | 79 views::Widget* target) { |
| 82 if (event.type() == ui::ET_POINTER_DOWN) | 80 if (event.type() == ui::ET_POINTER_DOWN) |
| 83 ProcessPressedEvent(location_in_screen); | 81 ProcessPressedEvent(location_in_screen); |
| 84 } | 82 } |
| 85 | 83 |
| 86 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { | 84 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { |
| 87 DCHECK(widget == bubble_->GetWidget()); | 85 DCHECK(widget == bubble_->GetWidget()); |
| 88 // Update the overflow button in the parent ShelfView. | 86 // Update the overflow button in the parent ShelfView. |
| 89 anchor_->SchedulePaint(); | 87 overflow_button_->SchedulePaint(); |
| 90 bubble_ = nullptr; | 88 bubble_ = nullptr; |
| 91 anchor_ = nullptr; | 89 overflow_button_ = nullptr; |
| 92 shelf_view_ = nullptr; | 90 shelf_view_ = nullptr; |
| 93 } | 91 } |
| 94 | 92 |
| 95 } // namespace ash | 93 } // namespace ash |
| OLD | NEW |