| Index: ui/aura/window.cc
|
| diff --git a/ui/aura/window.cc b/ui/aura/window.cc
|
| index bae67a94a863d5557c7732111704bef3a5bb7f71..0eae023f9a84e20ea78d449e7297709d37b1501a 100644
|
| --- a/ui/aura/window.cc
|
| +++ b/ui/aura/window.cc
|
| @@ -217,9 +217,9 @@ Window::Window(WindowDelegate* delegate)
|
| }
|
|
|
| Window::~Window() {
|
| - // |layer_| can be NULL during tests, or if this Window is layerless.
|
| - if (layer_)
|
| - layer_->SuppressPaint();
|
| + // |layer()| can be NULL during tests, or if this Window is layerless.
|
| + if (layer())
|
| + layer()->SuppressPaint();
|
|
|
| // Let the delegate know we're in the processing of destroying.
|
| if (delegate_)
|
| @@ -260,20 +260,18 @@ Window::~Window() {
|
| // If we have layer it will either be destroyed by |layer_owner_|'s dtor, or
|
| // by whoever acquired it. We don't have a layer if Init() wasn't invoked or
|
| // we are layerless.
|
| - if (layer_) {
|
| - layer_->set_delegate(NULL);
|
| - layer_ = NULL;
|
| - }
|
| + if (layer())
|
| + layer()->set_delegate(NULL);
|
| + DestroyLayer();
|
| }
|
|
|
| void Window::Init(WindowLayerType window_layer_type) {
|
| if (window_layer_type != WINDOW_LAYER_NONE) {
|
| - layer_ = new ui::Layer(WindowLayerTypeToUILayerType(window_layer_type));
|
| - layer_owner_.reset(layer_);
|
| - layer_->SetVisible(false);
|
| - layer_->set_delegate(this);
|
| + SetLayer(new ui::Layer(WindowLayerTypeToUILayerType(window_layer_type)));
|
| + layer()->SetVisible(false);
|
| + layer()->set_delegate(this);
|
| UpdateLayerName(name_);
|
| - layer_->SetFillsBoundsOpaquely(!transparent_);
|
| + layer()->SetFillsBoundsOpaquely(!transparent_);
|
| }
|
|
|
| Env::GetInstance()->NotifyWindowInitialized(this);
|
| @@ -289,22 +287,21 @@ ui::Layer* Window::RecreateLayer() {
|
|
|
| old_layer->set_delegate(NULL);
|
|
|
| - layer_ = new ui::Layer(old_layer->type());
|
| - layer_owner_.reset(layer_);
|
| - layer_->SetVisible(old_layer->visible());
|
| - layer_->set_scale_content(old_layer->scale_content());
|
| - layer_->set_delegate(this);
|
| - layer_->SetMasksToBounds(old_layer->GetMasksToBounds());
|
| + SetLayer(new ui::Layer(old_layer->type()));
|
| + layer()->SetVisible(old_layer->visible());
|
| + layer()->set_scale_content(old_layer->scale_content());
|
| + layer()->set_delegate(this);
|
| + layer()->SetMasksToBounds(old_layer->GetMasksToBounds());
|
|
|
| if (delegate_)
|
| - delegate_->DidRecreateLayer(old_layer, layer_);
|
| + delegate_->DidRecreateLayer(old_layer, layer());
|
|
|
| UpdateLayerName(name_);
|
| - layer_->SetFillsBoundsOpaquely(!transparent_);
|
| + layer()->SetFillsBoundsOpaquely(!transparent_);
|
| // Install new layer as a sibling of the old layer, stacked below it.
|
| if (old_layer->parent()) {
|
| - old_layer->parent()->Add(layer_);
|
| - old_layer->parent()->StackBelow(layer_, old_layer);
|
| + old_layer->parent()->Add(layer());
|
| + old_layer->parent()->StackBelow(layer(), old_layer);
|
| }
|
| // Migrate all the child layers over to the new layer. Copy the list because
|
| // the items are removed during iteration.
|
| @@ -313,28 +310,28 @@ ui::Layer* Window::RecreateLayer() {
|
| it != children_copy.end();
|
| ++it) {
|
| ui::Layer* child = *it;
|
| - layer_->Add(child);
|
| + layer()->Add(child);
|
| }
|
| return old_layer;
|
| }
|
|
|
| void Window::SetType(ui::wm::WindowType type) {
|
| // Cannot change type after the window is initialized.
|
| - DCHECK(!layer_);
|
| + DCHECK(!layer());
|
| type_ = type;
|
| }
|
|
|
| void Window::SetName(const std::string& name) {
|
| name_ = name;
|
|
|
| - if (layer_)
|
| + if (layer())
|
| UpdateLayerName(name_);
|
| }
|
|
|
| void Window::SetTransparent(bool transparent) {
|
| transparent_ = transparent;
|
| - if (layer_)
|
| - layer_->SetFillsBoundsOpaquely(!transparent_);
|
| + if (layer())
|
| + layer()->SetFillsBoundsOpaquely(!transparent_);
|
| }
|
|
|
| Window* Window::GetRootWindow() {
|
| @@ -373,8 +370,8 @@ bool Window::IsVisible() const {
|
| for (const Window* window = this; window; window = window->parent()) {
|
| if (!window->visible_)
|
| return false;
|
| - if (window->layer_)
|
| - return window->layer_->IsDrawn();
|
| + if (window->layer())
|
| + return window->layer()->IsDrawn();
|
| }
|
| return false;
|
| }
|
| @@ -406,7 +403,7 @@ gfx::Rect Window::GetBoundsInScreen() const {
|
| }
|
|
|
| void Window::SetTransform(const gfx::Transform& transform) {
|
| - if (!layer_) {
|
| + if (!layer()) {
|
| // Transforms aren't supported on layerless windows.
|
| NOTREACHED();
|
| return;
|
| @@ -414,7 +411,7 @@ void Window::SetTransform(const gfx::Transform& transform) {
|
| WindowEventDispatcher* dispatcher = GetHost()->dispatcher();
|
| bool contained_mouse = IsVisible() && dispatcher &&
|
| ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot());
|
| - layer_->SetTransform(transform);
|
| + layer()->SetTransform(transform);
|
| if (dispatcher)
|
| dispatcher->OnWindowTransformed(this, contained_mouse);
|
| }
|
| @@ -461,11 +458,11 @@ void Window::SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen,
|
| }
|
|
|
| gfx::Rect Window::GetTargetBounds() const {
|
| - if (!layer_)
|
| + if (!layer())
|
| return bounds();
|
|
|
| - if (!parent_ || parent_->layer_)
|
| - return layer_->GetTargetBounds();
|
| + if (!parent_ || parent_->layer())
|
| + return layer()->GetTargetBounds();
|
|
|
| // We have a layer but our parent (who is valid) doesn't. This means the
|
| // coordinates of the layer are relative to the first ancestor with a layer;
|
| @@ -474,15 +471,15 @@ gfx::Rect Window::GetTargetBounds() const {
|
| const aura::Window* ancestor_with_layer =
|
| parent_->GetAncestorWithLayer(&offset);
|
| if (!ancestor_with_layer)
|
| - return layer_->GetTargetBounds();
|
| + return layer()->GetTargetBounds();
|
|
|
| - gfx::Rect layer_target_bounds = layer_->GetTargetBounds();
|
| + gfx::Rect layer_target_bounds = layer()->GetTargetBounds();
|
| layer_target_bounds -= offset;
|
| return layer_target_bounds;
|
| }
|
|
|
| void Window::SchedulePaintInRect(const gfx::Rect& rect) {
|
| - if (!layer_ && parent_) {
|
| + if (!layer() && parent_) {
|
| // Notification of paint scheduled happens for the window with a layer.
|
| gfx::Rect parent_rect(bounds().size());
|
| parent_rect.Intersect(rect);
|
| @@ -490,7 +487,7 @@ void Window::SchedulePaintInRect(const gfx::Rect& rect) {
|
| parent_rect.Offset(bounds().origin().OffsetFromOrigin());
|
| parent_->SchedulePaintInRect(parent_rect);
|
| }
|
| - } else if (layer_ && layer_->SchedulePaint(rect)) {
|
| + } else if (layer() && layer()->SchedulePaint(rect)) {
|
| FOR_EACH_OBSERVER(
|
| WindowObserver, observers_, OnWindowPaintScheduled(this, rect));
|
| }
|
| @@ -608,20 +605,20 @@ void Window::ConvertPointToTarget(const Window* source,
|
| client::ScreenPositionClient* target_client =
|
| client::GetScreenPositionClient(target->GetRootWindow());
|
| target_client->ConvertPointFromScreen(target, point);
|
| - } else if ((source != target) && (!source->layer_ || !target->layer_)) {
|
| - if (!source->layer_) {
|
| + } else if ((source != target) && (!source->layer() || !target->layer())) {
|
| + if (!source->layer()) {
|
| gfx::Vector2d offset_to_layer;
|
| source = source->GetAncestorWithLayer(&offset_to_layer);
|
| *point += offset_to_layer;
|
| }
|
| - if (!target->layer_) {
|
| + if (!target->layer()) {
|
| gfx::Vector2d offset_to_layer;
|
| target = target->GetAncestorWithLayer(&offset_to_layer);
|
| *point -= offset_to_layer;
|
| }
|
| - ui::Layer::ConvertPointToLayer(source->layer_, target->layer_, point);
|
| + ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
|
| } else {
|
| - ui::Layer::ConvertPointToLayer(source->layer_, target->layer_, point);
|
| + ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
|
| }
|
| }
|
|
|
| @@ -762,8 +759,8 @@ bool Window::HasCapture() {
|
| }
|
|
|
| void Window::SuppressPaint() {
|
| - if (layer_)
|
| - layer_->SuppressPaint();
|
| + if (layer())
|
| + layer()->SuppressPaint();
|
| }
|
|
|
| // {Set,Get,Clear}Property are implemented in window_property.h.
|
| @@ -792,10 +789,10 @@ std::string Window::GetDebugInfo() const {
|
| name().empty() ? "Unknown" : name().c_str(), id(),
|
| bounds().x(), bounds().y(), bounds().width(), bounds().height(),
|
| visible_ ? "WindowVisible" : "WindowHidden",
|
| - layer_ ?
|
| - (layer_->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") :
|
| + layer() ?
|
| + (layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") :
|
| "NoLayer",
|
| - layer_ ? layer_->opacity() : 1.0f);
|
| + layer() ? layer()->opacity() : 1.0f);
|
| }
|
|
|
| void Window::PrintWindowHierarchy(int depth) const {
|
| @@ -889,32 +886,32 @@ 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.
|
| - if (!layer_) {
|
| + if (!layer()) {
|
| const gfx::Vector2d origin_delta = new_bounds.OffsetFromOrigin() -
|
| bounds_.OffsetFromOrigin();
|
| bounds_ = new_bounds;
|
| OffsetLayerBounds(origin_delta);
|
| } else {
|
| - if (parent_ && !parent_->layer_) {
|
| + if (parent_ && !parent_->layer()) {
|
| gfx::Vector2d offset;
|
| const aura::Window* ancestor_with_layer =
|
| parent_->GetAncestorWithLayer(&offset);
|
| if (ancestor_with_layer)
|
| actual_new_bounds.Offset(offset);
|
| }
|
| - layer_->SetBounds(actual_new_bounds);
|
| + layer()->SetBounds(actual_new_bounds);
|
| }
|
|
|
| // If we are currently not the layer's delegate, we will not get bounds
|
| // changed notification from the layer (this typically happens after animating
|
| // hidden). We must notify ourselves.
|
| - if (!layer_ || layer_->delegate() != this)
|
| + if (!layer() || layer()->delegate() != this)
|
| OnWindowBoundsChanged(old_bounds, ContainsMouse());
|
| }
|
|
|
| void Window::SetVisible(bool visible) {
|
| - if ((layer_ && visible == layer_->GetTargetVisibility()) ||
|
| - (!layer_ && visible == visible_))
|
| + if ((layer() && visible == layer()->GetTargetVisibility()) ||
|
| + (!layer() && visible == visible_))
|
| return; // No change.
|
|
|
| FOR_EACH_OBSERVER(WindowObserver, observers_,
|
| @@ -928,8 +925,8 @@ void Window::SetVisible(bool visible) {
|
| client::GetVisibilityClient(this);
|
| if (visibility_client)
|
| visibility_client->UpdateLayerVisibility(this, visible);
|
| - else if (layer_)
|
| - layer_->SetVisible(visible);
|
| + else if (layer())
|
| + layer()->SetVisible(visible);
|
| visible_ = visible;
|
| SchedulePaint();
|
| if (parent_ && parent_->layout_manager_)
|
| @@ -957,7 +954,7 @@ void Window::Paint(gfx::Canvas* canvas) {
|
| void Window::PaintLayerlessChildren(gfx::Canvas* canvas) {
|
| for (size_t i = 0, count = children_.size(); i < count; ++i) {
|
| Window* child = children_[i];
|
| - if (!child->layer_ && child->visible_) {
|
| + if (!child->layer() && child->visible_) {
|
| gfx::ScopedCanvas scoped_canvas(canvas);
|
| canvas->ClipRect(child->bounds());
|
| if (!canvas->IsClipEmpty()) {
|
| @@ -1037,7 +1034,7 @@ void Window::RemoveChildImpl(Window* child, Window* new_parent) {
|
|
|
| gfx::Vector2d offset;
|
| GetAncestorWithLayer(&offset);
|
| - child->UnparentLayers(!layer_, offset);
|
| + child->UnparentLayers(!layer(), offset);
|
| child->parent_ = NULL;
|
| Windows::iterator i = std::find(children_.begin(), children_.end(), child);
|
| DCHECK(i != children_.end());
|
| @@ -1049,7 +1046,7 @@ void Window::RemoveChildImpl(Window* child, Window* new_parent) {
|
|
|
| void Window::UnparentLayers(bool has_layerless_ancestor,
|
| const gfx::Vector2d& offset) {
|
| - if (!layer_) {
|
| + if (!layer()) {
|
| const gfx::Vector2d new_offset = offset + bounds().OffsetFromOrigin();
|
| for (size_t i = 0; i < children_.size(); ++i) {
|
| children_[i]->UnparentLayers(true, new_offset);
|
| @@ -1058,14 +1055,14 @@ void Window::UnparentLayers(bool has_layerless_ancestor,
|
| // Only remove the layer if we still own it. Someone else may have acquired
|
| // ownership of it via AcquireLayer() and may expect the hierarchy to go
|
| // unchanged as the Window is destroyed.
|
| - if (layer_owner_) {
|
| - if (layer_->parent())
|
| - layer_->parent()->Remove(layer_);
|
| + if (OwnsLayer()) {
|
| + if (layer()->parent())
|
| + layer()->parent()->Remove(layer());
|
| if (has_layerless_ancestor) {
|
| const gfx::Rect real_bounds(bounds_);
|
| - gfx::Rect layer_bounds(layer_->bounds());
|
| + gfx::Rect layer_bounds(layer()->bounds());
|
| layer_bounds.Offset(-offset);
|
| - layer_->SetBounds(layer_bounds);
|
| + layer()->SetBounds(layer_bounds);
|
| bounds_ = real_bounds;
|
| }
|
| }
|
| @@ -1074,7 +1071,7 @@ void Window::UnparentLayers(bool has_layerless_ancestor,
|
|
|
| void Window::ReparentLayers(ui::Layer* parent_layer,
|
| const gfx::Vector2d& offset) {
|
| - if (!layer_) {
|
| + if (!layer()) {
|
| for (size_t i = 0; i < children_.size(); ++i) {
|
| children_[i]->ReparentLayers(
|
| parent_layer,
|
| @@ -1082,22 +1079,22 @@ void Window::ReparentLayers(ui::Layer* parent_layer,
|
| }
|
| } else {
|
| const gfx::Rect real_bounds(bounds());
|
| - parent_layer->Add(layer_);
|
| - gfx::Rect layer_bounds(layer_->bounds().size());
|
| + parent_layer->Add(layer());
|
| + gfx::Rect layer_bounds(layer()->bounds().size());
|
| layer_bounds += offset;
|
| - layer_->SetBounds(layer_bounds);
|
| + layer()->SetBounds(layer_bounds);
|
| bounds_ = real_bounds;
|
| }
|
| }
|
|
|
| void Window::OffsetLayerBounds(const gfx::Vector2d& offset) {
|
| - if (!layer_) {
|
| + if (!layer()) {
|
| for (size_t i = 0; i < children_.size(); ++i)
|
| children_[i]->OffsetLayerBounds(offset);
|
| } else {
|
| - gfx::Rect layer_bounds(layer_->bounds());
|
| + gfx::Rect layer_bounds(layer()->bounds());
|
| layer_bounds += offset;
|
| - layer_->SetBounds(layer_bounds);
|
| + layer()->SetBounds(layer_bounds);
|
| }
|
| }
|
|
|
| @@ -1152,11 +1149,11 @@ void Window::StackChildLayerRelativeTo(Window* child,
|
| if (!ancestor_layer)
|
| return;
|
|
|
| - if (child->layer_ && target->layer_) {
|
| + if (child->layer() && target->layer()) {
|
| if (direction == STACK_ABOVE)
|
| - ancestor_layer->StackAbove(child->layer_, target->layer_);
|
| + ancestor_layer->StackAbove(child->layer(), target->layer());
|
| else
|
| - ancestor_layer->StackBelow(child->layer_, target->layer_);
|
| + ancestor_layer->StackBelow(child->layer(), target->layer());
|
| return;
|
| }
|
| typedef std::vector<ui::Layer*> Layers;
|
| @@ -1326,9 +1323,9 @@ void Window::NotifyWindowVisibilityChangedUp(aura::Window* target,
|
|
|
| void Window::OnWindowBoundsChanged(const gfx::Rect& old_bounds,
|
| bool contained_mouse) {
|
| - if (layer_) {
|
| - bounds_ = layer_->bounds();
|
| - if (parent_ && !parent_->layer_) {
|
| + if (layer()) {
|
| + bounds_ = layer()->bounds();
|
| + if (parent_ && !parent_->layer()) {
|
| gfx::Vector2d offset;
|
| aura::Window* ancestor_with_layer =
|
| parent_->GetAncestorWithLayer(&offset);
|
| @@ -1410,7 +1407,7 @@ void Window::ConvertEventToTarget(ui::EventTarget* target,
|
|
|
| void Window::UpdateLayerName(const std::string& name) {
|
| #if !defined(NDEBUG)
|
| - DCHECK(layer_);
|
| + DCHECK(layer());
|
|
|
| std::string layer_name(name_);
|
| if (layer_name.empty())
|
| @@ -1419,7 +1416,7 @@ void Window::UpdateLayerName(const std::string& name) {
|
| if (id_ != -1)
|
| layer_name += " " + base::IntToString(id_);
|
|
|
| - layer_->set_name(layer_name);
|
| + layer()->set_name(layer_name);
|
| #endif
|
| }
|
|
|
| @@ -1435,7 +1432,7 @@ bool Window::ContainsMouse() {
|
|
|
| const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const {
|
| for (const aura::Window* window = this; window; window = window->parent()) {
|
| - if (window->layer_)
|
| + if (window->layer())
|
| return window;
|
| if (offset)
|
| *offset += window->bounds().OffsetFromOrigin();
|
|
|