OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 590 |
591 // Ensure we don't go smaller than our minimum bounds. | 591 // Ensure we don't go smaller than our minimum bounds. |
592 if (delegate_) { | 592 if (delegate_) { |
593 const gfx::Size& min_size = delegate_->GetMinimumSize(); | 593 const gfx::Size& min_size = delegate_->GetMinimumSize(); |
594 actual_new_bounds.set_width( | 594 actual_new_bounds.set_width( |
595 std::max(min_size.width(), actual_new_bounds.width())); | 595 std::max(min_size.width(), actual_new_bounds.width())); |
596 actual_new_bounds.set_height( | 596 actual_new_bounds.set_height( |
597 std::max(min_size.height(), actual_new_bounds.height())); | 597 std::max(min_size.height(), actual_new_bounds.height())); |
598 } | 598 } |
599 | 599 |
| 600 gfx::Rect old_bounds = GetTargetBounds(); |
| 601 |
600 // Always need to set the layer's bounds -- even if it is to the same thing. | 602 // Always need to set the layer's bounds -- even if it is to the same thing. |
601 // This may cause important side effects such as stopping animation. | 603 // This may cause important side effects such as stopping animation. |
602 layer_->SetBounds(actual_new_bounds); | 604 layer_->SetBounds(actual_new_bounds); |
| 605 |
| 606 // If we are currently not the layer's delegate, we will not get bounds |
| 607 // changed notification from the layer (this typically happens after animating |
| 608 // hidden). We must notify ourselves. |
| 609 if (layer_->delegate() != this) |
| 610 OnLayerBoundsChanged(old_bounds, ContainsMouse()); |
603 } | 611 } |
604 | 612 |
605 void Window::SetVisible(bool visible) { | 613 void Window::SetVisible(bool visible) { |
606 if (visible == layer_->GetTargetVisibility()) | 614 if (visible == layer_->GetTargetVisibility()) |
607 return; // No change. | 615 return; // No change. |
608 | 616 |
609 RootWindow* root_window = GetRootWindow(); | 617 RootWindow* root_window = GetRootWindow(); |
610 if (client::GetVisibilityClient(root_window)) { | 618 if (client::GetVisibilityClient(root_window)) { |
611 client::GetVisibilityClient(root_window)->UpdateLayerVisibility( | 619 client::GetVisibilityClient(root_window)->UpdateLayerVisibility( |
612 this, visible); | 620 this, visible); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 if (root_window) | 814 if (root_window) |
807 root_window->OnWindowBoundsChanged(this, contained_mouse); | 815 root_window->OnWindowBoundsChanged(this, contained_mouse); |
808 } | 816 } |
809 | 817 |
810 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 818 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
811 if (delegate_) | 819 if (delegate_) |
812 delegate_->OnPaint(canvas); | 820 delegate_->OnPaint(canvas); |
813 } | 821 } |
814 | 822 |
815 base::Closure Window::PrepareForLayerBoundsChange() { | 823 base::Closure Window::PrepareForLayerBoundsChange() { |
816 bool contains_mouse = false; | |
817 if (IsVisible()) { | |
818 RootWindow* root_window = GetRootWindow(); | |
819 contains_mouse = | |
820 root_window && ContainsPointInRoot(root_window->last_mouse_location()); | |
821 } | |
822 return base::Bind(&Window::OnLayerBoundsChanged, base::Unretained(this), | 824 return base::Bind(&Window::OnLayerBoundsChanged, base::Unretained(this), |
823 bounds(), contains_mouse); | 825 bounds(), ContainsMouse()); |
824 } | 826 } |
825 | 827 |
826 void Window::UpdateLayerName(const std::string& name) { | 828 void Window::UpdateLayerName(const std::string& name) { |
827 #if !defined(NDEBUG) | 829 #if !defined(NDEBUG) |
828 DCHECK(layer()); | 830 DCHECK(layer()); |
829 | 831 |
830 std::string layer_name(name_); | 832 std::string layer_name(name_); |
831 if (layer_name.empty()) | 833 if (layer_name.empty()) |
832 layer_name.append("Unnamed Window"); | 834 layer_name.append("Unnamed Window"); |
833 | 835 |
834 if (id_ != -1) { | 836 if (id_ != -1) { |
835 char id_buf[10]; | 837 char id_buf[10]; |
836 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); | 838 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); |
837 layer_name.append(id_buf); | 839 layer_name.append(id_buf); |
838 } | 840 } |
839 layer()->set_name(layer_name); | 841 layer()->set_name(layer_name); |
840 #endif | 842 #endif |
841 } | 843 } |
842 | 844 |
| 845 bool Window::ContainsMouse() { |
| 846 bool contains_mouse = false; |
| 847 if (IsVisible()) { |
| 848 RootWindow* root_window = GetRootWindow(); |
| 849 contains_mouse = |
| 850 root_window && ContainsPointInRoot(root_window->last_mouse_location()); |
| 851 } |
| 852 return contains_mouse; |
| 853 } |
| 854 |
843 #ifndef NDEBUG | 855 #ifndef NDEBUG |
844 std::string Window::GetDebugInfo() const { | 856 std::string Window::GetDebugInfo() const { |
845 return StringPrintf( | 857 return StringPrintf( |
846 "%s<%d> bounds(%d, %d, %d, %d) %s", | 858 "%s<%d> bounds(%d, %d, %d, %d) %s", |
847 name().empty() ? "Unknown" : name().c_str(), id(), | 859 name().empty() ? "Unknown" : name().c_str(), id(), |
848 bounds().x(), bounds().y(), bounds().width(), bounds().height(), | 860 bounds().x(), bounds().y(), bounds().width(), bounds().height(), |
849 IsVisible() ? "Visible" : "Hidden"); | 861 IsVisible() ? "Visible" : "Hidden"); |
850 } | 862 } |
851 | 863 |
852 void Window::PrintWindowHierarchy(int depth) const { | 864 void Window::PrintWindowHierarchy(int depth) const { |
853 printf("%*s%s\n", depth * 2, "", GetDebugInfo().c_str()); | 865 printf("%*s%s\n", depth * 2, "", GetDebugInfo().c_str()); |
854 for (Windows::const_reverse_iterator it = children_.rbegin(), | 866 for (Windows::const_reverse_iterator it = children_.rbegin(), |
855 rend = children_.rend(); | 867 rend = children_.rend(); |
856 it != rend; ++it) { | 868 it != rend; ++it) { |
857 Window* child = *it; | 869 Window* child = *it; |
858 child->PrintWindowHierarchy(depth + 1); | 870 child->PrintWindowHierarchy(depth + 1); |
859 } | 871 } |
860 } | 872 } |
861 #endif | 873 #endif |
862 | 874 |
863 } // namespace aura | 875 } // namespace aura |
OLD | NEW |