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/system/tray/system_tray_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.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/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 const int kShadowThickness = 4; | 40 const int kShadowThickness = 4; |
41 | 41 |
42 const int kBottomLineHeight = 1; | 42 const int kBottomLineHeight = 1; |
43 | 43 |
44 const int kSystemTrayBubbleHorizontalInset = 1; | 44 const int kSystemTrayBubbleHorizontalInset = 1; |
45 const int kSystemTrayBubbleVerticalInset = 1; | 45 const int kSystemTrayBubbleVerticalInset = 1; |
46 | 46 |
47 const int kArrowHeight = 10; | 47 const int kArrowHeight = 10; |
48 const int kArrowWidth = 20; | 48 const int kArrowWidth = 20; |
49 const int kArrowPaddingFromRight = 20; | 49 |
50 const int kArrowPaddingFromBottom = 17; | 50 // Inset the arrow a bit from the edge. |
51 const int kMinArrowOffset = 12; | 51 const int kArrowMinOffset = kArrowWidth / 2 + 4; |
52 | 52 |
53 const int kAnimationDurationForPopupMS = 200; | 53 const int kAnimationDurationForPopupMS = 200; |
54 | 54 |
55 // Normally a detailed view is the same size as the default view. However, | 55 // Normally a detailed view is the same size as the default view. However, |
56 // when showing a detailed view directly (e.g. clicking on a notification), | 56 // when showing a detailed view directly (e.g. clicking on a notification), |
57 // we may not know the height of the default view, or the default view may | 57 // we may not know the height of the default view, or the default view may |
58 // be too short, so we use this as a default and minimum height for any | 58 // be too short, so we use this as a default and minimum height for any |
59 // detailed view. | 59 // detailed view. |
60 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; | 60 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
61 | 61 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 }; | 148 }; |
149 | 149 |
150 class SystemTrayBubbleBorder : public views::BubbleBorder { | 150 class SystemTrayBubbleBorder : public views::BubbleBorder { |
151 public: | 151 public: |
152 SystemTrayBubbleBorder(views::View* owner, | 152 SystemTrayBubbleBorder(views::View* owner, |
153 views::BubbleBorder::ArrowLocation arrow_location, | 153 views::BubbleBorder::ArrowLocation arrow_location, |
154 int arrow_offset) | 154 int arrow_offset) |
155 : views::BubbleBorder(arrow_location, | 155 : views::BubbleBorder(arrow_location, |
156 views::BubbleBorder::NO_SHADOW), | 156 views::BubbleBorder::NO_SHADOW), |
157 owner_(owner), | 157 owner_(owner), |
158 arrow_offset_(std::max(arrow_offset, kMinArrowOffset)) { | 158 tray_arrow_offset_(arrow_offset) { |
159 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 159 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
160 } | 160 } |
161 | 161 |
162 virtual ~SystemTrayBubbleBorder() {} | 162 virtual ~SystemTrayBubbleBorder() {} |
163 | 163 |
164 private: | 164 private: |
165 // Overridden from views::BubbleBorder. | 165 // Overridden from views::BubbleBorder. |
166 // Override views::BubbleBorder to set the bubble on top of the anchor when | 166 // Override views::BubbleBorder to set the bubble on top of the anchor when |
167 // it has no arrow. | 167 // it has no arrow. |
168 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, | 168 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 if (!Shell::GetInstance()->shelf()->IsVisible() || | 202 if (!Shell::GetInstance()->shelf()->IsVisible() || |
203 arrow_location() == views::BubbleBorder::NONE) | 203 arrow_location() == views::BubbleBorder::NONE) |
204 return; | 204 return; |
205 | 205 |
206 // Draw the arrow after drawing child borders, so that the arrow can cover | 206 // Draw the arrow after drawing child borders, so that the arrow can cover |
207 // the its overlap section with child border. | 207 // the its overlap section with child border. |
208 SkPath path; | 208 SkPath path; |
209 path.incReserve(4); | 209 path.incReserve(4); |
210 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) { | 210 if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) { |
211 int tip_x = base::i18n::IsRTL() ? arrow_offset_ : | 211 int tip_x = base::i18n::IsRTL() ? tray_arrow_offset_ : |
212 owner_->width() - arrow_offset_; | 212 owner_->width() - tray_arrow_offset_; |
213 if (tip_x < kArrowPaddingFromRight + kArrowWidth / 2) | 213 tip_x = std::min(std::max(kArrowMinOffset, tip_x), |
214 tip_x = kArrowPaddingFromRight + kArrowWidth / 2; | 214 owner_->width() - kArrowMinOffset); |
215 if (tip_x > owner_->width() - kArrowPaddingFromRight - kArrowWidth / 2) | |
216 tip_x = owner_->width() - kArrowPaddingFromRight - kArrowWidth / 2; | |
217 int left_base_x = tip_x - kArrowWidth / 2; | 215 int left_base_x = tip_x - kArrowWidth / 2; |
218 int left_base_y = y; | 216 int left_base_y = y; |
219 int tip_y = left_base_y + kArrowHeight; | 217 int tip_y = left_base_y + kArrowHeight; |
220 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); | 218 path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); |
221 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 219 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
222 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), | 220 path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), |
223 SkIntToScalar(left_base_y)); | 221 SkIntToScalar(left_base_y)); |
224 } else if (arrow_location() == views::BubbleBorder::LEFT_BOTTOM) { | 222 } else { |
225 int tip_y = y - arrow_offset_; | 223 int tip_y = y - tray_arrow_offset_; |
| 224 tip_y = std::min(std::max(kArrowMinOffset, tip_y), |
| 225 owner_->height() - kArrowMinOffset); |
226 int top_base_y = tip_y - kArrowWidth / 2; | 226 int top_base_y = tip_y - kArrowWidth / 2; |
227 int top_base_x = inset.left() + kSystemTrayBubbleHorizontalInset; | 227 int top_base_x, tip_x; |
228 int tip_x = top_base_x - kArrowHeight; | 228 if (arrow_location() == views::BubbleBorder::LEFT_BOTTOM) { |
| 229 top_base_x = inset.left() + kSystemTrayBubbleHorizontalInset; |
| 230 tip_x = top_base_x - kArrowHeight; |
| 231 } else { |
| 232 DCHECK(arrow_location() == views::BubbleBorder::RIGHT_BOTTOM); |
| 233 top_base_x = inset.left() + owner_->width() - |
| 234 kSystemTrayBubbleHorizontalInset; |
| 235 tip_x = top_base_x + kArrowHeight; |
| 236 } |
229 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); | 237 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); |
230 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 238 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
231 path.lineTo(SkIntToScalar(top_base_x), | 239 path.lineTo(SkIntToScalar(top_base_x), |
232 SkIntToScalar(top_base_y + kArrowWidth)); | |
233 } else if (arrow_location() == views::BubbleBorder::RIGHT_BOTTOM){ | |
234 int tip_y = y - arrow_offset_; | |
235 int top_base_y = tip_y - kArrowWidth / 2; | |
236 int top_base_x = inset.left() + owner_->width() - | |
237 kSystemTrayBubbleHorizontalInset; | |
238 int tip_x = top_base_x + kArrowHeight; | |
239 path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); | |
240 path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | |
241 path.lineTo(SkIntToScalar(top_base_x), | |
242 SkIntToScalar(top_base_y + kArrowWidth)); | 240 SkIntToScalar(top_base_y + kArrowWidth)); |
243 } | 241 } |
244 | 242 |
245 SkPaint paint; | 243 SkPaint paint; |
246 paint.setStyle(SkPaint::kFill_Style); | 244 paint.setStyle(SkPaint::kFill_Style); |
247 paint.setColor(kHeaderBackgroundColorDark); | 245 paint.setColor(kHeaderBackgroundColorDark); |
248 canvas->DrawPath(path, paint); | 246 canvas->DrawPath(path, paint); |
249 | 247 |
250 // Now draw the arrow border. | 248 // Now draw the arrow border. |
251 paint.setStyle(SkPaint::kStroke_Style); | 249 paint.setStyle(SkPaint::kStroke_Style); |
252 paint.setColor(kBorderDarkColor); | 250 paint.setColor(kBorderDarkColor); |
253 canvas->DrawPath(path, paint); | 251 canvas->DrawPath(path, paint); |
254 | 252 |
255 } | 253 } |
256 | 254 |
257 views::View* owner_; | 255 views::View* owner_; |
258 const int arrow_offset_; | 256 const int tray_arrow_offset_; |
259 | 257 |
260 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); | 258 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); |
261 }; | 259 }; |
262 | 260 |
263 // Implicit animation observer that deletes itself and the layer at the end of | 261 // Implicit animation observer that deletes itself and the layer at the end of |
264 // the animation. | 262 // the animation. |
265 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { | 263 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { |
266 public: | 264 public: |
267 explicit AnimationObserverDeleteLayer(ui::Layer* layer) | 265 explicit AnimationObserverDeleteLayer(ui::Layer* layer) |
268 : layer_(layer) { | 266 : layer_(layer) { |
(...skipping 14 matching lines...) Expand all Loading... |
283 | 281 |
284 } // namespace | 282 } // namespace |
285 | 283 |
286 namespace internal { | 284 namespace internal { |
287 | 285 |
288 // SystemTrayBubbleView | 286 // SystemTrayBubbleView |
289 | 287 |
290 SystemTrayBubbleView::SystemTrayBubbleView( | 288 SystemTrayBubbleView::SystemTrayBubbleView( |
291 views::View* anchor, | 289 views::View* anchor, |
292 views::BubbleBorder::ArrowLocation arrow_location, | 290 views::BubbleBorder::ArrowLocation arrow_location, |
293 SystemTrayBubble* host, | 291 Host* host, |
294 bool can_activate) | 292 bool can_activate, |
| 293 int bubble_width) |
295 : views::BubbleDelegateView(anchor, arrow_location), | 294 : views::BubbleDelegateView(anchor, arrow_location), |
296 host_(host), | 295 host_(host), |
297 can_activate_(can_activate), | 296 can_activate_(can_activate), |
298 max_height_(0) { | 297 max_height_(0), |
| 298 bubble_width_(bubble_width) { |
299 set_margin(0); | 299 set_margin(0); |
300 set_parent_window(ash::Shell::GetInstance()->GetContainer( | 300 set_parent_window(ash::Shell::GetInstance()->GetContainer( |
301 ash::internal::kShellWindowId_SettingBubbleContainer)); | 301 ash::internal::kShellWindowId_SettingBubbleContainer)); |
302 set_notify_enter_exit_on_child(true); | 302 set_notify_enter_exit_on_child(true); |
303 SetPaintToLayer(true); | 303 SetPaintToLayer(true); |
304 SetFillsBoundsOpaquely(true); | 304 SetFillsBoundsOpaquely(true); |
305 } | 305 } |
306 | 306 |
307 SystemTrayBubbleView::~SystemTrayBubbleView() { | 307 SystemTrayBubbleView::~SystemTrayBubbleView() { |
308 // Inform host items (models) that their views are being destroyed. | 308 // Inform host items (models) that their views are being destroyed. |
309 if (host_) | 309 if (host_) |
310 host_->DestroyItemViews(); | 310 host_->BubbleViewDestroyed(); |
311 } | 311 } |
312 | 312 |
313 void SystemTrayBubbleView::SetBubbleBorder(views::BubbleBorder* border) { | 313 void SystemTrayBubbleView::SetBubbleBorder(int arrow_offset) { |
314 GetBubbleFrameView()->SetBubbleBorder(border); | 314 DCHECK(GetWidget()); |
| 315 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( |
| 316 this, arrow_location(), arrow_offset); |
| 317 GetBubbleFrameView()->SetBubbleBorder(bubble_border); |
| 318 // Recalculate size with new border. |
| 319 SizeToContents(); |
315 } | 320 } |
316 | 321 |
317 void SystemTrayBubbleView::UpdateAnchor() { | 322 void SystemTrayBubbleView::UpdateAnchor() { |
318 SizeToContents(); | 323 SizeToContents(); |
319 GetWidget()->GetRootView()->SchedulePaint(); | 324 GetWidget()->GetRootView()->SchedulePaint(); |
320 } | 325 } |
321 | 326 |
| 327 void SystemTrayBubbleView::SetMaxHeight(int height) { |
| 328 max_height_ = height; |
| 329 if (GetWidget()) |
| 330 SizeToContents(); |
| 331 } |
| 332 |
322 void SystemTrayBubbleView::Init() { | 333 void SystemTrayBubbleView::Init() { |
323 views::BoxLayout* layout = | 334 views::BoxLayout* layout = |
324 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 335 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
325 layout->set_spread_blank_space(true); | 336 layout->set_spread_blank_space(true); |
326 SetLayoutManager(layout); | 337 SetLayoutManager(layout); |
327 set_background(NULL); | 338 set_background(NULL); |
328 } | 339 } |
329 | 340 |
330 gfx::Rect SystemTrayBubbleView::GetAnchorRect() { | 341 gfx::Rect SystemTrayBubbleView::GetAnchorRect() { |
331 gfx::Rect rect; | 342 gfx::Rect rect; |
332 if (host_) | 343 if (host_) |
333 rect = host_->GetAnchorRect(); | 344 rect = host_->GetAnchorRect(); |
334 // TODO(jennyz): May need to add left/right alignment in the following code. | 345 // TODO(jennyz): May need to add left/right alignment in the following code. |
335 if (rect.IsEmpty()) { | 346 if (rect.IsEmpty()) { |
336 rect = gfx::Screen::GetPrimaryMonitor().bounds(); | 347 rect = gfx::Screen::GetPrimaryMonitor().bounds(); |
337 rect = gfx::Rect( | 348 rect = gfx::Rect( |
338 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : | 349 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : |
339 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | 350 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
340 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | 351 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
341 0, 0); | 352 0, 0); |
342 } | 353 } |
343 return rect; | 354 return rect; |
344 } | 355 } |
345 | 356 |
| 357 gfx::Rect SystemTrayBubbleView::GetBubbleBounds() { |
| 358 // Same as BubbleDelegateView implementation, but don't try mirroring. |
| 359 return GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 360 GetAnchorRect(), GetPreferredSize(), false /*try_mirroring_arrow*/); |
| 361 } |
| 362 |
346 bool SystemTrayBubbleView::CanActivate() const { | 363 bool SystemTrayBubbleView::CanActivate() const { |
347 return can_activate_; | 364 return can_activate_; |
348 } | 365 } |
349 | 366 |
350 gfx::Size SystemTrayBubbleView::GetPreferredSize() { | 367 gfx::Size SystemTrayBubbleView::GetPreferredSize() { |
351 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); | 368 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); |
352 int height = size.height(); | 369 int height = size.height(); |
353 if (max_height_ != 0 && height > max_height_) | 370 if (max_height_ != 0 && height > max_height_) |
354 height = max_height_; | 371 height = max_height_; |
355 return gfx::Size(kTrayPopupWidth, height); | 372 return gfx::Size(bubble_width_, height); |
356 } | 373 } |
357 | 374 |
358 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { | 375 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { |
359 if (host_) | 376 if (host_) |
360 host_->StopAutoCloseTimer(); | 377 host_->OnMouseEnteredView(); |
361 } | 378 } |
362 | 379 |
363 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { | 380 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { |
364 if (host_) | 381 if (host_) |
365 host_->RestartAutoCloseTimer(); | 382 host_->OnMouseExitedView(); |
366 } | 383 } |
367 | 384 |
368 void SystemTrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { | 385 void SystemTrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { |
369 if (can_activate_) { | 386 if (can_activate_) { |
370 state->role = ui::AccessibilityTypes::ROLE_WINDOW; | 387 state->role = ui::AccessibilityTypes::ROLE_WINDOW; |
371 state->name = l10n_util::GetStringUTF16( | 388 state->name = l10n_util::GetStringUTF16( |
372 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 389 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
373 } | 390 } |
374 } | 391 } |
375 | 392 |
(...skipping 12 matching lines...) Expand all Loading... |
388 } | 405 } |
389 | 406 |
390 // SystemTrayBubble::InitParams | 407 // SystemTrayBubble::InitParams |
391 SystemTrayBubble::InitParams::InitParams( | 408 SystemTrayBubble::InitParams::InitParams( |
392 SystemTrayBubble::AnchorType anchor_type, | 409 SystemTrayBubble::AnchorType anchor_type, |
393 ShelfAlignment shelf_alignment) | 410 ShelfAlignment shelf_alignment) |
394 : anchor(NULL), | 411 : anchor(NULL), |
395 anchor_type(anchor_type), | 412 anchor_type(anchor_type), |
396 can_activate(false), | 413 can_activate(false), |
397 login_status(ash::user::LOGGED_IN_NONE), | 414 login_status(ash::user::LOGGED_IN_NONE), |
398 arrow_offset( | 415 arrow_offset(0), |
399 (shelf_alignment == SHELF_ALIGNMENT_BOTTOM ? | |
400 kArrowPaddingFromRight : kArrowPaddingFromBottom) | |
401 + kArrowWidth / 2), | |
402 max_height(0) { | 416 max_height(0) { |
403 } | 417 } |
404 | 418 |
405 // SystemTrayBubble | 419 // SystemTrayBubble |
406 | 420 |
407 SystemTrayBubble::SystemTrayBubble( | 421 SystemTrayBubble::SystemTrayBubble( |
408 ash::SystemTray* tray, | 422 ash::SystemTray* tray, |
409 const std::vector<ash::SystemTrayItem*>& items, | 423 const std::vector<ash::SystemTrayItem*>& items, |
410 BubbleType bubble_type) | 424 BubbleType bubble_type) |
411 : tray_(tray), | 425 : tray_(tray), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 501 |
488 DestroyItemViews(); | 502 DestroyItemViews(); |
489 bubble_view_->RemoveAllChildViews(true); | 503 bubble_view_->RemoveAllChildViews(true); |
490 | 504 |
491 items_ = items; | 505 items_ = items; |
492 bubble_type_ = bubble_type; | 506 bubble_type_ = bubble_type; |
493 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); | 507 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); |
494 bubble_widget_->GetContentsView()->Layout(); | 508 bubble_widget_->GetContentsView()->Layout(); |
495 // Make sure that the bubble is large enough for the default view. | 509 // Make sure that the bubble is large enough for the default view. |
496 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { | 510 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { |
497 bubble_view_->set_max_height(0); // Clear max height limit. | 511 bubble_view_->SetMaxHeight(0); // Clear max height limit. |
498 bubble_view_->SizeToContents(); | |
499 } | 512 } |
500 | 513 |
501 // When transitioning from default view to detailed view, animate the new | 514 // When transitioning from default view to detailed view, animate the new |
502 // view (slide in from the right). | 515 // view (slide in from the right). |
503 if (bubble_type == BUBBLE_TYPE_DETAILED) { | 516 if (bubble_type == BUBBLE_TYPE_DETAILED) { |
504 ui::Layer* new_layer = bubble_view_->layer(); | 517 ui::Layer* new_layer = bubble_view_->layer(); |
505 gfx::Rect bounds = new_layer->bounds(); | 518 gfx::Rect bounds = new_layer->bounds(); |
506 ui::Transform transform; | 519 ui::Transform transform; |
507 transform.SetTranslateX(bounds.width()); | 520 transform.SetTranslateX(bounds.width()); |
508 new_layer->SetTransform(transform); | 521 new_layer->SetTransform(transform); |
(...skipping 16 matching lines...) Expand all Loading... |
525 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; | 538 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; |
526 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 539 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
527 arrow_location = views::BubbleBorder::LEFT_BOTTOM; | 540 arrow_location = views::BubbleBorder::LEFT_BOTTOM; |
528 } else { | 541 } else { |
529 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; | 542 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; |
530 } | 543 } |
531 } else { | 544 } else { |
532 arrow_location = views::BubbleBorder::NONE; | 545 arrow_location = views::BubbleBorder::NONE; |
533 } | 546 } |
534 bubble_view_ = new SystemTrayBubbleView( | 547 bubble_view_ = new SystemTrayBubbleView( |
535 init_params.anchor, arrow_location, this, init_params.can_activate); | 548 init_params.anchor, arrow_location, |
| 549 this, init_params.can_activate, kTrayPopupWidth); |
536 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) | 550 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) |
537 bubble_view_->set_close_on_deactivate(false); | 551 bubble_view_->set_close_on_deactivate(false); |
538 int max_height = init_params.max_height; | 552 int max_height = init_params.max_height; |
539 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | 553 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
540 max_height < kDetailedBubbleMaxHeight) | 554 max_height < kDetailedBubbleMaxHeight) |
541 max_height = kDetailedBubbleMaxHeight; | 555 max_height = kDetailedBubbleMaxHeight; |
542 bubble_view_->set_max_height(max_height); | 556 bubble_view_->SetMaxHeight(max_height); |
543 | 557 |
544 CreateItemViews(init_params.login_status); | 558 CreateItemViews(init_params.login_status); |
545 | 559 |
546 DCHECK(bubble_widget_ == NULL); | 560 DCHECK(bubble_widget_ == NULL); |
547 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | 561 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
548 | 562 |
549 // Must occur after call to CreateBubble() | 563 // Must occur after call to CreateBubble() |
550 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 564 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
551 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | 565 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
552 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( | 566 bubble_view_->SetBubbleBorder(init_params.arrow_offset); |
553 bubble_view_, arrow_location, init_params.arrow_offset); | |
554 bubble_view_->SetBubbleBorder(bubble_border); | |
555 // Recalculate with new border. | |
556 bubble_view_->SizeToContents(); | |
557 | 567 |
558 bubble_widget_->AddObserver(this); | 568 bubble_widget_->AddObserver(this); |
559 | 569 |
560 // Setup animation. | 570 // Setup animation. |
561 ash::SetWindowVisibilityAnimationType( | 571 ash::SetWindowVisibilityAnimationType( |
562 bubble_widget_->GetNativeWindow(), | 572 bubble_widget_->GetNativeWindow(), |
563 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 573 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
564 ash::SetWindowVisibilityAnimationTransition( | 574 ash::SetWindowVisibilityAnimationTransition( |
565 bubble_widget_->GetNativeWindow(), | 575 bubble_widget_->GetNativeWindow(), |
566 ash::ANIMATE_BOTH); | 576 ash::ANIMATE_BOTH); |
567 ash::SetWindowVisibilityAnimationDuration( | 577 ash::SetWindowVisibilityAnimationDuration( |
568 bubble_widget_->GetNativeWindow(), | 578 bubble_widget_->GetNativeWindow(), |
569 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | 579 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); |
570 | 580 |
571 bubble_view_->Show(); | 581 bubble_view_->Show(); |
572 } | 582 } |
573 | 583 |
| 584 void SystemTrayBubble::BubbleViewDestroyed() { |
| 585 DestroyItemViews(); |
| 586 } |
| 587 |
574 gfx::Rect SystemTrayBubble::GetAnchorRect() const { | 588 gfx::Rect SystemTrayBubble::GetAnchorRect() const { |
575 gfx::Rect rect; | 589 gfx::Rect rect; |
576 views::Widget* widget = bubble_view()->anchor_widget(); | 590 views::Widget* widget = bubble_view()->anchor_widget(); |
577 if (widget->IsVisible()) { | 591 if (widget->IsVisible()) { |
578 rect = widget->GetWindowScreenBounds(); | 592 rect = widget->GetWindowScreenBounds(); |
579 if (anchor_type_ == ANCHOR_TYPE_TRAY) { | 593 if (anchor_type_ == ANCHOR_TYPE_TRAY) { |
580 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 594 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
581 rect.Inset( | 595 rect.Inset( |
582 base::i18n::IsRTL() ? | 596 base::i18n::IsRTL() ? |
583 kPaddingFromRightEdgeOfScreenBottomAlignment : 0, | 597 kPaddingFromRightEdgeOfScreenBottomAlignment : 0, |
(...skipping 14 matching lines...) Expand all Loading... |
598 // be deducted out from the anchor rect. | 612 // be deducted out from the anchor rect. |
599 views::View* anchor_view = bubble_view()->anchor_view(); | 613 views::View* anchor_view = bubble_view()->anchor_view(); |
600 rect = anchor_view->GetScreenBounds(); | 614 rect = anchor_view->GetScreenBounds(); |
601 gfx::Insets insets = anchor_view->GetInsets(); | 615 gfx::Insets insets = anchor_view->GetInsets(); |
602 rect.Inset(insets); | 616 rect.Inset(insets); |
603 } | 617 } |
604 } | 618 } |
605 return rect; | 619 return rect; |
606 } | 620 } |
607 | 621 |
| 622 void SystemTrayBubble::OnMouseEnteredView() { |
| 623 StopAutoCloseTimer(); |
| 624 } |
| 625 |
| 626 void SystemTrayBubble::OnMouseExitedView() { |
| 627 RestartAutoCloseTimer(); |
| 628 } |
| 629 |
608 void SystemTrayBubble::DestroyItemViews() { | 630 void SystemTrayBubble::DestroyItemViews() { |
609 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); | 631 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
610 it != items_.end(); | 632 it != items_.end(); |
611 ++it) { | 633 ++it) { |
612 switch (bubble_type_) { | 634 switch (bubble_type_) { |
613 case BUBBLE_TYPE_DEFAULT: | 635 case BUBBLE_TYPE_DEFAULT: |
614 (*it)->DestroyDefaultView(); | 636 (*it)->DestroyDefaultView(); |
615 break; | 637 break; |
616 case BUBBLE_TYPE_DETAILED: | 638 case BUBBLE_TYPE_DETAILED: |
617 (*it)->DestroyDetailedView(); | 639 (*it)->DestroyDetailedView(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 } | 735 } |
714 | 736 |
715 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { | 737 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { |
716 CHECK_EQ(bubble_widget_, widget); | 738 CHECK_EQ(bubble_widget_, widget); |
717 bubble_widget_ = NULL; | 739 bubble_widget_ = NULL; |
718 tray_->RemoveBubble(this); | 740 tray_->RemoveBubble(this); |
719 } | 741 } |
720 | 742 |
721 } // namespace internal | 743 } // namespace internal |
722 } // namespace ash | 744 } // namespace ash |
OLD | NEW |