OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "ui/aura_shell/workspace_controller.h" | |
6 | |
7 #include "ui/aura/client/activation_client.h" | |
8 #include "ui/aura/client/aura_constants.h" | |
9 #include "ui/aura/root_window.h" | |
10 #include "ui/aura/window.h" | |
11 #include "ui/aura_shell/default_container_layout_manager.h" | |
12 #include "ui/aura_shell/launcher/launcher.h" | |
13 #include "ui/aura_shell/launcher/launcher_model.h" | |
14 #include "ui/aura_shell/shell.h" | |
15 #include "ui/aura_shell/window_util.h" | |
16 #include "ui/aura_shell/workspace/workspace.h" | |
17 #include "ui/aura_shell/workspace/workspace_manager.h" | |
18 | |
19 namespace aura_shell { | |
20 namespace internal { | |
21 | |
22 WorkspaceController::WorkspaceController(aura::Window* viewport) | |
23 : workspace_manager_(new WorkspaceManager(viewport)), | |
24 launcher_model_(NULL), | |
25 ignore_move_event_(false) { | |
26 workspace_manager_->AddObserver(this); | |
27 aura::RootWindow::GetInstance()->AddRootWindowObserver(this); | |
28 aura::RootWindow::GetInstance()->AddObserver(this); | |
29 } | |
30 | |
31 WorkspaceController::~WorkspaceController() { | |
32 workspace_manager_->RemoveObserver(this); | |
33 if (launcher_model_) | |
34 launcher_model_->RemoveObserver(this); | |
35 aura::RootWindow::GetInstance()->RemoveObserver(this); | |
36 aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); | |
37 } | |
38 | |
39 void WorkspaceController::ToggleOverview() { | |
40 workspace_manager_->SetOverview(!workspace_manager_->is_overview()); | |
41 } | |
42 | |
43 void WorkspaceController::SetLauncherModel(LauncherModel* launcher_model) { | |
44 DCHECK(!launcher_model_); | |
45 launcher_model_ = launcher_model; | |
46 launcher_model_->AddObserver(this); | |
47 } | |
48 | |
49 //////////////////////////////////////////////////////////////////////////////// | |
50 // WorkspaceController, aura::RootWindowObserver overrides: | |
51 | |
52 void WorkspaceController::OnRootWindowResized(const gfx::Size& new_size) { | |
53 workspace_manager_->SetWorkspaceSize(new_size); | |
54 } | |
55 | |
56 //////////////////////////////////////////////////////////////////////////////// | |
57 // WorkspaceController, aura::WindowObserver overrides: | |
58 | |
59 void WorkspaceController::OnWindowPropertyChanged(aura::Window* window, | |
60 const char* key, | |
61 void* old) { | |
62 if (key == aura::client::kRootWindowActiveWindow) { | |
63 // FindBy handles NULL. | |
64 Workspace* workspace = workspace_manager_->FindBy(GetActiveWindow()); | |
65 if (workspace) | |
66 workspace->Activate(); | |
67 } | |
68 } | |
69 | |
70 //////////////////////////////////////////////////////////////////////////////// | |
71 // WorkspaceController, aura_shell::internal::WorkspaceObserver overrides: | |
72 | |
73 void WorkspaceController::WindowMoved(WorkspaceManager* manager, | |
74 aura::Window* source, | |
75 aura::Window* target) { | |
76 if (ignore_move_event_ || !launcher_model_) | |
77 return; | |
78 int start_index = launcher_model_->ItemIndexByWindow(source); | |
79 int target_index = launcher_model_->ItemIndexByWindow(target); | |
80 // The following condition may not be hold depending on future | |
81 // launcher design. Using DCHECK so that we can catch such change. | |
82 DCHECK(start_index >=0); | |
83 DCHECK(target_index >=0); | |
84 | |
85 ignore_move_event_ = true; | |
86 launcher_model_->Move(start_index, target_index); | |
87 ignore_move_event_ = false; | |
88 } | |
89 | |
90 void WorkspaceController::ActiveWorkspaceChanged(WorkspaceManager* manager, | |
91 Workspace* old) { | |
92 // TODO(oshima): Update Launcher and Status area state when the active | |
93 // workspace's fullscreen state changes. | |
94 //NOTIMPLEMENTED(); | |
95 } | |
96 | |
97 //////////////////////////////////////////////////////////////////////////////// | |
98 // WorkspaceController, aura_shell::LauncherModelObserver overrides: | |
99 | |
100 void WorkspaceController::LauncherItemAdded(int index) { | |
101 } | |
102 | |
103 void WorkspaceController::LauncherItemRemoved(int index) { | |
104 } | |
105 | |
106 void WorkspaceController::LauncherItemMoved(int start_index, int target_index) { | |
107 if (ignore_move_event_) | |
108 return; | |
109 DCHECK(launcher_model_); | |
110 // Adjust target/source indices as the item positions in |launcher_model_| | |
111 // has already been updated. | |
112 aura::Window* start = launcher_model_->items()[target_index].window; | |
113 size_t target_index_in_model = | |
114 start_index < target_index ? target_index - 1 : target_index + 1; | |
115 DCHECK_LE(target_index_in_model, launcher_model_->items().size()); | |
116 aura::Window* target = launcher_model_->items()[target_index_in_model].window; | |
117 | |
118 ignore_move_event_ = true; | |
119 workspace_manager_->RotateWindows(start, target); | |
120 ignore_move_event_ = false; | |
121 } | |
122 | |
123 void WorkspaceController::LauncherItemImagesChanged(int index) { | |
124 } | |
125 | |
126 } // namespace internal | |
127 } // namespace aura_shell | |
OLD | NEW |