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

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

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: nits 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
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 widget_->AddRemovalsObserver(this);
18 }
19
20 WidgetElement::~WidgetElement() {
21 widget_->RemoveRemovalsObserver(this);
22 }
23
24 void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) {
25 if (view == widget->GetRootView() &&
26 delegate()->OnUIElementRemoved(children()[0])) {
sadrul 2017/05/09 04:58:07 It'd be good to verify the assumption on children(
thanhph 2017/05/09 20:52:47 Done.
27 RemoveChild(children()[0]);
28 children()[0]->Destroy();
29 }
30 }
31
32 void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget,
33 const gfx::Rect& new_bounds) {
34 DCHECK(widget == widget_);
sadrul 2017/05/09 04:58:07 DCHECK_EQ
thanhph 2017/05/09 20:52:47 Done.
35 delegate()->OnUIElementBoundsChanged(this);
36 }
37
38 void WidgetElement::Destroy() {
39 delete this;
40 }
41
42 void WidgetElement::GetBounds(gfx::Rect* bounds) const {
43 *bounds = widget_->GetRestoredBounds();
44 }
45
46 void WidgetElement::SetBounds(const gfx::Rect& bounds) {
47 widget_->SetBounds(bounds);
48 }
49
50 void WidgetElement::GetVisible(bool* visible) const {
51 *visible = widget_->IsVisible();
52 }
53
54 void WidgetElement::SetVisible(bool visible) {
55 if (visible != widget_->IsVisible()) {
sadrul 2017/05/09 04:58:07 early return. i.e.: if (visible == widget_->IsV
thanhph 2017/05/09 20:52:47 Done.
56 if (visible)
57 widget_->Show();
58 else
59 widget_->Hide();
60 }
61 }
62
63 std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds()
64 const {
65 return std::make_pair(widget_->GetNativeWindow(),
66 widget_->GetWindowBoundsInScreen());
67 }
68
69 // static
70 views::Widget* WidgetElement::From(UIElement* element) {
71 DCHECK_EQ(UIElementType::WIDGET, element->type());
72 return static_cast<WidgetElement*>(element)->widget_;
73 }
74
75 } // namespace devtools
76 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698