Chromium Code Reviews| 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..007fb31537327c42e8c491bda44712b26035de35 |
| --- /dev/null |
| +++ b/ash/devtools/widget_element.cc |
| @@ -0,0 +1,76 @@ |
| +// 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() && |
| + delegate()->OnUIElementRemoved(children()[0])) { |
|
sadrul
2017/05/09 04:58:07
It'd be good to verify the assumption on children(
thanhph
2017/05/09 20:52:47
Done.
|
| + RemoveChild(children()[0]); |
| + children()[0]->Destroy(); |
| + } |
| +} |
| + |
| +void WidgetElement::OnWidgetBoundsChanged(views::Widget* widget, |
| + const gfx::Rect& new_bounds) { |
| + DCHECK(widget == widget_); |
|
sadrul
2017/05/09 04:58:07
DCHECK_EQ
thanhph
2017/05/09 20:52:47
Done.
|
| + delegate()->OnUIElementBoundsChanged(this); |
| +} |
| + |
| +void WidgetElement::Destroy() { |
| + delete 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()) { |
|
sadrul
2017/05/09 04:58:07
early return. i.e.:
if (visible == widget_->IsV
thanhph
2017/05/09 20:52:47
Done.
|
| + 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 |