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 f1dfbc1fbbbe622552a493ee13f4da12a2c7eb7c..67d8c75a3aa5c03d3c189f3f90f8e5d732f1e03c 100644 |
--- a/ui/views/bubble/tray_bubble_view.cc |
+++ b/ui/views/bubble/tray_bubble_view.cc |
@@ -48,7 +48,7 @@ class TrayBubbleBorder : public views::BubbleBorder { |
owner_(owner), |
anchor_(anchor), |
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 +59,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 +76,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 { |
- 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); |
- } |
+ 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 { |
+ 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 +152,15 @@ class TrayBubbleContentMask : public ui::LayerDelegate { |
TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) |
: layer_(ui::LAYER_TEXTURED), |
corner_radius_(corner_radius) { |
+#ifdef USE_AURA |
Pete Williamson
2013/01/17 19:07:45
Remove ifdefs
dewittj
2013/01/18 00:57:46
Done.
|
layer_.set_delegate(this); |
+#endif |
} |
TrayBubbleContentMask::~TrayBubbleContentMask() { |
+#ifdef USE_AURA |
layer_.set_delegate(NULL); |
+#endif |
} |
void TrayBubbleContentMask::OnPaintLayer(gfx::Canvas* canvas) { |
@@ -233,7 +242,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 |
@@ -293,7 +303,7 @@ 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(); |
if (get_use_acceleration_when_possible()) |