| 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..f9d3912f87a820f2693ba57b5b7d6b7d939af04d
|
| --- /dev/null
|
| +++ b/ash/devtools/view_element.cc
|
| @@ -0,0 +1,111 @@
|
| +// 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 {
|
| +
|
| +namespace {
|
| +
|
| +int FindSibling(views::View* view) {
|
| + views::View* parent = view->parent();
|
| + int view_index = -1;
|
| + for (int i = 0, count = parent->child_count(); i < count; i++) {
|
| + if (view == parent->child_at(i)) {
|
| + view_index = i;
|
| + break;
|
| + }
|
| + }
|
| + DCHECK_GE(view_index, 0);
|
| + return view_index;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ViewElement::ViewElement(views::View* view,
|
| + UIElementDelegate* ui_element_delegate,
|
| + UIElement* parent)
|
| + : UIElement(UIElementType::VIEW, ui_element_delegate, parent), view_(view) {
|
| + view_->AddObserver(this);
|
| +}
|
| +
|
| +ViewElement::~ViewElement() {
|
| + view_->RemoveObserver(this);
|
| +}
|
| +
|
| +views::View* ViewElement::view() const {
|
| + return view_;
|
| +}
|
| +
|
| +void ViewElement::OnChildViewRemoved(views::View* parent, views::View* view) {
|
| + DCHECK(parent == view_);
|
| + for (auto* child_element : GetChildren()) {
|
| + if (UIElement::GetBackingElement<views::View, ViewElement>(child_element) ==
|
| + view &&
|
| + delegate()->OnUIElementRemoved(child_element)) {
|
| + RemoveChild(child_element);
|
| + child_element->Destroy();
|
| + }
|
| + }
|
| +}
|
| +
|
| +void ViewElement::OnChildViewAdded(views::View* parent, views::View* view) {
|
| + DCHECK(parent == view_);
|
| + delegate()->OnUIElementAdded(
|
| + this, new ViewElement(view, delegate(), this),
|
| + GetChildren().empty() ? nullptr : GetChildren().back());
|
| +}
|
| +
|
| +void ViewElement::OnChildViewReordered(views::View* parent, views::View* view) {
|
| + DCHECK(view == view_);
|
| + GetParent()->RemoveChild(this);
|
| + UIElement* prev_sibling = GetParent()->ReorderChild(this, FindSibling(view));
|
| + delegate()->OnUIElementReordered(GetParent(), this, prev_sibling);
|
| +}
|
| +
|
| +void ViewElement::OnViewBoundsChanged(views::View* view) {
|
| + DCHECK(view_ == view);
|
| + delegate()->OnUIElementBoundsChanged(this);
|
| +}
|
| +
|
| +void ViewElement::Destroy() {
|
| + delete this;
|
| +}
|
| +
|
| +void ViewElement::GetBounds(gfx::Rect* bounds) const {
|
| + *bounds = view_->bounds();
|
| +}
|
| +
|
| +void ViewElement::SetBounds(const gfx::Rect& bounds) {
|
| + view_->SetBoundsRect(bounds);
|
| +}
|
| +
|
| +void ViewElement::GetVisible(bool* visible) const {
|
| + *visible = view_->visible();
|
| +}
|
| +
|
| +void ViewElement::SetVisible(bool visible) {
|
| + if (visible != view_->visible())
|
| + view_->SetVisible(visible);
|
| +}
|
| +
|
| +std::pair<aura::Window*, gfx::Rect> ViewElement::GetNodeWindowAndBounds()
|
| + const {
|
| + return std::make_pair(view_->GetWidget()->GetNativeWindow(), view_->bounds());
|
| +}
|
| +
|
| +// static
|
| +views::View* ViewElement::From(UIElement* element) {
|
| + DCHECK_EQ(UIElementType::VIEW, element->GetType());
|
| + return static_cast<ViewElement*>(element)->view_;
|
| +}
|
| +
|
| +} // namespace devtools
|
| +} // namespace ash
|
|
|