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.h" | 5 #include "ash/common/shelf/shelf.h" |
6 | 6 |
7 #include "ash/common/shelf/shelf_delegate.h" | 7 #include "ash/common/shelf/shelf_delegate.h" |
8 #include "ash/common/shelf/shelf_item_delegate.h" | |
9 #include "ash/common/shelf/shelf_model.h" | |
10 #include "ash/common/shelf/shelf_navigator.h" | |
11 #include "ash/common/shelf/shelf_view.h" | 8 #include "ash/common/shelf/shelf_view.h" |
12 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
13 #include "ash/common/wm_lookup.h" | |
14 #include "ash/common/wm_root_window_controller.h" | 10 #include "ash/common/wm_root_window_controller.h" |
15 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
16 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
17 #include "ash/common/wm_window_property.h" | |
18 #include "ui/gfx/geometry/point.h" | |
19 #include "ui/gfx/geometry/rect.h" | |
20 | 13 |
21 namespace ash { | 14 namespace ash { |
22 | 15 |
23 Shelf::Shelf(WmShelf* wm_shelf, | 16 Shelf::Shelf(WmShelf* wm_shelf, |
24 ShelfView* shelf_view, | 17 ShelfView* shelf_view, |
25 ShelfWidget* shelf_widget) | 18 ShelfWidget* shelf_widget) |
26 : wm_shelf_(wm_shelf), | 19 : wm_shelf_(wm_shelf), |
27 shelf_widget_(shelf_widget), | 20 shelf_widget_(shelf_widget), |
28 shelf_view_(shelf_view) { | 21 shelf_view_(shelf_view) { |
29 DCHECK(wm_shelf_); | 22 DCHECK(wm_shelf_); |
30 DCHECK(shelf_view_); | 23 DCHECK(shelf_view_); |
31 DCHECK(shelf_widget_); | 24 DCHECK(shelf_widget_); |
32 } | 25 } |
33 | 26 |
34 Shelf::~Shelf() { | 27 Shelf::~Shelf() { |
35 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(wm_shelf_); | 28 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(wm_shelf_); |
36 } | 29 } |
37 | 30 |
38 // static | 31 // static |
39 Shelf* Shelf::ForPrimaryDisplay() { | 32 Shelf* Shelf::ForPrimaryDisplay() { |
40 return Shelf::ForWindow(WmShell::Get()->GetPrimaryRootWindow()); | 33 return Shelf::ForWindow(WmShell::Get()->GetPrimaryRootWindow()); |
41 } | 34 } |
42 | 35 |
43 // static | 36 // static |
44 Shelf* Shelf::ForWindow(WmWindow* window) { | 37 Shelf* Shelf::ForWindow(WmWindow* window) { |
45 return window->GetRootWindowController()->GetShelf()->shelf(); | 38 return window->GetRootWindowController()->GetShelf()->shelf(); |
46 } | 39 } |
47 | 40 |
48 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | |
49 ShelfID id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | |
50 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); | |
51 gfx::Point screen_origin; | |
52 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); | |
53 return gfx::Rect(screen_origin.x() + bounds.x(), | |
54 screen_origin.y() + bounds.y(), bounds.width(), | |
55 bounds.height()); | |
56 } | |
57 | |
58 void Shelf::UpdateIconPositionForWindow(WmWindow* window) { | |
59 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); | |
60 shelf_view_->UpdatePanelIconPosition( | |
61 window->GetIntProperty(WmWindowProperty::SHELF_ID), | |
62 shelf_window->ConvertRectFromScreen(window->GetBoundsInScreen()) | |
63 .CenterPoint()); | |
64 } | |
65 | |
66 void Shelf::ActivateShelfItem(int index) { | |
67 // We pass in a keyboard event which will then trigger a switch to the | |
68 // next item if the current one is already active. | |
69 ui::KeyEvent event(ui::ET_KEY_RELEASED, | |
70 ui::VKEY_UNKNOWN, // The actual key gets ignored. | |
71 ui::EF_NONE); | |
72 | |
73 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | |
74 const ShelfItem& item = shelf_model->items()[index]; | |
75 ShelfItemDelegate* item_delegate = shelf_model->GetShelfItemDelegate(item.id); | |
76 item_delegate->ItemSelected(event); | |
77 } | |
78 | |
79 void Shelf::CycleWindowLinear(CycleDirection direction) { | |
80 int item_index = | |
81 GetNextActivatedItemIndex(*WmShell::Get()->shelf_model(), direction); | |
82 if (item_index >= 0) | |
83 ActivateShelfItem(item_index); | |
84 } | |
85 | |
86 AppListButton* Shelf::GetAppListButton() const { | 41 AppListButton* Shelf::GetAppListButton() const { |
87 return shelf_view_->GetAppListButton(); | 42 return shelf_view_->GetAppListButton(); |
88 } | 43 } |
89 | 44 |
90 void Shelf::LaunchAppIndexAt(int item_index) { | |
91 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | |
92 const ShelfItems& items = shelf_model->items(); | |
93 int item_count = shelf_model->item_count(); | |
94 int indexes_left = item_index >= 0 ? item_index : item_count; | |
95 int found_index = -1; | |
96 | |
97 // Iterating until we have hit the index we are interested in which | |
98 // is true once indexes_left becomes negative. | |
99 for (int i = 0; i < item_count && indexes_left >= 0; i++) { | |
100 if (items[i].type != TYPE_APP_LIST) { | |
101 found_index = i; | |
102 indexes_left--; | |
103 } | |
104 } | |
105 | |
106 // There are two ways how found_index can be valid: a.) the nth item was | |
107 // found (which is true when indexes_left is -1) or b.) the last item was | |
108 // requested (which is true when index was passed in as a negative number). | |
109 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { | |
110 // Then set this one as active (or advance to the next item of its kind). | |
111 ActivateShelfItem(found_index); | |
112 } | |
113 } | |
114 | |
115 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const { | |
116 return shelf_view_->GetVisibleItemsBoundsInScreen(); | |
117 } | |
118 | |
119 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { | 45 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { |
120 return shelf_view_; | 46 return shelf_view_; |
121 } | 47 } |
122 | 48 |
123 void Shelf::UpdateShelfItemBackground(int alpha) { | |
124 shelf_view_->UpdateShelfItemBackground(alpha); | |
125 } | |
126 | |
127 } // namespace ash | 49 } // namespace ash |
OLD | NEW |