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

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

Issue 1937673002: Close mash shelf tooltips on touches outside the shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase; 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/shelf_tooltip_manager.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/shelf_tooltip_manager.h" 5 #include "ash/shelf/shelf_tooltip_manager.h"
6 6
7 #include "ash/shelf/shelf.h" 7 #include "ash/shelf/shelf.h"
8 #include "ash/shelf/shelf_layout_manager.h" 8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_view.h" 9 #include "ash/shelf/shelf_view.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
12 #include "ash/wm/window_animations.h" 12 #include "ash/wm/window_animations.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/strings/string16.h"
14 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
17 #include "ui/events/event.h" 18 #include "ui/events/event.h"
18 #include "ui/events/event_constants.h" 19 #include "ui/events/event_constants.h"
19 #include "ui/gfx/geometry/insets.h" 20 #include "ui/gfx/geometry/insets.h"
20 #include "ui/views/bubble/bubble_dialog_delegate.h" 21 #include "ui/views/bubble/bubble_dialog_delegate.h"
21 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/fill_layout.h" 23 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) 95 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view)
95 : timer_delay_(kTooltipAppearanceDelay), 96 : timer_delay_(kTooltipAppearanceDelay),
96 shelf_view_(shelf_view), 97 shelf_view_(shelf_view),
97 root_window_(nullptr), 98 root_window_(nullptr),
98 shelf_layout_manager_(nullptr), 99 shelf_layout_manager_(nullptr),
99 bubble_(nullptr), 100 bubble_(nullptr),
100 weak_factory_(this) {} 101 weak_factory_(this) {}
101 102
102 ShelfTooltipManager::~ShelfTooltipManager() { 103 ShelfTooltipManager::~ShelfTooltipManager() {
103 WillDeleteShelf(); 104 WillDeleteShelf();
105
106 Shell::GetInstance()->RemovePointerWatcher(this);
107
104 if (root_window_) { 108 if (root_window_) {
105 root_window_->RemoveObserver(this); 109 root_window_->RemoveObserver(this);
106 root_window_->RemovePreTargetHandler(this); 110 root_window_->RemovePreTargetHandler(this);
107 root_window_ = nullptr; 111 root_window_ = nullptr;
108 } 112 }
109 } 113 }
110 114
111 void ShelfTooltipManager::Init() { 115 void ShelfTooltipManager::Init() {
112 shelf_layout_manager_ = shelf_view_->shelf()->shelf_layout_manager(); 116 shelf_layout_manager_ = shelf_view_->shelf()->shelf_layout_manager();
113 shelf_layout_manager_->AddObserver(this); 117 shelf_layout_manager_->AddObserver(this);
114 118
115 // TODO(msw): Observe events outside the shelf in mash, to close tooltips.
116 root_window_ = shelf_view_->GetWidget()->GetNativeWindow()->GetRootWindow(); 119 root_window_ = shelf_view_->GetWidget()->GetNativeWindow()->GetRootWindow();
117 root_window_->AddPreTargetHandler(this); 120 root_window_->AddPreTargetHandler(this);
118 root_window_->AddObserver(this); 121 root_window_->AddObserver(this);
122
123 Shell::GetInstance()->AddPointerWatcher(this);
119 } 124 }
120 125
121 void ShelfTooltipManager::Close() { 126 void ShelfTooltipManager::Close() {
122 timer_.Stop(); 127 timer_.Stop();
123 if (bubble_) 128 if (bubble_)
124 bubble_->GetWidget()->Close(); 129 bubble_->GetWidget()->Close();
125 bubble_ = nullptr; 130 bubble_ = nullptr;
126 } 131 }
127 132
128 bool ShelfTooltipManager::IsVisible() const { 133 bool ShelfTooltipManager::IsVisible() const {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 166 }
162 167
163 void ShelfTooltipManager::ShowTooltipWithDelay(views::View* view) { 168 void ShelfTooltipManager::ShowTooltipWithDelay(views::View* view) {
164 if (!shelf_layout_manager_ || shelf_layout_manager_->IsVisible()) { 169 if (!shelf_layout_manager_ || shelf_layout_manager_->IsVisible()) {
165 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(timer_delay_), 170 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(timer_delay_),
166 base::Bind(&ShelfTooltipManager::ShowTooltip, 171 base::Bind(&ShelfTooltipManager::ShowTooltip,
167 weak_factory_.GetWeakPtr(), view)); 172 weak_factory_.GetWeakPtr(), view));
168 } 173 }
169 } 174 }
170 175
176 void ShelfTooltipManager::OnMousePressed(const ui::MouseEvent& event,
177 const gfx::Point& location_in_screen) {
178 // PointerWatcher supports tracking events outside the root window in mash.
James Cook 2016/05/04 19:17:49 nit: I might say something explicitly that any cli
msw 2016/05/04 20:07:49 Done.
179 Close();
180 }
181
182 void ShelfTooltipManager::OnTouchPressed(const ui::TouchEvent& event,
183 const gfx::Point& location_in_screen) {
184 // PointerWatcher supports tracking events outside the root window in mash.
185 Close();
186 }
187
171 void ShelfTooltipManager::OnEvent(ui::Event* event) { 188 void ShelfTooltipManager::OnEvent(ui::Event* event) {
172 if (event->type() == ui::ET_MOUSE_PRESSED || 189 if (event->type() == ui::ET_MOUSE_PRESSED ||
James Cook 2016/05/04 19:17:49 Eliminate this one, as it's confusing that there a
msw 2016/05/04 20:07:49 Done. (Added early return for touch/mouse pressed)
173 event->type() == ui::ET_MOUSE_EXITED || !event->IsMouseEvent() || 190 event->type() == ui::ET_MOUSE_EXITED || !event->IsMouseEvent() ||
174 event->target() != shelf_view_->GetWidget()->GetNativeWindow()) { 191 event->target() != shelf_view_->GetWidget()->GetNativeWindow()) {
175 if (!event->IsKeyEvent()) 192 if (!event->IsKeyEvent())
176 Close(); 193 Close();
177 return; 194 return;
178 } 195 }
179 196
180 gfx::Point point = static_cast<ui::LocatedEvent*>(event)->location(); 197 gfx::Point point = static_cast<ui::LocatedEvent*>(event)->location();
181 aura::Window::ConvertPointToTarget( 198 aura::Window::ConvertPointToTarget(
182 static_cast<aura::Window*>(event->target()), 199 static_cast<aura::Window*>(event->target()),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // AutoHide state change happens during an event filter, so immediate close 238 // AutoHide state change happens during an event filter, so immediate close
222 // may cause a crash in the HandleMouseEvent() after the filter. So we just 239 // may cause a crash in the HandleMouseEvent() after the filter. So we just
223 // schedule the Close here. 240 // schedule the Close here.
224 base::ThreadTaskRunnerHandle::Get()->PostTask( 241 base::ThreadTaskRunnerHandle::Get()->PostTask(
225 FROM_HERE, 242 FROM_HERE,
226 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); 243 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr()));
227 } 244 }
228 } 245 }
229 246
230 } // namespace ash 247 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_tooltip_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698