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 RemoveChild(child_element); | |
34 delete child_element; | |
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::GetBounds(gfx::Rect* bounds) const { | |
61 *bounds = view_->bounds(); | |
62 } | |
63 | |
64 void ViewElement::SetBounds(const gfx::Rect& bounds) { | |
65 view_->SetBoundsRect(bounds); | |
66 } | |
67 | |
68 void ViewElement::GetVisible(bool* visible) const { | |
69 *visible = view_->visible(); | |
70 } | |
71 | |
72 void ViewElement::SetVisible(bool visible) { | |
73 view_->SetVisible(visible); | |
74 } | |
75 | |
76 std::pair<aura::Window*, gfx::Rect> ViewElement::GetNodeWindowAndBounds() | |
77 const { | |
78 return std::make_pair(view_->GetWidget()->GetNativeWindow(), | |
79 view_->GetBoundsInScreen()); | |
80 } | |
81 | |
82 // static | |
83 views::View* ViewElement::From(UIElement* element) { | |
84 DCHECK_EQ(UIElementType::VIEW, element->type()); | |
85 return static_cast<ViewElement*>(element)->view_; | |
86 } | |
87 | |
88 } // namespace devtools | |
89 } // namespace ash | |
OLD | NEW |