| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "ui/aura/client/event_client.h" |
| 12 #include "ui/aura/client/stacking_client.h" | 13 #include "ui/aura/client/stacking_client.h" |
| 13 #include "ui/aura/client/visibility_client.h" | 14 #include "ui/aura/client/visibility_client.h" |
| 14 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 15 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
| 16 #include "ui/aura/event_filter.h" | 17 #include "ui/aura/event_filter.h" |
| 17 #include "ui/aura/layout_manager.h" | 18 #include "ui/aura/layout_manager.h" |
| 18 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
| 19 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/aura/window_observer.h" | 21 #include "ui/aura/window_observer.h" |
| 21 #include "ui/base/animation/multi_animation.h" | 22 #include "ui/base/animation/multi_animation.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 Window::Window(WindowDelegate* delegate) | 48 Window::Window(WindowDelegate* delegate) |
| 48 : type_(client::WINDOW_TYPE_UNKNOWN), | 49 : type_(client::WINDOW_TYPE_UNKNOWN), |
| 49 delegate_(delegate), | 50 delegate_(delegate), |
| 50 layer_(NULL), | 51 layer_(NULL), |
| 51 parent_(NULL), | 52 parent_(NULL), |
| 52 transient_parent_(NULL), | 53 transient_parent_(NULL), |
| 53 visible_(false), | 54 visible_(false), |
| 54 id_(-1), | 55 id_(-1), |
| 55 transparent_(false), | 56 transparent_(false), |
| 56 user_data_(NULL), | 57 user_data_(NULL), |
| 57 stops_event_propagation_(false), | |
| 58 ignore_events_(false), | 58 ignore_events_(false), |
| 59 hit_test_bounds_override_outer_(0), | 59 hit_test_bounds_override_outer_(0), |
| 60 hit_test_bounds_override_inner_(0) { | 60 hit_test_bounds_override_inner_(0) { |
| 61 } | 61 } |
| 62 | 62 |
| 63 Window::~Window() { | 63 Window::~Window() { |
| 64 // layer_ can be NULL if Init() wasn't invoked, which can happen | 64 // layer_ can be NULL if Init() wasn't invoked, which can happen |
| 65 // only in tests. | 65 // only in tests. |
| 66 if (layer_) | 66 if (layer_) |
| 67 layer_->SuppressPaint(); | 67 layer_->SuppressPaint(); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 443 } |
| 444 | 444 |
| 445 // For a given window, we determine its focusability and ability to | 445 // For a given window, we determine its focusability and ability to |
| 446 // receive events by inspecting each sibling after it (i.e. drawn in | 446 // receive events by inspecting each sibling after it (i.e. drawn in |
| 447 // front of it in the z-order) to see if it stops propagation of | 447 // front of it in the z-order) to see if it stops propagation of |
| 448 // events that would otherwise be targeted at windows behind it. We | 448 // events that would otherwise be targeted at windows behind it. We |
| 449 // then perform this same check on every window up to the root. | 449 // then perform this same check on every window up to the root. |
| 450 bool Window::CanFocus() const { | 450 bool Window::CanFocus() const { |
| 451 if (!IsVisible() || !parent_ || (delegate_ && !delegate_->CanFocus())) | 451 if (!IsVisible() || !parent_ || (delegate_ && !delegate_->CanFocus())) |
| 452 return false; | 452 return false; |
| 453 return !IsBehindStopEventsWindow() && parent_->CanFocus(); | 453 |
| 454 // The client may forbid certain windows from receiving focus at a given point |
| 455 // in time. |
| 456 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
| 457 if (client && !client->CanProcessEventsWithinSubtree(this)) |
| 458 return false; |
| 459 |
| 460 return parent_->CanFocus(); |
| 454 } | 461 } |
| 455 | 462 |
| 456 bool Window::CanReceiveEvents() const { | 463 bool Window::CanReceiveEvents() const { |
| 457 return parent_ && IsVisible() && !IsBehindStopEventsWindow() && | 464 // The client may forbid certain windows from receiving events at a given |
| 458 parent_->CanReceiveEvents(); | 465 // point in time. |
| 466 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
| 467 if (client && !client->CanProcessEventsWithinSubtree(this)) |
| 468 return false; |
| 469 |
| 470 return parent_ && IsVisible() && parent_->CanReceiveEvents(); |
| 459 } | 471 } |
| 460 | 472 |
| 461 internal::FocusManager* Window::GetFocusManager() { | 473 internal::FocusManager* Window::GetFocusManager() { |
| 462 return const_cast<internal::FocusManager*>( | 474 return const_cast<internal::FocusManager*>( |
| 463 static_cast<const Window*>(this)->GetFocusManager()); | 475 static_cast<const Window*>(this)->GetFocusManager()); |
| 464 } | 476 } |
| 465 | 477 |
| 466 const internal::FocusManager* Window::GetFocusManager() const { | 478 const internal::FocusManager* Window::GetFocusManager() const { |
| 467 return parent_ ? parent_->GetFocusManager() : NULL; | 479 return parent_ ? parent_->GetFocusManager() : NULL; |
| 468 } | 480 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 484 return; | 496 return; |
| 485 | 497 |
| 486 root_window->ReleaseCapture(this); | 498 root_window->ReleaseCapture(this); |
| 487 } | 499 } |
| 488 | 500 |
| 489 bool Window::HasCapture() { | 501 bool Window::HasCapture() { |
| 490 RootWindow* root_window = GetRootWindow(); | 502 RootWindow* root_window = GetRootWindow(); |
| 491 return root_window && root_window->capture_window() == this; | 503 return root_window && root_window->capture_window() == this; |
| 492 } | 504 } |
| 493 | 505 |
| 494 bool Window::StopsEventPropagation() const { | |
| 495 if (!stops_event_propagation_ || children_.empty()) | |
| 496 return false; | |
| 497 aura::Window::Windows::const_iterator it = | |
| 498 std::find_if(children_.begin(), children_.end(), | |
| 499 std::mem_fun(&aura::Window::IsVisible)); | |
| 500 return it != children_.end(); | |
| 501 } | |
| 502 | |
| 503 void Window::SuppressPaint() { | 506 void Window::SuppressPaint() { |
| 504 layer_->SuppressPaint(); | 507 layer_->SuppressPaint(); |
| 505 } | 508 } |
| 506 | 509 |
| 507 // {Set,Get,Clear}Property are implemented in window_property.h. | 510 // {Set,Get,Clear}Property are implemented in window_property.h. |
| 508 | 511 |
| 509 void Window::SetNativeWindowProperty(const char* key, void* value) { | 512 void Window::SetNativeWindowProperty(const char* key, void* value) { |
| 510 SetPropertyInternal( | 513 SetPropertyInternal( |
| 511 key, key, NULL, reinterpret_cast<intptr_t>(value), 0); | 514 key, key, NULL, reinterpret_cast<intptr_t>(value), 0); |
| 512 } | 515 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 return delegate_ ? this : NULL; | 650 return delegate_ ? this : NULL; |
| 648 } | 651 } |
| 649 | 652 |
| 650 if (!return_tightest && delegate_) | 653 if (!return_tightest && delegate_) |
| 651 return this; | 654 return this; |
| 652 | 655 |
| 653 for (Windows::const_reverse_iterator it = children_.rbegin(), | 656 for (Windows::const_reverse_iterator it = children_.rbegin(), |
| 654 rend = children_.rend(); | 657 rend = children_.rend(); |
| 655 it != rend; ++it) { | 658 it != rend; ++it) { |
| 656 Window* child = *it; | 659 Window* child = *it; |
| 660 |
| 661 if (for_event_handling) { |
| 662 // The client may not allow events to be processed by certain subtrees. |
| 663 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
| 664 if (client && !client->CanProcessEventsWithinSubtree(child)) |
| 665 continue; |
| 666 } |
| 667 |
| 668 // We don't process events for invisible windows or those that have asked |
| 669 // to ignore events. |
| 657 if (!child->IsVisible() || (for_event_handling && child->ignore_events_)) | 670 if (!child->IsVisible() || (for_event_handling && child->ignore_events_)) |
| 658 continue; | 671 continue; |
| 659 | 672 |
| 660 gfx::Point point_in_child_coords(local_point); | 673 gfx::Point point_in_child_coords(local_point); |
| 661 Window::ConvertPointToWindow(this, child, &point_in_child_coords); | 674 Window::ConvertPointToWindow(this, child, &point_in_child_coords); |
| 662 Window* match = child->GetWindowForPoint(point_in_child_coords, | 675 Window* match = child->GetWindowForPoint(point_in_child_coords, |
| 663 return_tightest, | 676 return_tightest, |
| 664 for_event_handling); | 677 for_event_handling); |
| 665 if (match) | 678 if (match) |
| 666 return match; | 679 return match; |
| 667 | |
| 668 if (for_event_handling && child->StopsEventPropagation()) | |
| 669 break; | |
| 670 } | 680 } |
| 671 | 681 |
| 672 return delegate_ ? this : NULL; | 682 return delegate_ ? this : NULL; |
| 673 } | 683 } |
| 674 | 684 |
| 675 void Window::OnParentChanged() { | 685 void Window::OnParentChanged() { |
| 676 FOR_EACH_OBSERVER( | 686 FOR_EACH_OBSERVER( |
| 677 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); | 687 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); |
| 678 } | 688 } |
| 679 | 689 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 804 |
| 795 if (id_ != -1) { | 805 if (id_ != -1) { |
| 796 char id_buf[10]; | 806 char id_buf[10]; |
| 797 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); | 807 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); |
| 798 layer_name.append(id_buf); | 808 layer_name.append(id_buf); |
| 799 } | 809 } |
| 800 layer()->set_name(layer_name); | 810 layer()->set_name(layer_name); |
| 801 #endif | 811 #endif |
| 802 } | 812 } |
| 803 | 813 |
| 804 bool Window::IsBehindStopEventsWindow() const { | |
| 805 Windows::const_iterator i = std::find(parent_->children().begin(), | |
| 806 parent_->children().end(), | |
| 807 this); | |
| 808 for (++i; i != parent_->children().end(); ++i) { | |
| 809 if ((*i)->StopsEventPropagation()) | |
| 810 return true; | |
| 811 } | |
| 812 return false; | |
| 813 } | |
| 814 | |
| 815 } // namespace aura | 814 } // namespace aura |
| OLD | NEW |