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

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: 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') | no next file » | 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" 13 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/events/event.h" 14 #include "ui/events/event.h"
16 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
17 16
18 namespace ash { 17 namespace ash {
19 18
20 OverflowBubble::OverflowBubble() 19 OverflowBubble::OverflowBubble()
21 : bubble_(NULL), 20 : bubble_(NULL),
22 anchor_(NULL), 21 anchor_(NULL),
23 shelf_view_(NULL) { 22 shelf_view_(NULL) {
24 } 23 }
25 24
26 OverflowBubble::~OverflowBubble() { 25 OverflowBubble::~OverflowBubble() {
27 Hide(); 26 Hide();
28 } 27 }
29 28
30 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) { 29 void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) {
31 Hide(); 30 Hide();
32 31
33 bubble_ = new OverflowBubbleView(); 32 bubble_ = new OverflowBubbleView();
34 bubble_->InitOverflowBubble(anchor, shelf_view); 33 bubble_->InitOverflowBubble(anchor, shelf_view);
35 shelf_view_ = shelf_view; 34 shelf_view_ = shelf_view;
36 anchor_ = anchor; 35 anchor_ = anchor;
37 36
38 // TODO(jamescook): Change this to a PointerWatcher. 37 Shell::GetInstance()->AddPointerWatcher(this);
39 Shell::GetInstance()->AddPreTargetHandler(this);
40 38
41 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget()); 39 TrayBackgroundView::InitializeBubbleAnimations(bubble_->GetWidget());
42 bubble_->GetWidget()->AddObserver(this); 40 bubble_->GetWidget()->AddObserver(this);
43 bubble_->GetWidget()->Show(); 41 bubble_->GetWidget()->Show();
44 } 42 }
45 43
46 void OverflowBubble::Hide() { 44 void OverflowBubble::Hide() {
47 if (!IsShowing()) 45 if (!IsShowing())
48 return; 46 return;
49 47
50 Shell::GetInstance()->RemovePreTargetHandler(this); 48 Shell::GetInstance()->RemovePointerWatcher(this);
51 bubble_->GetWidget()->RemoveObserver(this); 49 bubble_->GetWidget()->RemoveObserver(this);
52 bubble_->GetWidget()->Close(); 50 bubble_->GetWidget()->Close();
53 bubble_ = NULL; 51 bubble_ = NULL;
54 anchor_ = NULL; 52 anchor_ = NULL;
55 shelf_view_ = NULL; 53 shelf_view_ = NULL;
56 } 54 }
57 55
58 void OverflowBubble::HideBubbleAndRefreshButton() { 56 void OverflowBubble::HideBubbleAndRefreshButton() {
59 if (!IsShowing()) 57 if (!IsShowing())
60 return; 58 return;
61 59
62 views::View* anchor = anchor_; 60 views::View* anchor = anchor_;
63 Hide(); 61 Hide();
64 // Update overflow button (|anchor|) status when overflow bubble is hidden 62 // Update overflow button (|anchor|) status when overflow bubble is hidden
65 // by outside event of overflow button. 63 // by outside event of overflow button.
66 anchor->SchedulePaint(); 64 anchor->SchedulePaint();
67 } 65 }
68 66
69 void OverflowBubble::ProcessPressedEvent(ui::LocatedEvent* event) { 67 void OverflowBubble::ProcessPressedEvent(const ui::LocatedEvent& event) {
70 aura::Window* target = static_cast<aura::Window*>(event->target()); 68 aura::Window* root = bubble_->GetWidget()->GetNativeWindow()->GetRootWindow();
71 gfx::Point event_location_in_screen = event->location(); 69 gfx::Point event_location_in_screen = event.root_location();
72 aura::client::GetScreenPositionClient(target->GetRootWindow())-> 70 aura::client::GetScreenPositionClient(root)->ConvertPointToScreen(
msw 2016/05/02 17:18:13 Will this work? What is the coordinate system used
James Cook 2016/05/02 17:48:34 Yes, I think this is wrong for multi-display. Good
73 ConvertPointToScreen(target, &event_location_in_screen); 71 root, &event_location_in_screen);
74 if (!shelf_view_->IsShowingMenu() && 72 if (!shelf_view_->IsShowingMenu() &&
75 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) && 73 !bubble_->GetBoundsInScreen().Contains(event_location_in_screen) &&
76 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) { 74 !anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) {
77 HideBubbleAndRefreshButton(); 75 HideBubbleAndRefreshButton();
78 } 76 }
79 } 77 }
80 78
81 void OverflowBubble::OnMouseEvent(ui::MouseEvent* event) { 79 void OverflowBubble::OnMousePressed(const ui::MouseEvent& event) {
82 if (event->type() == ui::ET_MOUSE_PRESSED) 80 ProcessPressedEvent(event);
83 ProcessPressedEvent(event);
84 } 81 }
85 82
86 void OverflowBubble::OnTouchEvent(ui::TouchEvent* event) { 83 void OverflowBubble::OnTouchPressed(const ui::TouchEvent& event) {
87 if (event->type() == ui::ET_TOUCH_PRESSED) 84 ProcessPressedEvent(event);
88 ProcessPressedEvent(event);
89 } 85 }
90 86
91 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { 87 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) {
92 DCHECK(widget == bubble_->GetWidget()); 88 DCHECK(widget == bubble_->GetWidget());
93 bubble_ = NULL; 89 bubble_ = NULL;
94 anchor_ = NULL; 90 anchor_ = NULL;
95 shelf_view_->shelf()->SchedulePaint(); 91 shelf_view_->shelf()->SchedulePaint();
96 shelf_view_ = NULL; 92 shelf_view_ = NULL;
97 } 93 }
98 94
99 } // namespace ash 95 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/overflow_bubble.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698