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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer.cc

Issue 10823199: While dragging a window, show a semi-transparent aura window instead of the standard gray phantom wi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_aura Created 8 years, 4 months 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
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/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
(...skipping 16 matching lines...) Expand all
27 #include "ui/gfx/transform.h" 27 #include "ui/gfx/transform.h"
28 28
29 namespace ash { 29 namespace ash {
30 namespace internal { 30 namespace internal {
31 31
32 namespace { 32 namespace {
33 33
34 // Duration of the animation when snapping the window into place. 34 // Duration of the animation when snapping the window into place.
35 const int kSnapDurationMS = 100; 35 const int kSnapDurationMS = 100;
36 36
37 // The maximum opacity of the drag phantom window.
38 const float kMaxOpacity = 0.8f;
39
37 // Returns true if should snap to the edge. 40 // Returns true if should snap to the edge.
38 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { 41 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) {
39 return distance_from_edge <= grid_size / 2 && 42 return distance_from_edge <= grid_size / 2 &&
40 distance_from_edge > -grid_size * 2; 43 distance_from_edge > -grid_size * 2;
41 } 44 }
42 45
43 // Returns true if Ash has more than one root window. 46 // Returns true if Ash has more than one root window.
44 bool HasSecondaryRootWindow() { 47 bool HasSecondaryRootWindow() {
45 return Shell::GetAllRootWindows().size() > 1; 48 return Shell::GetAllRootWindows().size() > 1;
46 } 49 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 117
115 const bool in_original_root = (window()->GetRootWindow() == current_root); 118 const bool in_original_root = (window()->GetRootWindow() == current_root);
116 // Hide a phantom window for snapping if the cursor is in another root window. 119 // Hide a phantom window for snapping if the cursor is in another root window.
117 if (in_original_root) 120 if (in_original_root)
118 UpdateSnapPhantomWindow(location_in_parent, bounds, grid_size); 121 UpdateSnapPhantomWindow(location_in_parent, bounds, grid_size);
119 else 122 else
120 snap_phantom_window_controller_.reset(); 123 snap_phantom_window_controller_.reset();
121 124
122 // Show a phantom window for dragging in another root window. 125 // Show a phantom window for dragging in another root window.
123 if (HasSecondaryRootWindow()) 126 if (HasSecondaryRootWindow())
124 UpdateDragPhantomWindow(bounds); 127 UpdateDragPhantomWindow(bounds, in_original_root);
125 else 128 else
126 drag_phantom_window_controller_.reset(); 129 drag_phantom_window_controller_.reset();
127 130
128 if (!attached_windows_.empty()) 131 if (!attached_windows_.empty())
129 LayoutAttachedWindows(bounds, grid_size); 132 LayoutAttachedWindows(bounds, grid_size);
130 if (bounds != details_.window->bounds()) 133 if (bounds != details_.window->bounds())
131 details_.window->SetBounds(bounds); 134 details_.window->SetBounds(bounds);
132 // WARNING: we may have been deleted. 135 // WARNING: we may have been deleted.
133 } 136 }
134 137
135 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { 138 void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
139 window()->layer()->SetOpacity(details_.initial_opacity);
136 drag_phantom_window_controller_.reset(); 140 drag_phantom_window_controller_.reset();
137 snap_phantom_window_controller_.reset(); 141 snap_phantom_window_controller_.reset();
138 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 142 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
139 return; 143 return;
140 144
141 if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) { 145 if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) {
142 if (!GetRestoreBoundsInScreen(details_.window)) 146 if (!GetRestoreBoundsInScreen(details_.window))
143 SetRestoreBoundsInParent(details_.window, details_.initial_bounds); 147 SetRestoreBoundsInParent(details_.window, details_.initial_bounds);
144 details_.window->SetBounds(snap_sizer_->target_bounds()); 148 details_.window->SetBounds(snap_sizer_->target_bounds());
145 return; 149 return;
(...skipping 29 matching lines...) Expand all
175 179
176 ui::ScopedLayerAnimationSettings scoped_setter( 180 ui::ScopedLayerAnimationSettings scoped_setter(
177 details_.window->layer()->GetAnimator()); 181 details_.window->layer()->GetAnimator());
178 // Use a small duration since the grid is small. 182 // Use a small duration since the grid is small.
179 scoped_setter.SetTransitionDuration( 183 scoped_setter.SetTransitionDuration(
180 base::TimeDelta::FromMilliseconds(kSnapDurationMS)); 184 base::TimeDelta::FromMilliseconds(kSnapDurationMS));
181 details_.window->SetBounds(bounds); 185 details_.window->SetBounds(bounds);
182 } 186 }
183 187
184 void WorkspaceWindowResizer::RevertDrag() { 188 void WorkspaceWindowResizer::RevertDrag() {
189 window()->layer()->SetOpacity(details_.initial_opacity);
185 drag_phantom_window_controller_.reset(); 190 drag_phantom_window_controller_.reset();
186 snap_phantom_window_controller_.reset(); 191 snap_phantom_window_controller_.reset();
187 192
188 if (!did_move_or_resize_) 193 if (!did_move_or_resize_)
189 return; 194 return;
190 195
191 details_.window->SetBounds(details_.initial_bounds); 196 details_.window->SetBounds(details_.initial_bounds);
192 if (details_.window_component == HTRIGHT) { 197 if (details_.window_component == HTRIGHT) {
193 int last_x = details_.initial_bounds.right(); 198 int last_x = details_.initial_bounds.right();
194 for (size_t i = 0; i < attached_windows_.size(); ++i) { 199 for (size_t i = 0; i < attached_windows_.size(); ++i) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 case HTRIGHT: 438 case HTRIGHT:
434 return x; 439 return x;
435 case HTBOTTOM: 440 case HTBOTTOM:
436 return y; 441 return y;
437 default: 442 default:
438 NOTREACHED(); 443 NOTREACHED();
439 } 444 }
440 return 0; 445 return 0;
441 } 446 }
442 447
443 void WorkspaceWindowResizer::UpdateDragPhantomWindow(const gfx::Rect& bounds) { 448 void WorkspaceWindowResizer::UpdateDragPhantomWindow(const gfx::Rect& bounds,
449 bool in_original_root) {
444 if (!did_move_or_resize_ || details_.window_component != HTCAPTION || 450 if (!did_move_or_resize_ || details_.window_component != HTCAPTION ||
445 !ShouldAllowMouseWarp()) { 451 !ShouldAllowMouseWarp()) {
446 return; 452 return;
447 } 453 }
448 454
449 // It's available. Show a phantom window on the display if needed. 455 // It's available. Show a phantom window on the display if needed.
450 aura::RootWindow* another_root = 456 aura::RootWindow* another_root =
451 GetAnotherRootWindow(window()->GetRootWindow()); 457 GetAnotherRootWindow(window()->GetRootWindow());
452 const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen()); 458 const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen());
453 const gfx::Rect bounds_in_screen = 459 const gfx::Rect bounds_in_screen =
454 ScreenAsh::ConvertRectToScreen(window()->parent(), bounds); 460 ScreenAsh::ConvertRectToScreen(window()->parent(), bounds);
455 const gfx::Rect phantom(root_bounds_in_screen.Intersect(bounds_in_screen)); 461 const gfx::Rect bounds_in_another_root =
462 root_bounds_in_screen.Intersect(bounds_in_screen);
456 463
457 if (!phantom.IsEmpty()) { 464 const float fraction_in_another_window =
465 (bounds_in_another_root.width() * bounds_in_another_root.height()) /
466 static_cast<float>(bounds.width() * bounds.height());
467 const float phantom_opacity =
468 !in_original_root ? 1 : (kMaxOpacity * fraction_in_another_window);
469 const float window_opacity =
470 in_original_root ? 1 : (kMaxOpacity * (1 - fraction_in_another_window));
471
472 if (fraction_in_another_window > 0) {
458 if (!drag_phantom_window_controller_.get()) { 473 if (!drag_phantom_window_controller_.get()) {
459 drag_phantom_window_controller_.reset( 474 drag_phantom_window_controller_.reset(
460 new PhantomWindowController(window())); 475 // Always show the drag phantom on the |another_root| window.
461 drag_phantom_window_controller_->Show(phantom); 476 new PhantomWindowController(window(),
477 another_root,
478 PhantomWindowController::STYLE_WINDOW));
479 drag_phantom_window_controller_->Show(bounds_in_screen);
462 } else { 480 } else {
463 drag_phantom_window_controller_->SetBounds(phantom); // no animation 481 // No animation.
482 drag_phantom_window_controller_->SetBounds(bounds_in_screen);
464 } 483 }
484 drag_phantom_window_controller_->SetOpacity(phantom_opacity);
485 window()->layer()->SetOpacity(window_opacity);
465 } else { 486 } else {
466 drag_phantom_window_controller_.reset(); 487 drag_phantom_window_controller_.reset();
488 window()->layer()->SetOpacity(1.0f);
467 } 489 }
468 } 490 }
469 491
470 void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location, 492 void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location,
471 const gfx::Rect& bounds, 493 const gfx::Rect& bounds,
472 int grid_size) { 494 int grid_size) {
473 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) 495 if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
474 return; 496 return;
475 497
476 SnapType last_type = snap_type_; 498 SnapType last_type = snap_type_;
477 snap_type_ = GetSnapType(location); 499 snap_type_ = GetSnapType(location);
478 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { 500 if (snap_type_ == SNAP_NONE || snap_type_ != last_type) {
479 snap_phantom_window_controller_.reset(); 501 snap_phantom_window_controller_.reset();
480 snap_sizer_.reset(); 502 snap_sizer_.reset();
481 if (snap_type_ == SNAP_NONE) 503 if (snap_type_ == SNAP_NONE)
482 return; 504 return;
483 } 505 }
484 if (!snap_sizer_.get()) { 506 if (!snap_sizer_.get()) {
485 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT_EDGE) ? 507 SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT_EDGE) ?
486 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; 508 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE;
487 snap_sizer_.reset( 509 snap_sizer_.reset(
488 new SnapSizer(details_.window, location, edge, grid_size)); 510 new SnapSizer(details_.window, location, edge, grid_size));
489 } else { 511 } else {
490 snap_sizer_->Update(location); 512 snap_sizer_->Update(location);
491 } 513 }
492 if (!snap_phantom_window_controller_.get()) { 514 if (!snap_phantom_window_controller_.get()) {
493 snap_phantom_window_controller_.reset( 515 snap_phantom_window_controller_.reset(
494 new PhantomWindowController(details_.window)); 516 new PhantomWindowController(details_.window,
517 NULL,
518 PhantomWindowController::STYLE_SHADOW));
495 } 519 }
496 snap_phantom_window_controller_->Show(ScreenAsh::ConvertRectToScreen( 520 snap_phantom_window_controller_->Show(ScreenAsh::ConvertRectToScreen(
497 details_.window->parent(), snap_sizer_->target_bounds())); 521 details_.window->parent(), snap_sizer_->target_bounds()));
498 } 522 }
499 523
500 void WorkspaceWindowResizer::RestackWindows() { 524 void WorkspaceWindowResizer::RestackWindows() {
501 if (attached_windows_.empty()) 525 if (attached_windows_.empty())
502 return; 526 return;
503 // Build a map from index in children to window, returning if there is a 527 // Build a map from index in children to window, returning if there is a
504 // window with a different parent. 528 // window with a different parent.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 565 }
542 566
543 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const { 567 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const {
544 return (details_.window_component == HTCAPTION) && 568 return (details_.window_component == HTCAPTION) &&
545 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && 569 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) &&
546 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); 570 (window()->type() == aura::client::WINDOW_TYPE_NORMAL);
547 } 571 }
548 572
549 } // namespace internal 573 } // namespace internal
550 } // namespace ash 574 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698