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