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

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, 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/view_element.h ('k') | ash/devtools/widget_element.h » ('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/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(), view_->bounds());
79 }
80
81 // static
82 views::View* ViewElement::From(UIElement* element) {
83 DCHECK_EQ(UIElementType::VIEW, element->type());
84 return static_cast<ViewElement*>(element)->view_;
85 }
86
87 } // namespace devtools
88 } // namespace ash
OLDNEW
« no previous file with comments | « ash/devtools/view_element.h ('k') | ash/devtools/widget_element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698