Index: ash/common/shelf/shelf_window_watcher_item_delegate.cc |
diff --git a/ash/common/shelf/shelf_window_watcher_item_delegate.cc b/ash/common/shelf/shelf_window_watcher_item_delegate.cc |
index a1450e171d42059cb1f0af117e2f9180ea446c36..3a18d68a98922cda7d01e54519843713dffa5ae0 100644 |
--- a/ash/common/shelf/shelf_window_watcher_item_delegate.cc |
+++ b/ash/common/shelf/shelf_window_watcher_item_delegate.cc |
@@ -4,18 +4,61 @@ |
#include "ash/common/shelf/shelf_window_watcher_item_delegate.h" |
+#include "ash/common/shelf/shelf_controller.h" |
+#include "ash/common/shelf/shelf_model.h" |
+#include "ash/common/wm/window_state.h" |
+#include "ash/common/wm_lookup.h" |
+#include "ash/common/wm_shell.h" |
#include "ash/common/wm_window.h" |
#include "ui/events/event.h" |
+#include "ui/views/view.h" |
+#include "ui/views/widget/widget.h" |
namespace ash { |
-ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(WmWindow* window) |
- : window_(window) {} |
+namespace { |
+ |
+ShelfItemType GetShelfItemType(ShelfID id) { |
+ ShelfModel* model = WmShell::Get()->shelf_controller()->model(); |
+ ShelfItems::const_iterator item = model->ItemByID(id); |
+ return item == model->items().end() ? TYPE_UNDEFINED : item->type; |
+} |
+ |
+// Moves |window| to the display where |event| occurred; returns true if moved. |
+// Note: This was forked from ash/wm/window_util.h's wm::MoveWindowToEventRoot. |
+// TODO(msw): Reduce function copies once aura-as-a-mus-client is resolved. |
+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).
|
+ views::View* target = static_cast<views::View*>(event.target()); |
+ if (!target) |
+ return false; |
+ WmWindow* target_root = |
+ WmLookup::Get()->GetWindowForWidget(target->GetWidget())->GetRootWindow(); |
+ if (!target_root || target_root == window->GetRootWindow()) |
+ return false; |
+ WmWindow* window_container = target_root->GetChildByShellWindowId( |
+ window->GetParent()->GetShellWindowId()); |
+ window_container->AddChild(window); |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(ShelfID id, |
+ WmWindow* window) |
+ : id_(id), window_(window) {} |
ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} |
ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( |
const ui::Event& event) { |
+ // Move panels attached on another display to the current display. |
+ if (GetShelfItemType(id_) == TYPE_APP_PANEL && |
+ window_->GetWindowState()->panel_attached() && |
+ MoveWindowToEventRoot(window_, event)) { |
+ window_->Activate(); |
+ return kExistingWindowActivated; |
+ } |
+ |
if (window_->IsActive()) { |
if (event.type() & ui::ET_KEY_RELEASED) { |
window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
@@ -42,10 +85,16 @@ bool ShelfWindowWatcherItemDelegate::IsDraggable() { |
} |
bool ShelfWindowWatcherItemDelegate::CanPin() const { |
- return true; |
+ return GetShelfItemType(id_) != TYPE_APP_PANEL; |
} |
bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { |
+ // Do not show tooltips for visible attached app panel windows. |
+ return GetShelfItemType(id_) != TYPE_APP_PANEL || !window_->IsVisible() || |
+ !window_->GetWindowState()->panel_attached(); |
+} |
+ |
+bool ShelfWindowWatcherItemDelegate::IsOpen() const { |
return true; |
} |