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

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

Issue 2852733002: Duplicate -Move DevTools out of ash and turn it to a component. (Closed)
Patch Set: move unittest to ui/views Created 3 years, 7 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
« no previous file with comments | « ash/devtools/window_element.h ('k') | ash/shell.cc » ('j') | 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 namespace {
13
14 int GetIndexOfChildInParent(aura::Window* window) {
15 const aura::Window::Windows& siblings = window->parent()->children();
16 auto it = std::find(siblings.begin(), siblings.end(), window);
17 DCHECK(it != siblings.end());
18 return std::distance(siblings.begin(), it);
19 }
20
21 } // namespace
22
23 WindowElement::WindowElement(aura::Window* window,
24 UIElementDelegate* ui_element_delegate,
25 UIElement* parent)
26 : UIElement(UIElementType::WINDOW, ui_element_delegate, parent),
27 window_(window) {
28 if (window)
29 window_->AddObserver(this);
30 }
31
32 WindowElement::~WindowElement() {
33 if (window_)
34 window_->RemoveObserver(this);
35 }
36
37 // Handles removing window_.
38 void WindowElement::OnWindowHierarchyChanging(
39 const aura::WindowObserver::HierarchyChangeParams& params) {
40 if (delegate()->IsHighlightingWindow(window_))
41 return;
42 if (params.target == window_) {
43 parent()->RemoveChild(this);
44 Destroy();
45 }
46 }
47
48 // Handles adding window_.
49 void WindowElement::OnWindowHierarchyChanged(
50 const aura::WindowObserver::HierarchyChangeParams& params) {
51 if (window_ == params.new_parent && params.receiver == params.new_parent) {
52 if (delegate()->IsHighlightingWindow(params.target))
53 return;
54 AddChild(new WindowElement(params.target, delegate(), this),
55 children().empty() ? nullptr : children().back());
56 }
57 }
58
59 void WindowElement::OnWindowStackingChanged(aura::Window* window) {
60 DCHECK_EQ(window_, window);
61 if (delegate()->IsHighlightingWindow(window))
62 return;
63 parent()->ReorderChild(this, GetIndexOfChildInParent(window));
64 }
65
66 void WindowElement::OnWindowBoundsChanged(aura::Window* window,
67 const gfx::Rect& old_bounds,
68 const gfx::Rect& new_bounds) {
69 DCHECK_EQ(window_, window);
70 delegate()->OnUIElementBoundsChanged(this);
71 }
72
73 void WindowElement::Destroy() {
74 delete this;
75 }
76
77 void WindowElement::GetBounds(gfx::Rect* bounds) const {
78 *bounds = window_->bounds();
79 }
80
81 void WindowElement::SetBounds(const gfx::Rect& bounds) {
82 window_->SetBounds(bounds);
83 }
84
85 void WindowElement::GetVisible(bool* visible) const {
86 *visible = window_->IsVisible();
87 }
88
89 void WindowElement::SetVisible(bool visible) {
90 if (visible == window_->IsVisible())
91 return;
92 if (visible)
93 window_->Show();
94 else
95 window_->Hide();
96 }
97
98 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds()
99 const {
100 return std::make_pair(window_, window_->GetBoundsInScreen());
101 }
102
103 // static
104 aura::Window* WindowElement::From(UIElement* element) {
105 DCHECK_EQ(UIElementType::WINDOW, element->type());
106 return static_cast<WindowElement*>(element)->window_;
107 }
108
109 } // namespace devtools
110 } // namespace ash
OLDNEW
« no previous file with comments | « ash/devtools/window_element.h ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698