| 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.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_util.h" | 12 #include "ash/screen_util.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" |
| 16 #include "ash/shelf/shelf_layout_manager.h" | 16 #include "ash/shelf/shelf_layout_manager.h" |
| 17 #include "ash/shelf/shelf_model.h" | 17 #include "ash/shelf/shelf_model.h" |
| 18 #include "ash/shelf/shelf_navigator.h" | 18 #include "ash/shelf/shelf_navigator.h" |
| 19 #include "ash/shelf/shelf_util.h" | 19 #include "ash/shelf/shelf_util.h" |
| 20 #include "ash/shelf/shelf_view.h" | 20 #include "ash/shelf/shelf_view.h" |
| 21 #include "ash/shelf/shelf_widget.h" | |
| 22 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| 23 #include "ash/shell_delegate.h" | 22 #include "ash/shell_delegate.h" |
| 24 #include "ash/shell_window_ids.h" | 23 #include "ash/shell_window_ids.h" |
| 25 #include "ash/wm/window_properties.h" | 24 #include "ash/wm/window_properties.h" |
| 26 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
| 28 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
| 29 #include "ui/compositor/layer.h" | 28 #include "ui/compositor/layer.h" |
| 30 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
| 31 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
| 32 #include "ui/gfx/image/image_skia_operations.h" | 31 #include "ui/gfx/image/image_skia_operations.h" |
| 33 #include "ui/gfx/skbitmap_operations.h" | 32 #include "ui/gfx/skbitmap_operations.h" |
| 34 #include "ui/views/accessible_pane_view.h" | 33 #include "ui/views/accessible_pane_view.h" |
| 35 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 36 #include "ui/views/widget/widget_delegate.h" | 35 #include "ui/views/widget/widget_delegate.h" |
| 37 #include "ui/wm/public/activation_client.h" | 36 #include "ui/wm/public/activation_client.h" |
| 38 | 37 |
| 39 namespace ash { | 38 namespace ash { |
| 40 | 39 |
| 41 const char Shelf::kNativeViewName[] = "ShelfView"; | 40 const char Shelf::kNativeViewName[] = "ShelfView"; |
| 42 | 41 |
| 43 Shelf::Shelf(ShelfModel* shelf_model, | 42 Shelf::Shelf(ShelfModel* shelf_model, |
| 44 ShelfDelegate* shelf_delegate, | 43 ShelfDelegate* shelf_delegate, |
| 45 ShelfWidget* shelf_widget) | 44 ShelfWidget* shelf_widget) |
| 46 : shelf_view_(NULL), | 45 : shelf_view_(NULL), |
| 47 alignment_(shelf_widget->GetAlignment()), | 46 alignment_(shelf_widget->GetAlignment()), |
| 48 delegate_(shelf_delegate), | 47 delegate_(shelf_delegate), |
| 49 shelf_widget_(shelf_widget) { | 48 shelf_widget_(shelf_widget) { |
| 50 shelf_view_ = new ShelfView( | 49 shelf_view_ = new ShelfView(shelf_model, delegate_, this); |
| 51 shelf_model, delegate_, shelf_widget_->shelf_layout_manager()); | |
| 52 shelf_view_->Init(); | 50 shelf_view_->Init(); |
| 53 shelf_widget_->GetContentsView()->AddChildView(shelf_view_); | 51 shelf_widget_->GetContentsView()->AddChildView(shelf_view_); |
| 54 shelf_widget_->GetNativeView()->SetName(kNativeViewName); | 52 shelf_widget_->GetNativeView()->SetName(kNativeViewName); |
| 55 delegate_->OnShelfCreated(this); | 53 delegate_->OnShelfCreated(this); |
| 56 } | 54 } |
| 57 | 55 |
| 58 Shelf::~Shelf() { | 56 Shelf::~Shelf() { |
| 59 delegate_->OnShelfDestroyed(this); | 57 delegate_->OnShelfDestroyed(this); |
| 60 } | 58 } |
| 61 | 59 |
| 62 // static | 60 // static |
| 63 Shelf* Shelf::ForPrimaryDisplay() { | 61 Shelf* Shelf::ForPrimaryDisplay() { |
| 64 ShelfWidget* shelf_widget = | 62 return Shelf::ForWindow(Shell::GetPrimaryRootWindow()); |
| 65 RootWindowController::ForShelf(Shell::GetPrimaryRootWindow())->shelf(); | 63 } |
| 64 |
| 65 // static |
| 66 Shelf* Shelf::ForWindow(const aura::Window* window) { |
| 67 ShelfWidget* shelf_widget = RootWindowController::ForWindow(window)->shelf(); |
| 66 return shelf_widget ? shelf_widget->shelf() : NULL; | 68 return shelf_widget ? shelf_widget->shelf() : NULL; |
| 67 } | 69 } |
| 68 | 70 |
| 69 // static | |
| 70 Shelf* Shelf::ForWindow(aura::Window* window) { | |
| 71 ShelfWidget* shelf_widget = RootWindowController::ForShelf(window)->shelf(); | |
| 72 return shelf_widget ? shelf_widget->shelf() : NULL; | |
| 73 } | |
| 74 | |
| 75 void Shelf::SetAlignment(ShelfAlignment alignment) { | 71 void Shelf::SetAlignment(ShelfAlignment alignment) { |
| 76 alignment_ = alignment; | 72 alignment_ = alignment; |
| 77 shelf_view_->OnShelfAlignmentChanged(); | 73 shelf_view_->OnShelfAlignmentChanged(); |
| 78 // ShelfLayoutManager will resize the shelf. | 74 // ShelfLayoutManager will resize the shelf. |
| 79 } | 75 } |
| 80 | 76 |
| 77 bool Shelf::IsHorizontalAlignment() const { |
| 78 return alignment_ == SHELF_ALIGNMENT_BOTTOM || |
| 79 alignment_ == SHELF_ALIGNMENT_TOP; |
| 80 } |
| 81 |
| 81 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow( | 82 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow( |
| 82 const aura::Window* window) { | 83 const aura::Window* window) { |
| 83 ShelfID id = GetShelfIDForWindow(window); | 84 ShelfID id = GetShelfIDForWindow(window); |
| 84 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); | 85 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); |
| 85 gfx::Point screen_origin; | 86 gfx::Point screen_origin; |
| 86 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); | 87 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); |
| 87 return gfx::Rect(screen_origin.x() + bounds.x(), | 88 return gfx::Rect(screen_origin.x() + bounds.x(), |
| 88 screen_origin.y() + bounds.y(), | 89 screen_origin.y() + bounds.y(), |
| 89 bounds.width(), | 90 bounds.width(), |
| 90 bounds.height()); | 91 bounds.height()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 187 |
| 187 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const { | 188 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const { |
| 188 return shelf_view_->GetVisibleItemsBoundsInScreen(); | 189 return shelf_view_->GetVisibleItemsBoundsInScreen(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { | 192 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { |
| 192 return shelf_view_; | 193 return shelf_view_; |
| 193 } | 194 } |
| 194 | 195 |
| 195 } // namespace ash | 196 } // namespace ash |
| OLD | NEW |