| 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/shelf/shelf_window_watcher_item_delegate.h" | 5 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/public/cpp/window_properties.h" | 9 #include "ash/public/cpp/window_properties.h" |
| 10 #include "ash/shelf/shelf_controller.h" | 10 #include "ash/shelf/shelf_controller.h" |
| 11 #include "ash/shelf/shelf_model.h" | 11 #include "ash/shelf/shelf_model.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm_window.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
| 18 #include "ui/wm/core/window_animations.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 ShelfItemType GetShelfItemType(const ShelfID& id) { | 24 ShelfItemType GetShelfItemType(const ShelfID& id) { |
| 24 ShelfModel* model = Shell::Get()->shelf_controller()->model(); | 25 ShelfModel* model = Shell::Get()->shelf_controller()->model(); |
| 25 ShelfItems::const_iterator item = model->ItemByID(id); | 26 ShelfItems::const_iterator item = model->ItemByID(id); |
| 26 return item == model->items().end() ? TYPE_UNDEFINED : item->type; | 27 return item == model->items().end() ? TYPE_UNDEFINED : item->type; |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate( | 32 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate( |
| 32 const ShelfID& id, | 33 const ShelfID& id, |
| 33 WmWindow* window) | 34 aura::Window* window) |
| 34 : ShelfItemDelegate(id), window_(window) { | 35 : ShelfItemDelegate(id), window_(window) { |
| 35 DCHECK(!id.IsNull()); | 36 DCHECK(!id.IsNull()); |
| 36 DCHECK(window_); | 37 DCHECK(window_); |
| 37 } | 38 } |
| 38 | 39 |
| 39 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} | 40 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} |
| 40 | 41 |
| 41 void ShelfWindowWatcherItemDelegate::ItemSelected( | 42 void ShelfWindowWatcherItemDelegate::ItemSelected( |
| 42 std::unique_ptr<ui::Event> event, | 43 std::unique_ptr<ui::Event> event, |
| 43 int64_t display_id, | 44 int64_t display_id, |
| 44 ShelfLaunchSource source, | 45 ShelfLaunchSource source, |
| 45 ItemSelectedCallback callback) { | 46 ItemSelectedCallback callback) { |
| 46 // Move panels attached on another display to the current display. | 47 // Move panels attached on another display to the current display. |
| 47 if (GetShelfItemType(shelf_id()) == TYPE_APP_PANEL && | 48 if (GetShelfItemType(shelf_id()) == TYPE_APP_PANEL && |
| 48 window_->aura_window()->GetProperty(kPanelAttachedKey) && | 49 window_->GetProperty(kPanelAttachedKey) && |
| 49 wm::MoveWindowToDisplay(window_->aura_window(), display_id)) { | 50 wm::MoveWindowToDisplay(window_, display_id)) { |
| 50 window_->Activate(); | 51 wm::ActivateWindow(window_); |
| 51 std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); | 52 std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); |
| 52 return; | 53 return; |
| 53 } | 54 } |
| 54 | 55 |
| 55 if (window_->IsActive()) { | 56 if (wm::IsActiveWindow(window_)) { |
| 56 if (event && event->type() == ui::ET_KEY_RELEASED) { | 57 if (event && event->type() == ui::ET_KEY_RELEASED) { |
| 57 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 58 ::wm::AnimateWindow(window_, ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 58 std::move(callback).Run(SHELF_ACTION_NONE, base::nullopt); | 59 std::move(callback).Run(SHELF_ACTION_NONE, base::nullopt); |
| 59 return; | 60 return; |
| 60 } | 61 } |
| 61 window_->Minimize(); | 62 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 62 std::move(callback).Run(SHELF_ACTION_WINDOW_MINIMIZED, base::nullopt); | 63 std::move(callback).Run(SHELF_ACTION_WINDOW_MINIMIZED, base::nullopt); |
| 63 return; | 64 return; |
| 64 } | 65 } |
| 65 window_->Activate(); | 66 wm::ActivateWindow(window_); |
| 66 std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); | 67 std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ShelfWindowWatcherItemDelegate::ExecuteCommand(uint32_t command_id, | 70 void ShelfWindowWatcherItemDelegate::ExecuteCommand(uint32_t command_id, |
| 70 int32_t event_flags) {} | 71 int32_t event_flags) {} |
| 71 | 72 |
| 72 void ShelfWindowWatcherItemDelegate::Close() { | 73 void ShelfWindowWatcherItemDelegate::Close() { |
| 73 window_->CloseWidget(); | 74 wm::CloseWidgetForWindow(window_); |
| 74 } | 75 } |
| 75 | 76 |
| 76 } // namespace ash | 77 } // namespace ash |
| OLD | NEW |