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

Side by Side Diff: ash/system/tray/tray_event_filter.cc

Issue 2099603002: Reland: mash: Convert TrayBackgroundView to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix conflict Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/system/tray/tray_event_filter.h"
6
7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wm/container_finder.h"
9 #include "ash/common/wm_lookup.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h"
12 #include "ash/system/tray/tray_background_view.h"
13 #include "ash/system/tray/tray_bubble_wrapper.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17
18 TrayEventFilter::TrayEventFilter() {
19 }
20
21 TrayEventFilter::~TrayEventFilter() {
22 DCHECK(wrappers_.empty());
23 }
24
25 void TrayEventFilter::AddWrapper(TrayBubbleWrapper* wrapper) {
26 bool was_empty = wrappers_.empty();
27 wrappers_.insert(wrapper);
28 if (was_empty && !wrappers_.empty())
29 WmShell::Get()->AddPointerWatcher(this);
30 }
31
32 void TrayEventFilter::RemoveWrapper(TrayBubbleWrapper* wrapper) {
33 wrappers_.erase(wrapper);
34 if (wrappers_.empty())
35 WmShell::Get()->RemovePointerWatcher(this);
36 }
37
38 void TrayEventFilter::OnMousePressed(const ui::MouseEvent& event,
39 const gfx::Point& location_in_screen,
40 views::Widget* target) {
41 ProcessPressedEvent(location_in_screen, target);
42 }
43
44 void TrayEventFilter::OnTouchPressed(const ui::TouchEvent& event,
45 const gfx::Point& location_in_screen,
46 views::Widget* target) {
47 ProcessPressedEvent(location_in_screen, target);
48 }
49
50 void TrayEventFilter::ProcessPressedEvent(const gfx::Point& location_in_screen,
51 views::Widget* target) {
52 if (target) {
53 WmWindow* window = WmLookup::Get()->GetWindowForWidget(target);
54 int container_id = wm::GetContainerForWindow(window)->GetShellWindowId();
55 // Don't process events that occurred inside an embedded menu, for example
56 // the right-click menu in a popup notification.
57 if (container_id == kShellWindowId_MenuContainer)
58 return;
59 // Don't process events that occurred inside the status area widget and
60 // a popup notification from message center.
61 if (container_id == kShellWindowId_StatusContainer)
62 return;
63 }
64
65 // Check the boundary for all wrappers, and do not handle the event if it
66 // happens inside of any of those wrappers.
67 for (std::set<TrayBubbleWrapper*>::const_iterator iter = wrappers_.begin();
68 iter != wrappers_.end(); ++iter) {
69 const TrayBubbleWrapper* wrapper = *iter;
70 const views::Widget* bubble_widget = wrapper->bubble_widget();
71 if (!bubble_widget)
72 continue;
73
74 gfx::Rect bounds = bubble_widget->GetWindowBoundsInScreen();
75 bounds.Inset(wrapper->bubble_view()->GetBorderInsets());
76 if (bounds.Contains(location_in_screen))
77 return;
78 if (wrapper->tray()) {
79 // If the user clicks on the parent tray, don't process the event here,
80 // let the tray logic handle the event and determine show/hide behavior.
81 bounds = wrapper->tray()->GetBoundsInScreen();
82 if (bounds.Contains(location_in_screen))
83 return;
84 }
85 }
86
87 // Handle clicking outside the bubble and tray.
88 // Cannot iterate |wrappers_| directly, because clicking outside will remove
89 // the wrapper, which shrinks |wrappers_| unsafely.
90 std::set<TrayBackgroundView*> trays;
91 for (std::set<TrayBubbleWrapper*>::iterator iter = wrappers_.begin();
92 iter != wrappers_.end(); ++iter) {
93 trays.insert((*iter)->tray());
94 }
95 for (std::set<TrayBackgroundView*>::iterator iter = trays.begin();
96 iter != trays.end(); ++iter) {
97 (*iter)->ClickedOutsideBubble();
98 }
99 }
100
101 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_event_filter.h ('k') | ash/system/web_notification/web_notification_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698