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) {} | |
James Cook
2016/11/10 22:32:46
DCHECK that id is valid and window isn't null
msw
2016/11/10 23:30:52
Done.
| |
14 | 29 |
15 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} | 30 ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {} |
16 | 31 |
17 ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( | 32 ShelfItemDelegate::PerformedAction ShelfWindowWatcherItemDelegate::ItemSelected( |
18 const ui::Event& event) { | 33 const ui::Event& event) { |
34 // Move panels attached on another display to the current display. | |
35 if (GetShelfItemType(id_) == TYPE_APP_PANEL && | |
36 window_->GetWindowState()->panel_attached() && | |
37 window_->MoveToEventRoot(event)) { | |
38 window_->Activate(); | |
39 return kExistingWindowActivated; | |
40 } | |
41 | |
19 if (window_->IsActive()) { | 42 if (window_->IsActive()) { |
20 if (event.type() & ui::ET_KEY_RELEASED) { | 43 if (event.type() & ui::ET_KEY_RELEASED) { |
21 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 44 window_->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
22 return kNoAction; | 45 return kNoAction; |
23 } | 46 } |
24 window_->Minimize(); | 47 window_->Minimize(); |
25 return kExistingWindowMinimized; | 48 return kExistingWindowMinimized; |
26 } | 49 } |
27 window_->Activate(); | 50 window_->Activate(); |
28 return kExistingWindowActivated; | 51 return kExistingWindowActivated; |
29 } | 52 } |
30 | 53 |
31 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { | 54 base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { |
32 return window_->GetTitle(); | 55 return window_->GetTitle(); |
33 } | 56 } |
34 | 57 |
35 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( | 58 ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( |
36 int event_flags) { | 59 int event_flags) { |
37 return nullptr; | 60 return nullptr; |
38 } | 61 } |
39 | 62 |
40 bool ShelfWindowWatcherItemDelegate::IsDraggable() { | 63 bool ShelfWindowWatcherItemDelegate::IsDraggable() { |
41 return true; | 64 return true; |
42 } | 65 } |
43 | 66 |
44 bool ShelfWindowWatcherItemDelegate::CanPin() const { | 67 bool ShelfWindowWatcherItemDelegate::CanPin() const { |
45 return true; | 68 return GetShelfItemType(id_) != TYPE_APP_PANEL; |
46 } | 69 } |
47 | 70 |
48 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { | 71 bool ShelfWindowWatcherItemDelegate::ShouldShowTooltip() { |
49 return true; | 72 // Do not show tooltips for visible attached app panel windows. |
73 return GetShelfItemType(id_) != TYPE_APP_PANEL || !window_->IsVisible() || | |
74 !window_->GetWindowState()->panel_attached(); | |
50 } | 75 } |
51 | 76 |
52 void ShelfWindowWatcherItemDelegate::Close() { | 77 void ShelfWindowWatcherItemDelegate::Close() { |
53 window_->CloseWidget(); | 78 window_->CloseWidget(); |
54 } | 79 } |
55 | 80 |
56 } // namespace ash | 81 } // namespace ash |
OLD | NEW |