Index: ui/views/bubble/tray_bubble_view.cc |
diff --git a/ui/views/bubble/tray_bubble_view.cc b/ui/views/bubble/tray_bubble_view.cc |
index 9a7b0412adfc2183b8aedc2c898b374030fa7a2e..c9600592613ad42aa6847398326e60791ab3bf0a 100644 |
--- a/ui/views/bubble/tray_bubble_view.cc |
+++ b/ui/views/bubble/tray_bubble_view.cc |
@@ -43,12 +43,14 @@ class TrayBubbleBorder : public views::BubbleBorder { |
public: |
TrayBubbleBorder(views::View* owner, |
views::View* anchor, |
+ gfx::Point anchor_point, |
TrayBubbleView::InitParams params) |
: views::BubbleBorder(params.arrow_location, params.shadow), |
owner_(owner), |
anchor_(anchor), |
+ anchor_point_(anchor_point.x(), anchor_point.y()), |
tray_arrow_offset_(params.arrow_offset) { |
- set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
+ set_alignment(params.arrow_alignment); |
set_background_color(params.arrow_color); |
} |
@@ -59,7 +61,7 @@ class TrayBubbleBorder : public views::BubbleBorder { |
// 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) { |
+ if (has_arrow(arrow_location())) { |
return views::BubbleBorder::GetBounds(position_relative_to, |
contents_size); |
} |
@@ -76,46 +78,51 @@ class TrayBubbleBorder : public views::BubbleBorder { |
return gfx::Rect(x, y, border_size.width(), border_size.height()); |
} |
+ // Anchor point is in screen coordinates. |
void UpdateArrowOffset() { |
+ if (!has_arrow(arrow_location())) { |
+ return; |
+ } |
+ |
int arrow_offset = 0; |
- if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT || |
- arrow_location() == views::BubbleBorder::BOTTOM_LEFT) { |
- // Note: tray_arrow_offset_ is relative to the anchor widget. |
- if (tray_arrow_offset_ == |
- TrayBubbleView::InitParams::kArrowDefaultOffset) { |
- arrow_offset = kArrowMinOffset; |
- } else { |
- const int width = owner_->GetWidget()->GetContentsView()->width(); |
- gfx::Point pt(tray_arrow_offset_, 0); |
- views::View::ConvertPointToScreen( |
- anchor_->GetWidget()->GetRootView(), &pt); |
- views::View::ConvertPointFromScreen( |
- owner_->GetWidget()->GetRootView(), &pt); |
- arrow_offset = pt.x(); |
- if (arrow_location() == views::BubbleBorder::BOTTOM_RIGHT) |
- arrow_offset = width - arrow_offset; |
- arrow_offset = std::max(arrow_offset, kArrowMinOffset); |
- } |
+ gfx::Point pt(0, 0); |
+ if (tray_arrow_offset_ == TrayBubbleView::InitParams::kArrowDefaultOffset) { |
+ set_arrow_offset(kArrowMinOffset); |
+ return; |
+ } |
+ // Note: tray_arrow_offset_ is relative to the anchor widget. |
+ if (is_arrow_on_horizontal(arrow_location())) |
+ pt.set_x(tray_arrow_offset_); |
+ else |
+ pt.set_y(tray_arrow_offset_); |
+ |
+ if (anchor_) { |
+ views::View::ConvertPointToScreen( |
+ anchor_->GetWidget()->GetRootView(), &pt); |
+ } else { |
+ pt.Offset(anchor_point_.x(), anchor_point_.y()); |
+ } |
+ |
+ views::View::ConvertPointFromScreen( |
+ owner_->GetWidget()->GetRootView(), &pt); |
+ const int width = owner_->GetWidget()->GetContentsView()->width(); |
+ |
+ if (is_arrow_on_horizontal(arrow_location())) { |
+ arrow_offset = pt.x(); |
+ if (!is_arrow_on_left(arrow_location())) |
+ arrow_offset = width - arrow_offset; |
} else { |
- if (tray_arrow_offset_ == |
- TrayBubbleView::InitParams::kArrowDefaultOffset) { |
- arrow_offset = kArrowMinOffset; |
- } else { |
- gfx::Point pt(0, tray_arrow_offset_); |
- views::View::ConvertPointToScreen( |
- anchor_->GetWidget()->GetRootView(), &pt); |
- views::View::ConvertPointFromScreen( |
- owner_->GetWidget()->GetRootView(), &pt); |
- arrow_offset = pt.y(); |
- arrow_offset = std::max(arrow_offset, kArrowMinOffset); |
- } |
+ arrow_offset = pt.y(); |
} |
+ |
+ arrow_offset = std::max(arrow_offset, kArrowMinOffset); |
set_arrow_offset(arrow_offset); |
} |
private: |
views::View* owner_; |
views::View* anchor_; |
+ gfx::Point anchor_point_; |
const int tray_arrow_offset_; |
DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder); |
@@ -147,11 +154,15 @@ class TrayBubbleContentMask : public ui::LayerDelegate { |
TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) |
: layer_(ui::LAYER_TEXTURED), |
corner_radius_(corner_radius) { |
+#ifdef USE_AURA |
layer_.set_delegate(this); |
+#endif |
} |
TrayBubbleContentMask::~TrayBubbleContentMask() { |
+#ifdef USE_AURA |
layer_.set_delegate(NULL); |
+#endif |
} |
void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { |
@@ -233,7 +244,8 @@ TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, |
arrow_color(SK_ColorBLACK), |
arrow_location(views::BubbleBorder::NONE), |
arrow_offset(kArrowDefaultOffset), |
- shadow(views::BubbleBorder::BIG_SHADOW) { |
+ shadow(views::BubbleBorder::BIG_SHADOW), |
+ arrow_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) { |
} |
// static |
@@ -273,13 +285,19 @@ TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window, |
set_notify_enter_exit_on_child(true); |
set_close_on_deactivate(init_params.close_on_deactivate); |
set_margins(gfx::Insets()); |
+ bubble_border_ = new TrayBubbleBorder( |
+ this, |
+ anchor_view(), |
+ gfx::Point(init_params.anchor_point_x, init_params.anchor_point_y), |
+ params_); |
+ |
+#ifdef USE_AURA |
SetPaintToLayer(true); |
SetFillsBoundsOpaquely(true); |
- bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_); |
- |
bubble_content_mask_.reset( |
new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius() - 1)); |
+#endif //USE_AURA |
} |
TrayBubbleView::~TrayBubbleView() { |
@@ -290,10 +308,12 @@ TrayBubbleView::~TrayBubbleView() { |
void TrayBubbleView::InitializeAndShowBubble() { |
// Must occur after call to BubbleDelegateView::CreateBubble(). |
- SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
+ SetAlignment(params_.arrow_alignment); |
bubble_border_->UpdateArrowOffset(); |
+#ifdef USE_AURA |
layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); |
+#endif // USE_AURA |
Show(); |
UpdateBubble(); |
@@ -301,7 +321,9 @@ void TrayBubbleView::InitializeAndShowBubble() { |
void TrayBubbleView::UpdateBubble() { |
SizeToContents(); |
+#ifdef USE_AURA |
bubble_content_mask_->layer()->SetBounds(layer()->bounds()); |
+#endif // USE_AURA |
GetWidget()->GetRootView()->SchedulePaint(); |
} |
@@ -401,11 +423,13 @@ void TrayBubbleView::ChildPreferredSizeChanged(View* child) { |
void TrayBubbleView::ViewHierarchyChanged(bool is_add, |
views::View* parent, |
views::View* child) { |
+#ifdef USE_AURA |
if (is_add && child == this) { |
parent->SetPaintToLayer(true); |
parent->SetFillsBoundsOpaquely(true); |
parent->layer()->SetMasksToBounds(true); |
} |
+#endif // USE_AURA |
} |
} // namespace views |