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