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

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

Issue 11293124: Remove top and bottom margins from TrayBubbleView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made TrayBubbleView aura-only, removed #ifdefs. Created 8 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
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 d83055bef30b98d451d61c0b314741ad9c1c7575..997f7917d1b4fd9b734bec6744361bd74ca192db 100644
--- a/ui/views/bubble/tray_bubble_view.cc
+++ b/ui/views/bubble/tray_bubble_view.cc
@@ -15,6 +15,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/path.h"
+#include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/layout/box_layout.h"
@@ -117,59 +118,40 @@ class TrayBubbleBorder : public views::BubbleBorder {
DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder);
};
-// Custom background for TrayBubbleView. Fills in the top and bottom margins
-// with appropriate background colors without overwriting the rounded corners.
-class TrayBubbleBackground : public views::Background {
+// This mask layer clips the bubble's content so that it does not overwrite the
+// rounded bubble corners.
+// TODO: This does not work on Windows. Implement layer masking or alternate
+// solutions if the TrayBubbleView is needed there in the future.
+class TrayBubbleContentMask : public ui::Layer, public ui::LayerDelegate {
public:
- explicit TrayBubbleBackground(views::BubbleBorder* border,
- SkColor top_color,
- SkColor bottom_color)
- : border_(border),
- top_color_(top_color),
- bottom_color_(bottom_color),
- radius_(SkIntToScalar(border->GetBorderCornerRadius() - 1)) {
+ TrayBubbleContentMask(views::BubbleBorder* border)
+ : Layer(ui::LAYER_TEXTURED),
+ radius_(SkIntToScalar(border->GetBorderCornerRadius() - 1)) {
+ set_delegate(this);
}
- SkScalar radius() const { return radius_; }
-
- // Overridden from Background:
- virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
- canvas->Save();
-
- // Set a clip mask for the bubble's rounded corners.
- gfx::Rect bounds(view->GetContentsBounds());
- const int border_thickness(border_->GetBorderThickness());
- bounds.Inset(-border_thickness, -border_thickness);
+ // Overridden from LayerDelegate:
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
SkPath path;
- path.addRoundRect(gfx::RectToSkRect(bounds), radius_, radius_);
- canvas->ClipPath(path);
-
- // Paint the header and footer (assumes the bubble contents fill in their
- // own backgrounds).
+ path.addRoundRect(gfx::RectToSkRect(gfx::Rect(bounds().size())),
+ radius_, radius_);
SkPaint paint;
+ paint.setAlpha(255);
paint.setStyle(SkPaint::kFill_Style);
+ canvas->DrawPath(path, paint);
+ }
- gfx::Rect top_rect(bounds);
- top_rect.set_height(radius_);
- paint.setColor(top_color_);
- canvas->DrawRect(top_rect, paint);
-
- gfx::Rect bottom_rect(bounds);
- bottom_rect.set_y(bounds.y() + (bounds.height() - radius_));
- bottom_rect.set_height(radius_);
- paint.setColor(bottom_color_);
- canvas->DrawRect(bottom_rect, paint);
+ virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {
+ }
- canvas->Restore();
+ virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE {
+ return base::Closure();
}
private:
- views::BubbleBorder* border_;
- SkColor top_color_;
- SkColor bottom_color_;
SkScalar radius_;
- DISALLOW_COPY_AND_ASSIGN(TrayBubbleBackground);
+ DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask);
};
// Custom layout for the bubble-view. Does the default box-layout if there is
@@ -212,7 +194,7 @@ class BottomAlignedBoxLayout : public views::BoxLayout {
} // namespace internal
using internal::TrayBubbleBorder;
-using internal::TrayBubbleBackground;
+using internal::TrayBubbleContentMask;
using internal::BottomAlignedBoxLayout;
// static
@@ -227,7 +209,6 @@ TrayBubbleView::InitParams::InitParams(AnchorType anchor_type,
max_height(0),
can_activate(false),
close_on_deactivate(true),
- top_color(SK_ColorBLACK),
arrow_color(SK_ColorBLACK),
arrow_location(views::BubbleBorder::NONE),
arrow_offset(kArrowDefaultOffset),
@@ -265,23 +246,17 @@ TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window,
params_(init_params),
delegate_(delegate),
bubble_border_(NULL),
- bubble_background_(NULL),
is_gesture_dragging_(false) {
set_parent_window(parent_window);
set_notify_enter_exit_on_child(true);
set_close_on_deactivate(init_params.close_on_deactivate);
+ set_margins(gfx::Insets());
SetPaintToLayer(true);
SetFillsBoundsOpaquely(true);
bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_);
- bubble_background_ = new TrayBubbleBackground(
- bubble_border_, init_params.top_color, init_params.arrow_color);
-
- // Inset the view on the top and bottom by the corner radius to avoid drawing
- // over the the bubble corners.
- const int radius = bubble_background_->radius();
- set_margins(gfx::Insets(radius, 0, radius, 0));
+ bubble_content_mask_.reset(new TrayBubbleContentMask(bubble_border_));
}
TrayBubbleView::~TrayBubbleView() {
@@ -295,12 +270,15 @@ void TrayBubbleView::InitializeAndShowBubble() {
SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
bubble_border_->UpdateArrowOffset();
+ layer()->parent()->SetMaskLayer(bubble_content_mask_.get());
+
Show();
UpdateBubble();
}
void TrayBubbleView::UpdateBubble() {
SizeToContents();
+ bubble_content_mask_->SetBounds(layer()->bounds());
GetWidget()->GetRootView()->SchedulePaint();
}
@@ -336,12 +314,11 @@ bool TrayBubbleView::CanActivate() const {
return params_.can_activate;
}
-// Overridden to create BubbleFrameView and set a custom border and background.
+// Overridden to create BubbleFrameView and set a custom border.
views::NonClientFrameView* TrayBubbleView::CreateNonClientFrameView(
views::Widget* widget) {
views::BubbleFrameView* bubble_frame_view =
new views::BubbleFrameView(margins(), bubble_border_);
- bubble_frame_view->set_background(bubble_background_);
return bubble_frame_view;
}
« no previous file with comments | « ui/views/bubble/tray_bubble_view.h ('k') | ui/views/views.gyp » ('j') | ui/views/views.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698