Chromium Code Reviews| 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..fa0bc06bab482193435467d0959c5797145552b1 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; |
| + } |
|
stevenjb
2013/01/18 23:11:46
No {}
dewittj
2013/01/20 19:02:06
Gone. This method is now unused by the Win code, s
|
| + |
| 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_); |
|
stevenjb
2013/01/18 23:11:46
indent
dewittj
2013/01/20 19:02:06
Gone. This method is now unused by the Win code, s
|
| + |
| + 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); |
| @@ -233,7 +238,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 +299,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()) |