Chromium Code Reviews| 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/shelf/shelf_window_watcher_item_delegate.h" | 5 #include "ash/common/shelf/shelf_window_watcher_item_delegate.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_controller.h" | |
| 8 #include "ash/common/shelf/shelf_model.h" | |
| 9 #include "ash/common/wm/window_state.h" | |
| 10 #include "ash/common/wm_lookup.h" | |
| 11 #include "ash/common/wm_shell.h" | |
| 7 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
| 8 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/views/view.h" | |
| 15 #include "ui/views/widget/widget.h" | |
| 9 | 16 |
| 10 namespace ash { | 17 namespace ash { |
| 11 | 18 |
| 12 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(WmWindow* window) | 19 namespace { |
| 13 : window_(window) {} | 20 |
| 21 ShelfItemType GetShelfItemType(ShelfID id) { | |
| 22 ShelfModel* model = WmShell::Get()->shelf_controller()->model(); | |
| 23 ShelfItems::const_iterator item = model->ItemByID(id); | |
| 24 return item == model->items().end() ? TYPE_UNDEFINED : item->type; | |
| 25 } | |
| 26 | |
| 27 // Moves |window| to the display where |event| occurred; returns true if moved. | |
| 28 // Note: This was forked from ash/wm/window_util.h's wm::MoveWindowToEventRoot. | |
| 29 // TODO(msw): Reduce function copies once aura-as-a-mus-client is resolved. | |
| 30 bool MoveWindowToEventRoot(WmWindow* window, const ui::Event& event) { | |
|
James Cook
2016/11/02 17:53:44
I think there's another copy of this in TestShelfI
msw
2016/11/10 21:07:46
Done (moved to WmWindow in a prior CL).
| |
| 31 views::View* target = static_cast<views::View*>(event.target()); | |
| 32 if (!target) | |
| 33 return false; | |
| 34 WmWindow* target_root = | |
| 35 WmLookup::Get()->GetWindowForWidget(target->GetWidget())->GetRootWindow(); | |
| 36 if (!target_root || target_root == window->GetRootWindow()) | |
| 37 return false; | |
| 38 WmWindow* window_container = target_root->GetChildByShellWindowId( | |
| 39 window->GetParent()->GetShellWindowId()); | |
| 40 window_container->AddChild(window); | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(ShelfID id, | |
| 47 WmWindow* window) | |
| 48 : id_(id), window_(window) {} | |
| 14 | 49 |
| 15 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} | 50 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} |
| 16 | 51 |
| 17 ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( | 52 ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( |
| 18 const ui::Event& event) { | 53 const ui::Event& event) { |
| 54 // Move panels attached on another display to the current display. | |
| 55 if (GetShelfItemType(id_) == TYPE_APP_PANEL && | |
| 56 window_->GetWindowState()->panel_attached() && | |
| 57 MoveWindowToEventRoot(window_, event)) { | |
| 58 window_->Activate(); | |
| 59 return kExistingWindowActivated; | |
| 60 } | |
| 61 | |
| 19 if (window_->IsActive()) { | 62 if (window_->IsActive()) { |
| 20 if (event.type() & ui::ET_KEY_RELEASED) { | 63 if (event.type() & ui::ET_KEY_RELEASED) { |
| 21 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 64 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 22 return kNoAction; | 65 return kNoAction; |
| 23 } | 66 } |
| 24 window_->Minimize(); | 67 window_->Minimize(); |
| 25 return kExistingWindowMinimized; | 68 return kExistingWindowMinimized; |
| 26 } | 69 } |
| 27 window_->Activate(); | 70 window_->Activate(); |
| 28 return kExistingWindowActivated; | 71 return kExistingWindowActivated; |
| 29 } | 72 } |
| 30 | 73 |
| 31 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { | 74 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { |
| 32 return window_->GetTitle(); | 75 return window_->GetTitle(); |
| 33 } | 76 } |
| 34 | 77 |
| 35 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( | 78 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( |
| 36 int event_flags) { | 79 int event_flags) { |
| 37 return nullptr; | 80 return nullptr; |
| 38 } | 81 } |
| 39 | 82 |
| 40 bool ShelfWindowWatcherItemDelegate::IsDraggable() { | 83 bool ShelfWindowWatcherItemDelegate::IsDraggable() { |
| 41 return true; | 84 return true; |
| 42 } | 85 } |
| 43 | 86 |
| 44 bool ShelfWindowWatcherItemDelegate::CanPin() const { | 87 bool ShelfWindowWatcherItemDelegate::CanPin() const { |
| 88 return GetShelfItemType(id_) != TYPE_APP_PANEL; | |
| 89 } | |
| 90 | |
| 91 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { | |
| 92 // Do not show tooltips for visible attached app panel windows. | |
| 93 return GetShelfItemType(id_) != TYPE_APP_PANEL || !window_->IsVisible() || | |
| 94 !window_->GetWindowState()->panel_attached(); | |
| 95 } | |
| 96 | |
| 97 bool ShelfWindowWatcherItemDelegate::IsOpen() const { | |
| 45 return true; | 98 return true; |
| 46 } | 99 } |
| 47 | 100 |
| 48 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 void ShelfWindowWatcherItemDelegate::Close() { | 101 void ShelfWindowWatcherItemDelegate::Close() { |
| 53 window_->CloseWidget(); | 102 window_->CloseWidget(); |
| 54 } | 103 } |
| 55 | 104 |
| 56 } // namespace ash | 105 } // namespace ash |
| OLD | NEW |