| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher.h" | 5 #include "ash/shelf/shelf.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "ash/focus_cycler.h" | 10 #include "ash/focus_cycler.h" |
| 11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
| 13 #include "ash/shelf/shelf_delegate.h" | 13 #include "ash/shelf/shelf_delegate.h" |
| 14 #include "ash/shelf/shelf_item_delegate.h" | 14 #include "ash/shelf/shelf_item_delegate.h" |
| 15 #include "ash/shelf/shelf_item_delegate_manager.h" | 15 #include "ash/shelf/shelf_item_delegate_manager.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 33 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
| 34 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
| 35 #include "ui/gfx/image/image_skia_operations.h" | 35 #include "ui/gfx/image/image_skia_operations.h" |
| 36 #include "ui/gfx/skbitmap_operations.h" | 36 #include "ui/gfx/skbitmap_operations.h" |
| 37 #include "ui/views/accessible_pane_view.h" | 37 #include "ui/views/accessible_pane_view.h" |
| 38 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 39 #include "ui/views/widget/widget_delegate.h" | 39 #include "ui/views/widget/widget_delegate.h" |
| 40 | 40 |
| 41 namespace ash { | 41 namespace ash { |
| 42 | 42 |
| 43 const char Launcher::kNativeViewName[] = "ShelfView"; | 43 const char Shelf::kNativeViewName[] = "ShelfView"; |
| 44 | 44 |
| 45 Launcher::Launcher(ShelfModel* shelf_model, | 45 Shelf::Shelf(ShelfModel* shelf_model, |
| 46 ShelfDelegate* shelf_delegate, | 46 ShelfDelegate* shelf_delegate, |
| 47 ShelfWidget* shelf_widget) | 47 ShelfWidget* shelf_widget) |
| 48 : shelf_view_(NULL), | 48 : shelf_view_(NULL), |
| 49 alignment_(shelf_widget->GetAlignment()), | 49 alignment_(shelf_widget->GetAlignment()), |
| 50 delegate_(shelf_delegate), | 50 delegate_(shelf_delegate), |
| 51 shelf_widget_(shelf_widget) { | 51 shelf_widget_(shelf_widget) { |
| 52 shelf_view_ = new internal::ShelfView( | 52 shelf_view_ = new internal::ShelfView( |
| 53 shelf_model, delegate_, shelf_widget_->shelf_layout_manager()); | 53 shelf_model, delegate_, shelf_widget_->shelf_layout_manager()); |
| 54 shelf_view_->Init(); | 54 shelf_view_->Init(); |
| 55 shelf_widget_->GetContentsView()->AddChildView(shelf_view_); | 55 shelf_widget_->GetContentsView()->AddChildView(shelf_view_); |
| 56 shelf_widget_->GetNativeView()->SetName(kNativeViewName); | 56 shelf_widget_->GetNativeView()->SetName(kNativeViewName); |
| 57 delegate_->OnLauncherCreated(this); | 57 delegate_->OnShelfCreated(this); |
| 58 } | 58 } |
| 59 | 59 |
| 60 Launcher::~Launcher() { | 60 Shelf::~Shelf() { |
| 61 delegate_->OnLauncherDestroyed(this); | 61 delegate_->OnShelfDestroyed(this); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // static | 64 // static |
| 65 Launcher* Launcher::ForPrimaryDisplay() { | 65 Shelf* Shelf::ForPrimaryDisplay() { |
| 66 ShelfWidget* shelf_widget = internal::RootWindowController::ForLauncher( | 66 ShelfWidget* shelf_widget = internal::RootWindowController::ForShelf( |
| 67 Shell::GetPrimaryRootWindow())->shelf(); | 67 Shell::GetPrimaryRootWindow())->shelf(); |
| 68 return shelf_widget ? shelf_widget->launcher() : NULL; | 68 return shelf_widget ? shelf_widget->shelf() : NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // static | 71 // static |
| 72 Launcher* Launcher::ForWindow(aura::Window* window) { | 72 Shelf* Shelf::ForWindow(aura::Window* window) { |
| 73 ShelfWidget* shelf_widget = | 73 ShelfWidget* shelf_widget = |
| 74 internal::RootWindowController::ForLauncher(window)->shelf(); | 74 internal::RootWindowController::ForShelf(window)->shelf(); |
| 75 return shelf_widget ? shelf_widget->launcher() : NULL; | 75 return shelf_widget ? shelf_widget->shelf() : NULL; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void Launcher::SetAlignment(ShelfAlignment alignment) { | 78 void Shelf::SetAlignment(ShelfAlignment alignment) { |
| 79 alignment_ = alignment; | 79 alignment_ = alignment; |
| 80 shelf_view_->OnShelfAlignmentChanged(); | 80 shelf_view_->OnShelfAlignmentChanged(); |
| 81 // ShelfLayoutManager will resize the launcher. | 81 // ShelfLayoutManager will resize the shelf. |
| 82 } | 82 } |
| 83 | 83 |
| 84 gfx::Rect Launcher::GetScreenBoundsOfItemIconForWindow(aura::Window* window) { | 84 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(aura::Window* window) { |
| 85 LauncherID id = GetLauncherIDForWindow(window); | 85 LauncherID id = GetLauncherIDForWindow(window); |
| 86 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); | 86 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); |
| 87 gfx::Point screen_origin; | 87 gfx::Point screen_origin; |
| 88 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); | 88 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); |
| 89 return gfx::Rect(screen_origin.x() + bounds.x(), | 89 return gfx::Rect(screen_origin.x() + bounds.x(), |
| 90 screen_origin.y() + bounds.y(), | 90 screen_origin.y() + bounds.y(), |
| 91 bounds.width(), | 91 bounds.width(), |
| 92 bounds.height()); | 92 bounds.height()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void Launcher::UpdateIconPositionForWindow(aura::Window* window) { | 95 void Shelf::UpdateIconPositionForWindow(aura::Window* window) { |
| 96 shelf_view_->UpdatePanelIconPosition( | 96 shelf_view_->UpdatePanelIconPosition( |
| 97 GetLauncherIDForWindow(window), | 97 GetLauncherIDForWindow(window), |
| 98 ash::ScreenAsh::ConvertRectFromScreen( | 98 ScreenAsh::ConvertRectFromScreen( |
| 99 shelf_widget()->GetNativeView(), | 99 shelf_widget()->GetNativeView(), |
| 100 window->GetBoundsInScreen()).CenterPoint()); | 100 window->GetBoundsInScreen()).CenterPoint()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void Launcher::ActivateLauncherItem(int index) { | 103 void Shelf::ActivateShelfItem(int index) { |
| 104 // We pass in a keyboard event which will then trigger a switch to the | 104 // We pass in a keyboard event which will then trigger a switch to the |
| 105 // next item if the current one is already active. | 105 // next item if the current one is already active. |
| 106 ui::KeyEvent event(ui::ET_KEY_RELEASED, | 106 ui::KeyEvent event(ui::ET_KEY_RELEASED, |
| 107 ui::VKEY_UNKNOWN, // The actual key gets ignored. | 107 ui::VKEY_UNKNOWN, // The actual key gets ignored. |
| 108 ui::EF_NONE, | 108 ui::EF_NONE, |
| 109 false); | 109 false); |
| 110 | 110 |
| 111 const LauncherItem& item = shelf_view_->model()->items()[index]; | 111 const LauncherItem& item = shelf_view_->model()->items()[index]; |
| 112 ShelfItemDelegate* item_delegate = | 112 ShelfItemDelegate* item_delegate = |
| 113 Shell::GetInstance()->shelf_item_delegate_manager()->GetShelfItemDelegate( | 113 Shell::GetInstance()->shelf_item_delegate_manager()->GetShelfItemDelegate( |
| 114 item.id); | 114 item.id); |
| 115 item_delegate->ItemSelected(event); | 115 item_delegate->ItemSelected(event); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void Launcher::CycleWindowLinear(CycleDirection direction) { | 118 void Shelf::CycleWindowLinear(CycleDirection direction) { |
| 119 int item_index = GetNextActivatedItemIndex( | 119 int item_index = GetNextActivatedItemIndex( |
| 120 *(shelf_view_->model()), direction); | 120 *(shelf_view_->model()), direction); |
| 121 if (item_index >= 0) | 121 if (item_index >= 0) |
| 122 ActivateLauncherItem(item_index); | 122 ActivateShelfItem(item_index); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void Launcher::AddIconObserver(ShelfIconObserver* observer) { | 125 void Shelf::AddIconObserver(ShelfIconObserver* observer) { |
| 126 shelf_view_->AddIconObserver(observer); | 126 shelf_view_->AddIconObserver(observer); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void Launcher::RemoveIconObserver(ShelfIconObserver* observer) { | 129 void Shelf::RemoveIconObserver(ShelfIconObserver* observer) { |
| 130 shelf_view_->RemoveIconObserver(observer); | 130 shelf_view_->RemoveIconObserver(observer); |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool Launcher::IsShowingMenu() const { | 133 bool Shelf::IsShowingMenu() const { |
| 134 return shelf_view_->IsShowingMenu(); | 134 return shelf_view_->IsShowingMenu(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool Launcher::IsShowingOverflowBubble() const { | 137 bool Shelf::IsShowingOverflowBubble() const { |
| 138 return shelf_view_->IsShowingOverflowBubble(); | 138 return shelf_view_->IsShowingOverflowBubble(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void Launcher::SetVisible(bool visible) const { | 141 void Shelf::SetVisible(bool visible) const { |
| 142 shelf_view_->SetVisible(visible); | 142 shelf_view_->SetVisible(visible); |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool Launcher::IsVisible() const { | 145 bool Shelf::IsVisible() const { |
| 146 return shelf_view_->visible(); | 146 return shelf_view_->visible(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void Launcher::SchedulePaint() { | 149 void Shelf::SchedulePaint() { |
| 150 shelf_view_->SchedulePaintForAllButtons(); | 150 shelf_view_->SchedulePaintForAllButtons(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 views::View* Launcher::GetAppListButtonView() const { | 153 views::View* Shelf::GetAppListButtonView() const { |
| 154 return shelf_view_->GetAppListButtonView(); | 154 return shelf_view_->GetAppListButtonView(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void Launcher::LaunchAppIndexAt(int item_index) { | 157 void Shelf::LaunchAppIndexAt(int item_index) { |
| 158 ShelfModel* shelf_model = shelf_view_->model(); | 158 ShelfModel* shelf_model = shelf_view_->model(); |
| 159 const LauncherItems& items = shelf_model->items(); | 159 const LauncherItems& items = shelf_model->items(); |
| 160 int item_count = shelf_model->item_count(); | 160 int item_count = shelf_model->item_count(); |
| 161 int indexes_left = item_index >= 0 ? item_index : item_count; | 161 int indexes_left = item_index >= 0 ? item_index : item_count; |
| 162 int found_index = -1; | 162 int found_index = -1; |
| 163 | 163 |
| 164 // Iterating until we have hit the index we are interested in which | 164 // Iterating until we have hit the index we are interested in which |
| 165 // is true once indexes_left becomes negative. | 165 // is true once indexes_left becomes negative. |
| 166 for (int i = 0; i < item_count && indexes_left >= 0; i++) { | 166 for (int i = 0; i < item_count && indexes_left >= 0; i++) { |
| 167 if (items[i].type != TYPE_APP_LIST) { | 167 if (items[i].type != TYPE_APP_LIST) { |
| 168 found_index = i; | 168 found_index = i; |
| 169 indexes_left--; | 169 indexes_left--; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 // There are two ways how found_index can be valid: a.) the nth item was | 173 // There are two ways how found_index can be valid: a.) the nth item was |
| 174 // found (which is true when indexes_left is -1) or b.) the last item was | 174 // found (which is true when indexes_left is -1) or b.) the last item was |
| 175 // requested (which is true when index was passed in as a negative number). | 175 // requested (which is true when index was passed in as a negative number). |
| 176 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { | 176 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { |
| 177 // Then set this one as active (or advance to the next item of its kind). | 177 // Then set this one as active (or advance to the next item of its kind). |
| 178 ActivateLauncherItem(found_index); | 178 ActivateShelfItem(found_index); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 void Launcher::SetShelfViewBounds(gfx::Rect bounds) { | 182 void Shelf::SetShelfViewBounds(gfx::Rect bounds) { |
| 183 shelf_view_->SetBoundsRect(bounds); | 183 shelf_view_->SetBoundsRect(bounds); |
| 184 } | 184 } |
| 185 | 185 |
| 186 gfx::Rect Launcher::GetShelfViewBounds() const { | 186 gfx::Rect Shelf::GetShelfViewBounds() const { |
| 187 return shelf_view_->bounds(); | 187 return shelf_view_->bounds(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 gfx::Rect Launcher::GetVisibleItemsBoundsInScreen() const { | 190 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const { |
| 191 return shelf_view_->GetVisibleItemsBoundsInScreen(); | 191 return shelf_view_->GetVisibleItemsBoundsInScreen(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 app_list::ApplicationDragAndDropHost* Launcher::GetDragAndDropHostForAppList() { | 194 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { |
| 195 return shelf_view_; | 195 return shelf_view_; |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace ash | 198 } // namespace ash |
| OLD | NEW |