Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: ash/devtools/view_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 UIElement* parent)
17 : UIElement(UIElementType::VIEW, ui_element_delegate, parent), view_(view) {
18 if (!view_->HasObserver(this))
19 view_->AddObserver(this);
20 }
21
22 ViewElement::~ViewElement() {
23 if (view_ && view_->HasObserver(this))
24 view_->RemoveObserver(this);
25 }
26
27 views::View* ViewElement::view() {
28 return view_;
29 }
30
31 void ViewElement::OnChildViewRemoved(views::View* parent, views::View* view) {
32 if (parent == view_) {
33 for (auto* child_element : GetChildren()) {
34 if (UIElement::GetBackingElement<views::View, ViewElement>(
35 child_element) == view)
36 GetUIElementDelegate()->OnUIElementRemoved(child_element->GetNodeId());
37 }
38 }
39 }
40
41 void ViewElement::OnChildViewAdded(views::View* parent, views::View* view) {
42 if (parent == view_) {
43 GetUIElementDelegate()->OnUIElementAdded(
44 GetNodeId(), new ViewElement(view, GetUIElementDelegate(), this),
45 GetChildren().end() - 1);
46 }
47 }
48
49 void ViewElement::OnChildViewReordered(views::View* parent, views::View* view) {
50 if (view == view_) {
51 std::vector<UIElement*>::iterator prev_sibling_position =
52 GetUIElementDelegate()->OnUIElementRemoved(GetNodeId());
53
54 GetUIElementDelegate()->OnUIElementAdded(
55 GetParent()->GetNodeId(),
56 new ViewElement(view, GetUIElementDelegate(), GetParent()),
sadrul 2017/04/24 18:35:21 This means there's a second ViewElement being crea
thanhph 2017/04/26 13:50:38 This was the cause. I move Destroy() out of OnUIEl
57 prev_sibling_position);
58 }
sadrul 2017/04/24 18:35:22 When stacking/ordering changes, instead of 'remove
thanhph 2017/04/26 13:50:38 I just call OnUIElementRemoved() and follow OnUIEl
59 }
60
61 void ViewElement::OnViewBoundsChanged(views::View* view) {
62 if (view_ == view)
63 GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId());
64 }
65
66 void ViewElement::Destroy() {
67 delete this;
68 }
69
70 bool ViewElement::GetBounds(gfx::Rect* bounds) {
71 if (view_) {
72 *bounds = view_->bounds();
73 return true;
74 }
75 return false;
76 }
77
78 bool ViewElement::SetBounds(const gfx::Rect& bounds) {
79 if (view_) {
80 view_->SetBoundsRect(bounds);
81 return true;
82 }
83 return false;
84 }
85
86 bool ViewElement::GetVisible(bool* visible) {
87 if (view_) {
88 *visible = view_->visible();
89 return true;
90 }
91 return false;
92 }
93
94 bool ViewElement::SetVisible(bool visible) {
95 if (view_) {
96 if (visible != view_->visible())
97 view_->SetVisible(visible);
98 return true;
99 }
100 return false;
101 }
102
103 std::pair<aura::Window*, gfx::Rect> ViewElement::GetNodeWindowAndBounds() {
104 if (view_)
105 return std::make_pair(view_->GetWidget()->GetNativeWindow(),
106 view_->bounds());
107 return std::make_pair(nullptr, gfx::Rect());
108 }
109
110 // static
111 views::View* ViewElement::From(UIElement* element) {
112 DCHECK_EQ(UIElementType::VIEW, element->GetType());
113 return static_cast<ViewElement*>(element)->view_;
114 }
115
116 } // namespace devtools
117 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698