| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/shelf/shelf.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <cmath> | |
| 9 | |
| 10 #include "ash/aura/wm_window_aura.h" | |
| 11 #include "ash/common/shelf/shelf_delegate.h" | |
| 12 #include "ash/common/shelf/shelf_item_delegate.h" | |
| 13 #include "ash/common/shelf/shelf_model.h" | |
| 14 #include "ash/common/shelf/shelf_navigator.h" | |
| 15 #include "ash/common/shelf/shelf_view.h" | |
| 16 #include "ash/common/shell_window_ids.h" | |
| 17 #include "ash/common/wm_lookup.h" | |
| 18 #include "ash/common/wm_shell.h" | |
| 19 #include "ash/common/wm_window_property.h" | |
| 20 #include "ash/root_window_controller.h" | |
| 21 #include "ash/shelf/shelf_layout_manager.h" | |
| 22 #include "ui/aura/window.h" | |
| 23 #include "ui/compositor/layer.h" | |
| 24 #include "ui/gfx/canvas.h" | |
| 25 #include "ui/gfx/image/image.h" | |
| 26 #include "ui/gfx/image/image_skia_operations.h" | |
| 27 #include "ui/gfx/skbitmap_operations.h" | |
| 28 #include "ui/views/accessible_pane_view.h" | |
| 29 #include "ui/views/widget/widget.h" | |
| 30 #include "ui/views/widget/widget_delegate.h" | |
| 31 #include "ui/wm/public/activation_client.h" | |
| 32 | |
| 33 namespace ash { | |
| 34 | |
| 35 Shelf::Shelf(WmShelf* wm_shelf, | |
| 36 ShelfView* shelf_view, | |
| 37 ShelfWidget* shelf_widget) | |
| 38 : wm_shelf_(wm_shelf), | |
| 39 shelf_widget_(shelf_widget), | |
| 40 shelf_view_(shelf_view), | |
| 41 shelf_locking_manager_(wm_shelf) { | |
| 42 DCHECK(wm_shelf_); | |
| 43 DCHECK(shelf_view_); | |
| 44 DCHECK(shelf_widget_); | |
| 45 } | |
| 46 | |
| 47 Shelf::~Shelf() { | |
| 48 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(this); | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 Shelf* Shelf::ForPrimaryDisplay() { | |
| 53 return Shelf::ForWindow(WmShell::Get()->GetPrimaryRootWindow()); | |
| 54 } | |
| 55 | |
| 56 // static | |
| 57 Shelf* Shelf::ForWindow(const WmWindow* window) { | |
| 58 const aura::Window* aura_window = WmWindowAura::GetAuraWindow(window); | |
| 59 ShelfWidget* shelf_widget = | |
| 60 RootWindowController::ForWindow(aura_window)->shelf_widget(); | |
| 61 return shelf_widget ? shelf_widget->shelf() : nullptr; | |
| 62 } | |
| 63 | |
| 64 void Shelf::SetAlignment(ShelfAlignment alignment) { | |
| 65 if (alignment_ == alignment) | |
| 66 return; | |
| 67 | |
| 68 if (shelf_locking_manager_.is_locked() && | |
| 69 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | |
| 70 shelf_locking_manager_.set_stored_alignment(alignment); | |
| 71 return; | |
| 72 } | |
| 73 | |
| 74 alignment_ = alignment; | |
| 75 shelf_view_->OnShelfAlignmentChanged(); | |
| 76 shelf_widget_->OnShelfAlignmentChanged(); | |
| 77 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this); | |
| 78 WmShell::Get()->NotifyShelfAlignmentChanged( | |
| 79 WmLookup::Get()->GetWindowForWidget(shelf_widget_)->GetRootWindow()); | |
| 80 // ShelfLayoutManager will resize the shelf. | |
| 81 } | |
| 82 | |
| 83 void Shelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { | |
| 84 if (auto_hide_behavior_ == auto_hide_behavior) | |
| 85 return; | |
| 86 | |
| 87 auto_hide_behavior_ = auto_hide_behavior; | |
| 88 WmShell::Get()->shelf_delegate()->OnShelfAutoHideBehaviorChanged(this); | |
| 89 WmShell::Get()->NotifyShelfAutoHideBehaviorChanged( | |
| 90 WmLookup::Get()->GetWindowForWidget(shelf_widget_)->GetRootWindow()); | |
| 91 } | |
| 92 | |
| 93 ShelfAutoHideState Shelf::GetAutoHideState() const { | |
| 94 return shelf_widget_->shelf_layout_manager()->auto_hide_state(); | |
| 95 } | |
| 96 | |
| 97 ShelfVisibilityState Shelf::GetVisibilityState() const { | |
| 98 return shelf_widget_->shelf_layout_manager()->visibility_state(); | |
| 99 } | |
| 100 | |
| 101 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | |
| 102 ShelfID id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | |
| 103 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); | |
| 104 gfx::Point screen_origin; | |
| 105 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); | |
| 106 return gfx::Rect(screen_origin.x() + bounds.x(), | |
| 107 screen_origin.y() + bounds.y(), bounds.width(), | |
| 108 bounds.height()); | |
| 109 } | |
| 110 | |
| 111 void Shelf::UpdateIconPositionForWindow(WmWindow* window) { | |
| 112 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); | |
| 113 shelf_view_->UpdatePanelIconPosition( | |
| 114 window->GetIntProperty(WmWindowProperty::SHELF_ID), | |
| 115 shelf_window->ConvertRectFromScreen(window->GetBoundsInScreen()) | |
| 116 .CenterPoint()); | |
| 117 } | |
| 118 | |
| 119 void Shelf::ActivateShelfItem(int index) { | |
| 120 // We pass in a keyboard event which will then trigger a switch to the | |
| 121 // next item if the current one is already active. | |
| 122 ui::KeyEvent event(ui::ET_KEY_RELEASED, | |
| 123 ui::VKEY_UNKNOWN, // The actual key gets ignored. | |
| 124 ui::EF_NONE); | |
| 125 | |
| 126 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | |
| 127 const ShelfItem& item = shelf_model->items()[index]; | |
| 128 ShelfItemDelegate* item_delegate = shelf_model->GetShelfItemDelegate(item.id); | |
| 129 item_delegate->ItemSelected(event); | |
| 130 } | |
| 131 | |
| 132 void Shelf::CycleWindowLinear(CycleDirection direction) { | |
| 133 int item_index = | |
| 134 GetNextActivatedItemIndex(*WmShell::Get()->shelf_model(), direction); | |
| 135 if (item_index >= 0) | |
| 136 ActivateShelfItem(item_index); | |
| 137 } | |
| 138 | |
| 139 AppListButton* Shelf::GetAppListButton() const { | |
| 140 return shelf_view_->GetAppListButton(); | |
| 141 } | |
| 142 | |
| 143 void Shelf::LaunchAppIndexAt(int item_index) { | |
| 144 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | |
| 145 const ShelfItems& items = shelf_model->items(); | |
| 146 int item_count = shelf_model->item_count(); | |
| 147 int indexes_left = item_index >= 0 ? item_index : item_count; | |
| 148 int found_index = -1; | |
| 149 | |
| 150 // Iterating until we have hit the index we are interested in which | |
| 151 // is true once indexes_left becomes negative. | |
| 152 for (int i = 0; i < item_count && indexes_left >= 0; i++) { | |
| 153 if (items[i].type != TYPE_APP_LIST) { | |
| 154 found_index = i; | |
| 155 indexes_left--; | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 // There are two ways how found_index can be valid: a.) the nth item was | |
| 160 // found (which is true when indexes_left is -1) or b.) the last item was | |
| 161 // requested (which is true when index was passed in as a negative number). | |
| 162 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { | |
| 163 // Then set this one as active (or advance to the next item of its kind). | |
| 164 ActivateShelfItem(found_index); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 gfx::Rect Shelf::GetVisibleItemsBoundsInScreen() const { | |
| 169 return shelf_view_->GetVisibleItemsBoundsInScreen(); | |
| 170 } | |
| 171 | |
| 172 app_list::ApplicationDragAndDropHost* Shelf::GetDragAndDropHostForAppList() { | |
| 173 return shelf_view_; | |
| 174 } | |
| 175 | |
| 176 void Shelf::UpdateShelfItemBackground(int alpha) { | |
| 177 shelf_view_->UpdateShelfItemBackground(alpha); | |
| 178 } | |
| 179 | |
| 180 } // namespace ash | |
| OLD | NEW |