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

Unified Diff: ui/aura/window.cc

Issue 8555025: aura: Draw drop shadows under browsers and menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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/aura/window.cc
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index d1caa0416e6eab3ea3e35464644793eef6d29341..c10ef6a20fd883e509b63178e5123a68df6f6483 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -13,6 +13,7 @@
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
#include "ui/aura/layout_manager.h"
+#include "ui/aura/shadow.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_types.h"
@@ -30,7 +31,8 @@ Window::Window(WindowDelegate* delegate)
transient_parent_(NULL),
id_(-1),
user_data_(NULL),
- stops_event_propagation_(false) {
+ stops_event_propagation_(false),
+ show_shadow_(false) {
}
Window::~Window() {
@@ -74,6 +76,9 @@ void Window::Init(ui::Layer::LayerType layer_type) {
layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), layer_type));
layer_->SetVisible(false);
layer_->set_delegate(this);
+
+ if (show_shadow_)
+ InitShadow();
}
void Window::SetType(WindowType type) {
@@ -190,6 +195,8 @@ void Window::MoveChildAbove(Window* child, Window* other) {
// Reorder the layer.
layer()->MoveAbove(child->layer(), other->layer());
+ if (child->shadow_.get())
+ layer()->MoveAbove(child->shadow_->layer(), other->layer());
// Move any transient children that share the same parent to be in front of
// 'child'.
@@ -214,7 +221,11 @@ void Window::AddChild(Window* child) {
if (child->parent())
child->parent()->RemoveChild(child);
child->parent_ = this;
+
+ if (child->shadow_.get())
+ layer_->Add(child->shadow_->layer());
layer_->Add(child->layer_.get());
+
children_.push_back(child);
if (layout_manager_.get())
layout_manager_->OnWindowAddedToLayout(child);
@@ -250,6 +261,8 @@ void Window::RemoveChild(Window* child) {
if (desktop)
desktop->WindowDetachedFromDesktop(child);
layer_->Remove(child->layer_.get());
+ if (child->shadow_.get())
+ layer_->Remove(child->shadow_->layer());
children_.erase(i);
}
@@ -405,6 +418,14 @@ int Window::GetIntProperty(const char* name) const {
GetProperty(name)));
}
+void Window::SetShadowVisible(bool visible) {
+ show_shadow_ = visible;
+ if (visible && !shadow_.get() && layer())
+ InitShadow();
+ else if (shadow_.get())
+ shadow_->layer()->SetVisible(visible);
+}
+
Desktop* Window::GetDesktop() {
return parent_ ? parent_->GetDesktop() : NULL;
}
@@ -418,6 +439,8 @@ void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
// Always need to set the layer's bounds -- even if it is to the same thing.
// This may cause important side effects such as stopping animation.
layer_->SetBounds(new_bounds);
+ if (shadow_.get())
+ shadow_->SetContentBounds(new_bounds);
// If we're not changing the effective bounds, then we can bail early and skip
// notifying our listeners.
@@ -442,6 +465,10 @@ void Window::SetVisible(bool visible) {
if (delegate_)
delegate_->OnWindowVisibilityChanged(is_visible);
}
+
+ if (shadow_.get())
+ shadow_->layer()->SetVisible(show_shadow_ && visible);
+
if (parent_ && parent_->layout_manager_.get())
parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible);
FOR_EACH_OBSERVER(WindowObserver, observers_,
@@ -490,6 +517,25 @@ Window* Window::GetWindowForPoint(const gfx::Point& local_point,
return delegate_ ? this : NULL;
}
+void Window::InitShadow() {
+ DCHECK(layer());
+
+ shadow_.reset(new internal::Shadow());
+ shadow_->Init();
+ if (parent_) {
+ // Stack the shadow directly below |layer_|.
+ parent_->layer_->Add(shadow_->layer());
+ // TODO(derat): Add a MoveBelow() method and use that instead (although we
+ // then run the risk of things getting stacked between a window and its
+ // shadow).
+ parent_->layer_->MoveAbove(shadow_->layer(), layer_.get());
+ parent_->layer_->MoveAbove(layer_.get(), shadow_->layer());
+ }
+
+ shadow_->SetContentBounds(bounds());
+ shadow_->layer()->SetVisible(show_shadow_);
+}
+
void Window::OnPaintLayer(gfx::Canvas* canvas) {
if (delegate_)
delegate_->OnPaint(canvas);

Powered by Google App Engine
This is Rietveld 408576698