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