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..2f25c3349ee33a9138c2c2dd692920801256f867 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,6 +118,7 @@ class TrayBubbleBorder : public views::BubbleBorder { |
DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder); |
}; |
+#if defined(OS_WIN) && !defined(USE_AURA) |
// 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 { |
@@ -171,6 +173,39 @@ class TrayBubbleBackground : public views::Background { |
DISALLOW_COPY_AND_ASSIGN(TrayBubbleBackground); |
}; |
+#else |
+class TrayBubbleContentMask : public ui::Layer, public ui::LayerDelegate { |
+ public: |
+ TrayBubbleContentMask(views::BubbleBorder* border) |
+ : Layer(ui::LAYER_TEXTURED), |
+ radius_(SkIntToScalar(border->GetBorderCornerRadius() - 1)) { |
+ set_delegate(this); |
+ } |
+ |
+ // Overridden from LayerDelegate: |
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
+ SkPath path; |
+ path.addRoundRect(gfx::RectToSkRect(gfx::Rect(bounds().size())), |
+ radius_, radius_); |
+ SkPaint paint; |
+ paint.setAlpha(255); |
+ paint.setStyle(SkPaint::kFill_Style); |
+ canvas->DrawPath(path, paint); |
+ } |
+ |
+ virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { |
+ } |
+ |
+ virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE { |
+ return base::Closure(); |
+ } |
+ |
+ private: |
+ SkScalar radius_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask); |
+}; |
+#endif // defined(OS_WIN) && !defined(USE_AURA) |
// Custom layout for the bubble-view. Does the default box-layout if there is |
// enough height. Otherwise, makes sure the bottom rows are visible. |
@@ -212,7 +247,11 @@ class BottomAlignedBoxLayout : public views::BoxLayout { |
} // namespace internal |
using internal::TrayBubbleBorder; |
+#if defined(OS_WIN) && !defined(USE_AURA) |
using internal::TrayBubbleBackground; |
+#else |
+using internal::TrayBubbleContentMask; |
+#endif |
using internal::BottomAlignedBoxLayout; |
// static |
@@ -227,7 +266,9 @@ TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, |
max_height(0), |
can_activate(false), |
close_on_deactivate(true), |
+#if defined(OS_WIN) && !defined(USE_AURA) |
top_color(SK_ColorBLACK), |
+#endif |
arrow_color(SK_ColorBLACK), |
arrow_location(views::BubbleBorder::NONE), |
arrow_offset(kArrowDefaultOffset), |
@@ -265,7 +306,9 @@ TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window, |
params_(init_params), |
delegate_(delegate), |
bubble_border_(NULL), |
+#if defined(OS_WIN) && !defined(USE_AURA) |
bubble_background_(NULL), |
+#endif |
is_gesture_dragging_(false) { |
set_parent_window(parent_window); |
set_notify_enter_exit_on_child(true); |
@@ -275,13 +318,20 @@ TrayBubbleView::TrayBubbleView(gfx::NativeView parent_window, |
bubble_border_ = new TrayBubbleBorder(this, anchor_view(), params_); |
+#if defined(OS_WIN) && !defined(USE_AURA) |
+ // On Windows non-aura, the bubble's top and bottom margins are painted by a |
+ // custom background class that is aware of the bubble's rounded corners. |
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)); |
+#else |
+ // On all other platforms, the bubble's content is allowed to extend to the |
+ // bubble's edges and a mask layer ensures that the bubble's rounded corners |
+ // do not get overwritten. |
+ bubble_content_mask_.reset(new TrayBubbleContentMask(bubble_border_)); |
sky
2012/11/07 15:30:37
Can we instead use ClipPath when painting so that
bartfab (slow)
2012/11/07 15:34:06
The problem is that the ash tray context menu cont
|
+ set_margins(gfx::Insets()); |
+#endif // defined(OS_WIN) && !defined(USE_AURA) |
} |
TrayBubbleView::~TrayBubbleView() { |
@@ -295,12 +345,19 @@ void TrayBubbleView::InitializeAndShowBubble() { |
SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
bubble_border_->UpdateArrowOffset(); |
+#if !defined(OS_WIN) || defined(USE_AURA) |
+ layer()->parent()->SetMaskLayer(bubble_content_mask_.get()); |
+#endif |
+ |
Show(); |
UpdateBubble(); |
} |
void TrayBubbleView::UpdateBubble() { |
SizeToContents(); |
+#if !defined(OS_WIN) || defined(USE_AURA) |
+ bubble_content_mask_->SetBounds(layer()->bounds()); |
+#endif |
GetWidget()->GetRootView()->SchedulePaint(); |
} |
@@ -341,7 +398,9 @@ views::NonClientFrameView* TrayBubbleView::CreateNonClientFrameView( |
views::Widget* widget) { |
views::BubbleFrameView* bubble_frame_view = |
new views::BubbleFrameView(margins(), bubble_border_); |
+#if defined(OS_WIN) && !defined(USE_AURA) |
bubble_frame_view->set_background(bubble_background_); |
+#endif |
return bubble_frame_view; |
} |