OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/devtools/window_element.h" |
| 6 |
| 7 #include "ash/devtools/ui_element_delegate.h" |
| 8 #include "ui/aura/window.h" |
| 9 |
| 10 namespace ash { |
| 11 namespace devtools { |
| 12 namespace { |
| 13 |
| 14 int GetIndexOfChildInParent(aura::Window* window) { |
| 15 const aura::Window::Windows& siblings = window->parent()->children(); |
| 16 auto it = std::find(siblings.begin(), siblings.end(), window); |
| 17 DCHECK(it != siblings.end()); |
| 18 return std::distance(siblings.begin(), it); |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 WindowElement::WindowElement(aura::Window* window, |
| 24 UIElementDelegate* ui_element_delegate, |
| 25 UIElement* parent) |
| 26 : UIElement(UIElementType::WINDOW, ui_element_delegate, parent), |
| 27 window_(window) { |
| 28 if (window) |
| 29 window_->AddObserver(this); |
| 30 } |
| 31 |
| 32 WindowElement::~WindowElement() { |
| 33 if (window_) |
| 34 window_->RemoveObserver(this); |
| 35 } |
| 36 |
| 37 // Handles removing window_. |
| 38 void WindowElement::OnWindowHierarchyChanging( |
| 39 const aura::WindowObserver::HierarchyChangeParams& params) { |
| 40 if (params.target == window_) { |
| 41 parent()->RemoveChild(this); |
| 42 delete this; |
| 43 } |
| 44 } |
| 45 |
| 46 // Handles adding window_. |
| 47 void WindowElement::OnWindowHierarchyChanged( |
| 48 const aura::WindowObserver::HierarchyChangeParams& params) { |
| 49 if (window_ == params.new_parent && params.receiver == params.new_parent) { |
| 50 if (delegate()->IsHighlightingWindow(params.target)) |
| 51 return; |
| 52 AddChild(new WindowElement(params.target, delegate(), this), |
| 53 children().empty() ? nullptr : children().back()); |
| 54 } |
| 55 } |
| 56 |
| 57 void WindowElement::OnWindowStackingChanged(aura::Window* window) { |
| 58 DCHECK_EQ(window_, window); |
| 59 parent()->ReorderChild(this, GetIndexOfChildInParent(window)); |
| 60 } |
| 61 |
| 62 void WindowElement::OnWindowBoundsChanged(aura::Window* window, |
| 63 const gfx::Rect& old_bounds, |
| 64 const gfx::Rect& new_bounds) { |
| 65 DCHECK_EQ(window_, window); |
| 66 delegate()->OnUIElementBoundsChanged(this); |
| 67 } |
| 68 |
| 69 void WindowElement::GetBounds(gfx::Rect* bounds) const { |
| 70 *bounds = window_->bounds(); |
| 71 } |
| 72 |
| 73 void WindowElement::SetBounds(const gfx::Rect& bounds) { |
| 74 window_->SetBounds(bounds); |
| 75 } |
| 76 |
| 77 void WindowElement::GetVisible(bool* visible) const { |
| 78 *visible = window_->IsVisible(); |
| 79 } |
| 80 |
| 81 void WindowElement::SetVisible(bool visible) { |
| 82 if (visible) |
| 83 window_->Show(); |
| 84 else |
| 85 window_->Hide(); |
| 86 } |
| 87 |
| 88 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() |
| 89 const { |
| 90 return std::make_pair(window_, window_->GetBoundsInScreen()); |
| 91 } |
| 92 |
| 93 // static |
| 94 aura::Window* WindowElement::From(UIElement* element) { |
| 95 DCHECK_EQ(UIElementType::WINDOW, element->type()); |
| 96 return static_cast<WindowElement*>(element)->window_; |
| 97 } |
| 98 |
| 99 } // namespace devtools |
| 100 } // namespace ash |
OLD | NEW |