Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2085)

Side by Side Diff: ash/wm/panel_layout_manager.cc

Issue 11363250: Allow Chrome apps to create Ash Panels (apps v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac and win builds Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/panel_layout_manager.h ('k') | ash/wm/panel_layout_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm/panel_layout_manager.h" 5 #include "ash/wm/panel_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "ash/launcher/launcher.h" 10 #include "ash/launcher/launcher.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/frame_painter.h" 12 #include "ash/wm/frame_painter.h"
13 #include "ash/wm/property_util.h" 13 #include "ash/wm/property_util.h"
14 #include "ash/wm/window_animations.h"
15 #include "ash/wm/window_util.h"
14 #include "base/auto_reset.h" 16 #include "base/auto_reset.h"
15 #include "base/bind.h" 17 #include "base/bind.h"
16 #include "base/bind_helpers.h" 18 #include "base/bind_helpers.h"
17 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
18 #include "third_party/skia/include/core/SkPaint.h" 20 #include "third_party/skia/include/core/SkPaint.h"
19 #include "third_party/skia/include/core/SkPath.h" 21 #include "third_party/skia/include/core/SkPath.h"
20 #include "ui/aura/client/activation_client.h" 22 #include "ui/aura/client/activation_client.h"
21 #include "ui/aura/client/aura_constants.h" 23 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/focus_manager.h"
22 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
23 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
24 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
26 #include "ui/views/background.h" 29 #include "ui/views/background.h"
27 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
28 31
29 namespace ash { 32 namespace ash {
30 namespace internal { 33 namespace internal {
31 34
32 namespace { 35 namespace {
33 const int kPanelMarginEdge = 4; 36 const int kPanelMarginEdge = 4;
34 const int kPanelMarginMiddle = 8; 37 const int kPanelMarginMiddle = 8;
35 const int kPanelIdealSpacing = 4; 38 const int kPanelIdealSpacing = 4;
36 39
37 const int kMinimizedHeight = 24;
38
39 const float kMaxHeightFactor = .80f; 40 const float kMaxHeightFactor = .80f;
40 const float kMaxWidthFactor = .50f; 41 const float kMaxWidthFactor = .50f;
41 42
42 // Callout arrow dimensions. 43 // Callout arrow dimensions.
43 const int kArrowWidth = 20; 44 const int kArrowWidth = 20;
44 const int kArrowHeight = 10; 45 const int kArrowHeight = 10;
45 46
46 class CalloutWidgetBackground : public views::Background { 47 class CalloutWidgetBackground : public views::Background {
47 public: 48 public:
48 CalloutWidgetBackground() {} 49 CalloutWidgetBackground() {}
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (launcher_) 153 if (launcher_)
153 launcher_->RemoveIconObserver(this); 154 launcher_->RemoveIconObserver(this);
154 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> 155 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
155 RemoveObserver(this); 156 RemoveObserver(this);
156 } 157 }
157 158
158 void PanelLayoutManager::StartDragging(aura::Window* panel) { 159 void PanelLayoutManager::StartDragging(aura::Window* panel) {
159 DCHECK(!dragged_panel_); 160 DCHECK(!dragged_panel_);
160 DCHECK(panel->parent() == panel_container_); 161 DCHECK(panel->parent() == panel_container_);
161 dragged_panel_ = panel; 162 dragged_panel_ = panel;
163 Relayout();
162 } 164 }
163 165
164 void PanelLayoutManager::FinishDragging() { 166 void PanelLayoutManager::FinishDragging() {
165 DCHECK(dragged_panel_); 167 DCHECK(dragged_panel_);
166 dragged_panel_ = NULL; 168 dragged_panel_ = NULL;
167 Relayout(); 169 Relayout();
168 } 170 }
169 171
170 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { 172 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) {
171 launcher_ = launcher; 173 launcher_ = launcher;
172 launcher_->AddIconObserver(this); 174 launcher_->AddIconObserver(this);
173 } 175 }
174 176
175 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { 177 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) {
176 DCHECK(panel->parent() == panel_container_); 178 DCHECK(panel->parent() == panel_container_);
177 if (panel->GetProperty(aura::client::kShowStateKey) == 179 if (panel->GetProperty(aura::client::kShowStateKey) ==
178 ui::SHOW_STATE_MINIMIZED) { 180 ui::SHOW_STATE_MINIMIZED) {
179 const gfx::Rect& old_bounds = panel->bounds();
180 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 181 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
181
182 gfx::Rect new_bounds(old_bounds);
183 const gfx::Rect* restore_bounds = GetRestoreBoundsInScreen(panel);
184 if (restore_bounds) {
185 new_bounds.set_height(restore_bounds->height());
186 new_bounds.set_y(old_bounds.bottom() - restore_bounds->height());
187 SetChildBounds(panel, new_bounds);
188 ClearRestoreBounds(panel);
189 }
190 } else { 182 } else {
191 const gfx::Rect& old_bounds = panel->bounds();
192 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 183 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
193 SetRestoreBoundsInParent(panel, old_bounds);
194 SetChildBounds(panel,
195 gfx::Rect(old_bounds.x(),
196 old_bounds.bottom() - kMinimizedHeight,
197 old_bounds.width(),
198 kMinimizedHeight));
199 } 184 }
200 Relayout();
201 } 185 }
202 186
203 //////////////////////////////////////////////////////////////////////////////// 187 ////////////////////////////////////////////////////////////////////////////////
204 // PanelLayoutManager, aura::LayoutManager implementation: 188 // PanelLayoutManager, aura::LayoutManager implementation:
205 void PanelLayoutManager::OnWindowResized() { 189 void PanelLayoutManager::OnWindowResized() {
206 Relayout(); 190 Relayout();
207 } 191 }
208 192
209 void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { 193 void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
210 if (child == callout_widget_->GetNativeWindow()) 194 if (child == callout_widget_->GetNativeWindow())
211 return; 195 return;
212 panel_windows_.push_back(child); 196 panel_windows_.push_back(child);
197 child->AddObserver(this);
213 Relayout(); 198 Relayout();
214 } 199 }
215 200
216 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { 201 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
217 PanelList::iterator found = 202 PanelList::iterator found =
218 std::find(panel_windows_.begin(), panel_windows_.end(), child); 203 std::find(panel_windows_.begin(), panel_windows_.end(), child);
219 if (found != panel_windows_.end()) 204 if (found != panel_windows_.end())
220 panel_windows_.erase(found); 205 panel_windows_.erase(found);
206 child->RemoveObserver(this);
221 207
222 if (dragged_panel_ == child) 208 if (dragged_panel_ == child)
223 dragged_panel_ = NULL; 209 dragged_panel_ = NULL;
224 210
225 if (last_active_panel_ == child) 211 if (last_active_panel_ == child)
226 last_active_panel_ = NULL; 212 last_active_panel_ = NULL;
227 213
228 Relayout(); 214 Relayout();
229 } 215 }
230 216
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 //////////////////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////////////////
273 // PanelLayoutManager, ash::LauncherIconObserver implementation: 259 // PanelLayoutManager, ash::LauncherIconObserver implementation:
274 260
275 void PanelLayoutManager::OnLauncherIconPositionsChanged() { 261 void PanelLayoutManager::OnLauncherIconPositionsChanged() {
276 // TODO: As this is called for every animation step now. Relayout needs to be 262 // TODO: As this is called for every animation step now. Relayout needs to be
277 // updated to use current icon position instead of use the ideal bounds so 263 // updated to use current icon position instead of use the ideal bounds so
278 // that the panels slide with their icons instead of jumping. 264 // that the panels slide with their icons instead of jumping.
279 Relayout(); 265 Relayout();
280 } 266 }
281 267
268 /////////////////////////////////////////////////////////////////////////////
269 // PanelLayoutManager, WindowObserver implementation:
270
271 void PanelLayoutManager::OnWindowPropertyChanged(aura::Window* window,
272 const void* key,
273 intptr_t old) {
274 if (key != aura::client::kShowStateKey)
275 return;
276 ui::WindowShowState new_state =
277 window->GetProperty(aura::client::kShowStateKey);
278 if (new_state == ui::SHOW_STATE_MINIMIZED)
279 MinimizePanel(window);
280 else
281 RestorePanel(window);
282 }
283
282 //////////////////////////////////////////////////////////////////////////////// 284 ////////////////////////////////////////////////////////////////////////////////
283 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: 285 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation:
284 void PanelLayoutManager::OnWindowActivated(aura::Window* active, 286 void PanelLayoutManager::OnWindowActivated(aura::Window* active,
285 aura::Window* old_active) { 287 aura::Window* old_active) {
286 if (active && active->type() == aura::client::WINDOW_TYPE_PANEL) { 288 if (active && active->type() == aura::client::WINDOW_TYPE_PANEL) {
287 UpdateStacking(active); 289 UpdateStacking(active);
288 UpdateCallout(active); 290 UpdateCallout(active);
289 } else { 291 } else {
290 UpdateCallout(NULL); 292 UpdateCallout(NULL);
291 } 293 }
292 } 294 }
293 295
294
295 //////////////////////////////////////////////////////////////////////////////// 296 ////////////////////////////////////////////////////////////////////////////////
296 // PanelLayoutManager private implementation: 297 // PanelLayoutManager private implementation:
298
299 void PanelLayoutManager::MinimizePanel(aura::Window* panel) {
300 views::corewm::SetWindowVisibilityAnimationType(
301 panel, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
302 panel->Hide();
303 if (wm::IsActiveWindow(panel))
304 wm::DeactivateWindow(panel);
305 Relayout();
306 }
307
308 void PanelLayoutManager::RestorePanel(aura::Window* panel) {
309 panel->Show();
310 Relayout();
311 }
312
297 void PanelLayoutManager::Relayout() { 313 void PanelLayoutManager::Relayout() {
298 if (!launcher_ || !launcher_->widget()) 314 if (!launcher_ || !launcher_->widget())
299 return; 315 return;
300 316
301 if (in_layout_) 317 if (in_layout_)
302 return; 318 return;
303 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 319 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
304 320
305 int launcher_top = launcher_->widget()->GetWindowBoundsInScreen().y(); 321 int launcher_top = launcher_->widget()->GetWindowBoundsInScreen().y();
306 int panel_left_bounds = kPanelIdealSpacing; 322 int panel_left_bounds = kPanelIdealSpacing;
(...skipping 10 matching lines...) Expand all
317 gfx::Rect icon_bounds = 333 gfx::Rect icon_bounds =
318 launcher_->GetScreenBoundsOfItemIconForWindow(panel); 334 launcher_->GetScreenBoundsOfItemIconForWindow(panel);
319 335
320 // An empty rect indicates that there is no icon for the panel in the 336 // An empty rect indicates that there is no icon for the panel in the
321 // launcher. Just use the current bounds, as there's no icon to draw the 337 // launcher. Just use the current bounds, as there's no icon to draw the
322 // panel above. 338 // panel above.
323 // TODO(dcheng): Need to anchor to overflow icon. 339 // TODO(dcheng): Need to anchor to overflow icon.
324 if (icon_bounds.IsEmpty()) 340 if (icon_bounds.IsEmpty())
325 continue; 341 continue;
326 342
327 if (panel->HasFocus()) { 343 if (panel->HasFocus() ||
344 panel->Contains(
345 aura::client::GetFocusClient(panel)->GetFocusedWindow())) {
328 DCHECK(!active_panel); 346 DCHECK(!active_panel);
329 active_panel = panel; 347 active_panel = panel;
330 } 348 }
331 349
332 gfx::Point icon_origin = icon_bounds.origin(); 350 gfx::Point icon_origin = icon_bounds.origin();
333 aura::Window::ConvertPointToTarget(panel_container_->GetRootWindow(), 351 aura::Window::ConvertPointToTarget(panel_container_->GetRootWindow(),
334 panel_container_, &icon_origin); 352 panel_container_, &icon_origin);
335 353
336 VisiblePanelPositionInfo position_info; 354 VisiblePanelPositionInfo position_info;
337 position_info.min_x = std::max(panel_left_bounds, icon_origin.x() + 355 position_info.min_x = std::max(panel_left_bounds, icon_origin.x() +
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 callout_bounds.set_x( 463 callout_bounds.set_x(
446 icon_bounds.x() + (icon_bounds.width() - callout_bounds.width()) / 2); 464 icon_bounds.x() + (icon_bounds.width() - callout_bounds.width()) / 2);
447 callout_bounds.set_y(bounds.bottom()); 465 callout_bounds.set_y(bounds.bottom());
448 SetChildBoundsDirect(callout_widget_->GetNativeWindow(), callout_bounds); 466 SetChildBoundsDirect(callout_widget_->GetNativeWindow(), callout_bounds);
449 panel_container_->StackChildAtTop(callout_widget_->GetNativeWindow()); 467 panel_container_->StackChildAtTop(callout_widget_->GetNativeWindow());
450 callout_widget_->Show(); 468 callout_widget_->Show();
451 } 469 }
452 470
453 } // namespace internal 471 } // namespace internal
454 } // namespace ash 472 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panel_layout_manager.h ('k') | ash/wm/panel_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698