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

Unified Diff: ash/devtools/window_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: nits 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 side-by-side diff with in-line comments
Download patch
« ash/devtools/widget_element.cc ('K') | « ash/devtools/window_element.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/devtools/window_element.cc
diff --git a/ash/devtools/window_element.cc b/ash/devtools/window_element.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e57d64bdf9f32dcc43c5214ac1fc654e937f1c9
--- /dev/null
+++ b/ash/devtools/window_element.cc
@@ -0,0 +1,130 @@
+// 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/window_element.h"
+
+#include "ash/devtools/ui_element_delegate.h"
+#include "ui/aura/window.h"
+
+namespace ash {
+namespace devtools {
+
+WindowElement::WindowElement(aura::Window* window,
+ UIElementDelegate* ui_element_delegate,
+ UIElement* parent)
+ : UIElement(UIElementType::WINDOW, ui_element_delegate, parent),
+ window_(window) {
+ if (window_ && !window_->HasObserver(this))
+ window_->AddObserver(this);
+}
+
+WindowElement::~WindowElement() {
+ if (window_ && window_->HasObserver(this))
+ window_->RemoveObserver(this);
+}
+
+aura::Window* WindowElement::window() {
+ return window_;
+}
+
+// Handles removing window_.
+void WindowElement::OnWindowHierarchyChanging(
+ const aura::WindowObserver::HierarchyChangeParams& params) {
+ if (params.target == window_ &&
+ GetUIElementDelegate()->OnUIElementRemoved(GetNodeId())) {
+ RemoveChildFromParent();
+ Destroy();
+ }
+}
+
+// Handles adding window_.
+void WindowElement::OnWindowHierarchyChanged(
+ const aura::WindowObserver::HierarchyChangeParams& params) {
+ if (window_ == params.new_parent && params.receiver == params.new_parent) {
+ GetUIElementDelegate()->OnUIElementAdded(
+ GetNodeId(),
+ new WindowElement(params.target, GetUIElementDelegate(), this),
+ GetChildren().end() - 1);
+ }
+}
+
+void WindowElement::OnWindowStackingChanged(aura::Window* window) {
+ if (window_ == window) {
sadrul 2017/05/01 16:22:27 This should be a DCHECK, right?
thanhph 2017/05/03 21:58:11 Done. Only the changed window is called back here.
+ std::vector<UIElement*>::iterator prev_sibling_position;
+
+ if (GetUIElementDelegate()->OnUIElementRemoved(GetNodeId()))
+ prev_sibling_position = RemoveChildFromParent();
+ else
+ prev_sibling_position = GetParent()->GetChildren().end();
+
+ GetUIElementDelegate()->OnUIElementAdded(
+ GetParent()->GetNodeId(),
+ new WindowElement(window, GetUIElementDelegate(), GetParent()),
+ prev_sibling_position);
sadrul 2017/05/01 16:22:27 Without doing Removed + Added, can we introduce UI
thanhph 2017/05/03 21:58:11 Done.
+ Destroy();
+ }
+}
+
+void WindowElement::OnWindowBoundsChanged(aura::Window* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) {
+ if (window_ == window)
sadrul 2017/05/01 16:22:27 ditto
thanhph 2017/05/03 21:58:11 Done.
+ GetUIElementDelegate()->OnUIElementBoundsChanged(GetNodeId());
+}
+
+void WindowElement::Destroy() {
+ delete this;
+}
+
+bool WindowElement::GetBounds(gfx::Rect* bounds) {
+ if (window_) {
+ *bounds = window_->bounds();
+ return true;
+ }
+ return false;
+}
+
+bool WindowElement::SetBounds(const gfx::Rect& bounds) {
+ if (window_) {
+ window_->SetBounds(bounds);
+ return true;
+ }
+ return false;
+}
+
+bool WindowElement::GetVisible(bool* visible) {
+ if (window_) {
+ *visible = window_->IsVisible();
+ return true;
+ }
+ return false;
+}
+
+bool WindowElement::SetVisible(bool visible) {
+ if (window_) {
+ if (visible != window_->IsVisible()) {
+ if (visible)
+ window_->Show();
+ else
+ window_->Hide();
+ }
+ return true;
+ }
+ return false;
+}
+
+std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() {
+ if (window_)
+ return std::make_pair(window_, window_->GetBoundsInScreen());
+ return std::make_pair(nullptr, gfx::Rect());
+}
+
+// static
+aura::Window* WindowElement::From(UIElement* element) {
+ DCHECK_EQ(UIElementType::WINDOW, element->GetType());
+ return static_cast<WindowElement*>(element)->window_;
+}
+
+} // namespace devtools
+} // namespace ash
« ash/devtools/widget_element.cc ('K') | « ash/devtools/window_element.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698