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/view_element.h" |
| 6 |
| 7 #include "ash/devtools/ui_element_delegate.h" |
| 8 #include "ui/views/widget/widget.h" |
| 9 |
| 10 namespace ash { |
| 11 namespace devtools { |
| 12 |
| 13 ViewElement::ViewElement(views::View* view, |
| 14 UIElementDelegate* ui_element_delegate, |
| 15 UIElement* parent) |
| 16 : UIElement(UIElementType::VIEW, ui_element_delegate, parent), view_(view) { |
| 17 view_->AddObserver(this); |
| 18 } |
| 19 |
| 20 ViewElement::~ViewElement() { |
| 21 view_->RemoveObserver(this); |
| 22 } |
| 23 |
| 24 void ViewElement::OnChildViewRemoved(views::View* parent, views::View* view) { |
| 25 DCHECK_EQ(parent, view_); |
| 26 auto iter = std::find_if( |
| 27 children().begin(), children().end(), [view](UIElement* child) { |
| 28 return view == |
| 29 UIElement::GetBackingElement<views::View, ViewElement>(child); |
| 30 }); |
| 31 DCHECK(iter != children().end()); |
| 32 UIElement* child_element = *iter; |
| 33 if (RemoveChild(child_element)) |
| 34 child_element->Destroy(); |
| 35 } |
| 36 |
| 37 void ViewElement::OnChildViewAdded(views::View* parent, views::View* view) { |
| 38 DCHECK_EQ(parent, view_); |
| 39 AddChild(new ViewElement(view, delegate(), this), |
| 40 children().empty() ? nullptr : children().back()); |
| 41 } |
| 42 |
| 43 void ViewElement::OnChildViewReordered(views::View* parent, views::View* view) { |
| 44 DCHECK_EQ(parent, view_); |
| 45 auto iter = std::find_if( |
| 46 children().begin(), children().end(), [view](UIElement* child) { |
| 47 return view == |
| 48 UIElement::GetBackingElement<views::View, ViewElement>(child); |
| 49 }); |
| 50 DCHECK(iter != children().end()); |
| 51 UIElement* child_element = *iter; |
| 52 ReorderChild(child_element, parent->GetIndexOf(view)); |
| 53 } |
| 54 |
| 55 void ViewElement::OnViewBoundsChanged(views::View* view) { |
| 56 DCHECK_EQ(view_, view); |
| 57 delegate()->OnUIElementBoundsChanged(this); |
| 58 } |
| 59 |
| 60 void ViewElement::Destroy() { |
| 61 delete this; |
| 62 } |
| 63 |
| 64 void ViewElement::GetBounds(gfx::Rect* bounds) const { |
| 65 *bounds = view_->bounds(); |
| 66 } |
| 67 |
| 68 void ViewElement::SetBounds(const gfx::Rect& bounds) { |
| 69 view_->SetBoundsRect(bounds); |
| 70 } |
| 71 |
| 72 void ViewElement::GetVisible(bool* visible) const { |
| 73 *visible = view_->visible(); |
| 74 } |
| 75 |
| 76 void ViewElement::SetVisible(bool visible) { |
| 77 if (visible != view_->visible()) |
| 78 view_->SetVisible(visible); |
| 79 } |
| 80 |
| 81 std::pair<aura::Window*, gfx::Rect> ViewElement::GetNodeWindowAndBounds() |
| 82 const { |
| 83 return std::make_pair(view_->GetWidget()->GetNativeWindow(), view_->bounds()); |
| 84 } |
| 85 |
| 86 // static |
| 87 views::View* ViewElement::From(UIElement* element) { |
| 88 DCHECK_EQ(UIElementType::VIEW, element->type()); |
| 89 return static_cast<ViewElement*>(element)->view_; |
| 90 } |
| 91 |
| 92 } // namespace devtools |
| 93 } // namespace ash |
OLD | NEW |