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

Unified Diff: ash/devtools/view_element.cc

Issue 2776543002: Create a unified UIElement interface for Widget, View and Window. (Closed)
Patch Set: rebase 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
Index: ash/devtools/view_element.cc
diff --git a/ash/devtools/view_element.cc b/ash/devtools/view_element.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e308a5a7dba520c22a1b04d1fa376177d1069711
--- /dev/null
+++ b/ash/devtools/view_element.cc
@@ -0,0 +1,124 @@
+// 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/view_element.h"
+
+#include "ash/devtools/ui_element_delegate.h"
+#include "ash/wm_window.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+namespace devtools {
+
+ViewElement::ViewElement(views::View* view,
+ UIElementDelegate* ui_element_delegate)
+ : view_(view) {
+ this->SetUIElementDelegate(ui_element_delegate);
sadrul 2017/04/19 18:21:39 Remove |this->| from the code.
thanhph 2017/04/24 15:56:50 Done.
+ this->SetType(UIElementType::VIEW);
+ if (!view_->HasObserver(this))
+ view_->AddObserver(this);
+}
+
+ViewElement::ViewElement(views::View* view, int node_id) : view_(view) {
+ this->SetType(UIElementType::VIEW);
+ if (!view_->HasObserver(this))
+ view_->AddObserver(this);
+ this->SetNodeId(node_id);
sadrul 2017/04/19 18:21:39 As far as I can see, none of the code actually use
thanhph 2017/04/24 15:56:50 The node id is set in dom_agent for view, window a
+}
+
+ViewElement::~ViewElement() {
+ if (view_ && view_->HasObserver(this))
+ view_->RemoveObserver(this);
+}
+
+views::View* ViewElement::view() {
+ return view_;
+}
+
+void ViewElement::OnChildViewRemoved(views::View* parent, views::View* view) {
+ if (parent == this->view_) {
+ for (auto* child_element : this->GetChildren()) {
+ if (UIElement::GetBackingElement<views::View, ViewElement>(
+ child_element) == view)
+ GetUIElementDelegate()->OnUIElementRemoved(child_element->GetNodeId());
+ }
+ }
+}
+
+void ViewElement::OnChildViewAdded(views::View* parent, views::View* view) {
+ if (parent == this->view_) {
+ GetUIElementDelegate()->OnUIElementAdded(
+ this->GetNodeId(), new ViewElement(view, GetUIElementDelegate()),
+ this->GetChildren().end() - 1);
+ }
+}
+
+void ViewElement::OnChildViewReordered(views::View* parent, views::View* view) {
+ if (view == this->view_) {
+ std::vector<UIElement*>::iterator prev_sibling_position =
+ GetUIElementDelegate()->OnUIElementRemoved(this->GetNodeId());
+
+ GetUIElementDelegate()->OnUIElementAdded(
+ this->GetParent()->GetNodeId(),
+ new ViewElement(view, GetUIElementDelegate()), prev_sibling_position);
+ }
+}
+
+void ViewElement::OnViewBoundsChanged(views::View* view) {
+ if (view == this->view_)
+ this->GetUIElementDelegate()->OnUIElementBoundsChanged(this->GetNodeId());
+}
+
+void ViewElement::Destroy() {
+ this->~ViewElement();
sadrul 2017/04/19 18:21:39 'delete this'
thanhph 2017/04/24 15:56:50 Done.
+}
+
+bool ViewElement::GetBounds(gfx::Rect* bounds) {
+ if (view_) {
+ *bounds = view_->bounds();
+ return true;
+ }
+ return false;
+}
+
+bool ViewElement::SetBounds(const gfx::Rect& bounds) {
+ if (view_) {
+ view_->SetBoundsRect(bounds);
+ return true;
+ }
+ return false;
+}
+
+bool ViewElement::GetVisible(bool* visible) {
+ if (view_) {
+ *visible = view_->visible();
+ return true;
+ }
+ return false;
+}
+
+bool ViewElement::SetVisible(bool visible) {
+ if (view_) {
+ if (visible != view_->visible())
+ view_->SetVisible(visible);
+ return true;
+ }
+ return false;
+}
+
+std::pair<WmWindow*, gfx::Rect> ViewElement::GetNodeWindowAndBounds() {
+ if (view_)
+ return std::make_pair(WmWindow::Get(view_->GetWidget()->GetNativeWindow()),
+ view_->bounds());
+ return std::make_pair(nullptr, gfx::Rect());
+}
+
+// static
+views::View* ViewElement::From(UIElement* element) {
+ DCHECK_EQ(UIElementType::VIEW, element->GetType());
+ return static_cast<ViewElement*>(element)->view_;
+}
+
+} // namespace devtools
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698