Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: ash/shelf/overflow_bubble.cc

Issue 1934123004: mash: Fix shelf overflow bubble not closing on click outside its bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2openoverflow
Patch Set: add screen coordinates, fix observer cleanup Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/overflow_bubble.h ('k') | ash/system/tray/tray_event_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shelf/overflow_bubble.h" 5 #include "ash/shelf/overflow_bubble.h"
6 6
7 #include "ash/shelf/overflow_bubble_view.h" 7 #include "ash/shelf/overflow_bubble_view.h"
8 #include "ash/shelf/shelf.h" 8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_view.h" 9 #include "ash/shelf/shelf_view.h"
10 #include "ash/shelf/shelf_widget.h" 10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/system/tray/tray_background_view.h" 12 #include "ash/system/tray/tray_background_view.h"
13 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/events/event.h" 13 #include "ui/events/event.h"
16 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
17 15
18 namespace ash { 16 namespace ash {
19 17
20 OverflowBubble::OverflowBubble() 18 OverflowBubble::OverflowBubble()
21 : bubble_(NULL), 19 : bubble_(NULL),
22 anchor_(NULL), 20 anchor_(NULL),
23 shelf_view_(NULL) { 21 shelf_view_(NULL) {
22 Shell::GetInstance()->AddPointerWatcher(this);
24 } 23 }
25 24
26 OverflowBubble::~OverflowBubble() { 25 OverflowBubble::~OverflowBubble() {
27 Hide(); 26 Hide();
27 Shell::GetInstance()->RemovePointerWatcher(this);
28 } 28 }
29 29
30 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) { 30 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) {
31 Hide(); 31 Hide();
32 32
33 bubble_ = new OverflowBubbleView(); 33 bubble_ = new OverflowBubbleView();
34 bubble_->InitOverflowBubble(anchor, shelf_view); 34 bubble_->InitOverflowBubble(anchor, shelf_view);
35 shelf_view_ = shelf_view; 35 shelf_view_ = shelf_view;
36 anchor_ = anchor; 36 anchor_ = anchor;
37 37
38 // TODO(jamescook): Change this to a PointerWatcher.
39 Shell::GetInstance()->AddPreTargetHandler(this);
40
41 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); 38 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget());
42 bubble_->GetWidget()->AddObserver(this); 39 bubble_->GetWidget()->AddObserver(this);
43 bubble_->GetWidget()->Show(); 40 bubble_->GetWidget()->Show();
44 } 41 }
45 42
46 void OverflowBubble::Hide() { 43 void OverflowBubble::Hide() {
47 if (!IsShowing()) 44 if (!IsShowing())
48 return; 45 return;
49 46
50 Shell::GetInstance()->RemovePreTargetHandler(this);
51 bubble_->GetWidget()->RemoveObserver(this); 47 bubble_->GetWidget()->RemoveObserver(this);
52 bubble_->GetWidget()->Close(); 48 bubble_->GetWidget()->Close();
53 bubble_ = NULL; 49 bubble_ = NULL;
54 anchor_ = NULL; 50 anchor_ = NULL;
55 shelf_view_ = NULL; 51 shelf_view_ = NULL;
56 } 52 }
57 53
58 void OverflowBubble::HideBubbleAndRefreshButton() { 54 void OverflowBubble::HideBubbleAndRefreshButton() {
59 if (!IsShowing()) 55 if (!IsShowing())
60 return; 56 return;
61 57
62 views::View* anchor = anchor_; 58 views::View* anchor = anchor_;
63 Hide(); 59 Hide();
64 // Update overflow button (|anchor|) status when overflow bubble is hidden 60 // Update overflow button (|anchor|) status when overflow bubble is hidden
65 // by outside event of overflow button. 61 // by outside event of overflow button.
66 anchor->SchedulePaint(); 62 anchor->SchedulePaint();
67 } 63 }
68 64
69 void OverflowBubble::ProcessPressedEvent(ui::LocatedEvent* event) { 65 void OverflowBubble::ProcessPressedEvent(
70 aura::Window* target = static_cast<aura::Window*>(event->target()); 66 const ui::LocatedEvent& event,
msw 2016/05/03 17:26:47 nit: |event| is no longer needed here.
James Cook 2016/05/03 17:35:53 Done.
71 gfx::Point event_location_in_screen = event->location(); 67 const gfx::Point& event_location_in_screen) {
72 aura::client::GetScreenPositionClient(target->GetRootWindow())-> 68 if (IsShowing() && !shelf_view_->IsShowingMenu() &&
73 ConvertPointToScreen(target, &event_location_in_screen);
74 if (!shelf_view_->IsShowingMenu() &&
75 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && 69 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) &&
76 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) { 70 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) {
77 HideBubbleAndRefreshButton(); 71 HideBubbleAndRefreshButton();
78 } 72 }
79 } 73 }
80 74
81 void OverflowBubble::OnMouseEvent(ui::MouseEvent* event) { 75 void OverflowBubble::OnMousePressed(const ui::MouseEvent& event,
82 if (event->type() == ui::ET_MOUSE_PRESSED) 76 const gfx::Point& location_in_screen) {
83 ProcessPressedEvent(event); 77 ProcessPressedEvent(event, location_in_screen);
84 } 78 }
85 79
86 void OverflowBubble::OnTouchEvent(ui::TouchEvent* event) { 80 void OverflowBubble::OnTouchPressed(const ui::TouchEvent& event,
87 if (event->type() == ui::ET_TOUCH_PRESSED) 81 const gfx::Point& location_in_screen) {
88 ProcessPressedEvent(event); 82 ProcessPressedEvent(event, location_in_screen);
89 } 83 }
90 84
91 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { 85 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) {
92 DCHECK(widget == bubble_->GetWidget()); 86 DCHECK(widget == bubble_->GetWidget());
93 bubble_ = NULL; 87 bubble_ = NULL;
94 anchor_ = NULL; 88 anchor_ = NULL;
95 shelf_view_->shelf()->SchedulePaint(); 89 shelf_view_->shelf()->SchedulePaint();
96 shelf_view_ = NULL; 90 shelf_view_ = NULL;
97 } 91 }
98 92
99 } // namespace ash 93 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/overflow_bubble.h ('k') | ash/system/tray/tray_event_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698