Index: ash/system/tray/system_tray_bubble.cc |
diff --git a/ash/system/tray/system_tray_bubble.cc b/ash/system/tray/system_tray_bubble.cc |
index a15bd59e87bfb6d65d2ffac4199918ecc0b48f55..2dd201f8cae043f1e76541074de4797948164683 100644 |
--- a/ash/system/tray/system_tray_bubble.cc |
+++ b/ash/system/tray/system_tray_bubble.cc |
@@ -5,51 +5,25 @@ |
#include "ash/system/tray/system_tray_bubble.h" |
#include "ash/shell.h" |
-#include "ash/shell_window_ids.h" |
#include "ash/system/tray/system_tray.h" |
#include "ash/system/tray/system_tray_delegate.h" |
#include "ash/system/tray/system_tray_item.h" |
#include "ash/system/tray/tray_constants.h" |
-#include "ash/wm/shelf_layout_manager.h" |
#include "ash/wm/window_animations.h" |
#include "base/message_loop.h" |
-#include "grit/ash_strings.h" |
-#include "third_party/skia/include/core/SkCanvas.h" |
-#include "third_party/skia/include/core/SkColor.h" |
-#include "third_party/skia/include/core/SkPaint.h" |
-#include "third_party/skia/include/core/SkPath.h" |
-#include "third_party/skia/include/effects/SkBlurImageFilter.h" |
#include "ui/aura/event.h" |
#include "ui/aura/window.h" |
-#include "ui/base/accessibility/accessible_view_state.h" |
-#include "ui/base/l10n/l10n_util.h" |
#include "ui/compositor/layer.h" |
#include "ui/compositor/layer_animation_observer.h" |
#include "ui/compositor/scoped_layer_animation_settings.h" |
#include "ui/gfx/canvas.h" |
-#include "ui/gfx/screen.h" |
-#include "ui/views/bubble/bubble_frame_view.h" |
#include "ui/views/layout/box_layout.h" |
-#include "ui/views/layout/fill_layout.h" |
#include "ui/views/view.h" |
namespace ash { |
namespace { |
-const int kShadowThickness = 4; |
- |
-const int kBottomLineHeight = 1; |
- |
-const int kSystemTrayBubbleHorizontalInset = 1; |
-const int kSystemTrayBubbleVerticalInset = 1; |
- |
-const int kArrowHeight = 10; |
-const int kArrowWidth = 20; |
-const int kArrowPaddingFromRight = 20; |
-const int kArrowPaddingFromBottom = 17; |
-const int kMinArrowOffset = 12; |
- |
const int kAnimationDurationForPopupMS = 200; |
// Normally a detailed view is the same size as the default view. However, |
@@ -59,34 +33,6 @@ const int kAnimationDurationForPopupMS = 200; |
// detailed view. |
const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
-const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); |
- |
-void DrawBlurredShadowAroundView(gfx::Canvas* canvas, |
- int top, |
- int bottom, |
- int width, |
- const gfx::Insets& inset) { |
- SkPath path; |
- path.incReserve(4); |
- path.moveTo(SkIntToScalar(inset.left() + kShadowThickness), |
- SkIntToScalar(top + kShadowThickness + 1)); |
- path.lineTo(SkIntToScalar(inset.left() + kShadowThickness), |
- SkIntToScalar(bottom)); |
- path.lineTo(SkIntToScalar(width), |
- SkIntToScalar(bottom)); |
- path.lineTo(SkIntToScalar(width), |
- SkIntToScalar(top + kShadowThickness + 1)); |
- |
- SkPaint paint; |
- paint.setColor(kShadowColor); |
- paint.setStyle(SkPaint::kStroke_Style); |
- paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
- paint.setStrokeWidth(SkIntToScalar(3)); |
- paint.setImageFilter(new SkBlurImageFilter( |
- SkIntToScalar(3), SkIntToScalar(3)))->unref(); |
- canvas->sk_canvas()->drawPath(path, paint); |
-} |
- |
// A view with some special behaviour for tray items in the popup: |
// - changes background color on hover. |
class TrayPopupItemContainer : public views::View { |
@@ -147,119 +93,6 @@ class TrayPopupItemContainer : public views::View { |
DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); |
}; |
-class SystemTrayBubbleBorder : public views::BubbleBorder { |
- public: |
- SystemTrayBubbleBorder(views::View* owner, |
- views::BubbleBorder::ArrowLocation arrow_location, |
- int arrow_offset) |
- : views::BubbleBorder(arrow_location, |
- views::BubbleBorder::NO_SHADOW), |
- owner_(owner), |
- arrow_offset_(std::max(arrow_offset, kMinArrowOffset)) { |
- set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
- } |
- |
- virtual ~SystemTrayBubbleBorder() {} |
- |
- private: |
- // Overridden from views::BubbleBorder. |
- // Override views::BubbleBorder to set the bubble on top of the anchor when |
- // it has no arrow. |
- virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
- const gfx::Size& contents_size) const OVERRIDE { |
- if (arrow_location() != NONE) { |
- return views::BubbleBorder::GetBounds(position_relative_to, |
- contents_size); |
- } |
- |
- gfx::Size border_size(contents_size); |
- gfx::Insets insets; |
- GetInsets(&insets); |
- border_size.Enlarge(insets.width(), insets.height()); |
- |
- const int kArrowOverlap = 3; |
- int x = position_relative_to.x() + |
- position_relative_to.width() / 2 - border_size.width() / 2; |
- // Position the bubble on top of the anchor. |
- int y = position_relative_to.y() + |
- kArrowOverlap - border_size.height(); |
- return gfx::Rect(x, y, border_size.width(), border_size.height()); |
- } |
- |
- // Overridden from views::Border. |
- virtual void Paint(const views::View& view, |
- gfx::Canvas* canvas) const OVERRIDE { |
- gfx::Insets inset; |
- GetInsets(&inset); |
- DrawBlurredShadowAroundView(canvas, 0, owner_->height(), owner_->width(), |
- inset); |
- |
- // Draw the bottom line. |
- int y = owner_->height() + 1; |
- canvas->FillRect(gfx::Rect(inset.left(), y, owner_->width(), |
- kBottomLineHeight), kBorderDarkColor); |
- |
- if (!Shell::GetInstance()->shelf()->IsVisible() || |
- arrow_location() == views::BubbleBorder::NONE) |
- return; |
- |
- // Draw the arrow after drawing child borders, so that the arrow can cover |
- // the its overlap section with child border. |
- SkPath path; |
- path.incReserve(4); |
- if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) { |
- int tip_x = base::i18n::IsRTL() ? arrow_offset_ : |
- owner_->width() - arrow_offset_; |
- if (tip_x < kArrowPaddingFromRight + kArrowWidth / 2) |
- tip_x = kArrowPaddingFromRight + kArrowWidth / 2; |
- if (tip_x > owner_->width() - kArrowPaddingFromRight - kArrowWidth / 2) |
- tip_x = owner_->width() - kArrowPaddingFromRight - kArrowWidth / 2; |
- int left_base_x = tip_x - kArrowWidth / 2; |
- int left_base_y = y; |
- int tip_y = left_base_y + kArrowHeight; |
- path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y)); |
- path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
- path.lineTo(SkIntToScalar(left_base_x + kArrowWidth), |
- SkIntToScalar(left_base_y)); |
- } else if (arrow_location() == views::BubbleBorder::LEFT_BOTTOM) { |
- int tip_y = y - arrow_offset_; |
- int top_base_y = tip_y - kArrowWidth / 2; |
- int top_base_x = inset.left() + kSystemTrayBubbleHorizontalInset; |
- int tip_x = top_base_x - kArrowHeight; |
- path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); |
- path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
- path.lineTo(SkIntToScalar(top_base_x), |
- SkIntToScalar(top_base_y + kArrowWidth)); |
- } else if (arrow_location() == views::BubbleBorder::RIGHT_BOTTOM){ |
- int tip_y = y - arrow_offset_; |
- int top_base_y = tip_y - kArrowWidth / 2; |
- int top_base_x = inset.left() + owner_->width() - |
- kSystemTrayBubbleHorizontalInset; |
- int tip_x = top_base_x + kArrowHeight; |
- path.moveTo(SkIntToScalar(top_base_x), SkIntToScalar(top_base_y)); |
- path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
- path.lineTo(SkIntToScalar(top_base_x), |
- SkIntToScalar(top_base_y + kArrowWidth)); |
- } |
- |
- SkPaint paint; |
- paint.setStyle(SkPaint::kFill_Style); |
- paint.setColor(kHeaderBackgroundColorDark); |
- canvas->DrawPath(path, paint); |
- |
- // Now draw the arrow border. |
- paint.setStyle(SkPaint::kStroke_Style); |
- paint.setColor(kBorderDarkColor); |
- canvas->DrawPath(path, paint); |
- |
- } |
- |
- views::View* owner_; |
- const int arrow_offset_; |
- |
- DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); |
-}; |
- |
// Implicit animation observer that deletes itself and the layer at the end of |
// the animation. |
class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { |
@@ -285,108 +118,6 @@ class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { |
namespace internal { |
-// SystemTrayBubbleView |
- |
-SystemTrayBubbleView::SystemTrayBubbleView( |
- views::View* anchor, |
- views::BubbleBorder::ArrowLocation arrow_location, |
- SystemTrayBubble* host, |
- bool can_activate) |
- : views::BubbleDelegateView(anchor, arrow_location), |
- host_(host), |
- can_activate_(can_activate), |
- max_height_(0) { |
- set_margin(0); |
- set_parent_window(ash::Shell::GetInstance()->GetContainer( |
- ash::internal::kShellWindowId_SettingBubbleContainer)); |
- set_notify_enter_exit_on_child(true); |
- SetPaintToLayer(true); |
- SetFillsBoundsOpaquely(true); |
-} |
- |
-SystemTrayBubbleView::~SystemTrayBubbleView() { |
- // Inform host items (models) that their views are being destroyed. |
- if (host_) |
- host_->DestroyItemViews(); |
-} |
- |
-void SystemTrayBubbleView::SetBubbleBorder(views::BubbleBorder* border) { |
- GetBubbleFrameView()->SetBubbleBorder(border); |
-} |
- |
-void SystemTrayBubbleView::UpdateAnchor() { |
- SizeToContents(); |
- GetWidget()->GetRootView()->SchedulePaint(); |
-} |
- |
-void SystemTrayBubbleView::Init() { |
- views::BoxLayout* layout = |
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
- layout->set_spread_blank_space(true); |
- SetLayoutManager(layout); |
- set_background(NULL); |
-} |
- |
-gfx::Rect SystemTrayBubbleView::GetAnchorRect() { |
- gfx::Rect rect; |
- if (host_) |
- rect = host_->GetAnchorRect(); |
- // TODO(jennyz): May need to add left/right alignment in the following code. |
- if (rect.IsEmpty()) { |
- rect = gfx::Screen::GetPrimaryMonitor().bounds(); |
- rect = gfx::Rect( |
- base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : |
- rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
- rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
- 0, 0); |
- } |
- return rect; |
-} |
- |
-bool SystemTrayBubbleView::CanActivate() const { |
- return can_activate_; |
-} |
- |
-gfx::Size SystemTrayBubbleView::GetPreferredSize() { |
- gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); |
- int height = size.height(); |
- if (max_height_ != 0 && height > max_height_) |
- height = max_height_; |
- return gfx::Size(kTrayPopupWidth, height); |
-} |
- |
-void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { |
- if (host_) |
- host_->StopAutoCloseTimer(); |
-} |
- |
-void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { |
- if (host_) |
- host_->RestartAutoCloseTimer(); |
-} |
- |
-void SystemTrayBubbleView::GetAccessibleState(ui::AccessibleViewState* state) { |
- if (can_activate_) { |
- state->role = ui::AccessibilityTypes::ROLE_WINDOW; |
- state->name = l10n_util::GetStringUTF16( |
- IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
- } |
-} |
- |
-void SystemTrayBubbleView::ChildPreferredSizeChanged(View* child) { |
- SizeToContents(); |
-} |
- |
-void SystemTrayBubbleView::ViewHierarchyChanged(bool is_add, |
- views::View* parent, |
- views::View* child) { |
- if (is_add && child == this) { |
- parent->SetPaintToLayer(true); |
- parent->SetFillsBoundsOpaquely(true); |
- parent->layer()->SetMasksToBounds(true); |
- } |
-} |
- |
// SystemTrayBubble::InitParams |
SystemTrayBubble::InitParams::InitParams( |
SystemTrayBubble::AnchorType anchor_type, |
@@ -395,10 +126,7 @@ SystemTrayBubble::InitParams::InitParams( |
anchor_type(anchor_type), |
can_activate(false), |
login_status(ash::user::LOGGED_IN_NONE), |
- arrow_offset( |
- (shelf_alignment == SHELF_ALIGNMENT_BOTTOM ? |
- kArrowPaddingFromRight : kArrowPaddingFromBottom) |
- + kArrowWidth / 2), |
+ arrow_offset(0), |
max_height(0) { |
} |
@@ -494,8 +222,7 @@ void SystemTrayBubble::UpdateView( |
bubble_widget_->GetContentsView()->Layout(); |
// Make sure that the bubble is large enough for the default view. |
if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { |
- bubble_view_->set_max_height(0); // Clear max height limit. |
- bubble_view_->SizeToContents(); |
+ bubble_view_->SetMaxHeight(0); // Clear max height limit. |
} |
// When transitioning from default view to detailed view, animate the new |
@@ -539,7 +266,7 @@ void SystemTrayBubble::InitView(const InitParams& init_params) { |
if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
max_height < kDetailedBubbleMaxHeight) |
max_height = kDetailedBubbleMaxHeight; |
- bubble_view_->set_max_height(max_height); |
+ bubble_view_->SetMaxHeight(max_height); |
CreateItemViews(init_params.login_status); |
@@ -549,11 +276,7 @@ void SystemTrayBubble::InitView(const InitParams& init_params) { |
// Must occur after call to CreateBubble() |
bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
- SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( |
- bubble_view_, arrow_location, init_params.arrow_offset); |
- bubble_view_->SetBubbleBorder(bubble_border); |
- // Recalculate with new border. |
- bubble_view_->SizeToContents(); |
+ bubble_view_->SetBubbleBorder(init_params.arrow_offset); |
bubble_widget_->AddObserver(this); |
@@ -571,6 +294,10 @@ void SystemTrayBubble::InitView(const InitParams& init_params) { |
bubble_view_->Show(); |
} |
+void SystemTrayBubble::BubbleViewDestroyed() { |
+ DestroyItemViews(); |
+} |
+ |
gfx::Rect SystemTrayBubble::GetAnchorRect() const { |
gfx::Rect rect; |
views::Widget* widget = bubble_view()->anchor_widget(); |
@@ -605,6 +332,14 @@ gfx::Rect SystemTrayBubble::GetAnchorRect() const { |
return rect; |
} |
+void SystemTrayBubble::OnMouseEnteredView() { |
+ StopAutoCloseTimer(); |
+} |
+ |
+void SystemTrayBubble::OnMouseExitedView() { |
+ RestartAutoCloseTimer(); |
+} |
+ |
void SystemTrayBubble::DestroyItemViews() { |
for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
it != items_.end(); |
@@ -647,6 +382,19 @@ void SystemTrayBubble::Close() { |
bubble_widget_->Close(); |
} |
+void SystemTrayBubble::SetVisible(bool is_visible) { |
+ if (bubble_widget_) { |
+ if (is_visible) |
+ bubble_widget_->Show(); |
+ else |
+ bubble_widget_->Hide(); |
+ } |
+} |
+ |
+bool SystemTrayBubble::IsVisible() { |
+ return bubble_widget_ && bubble_widget_->IsVisible(); |
+} |
+ |
void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) { |
for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
it != items_.end(); |