OLD | NEW |
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 "mash/shelf/shelf_tooltip_manager.h" |
6 | 6 |
7 #include "ash/shelf/shelf_layout_manager.h" | |
8 #include "ash/shelf/shelf_view.h" | |
9 #include "ash/shell.h" | |
10 #include "ash/shell_window_ids.h" | |
11 #include "ash/wm/window_animations.h" | |
12 #include "base/bind.h" | 7 #include "base/bind.h" |
13 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
14 #include "base/time/time.h" | 9 #include "base/time/time.h" |
15 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 11 #include "components/mus/public/cpp/property_type_converters.h" |
| 12 #include "mash/shelf/shelf_view.h" |
| 13 #include "mash/wm/public/interfaces/container.mojom.h" |
| 14 #include "mojo/shell/public/cpp/application_impl.h" |
16 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
17 #include "ui/aura/window_event_dispatcher.h" | |
18 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
19 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
20 #include "ui/gfx/geometry/insets.h" | 18 #include "ui/gfx/geometry/insets.h" |
21 #include "ui/views/bubble/bubble_delegate.h" | 19 #include "ui/views/bubble/bubble_delegate.h" |
22 #include "ui/views/bubble/bubble_frame_view.h" | |
23 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/fill_layout.h" | 21 #include "ui/views/layout/fill_layout.h" |
| 22 #include "ui/views/mus/native_widget_mus.h" |
| 23 #include "ui/views/mus/window_manager_connection.h" |
25 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 25 #include "ui/wm/core/window_animations.h" |
26 | 26 |
27 namespace ash { | 27 namespace mash { |
| 28 namespace shelf { |
28 namespace { | 29 namespace { |
29 const int kTooltipTopBottomMargin = 3; | 30 const int kTooltipTopBottomMargin = 3; |
30 const int kTooltipLeftRightMargin = 10; | 31 const int kTooltipLeftRightMargin = 10; |
31 const int kTooltipAppearanceDelay = 1000; // msec | 32 const int kTooltipAppearanceDelay = 1000; // msec |
32 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin; | 33 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin; |
33 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); | 34 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); |
34 | 35 |
35 // The maximum width of the tooltip bubble. Borrowed the value from | 36 // The maximum width of the tooltip bubble. Borrowed the value from |
36 // ash/tooltip/tooltip_controller.cc | 37 // ash/tooltip/tooltip_controller.cc |
37 const int kTooltipMaxWidth = 250; | 38 const int kTooltipMaxWidth = 250; |
38 | 39 |
39 // The offset for the tooltip bubble - making sure that the bubble is flush | 40 // The offset for the tooltip bubble - making sure that the bubble is flush |
40 // with the shelf. The offset includes the arrow size in pixels as well as | 41 // with the shelf. The offset includes the arrow size in pixels as well as |
41 // the activation bar and other spacing elements. | 42 // the activation bar and other spacing elements. |
42 const int kArrowOffsetLeftRight = 11; | 43 const int kArrowOffsetLeftRight = 11; |
43 const int kArrowOffsetTopBottom = 7; | 44 const int kArrowOffsetTopBottom = 7; |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 // The implementation of tooltip of the launcher. | 48 // The implementation of tooltip of the launcher. |
48 class ShelfTooltipManager::ShelfTooltipBubble | 49 class ShelfTooltipManager::ShelfTooltipBubble |
49 : public views::BubbleDelegateView { | 50 : public views::BubbleDelegateView { |
50 public: | 51 public: |
51 ShelfTooltipBubble(views::View* anchor, | 52 ShelfTooltipBubble(views::View* anchor, |
52 views::BubbleBorder::Arrow arrow, | 53 views::BubbleBorder::Arrow arrow, |
53 ShelfTooltipManager* host); | 54 const base::string16& text, |
| 55 ShelfTooltipManager* host); |
54 | 56 |
55 void SetText(const base::string16& text); | 57 void SetText(const base::string16& text); |
56 void Close(); | 58 void Close(); |
57 | 59 |
58 private: | 60 private: |
| 61 // views::BubbleDelegateView overrides: |
| 62 void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, |
| 63 views::Widget* widget) const override; |
| 64 |
59 // views::WidgetDelegate overrides: | 65 // views::WidgetDelegate overrides: |
| 66 bool ShouldShowWindowTitle() const override; |
60 void WindowClosing() override; | 67 void WindowClosing() override; |
61 | 68 |
62 // views::View overrides: | 69 // views::View overrides: |
63 gfx::Size GetPreferredSize() const override; | 70 gfx::Size GetPreferredSize() const override; |
64 | 71 |
65 ShelfTooltipManager* host_; | 72 ShelfTooltipManager* host_; |
66 views::Label* label_; | 73 views::Label* label_; |
67 | 74 |
68 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); | 75 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); |
69 }; | 76 }; |
70 | 77 |
71 ShelfTooltipManager::ShelfTooltipBubble::ShelfTooltipBubble( | 78 ShelfTooltipManager::ShelfTooltipBubble::ShelfTooltipBubble( |
72 views::View* anchor, | 79 views::View* anchor, |
73 views::BubbleBorder::Arrow arrow, | 80 views::BubbleBorder::Arrow arrow, |
| 81 const base::string16& text, |
74 ShelfTooltipManager* host) | 82 ShelfTooltipManager* host) |
75 : views::BubbleDelegateView(anchor, arrow), host_(host) { | 83 : views::BubbleDelegateView(anchor, arrow), host_(host) { |
76 gfx::Insets insets = gfx::Insets(kArrowOffsetTopBottom, | 84 gfx::Insets insets = gfx::Insets(kArrowOffsetTopBottom, |
77 kArrowOffsetLeftRight, | 85 kArrowOffsetLeftRight, |
78 kArrowOffsetTopBottom, | 86 kArrowOffsetTopBottom, |
79 kArrowOffsetLeftRight); | 87 kArrowOffsetLeftRight); |
80 // Shelf items can have an asymmetrical border for spacing reasons. | 88 // Shelf items can have an asymmetrical border for spacing reasons. |
81 // Adjust anchor location for this. | 89 // Adjust anchor location for this. |
82 if (anchor->border()) | 90 if (anchor->border()) |
83 insets += anchor->border()->GetInsets(); | 91 insets += anchor->border()->GetInsets(); |
84 | 92 |
85 set_anchor_view_insets(insets); | 93 set_anchor_view_insets(insets); |
86 set_close_on_esc(false); | 94 set_close_on_esc(false); |
87 set_close_on_deactivate(false); | 95 set_close_on_deactivate(false); |
88 set_can_activate(false); | 96 set_can_activate(false); |
89 set_accept_events(false); | 97 set_accept_events(false); |
90 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin, | 98 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin, |
91 kTooltipTopBottomMargin, kTooltipLeftRightMargin)); | 99 kTooltipTopBottomMargin, kTooltipLeftRightMargin)); |
92 set_shadow(views::BubbleBorder::SMALL_SHADOW); | 100 set_shadow(views::BubbleBorder::SMALL_SHADOW); |
93 SetLayoutManager(new views::FillLayout()); | 101 SetLayoutManager(new views::FillLayout()); |
94 // The anchor may not have the widget in tests. | 102 label_ = new views::Label(text); |
95 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeView()) { | |
96 aura::Window* root_window = | |
97 anchor->GetWidget()->GetNativeView()->GetRootWindow(); | |
98 set_parent_window(ash::Shell::GetInstance()->GetContainer( | |
99 root_window, ash::kShellWindowId_SettingBubbleContainer)); | |
100 } | |
101 label_ = new views::Label; | |
102 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 103 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
103 label_->SetEnabledColor(kTooltipTextColor); | 104 label_->SetEnabledColor(kTooltipTextColor); |
104 AddChildView(label_); | 105 AddChildView(label_); |
105 views::BubbleDelegateView::CreateBubble(this); | 106 views::BubbleDelegateView::CreateBubble(this); |
106 } | 107 } |
107 | 108 |
108 void ShelfTooltipManager::ShelfTooltipBubble::SetText( | 109 void ShelfTooltipManager::ShelfTooltipBubble::Close() { |
109 const base::string16& text) { | 110 if (GetWidget()) { |
110 label_->SetText(text); | 111 host_ = nullptr; |
111 SizeToContents(); | 112 GetWidget()->Close(); |
| 113 } |
112 } | 114 } |
113 | 115 |
114 void ShelfTooltipManager::ShelfTooltipBubble::Close() { | 116 void ShelfTooltipManager::ShelfTooltipBubble::OnBeforeBubbleWidgetInit( |
115 if (GetWidget()) { | 117 views::Widget::InitParams* params, |
116 host_ = NULL; | 118 views::Widget* widget) const { |
117 GetWidget()->Close(); | 119 // Ensure the widget is treated as a tooltip by the window manager. |
118 } | 120 std::map<std::string, std::vector<uint8_t>> properties; |
| 121 properties[mash::wm::mojom::kWindowContainer_Property] = |
| 122 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert( |
| 123 static_cast<int32_t>(mash::wm::mojom::Container::TOOLTIPS)); |
| 124 mus::Window* window = |
| 125 views::WindowManagerConnection::Get()->NewWindow(properties); |
| 126 params->native_widget = new views::NativeWidgetMus( |
| 127 widget, host_->shelf_view()->app()->shell(), window, |
| 128 mus::mojom::SurfaceType::DEFAULT); |
119 } | 129 } |
120 | 130 |
121 void ShelfTooltipManager::ShelfTooltipBubble::WindowClosing() { | 131 void ShelfTooltipManager::ShelfTooltipBubble::WindowClosing() { |
122 views::BubbleDelegateView::WindowClosing(); | 132 views::BubbleDelegateView::WindowClosing(); |
123 if (host_) | 133 if (host_) |
124 host_->OnBubbleClosed(this); | 134 host_->OnBubbleClosed(this); |
125 } | 135 } |
126 | 136 |
| 137 bool ShelfTooltipManager::ShelfTooltipBubble::ShouldShowWindowTitle() const { |
| 138 return false; |
| 139 } |
| 140 |
127 gfx::Size ShelfTooltipManager::ShelfTooltipBubble::GetPreferredSize() const { | 141 gfx::Size ShelfTooltipManager::ShelfTooltipBubble::GetPreferredSize() const { |
128 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize(); | 142 gfx::Size pref_size = views::BubbleDelegateView::GetPreferredSize(); |
129 if (pref_size.height() < kTooltipMinHeight) | 143 if (pref_size.height() < kTooltipMinHeight) |
130 pref_size.set_height(kTooltipMinHeight); | 144 pref_size.set_height(kTooltipMinHeight); |
131 if (pref_size.width() > kTooltipMaxWidth) | 145 if (pref_size.width() > kTooltipMaxWidth) |
132 pref_size.set_width(kTooltipMaxWidth); | 146 pref_size.set_width(kTooltipMaxWidth); |
133 return pref_size; | 147 return pref_size; |
134 } | 148 } |
135 | 149 |
136 ShelfTooltipManager::ShelfTooltipManager( | 150 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) |
137 ShelfLayoutManager* shelf_layout_manager, | 151 : view_(nullptr), |
138 ShelfView* shelf_view) | 152 widget_(nullptr), |
139 : view_(NULL), | |
140 widget_(NULL), | |
141 anchor_(NULL), | |
142 shelf_layout_manager_(shelf_layout_manager), | |
143 shelf_view_(shelf_view), | 153 shelf_view_(shelf_view), |
144 weak_factory_(this) { | 154 weak_factory_(this) { |
145 if (shelf_layout_manager) | 155 // Ensure mouse movements between the shelf and its buttons isn't an exit. |
146 shelf_layout_manager->AddObserver(this); | 156 shelf_view_->set_notify_enter_exit_on_child(true); |
147 if (Shell::HasInstance()) | 157 shelf_view_->AddPreTargetHandler(this); |
148 Shell::GetInstance()->AddPreTargetHandler(this); | |
149 } | 158 } |
150 | 159 |
151 ShelfTooltipManager::~ShelfTooltipManager() { | 160 ShelfTooltipManager::~ShelfTooltipManager() { |
152 CancelHidingAnimation(); | 161 CancelHidingAnimation(); |
153 Close(); | 162 Close(); |
154 if (shelf_layout_manager_) | 163 shelf_view_->RemovePreTargetHandler(this); |
155 shelf_layout_manager_->RemoveObserver(this); | |
156 if (Shell::HasInstance()) | |
157 Shell::GetInstance()->RemovePreTargetHandler(this); | |
158 } | 164 } |
159 | 165 |
160 void ShelfTooltipManager::ShowDelayed(views::View* anchor, | 166 void ShelfTooltipManager::ShowDelayed(views::View* anchor, |
161 const base::string16& text) { | 167 const base::string16& text) { |
162 if (view_) { | 168 if (view_) { |
163 if (timer_.get() && timer_->IsRunning()) { | 169 if (timer_.get() && timer_->IsRunning()) { |
164 return; | 170 return; |
165 } else { | 171 } else { |
166 CancelHidingAnimation(); | 172 CancelHidingAnimation(); |
167 Close(); | 173 Close(); |
168 } | 174 } |
169 } | 175 } |
170 | 176 |
171 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) | 177 if (!shelf_view_->GetWidget() || !shelf_view_->GetWidget()->IsVisible()) |
172 return; | 178 return; |
173 | 179 |
174 CreateBubble(anchor, text); | 180 CreateBubble(anchor, text); |
175 ResetTimer(); | 181 ResetTimer(); |
176 } | 182 } |
177 | 183 |
178 void ShelfTooltipManager::ShowImmediately(views::View* anchor, | 184 void ShelfTooltipManager::ShowImmediately(views::View* anchor, |
179 const base::string16& text) { | 185 const base::string16& text) { |
180 if (view_) { | 186 if (view_) { |
181 if (timer_.get() && timer_->IsRunning()) | 187 if (timer_.get() && timer_->IsRunning()) |
182 StopTimer(); | 188 StopTimer(); |
183 CancelHidingAnimation(); | 189 CancelHidingAnimation(); |
184 Close(); | 190 Close(); |
185 } | 191 } |
186 | 192 |
187 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) | 193 if (!shelf_view_->GetWidget() || !shelf_view_->GetWidget()->IsVisible()) |
188 return; | 194 return; |
189 | 195 |
190 CreateBubble(anchor, text); | 196 CreateBubble(anchor, text); |
191 ShowInternal(); | 197 ShowInternal(); |
192 } | 198 } |
193 | 199 |
194 void ShelfTooltipManager::Close() { | 200 void ShelfTooltipManager::Close() { |
195 StopTimer(); | 201 StopTimer(); |
196 if (view_) { | 202 if (view_) { |
197 view_->Close(); | 203 view_->Close(); |
198 view_ = NULL; | 204 view_ = nullptr; |
199 widget_ = NULL; | 205 widget_ = nullptr; |
200 } | 206 } |
201 } | 207 } |
202 | 208 |
203 void ShelfTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) { | 209 void ShelfTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) { |
204 if (view == view_) { | 210 if (view == view_) { |
205 view_ = NULL; | 211 view_ = nullptr; |
206 widget_ = NULL; | 212 widget_ = nullptr; |
207 } | 213 } |
208 } | 214 } |
209 | 215 |
210 void ShelfTooltipManager::UpdateArrow() { | |
211 if (view_) { | |
212 CancelHidingAnimation(); | |
213 Close(); | |
214 ShowImmediately(anchor_, text_); | |
215 } | |
216 } | |
217 | |
218 void ShelfTooltipManager::ResetTimer() { | 216 void ShelfTooltipManager::ResetTimer() { |
219 if (timer_.get() && timer_->IsRunning()) { | 217 if (timer_.get() && timer_->IsRunning()) { |
220 timer_->Reset(); | 218 timer_->Reset(); |
221 return; | 219 return; |
222 } | 220 } |
223 | 221 |
224 // We don't start the timer if the shelf isn't visible. | 222 // We don't start the timer if the shelf isn't visible. |
225 if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) | 223 if (!shelf_view_->GetWidget() || !shelf_view_->GetWidget()->IsVisible()) |
226 return; | 224 return; |
227 | 225 |
228 CreateTimer(kTooltipAppearanceDelay); | 226 CreateTimer(kTooltipAppearanceDelay); |
229 } | 227 } |
230 | 228 |
231 void ShelfTooltipManager::StopTimer() { | 229 void ShelfTooltipManager::StopTimer() { |
232 timer_.reset(); | 230 timer_.reset(); |
233 } | 231 } |
234 | 232 |
235 bool ShelfTooltipManager::IsVisible() { | 233 bool ShelfTooltipManager::IsVisible() const { |
236 if (timer_.get() && timer_->IsRunning()) | 234 if (timer_.get() && timer_->IsRunning()) |
237 return false; | 235 return false; |
238 | 236 |
239 return widget_ && widget_->IsVisible(); | 237 return widget_ && widget_->IsVisible(); |
240 } | 238 } |
241 | 239 |
| 240 views::View* ShelfTooltipManager::GetCurrentAnchorView() const { |
| 241 return view_ ? view_->GetAnchorView() : nullptr; |
| 242 } |
| 243 |
242 void ShelfTooltipManager::CreateZeroDelayTimerForTest() { | 244 void ShelfTooltipManager::CreateZeroDelayTimerForTest() { |
243 CreateTimer(0); | 245 CreateTimer(0); |
244 } | 246 } |
245 | 247 |
246 void ShelfTooltipManager::OnMouseEvent(ui::MouseEvent* event) { | 248 void ShelfTooltipManager::OnMouseEvent(ui::MouseEvent* event) { |
247 DCHECK(event); | 249 DCHECK(event); |
248 DCHECK(event->target()); | 250 DCHECK(event->target()); |
249 if (!widget_ || !widget_->IsVisible()) | 251 if (!widget_ || !widget_->IsVisible()) |
250 return; | 252 return; |
251 | 253 |
252 DCHECK(view_); | 254 DCHECK(view_); |
253 DCHECK(shelf_view_); | 255 DCHECK(shelf_view_); |
254 | 256 |
255 // Pressing the mouse button anywhere should close the tooltip. | 257 // Close the tooltip when the mouse is pressed or exits the shelf view area. |
256 if (event->type() == ui::ET_MOUSE_PRESSED) { | 258 if (event->type() == ui::ET_MOUSE_PRESSED || |
| 259 (event->type() == ui::ET_MOUSE_EXITED && |
| 260 event->target() == shelf_view_)) { |
257 CloseSoon(); | 261 CloseSoon(); |
258 return; | 262 return; |
259 } | 263 } |
260 | 264 |
261 aura::Window* target = static_cast<aura::Window*>(event->target()); | 265 gfx::Point location = event->location(); |
262 if (widget_->GetNativeWindow()->GetRootWindow() != target->GetRootWindow()) { | 266 views::View* target = static_cast<views::View*>(event->target()); |
263 CloseSoon(); | 267 views::View::ConvertPointToTarget(target, shelf_view_, &location); |
264 return; | 268 if (shelf_view_->ShouldHideTooltip(location)) { |
265 } | |
266 | |
267 gfx::Point location_in_shelf_view = event->location(); | |
268 aura::Window::ConvertPointToTarget( | |
269 target, shelf_view_->GetWidget()->GetNativeWindow(), | |
270 &location_in_shelf_view); | |
271 | |
272 if (shelf_view_->ShouldHideTooltip(location_in_shelf_view)) { | |
273 // Because this mouse event may arrive to |view_|, here we just schedule | 269 // Because this mouse event may arrive to |view_|, here we just schedule |
274 // the closing event rather than directly calling Close(). | 270 // the closing event rather than directly calling Close(). |
275 CloseSoon(); | 271 CloseSoon(); |
276 } | 272 } |
277 } | 273 } |
278 | 274 |
279 void ShelfTooltipManager::OnTouchEvent(ui::TouchEvent* event) { | 275 void ShelfTooltipManager::OnTouchEvent(ui::TouchEvent* event) { |
280 aura::Window* target = static_cast<aura::Window*>(event->target()); | 276 // TODO(msw): Fix this; touch events outside the shelf are not captured. |
| 277 views::View* view = static_cast<views::View*>(event->target()); |
| 278 aura::Window* target = view->GetWidget()->GetNativeWindow(); |
281 if (widget_ && widget_->IsVisible() && widget_->GetNativeWindow() != target) | 279 if (widget_ && widget_->IsVisible() && widget_->GetNativeWindow() != target) |
282 Close(); | 280 Close(); |
283 } | 281 } |
284 | 282 |
285 void ShelfTooltipManager::OnGestureEvent(ui::GestureEvent* event) { | 283 void ShelfTooltipManager::OnGestureEvent(ui::GestureEvent* event) { |
286 if (widget_ && widget_->IsVisible()) { | 284 if (widget_ && widget_->IsVisible()) { |
287 // Because this mouse event may arrive to |view_|, here we just schedule | 285 // Because this mouse event may arrive to |view_|, here we just schedule |
288 // the closing event rather than directly calling Close(). | 286 // the closing event rather than directly calling Close(). |
289 CloseSoon(); | 287 CloseSoon(); |
290 } | 288 } |
291 } | 289 } |
292 | 290 |
293 void ShelfTooltipManager::OnCancelMode(ui::CancelModeEvent* event) { | 291 void ShelfTooltipManager::OnCancelMode(ui::CancelModeEvent* event) { |
294 Close(); | 292 Close(); |
295 } | 293 } |
296 | 294 |
297 void ShelfTooltipManager::WillDeleteShelf() { | 295 /* TODO(msw): Restore functionality: |
298 shelf_layout_manager_ = NULL; | |
299 } | |
300 | |
301 void ShelfTooltipManager::WillChangeVisibilityState( | 296 void ShelfTooltipManager::WillChangeVisibilityState( |
302 ShelfVisibilityState new_state) { | 297 ShelfVisibilityState new_state) { |
303 if (new_state == SHELF_HIDDEN) { | 298 if (new_state == SHELF_HIDDEN) { |
304 StopTimer(); | 299 StopTimer(); |
305 Close(); | 300 Close(); |
306 } | 301 } |
307 } | 302 } |
308 | 303 |
309 void ShelfTooltipManager::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 304 void ShelfTooltipManager::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
310 if (new_state == SHELF_AUTO_HIDE_HIDDEN) { | 305 if (new_state == SHELF_AUTO_HIDE_HIDDEN) { |
311 StopTimer(); | 306 StopTimer(); |
312 // AutoHide state change happens during an event filter, so immediate close | 307 // AutoHide state change happens during an event filter, so immediate close |
313 // may cause a crash in the HandleMouseEvent() after the filter. So we just | 308 // may cause a crash in the HandleMouseEvent() after the filter. So we just |
314 // schedule the Close here. | 309 // schedule the Close here. |
315 CloseSoon(); | 310 CloseSoon(); |
316 } | 311 } |
317 } | 312 }*/ |
318 | 313 |
319 void ShelfTooltipManager::CancelHidingAnimation() { | 314 void ShelfTooltipManager::CancelHidingAnimation() { |
320 if (!widget_ || !widget_->GetNativeView()) | 315 if (!widget_ || !widget_->GetNativeView()) |
321 return; | 316 return; |
322 | 317 |
323 gfx::NativeView native_view = widget_->GetNativeView(); | 318 ::wm::SetWindowVisibilityAnimationTransition(widget_->GetNativeView(), |
324 wm::SetWindowVisibilityAnimationTransition( | 319 ::wm::ANIMATE_NONE); |
325 native_view, wm::ANIMATE_NONE); | |
326 } | 320 } |
327 | 321 |
328 void ShelfTooltipManager::CloseSoon() { | 322 void ShelfTooltipManager::CloseSoon() { |
329 base::MessageLoopForUI::current()->PostTask( | 323 base::MessageLoop::current()->PostTask( |
330 FROM_HERE, | 324 FROM_HERE, |
331 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); | 325 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); |
332 } | 326 } |
333 | 327 |
334 void ShelfTooltipManager::ShowInternal() { | 328 void ShelfTooltipManager::ShowInternal() { |
335 if (view_) | 329 if (view_) |
336 view_->GetWidget()->Show(); | 330 view_->GetWidget()->Show(); |
337 | 331 |
338 timer_.reset(); | 332 timer_.reset(); |
339 } | 333 } |
340 | 334 |
341 void ShelfTooltipManager::CreateBubble(views::View* anchor, | 335 void ShelfTooltipManager::CreateBubble(views::View* anchor, |
342 const base::string16& text) { | 336 const base::string16& text) { |
343 DCHECK(!view_); | 337 DCHECK(!view_); |
344 | 338 views::BubbleBorder::Arrow arrow = shelf_view_->SelectValueForShelfAlignment( |
345 anchor_ = anchor; | 339 views::BubbleBorder::BOTTOM_CENTER, views::BubbleBorder::LEFT_CENTER, |
346 text_ = text; | 340 views::BubbleBorder::RIGHT_CENTER, views::BubbleBorder::TOP_CENTER); |
347 views::BubbleBorder::Arrow arrow = | 341 view_ = new ShelfTooltipBubble(anchor, arrow, text, this); |
348 shelf_layout_manager_->SelectValueForShelfAlignment( | |
349 views::BubbleBorder::BOTTOM_CENTER, | |
350 views::BubbleBorder::LEFT_CENTER, | |
351 views::BubbleBorder::RIGHT_CENTER, | |
352 views::BubbleBorder::TOP_CENTER); | |
353 | |
354 view_ = new ShelfTooltipBubble(anchor, arrow, this); | |
355 widget_ = view_->GetWidget(); | 342 widget_ = view_->GetWidget(); |
356 view_->SetText(text_); | |
357 | 343 |
358 gfx::NativeView native_view = widget_->GetNativeView(); | 344 gfx::NativeView native_view = widget_->GetNativeView(); |
359 wm::SetWindowVisibilityAnimationType( | 345 ::wm::SetWindowVisibilityAnimationType( |
360 native_view, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | 346 native_view, ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
361 wm::SetWindowVisibilityAnimationTransition( | 347 ::wm::SetWindowVisibilityAnimationTransition( |
362 native_view, wm::ANIMATE_HIDE); | 348 native_view, ::wm::ANIMATE_HIDE); |
363 } | 349 } |
364 | 350 |
365 void ShelfTooltipManager::CreateTimer(int delay_in_ms) { | 351 void ShelfTooltipManager::CreateTimer(int delay_in_ms) { |
366 base::OneShotTimer* new_timer = new base::OneShotTimer(); | 352 base::OneShotTimer* new_timer = new base::OneShotTimer(); |
367 new_timer->Start(FROM_HERE, | 353 new_timer->Start(FROM_HERE, |
368 base::TimeDelta::FromMilliseconds(delay_in_ms), | 354 base::TimeDelta::FromMilliseconds(delay_in_ms), |
369 this, | 355 this, |
370 &ShelfTooltipManager::ShowInternal); | 356 &ShelfTooltipManager::ShowInternal); |
371 timer_.reset(new_timer); | 357 timer_.reset(new_timer); |
372 } | 358 } |
373 | 359 |
374 } // namespace ash | 360 } // namespace shelf |
| 361 } // namespace mash |
OLD | NEW |