OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/launcher/launcher_tooltip_manager.h" | 5 #include "ash/launcher/launcher_tooltip_manager.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/wm/window_animations.h" | 9 #include "ash/wm/window_animations.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/message_loop.h" |
10 #include "base/time.h" | 12 #include "base/time.h" |
11 #include "base/timer.h" | 13 #include "base/timer.h" |
12 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
13 #include "ui/views/bubble/bubble_delegate.h" | 15 #include "ui/views/bubble/bubble_delegate.h" |
14 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
15 #include "ui/views/layout/fill_layout.h" | 17 #include "ui/views/layout/fill_layout.h" |
16 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 namespace internal { | 21 namespace internal { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const views::MouseEvent& event) { | 97 const views::MouseEvent& event) { |
96 GetWidget()->Close(); | 98 GetWidget()->Close(); |
97 host_->OnBubbleClosed(this); | 99 host_->OnBubbleClosed(this); |
98 } | 100 } |
99 | 101 |
100 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { | 102 void LauncherTooltipManager::LauncherTooltipBubble::WindowClosing() { |
101 views::BubbleDelegateView::WindowClosing(); | 103 views::BubbleDelegateView::WindowClosing(); |
102 host_->OnBubbleClosed(this); | 104 host_->OnBubbleClosed(this); |
103 } | 105 } |
104 | 106 |
105 LauncherTooltipManager::LauncherTooltipManager(ShelfAlignment alignment) | 107 LauncherTooltipManager::LauncherTooltipManager( |
| 108 ShelfAlignment alignment, ShelfLayoutManager* shelf_layout_manager) |
106 : view_(NULL), | 109 : view_(NULL), |
107 anchor_(NULL), | 110 anchor_(NULL), |
108 alignment_(alignment) {} | 111 alignment_(alignment), |
| 112 shelf_layout_manager_(shelf_layout_manager) { |
| 113 if (shelf_layout_manager) |
| 114 shelf_layout_manager->AddObserver(this); |
| 115 } |
109 | 116 |
110 LauncherTooltipManager::~LauncherTooltipManager() { | 117 LauncherTooltipManager::~LauncherTooltipManager() { |
111 Close(); | 118 Close(); |
| 119 if (shelf_layout_manager_) |
| 120 shelf_layout_manager_->RemoveObserver(this); |
112 } | 121 } |
113 | 122 |
114 void LauncherTooltipManager::ShowDelayed(views::View* anchor, | 123 void LauncherTooltipManager::ShowDelayed(views::View* anchor, |
115 const string16& text) { | 124 const string16& text) { |
116 if (view_) { | 125 if (view_) { |
117 if (timer_.get() && timer_->IsRunning()) | 126 if (timer_.get() && timer_->IsRunning()) |
118 return; | 127 return; |
119 else | 128 else |
120 Close(); | 129 Close(); |
121 } | 130 } |
122 | 131 |
| 132 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) |
| 133 return; |
| 134 |
123 CreateBubble(anchor, text); | 135 CreateBubble(anchor, text); |
124 gfx::NativeView native_view = view_->GetWidget()->GetNativeView(); | 136 gfx::NativeView native_view = view_->GetWidget()->GetNativeView(); |
125 SetWindowVisibilityAnimationType( | 137 SetWindowVisibilityAnimationType( |
126 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | 138 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
127 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_SHOW); | 139 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_SHOW); |
128 ResetTimer(); | 140 ResetTimer(); |
129 } | 141 } |
130 | 142 |
131 void LauncherTooltipManager::ShowImmediately(views::View* anchor, | 143 void LauncherTooltipManager::ShowImmediately(views::View* anchor, |
132 const string16& text) { | 144 const string16& text) { |
133 if (view_ && IsVisible()) | 145 if (view_) { |
134 Close(); | 146 if (timer_.get() && timer_->IsRunning()) |
| 147 StopTimer(); |
| 148 Close(); |
| 149 } |
| 150 |
| 151 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) |
| 152 return; |
135 | 153 |
136 CreateBubble(anchor, text); | 154 CreateBubble(anchor, text); |
137 gfx::NativeView native_view = view_->GetWidget()->GetNativeView(); | 155 gfx::NativeView native_view = view_->GetWidget()->GetNativeView(); |
138 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE); | 156 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE); |
139 ShowInternal(); | 157 ShowInternal(); |
140 } | 158 } |
141 | 159 |
142 void LauncherTooltipManager::Close() { | 160 void LauncherTooltipManager::Close() { |
143 if (view_) { | 161 if (view_) { |
144 view_->GetWidget()->Close(); | 162 view_->GetWidget()->Close(); |
(...skipping 17 matching lines...) Expand all Loading... |
162 ShowImmediately(anchor_, text_); | 180 ShowImmediately(anchor_, text_); |
163 } | 181 } |
164 } | 182 } |
165 | 183 |
166 void LauncherTooltipManager::ResetTimer() { | 184 void LauncherTooltipManager::ResetTimer() { |
167 if (timer_.get() && timer_->IsRunning()) { | 185 if (timer_.get() && timer_->IsRunning()) { |
168 timer_->Reset(); | 186 timer_->Reset(); |
169 return; | 187 return; |
170 } | 188 } |
171 | 189 |
| 190 // We don't start the timer if the shelf isn't visible. |
| 191 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) |
| 192 return; |
| 193 |
172 base::OneShotTimer<LauncherTooltipManager>* new_timer = | 194 base::OneShotTimer<LauncherTooltipManager>* new_timer = |
173 new base::OneShotTimer<LauncherTooltipManager>(); | 195 new base::OneShotTimer<LauncherTooltipManager>(); |
174 new_timer->Start( | 196 new_timer->Start( |
175 FROM_HERE, | 197 FROM_HERE, |
176 base::TimeDelta::FromMilliseconds(kTooltipAppearanceDelay), | 198 base::TimeDelta::FromMilliseconds(kTooltipAppearanceDelay), |
177 this, | 199 this, |
178 &LauncherTooltipManager::ShowInternal); | 200 &LauncherTooltipManager::ShowInternal); |
179 timer_.reset(new_timer); | 201 timer_.reset(new_timer); |
180 } | 202 } |
181 | 203 |
182 void LauncherTooltipManager::StopTimer() { | 204 void LauncherTooltipManager::StopTimer() { |
183 timer_.reset(); | 205 timer_.reset(); |
184 } | 206 } |
185 | 207 |
186 bool LauncherTooltipManager::IsVisible() { | 208 bool LauncherTooltipManager::IsVisible() { |
187 if (timer_.get() && timer_->IsRunning()) | 209 if (timer_.get() && timer_->IsRunning()) |
188 return false; | 210 return false; |
189 | 211 |
190 return view_ && view_->GetWidget() && view_->GetWidget()->IsVisible(); | 212 return view_ && view_->GetWidget() && view_->GetWidget()->IsVisible(); |
191 } | 213 } |
192 | 214 |
| 215 void LauncherTooltipManager::WillVisibilityStateChange( |
| 216 ShelfLayoutManager::VisibilityState new_state) { |
| 217 if (new_state == ShelfLayoutManager::HIDDEN) { |
| 218 StopTimer(); |
| 219 Close(); |
| 220 } |
| 221 } |
| 222 |
| 223 void LauncherTooltipManager::OnAutoHideStateChanged( |
| 224 ShelfLayoutManager::AutoHideState new_state) { |
| 225 if (new_state == ShelfLayoutManager::AUTO_HIDE_HIDDEN) { |
| 226 StopTimer(); |
| 227 // AutoHide state change happens during an event filter, so immediate close |
| 228 // may cause a crash in the HandleMouseEvent() after the filter. So we just |
| 229 // schedule the Close here. |
| 230 MessageLoopForUI::current()->PostTask( |
| 231 FROM_HERE, |
| 232 base::Bind(&LauncherTooltipManager::Close, base::Unretained(this))); |
| 233 } |
| 234 } |
| 235 |
193 void LauncherTooltipManager::ShowInternal() { | 236 void LauncherTooltipManager::ShowInternal() { |
194 if (view_) | 237 if (view_) |
195 view_->Show(); | 238 view_->Show(); |
196 | 239 |
197 timer_.reset(); | 240 timer_.reset(); |
198 } | 241 } |
199 | 242 |
200 void LauncherTooltipManager::CreateBubble(views::View* anchor, | 243 void LauncherTooltipManager::CreateBubble(views::View* anchor, |
201 const string16& text) { | 244 const string16& text) { |
202 DCHECK(!view_); | 245 DCHECK(!view_); |
203 | 246 |
204 anchor_ = anchor; | 247 anchor_ = anchor; |
205 text_ = text; | 248 text_ = text; |
206 view_ = new LauncherTooltipBubble( | 249 view_ = new LauncherTooltipBubble( |
207 anchor, GetArrowLocation(alignment_), this); | 250 anchor, GetArrowLocation(alignment_), this); |
208 views::BubbleDelegateView::CreateBubble(view_); | 251 views::BubbleDelegateView::CreateBubble(view_); |
209 view_->SetText(text_); | 252 view_->SetText(text_); |
210 } | 253 } |
211 | 254 |
212 } // namespace internal | 255 } // namespace internal |
213 } // namespace ash | 256 } // namespace ash |
OLD | NEW |