Index: ash/devtools/widget_element.cc |
diff --git a/ash/devtools/widget_element.cc b/ash/devtools/widget_element.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..987b02a87e5509352fb51347d73c42b17bdffcbe |
--- /dev/null |
+++ b/ash/devtools/widget_element.cc |
@@ -0,0 +1,101 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/devtools/widget_element.h" |
+ |
+#include "ash/devtools/ui_element_delegate.h" |
+ |
+namespace ash { |
+namespace devtools { |
+ |
+WidgetElement::WidgetElement(views::Widget* widget, |
+ UIElementDelegate* ui_element_delegate, |
+ UIElement* parent) |
+ : UIElement(UIElementType::WIDGET, ui_element_delegate, parent), |
+ widget_(widget) { |
+ if (!widget_->HasRemovalsObserver(this)) |
sadrul
2017/05/01 16:22:27
There's no reason for having this check.
thanhph
2017/05/03 21:58:11
Done.
|
+ widget_->AddRemovalsObserver(this); |
+} |
+ |
+WidgetElement::~WidgetElement() { |
+ if (widget_ && widget_->HasRemovalsObserver(this)) |
sadrul
2017/05/01 16:22:27
You are never resetting |widget_|. So this check s
thanhph
2017/05/03 21:58:11
Done.
|
+ widget_->RemoveRemovalsObserver(this); |
+} |
+ |
+views::Widget* WidgetElement::widget() { |
+ return widget_; |
+} |
+ |
+void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) { |
+ if (view == widget->GetRootView()) { |
+ if (GetUIElementDelegate()->OnUIElementRemoved( |
+ GetChildren()[0]->GetNodeId())) { |
+ GetChildren()[0]->RemoveChildFromParent(); |
+ GetChildren()[0]->Destroy(); |
sadrul
2017/05/01 16:22:27
Can you explain this? e.g. why use GetChildren()[0
thanhph
2017/05/03 21:58:11
Widget has only 1 child which is the root view, a.
|
+ } |
+ } |
+} |
+ |
+void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget, |
+ const gfx::Rect& new_bounds) { |
+ if (widget == widget_) |
sadrul
2017/05/01 16:22:27
This should be a DCHECK()?
thanhph
2017/05/03 21:58:10
Done.
|
+ GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId()); |
+} |
+ |
+void WidgetElement::Destroy() { |
+ delete this; |
+} |
+ |
+bool WidgetElement::GetBounds(gfx::Rect* bounds) { |
+ if (widget_) { |
sadrul
2017/05/01 16:22:27
Why do you need these null-checks?
thanhph
2017/05/03 21:58:11
I removed them.
|
+ *bounds = widget_->GetRestoredBounds(); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool WidgetElement::SetBounds(const gfx::Rect& bounds) { |
+ if (widget_) { |
+ widget_->SetBounds(bounds); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool WidgetElement::GetVisible(bool* visible) { |
+ if (widget_) { |
+ *visible = widget_->IsVisible(); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool WidgetElement::SetVisible(bool visible) { |
+ if (widget_) { |
+ if (visible != widget_->IsVisible()) { |
+ if (visible) |
+ widget_->Show(); |
+ else |
+ widget_->Hide(); |
+ } |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds() { |
+ if (widget_) |
+ return std::make_pair(widget_->GetNativeWindow(), |
+ widget_->GetWindowBoundsInScreen()); |
+ return std::make_pair(nullptr, gfx::Rect()); |
+} |
+ |
+// static |
+views::Widget* WidgetElement::From(UIElement* element) { |
+ DCHECK_EQ(UIElementType::WIDGET, element->GetType()); |
+ return static_cast<WidgetElement*>(element)->widget_; |
+} |
+ |
+} // namespace devtools |
+} // namespace ash |