diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-27 02:45:09 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-27 02:45:09 +0000 |
commit | 8d6b180d0a3b5e02737f0b5847b10536b55dbb06 (patch) | |
tree | 7795c3d6181ea95fc43e4c9f64717e5fc6171024 /ash/wm | |
parent | cadd8c499c6bdd316bc50df4082fb9178328cf78 (diff) | |
download | chromium_src-8d6b180d0a3b5e02737f0b5847b10536b55dbb06.zip chromium_src-8d6b180d0a3b5e02737f0b5847b10536b55dbb06.tar.gz chromium_src-8d6b180d0a3b5e02737f0b5847b10536b55dbb06.tar.bz2 |
Makes the phantom appear immediately and does away with a phantom for
the destination.
BUG=120252
TEST=none
R=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9864014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129109 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm')
-rw-r--r-- | ash/wm/workspace/frame_maximize_button.cc | 3 | ||||
-rw-r--r-- | ash/wm/workspace/phantom_window_controller.cc | 107 | ||||
-rw-r--r-- | ash/wm/workspace/phantom_window_controller.h | 32 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_window_resizer.cc | 60 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_window_resizer.h | 3 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_window_resizer_unittest.cc | 2 |
6 files changed, 36 insertions, 171 deletions
diff --git a/ash/wm/workspace/frame_maximize_button.cc b/ash/wm/workspace/frame_maximize_button.cc index e5a483d..49e4a61 100644 --- a/ash/wm/workspace/frame_maximize_button.cc +++ b/ash/wm/workspace/frame_maximize_button.cc @@ -265,8 +265,7 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { } if (!phantom_window_.get()) { phantom_window_.reset(new internal::PhantomWindowController( - frame_->GetWidget()->GetNativeWindow(), - internal::PhantomWindowController::TYPE_EDGE, 0)); + frame_->GetWidget()->GetNativeWindow())); } phantom_window_->Show(BoundsForType(snap_type_)); } diff --git a/ash/wm/workspace/phantom_window_controller.cc b/ash/wm/workspace/phantom_window_controller.cc index 75deedc..b491ddf 100644 --- a/ash/wm/workspace/phantom_window_controller.cc +++ b/ash/wm/workspace/phantom_window_controller.cc @@ -22,27 +22,13 @@ namespace internal { namespace { -// Paints the background of the phantom window for TYPE_DESTINATION. -class DestinationPainter : public views::Painter { - public: - DestinationPainter() {} - - // views::Painter overrides: - virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { - canvas->DrawDashedRect(gfx::Rect(size), SkColorSetARGB(128, 0, 0, 0)); - } - - private: - DISALLOW_COPY_AND_ASSIGN(DestinationPainter); -}; - // Amount to inset from the bounds for EdgePainter. const int kInsetSize = 4; // Size of the round rect used by EdgePainter. const int kRoundRectSize = 4; -// Paints the background of the phantom window for TYPE_EDGE. +// Paints the background of the phantom window. class EdgePainter : public views::Painter { public: EdgePainter() {} @@ -82,53 +68,10 @@ class EdgePainter : public views::Painter { DISALLOW_COPY_AND_ASSIGN(EdgePainter); }; -// Used to delete the widget after a delay, or if the window is deleted. -class DelayedWidgetDeleter : public aura::WindowObserver { - public: - DelayedWidgetDeleter(views::Widget* widget, aura::Window* window) - : widget_(widget), - window_(window) { - window->AddObserver(this); - } - - // Schedules deletion of the widget passed to the constructor after |delay_ms| - // milliseconds. - void ScheduleDelete(int delay_ms) { - timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(delay_ms), - this, &DelayedWidgetDeleter::TimerFired); - } - - // aura::WindowObserver: - virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { - delete this; - } - - private: - virtual ~DelayedWidgetDeleter() { - window_->RemoveObserver(this); - } - - void TimerFired() { - delete this; - } - - scoped_ptr<views::Widget> widget_; - - aura::Window* window_; - - base::OneShotTimer<DelayedWidgetDeleter> timer_; - - DISALLOW_COPY_AND_ASSIGN(DelayedWidgetDeleter); -}; - } // namespace -PhantomWindowController::PhantomWindowController(aura::Window* window, - Type type, - int delay_ms) - : window_(window), - type_(type), - delay_ms_(delay_ms) { +PhantomWindowController::PhantomWindowController(aura::Window* window) + : window_(window) { } PhantomWindowController::~PhantomWindowController() { @@ -140,51 +83,30 @@ void PhantomWindowController::Show(const gfx::Rect& bounds) { return; bounds_ = bounds; if (phantom_widget_.get()) { - if (type_ == TYPE_EDGE) { - phantom_widget_->SetBounds(bounds); - return; - } - phantom_widget_->Hide(); + phantom_widget_->SetBounds(bounds); + return; } - show_timer_.Stop(); - show_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(delay_ms_), - this, &PhantomWindowController::ShowNow); + ShowNow(); } void PhantomWindowController::Hide() { phantom_widget_.reset(); - show_timer_.Stop(); } bool PhantomWindowController::IsShowing() const { return phantom_widget_.get() != NULL; } -void PhantomWindowController::DelayedClose(int delay_ms) { - show_timer_.Stop(); - if (!phantom_widget_.get() || !phantom_widget_->IsVisible()) - return; - - // DelayedWidgetDeleter deletes itself after the delay. - DelayedWidgetDeleter* deleter = - new DelayedWidgetDeleter(phantom_widget_.release(), window_); - deleter->ScheduleDelete(delay_ms); -} - void PhantomWindowController::ShowNow() { if (!phantom_widget_.get()) { phantom_widget_.reset(new views::Widget); views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - if (type_ == TYPE_DESTINATION) { - params.parent = window_->parent(); - } else { - // TYPE_EDGE is used by FrameMaximizeButton to highlight the launcher - // button, make sure the phantom appears over it. - params.parent = - Shell::GetInstance()->GetContainer(kShellWindowId_LauncherContainer); - } + // This is used by FrameMaximizeButton to highlight the launcher button, + // make sure the phantom appears over the launcher. + params.parent = + Shell::GetInstance()->GetContainer(kShellWindowId_LauncherContainer); params.can_activate = false; params.keep_on_top = true; phantom_widget_->set_focus_on_creation(false); @@ -192,17 +114,12 @@ void PhantomWindowController::ShowNow() { phantom_widget_->SetVisibilityChangedAnimationsEnabled(false); phantom_widget_->GetNativeWindow()->SetName("PhantomWindow"); views::View* content_view = new views::View; - views::Painter* painter = type_ == TYPE_DESTINATION ? - static_cast<views::Painter*>(new DestinationPainter) : - static_cast<views::Painter*>(new EdgePainter); + views::Painter* painter = static_cast<views::Painter*>(new EdgePainter); content_view->set_background( views::Background::CreateBackgroundPainter(true, painter)); phantom_widget_->SetContentsView(content_view); phantom_widget_->SetBounds(bounds_); - if (type_ == TYPE_DESTINATION) - phantom_widget_->StackBelow(window_); - else - phantom_widget_->StackAbove(window_); + phantom_widget_->StackAbove(window_); phantom_widget_->Show(); return; } diff --git a/ash/wm/workspace/phantom_window_controller.h b/ash/wm/workspace/phantom_window_controller.h index f3981c5..6991872 100644 --- a/ash/wm/workspace/phantom_window_controller.h +++ b/ash/wm/workspace/phantom_window_controller.h @@ -6,9 +6,8 @@ #define ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ #include "ash/ash_export.h" -#include "base/compiler_specific.h" +#include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -#include "base/timer.h" #include "ui/gfx/rect.h" namespace aura { @@ -22,25 +21,13 @@ class Widget; namespace ash { namespace internal { -// PhantomWindowController is responsible for showing a phantom beneath an -// existing window. PhantomWindowController is used during dragging a window to -// give an indication of where the window will land. +// PhantomWindowController is responsible for showing a phantom above a window. +// It's used used during dragging a window to show a snap location. class ASH_EXPORT PhantomWindowController { public: - enum Type { - // Used for showing an indication of where on the grid the window will land. - TYPE_DESTINATION, - - // Used when the window is placed along the edge of the screen. - TYPE_EDGE, - }; - - // |delay_ms| specifies the delay before the phantom is shown. - PhantomWindowController(aura::Window* window, Type type, int delay_ms); + explicit PhantomWindowController(aura::Window* window); ~PhantomWindowController(); - Type type() const { return type_; } - // Bounds last passed to Show(). const gfx::Rect& bounds() const { return bounds_; } @@ -54,9 +41,6 @@ class ASH_EXPORT PhantomWindowController { // Returns true if the phantom is showing. bool IsShowing() const; - // Closes the phantom window after a delay (in milliseconds). - void DelayedClose(int delay_ms); - private: // Shows the window immediately. void ShowNow(); @@ -64,19 +48,11 @@ class ASH_EXPORT PhantomWindowController { // Window the phantom is placed beneath. aura::Window* window_; - const Type type_; - - // Delay before closing. - const int delay_ms_; - // Last bounds passed to Show(). gfx::Rect bounds_; scoped_ptr<views::Widget> phantom_widget_; - // Timer used to show the phantom window. - base::OneShotTimer<PhantomWindowController> show_timer_; - DISALLOW_COPY_AND_ASSIGN(PhantomWindowController); }; diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc index feed24e..7e6eb1e 100644 --- a/ash/wm/workspace/workspace_window_resizer.cc +++ b/ash/wm/workspace/workspace_window_resizer.cc @@ -29,9 +29,6 @@ namespace { // Duration of the animation when snapping the window into place. const int kSnapDurationMS = 100; -// Delay before the phantom window is shown (in milliseconds). -const int kPhantomDelayMS = 400; - // Returns true if should snap to the edge. bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { return distance_from_edge <= grid_size / 2 && @@ -81,11 +78,7 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location) { } void WorkspaceWindowResizer::CompleteDrag() { - if (phantom_window_controller_.get()) { - if (snap_type_ == SNAP_DESTINATION) - phantom_window_controller_->DelayedClose(kSnapDurationMS); - phantom_window_controller_.reset(); - } + phantom_window_controller_.reset(); if (!did_move_or_resize_ || details_.window_component != HTCAPTION) return; @@ -204,9 +197,7 @@ WorkspaceWindowResizer::WorkspaceWindowResizer( gfx::Rect WorkspaceWindowResizer::GetFinalBounds( const gfx::Rect& bounds) const { if (phantom_window_controller_.get() && - phantom_window_controller_->IsShowing() && - phantom_window_controller_->type() == - PhantomWindowController::TYPE_EDGE) { + phantom_window_controller_->IsShowing()) { return phantom_window_controller_->bounds(); } return AdjustBoundsToGrid(bounds, details_.grid_size); @@ -320,7 +311,8 @@ void WorkspaceWindowResizer::SnapToWorkAreaEdges( } else if (ShouldSnapToEdge(right_edge - bounds->right(), details_.grid_size)) { bounds->set_x(right_edge - bounds->width()); - } if (ShouldSnapToEdge(bounds->y() - top_edge, details_.grid_size)) { + } + if (ShouldSnapToEdge(bounds->y() - top_edge, details_.grid_size)) { bounds->set_y(top_edge); } else if (ShouldSnapToEdge(bottom_edge - bounds->bottom(), details_.grid_size) && @@ -362,43 +354,27 @@ void WorkspaceWindowResizer::UpdatePhantomWindow(const gfx::Point& location, if (!did_move_or_resize_ || details_.window_component != HTCAPTION) return; + SnapType last_type = snap_type_; snap_type_ = GetSnapType(location); - if (snap_type_ == SNAP_NONE) { - phantom_window_controller_.reset(); - snap_sizer_.reset(); - return; - } - PhantomWindowController::Type phantom_type; - if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) - phantom_type = PhantomWindowController::TYPE_EDGE; - else - phantom_type = PhantomWindowController::TYPE_DESTINATION; - if (phantom_window_controller_.get() && - phantom_window_controller_->type() != phantom_type) { + if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { phantom_window_controller_.reset(); snap_sizer_.reset(); + if (snap_type_ == SNAP_NONE) + return; } - if (phantom_type == PhantomWindowController::TYPE_EDGE) { - if (!snap_sizer_.get()) { - SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT_EDGE) ? - SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; - snap_sizer_.reset( - new SnapSizer(details_.window, location, edge, details_.grid_size)); - } else { - snap_sizer_->Update(location); - } + if (!snap_sizer_.get()) { + SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT_EDGE) ? + SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; + snap_sizer_.reset( + new SnapSizer(details_.window, location, edge, details_.grid_size)); + } else { + snap_sizer_->Update(location); } if (!phantom_window_controller_.get()) { phantom_window_controller_.reset( - new PhantomWindowController(details_.window, phantom_type, - kPhantomDelayMS)); + new PhantomWindowController(details_.window)); } - gfx::Rect phantom_bounds; - if (snap_sizer_.get()) - phantom_bounds = snap_sizer_->target_bounds(); - else - phantom_bounds = GetFinalBounds(bounds); - phantom_window_controller_->Show(phantom_bounds); + phantom_window_controller_->Show(snap_sizer_->target_bounds()); } void WorkspaceWindowResizer::RestackWindows() { @@ -441,8 +417,6 @@ WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType( return SNAP_LEFT_EDGE; if (location.x() >= area.right() - 1) return SNAP_RIGHT_EDGE; - if (details_.grid_size > 1 && wm::IsWindowNormal(details_.window)) - return SNAP_DESTINATION; return SNAP_NONE; } diff --git a/ash/wm/workspace/workspace_window_resizer.h b/ash/wm/workspace/workspace_window_resizer.h index 73f4850..34a960d 100644 --- a/ash/wm/workspace/workspace_window_resizer.h +++ b/ash/wm/workspace/workspace_window_resizer.h @@ -67,9 +67,6 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { SNAP_LEFT_EDGE, SNAP_RIGHT_EDGE, - // Snap to the final bounds. Used when there is a grid. - SNAP_DESTINATION, - // No snap position. SNAP_NONE }; diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc index 160ba43..3155476 100644 --- a/ash/wm/workspace/workspace_window_resizer_unittest.cc +++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc @@ -520,6 +520,8 @@ TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { // Verifies snapping to edges works. TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { + Shell::GetInstance()->SetShelfAutoHideBehavior( + SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); window_->SetBounds(gfx::Rect(96, 112, 320, 160)); scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( window_.get(), gfx::Point(), HTCAPTION, 16, empty_windows())); |