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

Side by Side Diff: ash/devtools/window_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
« ash/devtools/view_element.cc ('K') | « ash/devtools/window_element.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
13 WindowElement::WindowElement(aura::Window* window,
14 UIElementDelegate* ui_element_delegate,
15 UIElement* parent)
16 : UIElement(UIElementType::WINDOW, ui_element_delegate, parent),
17 window_(window) {
18 if (window_ && !window_->HasObserver(this))
19 window_->AddObserver(this);
20 }
21
22 WindowElement::~WindowElement() {
23 if (window_ && window_->HasObserver(this))
24 window_->RemoveObserver(this);
25 }
26
27 aura::Window* WindowElement::window() {
28 return window_;
29 }
30
31 // Handles removing window_.
32 void WindowElement::OnWindowHierarchyChanging(
33 const aura::WindowObserver::HierarchyChangeParams& params) {
34 if (params.target == window_)
35 GetUIElementDelegate()->OnUIElementRemoved(GetNodeId());
36 }
37
38 // Handles adding window_.
39 void WindowElement::OnWindowHierarchyChanged(
40 const aura::WindowObserver::HierarchyChangeParams& params) {
41 if (window_ == params.new_parent && params.receiver == params.new_parent) {
42 UIElement* child_window_element =
43 new WindowElement(params.target, GetUIElementDelegate(), this);
44 GetUIElementDelegate()->OnUIElementAdded(GetNodeId(), child_window_element,
45 GetChildren().end() - 1);
46 }
47 }
48
49 void WindowElement::OnWindowStackingChanged(aura::Window* window) {
50 if (window_ == window) {
51 int parent_node_id = GetParent()->GetNodeId();
52 std::vector<UIElement*>::iterator prev_sibling_position =
53 GetUIElementDelegate()->OnUIElementRemoved(GetNodeId());
54 UIElement* window_element =
55 new WindowElement(window, GetUIElementDelegate(), GetParent());
56 GetUIElementDelegate()->OnUIElementAdded(parent_node_id, window_element,
57 prev_sibling_position);
58 }
59 }
60
61 void WindowElement::OnWindowBoundsChanged(aura::Window* window,
62 const gfx::Rect& old_bounds,
63 const gfx::Rect& new_bounds) {
64 if (window_ == window)
65 GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId());
66 }
67
68 void WindowElement::Destroy() {
69 delete this;
70 }
71
72 bool WindowElement::GetBounds(gfx::Rect* bounds) {
73 if (window_) {
74 *bounds = window_->bounds();
75 return true;
76 }
77 return false;
78 }
79
80 bool WindowElement::SetBounds(const gfx::Rect& bounds) {
81 if (window_) {
82 window_->SetBounds(bounds);
83 return true;
84 }
85 return false;
86 }
87
88 bool WindowElement::GetVisible(bool* visible) {
89 if (window_) {
90 *visible = window_->IsVisible();
91 return true;
92 }
93 return false;
94 }
95
96 bool WindowElement::SetVisible(bool visible) {
97 if (window_) {
98 if (visible != window_->IsVisible()) {
99 if (visible)
100 window_->Show();
101 else
102 window_->Hide();
103 }
104 return true;
105 }
106 return false;
107 }
108
109 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() {
110 if (window_)
111 return std::make_pair(window_, window_->GetBoundsInScreen());
112 return std::make_pair(nullptr, gfx::Rect());
113 }
114
115 // static
116 aura::Window* WindowElement::From(UIElement* element) {
117 DCHECK_EQ(UIElementType::WINDOW, element->GetType());
118 return static_cast<WindowElement*>(element)->window_;
119 }
120
121 } // namespace devtools
122 } // namespace ash
OLDNEW
« ash/devtools/view_element.cc ('K') | « ash/devtools/window_element.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698