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

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, 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
« 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..bbb0103d3ce74cb9d6b35883f14e720780ae6239
--- /dev/null
+++ b/ash/devtools/window_element.cc
@@ -0,0 +1,109 @@
+// 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 {
+namespace {
+
+int FindSibling(aura::Window* window) {
sadrul 2017/05/09 04:58:07 Call this: int GetIndexOfChildInParent(aura::Windo
thanhph 2017/05/09 20:52:47 Done.
+ const aura::Window::Windows& siblings = window->parent()->children();
+ auto it = std::find(siblings.begin(), siblings.end(), window);
+ DCHECK(it != siblings.end());
+ return std::distance(siblings.begin(), it);
+}
+
+} // namespace
+
+WindowElement::WindowElement(aura::Window* window,
+ UIElementDelegate* ui_element_delegate,
+ UIElement* parent)
+ : UIElement(UIElementType::WINDOW, ui_element_delegate, parent),
+ window_(window) {
+ if (window_)
sadrul 2017/05/09 04:58:07 |window_| should be non-null. You should not need
thanhph 2017/05/09 20:52:47 For root ui_element tree, I assume associated wind
+ window_->AddObserver(this);
+}
+
+WindowElement::~WindowElement() {
+ if (window_)
+ window_->RemoveObserver(this);
+}
+
+// Handles removing window_.
+void WindowElement::OnWindowHierarchyChanging(
+ const aura::WindowObserver::HierarchyChangeParams& params) {
+ if (params.target == window_ && delegate()->OnUIElementRemoved(this)) {
+ this->parent()->RemoveChild(this);
+ Destroy();
+ }
+}
+
+// Handles adding window_.
+void WindowElement::OnWindowHierarchyChanged(
+ const aura::WindowObserver::HierarchyChangeParams& params) {
+ if (window_ == params.new_parent && params.receiver == params.new_parent) {
+ AddChild(new WindowElement(params.target, delegate(), this),
+ children().empty() ? nullptr : children().back());
+ }
+}
+
+void WindowElement::OnWindowStackingChanged(aura::Window* window) {
+ DCHECK(window_ == window);
+ if (delegate()->IsHighlightingWindow(window))
+ return;
+
+ this->parent()->RemoveChild(this);
sadrul 2017/05/09 04:58:07 Don't need |this->| Why do you need to RemoveChil
thanhph 2017/05/09 20:52:47 Done, I put this line in ReorderChild.
+ this->parent()->ReorderChild(this, FindSibling(window));
+ delegate()->OnUIElementReordered(this->parent(), this);
sadrul 2017/05/09 04:58:07 UIElement::ReorderChild() should call OnUIElementR
thanhph 2017/05/09 20:52:47 Done.
+}
+
+void WindowElement::OnWindowBoundsChanged(aura::Window* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) {
+ DCHECK(window_ == window);
+ delegate()->OnUIElementBoundsChanged(this);
+}
+
+void WindowElement::Destroy() {
+ delete this;
+}
+
+void WindowElement::GetBounds(gfx::Rect* bounds) const {
+ *bounds = window_->bounds();
+}
+
+void WindowElement::SetBounds(const gfx::Rect& bounds) {
+ window_->SetBounds(bounds);
+}
+
+void WindowElement::GetVisible(bool* visible) const {
+ *visible = window_->IsVisible();
+}
+
+void WindowElement::SetVisible(bool visible) {
+ if (visible != window_->IsVisible()) {
sadrul 2017/05/09 04:58:07 early return
thanhph 2017/05/09 20:52:47 Done.
+ if (visible)
+ window_->Show();
+ else
+ window_->Hide();
+ }
+}
+
+std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds()
+ const {
+ return std::make_pair(window_, window_->GetBoundsInScreen());
+}
+
+// static
+aura::Window* WindowElement::From(UIElement* element) {
+ DCHECK_EQ(UIElementType::WINDOW, element->type());
+ 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