diff options
Diffstat (limited to 'views')
-rw-r--r-- | views/bubble/border_contents_view.cc | 5 | ||||
-rw-r--r-- | views/bubble/border_contents_view.h | 3 | ||||
-rw-r--r-- | views/bubble/bubble_border.cc | 14 | ||||
-rw-r--r-- | views/bubble/bubble_border.h | 14 |
4 files changed, 32 insertions, 4 deletions
diff --git a/views/bubble/border_contents_view.cc b/views/bubble/border_contents_view.cc index 1582751..f846b3a 100644 --- a/views/bubble/border_contents_view.cc +++ b/views/bubble/border_contents_view.cc @@ -87,6 +87,11 @@ void BorderContentsView::SetBackgroundColor(SkColor color) { bubble_border_->set_background_color(color); } +void BorderContentsView::SetAlignment( + views::BubbleBorder::BubbleAlignment alignment) { + bubble_border_->set_alignment(alignment); +} + void BorderContentsView::SizeAndGetBounds( const gfx::Rect& position_relative_to, BubbleBorder::ArrowLocation arrow_location, diff --git a/views/bubble/border_contents_view.h b/views/bubble/border_contents_view.h index 3c5a162..49ddb6a 100644 --- a/views/bubble/border_contents_view.h +++ b/views/bubble/border_contents_view.h @@ -27,6 +27,9 @@ class VIEWS_EXPORT BorderContentsView : public View { // Sets the background color. void SetBackgroundColor(SkColor color); + // Sets the bubble alignment. + void SetAlignment(views::BubbleBorder::BubbleAlignment alignment); + // Given the size of the contents and the rect to point at, returns the bounds // of both the border and the contents inside the bubble. // |arrow_location| specifies the preferred location for the arrow diff --git a/views/bubble/bubble_border.cc b/views/bubble/bubble_border.cc index 377e94f..70f08dd 100644 --- a/views/bubble/bubble_border.cc +++ b/views/bubble/bubble_border.cc @@ -60,12 +60,15 @@ gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& position_relative_to, switch (arrow_location_) { case TOP_LEFT: case BOTTOM_LEFT: - x += w / 2 - arrow_offset; + x += alignment_ == ALIGN_ARROW_TO_MID_ANCHOR ? w / 2 - arrow_offset : + -kArrowOverlap; break; case TOP_RIGHT: case BOTTOM_RIGHT: - x += w / 2 + arrow_offset - border_size.width() + 1; + x += alignment_ == ALIGN_ARROW_TO_MID_ANCHOR ? + w / 2 + arrow_offset - border_size.width() + 1 : + w - border_size.width() + kArrowOverlap; break; case LEFT_TOP: @@ -98,12 +101,15 @@ gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& position_relative_to, case LEFT_TOP: case RIGHT_TOP: - y += h / 2 - arrow_offset; + y += alignment_ == ALIGN_ARROW_TO_MID_ANCHOR ? h / 2 - arrow_offset : + -kArrowOverlap; break; case LEFT_BOTTOM: case RIGHT_BOTTOM: - y += h / 2 + arrow_offset - border_size.height() + 1; + y += alignment_ == ALIGN_ARROW_TO_MID_ANCHOR ? + h / 2 + arrow_offset - border_size.height() + 1 : + h - border_size.height() + kArrowOverlap; break; case NONE: diff --git a/views/bubble/bubble_border.h b/views/bubble/bubble_border.h index ce0c448..edca71e 100644 --- a/views/bubble/bubble_border.h +++ b/views/bubble/bubble_border.h @@ -34,9 +34,18 @@ class VIEWS_EXPORT BubbleBorder : public views::Border { FLOAT = 9 // No arrow. Centered over the supplied rect. }; + // The position of the bubble in relation to the anchor. + enum BubbleAlignment { + // The tip of the arrow points to the middle of the anchor. + ALIGN_ARROW_TO_MID_ANCHOR, + // The edge nearest to the arrow is lined up with the edge of the anchor. + ALIGN_EDGE_TO_ANCHOR_EDGE + }; + explicit BubbleBorder(ArrowLocation arrow_location) : override_arrow_offset_(0), arrow_location_(arrow_location), + alignment_(ALIGN_ARROW_TO_MID_ANCHOR), background_color_(SK_ColorWHITE) { InitClass(); } @@ -56,6 +65,10 @@ class VIEWS_EXPORT BubbleBorder : public views::Border { } ArrowLocation arrow_location() const { return arrow_location_; } + // Sets the alignment. + void set_alignment(BubbleAlignment alignment) { alignment_ = alignment; } + BubbleAlignment alignment() const { return alignment_; } + static ArrowLocation horizontal_mirror(ArrowLocation loc) { return loc >= NONE ? loc : static_cast<ArrowLocation>(loc ^ 1); } @@ -150,6 +163,7 @@ class VIEWS_EXPORT BubbleBorder : public views::Border { int override_arrow_offset_; ArrowLocation arrow_location_; + BubbleAlignment alignment_; SkColor background_color_; DISALLOW_COPY_AND_ASSIGN(BubbleBorder); |