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

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

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: rebase 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 : widget_(widget) {
15 this->SetUIElementDelegate(ui_element_delegate);
16 this->SetType(UIElementType::WIDGET);
17 if (!widget_->HasRemovalsObserver(this))
18 widget_->AddRemovalsObserver(this);
19 }
20
21 WidgetElement::WidgetElement(views::Widget* widget, int node_id)
22 : widget_(widget) {
23 this->SetType(UIElementType::WIDGET);
24 if (!widget_->HasRemovalsObserver(this))
25 widget_->AddRemovalsObserver(this);
26 this->SetNodeId(node_id);
27 }
28
29 WidgetElement::~WidgetElement() {
30 if (widget_ && widget_->HasRemovalsObserver(this))
31 widget_->RemoveRemovalsObserver(this);
32 }
33
34 views::Widget* WidgetElement::widget() {
35 return widget_;
36 }
37
38 void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) {
39 if (view == widget->GetRootView())
40 GetUIElementDelegate()->OnUIElementRemoved(
41 this->GetChildren()[0]->GetNodeId());
42 }
43
44 void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget,
45 const gfx::Rect& new_bounds) {
46 if (widget == this->widget_)
47 GetUIElementDelegate()->OnUIElementBoundsChanged(this->GetNodeId());
48 }
49
50 void WidgetElement::Destroy() {
51 this->~WidgetElement();
52 }
53
54 bool WidgetElement::GetBounds(gfx::Rect* bounds) {
55 if (widget_) {
56 *bounds = widget_->GetRestoredBounds();
57 return true;
58 }
59 return false;
60 }
61
62 bool WidgetElement::SetBounds(const gfx::Rect& bounds) {
63 if (widget_) {
64 widget_->SetBounds(bounds);
65 return true;
66 }
67 return false;
68 }
69
70 bool WidgetElement::GetVisible(bool* visible) {
71 if (widget_) {
72 *visible = widget_->IsVisible();
73 return true;
74 }
75 return false;
76 }
77
78 bool WidgetElement::SetVisible(bool visible) {
79 if (widget_) {
80 if (visible != widget_->IsVisible()) {
81 if (visible)
82 widget_->Show();
83 else
84 widget_->Hide();
85 }
86 return true;
87 }
88 return false;
89 }
90
91 std::pair<WmWindow*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds() {
92 if (widget_)
93 return std::make_pair(WmWindow::Get(widget_->GetNativeWindow()),
94 widget_->GetWindowBoundsInScreen());
95 return std::make_pair(nullptr, gfx::Rect());
96 }
97
98 // static
99 views::Widget* WidgetElement::From(UIElement* element) {
100 DCHECK_EQ(UIElementType::WIDGET, element->GetType());
101 return static_cast<WidgetElement*>(element)->widget_;
102 }
103
104 } // namespace devtools
105 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698