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 29 matching lines...) Expand all Loading... | |
40 const int kSystemTrayBubbleHorizontalInset = 1; | 40 const int kSystemTrayBubbleHorizontalInset = 1; |
41 const int kSystemTrayBubbleVerticalInset = 1; | 41 const int kSystemTrayBubbleVerticalInset = 1; |
42 | 42 |
43 const int kArrowHeight = 10; | 43 const int kArrowHeight = 10; |
44 const int kArrowWidth = 20; | 44 const int kArrowWidth = 20; |
45 const int kArrowPaddingFromRight = 20; | 45 const int kArrowPaddingFromRight = 20; |
46 const int kMinArrowOffset = 12; | 46 const int kMinArrowOffset = 12; |
47 | 47 |
48 const int kAnimationDurationForPopupMS = 200; | 48 const int kAnimationDurationForPopupMS = 200; |
49 | 49 |
50 // When showing a detailed view directly (e.g. from a notification), we may not | |
51 // know the height of the default view, or the default view may be too small, | |
52 // so pick a reasonable max height. | |
53 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; | |
sadrul
2012/05/22 19:05:17
Let's call this kNotificationBubbleMaxHeight. I do
stevenjb
2012/05/22 22:39:00
This has nothing to do with notifications, it only
| |
54 | |
50 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); | 55 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); |
51 | 56 |
52 void DrawBlurredShadowAroundView(gfx::Canvas* canvas, | 57 void DrawBlurredShadowAroundView(gfx::Canvas* canvas, |
53 int top, | 58 int top, |
54 int bottom, | 59 int bottom, |
55 int width, | 60 int width, |
56 const gfx::Insets& inset) { | 61 const gfx::Insets& inset) { |
57 SkPath path; | 62 SkPath path; |
58 path.incReserve(4); | 63 path.incReserve(4); |
59 path.moveTo(SkIntToScalar(inset.left() + kShadowThickness), | 64 path.moveTo(SkIntToScalar(inset.left() + kShadowThickness), |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 | 260 |
256 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); | 261 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); |
257 }; | 262 }; |
258 | 263 |
259 } // namespace | 264 } // namespace |
260 | 265 |
261 namespace internal { | 266 namespace internal { |
262 | 267 |
263 // SystemTrayBubbleView | 268 // SystemTrayBubbleView |
264 | 269 |
265 SystemTrayBubbleView::SystemTrayBubbleView(views::View* anchor, | 270 SystemTrayBubbleView::SystemTrayBubbleView( |
271 views::View* anchor, | |
266 views::BubbleBorder::ArrowLocation arrow_location, | 272 views::BubbleBorder::ArrowLocation arrow_location, |
267 SystemTrayBubble* host, | 273 SystemTrayBubble* host, |
268 bool can_activate) | 274 bool can_activate) |
269 : views::BubbleDelegateView(anchor, arrow_location), | 275 : views::BubbleDelegateView(anchor, arrow_location), |
270 host_(host), | 276 host_(host), |
271 can_activate_(can_activate) { | 277 can_activate_(can_activate), |
278 max_height_(0) { | |
272 set_margin(0); | 279 set_margin(0); |
273 set_parent_window(ash::Shell::GetInstance()->GetContainer( | 280 set_parent_window(ash::Shell::GetInstance()->GetContainer( |
274 ash::internal::kShellWindowId_SettingBubbleContainer)); | 281 ash::internal::kShellWindowId_SettingBubbleContainer)); |
275 set_notify_enter_exit_on_child(true); | 282 set_notify_enter_exit_on_child(true); |
276 } | 283 } |
277 | 284 |
278 SystemTrayBubbleView::~SystemTrayBubbleView() { | 285 SystemTrayBubbleView::~SystemTrayBubbleView() { |
279 // Inform host items (models) that their views are being destroyed. | 286 // Inform host items (models) that their views are being destroyed. |
280 if (host_) | 287 if (host_) |
281 host_->DestroyItemViews(); | 288 host_->DestroyItemViews(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 335 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
329 } | 336 } |
330 } | 337 } |
331 | 338 |
332 bool SystemTrayBubbleView::CanActivate() const { | 339 bool SystemTrayBubbleView::CanActivate() const { |
333 return can_activate_; | 340 return can_activate_; |
334 } | 341 } |
335 | 342 |
336 gfx::Size SystemTrayBubbleView::GetPreferredSize() { | 343 gfx::Size SystemTrayBubbleView::GetPreferredSize() { |
337 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); | 344 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); |
338 return gfx::Size(kTrayPopupWidth, size.height()); | 345 int height = size.height(); |
346 if (max_height_ != 0 && height > max_height_) | |
347 height = max_height_; | |
348 return gfx::Size(kTrayPopupWidth, height); | |
339 } | 349 } |
340 | 350 |
341 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { | 351 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { |
342 if (host_) | 352 if (host_) |
343 host_->StopAutoCloseTimer(); | 353 host_->StopAutoCloseTimer(); |
344 } | 354 } |
345 | 355 |
346 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { | 356 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { |
347 if (host_) | 357 if (host_) |
348 host_->RestartAutoCloseTimer(); | 358 host_->RestartAutoCloseTimer(); |
349 } | 359 } |
350 | 360 |
351 // SystemTrayBubble::InitParams | 361 // SystemTrayBubble::InitParams |
352 SystemTrayBubble::InitParams::InitParams( | 362 SystemTrayBubble::InitParams::InitParams( |
353 SystemTrayBubble::AnchorType anchor_type) | 363 SystemTrayBubble::AnchorType anchor_type) |
354 : anchor(NULL), | 364 : anchor(NULL), |
355 anchor_type(anchor_type), | 365 anchor_type(anchor_type), |
356 can_activate(false), | 366 can_activate(false), |
357 login_status(ash::user::LOGGED_IN_NONE), | 367 login_status(ash::user::LOGGED_IN_NONE), |
358 arrow_offset(kArrowPaddingFromRight + kArrowWidth / 2) { | 368 arrow_offset(kArrowPaddingFromRight + kArrowWidth / 2), |
369 max_height(0) { | |
359 } | 370 } |
360 | 371 |
361 // SystemTrayBubble | 372 // SystemTrayBubble |
362 | 373 |
363 SystemTrayBubble::SystemTrayBubble( | 374 SystemTrayBubble::SystemTrayBubble( |
364 ash::SystemTray* tray, | 375 ash::SystemTray* tray, |
365 const std::vector<ash::SystemTrayItem*>& items, | 376 const std::vector<ash::SystemTrayItem*>& items, |
366 BubbleType bubble_type) | 377 BubbleType bubble_type) |
367 : tray_(tray), | 378 : tray_(tray), |
368 bubble_view_(NULL), | 379 bubble_view_(NULL), |
(...skipping 24 matching lines...) Expand all Loading... | |
393 const std::vector<ash::SystemTrayItem*>& items, | 404 const std::vector<ash::SystemTrayItem*>& items, |
394 BubbleType bubble_type) { | 405 BubbleType bubble_type) { |
395 DestroyItemViews(); | 406 DestroyItemViews(); |
396 bubble_view_->RemoveAllChildViews(true); | 407 bubble_view_->RemoveAllChildViews(true); |
397 | 408 |
398 items_ = items; | 409 items_ = items; |
399 bubble_type_ = bubble_type; | 410 bubble_type_ = bubble_type; |
400 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); | 411 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); |
401 bubble_widget_->GetContentsView()->Layout(); | 412 bubble_widget_->GetContentsView()->Layout(); |
402 // Make sure that the bubble is large enough for the default view. | 413 // Make sure that the bubble is large enough for the default view. |
403 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) | 414 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { |
415 bubble_view_->set_max_height(0); // Clear max height limit. | |
404 bubble_view_->SizeToContents(); | 416 bubble_view_->SizeToContents(); |
417 } | |
405 } | 418 } |
406 | 419 |
407 void SystemTrayBubble::InitView(const InitParams& init_params) { | 420 void SystemTrayBubble::InitView(const InitParams& init_params) { |
408 DCHECK(bubble_view_ == NULL); | 421 DCHECK(bubble_view_ == NULL); |
409 anchor_type_ = init_params.anchor_type; | 422 anchor_type_ = init_params.anchor_type; |
410 views::BubbleBorder::ArrowLocation arrow_location; | 423 views::BubbleBorder::ArrowLocation arrow_location; |
411 if (anchor_type_ == ANCHOR_TYPE_TRAY) { | 424 if (anchor_type_ == ANCHOR_TYPE_TRAY) { |
412 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 425 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
413 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; | 426 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; |
414 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 427 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
415 arrow_location = views::BubbleBorder::LEFT_BOTTOM; | 428 arrow_location = views::BubbleBorder::LEFT_BOTTOM; |
416 } else { | 429 } else { |
417 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; | 430 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; |
418 } | 431 } |
419 } else { | 432 } else { |
420 arrow_location = views::BubbleBorder::NONE; | 433 arrow_location = views::BubbleBorder::NONE; |
421 } | 434 } |
422 bubble_view_ = new SystemTrayBubbleView( | 435 bubble_view_ = new SystemTrayBubbleView( |
423 init_params.anchor, arrow_location, this, init_params.can_activate); | 436 init_params.anchor, arrow_location, this, init_params.can_activate); |
424 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) | 437 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) |
425 bubble_view_->set_close_on_deactivate(false); | 438 bubble_view_->set_close_on_deactivate(false); |
439 int max_height = init_params.max_height; | |
440 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | |
441 max_height < kDetailedBubbleMaxHeight) | |
442 max_height = kDetailedBubbleMaxHeight; | |
443 bubble_view_->set_max_height(max_height); | |
426 | 444 |
427 CreateItemViews(init_params.login_status); | 445 CreateItemViews(init_params.login_status); |
428 | 446 |
429 DCHECK(bubble_widget_ == NULL); | 447 DCHECK(bubble_widget_ == NULL); |
430 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | 448 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
431 | 449 |
432 // Must occur after call to CreateBubble() | 450 // Must occur after call to CreateBubble() |
433 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 451 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
434 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | 452 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
435 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( | 453 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, | 593 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, |
576 bool visible) { | 594 bool visible) { |
577 if (!visible) | 595 if (!visible) |
578 MessageLoopForUI::current()->RemoveObserver(this); | 596 MessageLoopForUI::current()->RemoveObserver(this); |
579 else | 597 else |
580 MessageLoopForUI::current()->AddObserver(this); | 598 MessageLoopForUI::current()->AddObserver(this); |
581 } | 599 } |
582 | 600 |
583 } // namespace internal | 601 } // namespace internal |
584 } // namespace ash | 602 } // namespace ash |
OLD | NEW |