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/launcher/launcher_view.h" | 7 #include "ash/launcher/launcher_view.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/wm/window_animations.h" | 10 #include "ash/wm/window_animations.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 : public views::BubbleDelegateView { | 51 : public views::BubbleDelegateView { |
52 public: | 52 public: |
53 LauncherTooltipBubble(views::View* anchor, | 53 LauncherTooltipBubble(views::View* anchor, |
54 views::BubbleBorder::ArrowLocation arrow_location, | 54 views::BubbleBorder::ArrowLocation arrow_location, |
55 LauncherTooltipManager* host); | 55 LauncherTooltipManager* host); |
56 | 56 |
57 void SetText(const string16& text); | 57 void SetText(const string16& text); |
58 void Close(); | 58 void Close(); |
59 | 59 |
60 private: | 60 private: |
61 // views::WidgetDelegate overrides; | 61 // views::WidgetDelegate overrides: |
62 virtual void WindowClosing() OVERRIDE; | 62 virtual void WindowClosing() OVERRIDE; |
63 | 63 |
64 LauncherTooltipManager* host_; | 64 LauncherTooltipManager* host_; |
65 views::Label* label_; | 65 views::Label* label_; |
66 }; | 66 }; |
67 | 67 |
68 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble( | 68 LauncherTooltipManager::LauncherTooltipBubble::LauncherTooltipBubble( |
69 views::View* anchor, | 69 views::View* anchor, |
70 views::BubbleBorder::ArrowLocation arrow_location, | 70 views::BubbleBorder::ArrowLocation arrow_location, |
71 LauncherTooltipManager* host) | 71 LauncherTooltipManager* host) |
72 : views::BubbleDelegateView(anchor, arrow_location), | 72 : views::BubbleDelegateView(anchor, arrow_location), |
73 host_(host) { | 73 host_(host) { |
74 set_close_on_esc(false); | 74 set_close_on_esc(false); |
75 set_close_on_deactivate(false); | 75 set_close_on_deactivate(false); |
76 set_use_focusless(true); | 76 set_use_focusless(true); |
77 set_margins(gfx::Insets(kTooltipMargin, kTooltipMargin, kTooltipMargin, | 77 set_margins(gfx::Insets(kTooltipMargin, kTooltipMargin, kTooltipMargin, |
78 kTooltipMargin)); | 78 kTooltipMargin)); |
79 SetLayoutManager(new views::FillLayout()); | 79 SetLayoutManager(new views::FillLayout()); |
80 // The anchor may not have the widget in tests. | 80 // The anchor may not have the widget in tests. |
81 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { | 81 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { |
82 aura::RootWindow* root_window = | 82 aura::RootWindow* root_window = |
83 anchor->GetWidget()->GetNativeView()->GetRootWindow(); | 83 anchor->GetWidget()->GetNativeView()->GetRootWindow(); |
84 set_parent_window(ash::Shell::GetInstance()->GetContainer( | 84 set_parent_window(ash::Shell::GetInstance()->GetContainer( |
85 root_window, ash::internal::kShellWindowId_LauncherContainer)); | 85 root_window, ash::internal::kShellWindowId_SettingBubbleContainer)); |
86 } | 86 } |
87 label_ = new views::Label; | 87 label_ = new views::Label; |
88 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 88 label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
89 AddChildView(label_); | 89 AddChildView(label_); |
90 } | 90 } |
91 | 91 |
92 void LauncherTooltipManager::LauncherTooltipBubble::SetText( | 92 void LauncherTooltipManager::LauncherTooltipBubble::SetText( |
93 const string16& text) { | 93 const string16& text) { |
94 label_->SetText(text); | 94 label_->SetText(text); |
95 label_->SetMultiLine(true); | 95 label_->SetMultiLine(true); |
(...skipping 24 matching lines...) Expand all Loading... |
120 alignment_(alignment), | 120 alignment_(alignment), |
121 shelf_layout_manager_(shelf_layout_manager), | 121 shelf_layout_manager_(shelf_layout_manager), |
122 launcher_view_(launcher_view) { | 122 launcher_view_(launcher_view) { |
123 if (shelf_layout_manager) | 123 if (shelf_layout_manager) |
124 shelf_layout_manager->AddObserver(this); | 124 shelf_layout_manager->AddObserver(this); |
125 if (Shell::HasInstance()) | 125 if (Shell::HasInstance()) |
126 Shell::GetInstance()->AddEnvEventFilter(this); | 126 Shell::GetInstance()->AddEnvEventFilter(this); |
127 } | 127 } |
128 | 128 |
129 LauncherTooltipManager::~LauncherTooltipManager() { | 129 LauncherTooltipManager::~LauncherTooltipManager() { |
| 130 CancelHidingAnimation(); |
130 Close(); | 131 Close(); |
131 if (shelf_layout_manager_) | 132 if (shelf_layout_manager_) |
132 shelf_layout_manager_->RemoveObserver(this); | 133 shelf_layout_manager_->RemoveObserver(this); |
133 if (Shell::HasInstance()) | 134 if (Shell::HasInstance()) |
134 Shell::GetInstance()->RemoveEnvEventFilter(this); | 135 Shell::GetInstance()->RemoveEnvEventFilter(this); |
135 } | 136 } |
136 | 137 |
137 void LauncherTooltipManager::ShowDelayed(views::View* anchor, | 138 void LauncherTooltipManager::ShowDelayed(views::View* anchor, |
138 const string16& text) { | 139 const string16& text) { |
139 if (view_) { | 140 if (view_) { |
140 if (timer_.get() && timer_->IsRunning()) | 141 if (timer_.get() && timer_->IsRunning()) |
141 return; | 142 return; |
142 else | 143 else { |
| 144 CancelHidingAnimation(); |
143 Close(); | 145 Close(); |
| 146 } |
144 } | 147 } |
145 | 148 |
146 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) | 149 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) |
147 return; | 150 return; |
148 | 151 |
149 CreateBubble(anchor, text); | 152 CreateBubble(anchor, text); |
150 gfx::NativeView native_view = widget_->GetNativeView(); | |
151 SetWindowVisibilityAnimationType( | |
152 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | |
153 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_SHOW); | |
154 ResetTimer(); | 153 ResetTimer(); |
155 } | 154 } |
156 | 155 |
157 void LauncherTooltipManager::ShowImmediately(views::View* anchor, | 156 void LauncherTooltipManager::ShowImmediately(views::View* anchor, |
158 const string16& text) { | 157 const string16& text) { |
159 if (view_) { | 158 if (view_) { |
160 if (timer_.get() && timer_->IsRunning()) | 159 if (timer_.get() && timer_->IsRunning()) |
161 StopTimer(); | 160 StopTimer(); |
| 161 CancelHidingAnimation(); |
162 Close(); | 162 Close(); |
163 } | 163 } |
164 | 164 |
165 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) | 165 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) |
166 return; | 166 return; |
167 | 167 |
168 CreateBubble(anchor, text); | 168 CreateBubble(anchor, text); |
169 gfx::NativeView native_view = widget_->GetNativeView(); | |
170 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE); | |
171 ShowInternal(); | 169 ShowInternal(); |
172 } | 170 } |
173 | 171 |
174 void LauncherTooltipManager::Close() { | 172 void LauncherTooltipManager::Close() { |
| 173 StopTimer(); |
175 if (view_) { | 174 if (view_) { |
176 view_->Close(); | 175 view_->Close(); |
177 view_ = NULL; | 176 view_ = NULL; |
178 widget_ = NULL; | 177 widget_ = NULL; |
179 } | 178 } |
180 } | 179 } |
181 | 180 |
182 void LauncherTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) { | 181 void LauncherTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) { |
183 if (view == view_) { | 182 if (view == view_) { |
184 view_ = NULL; | 183 view_ = NULL; |
185 widget_ = NULL; | 184 widget_ = NULL; |
186 } | 185 } |
187 } | 186 } |
188 | 187 |
189 void LauncherTooltipManager::SetArrowLocation(ShelfAlignment alignment) { | 188 void LauncherTooltipManager::SetArrowLocation(ShelfAlignment alignment) { |
190 if (alignment_ == alignment) | 189 if (alignment_ == alignment) |
191 return; | 190 return; |
192 | 191 |
193 alignment_ = alignment; | 192 alignment_ = alignment; |
194 if (view_) { | 193 if (view_) { |
| 194 CancelHidingAnimation(); |
195 Close(); | 195 Close(); |
196 ShowImmediately(anchor_, text_); | 196 ShowImmediately(anchor_, text_); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 void LauncherTooltipManager::ResetTimer() { | 200 void LauncherTooltipManager::ResetTimer() { |
201 if (timer_.get() && timer_->IsRunning()) { | 201 if (timer_.get() && timer_->IsRunning()) { |
202 timer_->Reset(); | 202 timer_->Reset(); |
203 return; | 203 return; |
204 } | 204 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 ShelfLayoutManager::AutoHideState new_state) { | 303 ShelfLayoutManager::AutoHideState new_state) { |
304 if (new_state == ShelfLayoutManager::AUTO_HIDE_HIDDEN) { | 304 if (new_state == ShelfLayoutManager::AUTO_HIDE_HIDDEN) { |
305 StopTimer(); | 305 StopTimer(); |
306 // AutoHide state change happens during an event filter, so immediate close | 306 // AutoHide state change happens during an event filter, so immediate close |
307 // may cause a crash in the HandleMouseEvent() after the filter. So we just | 307 // may cause a crash in the HandleMouseEvent() after the filter. So we just |
308 // schedule the Close here. | 308 // schedule the Close here. |
309 CloseSoon(); | 309 CloseSoon(); |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
| 313 void LauncherTooltipManager::CancelHidingAnimation() { |
| 314 if (!widget_ || !widget_->GetNativeView()) |
| 315 return; |
| 316 |
| 317 gfx::NativeView native_view = widget_->GetNativeView(); |
| 318 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_NONE); |
| 319 } |
| 320 |
313 void LauncherTooltipManager::CloseSoon() { | 321 void LauncherTooltipManager::CloseSoon() { |
314 MessageLoopForUI::current()->PostTask( | 322 MessageLoopForUI::current()->PostTask( |
315 FROM_HERE, | 323 FROM_HERE, |
316 base::Bind(&LauncherTooltipManager::Close, base::Unretained(this))); | 324 base::Bind(&LauncherTooltipManager::Close, base::Unretained(this))); |
317 } | 325 } |
318 | 326 |
319 void LauncherTooltipManager::ShowInternal() { | 327 void LauncherTooltipManager::ShowInternal() { |
320 if (view_) | 328 if (view_) |
321 view_->Show(); | 329 view_->Show(); |
322 | 330 |
323 timer_.reset(); | 331 timer_.reset(); |
324 } | 332 } |
325 | 333 |
326 void LauncherTooltipManager::CreateBubble(views::View* anchor, | 334 void LauncherTooltipManager::CreateBubble(views::View* anchor, |
327 const string16& text) { | 335 const string16& text) { |
328 DCHECK(!view_); | 336 DCHECK(!view_); |
329 | 337 |
330 anchor_ = anchor; | 338 anchor_ = anchor; |
331 text_ = text; | 339 text_ = text; |
332 view_ = new LauncherTooltipBubble( | 340 view_ = new LauncherTooltipBubble( |
333 anchor, GetArrowLocation(alignment_), this); | 341 anchor, GetArrowLocation(alignment_), this); |
334 views::BubbleDelegateView::CreateBubble(view_); | 342 views::BubbleDelegateView::CreateBubble(view_); |
335 widget_ = view_->GetWidget(); | 343 widget_ = view_->GetWidget(); |
336 view_->SetText(text_); | 344 view_->SetText(text_); |
| 345 |
| 346 gfx::NativeView native_view = widget_->GetNativeView(); |
| 347 SetWindowVisibilityAnimationType( |
| 348 native_view, WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
| 349 SetWindowVisibilityAnimationTransition(native_view, ANIMATE_HIDE); |
337 } | 350 } |
338 | 351 |
339 } // namespace internal | 352 } // namespace internal |
340 } // namespace ash | 353 } // namespace ash |
OLD | NEW |