| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/test/test_shelf_item_delegate.h" | 5 #include "ash/common/test/test_shelf_item_delegate.h" |
| 6 | 6 |
| 7 #include "ash/common/wm_lookup.h" | |
| 8 #include "ash/common/wm_window.h" | 7 #include "ash/common/wm_window.h" |
| 9 #include "ui/events/event.h" | |
| 10 #include "ui/views/view.h" | |
| 11 #include "ui/views/widget/widget.h" | |
| 12 | 8 |
| 13 namespace ash { | 9 namespace ash { |
| 14 namespace test { | 10 namespace test { |
| 15 | 11 |
| 16 namespace { | |
| 17 | |
| 18 // Moves |window| to the root window where the |event| occurred. | |
| 19 // Note: This was forked from ash/wm/window_util.h's wm::MoveWindowToEventRoot. | |
| 20 void MoveWindowToEventRoot(WmWindow* window, const ui::Event& event) { | |
| 21 views::View* target = static_cast<views::View*>(event.target()); | |
| 22 if (!target) | |
| 23 return; | |
| 24 WmWindow* target_root = | |
| 25 WmLookup::Get()->GetWindowForWidget(target->GetWidget())->GetRootWindow(); | |
| 26 if (!target_root || target_root == window->GetRootWindow()) | |
| 27 return; | |
| 28 WmWindow* window_container = target_root->GetChildByShellWindowId( | |
| 29 window->GetParent()->GetShellWindowId()); | |
| 30 window_container->AddChild(window); | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 TestShelfItemDelegate::TestShelfItemDelegate(WmWindow* window) | 12 TestShelfItemDelegate::TestShelfItemDelegate(WmWindow* window) |
| 36 : window_(window), is_draggable_(true) {} | 13 : window_(window), is_draggable_(true) {} |
| 37 | 14 |
| 38 TestShelfItemDelegate::~TestShelfItemDelegate() {} | 15 TestShelfItemDelegate::~TestShelfItemDelegate() {} |
| 39 | 16 |
| 40 ShelfItemDelegate::PerformedAction TestShelfItemDelegate::ItemSelected( | 17 ShelfItemDelegate::PerformedAction TestShelfItemDelegate::ItemSelected( |
| 41 const ui::Event& event) { | 18 const ui::Event& event) { |
| 42 if (window_) { | 19 if (window_) { |
| 43 if (window_->GetType() == ui::wm::WINDOW_TYPE_PANEL) | 20 if (window_->GetType() == ui::wm::WINDOW_TYPE_PANEL) |
| 44 MoveWindowToEventRoot(window_, event); | 21 window_->MoveToEventRoot(event); |
| 45 window_->Show(); | 22 window_->Show(); |
| 46 window_->Activate(); | 23 window_->Activate(); |
| 47 return kExistingWindowActivated; | 24 return kExistingWindowActivated; |
| 48 } | 25 } |
| 49 return kNoAction; | 26 return kNoAction; |
| 50 } | 27 } |
| 51 | 28 |
| 52 base::string16 TestShelfItemDelegate::GetTitle() { | 29 base::string16 TestShelfItemDelegate::GetTitle() { |
| 53 return window_ ? window_->GetTitle() : base::string16(); | 30 return window_ ? window_->GetTitle() : base::string16(); |
| 54 } | 31 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 } | 43 } |
| 67 | 44 |
| 68 bool TestShelfItemDelegate::ShouldShowTooltip() { | 45 bool TestShelfItemDelegate::ShouldShowTooltip() { |
| 69 return true; | 46 return true; |
| 70 } | 47 } |
| 71 | 48 |
| 72 void TestShelfItemDelegate::Close() {} | 49 void TestShelfItemDelegate::Close() {} |
| 73 | 50 |
| 74 } // namespace test | 51 } // namespace test |
| 75 } // namespace ash | 52 } // namespace ash |
| OLD | NEW |