Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/devtools/window_element.h" | |
| 6 | |
| 7 #include "ash/devtools/ui_element_delegate.h" | |
| 8 #include "ui/aura/window.h" | |
| 9 | |
| 10 namespace ash { | |
| 11 namespace devtools { | |
| 12 namespace { | |
| 13 | |
| 14 int GetIndexOfChildInParent(aura::Window* window) { | |
| 15 const aura::Window::Windows& siblings = window->parent()->children(); | |
| 16 auto it = std::find(siblings.begin(), siblings.end(), window); | |
| 17 DCHECK(it != siblings.end()); | |
| 18 return std::distance(siblings.begin(), it); | |
| 19 } | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 WindowElement::WindowElement(aura::Window* window, | |
| 24 UIElementDelegate* ui_element_delegate, | |
| 25 UIElement* parent) | |
| 26 : UIElement(UIElementType::WINDOW, ui_element_delegate, parent), | |
| 27 window_(window) { | |
| 28 if (window) | |
| 29 window_->AddObserver(this); | |
| 30 } | |
| 31 | |
| 32 WindowElement::~WindowElement() { | |
| 33 if (window_) | |
| 34 window_->RemoveObserver(this); | |
| 35 } | |
| 36 | |
| 37 // Handles removing window_. | |
| 38 void WindowElement::OnWindowHierarchyChanging( | |
| 39 const aura::WindowObserver::HierarchyChangeParams& params) { | |
| 40 if (params.target == window_ && this->parent()->RemoveChild(this)) | |
| 41 Destroy(); | |
| 42 } | |
| 43 | |
| 44 // Handles adding window_. | |
| 45 void WindowElement::OnWindowHierarchyChanged( | |
| 46 const aura::WindowObserver::HierarchyChangeParams& params) { | |
| 47 if (window_ == params.new_parent && params.receiver == params.new_parent) { | |
| 48 AddChild(new WindowElement(params.target, delegate(), this), | |
|
sadrul
2017/05/10 03:03:38
Can you check if |params.target| is the highlight
thanhph
2017/05/10 17:21:49
Nice. I'm also able to turn bool UIElement::Remove
| |
| 49 children().empty() ? nullptr : children().back()); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void WindowElement::OnWindowStackingChanged(aura::Window* window) { | |
| 54 DCHECK_EQ(window_, window); | |
| 55 if (delegate()->IsHighlightingWindow(window)) | |
| 56 return; | |
| 57 this->parent()->ReorderChild(this, GetIndexOfChildInParent(window)); | |
|
sadrul
2017/05/10 03:03:38
Don't need this->
thanhph
2017/05/10 17:21:49
Done.
| |
| 58 } | |
| 59 | |
| 60 void WindowElement::OnWindowBoundsChanged(aura::Window* window, | |
| 61 const gfx::Rect& old_bounds, | |
| 62 const gfx::Rect& new_bounds) { | |
| 63 DCHECK_EQ(window_, window); | |
| 64 delegate()->OnUIElementBoundsChanged(this); | |
| 65 } | |
| 66 | |
| 67 void WindowElement::Destroy() { | |
| 68 delete this; | |
| 69 } | |
| 70 | |
| 71 void WindowElement::GetBounds(gfx::Rect* bounds) const { | |
| 72 *bounds = window_->bounds(); | |
| 73 } | |
| 74 | |
| 75 void WindowElement::SetBounds(const gfx::Rect& bounds) { | |
| 76 window_->SetBounds(bounds); | |
| 77 } | |
| 78 | |
| 79 void WindowElement::GetVisible(bool* visible) const { | |
| 80 *visible = window_->IsVisible(); | |
| 81 } | |
| 82 | |
| 83 void WindowElement::SetVisible(bool visible) { | |
| 84 if (visible == window_->IsVisible()) | |
| 85 return; | |
| 86 if (visible) | |
| 87 window_->Show(); | |
| 88 else | |
| 89 window_->Hide(); | |
| 90 } | |
| 91 | |
| 92 std::pair<aura::Window*, gfx::Rect> WindowElement::GetNodeWindowAndBounds() | |
| 93 const { | |
| 94 return std::make_pair(window_, window_->GetBoundsInScreen()); | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 aura::Window* WindowElement::From(UIElement* element) { | |
| 99 DCHECK_EQ(UIElementType::WINDOW, element->type()); | |
| 100 return static_cast<WindowElement*>(element)->window_; | |
| 101 } | |
| 102 | |
| 103 } // namespace devtools | |
| 104 } // namespace ash | |
| OLD | NEW |