| 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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 delegate_->GetHitTestMask(&mask); | 494 delegate_->GetHitTestMask(&mask); |
| 495 | 495 |
| 496 SkRegion clip_region; | 496 SkRegion clip_region; |
| 497 clip_region.setRect(local_bounds.x(), local_bounds.y(), | 497 clip_region.setRect(local_bounds.x(), local_bounds.y(), |
| 498 local_bounds.width(), local_bounds.height()); | 498 local_bounds.width(), local_bounds.height()); |
| 499 SkRegion mask_region; | 499 SkRegion mask_region; |
| 500 return mask_region.setPath(mask, clip_region) && | 500 return mask_region.setPath(mask, clip_region) && |
| 501 mask_region.contains(local_point.x(), local_point.y()); | 501 mask_region.contains(local_point.x(), local_point.y()); |
| 502 } | 502 } |
| 503 | 503 |
| 504 Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point) { | 504 Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point, |
| 505 return GetWindowForPoint(local_point, true, true); | 505 ui::EventType event_type) { |
| 506 return GetWindowForPoint(local_point, true, event_type); |
| 506 } | 507 } |
| 507 | 508 |
| 508 Window* Window::GetTopWindowContainingPoint(const gfx::Point& local_point) { | 509 Window* Window::GetTopWindowContainingPoint(const gfx::Point& local_point) { |
| 509 return GetWindowForPoint(local_point, false, false); | 510 return GetWindowForPoint(local_point, false, ui::ET_UNKNOWN); |
| 510 } | 511 } |
| 511 | 512 |
| 512 Window* Window::GetToplevelWindow() { | 513 Window* Window::GetToplevelWindow() { |
| 513 Window* topmost_window_with_delegate = NULL; | 514 Window* topmost_window_with_delegate = NULL; |
| 514 for (aura::Window* window = this; window != NULL; window = window->parent()) { | 515 for (aura::Window* window = this; window != NULL; window = window->parent()) { |
| 515 if (window->delegate()) | 516 if (window->delegate()) |
| 516 topmost_window_with_delegate = window; | 517 topmost_window_with_delegate = window; |
| 517 } | 518 } |
| 518 return topmost_window_with_delegate; | 519 return topmost_window_with_delegate; |
| 519 } | 520 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 if (root_window) | 694 if (root_window) |
| 694 root_window->OnWindowVisibilityChanged(this, visible); | 695 root_window->OnWindowVisibilityChanged(this, visible); |
| 695 } | 696 } |
| 696 | 697 |
| 697 void Window::SchedulePaint() { | 698 void Window::SchedulePaint() { |
| 698 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 699 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 699 } | 700 } |
| 700 | 701 |
| 701 Window* Window::GetWindowForPoint(const gfx::Point& local_point, | 702 Window* Window::GetWindowForPoint(const gfx::Point& local_point, |
| 702 bool return_tightest, | 703 bool return_tightest, |
| 703 bool for_event_handling) { | 704 ui::EventType event_type) { |
| 704 if (!IsVisible()) | 705 if (!IsVisible()) |
| 705 return NULL; | 706 return NULL; |
| 706 | 707 |
| 708 bool for_event_handling = event_type != ui::ET_UNKNOWN; |
| 707 if ((for_event_handling && !HitTest(local_point)) || | 709 if ((for_event_handling && !HitTest(local_point)) || |
| 708 (!for_event_handling && !ContainsPoint(local_point))) | 710 (!for_event_handling && !ContainsPoint(local_point))) |
| 709 return NULL; | 711 return NULL; |
| 710 | 712 |
| 711 // Check if I should claim this event and not pass it to my children because | 713 // Check if I should claim this event and not pass it to my children because |
| 712 // the location is inside my hit test override area. For details, see | 714 // the location is inside my hit test override area. For details, see |
| 713 // set_hit_test_bounds_override_inner(). | 715 // set_hit_test_bounds_override_inner(). |
| 714 if (for_event_handling && !hit_test_bounds_override_inner_.empty()) { | 716 if (for_event_handling && !hit_test_bounds_override_inner_.empty()) { |
| 715 gfx::Rect inset_local_bounds(gfx::Point(), bounds().size()); | 717 gfx::Rect inset_local_bounds(gfx::Point(), bounds().size()); |
| 716 inset_local_bounds.Inset(hit_test_bounds_override_inner_); | 718 inset_local_bounds.Inset(hit_test_bounds_override_inner_); |
| 717 // We know we're inside the normal local bounds, so if we're outside the | 719 // We know we're inside the normal local bounds, so if we're outside the |
| 718 // inset bounds we must be in the special hit test override area. | 720 // inset bounds we must be in the special hit test override area. |
| 719 DCHECK(HitTest(local_point)); | 721 DCHECK(HitTest(local_point)); |
| 720 if (!inset_local_bounds.Contains(local_point)) | 722 if (!inset_local_bounds.Contains(local_point)) |
| 721 return delegate_ ? this : NULL; | 723 return delegate_ ? this : NULL; |
| 722 } | 724 } |
| 723 | 725 |
| 726 // Check if I should claim the mouse click/drag event and not pass it to my |
| 727 // children because this location is inside the draggable region. |
| 728 if (delegate_ && |
| 729 (event_type == ui::ET_MOUSE_PRESSED || |
| 730 event_type == ui::ET_MOUSE_DRAGGED || |
| 731 event_type == ui::ET_MOUSE_RELEASED) && |
| 732 draggable_region_.get() && |
| 733 draggable_region_->contains(local_point.x(), local_point.y())) |
| 734 return this; |
| 735 |
| 724 if (!return_tightest && delegate_) | 736 if (!return_tightest && delegate_) |
| 725 return this; | 737 return this; |
| 726 | 738 |
| 727 for (Windows::const_reverse_iterator it = children_.rbegin(), | 739 for (Windows::const_reverse_iterator it = children_.rbegin(), |
| 728 rend = children_.rend(); | 740 rend = children_.rend(); |
| 729 it != rend; ++it) { | 741 it != rend; ++it) { |
| 730 Window* child = *it; | 742 Window* child = *it; |
| 731 | 743 |
| 732 if (for_event_handling) { | 744 if (for_event_handling) { |
| 733 // The client may not allow events to be processed by certain subtrees. | 745 // The client may not allow events to be processed by certain subtrees. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 744 gfx::Point point_in_child_coords(local_point); | 756 gfx::Point point_in_child_coords(local_point); |
| 745 ConvertPointToTarget(this, child, &point_in_child_coords); | 757 ConvertPointToTarget(this, child, &point_in_child_coords); |
| 746 if (for_event_handling && delegate_ && | 758 if (for_event_handling && delegate_ && |
| 747 !delegate_->ShouldDescendIntoChildForEventHandling( | 759 !delegate_->ShouldDescendIntoChildForEventHandling( |
| 748 child, local_point)) { | 760 child, local_point)) { |
| 749 continue; | 761 continue; |
| 750 } | 762 } |
| 751 | 763 |
| 752 Window* match = child->GetWindowForPoint(point_in_child_coords, | 764 Window* match = child->GetWindowForPoint(point_in_child_coords, |
| 753 return_tightest, | 765 return_tightest, |
| 754 for_event_handling); | 766 event_type); |
| 755 if (match) | 767 if (match) |
| 756 return match; | 768 return match; |
| 757 } | 769 } |
| 758 | 770 |
| 759 return delegate_ ? this : NULL; | 771 return delegate_ ? this : NULL; |
| 760 } | 772 } |
| 761 | 773 |
| 762 void Window::RemoveChildImpl(Window* child, Window* new_parent) { | 774 void Window::RemoveChildImpl(Window* child, Window* new_parent) { |
| 763 Windows::iterator i = std::find(children_.begin(), children_.end(), child); | 775 Windows::iterator i = std::find(children_.begin(), children_.end(), child); |
| 764 DCHECK(i != children_.end()); | 776 DCHECK(i != children_.end()); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 bool Window::ContainsMouse() { | 946 bool Window::ContainsMouse() { |
| 935 bool contains_mouse = false; | 947 bool contains_mouse = false; |
| 936 if (IsVisible()) { | 948 if (IsVisible()) { |
| 937 RootWindow* root_window = GetRootWindow(); | 949 RootWindow* root_window = GetRootWindow(); |
| 938 contains_mouse = root_window && | 950 contains_mouse = root_window && |
| 939 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); | 951 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); |
| 940 } | 952 } |
| 941 return contains_mouse; | 953 return contains_mouse; |
| 942 } | 954 } |
| 943 | 955 |
| 956 void Window::SetDraggableRegion(SkRegion* region) { |
| 957 draggable_region_.reset(region); |
| 958 } |
| 959 |
| 944 #ifndef NDEBUG | 960 #ifndef NDEBUG |
| 945 std::string Window::GetDebugInfo() const { | 961 std::string Window::GetDebugInfo() const { |
| 946 return StringPrintf( | 962 return StringPrintf( |
| 947 "%s<%d> bounds(%d, %d, %d, %d) %s", | 963 "%s<%d> bounds(%d, %d, %d, %d) %s", |
| 948 name().empty() ? "Unknown" : name().c_str(), id(), | 964 name().empty() ? "Unknown" : name().c_str(), id(), |
| 949 bounds().x(), bounds().y(), bounds().width(), bounds().height(), | 965 bounds().x(), bounds().y(), bounds().width(), bounds().height(), |
| 950 IsVisible() ? "Visible" : "Hidden"); | 966 IsVisible() ? "Visible" : "Hidden"); |
| 951 } | 967 } |
| 952 | 968 |
| 953 void Window::PrintWindowHierarchy(int depth) const { | 969 void Window::PrintWindowHierarchy(int depth) const { |
| 954 printf("%*s%s\n", depth * 2, "", GetDebugInfo().c_str()); | 970 printf("%*s%s\n", depth * 2, "", GetDebugInfo().c_str()); |
| 955 for (Windows::const_reverse_iterator it = children_.rbegin(), | 971 for (Windows::const_reverse_iterator it = children_.rbegin(), |
| 956 rend = children_.rend(); | 972 rend = children_.rend(); |
| 957 it != rend; ++it) { | 973 it != rend; ++it) { |
| 958 Window* child = *it; | 974 Window* child = *it; |
| 959 child->PrintWindowHierarchy(depth + 1); | 975 child->PrintWindowHierarchy(depth + 1); |
| 960 } | 976 } |
| 961 } | 977 } |
| 962 #endif | 978 #endif |
| 963 | 979 |
| 964 } // namespace aura | 980 } // namespace aura |
| OLD | NEW |