Index: ui/app_list/views/app_list_view.cc |
diff --git a/ui/app_list/views/app_list_view.cc b/ui/app_list/views/app_list_view.cc |
index 0499d4569cac8f8c206fcef42d7021c09f3db87d..7daafdb475af2a336cc427d2f353e40f1bc90863 100644 |
--- a/ui/app_list/views/app_list_view.cc |
+++ b/ui/app_list/views/app_list_view.cc |
@@ -28,6 +28,7 @@ |
#include "ui/compositor/layer.h" |
#include "ui/compositor/layer_animation_observer.h" |
#include "ui/compositor/scoped_layer_animation_settings.h" |
+#include "ui/gfx/canvas.h" |
#include "ui/gfx/image/image_skia.h" |
#include "ui/gfx/insets.h" |
#include "ui/gfx/path.h" |
@@ -80,6 +81,26 @@ bool SupportsShadow() { |
return true; |
} |
+// An background for a view that appears as a colored rounded rectangle with the |
+// given radius and the same size as the target view. |
+class ColoredRoundRectBackground : public views::Background { |
+ public: |
+ ColoredRoundRectBackground(int corner_radius, SkColor color) |
+ : corner_radius_(corner_radius), color_(color) {}; |
+ virtual ~ColoredRoundRectBackground() {}; |
+ |
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
+ SkPaint paint; |
+ paint.setStyle(SkPaint::kFill_Style); |
+ paint.setColor(color_); |
+ canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); |
+ } |
+ |
+ private: |
+ const int corner_radius_; |
+ const SkColor color_; |
+}; |
+ |
} // namespace |
// An animation observer to hide the view at the end of the animation. |
@@ -129,6 +150,7 @@ AppListView::AppListView(AppListViewDelegate* delegate) |
app_list_main_view_(NULL), |
signin_view_(NULL), |
speech_view_(NULL), |
+ overlay_view_(NULL), |
animation_observer_(new HideViewAnimationObserver()) { |
CHECK(delegate); |
@@ -196,6 +218,32 @@ void AppListView::UpdateBounds() { |
SizeToContents(); |
} |
+void AppListView::ShowAppListOverlay(bool visible) { |
+ if (overlay_view_ == NULL) { |
calamity
2014/05/16 05:54:32
Any reason not to just construct this in the initi
sashab
2014/05/19 07:24:53
Originally I thought it would be a memory leak - i
calamity
2014/05/20 01:25:17
Actually, you're right. Better to DCHECK overlay_v
|
+ // The contents corner radius is 1px smaller than border corner radius. |
+ const int kOverlayCornerRadius = |
+ GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius() - 1; |
calamity
2014/05/16 05:54:32
Good news! Since this is a view inside the bubble
sashab
2014/05/19 07:24:53
Cool!!!
|
+ const float kOverlayOpacity = 0.75f; |
+ |
+ // To make the overlay view, construct a regular view with |
+ // ColoredRoundRectBackground as the background. This is because we need |
+ // overlay_view_ to be drawn to its own layer (so it appears correctly in |
+ // the foreground), but we also need a custom Paint() method to draw our |
+ // custom rounded rectangle (View::Paint() is not called when |
+ // SetPaintToLayer is true). |
+ overlay_view_ = new views::View(); |
+ overlay_view_->SetPaintToLayer(true); |
+ overlay_view_->set_background( |
+ new ColoredRoundRectBackground(kOverlayCornerRadius, SK_ColorWHITE)); |
calamity
2014/05/16 05:54:32
That means you can get away with views::Background
sashab
2014/05/19 07:24:53
Nice!! Done.
|
+ overlay_view_->layer()->SetOpacity(kOverlayOpacity); |
+ overlay_view_->SetBoundsRect(bounds()); |
+ |
+ // Add this view to the 'front' of the screen (end of the child view list). |
+ AddChildViewAt(overlay_view_, this->child_count()); |
calamity
2014/05/16 05:54:32
This is equivalent to AddChildView().
sashab
2014/05/19 07:24:53
So it is. Thanks.
|
+ } |
+ overlay_view_->SetVisible(visible); |
+} |
+ |
bool AppListView::ShouldCenterWindow() const { |
return delegate_->ShouldCenterWindow(); |
} |