| 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_window_watcher.h" | 5 #include "ash/shelf/shelf_window_watcher.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/shelf/shelf_item_delegate_manager.h" | 8 #include "ash/shelf/shelf_item_delegate_manager.h" |
| 9 #include "ash/shelf/shelf_model.h" | 9 #include "ash/shelf/shelf_model.h" |
| 10 #include "ash/shelf/shelf_util.h" | 10 #include "ash/shelf/shelf_util.h" |
| 11 #include "ash/shelf/shelf_window_watcher_item_delegate.h" | 11 #include "ash/shelf/shelf_window_watcher_item_delegate.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "ui/aura/client/activation_client.h" | 16 #include "ui/aura/client/activation_client.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
| 20 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Sets LauncherItem property by using the value of |details|. | 24 // Sets LauncherItem property by using the value of |details|. |
| 25 void SetLauncherItemDetailsForLauncherItem( | 25 void SetShelfItemDetailsForLauncherItem( |
| 26 ash::LauncherItem* item, | 26 ash::LauncherItem* item, |
| 27 const ash::LauncherItemDetails& details) { | 27 const ash::LauncherItemDetails& details) { |
| 28 item->type = details.type; | 28 item->type = details.type; |
| 29 if (details.image_resource_id != ash::kInvalidImageResourceID) { | 29 if (details.image_resource_id != ash::kInvalidImageResourceID) { |
| 30 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 30 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 31 item->image = *rb.GetImageSkiaNamed(details.image_resource_id); | 31 item->image = *rb.GetImageSkiaNamed(details.image_resource_id); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Returns true if |window| has a LauncherItem added by ShelfWindowWatcher. | 35 // Returns true if |window| has a LauncherItem added by ShelfWindowWatcher. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 ShelfWindowWatcher::~ShelfWindowWatcher() { | 80 ShelfWindowWatcher::~ShelfWindowWatcher() { |
| 81 Shell::GetScreen()->RemoveObserver(this); | 81 Shell::GetScreen()->RemoveObserver(this); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ShelfWindowWatcher::AddLauncherItem(aura::Window* window) { | 84 void ShelfWindowWatcher::AddLauncherItem(aura::Window* window) { |
| 85 const LauncherItemDetails* item_details = | 85 const LauncherItemDetails* item_details = |
| 86 GetLauncherItemDetailsForWindow(window); | 86 GetLauncherItemDetailsForWindow(window); |
| 87 LauncherItem item; | 87 LauncherItem item; |
| 88 LauncherID id = model_->next_id(); | 88 LauncherID id = model_->next_id(); |
| 89 item.status = ash::wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; | 89 item.status = ash::wm::IsActiveWindow(window) ? STATUS_ACTIVE: STATUS_RUNNING; |
| 90 SetLauncherItemDetailsForLauncherItem(&item, *item_details); | 90 SetShelfItemDetailsForLauncherItem(&item, *item_details); |
| 91 SetLauncherIDForWindow(id, window); | 91 SetLauncherIDForWindow(id, window); |
| 92 scoped_ptr<ShelfItemDelegate> item_delegate( | 92 scoped_ptr<ShelfItemDelegate> item_delegate( |
| 93 new ShelfWindowWatcherItemDelegate(window)); | 93 new ShelfWindowWatcherItemDelegate(window)); |
| 94 // |item_delegate| is owned by |item_delegate_manager_|. | 94 // |item_delegate| is owned by |item_delegate_manager_|. |
| 95 item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass()); | 95 item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass()); |
| 96 model_->Add(item); | 96 model_->Add(item); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ShelfWindowWatcher::RemoveLauncherItem(aura::Window* window) { | 99 void ShelfWindowWatcher::RemoveLauncherItem(aura::Window* window) { |
| 100 model_->RemoveItemAt(model_->ItemIndexByID(GetLauncherIDForWindow(window))); | 100 model_->RemoveItemAt(model_->ItemIndexByID(GetLauncherIDForWindow(window))); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 // When LauncherItemDetails is changed, update LauncherItem. | 186 // When LauncherItemDetails is changed, update LauncherItem. |
| 187 if (HasLauncherItemForWindow(window)) { | 187 if (HasLauncherItemForWindow(window)) { |
| 188 int index = GetLauncherItemIndexForWindow(window); | 188 int index = GetLauncherItemIndexForWindow(window); |
| 189 DCHECK_GE(index, 0); | 189 DCHECK_GE(index, 0); |
| 190 LauncherItem item = model_->items()[index]; | 190 LauncherItem item = model_->items()[index]; |
| 191 const LauncherItemDetails* details = | 191 const LauncherItemDetails* details = |
| 192 GetLauncherItemDetailsForWindow(window); | 192 GetLauncherItemDetailsForWindow(window); |
| 193 SetLauncherItemDetailsForLauncherItem(&item, *details); | 193 SetShelfItemDetailsForLauncherItem(&item, *details); |
| 194 model_->Set(index, item); | 194 model_->Set(index, item); |
| 195 return; | 195 return; |
| 196 } | 196 } |
| 197 | 197 |
| 198 // Creates a new LauncherItem for |window|. | 198 // Creates a new LauncherItem for |window|. |
| 199 AddLauncherItem(window); | 199 AddLauncherItem(window); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void ShelfWindowWatcher::OnDisplayBoundsChanged(const gfx::Display& display) { | 202 void ShelfWindowWatcher::OnDisplayBoundsChanged(const gfx::Display& display) { |
| 203 } | 203 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 215 | 215 |
| 216 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { | 216 void ShelfWindowWatcher::OnDisplayRemoved(const gfx::Display& old_display) { |
| 217 // When this is called, RootWindow of |old_display| is already removed. | 217 // When this is called, RootWindow of |old_display| is already removed. |
| 218 // Instead, we remove an observer from RootWindow and ActivationClient in the | 218 // Instead, we remove an observer from RootWindow and ActivationClient in the |
| 219 // OnRootWindowDestroyed(). | 219 // OnRootWindowDestroyed(). |
| 220 // Do nothing here. | 220 // Do nothing here. |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace internal | 223 } // namespace internal |
| 224 } // namespace ash | 224 } // namespace ash |
| OLD | NEW |