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 "ash/wm_window.h" | |
9 #include "ui/views/widget/widget.h" | |
10 | |
11 namespace ash { | |
12 namespace devtools { | |
13 | |
14 ViewElement::ViewElement(views::View* view, | |
15 UIElementDelegate* ui_element_delegate) | |
16 : view_(view) { | |
17 this->SetUIElementDelegate(ui_element_delegate); | |
sadrul
2017/04/19 18:21:39
Remove |this->| from the code.
thanhph
2017/04/24 15:56:50
Done.
| |
18 this->SetType(UIElementType::VIEW); | |
19 if (!view_->HasObserver(this)) | |
20 view_->AddObserver(this); | |
21 } | |
22 | |
23 ViewElement::ViewElement(views::View* view, int node_id) : view_(view) { | |
24 this->SetType(UIElementType::VIEW); | |
25 if (!view_->HasObserver(this)) | |
26 view_->AddObserver(this); | |
27 this->SetNodeId(node_id); | |
sadrul
2017/04/19 18:21:39
As far as I can see, none of the code actually use
thanhph
2017/04/24 15:56:50
The node id is set in dom_agent for view, window a
| |
28 } | |
29 | |
30 ViewElement::~ViewElement() { | |
31 if (view_ && view_->HasObserver(this)) | |
32 view_->RemoveObserver(this); | |
33 } | |
34 | |
35 views::View* ViewElement::view() { | |
36 return view_; | |
37 } | |
38 | |
39 void ViewElement::OnChildViewRemoved(views::View* parent, views::View* view) { | |
40 if (parent == this->view_) { | |
41 for (auto* child_element : this->GetChildren()) { | |
42 if (UIElement::GetBackingElement<views::View, ViewElement>( | |
43 child_element) == view) | |
44 GetUIElementDelegate()->OnUIElementRemoved(child_element->GetNodeId()); | |
45 } | |
46 } | |
47 } | |
48 | |
49 void ViewElement::OnChildViewAdded(views::View* parent, views::View* view) { | |
50 if (parent == this->view_) { | |
51 GetUIElementDelegate()->OnUIElementAdded( | |
52 this->GetNodeId(), new ViewElement(view, GetUIElementDelegate()), | |
53 this->GetChildren().end() - 1); | |
54 } | |
55 } | |
56 | |
57 void ViewElement::OnChildViewReordered(views::View* parent, views::View* view) { | |
58 if (view == this->view_) { | |
59 std::vector<UIElement*>::iterator prev_sibling_position = | |
60 GetUIElementDelegate()->OnUIElementRemoved(this->GetNodeId()); | |
61 | |
62 GetUIElementDelegate()->OnUIElementAdded( | |
63 this->GetParent()->GetNodeId(), | |
64 new ViewElement(view, GetUIElementDelegate()), prev_sibling_position); | |
65 } | |
66 } | |
67 | |
68 void ViewElement::OnViewBoundsChanged(views::View* view) { | |
69 if (view == this->view_) | |
70 this->GetUIElementDelegate()->OnUIElementBoundsChanged(this->GetNodeId()); | |
71 } | |
72 | |
73 void ViewElement::Destroy() { | |
74 this->~ViewElement(); | |
sadrul
2017/04/19 18:21:39
'delete this'
thanhph
2017/04/24 15:56:50
Done.
| |
75 } | |
76 | |
77 bool ViewElement::GetBounds(gfx::Rect* bounds) { | |
78 if (view_) { | |
79 *bounds = view_->bounds(); | |
80 return true; | |
81 } | |
82 return false; | |
83 } | |
84 | |
85 bool ViewElement::SetBounds(const gfx::Rect& bounds) { | |
86 if (view_) { | |
87 view_->SetBoundsRect(bounds); | |
88 return true; | |
89 } | |
90 return false; | |
91 } | |
92 | |
93 bool ViewElement::GetVisible(bool* visible) { | |
94 if (view_) { | |
95 *visible = view_->visible(); | |
96 return true; | |
97 } | |
98 return false; | |
99 } | |
100 | |
101 bool ViewElement::SetVisible(bool visible) { | |
102 if (view_) { | |
103 if (visible != view_->visible()) | |
104 view_->SetVisible(visible); | |
105 return true; | |
106 } | |
107 return false; | |
108 } | |
109 | |
110 std::pair<WmWindow*, gfx::Rect> ViewElement::GetNodeWindowAndBounds() { | |
111 if (view_) | |
112 return std::make_pair(WmWindow::Get(view_->GetWidget()->GetNativeWindow()), | |
113 view_->bounds()); | |
114 return std::make_pair(nullptr, gfx::Rect()); | |
115 } | |
116 | |
117 // static | |
118 views::View* ViewElement::From(UIElement* element) { | |
119 DCHECK_EQ(UIElementType::VIEW, element->GetType()); | |
120 return static_cast<ViewElement*>(element)->view_; | |
121 } | |
122 | |
123 } // namespace devtools | |
124 } // namespace ash | |
OLD | NEW |