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 d83055bef30b98d451d61c0b314741ad9c1c7575..adacb81ea22768359dda811bd1eb04016ad1d026 100644 |
| --- a/ui/views/bubble/tray_bubble_view.cc |
| +++ b/ui/views/bubble/tray_bubble_view.cc |
| @@ -117,59 +117,34 @@ 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 { |
| +class TrayBubbleContentMask : public ui::Layer, public ui::LayerDelegate { |
|
sky
2012/11/07 00:37:05
This code won't work on windows non-aura.
bartfab (slow)
2012/11/07 12:12:16
I modified the CL to preserve the previous impleme
|
| 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(bounds()), radius_, radius_); |
|
sky
2012/11/07 00:37:05
Bounds() is in the coordinate system of the parent
bartfab (slow)
2012/11/07 12:12:16
Done.
bounds() actually worked here because the b
|
| SkPaint paint; |
| paint.setStyle(SkPaint::kFill_Style); |
|
stevenjb
2012/11/06 21:43:26
What are we drawing here? I'm unfamiliar with what
bartfab (slow)
2012/11/06 23:09:14
Since this is a mask layer, only alpha matters. A
stevenjb
2012/11/06 23:17:45
I see. Might be worth commenting to that effect (o
bartfab (slow)
2012/11/07 12:12:16
I added an explicit setAlpha() call.
|
| + 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 +187,7 @@ class BottomAlignedBoxLayout : public views::BoxLayout { |
| } // namespace internal |
| using internal::TrayBubbleBorder; |
| -using internal::TrayBubbleBackground; |
| +using internal::TrayBubbleContentMask; |
| using internal::BottomAlignedBoxLayout; |
| // static |
| @@ -227,7 +202,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 +239,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 +263,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(GetContentsBounds()); |
| GetWidget()->GetRootView()->SchedulePaint(); |
| } |
| @@ -336,12 +307,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; |
| } |