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

Unified Diff: ash/devtools/widget_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/devtools/widget_element.h ('k') | ash/devtools/window_element.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ec07a1f7d2b75b90fec6a8bb9d13e6a39a66a70e
--- /dev/null
+++ b/ash/devtools/widget_element.cc
@@ -0,0 +1,73 @@
+// 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) {
+ widget_->AddRemovalsObserver(this);
+}
+
+WidgetElement::~WidgetElement() {
+ widget_->RemoveRemovalsObserver(this);
+}
+
+void WidgetElement::OnWillRemoveView(views::Widget* widget, views::View* view) {
+ if (view != widget->GetRootView())
+ return;
+ DCHECK_EQ(1u, children().size());
+ UIElement* child = children()[0];
+ RemoveChild(child);
+ delete child;
+}
+
+void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget,
+ const gfx::Rect& new_bounds) {
+ DCHECK_EQ(widget, widget_);
+ delegate()->OnUIElementBoundsChanged(this);
+}
+
+void WidgetElement::GetBounds(gfx::Rect* bounds) const {
+ *bounds = widget_->GetRestoredBounds();
+}
+
+void WidgetElement::SetBounds(const gfx::Rect& bounds) {
+ widget_->SetBounds(bounds);
+}
+
+void WidgetElement::GetVisible(bool* visible) const {
+ *visible = widget_->IsVisible();
+}
+
+void WidgetElement::SetVisible(bool visible) {
+ if (visible == widget_->IsVisible())
+ return;
+ if (visible)
+ widget_->Show();
+ else
+ widget_->Hide();
+}
+
+std::pair<aura::Window*, gfx::Rect> WidgetElement::GetNodeWindowAndBounds()
+ const {
+ return std::make_pair(widget_->GetNativeWindow(),
+ widget_->GetWindowBoundsInScreen());
+}
+
+// static
+views::Widget* WidgetElement::From(UIElement* element) {
+ DCHECK_EQ(UIElementType::WIDGET, element->type());
+ return static_cast<WidgetElement*>(element)->widget_;
+}
+
+} // namespace devtools
+} // namespace ash
« no previous file with comments | « ash/devtools/widget_element.h ('k') | ash/devtools/window_element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698