Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(848)

Unified Diff: ui/views/bubble/tray_bubble_view.cc

Issue 2491033006: Adjust positioning of cros tray bubbles. (Closed)
Patch Set: rebase and update bug link Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/views/bubble/tray_bubble_view.h ('K') | « ui/views/bubble/tray_bubble_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6725b8b7a45fde10816b43636f011a2d0cfd51e0..61f1f7eed7b6a62befdb274ac7d5253ba7a80279 100644
--- a/ui/views/bubble/tray_bubble_view.cc
+++ b/ui/views/bubble/tray_bubble_view.cc
@@ -19,6 +19,7 @@
#include "ui/compositor/paint_recorder.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/path.h"
@@ -28,25 +29,26 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
-namespace {
-
-// Inset the arrow a bit from the edge.
-const int kArrowMinOffset = 20;
-const int kBubbleSpacing = 20;
+namespace views {
-// The new theme adjusts the menus / bubbles to be flush with the shelf when
-// there is no bubble. These are the offsets which need to be applied.
-const int kArrowOffsetTopBottom = 4;
-const int kArrowOffsetLeft = 9;
-const int kArrowOffsetRight = -5;
-const int kOffsetLeftRightForTopBottomOrientation = 5;
+namespace {
// The sampling time for mouse position changes in ms - which is roughly a frame
// time.
const int kFrameTimeInMS = 30;
-} // namespace
-namespace views {
+BubbleBorder::Arrow GetArrowAlignment(
+ TrayBubbleView::AnchorAlignment alignment) {
+ if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
+ return base::i18n::IsRTL() ? BubbleBorder::BOTTOM_LEFT
+ : BubbleBorder::BOTTOM_RIGHT;
+ }
+ if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT)
+ return BubbleBorder::LEFT_BOTTOM;
+ return BubbleBorder::RIGHT_BOTTOM;
+}
+
+} // namespace
namespace internal {
@@ -74,104 +76,6 @@ bool MouseMoveDetectorHost::Contains(const gfx::Point& screen_point,
return false;
}
-// Custom border for TrayBubbleView. Contains special logic for GetBounds()
-// to stack bubbles with no arrows correctly. Also calculates the arrow offset.
-class TrayBubbleBorder : public BubbleBorder {
- public:
- TrayBubbleBorder(View* owner,
- View* anchor,
- TrayBubbleView::InitParams params)
- : BubbleBorder(params.arrow, params.shadow, params.arrow_color),
- owner_(owner),
- anchor_(anchor),
- tray_arrow_offset_(params.arrow_offset),
- first_item_has_no_margin_(params.first_item_has_no_margin) {
- set_alignment(params.arrow_alignment);
- set_background_color(params.arrow_color);
- set_paint_arrow(params.arrow_paint_type);
- }
-
- ~TrayBubbleBorder() override {}
-
- // Overridden from BubbleBorder.
- // Sets the bubble on top of the anchor when it has no arrow.
- gfx::Rect GetBounds(const gfx::Rect& position_relative_to,
- const gfx::Size& contents_size) const override {
- if (has_arrow(arrow())) {
- gfx::Rect rect =
- BubbleBorder::GetBounds(position_relative_to, contents_size);
- if (first_item_has_no_margin_) {
- if (arrow() == BubbleBorder::BOTTOM_RIGHT ||
- arrow() == BubbleBorder::BOTTOM_LEFT) {
- rect.set_y(rect.y() + kArrowOffsetTopBottom);
- int rtl_factor = base::i18n::IsRTL() ? -1 : 1;
- rect.set_x(rect.x() +
- rtl_factor * kOffsetLeftRightForTopBottomOrientation);
- } else if (arrow() == BubbleBorder::LEFT_BOTTOM) {
- rect.set_x(rect.x() + kArrowOffsetLeft);
- } else if (arrow() == BubbleBorder::RIGHT_BOTTOM) {
- rect.set_x(rect.x() + kArrowOffsetRight);
- }
- }
- return rect;
- }
-
- gfx::Size border_size(contents_size);
- gfx::Insets insets = GetInsets();
- border_size.Enlarge(insets.width(), insets.height());
- const int x = position_relative_to.x() +
- position_relative_to.width() / 2 - border_size.width() / 2;
- // Position the bubble on top of the anchor.
- const int y = position_relative_to.y() - border_size.height() +
- insets.height() - kBubbleSpacing;
- return gfx::Rect(x, y, border_size.width(), border_size.height());
- }
-
- void UpdateArrowOffset() {
- int arrow_offset = 0;
- if (arrow() == BubbleBorder::BOTTOM_RIGHT ||
- arrow() == 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);
- View::ConvertPointToScreen(anchor_->GetWidget()->GetRootView(), &pt);
- View::ConvertPointFromScreen(owner_->GetWidget()->GetRootView(), &pt);
- arrow_offset = pt.x();
- if (arrow() == BubbleBorder::BOTTOM_RIGHT)
- arrow_offset = width - arrow_offset;
- arrow_offset = std::max(arrow_offset, kArrowMinOffset);
- }
- } else {
- if (tray_arrow_offset_ ==
- TrayBubbleView::InitParams::kArrowDefaultOffset) {
- arrow_offset = kArrowMinOffset;
- } else {
- gfx::Point pt(0, tray_arrow_offset_);
- View::ConvertPointToScreen(anchor_->GetWidget()->GetRootView(), &pt);
- View::ConvertPointFromScreen(owner_->GetWidget()->GetRootView(), &pt);
- arrow_offset = pt.y();
- arrow_offset = std::max(arrow_offset, kArrowMinOffset);
- }
- }
- set_arrow_offset(arrow_offset);
- }
-
- private:
- View* owner_;
- View* anchor_;
- const int tray_arrow_offset_;
-
- // If true the first item should not get any additional spacing against the
- // anchor (without the bubble tip the bubble should be flush to the shelf).
- const bool first_item_has_no_margin_;
-
- DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder);
-};
-
// This mask layer clips the bubble's content so that it does not overwrite the
// rounded bubble corners.
// TODO(miket): This does not work on Windows. Implement layer masking or
@@ -259,32 +163,19 @@ class BottomAlignedBoxLayout : public BoxLayout {
} // namespace internal
-using internal::TrayBubbleBorder;
using internal::TrayBubbleContentMask;
using internal::BottomAlignedBoxLayout;
-// static
-const int TrayBubbleView::InitParams::kArrowDefaultOffset = -1;
-
-TrayBubbleView::InitParams::InitParams(AnchorType anchor_type,
- AnchorAlignment anchor_alignment,
+TrayBubbleView::InitParams::InitParams(AnchorAlignment anchor_alignment,
int min_width,
int max_width)
- : anchor_type(anchor_type),
- anchor_alignment(anchor_alignment),
+ : anchor_alignment(anchor_alignment),
min_width(min_width),
max_width(max_width),
max_height(0),
can_activate(false),
close_on_deactivate(true),
- arrow_color(SK_ColorBLACK),
- first_item_has_no_margin(false),
- arrow(BubbleBorder::NONE),
- arrow_offset(kArrowDefaultOffset),
- arrow_paint_type(BubbleBorder::PAINT_NORMAL),
- shadow(BubbleBorder::BIG_SHADOW),
- arrow_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) {
-}
+ bg_color(gfx::kPlaceholderColor) {}
TrayBubbleView::InitParams::InitParams(const InitParams& other) = default;
@@ -292,37 +183,25 @@ TrayBubbleView::InitParams::InitParams(const InitParams& other) = default;
TrayBubbleView* TrayBubbleView::Create(View* anchor,
Delegate* delegate,
InitParams* init_params) {
- DCHECK(anchor);
- // Set arrow here so that it can be passed to the BubbleView constructor.
- if (init_params->anchor_type == ANCHOR_TYPE_TRAY) {
- if (init_params->anchor_alignment == ANCHOR_ALIGNMENT_BOTTOM) {
- init_params->arrow = base::i18n::IsRTL() ?
- BubbleBorder::BOTTOM_LEFT : BubbleBorder::BOTTOM_RIGHT;
- } else if (init_params->anchor_alignment == ANCHOR_ALIGNMENT_TOP) {
- init_params->arrow = BubbleBorder::TOP_LEFT;
- } else if (init_params->anchor_alignment == ANCHOR_ALIGNMENT_LEFT) {
- init_params->arrow = BubbleBorder::LEFT_BOTTOM;
- } else {
- init_params->arrow = BubbleBorder::RIGHT_BOTTOM;
- }
- } else {
- init_params->arrow = BubbleBorder::NONE;
- }
-
return new TrayBubbleView(anchor, delegate, *init_params);
}
TrayBubbleView::TrayBubbleView(View* anchor,
Delegate* delegate,
const InitParams& init_params)
- : BubbleDialogDelegateView(anchor, init_params.arrow),
+ : BubbleDialogDelegateView(anchor,
+ GetArrowAlignment(init_params.anchor_alignment)),
params_(init_params),
delegate_(delegate),
preferred_width_(init_params.min_width),
- bubble_border_(new TrayBubbleBorder(this, GetAnchorView(), init_params)),
+ bubble_border_(new BubbleBorder(arrow(),
+ BubbleBorder::BIG_SHADOW,
+ init_params.bg_color)),
owned_bubble_border_(bubble_border_),
is_gesture_dragging_(false),
mouse_actively_entered_(false) {
+ bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
+ bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE);
set_can_activate(params_.can_activate);
DCHECK(anchor_widget()); // Computed by BubbleDialogDelegateView().
set_notify_enter_exit_on_child(true);
@@ -342,10 +221,6 @@ TrayBubbleView::~TrayBubbleView() {
}
void TrayBubbleView::InitializeAndShowBubble() {
- // Must occur after call to BubbleDialogDelegateView::CreateBubble().
- SetAlignment(params_.arrow_alignment);
- bubble_border_->UpdateArrowOffset();
-
layer()->parent()->SetMaskLayer(bubble_content_mask_->layer());
GetWidget()->Show();
@@ -377,12 +252,6 @@ void TrayBubbleView::SetWidth(int width) {
SizeToContents();
}
-void TrayBubbleView::SetArrowPaintType(
- views::BubbleBorder::ArrowPaintType paint_type) {
- bubble_border_->set_paint_arrow(paint_type);
- UpdateBubble();
-}
-
gfx::Insets TrayBubbleView::GetBorderInsets() const {
return bubble_border_->GetInsets();
}
@@ -397,14 +266,6 @@ void TrayBubbleView::Init() {
SetLayoutManager(layout);
}
-gfx::Rect TrayBubbleView::GetAnchorRect() const {
- if (!delegate_)
- return gfx::Rect();
- return delegate_->GetAnchorRect(anchor_widget(),
- params_.anchor_type,
- params_.anchor_alignment);
-}
-
void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params,
Widget* bubble_widget) const {
if (delegate_)
« ui/views/bubble/tray_bubble_view.h ('K') | « ui/views/bubble/tray_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698