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

Side by Side Diff: ash/devtools/widget_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/widget_element.h"
6
7 #include "ash/devtools/ui_element_delegate.h"
8
9 namespace ash {
10 namespace devtools {
11
12 WidgetElement::WidgetElement(views::Widget* widget,
13 UIElementDelegate* ui_element_delegate,
14 UIElement* parent)
15 : UIElement(UIElementType::WIDGET, ui_element_delegate, parent),
16 widget_(widget) {
17 if (!widget_->HasRemovalsObserver(this))
18 widget_->AddRemovalsObserver(this);
19 }
20
21 WidgetElement::~WidgetElement() {
22 if (widget_ && widget_->HasRemovalsObserver(this))
23 widget_->RemoveRemovalsObserver(this);
24 }
25
26 views::Widget* WidgetElement::widget() {
27 return widget_;
28 }
29
30 void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) {
31 if (view == widget->GetRootView())
32 GetUIElementDelegate()->OnUIElementRemoved(GetChildren()[0]->GetNodeId());
33 }
34
35 void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget,
36 const gfx::Rect& new_bounds) {
37 if (widget == widget_)
38 GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId());
39 }
40
41 void WidgetElement::Destroy() {
42 delete this;
43 }
44
45 bool WidgetElement::GetBounds(gfx::Rect* bounds) {
46 if (widget_) {
47 *bounds = widget_->GetRestoredBounds();
48 return true;
49 }
50 return false;
51 }
52
53 bool WidgetElement::SetBounds(const gfx::Rect& bounds) {
54 if (widget_) {
55 widget_->SetBounds(bounds);
56 return true;
57 }
58 return false;
59 }
60
61 bool WidgetElement::GetVisible(bool* visible) {
62 if (widget_) {
63 *visible = widget_->IsVisible();
64 return true;
65 }
66 return false;
67 }
68
69 bool WidgetElement::SetVisible(bool visible) {
70 if (widget_) {
71 if (visible != widget_->IsVisible()) {
72 if (visible)
73 widget_->Show();
74 else
75 widget_->Hide();
76 }
77 return true;
78 }
79 return false;
80 }
81
82 std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds() {
83 if (widget_)
84 return std::make_pair(widget_->GetNativeWindow(),
85 widget_->GetWindowBoundsInScreen());
86 return std::make_pair(nullptr, gfx::Rect());
87 }
88
89 // static
90 views::Widget* WidgetElement::From(UIElement* element) {
91 DCHECK_EQ(UIElementType::WIDGET, element->GetType());
92 return static_cast<WidgetElement*>(element)->widget_;
93 }
94
95 } // namespace devtools
96 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698