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_shell.h" |
7 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
8 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
9 | 13 |
10 namespace ash { | 14 namespace ash { |
11 | 15 |
12 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(WmWindow* window) | 16 namespace { |
13 : window_(window) {} | 17 |
| 18 ShelfItemType GetShelfItemType(ShelfID id) { |
| 19 ShelfModel* model = WmShell::Get()->shelf_controller()->model(); |
| 20 ShelfItems::const_iterator item = model->ItemByID(id); |
| 21 return item == model->items().end() ? TYPE_UNDEFINED : item->type; |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(ShelfID id, |
| 27 WmWindow* window) |
| 28 : id_(id), window_(window) { |
| 29 DCHECK_NE(kInvalidShelfID, id_); |
| 30 DCHECK(window_); |
| 31 } |
14 | 32 |
15 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} | 33 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} |
16 | 34 |
17 ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( | 35 ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( |
18 const ui::Event& event) { | 36 const ui::Event& event) { |
| 37 // Move panels attached on another display to the current display. |
| 38 if (GetShelfItemType(id_) == TYPE_APP_PANEL && |
| 39 window_->GetWindowState()->panel_attached() && |
| 40 window_->MoveToEventRoot(event)) { |
| 41 window_->Activate(); |
| 42 return kExistingWindowActivated; |
| 43 } |
| 44 |
19 if (window_->IsActive()) { | 45 if (window_->IsActive()) { |
20 if (event.type() & ui::ET_KEY_RELEASED) { | 46 if (event.type() & ui::ET_KEY_RELEASED) { |
21 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 47 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
22 return kNoAction; | 48 return kNoAction; |
23 } | 49 } |
24 window_->Minimize(); | 50 window_->Minimize(); |
25 return kExistingWindowMinimized; | 51 return kExistingWindowMinimized; |
26 } | 52 } |
27 window_->Activate(); | 53 window_->Activate(); |
28 return kExistingWindowActivated; | 54 return kExistingWindowActivated; |
29 } | 55 } |
30 | 56 |
31 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { | 57 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { |
32 return window_->GetTitle(); | 58 return window_->GetTitle(); |
33 } | 59 } |
34 | 60 |
35 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( | 61 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( |
36 int event_flags) { | 62 int event_flags) { |
37 return nullptr; | 63 return nullptr; |
38 } | 64 } |
39 | 65 |
40 bool ShelfWindowWatcherItemDelegate::IsDraggable() { | 66 bool ShelfWindowWatcherItemDelegate::IsDraggable() { |
41 return true; | 67 return true; |
42 } | 68 } |
43 | 69 |
44 bool ShelfWindowWatcherItemDelegate::CanPin() const { | 70 bool ShelfWindowWatcherItemDelegate::CanPin() const { |
45 return true; | 71 return GetShelfItemType(id_) != TYPE_APP_PANEL; |
46 } | 72 } |
47 | 73 |
48 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { | 74 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { |
49 return true; | 75 // Do not show tooltips for visible attached app panel windows. |
| 76 return GetShelfItemType(id_) != TYPE_APP_PANEL || !window_->IsVisible() || |
| 77 !window_->GetWindowState()->panel_attached(); |
50 } | 78 } |
51 | 79 |
52 void ShelfWindowWatcherItemDelegate::Close() { | 80 void ShelfWindowWatcherItemDelegate::Close() { |
53 window_->CloseWidget(); | 81 window_->CloseWidget(); |
54 } | 82 } |
55 | 83 |
56 } // namespace ash | 84 } // namespace ash |
OLD | NEW |